通過Go Agent 接入應用監控的應用,可通過OTel SDK在代碼中擷取TraceId,SpanId。
操作步驟
在應用設定的探針開關設定中開啟opentelemetry開關。
添加代碼塊。
package main import ( "context" "go.opentelemetry.io/otel/trace" ) func GetTraceIdAndSpanId() (string, string) { span := trace.SpanFromContext(context.Background()) return span.SpanContext().TraceID().String(), span.SpanContext().SpanID().String() }