[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-639bedf4-26ab-41af-9ba4-b426c5dd3576":3,"$fj_zkYtlJLaWgPAtQ04Xg0C4XC7v8vqU3oQYdxJD_umM":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},"639bedf4-26ab-41af-9ba4-b426c5dd3576","azure-monitor-opentelemetry-exporter-py","Azure Monitor OpenTelemetry 导出器 for Python。用于低级 OpenTelemetry 导出到 Application Insights。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-monitor-opentelemetry-exporter-py\ndescription: Azure Monitor OpenTelemetry Exporter for Python. Use for low-level OpenTelemetry export to Application Insights.\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n# Azure Monitor OpenTelemetry Exporter for Python\n\nLow-level exporter for sending OpenTelemetry traces, metrics, and logs to Application Insights.\n\n## Installation\n\n```bash\npip install azure-monitor-opentelemetry-exporter\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## When to Use\n| Scenario | Use |\n|----------|-----|\n| Quick setup, auto-instrumentation | `azure-monitor-opentelemetry` (distro) |\n| Custom OpenTelemetry pipeline | `azure-monitor-opentelemetry-exporter` (this) |\n| Fine-grained control over telemetry | `azure-monitor-opentelemetry-exporter` (this) |\n\n## Trace Exporter\n\n```python\nfrom opentelemetry import trace\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.export import BatchSpanProcessor\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n\n# Create exporter\nexporter = AzureMonitorTraceExporter(\n    connection_string=\"InstrumentationKey=xxx;...\"\n)\n\n# Configure tracer provider\ntrace.set_tracer_provider(TracerProvider())\ntrace.get_tracer_provider().add_span_processor(\n    BatchSpanProcessor(exporter)\n)\n\n# Use tracer\ntracer = trace.get_tracer(__name__)\nwith tracer.start_as_current_span(\"my-span\"):\n    print(\"Hello, World!\")\n```\n\n## Metric Exporter\n\n```python\nfrom opentelemetry import metrics\nfrom opentelemetry.sdk.metrics import MeterProvider\nfrom opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter\n\n# Create exporter\nexporter = AzureMonitorMetricExporter(\n    connection_string=\"InstrumentationKey=xxx;...\"\n)\n\n# Configure meter provider\nreader = PeriodicExportingMetricReader(exporter, export_interval_millis=60000)\nmetrics.set_meter_provider(MeterProvider(metric_readers=[reader]))\n\n# Use meter\nmeter = metrics.get_meter(__name__)\ncounter = meter.create_counter(\"requests_total\")\ncounter.add(1, {\"route\": \"\u002Fapi\u002Fusers\"})\n```\n\n## Log Exporter\n\n```python\nimport logging\nfrom opentelemetry._logs import set_logger_provider\nfrom opentelemetry.sdk._logs import LoggerProvider, LoggingHandler\nfrom opentelemetry.sdk._logs.export import BatchLogRecordProcessor\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorLogExporter\n\n# Create exporter\nexporter = AzureMonitorLogExporter(\n    connection_string=\"InstrumentationKey=xxx;...\"\n)\n\n# Configure logger provider\nlogger_provider = LoggerProvider()\nlogger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))\nset_logger_provider(logger_provider)\n\n# Add handler to Python logging\nhandler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider)\nlogging.getLogger().addHandler(handler)\n\n# Use logging\nlogger = logging.getLogger(__name__)\nlogger.info(\"This will be sent to Application Insights\")\n```\n\n## From Environment Variable\n\nExporters read `APPLICATIONINSIGHTS_CONNECTION_STRING` automatically:\n\n```python\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n\n# Connection string from environment\nexporter = AzureMonitorTraceExporter()\n```\n\n## Azure AD Authentication\n\n```python\nfrom azure.identity import DefaultAzureCredential\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n\nexporter = AzureMonitorTraceExporter(\n    credential=DefaultAzureCredential()\n)\n```\n\n## Sampling\n\nUse `ApplicationInsightsSampler` for consistent sampling:\n\n```python\nfrom opentelemetry.sdk.trace import TracerProvider\nfrom opentelemetry.sdk.trace.sampling import ParentBasedTraceIdRatio\nfrom azure.monitor.opentelemetry.exporter import ApplicationInsightsSampler\n\n# Sample 10% of traces\nsampler = ApplicationInsightsSampler(sampling_ratio=0.1)\n\ntrace.set_tracer_provider(TracerProvider(sampler=sampler))\n```\n\n## Offline Storage\n\nConfigure offline storage for retry:\n\n```python\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n\nexporter = AzureMonitorTraceExporter(\n    connection_string=\"...\",\n    storage_directory=\"\u002Fpath\u002Fto\u002Fstorage\",  # Custom storage path\n    disable_offline_storage=False  # Enable retry (default)\n)\n```\n\n## Disable Offline Storage\n\n```python\nexporter = AzureMonitorTraceExporter(\n    connection_string=\"...\",\n    disable_offline_storage=True  # No retry on failure\n)\n```\n\n## Sovereign Clouds\n\n```python\nfrom azure.identity import AzureAuthorityHosts, DefaultAzureCredential\nfrom azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter\n\n# Azure Government\ncredential = DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_GOVERNMENT)\nexporter = AzureMonitorTraceExporter(\n    connection_string=\"InstrumentationKey=xxx;IngestionEndpoint=https:\u002F\u002Fxxx.in.applicationinsights.azure.us\u002F\",\n    credential=credential\n)\n```\n\n## Exporter Types\n\n| Exporter | Telemetry Type | Application Insights Table |\n|----------|---------------|---------------------------|\n| `AzureMonitorTraceExporter` | Traces\u002FSpans | requests, dependencies, exceptions |\n| `AzureMonitorMetricExporter` | Metrics | customMetrics, performanceCounters |\n| `AzureMonitorLogExporter` | Logs | traces, customEvents |\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| `disable_offline_storage` | Disable retry storage | False |\n| `storage_directory` | Custom storage path | Temp directory |\n\n## Best Practices\n\n1. **Use BatchSpanProcessor** for production (not SimpleSpanProcessor)\n2. **Use ApplicationInsightsSampler** for consistent sampling across services\n3. **Enable offline storage** for reliability in production\n4. **Use AAD authentication** instead of instrumentation keys\n5. **Set export intervals** appropriate for your workload\n6. **Use the distro** (`azure-monitor-opentelemetry`) unless you need custom pipelines\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,149,900,"2026-05-16 13:07:15",{"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},"e2fc94d8-d67e-41b1-aee3-aac2ccb933e7","1.0.0","azure-monitor-opentelemetry-exporter-py.zip",2155,"uploads\u002Fskills\u002F639bedf4-26ab-41af-9ba4-b426c5dd3576\u002Fazure-monitor-opentelemetry-exporter-py.zip","db7b1012d7cee0e1a868f0a1527eb3bfa26defc857863963d7890ce4267136e8","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":6514}]",{"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]