Skip to content

Commit

Permalink
Enable DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoffl01 committed Jan 14, 2025
1 parent 471d723 commit bc24881
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions contrib/net/http/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ func TestTraceAndServe(t *testing.T) {
t.Setenv("DD_TRACE_HTTP_SERVER_ERROR_STATUSES", "500")

cfg := &ServeConfig{
Service: "service",
Resource: "resource",
Service: "service",
Resource: "resource",
}

handler := func(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ func (s *span) Format(f fmt.State, c rune) {
}
}
var traceID string
if sharedinternal.BoolEnv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", false) && s.context.traceID.HasUpper() {
if sharedinternal.BoolEnv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", true) && s.context.traceID.HasUpper() {
traceID = s.context.TraceID128()
} else {
traceID = fmt.Sprintf("%d", s.TraceID)
Expand Down
46 changes: 19 additions & 27 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,27 +810,24 @@ func TestSpanLog(t *testing.T) {
assert.Equal(expect, fmt.Sprintf("%v", span))
})

t.Run("128-bit-generation-only", func(t *testing.T) {
// Generate 128 bit trace ids, but don't log them. So only the lower
// 64 bits should be logged in decimal form.
// DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED is true by default
// DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED is false by default
t.Run("128-bit-logging-default", func(t *testing.T) {
// Generate and log 128 bit trace ids by default
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
defer stop()
span := tracer.StartSpan("test.request").(*span)
span.TraceID = 12345678
span.SpanID = 87654321
span.Finish()
expect := `dd.service=tracer.test dd.env=testenv dd.trace_id="12345678" dd.span_id="87654321" dd.parent_id="0"`
expect := fmt.Sprintf(`dd.service=tracer.test dd.env=testenv dd.trace_id=%q dd.span_id="87654321" dd.parent_id="0"`, span.context.TraceID128())
assert.Equal(expect, fmt.Sprintf("%v", span))
v, _ := getMeta(span, keyTraceID128)
assert.NotEmpty(v)
})

t.Run("128-bit-logging-only", func(t *testing.T) {
// Logging 128-bit trace ids is enabled, but it's not present in
// the span. So only the lower 64 bits should be logged in decimal form.
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "false")
t.Setenv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "true")
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
defer stop()
Expand All @@ -842,27 +839,9 @@ func TestSpanLog(t *testing.T) {
assert.Equal(expect, fmt.Sprintf("%v", span))
})

t.Run("128-bit-logging-with-generation", func(t *testing.T) {
// Logging 128-bit trace ids is enabled, and a 128-bit trace id, so
// a quoted 32 byte hex string should be printed for the dd.trace_id.
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "true")
t.Setenv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "true")
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
defer stop()
span := tracer.StartSpan("test.request").(*span)
span.SpanID = 87654321
span.Finish()
expect := fmt.Sprintf(`dd.service=tracer.test dd.env=testenv dd.trace_id=%q dd.span_id="87654321" dd.parent_id="0"`, span.context.TraceID128())
assert.Equal(expect, fmt.Sprintf("%v", span))
v, _ := getMeta(span, keyTraceID128)
assert.NotEmpty(v)
})

t.Run("128-bit-logging-with-small-upper-bits", func(t *testing.T) {
// Logging 128-bit trace ids is enabled, and a 128-bit trace id, so
// a quoted 32 byte hex string should be printed for the dd.trace_id.
t.Setenv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "true")
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "false")
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
Expand All @@ -878,7 +857,6 @@ func TestSpanLog(t *testing.T) {
t.Run("128-bit-logging-with-empty-upper-bits", func(t *testing.T) {
// Logging 128-bit trace ids is enabled, and but the upper 64 bits
// are empty, so the dd.trace_id should be printed as raw digits (not hex).
t.Setenv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "true")
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "false")
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
Expand All @@ -890,6 +868,20 @@ func TestSpanLog(t *testing.T) {
v, _ := getMeta(span, keyTraceID128)
assert.Equal("", v)
})
t.Run("128-bit-logging-disabled", func(t *testing.T) {
// Only the lower 64 bits should be logged in decimal form.
// DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED is true by default
t.Setenv("DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED", "false")
assert := assert.New(t)
tracer, _, _, stop := startTestTracer(t, WithService("tracer.test"), WithEnv("testenv"))
defer stop()
span := tracer.StartSpan("test.request").(*span)
span.TraceID = 12345678
span.SpanID = 87654321
span.Finish()
expect := `dd.service=tracer.test dd.env=testenv dd.trace_id="12345678" dd.span_id="87654321" dd.parent_id="0"`
assert.Equal(expect, fmt.Sprintf("%v", span))
})
}

func TestRootSpanAccessor(t *testing.T) {
Expand Down

0 comments on commit bc24881

Please sign in to comment.