Alexander Chuprov
c1e4130020
All checks were successful
Vulncheck / Vulncheck (pull_request) Successful in 3m7s
DCO action / DCO (pull_request) Successful in 3m36s
Build / Build Components (1.21) (pull_request) Successful in 3m29s
Build / Build Components (1.20) (pull_request) Successful in 3m37s
Tests and linters / Staticcheck (pull_request) Successful in 4m39s
Tests and linters / Lint (pull_request) Successful in 5m2s
Tests and linters / Tests (1.21) (pull_request) Successful in 6m27s
Tests and linters / Tests with -race (pull_request) Successful in 6m29s
Tests and linters / Tests (1.20) (pull_request) Successful in 9m19s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
19 lines
436 B
Go
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()
|
|
}
|