azure-monitor-opentelemetry-exporter-py – skill DevOps & Hạ tầng cho agent AI
Azure Monitor OpenTelemetry Exporter cho Python. Dùng để xuất OpenTelemetry ở mức thấp sang Application Insights.
Cài skill azure-monitor-opentelemetry-exporter-py bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-monitor-opentelemetry-exporter-py-ac74b.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /azure-monitor-opentelemetry-exporter-py – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-monitor-opentelemetry-exporter-py-ac74b.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $azure-monitor-opentelemetry-exporter-py – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-monitor-opentelemetry-exporter-py-ac74b.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /azure-monitor-opentelemetry-exporter-py – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/azure-monitor-opentelemetry-exporter-py-ac74b.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /azure-monitor-opentelemetry-exporter-py – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Azure Monitor OpenTelemetry Exporter for Python
Low-level exporter for sending OpenTelemetry traces, metrics, and logs to Application Insights.
Installation
pip install azure-monitor-opentelemetry-exporterEnvironment Variables
export 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) |
Export and privacy boundary
Telemetry leaves the application for Azure and may also persist locally in offline storage. Review fields, endpoints, credentials, retention and cost; redact secrets and personal data before export. Reuse an existing provider instead of repeatedly resetting global providers, and flush/shut down providers during process termination. The independent snippets below are alternatives, not a single combined initialization script.
Trace Exporter
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
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
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:
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
# Connection string from environment
exporter = AzureMonitorTraceExporter()Azure AD Authentication
from azure.identity import DefaultAzureCredential
from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter
exporter = AzureMonitorTraceExporter(
credential=DefaultAzureCredential()
)Sampling
Use ApplicationInsightsSampler for consistent sampling:
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:
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
exporter = AzureMonitorTraceExporter(
connection_string="...",
disable_offline_storage=True # Disable disk persistence; transport retry behavior is separate
)Sovereign Clouds
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
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Skill liên quan
- azure-monitor-opentelemetry-py – Azure Monitor OpenTelemetry Distro cho Python. Dùng để thiết lập Application Insights…
- azure-monitor-opentelemetry-ts – Tự động instrument ứng dụng Node.js với distributed tracing, metrics và logs.
- azure-monitor-query-java – SDK Azure Monitor Query cho Java. Thực thi truy vấn Kusto trên Log Analytics workspace…
- azure-monitor-query-py – SDK Azure Monitor Query cho Python. Dùng để truy vấn Log Analytics workspace và metric…
- azure-networking – Cấu hình Azure VNet, NSG và Azure Firewall. Triển khai mô hình hub-spoke và private…
- azure-resource-manager-cosmosdb-dotnet – SDK Azure Resource Manager cho Cosmos DB trên .NET.
- azure-resource-manager-durabletask-dotnet – SDK Azure Resource Manager cho Durable Task Scheduler trên .NET.
- azure-resource-manager-mysql-dotnet – SDK Azure MySQL Flexible Server cho .NET. Quản lý cơ sở dữ liệu cho các triển khai MySQL…