Slide 35
Slide 35 text
OpenTelemetry Trace のコンテキスト伝播
otelhttp のようなパッケージは、
ヘッダーの解析、スパンコンテキストへの設定を行ってくれる計装ライブラリ
github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/handler.go#L134
helloHandler := func(w http.ResponseWriter, req *http.Request) {
… // 何かしらの処理
_, _ = io.WriteString(w, "Hello, world!\n")
}
// otelhttp でラップ
// 計装 = ヘッダからトレース情報を抽出して、スパンコンテキストに設定
otelHandler := otelhttp.NewHandler(http.HandlerFunc(helloHandler), "Hello")
// サーバーの起動
http.Handle("/hello", otelHandler)
err = http.ListenAndServe(":8080", nil)
github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/example/server/server.go#L82-L97