Registry /
azure / azure-monitor-opentelemetry-exporter
Install & Compatibility
Where this runs
tested against v1.0.0b56 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.560s · 52.2MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.8s · import 1.462s · 53MB
52MB installed
● package 52MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
AzureMonitorTraceExporter
✓ from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
AzureMonitorMetricExporter
✓ from azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter
AzureMonitorLogExporter
✓ from azure.monitor.opentelemetry.exporter import AzureMonitorLogExporter
Note: The logging signal for AzureMonitorLogExporter is currently experimental and may have breaking changes.
This quickstart demonstrates how to set up OpenTelemetry tracing, metrics, and logging with the Azure Monitor Exporter. It uses a connection string, preferably from an environment variable (`APPLICATIONINSIGHTS_CONNECTION_STRING`), to authenticate and send telemetry to Azure Application Insights. Remember to replace 'YOUR_INSTRUMENTATION_KEY' with your actual key if not using an environment variable. Ensure to call `shutdown()` on providers to guarantee telemetry is flushed before the application exits.
import os
import logging
from opentelemetry import trace, metrics
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader, ConsoleMetricExporter
from opentelemetry._logs import set_logger_provider
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
from azure.monitor.opentelemetry.exporter import (
AzureMonitorTraceExporter,
AzureMonitorMetricExporter,
AzureMonitorLogExporter
)
CONNECTION_STRING = os.environ.get('APPLICATIONINSIGHTS_CONNECTION_STRING', 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY')
# --- Tracing ---
print('Setting up tracing...')
exporter_trace = AzureMonitorTraceExporter(connection_string=CONNECTION_STRING)
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(BatchSpanProcessor(exporter_trace))
trace.set_tracer_provider(tracer_provider)
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("my-trace-span"):
print("Hello from trace!")
# --- Metrics ---
print('Setting up metrics...')
exporter_metric = AzureMonitorMetricExporter(connection_string=CONNECTION_STRING)
metric_reader = PeriodicExportingMetricReader(exporter_metric, export_interval_millis=1000)
meter_provider = MeterProvider(metric_readers=[metric_reader])
metrics.set_meter_provider(meter_provider)
meter = metrics.get_meter(__name__)
counter = meter.create_counter("my_counter", description="A simple counter")
counter.add(1, {"key": "value"})
# --- Logging ---
print('Setting up logging...')
exporter_log = AzureMonitorLogExporter(connection_string=CONNECTION_STRING)
logger_provider = LoggerProvider()
set_logger_provider(logger_provider)
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter_log))
handler = LoggingHandler(logger_provider=logger_provider)
# Attach OTel handler to root logger
root_logger = logging.getLogger()
root_logger.addHandler(handler)
root_logger.setLevel(logging.INFO)
# Log a message
root_logger.info("Hello from log!")
# --- Flush and Shutdown ---
print('Flushing and shutting down...')
tracer_provider.shutdown()
meter_provider.shutdown()
logger_provider.shutdown()
print('Telemetry sent to Azure Monitor (check your Application Insights resource).')
Debug
Known issues
breakingThe package name has undergone several changes. Ensure you are using the correct and current package name: `azure-monitor-opentelemetry-exporter`. Older documentation or samples might refer to `azure-opentelemetry-exporter-azuremonitor` or `microsoft-opentelemetry-exporter-azuremonitor`.fixAlways use `pip install azure-monitor-opentelemetry-exporter --pre` and import from `azure.monitor.opentelemetry.exporter`.
affects: <=1.0.0b49
deprecatedThe `AzureMonitorLogExporter` for logging is currently in an EXPERIMENTAL state. Microsoft warns that possible breaking changes may occur in future releases for this component.fixBe aware that logging implementation might require adjustments with future updates. Review the changelog for specific breaking changes in logging.
affects: All beta versions
gotchaUsers often confuse this exporter with the `Azure Monitor OpenTelemetry Distro`. This `azure-monitor-opentelemetry-exporter` library is for advanced scenarios requiring explicit OpenTelemetry SDK configuration. For simpler, one-line setup and auto-instrumentation, the `azure-monitor-opentelemetry` distro is recommended.
gotchaConnection string is the primary configuration method. It's best practice to set the `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable for authentication. Directly embedding the instrumentation key in code is not recommended for production.
gotchaFailing to explicitly shut down or flush OpenTelemetry providers and exporters can lead to lost telemetry. It is critical to call `shutdown()` on `TracerProvider`, `MeterProvider`, and `LoggerProvider` before your application exits to ensure all buffered telemetry is sent.
gotchaWhen logging in Azure Functions environments, avoid duplicate telemetry by not enabling both the native logging instrumentation in Azure Functions and the `azure-monitor-opentelemetry` logging instrumentation within the distribution. This can result in two entries for each log.
gotchaThe Azure Monitor Exporter currently has limitations in handling oversized log messages (exceeding 65536 bytes), which may prevent larger logs from being delivered to Application Insights. This could be a blocker for migration in environments with verbose logging.fixBe mindful of log message size; there is no current workaround to guarantee delivery of oversized logs. Monitor related GitHub issues for updates.
affects: All beta versions
breakingThe instrumentation key provided within the connection string must be a valid UUID. Failing to provide a properly formatted UUID will result in a `ValueError` during exporter initialization.fixEnsure the `InstrumentationKey` parameter in your connection string (or the environment variable `APPLICATIONINSIGHTS_CONNECTION_STRING`) is set to a valid UUID.
affects: All beta versions
gotchaThe instrumentation key, typically found within the connection string, must be a valid UUID (Globally Unique Identifier). Providing an incorrectly formatted instrumentation key will result in a `ValueError` during exporter initialization.fixEnsure your `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable or the `connection_string` parameter in the exporter constructor contains an instrumentation key that adheres to the UUID format (e.g., `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`).
affects: All
Upgrade
Version history
1.0.0b56latest on PyPI · released Aug 5, 2026
Audit
Dependencies
opentelemetry-sdkrequiredCore OpenTelemetry SDK components required for trace, metric, and log providers and processors.
opentelemetry-apirequiredProvides the OpenTelemetry API for creating telemetry.