mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
26 lines
554 B
Go
26 lines
554 B
Go
package tracing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/dskit/tracing"
|
|
"go.opentelemetry.io/otel/trace"
|
|
)
|
|
|
|
// ExtractTraceID extracts the trace id, if any from the context.
|
|
func ExtractTraceID(ctx context.Context) (string, bool) {
|
|
// Extract from OpenTracing Jaeger exporter
|
|
traceID, ok := tracing.ExtractTraceID(ctx)
|
|
if ok {
|
|
return traceID, true
|
|
}
|
|
|
|
// Extract from OpenTelemetry
|
|
otelSpan := trace.SpanFromContext(ctx)
|
|
if otelSpan.SpanContext().HasTraceID() {
|
|
return otelSpan.SpanContext().TraceID().String(), true
|
|
}
|
|
|
|
return "", false
|
|
}
|