azure-monitor-opentelemetry-exporter-py

Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights.

31,392 stars
Complexity: easy

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

$curl -o ~/.claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.md --create-dirs "https://raw.githubusercontent.com/sickn33/antigravity-awesome-skills/main/plugins/antigravity-awesome-skills-claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How azure-monitor-opentelemetry-exporter-py Compares

Feature / Agentazure-monitor-opentelemetry-exporter-pyStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/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

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 pipelines

Related Skills

azure-monitor-opentelemetry-py

31392
from sickn33/antigravity-awesome-skills

Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation.

Observability & MonitoringClaude

azure-monitor-ingestion-py

31392
from sickn33/antigravity-awesome-skills

Azure Monitor Ingestion SDK for Python. Use for sending custom logs to Log Analytics workspace via Logs Ingestion API.

Observability & MonitoringClaude

manifest

31392
from sickn33/antigravity-awesome-skills

Install and configure the Manifest observability plugin for your agents. Use when setting up telemetry, configuring API keys, or troubleshooting the plugin.

Observability & MonitoringClaude

grafana-dashboards

31392
from sickn33/antigravity-awesome-skills

Create and manage production-ready Grafana dashboards for comprehensive system observability.

Observability & MonitoringClaude

distributed-tracing

31392
from sickn33/antigravity-awesome-skills

Implement distributed tracing with Jaeger and Tempo for request flow visibility across microservices.

Observability & MonitoringClaude

microsoft-azure-webjobs-extensions-authentication-events-dotnet

31392
from sickn33/antigravity-awesome-skills

Microsoft Entra Authentication Events SDK for .NET. Azure Functions triggers for custom authentication extensions.

Identity Management / Authentication & AuthorizationClaude

claude-monitor

31392
from sickn33/antigravity-awesome-skills

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.

Monitoring & DiagnosticsClaudeCursorGemini

azure-web-pubsub-ts

31392
from sickn33/antigravity-awesome-skills

Real-time messaging with WebSocket connections and pub/sub patterns.

Messaging & CommunicationClaude

azure-storage-queue-ts

31392
from sickn33/antigravity-awesome-skills

Azure Queue Storage JavaScript/TypeScript SDK (@azure/storage-queue) for message queue operations. Use for sending, receiving, peeking, and deleting messages in queues.

Cloud IntegrationClaude

azure-storage-queue-py

31392
from sickn33/antigravity-awesome-skills

Azure Queue Storage SDK for Python. Use for reliable message queuing, task distribution, and asynchronous processing.

Cloud IntegrationClaude

azure-storage-file-share-ts

31392
from sickn33/antigravity-awesome-skills

Azure File Share JavaScript/TypeScript SDK (@azure/storage-file-share) for SMB file share operations.

Cloud Storage ManagementClaude

azure-storage-file-share-py

31392
from sickn33/antigravity-awesome-skills

Azure Storage File Share SDK for Python. Use for SMB file shares, directories, and file operations in the cloud.

Cloud Storage ManagementClaude