azure-monitor-opentelemetry-exporter-py
Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights.
About this skill
This skill provides a low-level OpenTelemetry exporter specifically for Python applications, allowing them to send detailed telemetry data—including traces, metrics, and logs—directly to Azure Application Insights. It grants developers and AI agents fine-grained control over their telemetry pipeline, making it ideal for custom instrumentation scenarios where the standard auto-instrumentation provided by the Azure Monitor OpenTelemetry Distro might not be sufficient or desired. By leveraging this exporter, AI agents can programmatically configure precise monitoring for Python services, ensuring critical operational data is captured and made available for analysis within Azure Monitor.
Best use case
Setting up custom, low-level monitoring for Python applications. Integrating specific Python services with Azure Application Insights for deep observability. Empowering AI agents to instrument user applications or their own components with OpenTelemetry for comprehensive performance and health tracking.
Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights.
Successfully configured Python applications will stream OpenTelemetry traces, metrics, and logs to the specified Azure Application Insights instance. This data will be available for visualization, analysis, and alerting in Azure Monitor, providing deep insights into application performance and behavior.
Practical example
Example input
Set up low-level OpenTelemetry export for a Python service named 'my-api' to Azure Application Insights. Use the connection string `InstrumentationKey=YOUR_KEY;IngestionEndpoint=https://YOUR_ENDPOINT` for configuration. Ensure traces, metrics, and logs are captured.
Example output
OpenTelemetry exporter for 'my-api' successfully configured to send traces, metrics, and logs to Azure Application Insights. Verify data flow in your Azure Monitor workspace under the specified connection string. Here is a basic Python configuration snippet to achieve this:
```python
import os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Ensure the connection string is set via environment variable or directly
# os.environ['APPLICATIONINSIGHTS_CONNECTION_STRING'] = 'InstrumentationKey=YOUR_KEY;IngestionEndpoint=https://YOUR_ENDPOINT'
# Configure trace provider
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(
SimpleSpanProcessor(AzureMonitorTraceExporter())
)
trace.set_tracer_provider(tracer_provider)
# Example of using the tracer
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span('example-operation'):
print('Performing some tracked operation...')
```When to use this skill
- When a Python application requires a custom OpenTelemetry pipeline.
- For scenarios demanding granular control over the telemetry data sent to Azure Application Insights.
- When integrating complex or specialized Python services where auto-instrumentation is not ideal or sufficient.
- When an AI agent needs to configure a precise, programmatic approach to application monitoring.
When not to use this skill
- For quick setup or automatic instrumentation; the `azure-monitor-opentelemetry` distro is generally recommended for such cases.
- When working with languages other than Python.
- If the target monitoring system is not Azure Application Insights.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How azure-monitor-opentelemetry-exporter-py Compares
| Feature / Agent | azure-monitor-opentelemetry-exporter-py | Standard Approach |
|---|---|---|
| Platform Support | Claude | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | easy | N/A |
Frequently Asked Questions
What does this skill do?
Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights.
Which AI agents support this skill?
This skill is designed for Claude.
How difficult is it to install?
The installation complexity is rated as easy. You can find the installation instructions above.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
AI Agent for Product Research
Browse AI agent skills for product research, competitive analysis, customer discovery, and structured product decision support.
SKILL.md Source
# Azure Monitor OpenTelemetry Exporter for Python
Low-level exporter for sending OpenTelemetry traces, metrics, and logs to Application Insights.
## Installation
```bash
pip install azure-monitor-opentelemetry-exporter
```
## Environment Variables
```bash
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/
```
## 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
```python
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Create exporter
exporter = AzureMonitorTraceExporter(
connection_string="InstrumentationKey=xxx;..."
)
# 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
```python
from opentelemetry import metrics
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter
# Create exporter
exporter = AzureMonitorMetricExporter(
connection_string="InstrumentationKey=xxx;..."
)
# 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
```python
import logging
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
# Create exporter
exporter = AzureMonitorLogExporter(
connection_string="InstrumentationKey=xxx;..."
)
# 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:
```python
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Connection string from environment
exporter = AzureMonitorTraceExporter()
```
## Azure AD Authentication
```python
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential()
)
```
## Sampling
Use `ApplicationInsightsSampler` for consistent sampling:
```python
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:
```python
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
connection_string="...",
storage_directory="/path/to/storage", # Custom storage path
disable_offline_storage=False # Enable retry (default)
)
```
## Disable Offline Storage
```python
exporter = AzureMonitorTraceExporter(
connection_string="...",
disable_offline_storage=True # No retry on failure
)
```
## Sovereign Clouds
```python
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
1. **Use BatchSpanProcessor** for production (not SimpleSpanProcessor)
2. **Use ApplicationInsightsSampler** for consistent sampling across services
3. **Enable offline storage** for reliability in production
4. **Use AAD authentication** instead of instrumentation keys
5. **Set export intervals** appropriate for your workload
6. **Use the distro** (`azure-monitor-opentelemetry`) unless you need custom pipelinesRelated Skills
azure-monitor-opentelemetry-py
Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation.
azure-monitor-ingestion-py
Azure Monitor Ingestion SDK for Python. Use for sending custom logs to Log Analytics workspace via Logs Ingestion API.
manifest
Install and configure the Manifest observability plugin for your agents. Use when setting up telemetry, configuring API keys, or troubleshooting the plugin.
grafana-dashboards
Create and manage production-ready Grafana dashboards for comprehensive system observability.
distributed-tracing
Implement distributed tracing with Jaeger and Tempo for request flow visibility across microservices.
microsoft-azure-webjobs-extensions-authentication-events-dotnet
Microsoft Entra Authentication Events SDK for .NET. Azure Functions triggers for custom authentication extensions.
claude-monitor
Monitor de performance do Claude Code e sistema local. Diagnostica lentidao, mede CPU/RAM/disco, verifica API latency e gera relatorios de saude do sistema.
azure-web-pubsub-ts
Real-time messaging with WebSocket connections and pub/sub patterns.
azure-storage-queue-ts
Azure Queue Storage JavaScript/TypeScript SDK (@azure/storage-queue) for message queue operations. Use for sending, receiving, peeking, and deleting messages in queues.
azure-storage-queue-py
Azure Queue Storage SDK for Python. Use for reliable message queuing, task distribution, and asynchronous processing.
azure-storage-file-share-ts
Azure File Share JavaScript/TypeScript SDK (@azure/storage-file-share) for SMB file share operations.
azure-storage-file-share-py
Azure Storage File Share SDK for Python. Use for SMB file shares, directories, and file operations in the cloud.