applicationinsights module

TelemetryClient class

class applicationinsights.TelemetryClient(instrumentation_key, telemetry_channel=None)[source]

The telemetry client used for sending all types of telemetry. It serves as the main entry point for interacting with the Application Insights service.

add_telemetry_processor(telemetry_processor)[source]
Adds telemetry processor to the collection. Telemetry processors will be called one by one

before telemetry item is pushed for sending and in the order they were added.

Args:
telemetry_processor (function). Takes a telemetry item, and context object and returns boolean

that determines if the event is passed to the server (False = Filtered)

flush()[source]

Flushes data in the queue. Data in the queue will be sent either immediately irrespective of what sender is being used.

track_availability(name, duration, success, run_location, message=None, properties=None, measurements=None, availability_id=None)[source]

Sends a single availability telemetry that was captured for the application.

Args:

name (str). the name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template.

duration (int). the number of milliseconds that this dependency call lasted.

success (bool). true if the dependency call ended in success, false otherwise.

run_location (str). the name of the location where the test has been executed.

message (str). the message for this availability telemetry. (defaults to: None)

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

id (str). the id for this dependency call. If None, a new uuid will be generated. (defaults to: None)

track_dependency(name, data, type=None, target=None, duration=None, success=None, result_code=None, properties=None, measurements=None, dependency_id=None)[source]

Sends a single dependency telemetry that was captured for the application.

Args:

name (str). the name of the command initiated with this dependency call. Low cardinality value. Examples are stored procedure name and URL path template.

data (str). the command initiated by this dependency call. Examples are SQL statement and HTTP URL with all query parameters.

type (str). the dependency type name. Low cardinality value for logical grouping of dependencies and interpretation of other fields like commandName and resultCode. Examples are SQL, Azure table, and HTTP. (default to: None)

target (str). the target site of a dependency call. Examples are server name, host address. (default to: None)

duration (int). the number of milliseconds that this dependency call lasted. (defaults to: None)

success (bool). true if the dependency call ended in success, false otherwise. (defaults to: None)

result_code (str). the result code of a dependency call. Examples are SQL error code and HTTP status code. (defaults to: None)

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

id (str). the id for this dependency call. If None, a new uuid will be generated. (defaults to: None)

track_event(name, properties=None, measurements=None)[source]

Send information about a single event that has occurred in the context of the application.

Args:

name (str). the data to associate to this event.

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

track_exception(type=None, value=None, tb=None, properties=None, measurements=None)[source]

Send information about a single exception that occurred in the application.

Args:

type (Type). the type of the exception that was thrown.

value (Exception). the exception that the client wants to send.

tb (Traceback). the traceback information as returned by sys.exc_info().

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

track_metric(name, value, type=None, count=None, min=None, max=None, std_dev=None, properties=None)[source]

Send information about a single metric data point that was captured for the application.

Args:

name (str). the name of the metric that was captured.

value (float). the value of the metric that was captured.

type (channel.contracts.DataPointType). the type of the metric. (defaults to: channel.contracts.DataPointType.aggregation())

count (int). the number of metrics that were aggregated into this data point. (defaults to: None)

min (float). the minimum of all metrics collected that were aggregated into this data point. (defaults to: None)

max (float). the maximum of all metrics collected that were aggregated into this data point. (defaults to: None)

std_dev (float). the standard deviation of all metrics collected that were aggregated into this data point. (defaults to: None)

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

track_pageview(name, url, duration=0, properties=None, measurements=None)[source]

Send information about the page viewed in the application (a web page for instance).

Args:

name (str). the name of the page that was viewed.

url (str). the URL of the page that was viewed.

duration (int). the duration of the page view in milliseconds. (defaults to: 0)

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

track_request(name, url, success, start_time=None, duration=None, response_code=None, http_method=None, properties=None, measurements=None, request_id=None)[source]

Sends a single request that was captured for the application.

Args:

name (str). the name for this request. All requests with the same name will be grouped together.

url (str). the actual URL for this request (to show in individual request instances).

success (bool). true if the request ended in success, false otherwise.

start_time (str). the start time of the request. The value should look the same as the one returned by datetime.isoformat() (defaults to: None)

duration (int). the number of milliseconds that this request lasted. (defaults to: None)

response_code (str). the response code that this request returned. (defaults to: None)

http_method (str). the HTTP method that triggered this request. (defaults to: None)

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

measurements (dict). the set of custom measurements the client wants to attach to this data item. (defaults to: None)

request_id (str). the id for this request. If None, a new uuid will be generated. (defaults to: None)

track_trace(name, properties=None, severity=None)[source]

Sends a single trace statement.

Args:

name (str). the trace statement.

properties (dict). the set of custom properties the client wants attached to this data item. (defaults to: None)

severity (str). the severity level of this trace, one of DEBUG, INFO, WARNING, ERROR, CRITICAL

property channel

The channel associated with this telemetry client. All data created by this client will be passed along with the context() object to channel.TelemetryChannel’s write().

Returns:

channel.TelemetryChannel. the channel instance.

property context

The context associated with this client. All data objects created by this client will be accompanied by this value.

Returns:

channel.TelemetryContext. the context instance.