Skip to content

Commit

Permalink
Tie logrus 128bit logging to the env var seting
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Jan 22, 2025
1 parent 9851ac3 commit 4baf383
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions contrib/sirupsen/logrus/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"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"
"gopkg.in/DataDog/dd-trace-go.v1/internal"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"

"github.com/sirupsen/logrus"
)

const componentName = "sirupsen/logrus"

var log128bits = internal.BoolEnv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", true)

func init() {
telemetry.LoadIntegration(componentName)
tracer.MarkIntegrationImported("github.com/sirupsen/logrus")
Expand All @@ -36,9 +39,8 @@ func (d *DDContextLogHook) Fire(e *logrus.Entry) error {
if !found {
return nil
}
spanCtx128, ok := span.Context().(ddtrace.SpanContextW3C)
if ok {
e.Data[ext.LogKeyTraceID] = spanCtx128.TraceID128()
if ctxW3c, ok := span.Context().(ddtrace.SpanContextW3C); ok && log128bits {
e.Data[ext.LogKeyTraceID] = ctxW3c.TraceID128()
} else {
e.Data[ext.LogKeyTraceID] = span.Context().TraceID()
}
Expand Down

0 comments on commit 4baf383

Please sign in to comment.