[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-6158a911-9687-44e2-a92d-06fe1f954e91":3,"$fHiME4hl0fM7SlSGAWmgKJEeyApa1AOeU7agUPNUaZS8":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"6158a911-9687-44e2-a92d-06fe1f954e91","azure-monitor-opentelemetry-py","Azure Monitor OpenTelemetry Distro for Python。用于一行式 Application Insights 设置，自动检测。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-monitor-opentelemetry-py\ndescription: Azure Monitor OpenTelemetry Distro for Python. Use for one-line Application Insights setup with auto-instrumentation.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure Monitor OpenTelemetry Distro for Python\n\nOne-line setup for Application Insights with OpenTelemetry auto-instrumentation.\n\n## Installation\n\n```bash\npip install azure-monitor-opentelemetry\n```\n\n## Environment Variables\n\n```bash\nAPPLICATIONINSIGHTS_CONNECTION_STRING=InstrumentationKey=xxx;IngestionEndpoint=https:\u002F\u002Fxxx.in.applicationinsights.azure.com\u002F\n```\n\n## Quick Start\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\n# One-line setup - reads connection string from environment\nconfigure_azure_monitor()\n\n# Your application code...\n```\n\n## Explicit Configuration\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor(\n    connection_string=\"InstrumentationKey=xxx;IngestionEndpoint=https:\u002F\u002Fxxx.in.applicationinsights.azure.com\u002F\"\n)\n```\n\n## With Flask\n\n```python\nfrom flask import Flask\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\napp = Flask(__name__)\n\n@app.route(\"\u002F\")\ndef hello():\n    return \"Hello, World!\"\n\nif __name__ == \"__main__\":\n    app.run()\n```\n\n## With Django\n\n```python\n# settings.py\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\n# Django settings...\n```\n\n## With FastAPI\n\n```python\nfrom fastapi import FastAPI\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\napp = FastAPI()\n\n@app.get(\"\u002F\")\nasync def root():\n    return {\"message\": \"Hello World\"}\n```\n\n## Custom Traces\n\n```python\nfrom opentelemetry import trace\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\ntracer = trace.get_tracer(__name__)\n\nwith tracer.start_as_current_span(\"my-operation\") as span:\n    span.set_attribute(\"custom.attribute\", \"value\")\n    # Do work...\n```\n\n## Custom Metrics\n\n```python\nfrom opentelemetry import metrics\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\nmeter = metrics.get_meter(__name__)\ncounter = meter.create_counter(\"my_counter\")\n\ncounter.add(1, {\"dimension\": \"value\"})\n```\n\n## Custom Logs\n\n```python\nimport logging\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor()\n\nlogger = logging.getLogger(__name__)\nlogger.setLevel(logging.INFO)\n\nlogger.info(\"This will appear in Application Insights\")\nlogger.error(\"Errors are captured too\", exc_info=True)\n```\n\n## Sampling\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\n# Sample 10% of requests\nconfigure_azure_monitor(\n    sampling_ratio=0.1\n)\n```\n\n## Cloud Role Name\n\nSet cloud role name for Application Map:\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\nfrom opentelemetry.sdk.resources import Resource, SERVICE_NAME\n\nconfigure_azure_monitor(\n    resource=Resource.create({SERVICE_NAME: \"my-service-name\"})\n)\n```\n\n## Disable Specific Instrumentations\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor(\n    instrumentations=[\"flask\", \"requests\"]  # Only enable these\n)\n```\n\n## Enable Live Metrics\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor(\n    enable_live_metrics=True\n)\n```\n\n## Azure AD Authentication\n\n```python\nfrom azure.monitor.opentelemetry import configure_azure_monitor\nfrom azure.identity import DefaultAzureCredential\n\nconfigure_azure_monitor(\n    credential=DefaultAzureCredential()\n)\n```\n\n## Auto-Instrumentations Included\n\n| Library | Telemetry Type |\n|---------|---------------|\n| Flask | Traces |\n| Django | Traces |\n| FastAPI | Traces |\n| Requests | Traces |\n| urllib3 | Traces |\n| httpx | Traces |\n| aiohttp | Traces |\n| psycopg2 | Traces |\n| pymysql | Traces |\n| pymongo | Traces |\n| redis | Traces |\n\n## Configuration Options\n\n| Parameter | Description | Default |\n|-----------|-------------|---------|\n| `connection_string` | Application Insights connection string | From env var |\n| `credential` | Azure credential for AAD auth | None |\n| `sampling_ratio` | Sampling rate (0.0 to 1.0) | 1.0 |\n| `resource` | OpenTelemetry Resource | Auto-detected |\n| `instrumentations` | List of instrumentations to enable | All |\n| `enable_live_metrics` | Enable Live Metrics stream | False |\n\n## Best Practices\n\n1. **Call configure_azure_monitor() early** — Before importing instrumented libraries\n2. **Use environment variables** for connection string in production\n3. **Set cloud role name** for multi-service applications\n4. **Enable sampling** in high-traffic applications\n5. **Use structured logging** for better log analytics queries\n6. **Add custom attributes** to spans for better debugging\n7. **Use AAD authentication** for production workloads\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,176,1518,"2026-05-16 13:07:16",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"c3e15d0b-bfed-4758-be35-50dd9a54bcbf","1.0.0","azure-monitor-opentelemetry-py.zip",1935,"uploads\u002Fskills\u002F6158a911-9687-44e2-a92d-06fe1f954e91\u002Fazure-monitor-opentelemetry-py.zip","cc68f1e7aeb32da8fae01d0c03d0853a951d76aa274fef3038b67cafd0ea0912","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":5380}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]