Skip to content

Commit

Permalink
log trace and span IDs as string in logrus
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Jan 22, 2025
1 parent 4baf383 commit 3ed7ac8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions contrib/sirupsen/logrus/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package logrus

import (
"strconv"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
Expand Down Expand Up @@ -42,8 +44,8 @@ func (d *DDContextLogHook) Fire(e *logrus.Entry) error {
if ctxW3c, ok := span.Context().(ddtrace.SpanContextW3C); ok && log128bits {
e.Data[ext.LogKeyTraceID] = ctxW3c.TraceID128()
} else {
e.Data[ext.LogKeyTraceID] = span.Context().TraceID()
e.Data[ext.LogKeyTraceID] = strconv.FormatUint(span.Context().TraceID(), 10)
}
e.Data[ext.LogKeySpanID] = span.Context().SpanID()
e.Data[ext.LogKeySpanID] = strconv.FormatUint(span.Context().SpanID(), 10)
return nil
}

0 comments on commit 3ed7ac8

Please sign in to comment.