mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
26 lines
431 B
Go
26 lines
431 B
Go
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 ""
|
|
}
|