Closed17

Next.jsとOpenTelemetry

君津君津

トレースについて

APIはTracerProvider→Tracer→Spanの三層構造
TracerProviderは共通の設定やTracerの生成、TracerはSpanの生成を行う
TracerProviderにはNodeTracerProviderとWebTracerProviderがある

君津君津

TraceExporter
トレースの出力方法を指定する
JSではデバッグ用のConsoleTraceExporter, テスト用のInMemoryTraceExporter, アプリケーション用のOTLPTraceExporterがある
Exporterについてはメトリクス、ログも同様

SpanProcessor
トレースの出力タイミングを指定する
JSには即座に出力するSimpleSpanProcessor, バッチ処理するBatchSpanProcessorがある
Simple〜はデバッグ、テスト用、Batch〜はアプリ用
Processorについてはログも同様

ContextManager
OTelのコンテキストは異なるサービス間で情報をやりとりする仕組み
利用にはContextManagerが必要
ブラウザJSではZoneContextManagerとStackContextManagerがあり、非同期処理をトレースするにはZoneContextManagerが必要
Node.jsにはAsyncHooksContextManagerとAsyncLocalStorageContextManagerがあり、パフォーマンス、メモリ安全性、既知の不具合からAsyncLocalStorageContextManagerの方が良さそう

Propagator
異なるサービス間でコンテキストを伝播させる
JSにはW3CTraceContextPropagator、W3CBaggagePropagatorがある
トレースの場合はW3CTraceContextPropagatorを使う?

WebTracerProviderの設定は最終的にこうなった
https://github.com/YunosukeY/next-otel-sample/blob/main/src/otel/web/webTracer.ts#L13-L21

このスクラップは2ヶ月前にクローズされました