20 lines
436 B
Go
20 lines
436 B
Go
|
package tracing
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"go.opentelemetry.io/otel/trace"
|
||
|
)
|
||
|
|
||
|
var emptyTraceID = [16]byte{}
|
||
|
|
||
|
// GetTraceID retrieves the trace ID from the provided context.
|
||
|
// It returns an empty string if no trace ID is found.
|
||
|
func GetTraceID(ctx context.Context) string {
|
||
|
span := trace.SpanFromContext(ctx)
|
||
|
if span == nil || span.SpanContext().TraceID() == emptyTraceID {
|
||
|
return ""
|
||
|
}
|
||
|
return span.SpanContext().TraceID().String()
|
||
|
}
|