Python용 Azure Core 추적 OpenTelemetry 클라이언트 라이브러리 - 버전 1.0.0b9

시작

패키지 설치

pip를 사용하여 Python용 opentelemetry Python을 설치합니다.

pip install azure-core-tracing-opentelemetry

이제 azure-core 추적과 호환되는 모든 SDK에서 평소와 같이 Python용 opentelemetry를 사용할 수 있습니다. 여기에는 (전체 목록이 아님), azure-storage-blob, azure-keyvault-secrets, azure-eventhub 등이 포함됩니다.

주요 개념

  • 컨텍스트를 전달할 필요가 없습니다. SDK에서 해당 컨텍스트를 가져올 수 있습니다.

  • 이러한 줄은 추적을 사용하도록 설정하는 데 필요한 유일한 줄입니다.

      from azure.core.settings import settings
      from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
      settings.tracing_implementation = OpenTelemetrySpan
    

예제

전달할 명시적 컨텍스트가 없으며, 일반적인 opentelemetry 추적기를 만들고 azure-core 추적과 호환되는 모든 SDK 코드를 호출하기만 하면 됩니다. Azure Monitor 내보내기를 사용하는 예제이지만 모든 내보내기(Zipkin 등)를 사용할 수 있습니다.


# Declare OpenTelemetry as enabled tracing plugin for Azure SDKs
from azure.core.settings import settings
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan

settings.tracing_implementation = OpenTelemetrySpan

# In the below example, we use a simple console exporter, uncomment these lines to use
# the Azure Monitor Exporter.
# Example of Azure Monitor exporter, but you can use anything OpenTelemetry supports
# from azure_monitor import AzureMonitorSpanExporter
# exporter = AzureMonitorSpanExporter(
#     instrumentation_key="uuid of the instrumentation key (see your Azure Monitor account)"
# )

# Regular open telemetry usage from here, see https://github.com/open-telemetry/opentelemetry-python
# for details
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import ConsoleSpanExporter
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

# Simple console exporter
exporter = ConsoleSpanExporter()

trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(exporter)
)

# Example with Storage SDKs

from azure.storage.blob import BlobServiceClient

with tracer.start_as_current_span(name="MyApplication"):
    client = BlobServiceClient.from_connection_string('connectionstring')
    client.create_container('mycontainer')  # Call will be traced

Azure Exporter는 패키지에서 찾을 수 있습니다.opentelemetry-azure-monitor-exporter

문제 해결

이 클라이언트는 Azure Core에 정의된 예외를 발생합니다.

다음 단계

OpenTelemetry 구성에 대한 자세한 설명서는 OpenTelemetry 웹 사이트에서 찾을 수 있습니다.

참여

이 프로젝트에 대한 기여와 제안을 환영합니다. 대부분의 경우 기여하려면 권한을 부여하며 실제로 기여를 사용할 권한을 당사에 부여한다고 선언하는 CLA(기여자 라이선스 계약)에 동의해야 합니다. 자세한 내용은 https://cla.microsoft.com 을 참조하세요.

끌어오기 요청을 제출하면 CLA-bot은 CLA를 제공하고 PR을 적절하게 데코레이팅해야 하는지 여부를 자동으로 결정합니다(예: 레이블, 설명). 봇에서 제공하는 지침을 따르기만 하면 됩니다. 이 작업은 CLA를 사용하여 모든 리포지토리에서 한 번만 수행하면 됩니다.

이 프로젝트에는 Microsoft Open Source Code of Conduct(Microsoft 오픈 소스 준수 사항)가 적용됩니다. 자세한 내용은 Code of Conduct FAQ(규정 FAQ)를 참조하세요. 또는 추가 질문이나 의견은 opencode@microsoft.com으로 문의하세요.