|
Add this skill
npx mdskills install sickn33/azure-monitor-opentelemetry-pyReference docs for a Python library, but lacks agent trigger conditions and step-by-step instructions
1---2name: azure-monitor-opentelemetry-py3description: |4 Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation.5 Triggers: "azure-monitor-opentelemetry", "configure_azure_monitor", "Application Insights", "OpenTelemetry distro", "auto-instrumentation".6package: azure-monitor-opentelemetry7---89# Azure Monitor OpenTelemetry Distro for Python1011One-line setup for Application Insights with OpenTelemetry auto-instrumentation.1213## Installation1415```bash16pip install azure-monitor-opentelemetry17```1819## Environment Variables2021```bash22APPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/23```2425## Quick Start2627```python28from azure.monitor.opentelemetry import configure_azure_monitor2930# One-line setup - reads connection string from environment31configure_azure_monitor()3233# Your application code...34```3536## Explicit Configuration3738```python39from azure.monitor.opentelemetry import configure_azure_monitor4041configure_azure_monitor(42 connection_string="InstrumentationKey=xxx;IngestionEndpoint=https://xxx.in.applicationinsights.azure.com/"43)44```4546## With Flask4748```python49from flask import Flask50from azure.monitor.opentelemetry import configure_azure_monitor5152configure_azure_monitor()5354app = Flask(__name__)5556@app.route("/")57def hello():58 return "Hello, World!"5960if __name__ == "__main__":61 app.run()62```6364## With Django6566```python67# settings.py68from azure.monitor.opentelemetry import configure_azure_monitor6970configure_azure_monitor()7172# Django settings...73```7475## With FastAPI7677```python78from fastapi import FastAPI79from azure.monitor.opentelemetry import configure_azure_monitor8081configure_azure_monitor()8283app = FastAPI()8485@app.get("/")86async def root():87 return {"message": "Hello World"}88```8990## Custom Traces9192```python93from opentelemetry import trace94from azure.monitor.opentelemetry import configure_azure_monitor9596configure_azure_monitor()9798tracer = trace.get_tracer(__name__)99100with tracer.start_as_current_span("my-operation") as span:101 span.set_attribute("custom.attribute", "value")102 # Do work...103```104105## Custom Metrics106107```python108from opentelemetry import metrics109from azure.monitor.opentelemetry import configure_azure_monitor110111configure_azure_monitor()112113meter = metrics.get_meter(__name__)114counter = meter.create_counter("my_counter")115116counter.add(1, {"dimension": "value"})117```118119## Custom Logs120121```python122import logging123from azure.monitor.opentelemetry import configure_azure_monitor124125configure_azure_monitor()126127logger = logging.getLogger(__name__)128logger.setLevel(logging.INFO)129130logger.info("This will appear in Application Insights")131logger.error("Errors are captured too", exc_info=True)132```133134## Sampling135136```python137from azure.monitor.opentelemetry import configure_azure_monitor138139# Sample 10% of requests140configure_azure_monitor(141 sampling_ratio=0.1142)143```144145## Cloud Role Name146147Set cloud role name for Application Map:148149```python150from azure.monitor.opentelemetry import configure_azure_monitor151from opentelemetry.sdk.resources import Resource, SERVICE_NAME152153configure_azure_monitor(154 resource=Resource.create({SERVICE_NAME: "my-service-name"})155)156```157158## Disable Specific Instrumentations159160```python161from azure.monitor.opentelemetry import configure_azure_monitor162163configure_azure_monitor(164 instrumentations=["flask", "requests"] # Only enable these165)166```167168## Enable Live Metrics169170```python171from azure.monitor.opentelemetry import configure_azure_monitor172173configure_azure_monitor(174 enable_live_metrics=True175)176```177178## Azure AD Authentication179180```python181from azure.monitor.opentelemetry import configure_azure_monitor182from azure.identity import DefaultAzureCredential183184configure_azure_monitor(185 credential=DefaultAzureCredential()186)187```188189## Auto-Instrumentations Included190191| Library | Telemetry Type |192|---------|---------------|193| Flask | Traces |194| Django | Traces |195| FastAPI | Traces |196| Requests | Traces |197| urllib3 | Traces |198| httpx | Traces |199| aiohttp | Traces |200| psycopg2 | Traces |201| pymysql | Traces |202| pymongo | Traces |203| redis | Traces |204205## Configuration Options206207| Parameter | Description | Default |208|-----------|-------------|---------|209| `connection_string` | Application Insights connection string | From env var |210| `credential` | Azure credential for AAD auth | None |211| `sampling_ratio` | Sampling rate (0.0 to 1.0) | 1.0 |212| `resource` | OpenTelemetry Resource | Auto-detected |213| `instrumentations` | List of instrumentations to enable | All |214| `enable_live_metrics` | Enable Live Metrics stream | False |215216## Best Practices2172181. **Call configure_azure_monitor() early** — Before importing instrumented libraries2192. **Use environment variables** for connection string in production2203. **Set cloud role name** for multi-service applications2214. **Enable sampling** in high-traffic applications2225. **Use structured logging** for better log analytics queries2236. **Add custom attributes** to spans for better debugging2247. **Use AAD authentication** for production workloads225
Full transparency — inspect the skill content before installing.