azure-monitor-opentelemetry-py

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

31,392 stars
Complexity: easy

About this skill

The `azure-monitor-opentelemetry-py` skill provides a simplified, one-line setup for integrating OpenTelemetry-based monitoring into Python applications, pushing telemetry data to Azure Application Insights. It leverages the Azure Monitor OpenTelemetry Distro for Python to automatically instrument your application, capturing requests, dependencies, logs, and metrics. This skill significantly reduces the effort required to configure comprehensive application performance monitoring (APM) and distributed tracing within the Azure ecosystem, allowing AI agents to quickly enable robust observability for Python services.

Best use case

Quickly enable application performance monitoring (APM) for Python applications. Automatically collect telemetry data (requests, dependencies, logs, metrics) for analysis in Azure Application Insights. Implement distributed tracing for complex microservices architectures. Gain insights into application health, performance bottlenecks, and user behavior.

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

The Python application will automatically send telemetry data (traces, metrics, logs) to the configured Azure Application Insights instance. Developers and operations teams will gain real-time visibility into application performance, errors, and dependencies. Distributed tracing will be enabled, allowing end-to-end transaction flow analysis for complex requests.

Practical example

Example input

Set up Azure Application Insights monitoring for my Python web application. I need to enable auto-instrumentation for my Python service and send data to my Azure Monitor instance.

Example output

```
To set up Azure Application Insights monitoring for your Python application with auto-instrumentation:

1.  **Install the necessary package:**
    ```bash
    pip install azure-monitor-opentelemetry
    ```

2.  **Set your Application Insights Connection String as an environment variable:**
    ```bash
    export APPLICATIONINSIGHTS_CONNECTION_STRING="InstrumentationKey=YOUR_INSTRUMENTATION_KEY;IngestionEndpoint=https://YOUR_ENDPOINT.in.applicationinsights.azure.com/"
    ```
    (Replace `YOUR_INSTRUMENTATION_KEY` and `YOUR_ENDPOINT` with your actual Azure Application Insights connection string.)

3.  **Add the following line to the entry point of your Python application (e.g., at the top of your main script or before your application starts):**
    ```python
    from azure.monitor.opentelemetry import configure_azure_monitor
    configure_azure_monitor()
    # Your existing application code follows
    ```

After these steps, your application will automatically start sending telemetry data to Azure Application Insights, providing insights into its performance and health.
```

When to use this skill

  • When deploying a new Python application to Azure and needing immediate observability. When existing Python applications lack comprehensive monitoring and you want to quickly add it. When an AI agent is tasked with instrumenting a Python service for APM. When needing to centralize telemetry data from Python services in Azure Application Insights using OpenTelemetry standards.

When not to use this skill

  • When monitoring non-Python applications (as this skill is Python-specific). When using a different APM solution or observability platform not integrated with Azure Application Insights. When manual, highly customized OpenTelemetry instrumentation is preferred over auto-instrumentation (though it can be used in conjunction). When the application doesn't run in an environment without access to Azure (e.g., on-premises without Azure connectivity or Azure Arc).

Installation

Claude Code / Cursor / Codex

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

Manual Installation

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

How azure-monitor-opentelemetry-py Compares

Feature / Agentazure-monitor-opentelemetry-pyStandard Approach
Platform SupportClaudeLimited / Varies
Context Awareness High Baseline
Installation ComplexityeasyN/A

Frequently Asked Questions

What does this skill do?

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

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 Distro for Python

One-line setup for Application Insights with OpenTelemetry auto-instrumentation.

## Installation

```bash
pip install azure-monitor-opentelemetry
```

## Environment Variables

```bash
APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/
```

## Quick Start

```python
from azure.monitor.opentelemetry import configure_azure_monitor

# One-line setup - reads connection string from environment
configure_azure_monitor()

# Your application code...
```

## Explicit Configuration

```python
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
    connection_string="InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/"
)
```

## With Flask

```python
from flask import Flask
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()
```

## With Django

```python
# settings.py
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

# Django settings...
```

## With FastAPI

```python
from fastapi import FastAPI
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}
```

## Custom Traces

```python
from opentelemetry import trace
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

tracer = trace.get_tracer(__name__)

with tracer.start_as_current_span("my-operation") as span:
    span.set_attribute("custom.attribute", "value")
    # Do work...
```

## Custom Metrics

```python
from opentelemetry import metrics
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

meter = metrics.get_meter(__name__)
counter = meter.create_counter("my_counter")

counter.add(1, {"dimension": "value"})
```

## Custom Logs

```python
import logging
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor()

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

logger.info("This will appear in Application Insights")
logger.error("Errors are captured too", exc_info=True)
```

## Sampling

```python
from azure.monitor.opentelemetry import configure_azure_monitor

# Sample 10% of requests
configure_azure_monitor(
    sampling_ratio=0.1
)
```

## Cloud Role Name

Set cloud role name for Application Map:

```python
from azure.monitor.opentelemetry import configure_azure_monitor
from opentelemetry.sdk.resources import Resource, SERVICE_NAME

configure_azure_monitor(
    resource=Resource.create({SERVICE_NAME: "my-service-name"})
)
```

## Disable Specific Instrumentations

```python
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
    instrumentations=["flask", "requests"]  # Only enable these
)
```

## Enable Live Metrics

```python
from azure.monitor.opentelemetry import configure_azure_monitor

configure_azure_monitor(
    enable_live_metrics=True
)
```

## Azure AD Authentication

```python
from azure.monitor.opentelemetry import configure_azure_monitor
from azure.identity import DefaultAzureCredential

configure_azure_monitor(
    credential=DefaultAzureCredential()
)
```

## Auto-Instrumentations Included

| Library | Telemetry Type |
|---------|---------------|
| Flask | Traces |
| Django | Traces |
| FastAPI | Traces |
| Requests | Traces |
| urllib3 | Traces |
| httpx | Traces |
| aiohttp | Traces |
| psycopg2 | Traces |
| pymysql | Traces |
| pymongo | Traces |
| redis | Traces |

## Configuration Options

| Parameter | Description | Default |
|-----------|-------------|---------|
| `connection_string` | Application Insights connection string | From env var |
| `credential` | Azure credential for AAD auth | None |
| `sampling_ratio` | Sampling rate (0.0 to 1.0) | 1.0 |
| `resource` | OpenTelemetry Resource | Auto-detected |
| `instrumentations` | List of instrumentations to enable | All |
| `enable_live_metrics` | Enable Live Metrics stream | False |

## Best Practices

1. **Call configure_azure_monitor() early** — Before importing instrumented libraries
2. **Use environment variables** for connection string in production
3. **Set cloud role name** for multi-service applications
4. **Enable sampling** in high-traffic applications
5. **Use structured logging** for better log analytics queries
6. **Add custom attributes** to spans for better debugging
7. **Use AAD authentication** for production workloads

## When to Use
This skill is applicable to execute the workflow or actions described in the overview.

Related Skills

azure-monitor-opentelemetry-exporter-py

31392
from sickn33/antigravity-awesome-skills

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

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