Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Reason given by maintainers: Deprecated this package due to naming. Please utilize azure-monitor-opentelemetry-exporter.

Microsoft Opentelemetry exporter for Azure Monitor

Gitter chat

The exporter for Azure Monitor allows you to export tracing data utilizing the OpenTelemetry SDK and send telemetry data to Azure Monitor for applications written in Python.

Source code | Package (PyPi) | API reference documentation | Product documentation | Samples | Changelog

NOTE: This is the preview for the next major version of opentelemetry-azure-monitor-python.

Getting started

Install the package

Install the Microsoft Opentelemetry exporter for Azure Monitor with pip:

pip install microsoft-opentelemetry-exporter-azuremonitor --pre

Prerequisites:

To use this package, you must have:

Authenticate the client

Interaction with Azure monitor exporter starts with an instance of the AzureMonitorSpanExporter class. You will need a connection_string to instantiate the object. Please find the samples linked below for demonstration as to how to authenticate using a connection string.

Create Exporter from connection string

from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter
exporter = AzureMonitorSpanExporter(
    connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)

Key concepts

Some of the key concepts for the Azure monitor exporter include:

  • Opentelemetry: Opentelemetry is a set of libraries used to collect and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior.

  • Instrumentation: The ability to call the opentelemetry API directly by any application is facilitated by instrumentaton. A library that enables OpenTelemetry observability for another library is called an Instrumentation Library.

  • Trace: Trace refers to distributed tracing. It can be thought of as a directed acyclic graph (DAG) of Spans, where the edges between Spans are defined as parent/child relationship.

  • Tracer Provider: Provides a Tracer for use by the given instrumentation library.

  • Span Processor: A span processor allows hooks for SDK's Span start and end method invocations. Follow the link for more information.

  • Sampling: Sampling is a mechanism to control the noise and overhead introduced by OpenTelemetry by reducing the number of samples of traces collected and sent to the backend.

  • AzureMonitorSpanExporter: This is the class that is initialized to send tracing related telemetry to Azure Monitor.

  • Exporter Options: Options to configure Azure exporters. Includes connection_string, instrumentation_key, proxies, timeout etc.

For more information about these resources, see What is Azure Monitor?.

Examples

The following sections provide several code snippets covering some of the most common tasks, including:

Export Hello World Trace

import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter

exporter = AzureMonitorSpanExporter(
    connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
)

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span("hello"):
    print("Hello, World!")

Modifying Traces

  • You can pass a callback function to the exporter to process telemetry before it is exported.
  • Your callback function can return False if you do not want this envelope exported.
  • Your callback function must accept an envelope data type as its parameter.
  • You can see the schema for Azure Monitor data types in the envelopes here.
  • The AzureMonitorSpanExporter handles Data data types.
from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

# Callback function to add os_type: linux to span properties
def callback_function(envelope):
    envelope.data.baseData.properties['os_type'] = 'linux'
    return True

exporter = AzureMonitorSpanExporter(
    connection_string='InstrumentationKey=<your-ikey-here>'
)
# This line will modify telemetry
exporter.add_telemetry_processor(callback_function)

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
span_processor = BatchExportSpanProcessor(exporter)
trace.get_tracer_provider().add_span_processor(span_processor)

with tracer.start_as_current_span('hello'):
    print('Hello World!')

Instrumentation with requests library

OpenTelemetry also supports several instrumentations which allows to instrument with third party libraries.

This example shows how to instrument with the requests library.

  • Install the requests integration package using pip install opentelemetry-instrumentation-requests.
import os
import requests
from opentelemetry import trace
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor

from microsoft.opentelemetry.exporter.azuremonitor import AzureMonitorSpanExporter

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)

# This line causes your calls made with the requests library to be tracked.
RequestsInstrumentor().instrument()
span_processor = BatchExportSpanProcessor(
    AzureMonitorSpanExporter(
        connection_string = os.environ["APPLICATIONINSIGHTS_CONNECTION_STRING "]
    )
)
trace.get_tracer_provider().add_span_processor(span_processor)

RequestsInstrumentor().instrument()

# This request will be traced
response = requests.get(url="https://azure.microsoft.com/")

Troubleshooting

The exporter raises exceptions defined in Azure Core.

Next steps

More sample code

Please find further examples in the samples directory demonstrating common scenarios.

Additional documentation

For more extensive documentation on the Azure Monitor service, see the Azure Monitor documentation on docs.microsoft.com.

For detailed overview of Opentelemetry, visit their overview page.

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.

Release files for microsoft-opentelemetry-exporter-azuremonitor 1.0.0b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microsoft-opentelemetry-exporter-azuremonitor 1.0.0b1
File Size Uploaded
microsoft-opentelemetry-exporter-azuremonitor-1.0.0b1.zip 74.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for microsoft-opentelemetry-exporter-azuremonitor 1.0.0b1
File Interpreter ABI Platform
microsoft_opentelemetry_exporter_azuremonitor-1.0.0b1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 117.8 kB

Release files / microsoft-opentelemetry-exporter-azuremonitor-1.0.0b1.zip

Download URL microsoft-opentelemetry-exporter-azuremonitor-1.0.0b1.zip
Size 74.8 kB
Tags Source
SHA-256 checksum
How to use checksums
52a840e1c7edfce38d5141be13d163a97785927ea7aa60322474254923d4e353
BLAKE2b-256 checksum
How to use checksums
1c5d647bb3c65dd9f6a9c18f92c5d855e9b24517202a0723cac2285f6a2c5e3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / microsoft_opentelemetry_exporter_azuremonitor-1.0.0b1-py2.py3-none-any.whl

Download URL microsoft_opentelemetry_exporter_azuremonitor-1.0.0b1-py2.py3-none-any.whl
Size 43.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
07517f7961cd3a91d00777fa2f11c8398fc253d32c69ed33d378b7b01885a5a8
BLAKE2b-256 checksum
How to use checksums
5752ed59ff27a2f0831dc1d363c7c051b052050cefb4995999e763bd2bc0e0d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

1.0.0b1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page