Microsoft Azure Monitor Opentelemetry Distro Client Library for Python
Project description
Azure Monitor Opentelemetry Distro client library for Python
The Azure Monitor Distro of Opentelemetry Python provides multiple installable components available for an Opentelemetry Azure Monitor monitoring solution. It allows you to instrument your Python applications to capture and report telemetry to Azure Monitor via the Azure monitor exporters.
This distro automatically installs the following libraries:
- Azure Monitor OpenTelemetry exporters
- A subset of OpenTelemetry instrumentations that are officially supported as listed below.
Officially supported instrumentations
OpenTelemetry instrumentations allow automatic collection of requests sent from underlying instrumented libraries. The following is a list of OpenTelemetry instrumentations that come bundled in with the Azure monitor distro. These instrumentations are enabled by default. See the Usage section below for how to opt-out of these instrumentations.
Instrumentation | Supported library Name | Supported versions |
---|---|---|
Azure Core Tracing OpenTelemetry | azure_sdk |
|
OpenTelemetry Django Instrumentation | django | link |
OpenTelemetry FastApi Instrumentation | fastapi | link |
OpenTelemetry Flask Instrumentation | flask | link |
OpenTelemetry Psycopg2 Instrumentation | psycopg2 | link |
OpenTelemetry Requests Instrumentation | requests | link |
OpenTelemetry UrlLib Instrumentation | urllib | All |
OpenTelemetry UrlLib3 Instrumentation | urllib3 | link |
If you would like to add support for another OpenTelemetry instrumentation, please submit a feature request. In the meantime, you can use the OpenTelemetry instrumentation manually via it's own APIs (i.e. instrument()
) in your code. See this for an example.
Key concepts
This package bundles a series of OpenTelemetry and Azure Monitor components to enable the collection and sending of telemetry to Azure Monitor. For MANUAL instrumentation, use the configure_azure_monitor
function. AUTOMATIC instrumentation is not yet supported.
The Azure Monitor OpenTelemetry exporters are the main components in accomplishing this. You will be able to use the exporters and their APIs directly through this package. Please go the exporter documentation to understand how OpenTelemetry and Azure Monitor components work in enabling telemetry collection and exporting.
Currently, all instrumentations available in OpenTelemetry are in a beta state, meaning they are not stable and may have breaking changes in the future. Efforts are being made in pushing these to a more stable state.
Getting started
Prerequisites
To use this package, you must have:
- Azure subscription - Create a free account
- Azure Monitor - How to use application insights
- Opentelemetry SDK - Opentelemetry SDK for Python
- Python 3.7 or later - Install Python
Install the package
Install the Azure Monitor Opentelemetry Distro with pip:
pip install azure-monitor-opentelemetry
Usage
You can use configure_azure_monitor
to set up instrumentation for your app to Azure Monitor. configure_azure_monitor
supports the following optional arguments. All pass-in parameters take priority over any related environment variables.
Parameter | Description | Environment Variable |
---|---|---|
connection_string |
The connection string for your Application Insights resource. The connection string will be automatically populated from the APPLICATIONINSIGHTS_CONNECTION_STRING environment variable if not explicitly passed in. |
APPLICATIONINSIGHTS_CONNECTION_STRING |
logger_name |
The name of the Python logger under which telemetry is collected. | N/A |
instrumentation_options |
A nested dictionary that determines which instrumentations to enable or disable. Instrumentations are referred to by their Library Names. For example, {"azure_sdk": {"enabled": False}, "flask": {"enabled": False}, "django": {"enabled": True}} will disable Azure Core Tracing and the Flask instrumentation but leave Django and the other default instrumentations enabled. The OTEL_PYTHON_DISABLED_INSTRUMENTATIONS environment variable explained below can also be used to disable instrumentations. |
N/A |
You can configure further with OpenTelemetry environment variables such as:
Environment Variable | Description |
---|---|
OTEL_SERVICE_NAME, OTEL_RESOURCE_ATTRIBUTES | Specifies the OpenTelemetry resource associated with your application. |
OTEL_LOGS_EXPORTER |
If set to None , disables collection and export of logging telemetry. |
OTEL_METRICS_EXPORTER |
If set to None , disables collection and export of metric telemetry. |
OTEL_TRACES_EXPORTER |
If set to None , disables collection and export of distributed tracing telemetry. |
OTEL_BLRP_SCHEDULE_DELAY |
Specifies the logging export interval in milliseconds. Defaults to 5000. |
OTEL_BSP_SCHEDULE_DELAY |
Specifies the distributed tracing export interval in milliseconds. Defaults to 5000. |
OTEL_TRACES_SAMPLER_ARG |
Specifies the ratio of distributed tracing telemetry to be sampled. Accepted values are in the range [0,1]. Defaults to 1.0, meaning no telemetry is sampled out. |
OTEL_PYTHON_DISABLED_INSTRUMENTATIONS |
Specifies which of the supported instrumentations to disable. Disabled instrumentations will not be instrumented as part of configure_azure_monitor . However, they can still be manually instrumented with instrument() directly. Accepts a comma-separated list of lowercase Library Names. For example, set to "psycopg2,fastapi" to disable the Psycopg2 and FastAPI instrumentations. Defaults to an empty list, enabling all supported instrumentations. |
Azure monitor OpenTelemetry Exporter configurations
You can pass Azure monitor OpenTelemetry exporter configuration parameters directly into configure_azure_monitor
. See additional configuration related to exporting here.
...
configure_azure_monitor(
connection_string="<your-connection-string>",
disable_offline_storage=True,
)
...
Examples
Samples are available here to demonstrate how to utilize the above configuration options.
Troubleshooting
The exporter raises exceptions defined in Azure Core.
Next steps
Check out the documentation for more.
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Additional documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file azure-monitor-opentelemetry-1.1.0.tar.gz
.
File metadata
- Download URL: azure-monitor-opentelemetry-1.1.0.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5d3597f01e0b7e173ca14784b6be465f0e595d01989f809a37f74ba02dc895b |
|
MD5 | a0d6fac68fee6aa8109297f1f9f037dd |
|
BLAKE2b-256 | b187fb9cc8ec4af699cb4ed07c8168537e8ae3d0240a1f63595531c752eced71 |
File details
Details for the file azure_monitor_opentelemetry-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: azure_monitor_opentelemetry-1.1.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: RestSharp/106.13.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f56aa5ed3efca5e825122734f10cee5161c4c79ee2cb6f614eb1a74ae9df729d |
|
MD5 | be309fb9c721bee8ef07e57606efb175 |
|
BLAKE2b-256 | dd8cc5350cb855efa64b8573c41e9adb9ba62279673a138fff4db353ce3c9df3 |