azure-monitor-opentelemetry-exporter-py
A Python exporter for sending OpenTelemetry-compliant traces and metrics to Azure Monitor.
Install
mkdir -p .claude/skills/azure-monitor-opentelemetry-exporter-py && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/5466" && unzip -o skill.zip -d .claude/skills/azure-monitor-opentelemetry-exporter-py && rm skill.zipInstalls to .claude/skills/azure-monitor-opentelemetry-exporter-py
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights. Triggers: "azure-monitor-opentelemetry-exporter", "AzureMonitorTraceExporter", "AzureMonitorMetricExporter", "AzureMonitorLogExporter".Key capabilities
- →Export OpenTelemetry traces to Application Insights
- →Collect and export custom metrics
- →Export logs via OpenTelemetry logging handler
- →Configure offline storage for retries
- →Support for consistent sampling
How it works
The exporter acts as a bridge, converting OpenTelemetry telemetry data into the format required by the Application Insights ingestion endpoint.
Inputs & outputs
When to use azure-monitor-opentelemetry-exporter-py
- →Export traces to App Insights
- →Collect custom metrics
- →Monitor application performance
About this skill
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-exporter
Environment 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 production
Authentication & 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. |
When not to use it
- →Standard application logging
- →Direct instrumentation without OpenTelemetry
Prerequisites
Limitations
- →Requires explicit provider shutdown
- →Dependent on OpenTelemetry SDK versions
How it compares
It allows using standard OpenTelemetry APIs while maintaining compatibility with Azure-specific monitoring features.
Compared to similar skills
azure-monitor-opentelemetry-exporter-py side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| azure-monitor-opentelemetry-exporter-py (this skill) | 1 | 29d | Review | Advanced |
| distributed-tracing | 5 | 2mo | No flags | Intermediate |
| langfuse | 7 | 6mo | No flags | Intermediate |
| langsmith-observability | 4 | 7mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by microsoft
View all by microsoft →You might also like
distributed-tracing
wshobson
Implement distributed tracing with Jaeger and Tempo to track requests across microservices and identify performance bottlenecks. Use when debugging microservices, analyzing request flows, or implementing observability for distributed systems.
langfuse
davila7
Expert in Langfuse - the open-source LLM observability platform. Covers tracing, prompt management, evaluation, datasets, and integration with LangChain, LlamaIndex, and OpenAI. Essential for debugging, monitoring, and improving LLM applications in production. Use when: langfuse, llm observability, llm tracing, prompt management, llm evaluation.
langsmith-observability
davila7
LLM observability platform for tracing, evaluation, and monitoring. Use when debugging LLM applications, evaluating model outputs against datasets, monitoring production systems, or building systematic testing pipelines for AI applications.
phoenix-observability
davila7
Open-source AI observability platform for LLM tracing, evaluation, and monitoring. Use when debugging LLM applications with detailed traces, running evaluations on datasets, or monitoring production AI systems with real-time insights.
mlops-observability
fmind
Guide to implement full stack observability including reproducibility, lineage, monitoring, alerting, and explainability.
trulens-instrumentation
truera
Instrument LLM apps with TruLens OTEL-based tracing - from setup to debugging and optimization