From e6bf914dd96c8f4aa9879d477e425fb819d43543 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 13 Jul 2025 00:08:30 +0300 Subject: [PATCH] tracer: write log fields only if span exists and recording Signed-off-by: Vasiliy Tolstov --- tracer/tracer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tracer/tracer.go b/tracer/tracer.go index 45c20df5..726a5c3d 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -29,10 +29,10 @@ type ContextAttrFunc func(ctx context.Context) []interface{} func init() { logger.DefaultContextAttrFuncs = append(logger.DefaultContextAttrFuncs, func(ctx context.Context) []interface{} { - if span, ok := SpanFromContext(ctx); ok { + if sp, ok := SpanFromContext(ctx); ok && sp != nil && sp.IsRecording() { return []interface{}{ - TraceIDKey, span.TraceID(), - SpanIDKey, span.SpanID(), + TraceIDKey, sp.TraceID(), + SpanIDKey, sp.SpanID(), } } return nil