Azure Monitor Opentelemetry Exporter Py
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Cloud and DevOps
- MIT
- Low risk
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The azure-monitor-opentelemetry-exporter-py provides a low-level exporter for Python applications using the OpenTelemetry standard. It enables developers to send custom telemetry data, including traces, metrics, and logs, directly to Azure Application Insights. This tool is designed for scenarios requiring fine-grained control over telemetry pipelines, supporting advanced features like Microsoft Entra ID authentication, custom sampling, and offline storage for reliable data delivery.
What it does
- Exports OpenTelemetry traces, metrics, and logs to Azure Application Insights.
- Supports Microsoft Entra ID authentication via DefaultAzureCredential.
- Provides configurable offline storage for reliable telemetry retries.
- Allows for custom sampling strategies using ApplicationInsightsSampler.
- Supports sovereign cloud configurations for specialized environments.
When to use it
- When you need to build a custom OpenTelemetry pipeline instead of using auto-instrumentation.
- When your application requires fine-grained control over how telemetry is exported.
- When you need to integrate telemetry data into Azure Monitor from a Python-based service.
- When you require reliable telemetry delivery with offline retry capabilities.
Advantages
- Native integration with Azure Monitor and Application Insights.
- Supports secure authentication using Azure identity credentials.
- Configurable retry logic via offline storage.
- Flexible configuration for various telemetry types.
Usage examples
- “How do I export traces to Application Insights using OpenTelemetry in Python?”
- You can use the AzureMonitorTraceExporter class, configure it with your connection string and credentials, and add it to your TracerProvider using a BatchSpanProcessor.
- “How can I enable offline storage for my telemetry exporter?”
- Initialize the exporter with the storage_directory parameter and ensure disable_offline_storage is set to False to enable automatic retries on failure.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/azure-monitor-opentelemetry-exporter-py/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-monitor-opentelemetry-exporter-py.zip -d .agents/skills
Documentation by Microsoft
Azure Monitor OpenTelemetry Exporter for Python
Low-level exporter for sending OpenTelemetry traces, metrics, and logs to Application Insights.
Installation
pip install azure-monitor-opentelemetry-exporterEnvironment Variables
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/ # Required for all auth methods
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in productionAuthentication & Lifecycle
🔑 Two rules apply to every code sample below:
Prefer
DefaultAzureCredentialfor ingestion auth when supported.APPLICATIONINSIGHTS_CONNECTION_STRINGidentifies the target Application Insights resource, andcredential=DefaultAzureCredential(...)provides Microsoft Entra authentication.
Local dev:
DefaultAzureCredentialworks as-is.Production: set
AZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.Providers are not context managers. Flush and shut down telemetry providers explicitly at process exit so buffers are exported deterministically.
Snippets may abbreviate this setup, but production code should always follow both rules.
When to Use
| Scenario | Use |
|---|---|
| Quick setup, auto-instrumentation | azure-monitor-opentelemetry (distro) |
| Custom OpenTelemetry pipeline | azure-monitor-opentelemetry-exporter (this) |
| Fine-grained control over telemetry | azure-monitor-opentelemetry-exporter (this) |
Trace Exporter
from azure.identity import DefaultAzureCredential
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Reads APPLICATIONINSIGHTS_CONNECTION_STRING from env to identify the resource;
# DefaultAzureCredential authenticates ingestion via Microsoft Entra ID.
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential(),
)
# Configure tracer provider
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(exporter)
)
# Use tracer
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("my-span"):
print("Hello, World!")Metric Exporter
from azure.identity import DefaultAzureCredential
from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter
# Reads APPLICATIONINSIGHTS_CONNECTION_STRING from env; AAD-authenticated ingestion via DefaultAzureCredential.
exporter = AzureMonitorMetricExporter(
credential=DefaultAzureCredential(),
)
# Configure meter provider
reader = PeriodicExportingMetricReader(exporter, export_interval_millis=60000)
metrics.set_meter_provider(MeterProvider(metric_readers=[reader]))
# Use meter
meter = metrics.get_meter(__name__)
counter = meter.create_counter("requests_total")
counter.add(1, {"route": "/api/users"})Log Exporter
import logging
from azure.identity import DefaultAzureCredential
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 AzureMonitorLogExporter
# Reads APPLICATIONINSIGHTS_CONNECTION_STRING from env; AAD-authenticated ingestion via DefaultAzureCredential.
exporter = AzureMonitorLogExporter(
credential=DefaultAzureCredential(),
)
# Configure logger provider
logger_provider = LoggerProvider()
logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
set_logger_provider(logger_provider)
# Add handler to Python logging
handler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider)
logging.getLogger().addHandler(handler)
# Use logging
logger = logging.getLogger(__name__)
logger.info("This will be sent to Application Insights")From Environment Variable
Exporters read APPLICATIONINSIGHTS_CONNECTION_STRING automatically:
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Connection string from environment; AAD-authenticated ingestion via DefaultAzureCredential.
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential(),
)Azure AD Authentication
from azure.identity import DefaultAzureCredential, ManagedIdentityCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
credential = DefaultAzureCredential(require_envvar=True)
# Or use a specific credential directly in production:
# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes
# credential = ManagedIdentityCredential()
exporter = AzureMonitorTraceExporter(
credential=credential
)Sampling
Use ApplicationInsightsSampler for consistent sampling:
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.sampling import ParentBasedTraceIdRatio
from azure.monitor.opentelemetry.exporter import ApplicationInsightsSampler
# Sample 10% of traces
sampler = ApplicationInsightsSampler(sampling_ratio=0.1)
trace.set_tracer_provider(TracerProvider(sampler=sampler))Offline Storage
Configure offline storage for retry:
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential(),
storage_directory="/path/to/storage", # Custom storage path
disable_offline_storage=False # Enable retry (default)
)Disable Offline Storage
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential(),
disable_offline_storage=True # No retry on failure
)Sovereign Clouds
from azure.identity import AzureAuthorityHosts, DefaultAzureCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Azure Government
credential = DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_GOVERNMENT)
exporter = AzureMonitorTraceExporter(
connection_string="InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.us/",
credential=credential
)Exporter Types
| Exporter | Telemetry Type | Application Insights Table |
|---|---|---|
AzureMonitorTraceExporter | Traces/Spans | requests, dependencies, exceptions |
AzureMonitorMetricExporter | Metrics | customMetrics, performanceCounters |
AzureMonitorLogExporter | Logs | traces, customEvents |
Configuration Options
| Parameter | Description | Default |
|---|---|---|
connection_string | Application Insights connection string | From env var |
credential | Azure credential for AAD auth | None |
disable_offline_storage | Disable retry storage | False |
storage_directory | Custom storage path | Temp directory |
Best Practices
Pick sync OR async and stay consistent. Do not mix
azure.xxxsync clients withazure.xxx.aioasync clients in the same call path. Choose one mode per module.Call
provider.shutdown()/force_flush()at process exit to flush telemetry — providers are not context managers.Use BatchSpanProcessor for production (not SimpleSpanProcessor)
Use ApplicationInsightsSampler for consistent sampling across services
Enable offline storage for reliability in production
Use Microsoft Entra authentication instead of instrumentation keys
Set export intervals appropriate for your workload
Use the distro (
azure-monitor-opentelemetry) unless you need custom pipelines
Reference Files
| File | Contents |
|---|---|
| references/capabilities.md | Additional non-hero capabilities, operation-group coverage, and production checklists. |
| references/non-hero-scenarios.md | Dedicated non-hero examples for secondary/advanced scenarios. |
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md8.9 KiB
- references/capabilities.md2.1 KiB
- references/non-hero-scenarios.md3.0 KiB
references/capabilities.md
azure-monitor-opentelemetry-exporter-py capability coverage
SDK/package: azure-monitor-opentelemetry-exporter
This index maps hero scenarios in SKILL.md and links non-hero scenarios documented in dedicated reference files.
Hero scenarios covered in SKILL.md
Trace ExporterMetric ExporterLog ExporterFrom Environment Variable
Non-hero scenarios
Azure AD Authentication: Dedicated example and implementation notes.
See:non-hero-scenarios.md#azure-ad-authenticationSampling: UseApplicationInsightsSamplerfor consistent sampling:
See:non-hero-scenarios.md#samplingOffline Storage: Configure offline storage for retry:
See:non-hero-scenarios.md#offline-storageDisable Offline Storage: Dedicated example and implementation notes.
See:non-hero-scenarios.md#disable-offline-storageSovereign Clouds: Dedicated example and implementation notes.
See:non-hero-scenarios.md#sovereign-cloudsExporter Types: | Exporter | Telemetry Type | Application Insights Table |
See:non-hero-scenarios.md#exporter-typesConfiguration Options: | Parameter | Description | Default |
See:non-hero-scenarios.md#configuration-options
Related deep-dive references
non-hero-scenarios.md: Dedicated non-hero examples and implementation notes.
API breadth checklist
Verify client/auth mode for the environment before coding.
Confirm operation-group/method names against current Microsoft Learn API reference.
For Python SDKs with both sync and async clients, document both forms without a blanket preference.
Include cleanup/delete paths for created resources in examples.
Prefer idempotent create/update operations where available.
Validate paging/LRO/error-handling patterns for production paths.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Python
Security
What our scanner noticed· Low risk
- Instructions that use the network
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-python/skills/azure-monitor-opentelemetry-exporter-py · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-monitor-opentelemetry-exporter-py.zip