Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracer: remove WithTraceID128 #1687

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ddtrace/ddtrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ type StartSpanConfig struct {
// TraceID to the same value.
SpanID uint64

// TraceID128High will be the upper 64 bits of a 128-bit trace id of the span if no
// Parent SpanContext is present, overriding the random number that would be generated.
TraceID128High uint64

// Context is the parent context where the span should be stored.
Context context.Context
}
Expand Down
9 changes: 0 additions & 9 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,6 @@ func WithSpanID(id uint64) StartSpanOption {
}
}

// WithTraceID128High sets the higher-order 64 bits of a 128-bit trace id
// of the started span if no Parent SpanContext is present,
// overriding the random number that would be generated.
func WithTraceID128High(id uint64) StartSpanOption {
return func(cfg *ddtrace.StartSpanConfig) {
cfg.TraceID128High = id
}
}

// ChildOf tells StartSpan to use the given span context as a parent for the
// created span.
func ChildOf(ctx ddtrace.SpanContext) StartSpanOption {
Expand Down
5 changes: 1 addition & 4 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,7 @@ func (t *tracer) StartSpan(operationName string, options ...ddtrace.StartSpanOpt

// add 128 bit trace id, if enabled.
if os.Getenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED") == "true" {
id128 := opts.TraceID128High
if id128 == 0 {
id128 = generateSpanID(startTime)
}
id128 := generateSpanID(startTime)
buf := make([]byte, 8)
binary.BigEndian.PutUint64(buf, id128)
span.setMeta(keyTraceID128, hex.EncodeToString(buf))
Expand Down
70 changes: 38 additions & 32 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,39 +662,45 @@ func TestTracerStartSpanOptions(t *testing.T) {
func TestTracerStartSpanOptions128(t *testing.T) {
tracer := newTracer()
defer tracer.Stop()
opts := []StartSpanOption{
WithSpanID(987654),
WithTraceID128High(123456),
}
s := tracer.StartSpan("web.request", opts...).(*span)
assert := assert.New(t)
assert.Equal(uint64(987654), s.SpanID)
assert.Equal(uint64(987654), s.TraceID)
w3cCtx, ok := s.Context().(ddtrace.SpanContextW3C)
if !ok {
assert.Fail("couldn't cast to ddtrace.SpanContextW3C")
}
id128 := w3cCtx.TraceID128()
assert.Len(id128, 32) // ensure there are enough leading zeros
idBytes, err := hex.DecodeString(id128)
assert.NoError(err)
assert.Equal(uint64(0), binary.BigEndian.Uint64(idBytes[:8])) // high 64 bits should be 0
assert.Equal(s.Context().TraceID(), binary.BigEndian.Uint64(idBytes[8:]))

// Enable 128 bit trace ids
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "true")
opts128 := []StartSpanOption{
WithSpanID(987654),
WithTraceID128High(123456),
}
s128 := tracer.StartSpan("web.request", opts128...).(*span)
assert.Equal(uint64(987654), s128.SpanID)
assert.Equal(uint64(987654), s128.TraceID)
w3cCtx, ok = s128.Context().(ddtrace.SpanContextW3C)
if !ok {
assert.Fail("couldn't cast to ddtrace.SpanContextW3C")
}
assert.Equal("000000000001e24000000000000f1206", w3cCtx.TraceID128()) // raw bytes = [0 0 0 0 0 0 123 42 0 0 0 0 0 0 3 219]
t.Run("64-bit-trace-id", func(t *testing.T) {
opts := []StartSpanOption{
WithSpanID(987654),
}
s := tracer.StartSpan("web.request", opts...).(*span)
assert.Equal(uint64(987654), s.SpanID)
assert.Equal(uint64(987654), s.TraceID)
w3cCtx, ok := s.Context().(ddtrace.SpanContextW3C)
if !ok {
assert.Fail("couldn't cast to ddtrace.SpanContextW3C")
}
id128 := w3cCtx.TraceID128()
assert.Len(id128, 32) // ensure there are enough leading zeros
idBytes, err := hex.DecodeString(id128)
assert.NoError(err)
assert.Equal(uint64(0), binary.BigEndian.Uint64(idBytes[:8])) // high 64 bits should be 0
assert.Equal(s.Context().TraceID(), binary.BigEndian.Uint64(idBytes[8:]))
})
t.Run("128-bit-trace-id", func(t *testing.T) {
// Enable 128 bit trace ids
t.Setenv("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", "true")
opts128 := []StartSpanOption{
WithSpanID(987654),
}
s := tracer.StartSpan("web.request", opts128...).(*span)
assert.Equal(uint64(987654), s.SpanID)
assert.Equal(uint64(987654), s.TraceID)
w3cCtx, ok := s.Context().(ddtrace.SpanContextW3C)
if !ok {
assert.Fail("couldn't cast to ddtrace.SpanContextW3C")
}
id := w3cCtx.TraceID128()
assert.Len(id, 32) // ensure there are enough leading zeros
idBytes, err := hex.DecodeString(id)
assert.NoError(err)
assert.NotEqual(uint64(0), binary.BigEndian.Uint64(idBytes[:8])) // high 64 bits should not be 0
assert.Equal(s.Context().TraceID(), binary.BigEndian.Uint64(idBytes[8:]))
})
}

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