JavaScript 用 Azure OpenTelemetry インストルメンテーション ライブラリ
はじめ
現在サポートされている環境
- Node.js の LTS バージョンを
する - Safari、Chrome、Edge、Firefox の最新バージョン。
詳細については、サポート ポリシーの を参照してください。
前提 条件
テレメトリ データを生成するには、OpenTelemetry SDK を構成する必要があります。 OpenTelemetry の構成は、この README の範囲外ですが、OpenTelemetry の使用を開始するために、OpenTelemetry のドキュメント を確認することをお勧めします。
@azure/opentelemetry-instrumentation-azure-sdk
パッケージをインストールする
npm
を使用して Azure OpenTelemetry Instrumentation クライアント ライブラリをインストールします。
npm install @azure/opentelemetry-instrumentation-azure-sdk
ブラウザーのサポート
JavaScript バンドル
ブラウザーでこのクライアント ライブラリを使用するには、まず、バンドルを使用する必要があります。 これを行う方法の詳細については、
主な概念
- createAzureSdkInstrumentation 関数は、OpenTelemetry に登録する Azure SDK Instrumentation オブジェクトを作成する方法を提供するこのライブラリによってエクスポートされるメイン フックです。
例
OpenTelemetry インストルメンテーションを有効にする
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
import { SimpleSpanProcessor, ConsoleSpanExporter } from "@opentelemetry/tracing";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { createAzureSdkInstrumentation } from "@azure/opentelemetry-instrumentation-azure-sdk";
import { KeyClient } from "@azure/keyvault-keys";
import { DefaultAzureCredential } from "@azure/identity";
// Set-up and configure a Node Tracer Provider using OpenTelemetry SDK.
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
registerInstrumentations({
instrumentations: [createAzureSdkInstrumentation()],
});
// Continue to import any Azure SDK client libraries after registering the instrumentation.
// import { KeyClient } from "@azure/keyvault-keys";
// import { DefaultAzureCredential } from "@azure/identity";
const keyClient = new KeyClient("https://my.keyvault.azure.net", new DefaultAzureCredential());
// Tracing is now enabled using automatic span propagation with an active context.
await keyClient.getKey("MyKeyName");
// If your scenario requires manual span propagation, all Azure client libraries
// support explicitly passing a parent context via an `options` parameter.
// Get a tracer from a registered provider, create a span, and get the current context.
const tracer = opentelemetry.trace.getTracer("my-tracer");
const span = tracer.startSpan("main");
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), span);
await keyClient.getKey("MyKeyName", {
tracingOptions: {
// ctx will be used as the parent context for all operations.
tracingContext: ctx,
},
});
トラブルシューティング
伐採
ログ記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、AZURE_LOG_LEVEL
環境変数を info
に設定します。 または、setLogLevel
で @azure/logger
を呼び出すことによって、実行時にログを有効にすることもできます。
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
ログを有効にする方法の詳細な手順については、@azure/logger パッケージのドキュメントを参照してください。
ES モジュールのインストルメンテーション
このパッケージでは、@opentelemetry/インストルメンテーション を使用して、必要なフックとローダーを設定します。 ESM パッケージのトレースを構成する手順については、@opentelemetry/インストルメンテーションの README を参照してください。
貢献
このライブラリに投稿する場合は、コードをビルドしてテストする方法の詳細については、投稿ガイド を参照してください。
関連プロジェクト
- Microsoft Azure SDK for Javascript の
Azure SDK for JavaScript