feat: add trace.SpanIDFromContext and trace.TraceIDFromContext (#2654)

This commit is contained in:
Kevin Wan
2022-12-02 11:00:44 +08:00
committed by GitHub
parent 10fd9131a1
commit 9941055eaa
4 changed files with 68 additions and 21 deletions

25
internal/trace/trace.go Normal file
View File

@@ -0,0 +1,25 @@
package trace
import (
"context"
"go.opentelemetry.io/otel/trace"
)
func SpanIDFromContext(ctx context.Context) string {
spanCtx := trace.SpanContextFromContext(ctx)
if spanCtx.HasSpanID() {
return spanCtx.SpanID().String()
}
return ""
}
func TraceIDFromContext(ctx context.Context) string {
spanCtx := trace.SpanContextFromContext(ctx)
if spanCtx.HasTraceID() {
return spanCtx.TraceID().String()
}
return ""
}