Python 用 Azure Core Tracing 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 Web サイトを参照してください

共同作成

このプロジェクトでは、共同作成と提案を歓迎しています。 ほとんどの共同作成では、共同作成者使用許諾契約書 (CLA) にご同意いただき、ご自身の共同作成内容を使用する権利を Microsoft に供与する権利をお持ちであり、かつ実際に供与することを宣言していただく必要があります。 詳細については、 https://cla.microsoft.com を参照してください。

pull request を送信すると、CLA を提供して PR (ラベル、コメントなど) を適宜装飾する必要があるかどうかを CLA ボットが自動的に決定します。 ボットによって提供される手順にそのまま従ってください。 この操作は、Microsoft の CLA を使用するすべてのリポジトリについて、1 回だけ行う必要があります。

このプロジェクトでは、Microsoft オープン ソースの倫理規定を採用しています。 詳しくは、「Code of Conduct FAQ (倫理規定についてよくある質問)」を参照するか、opencode@microsoft.com 宛てに質問またはコメントをお送りください。