frostfs-node/pkg/tracing/trace.go
Alexander Chuprov c1e4130020 [#146] node: Add trace_id to logs
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
2023-09-27 11:05:27 +03:00

19 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()
}