forked from TrueCloudLab/frostfs-node
[#146] node: Add trace_id to logs
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
parent
b8c3c2486d
commit
c1e4130020
24 changed files with 129 additions and 41 deletions
19
pkg/tracing/trace.go
Normal file
19
pkg/tracing/trace.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
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()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue