[#146] node: Add trace_id to logs

Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
This commit is contained in:
Alexander Chuprov 2023-09-27 11:02:06 +03:00
parent b8c3c2486d
commit c1e4130020
24 changed files with 129 additions and 41 deletions

19
pkg/tracing/trace.go Normal file
View 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()
}