Getting started
現在サポートされている環境
- LTS版の Node.js
- Safari、Chrome、Edge、Firefox の最新バージョン。
詳細はsupportポリシーをご覧ください。
前提 条件
テレメトリ データを生成するには、OpenTelemetry SDK を構成する必要があります。 OpenTelemetryの設定はこのREADMEの範囲外ですが、OpenTelemetryの利用をget startedご検討いただくためにOpenTelemetryのドキュメントをご確認ください。
@azure/opentelemetry-instrumentation-azure-sdkパッケージをインストールしてください
npmでAzure OpenTelemetry Instrumentationクライアントライブラリをインストールしてください:
npm install @azure/opentelemetry-instrumentation-azure-sdk
ブラウザーのサポート
JavaScript バンドル
ブラウザーでこのクライアント ライブラリを使用するには、まず、バンドルを使用する必要があります。 そのto doの詳細については、当社のバンドリングドキュメントをご参照ください。
主な概念
- createAzureSdkInstrumentation関数は、このライブラリがエクスポートする主なフックであり、OpenTelemetryに登録するAzure SDKインストゥルメンテーションオブジェクトを作成する方法を提供します。
例
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";
import { trace, context } from "@opentelemetry/api";
// 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 = trace.getTracer("my-tracer");
const span = tracer.startSpan("main");
const ctx = trace.setSpan(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に設定します。 あるいは、実行時に@azure/loggerでsetLogLevelを呼び出すことでログログを有効にすることもできます:
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
ログを有効にする方法の詳細については、@azure/logger パッケージドキュメントを参照してください。
ES モジュールのインストルメンテーション
このパッケージは @opentelemetry/計装機器 を活用して必要なフックとローダーを設置します。 ESMパッケージのトレーシング設定については、@opentelemetry/instrumentationのREADMEを参照してください。
貢献
このライブラリに貢献したい場合は、コードのビルドやテスト方法について詳しく知るために、contributing guideをお読みください。
関連プロジェクト
Azure SDK for JavaScript