Chuyển đến nội dung
Skillpedia
Học máy48k · #3966

azure-monitor-opentelemetry-exporter-py

Skill này làm gì

Đoạn mã này gửi thông tin về hoạt động của chương trình (như truy vết, số liệu và nhật ký) đến Azure Application Insights. Nó giúp bạn thấy điều gì đang diễn ra bên trong ứng dụng.

Khi nào nên dùng

  • ✓Khi bạn muốn gửi dữ liệu truy vết từ mã của mình lên Azure.
  • ✓Khi bạn cần giám sát hiệu suất ứng dụng bằng số liệu tùy chỉnh.
  • ✓Khi bạn muốn ghi lại các sự kiện quan trọng của chương trình để phân tích sau.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/azure-monitor-opentelemetry-exporter-py/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Gửi dữ liệu truy vết của ứng dụng Python của tôi đến Application Insights bằng chuỗi kết nối.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ hoạt động bằng cách thiết lập một “exporter” biết cách giao tiếp với Azure Application Insights. Exporter này được kết nối với hệ thống truy vết, số liệu hoặc nhật ký của chương trình, nhờ đó dữ liệu được gửi tự động.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết 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-exporter

Environment Variables

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)

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  # No retry on failure
)

Sovereign Clouds

from azure.identity import AzureAuthorityHosts, DefaultAzureCredential

…
Câu hỏi thường gặp

“Truy vết” (traces), “số liệu” (metrics) và “nhật ký” (logs) là gì?

Truy vết cho thấy đường đi của một yêu cầu qua chương trình. Số liệu là các con số đo hiệu suất, như thời gian phản hồi. Nhật ký là các thông báo văn bản mô tả sự kiện hoặc lỗi.

OpenTelemetry là gì?

Đây là chuẩn thu thập và gửi dữ liệu đo lường (truy vết, số liệu, nhật ký) theo cách thống nhất, cho phép dùng nhiều công cụ giám sát khác nhau.

Khác biệt giữa “distro” và “exporter” là gì?

“Distro” dễ dùng hơn cho thiết lập nhanh và tự động. “Exporter” (công cụ này) cho bạn quyền kiểm soát cao hơn để xây dựng hệ thống giám sát tùy chỉnh.

Chi tiết

Mô tả gốc của tác giả

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

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#3966
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự