telemetry package

Provides functionality for logging, capturing events and metrics, and monitoring code activity.

This package enables you to collect different types of telemetry using free text or structured logging. For example, for unstructured text in high volumes you can use one of the logs from the loggers module. For collecting and aggregating metrics or capturing low volume events or user activities with a defined schema use the structured schema defined in the contracts module. You can also, monitor blocks of code with the the activity module.

Log messages, metrics, events, and activity messages can written to Application Insights. For example, you can the get_appinsights_log_handler(instrumentation_key, logger=None, *args, **kwargs) function to get a handle to an Application Insights instance.

Packages

contracts

Defines classes for collecting structured metrics and events telemetry.

Structured telemetry is collected based on a common schema instead of free text logging of the data. Using a schema enables easier post-analysis of the data. Metrics and events in a common schema are collected with RequiredFields, StandardFields, and ExtensionFields.

logger

Init for logger module.

Modules

activity

Defines functionality for collecting telemetry about code.

An activity is a logical block of code that consumers want to monitor. To monitor an activity, either wrap the logical block of code with the log_activity() method or use the @monitor_with_activity decorator.

log_scope

Modules for log scope, including the definition of context manager and decorator.

loggers

Factory for creating loggers.

logging_handler

Contains functionality for sending telemetry to Application Insights.

Classes

UserErrorException

Class for raising user exceptions.

Functions

add_diagnostics_properties(properties)

Add additional diagnostics properties.

add_diagnostics_properties(properties)

Parameters

properties
dict

Additional diagnostic properties.

get_diagnostics_collection_info(component_name=None, path=None)

Return the current diagnostics collection status.

get_diagnostics_collection_info(component_name=None, path=None)

Parameters

component_name
str

The name of the component for which to retrieve the default value.

default value: None
path
str

The path of telemetry settings file.

default value: None

Returns

Usage statistics configuration.

Return type

Tuple[bool, str]

get_event_logger(*args, **kwargs)

Return the registered default event logger.

Use this function to get the default logger.

get_event_logger(*args, **kwargs)

Returns

the registered default event logger

Return type

_AbstractEventLogger

Remarks

The following code sample shows how to use get_event_logger.


   >>> from azureml import telemetry
   >>> from azureml.telemetry.contracts import Event
   >>> logger = telemetry.get_event_logger()
   >>> track_event = Event("new event")
   >>> # add values for required_fields, standard_fields and/or extension_fields
   >>> # to track_event per your business need here
   >>> logger.log_event(track_event)

get_telemetry_log_handler(instrumentation_key='625b9182-81ec-41de-adce-183c9489ac1a', component_name=None, path=None)

Get the telemetry log handler if enabled otherwise return null handler.

get_telemetry_log_handler(instrumentation_key='625b9182-81ec-41de-adce-183c9489ac1a', component_name=None, path=None)

Parameters

instrumentation_key
str

The instrumentation key.

default value: 625b9182-81ec-41de-adce-183c9489ac1a
component_name
str

The component name.

default value: None
path
str

The telemetry file with full path.

default value: None

Returns

The telemetry handler if enabled, else null log handler.

Return type

logging.handler

is_diagnostics_collection_info_available()

Check that the diagnostics collection is being set by user.

is_diagnostics_collection_info_available()

Returns

whether diagnostics collection is being set by user

Return type

set_diagnostics_collection(send_diagnostics=True, verbosity=20, reason='', path=None)

Enable or disable diagnostics collection.

set_diagnostics_collection(send_diagnostics=True, verbosity=20, reason='', path=None)

Parameters

send_diagnostics
bool

Specifies whether to send diagnostics.

default value: True
verbosity
logging(const)

Sets the diagnostics verbosity.

default value: 20
reason
str

The reason for enabling diagnostics.

path
str

The path of the config file.

default value: None

Returns

The telemetry file path.

Return type

str

set_diagnostics_properties(properties)

Set the diagnostics properties.

set_diagnostics_properties(properties)

Parameters

properties
dict

The diagnostics properties.