Skip to content

Commit

Permalink
correctly handle 128 bits traceids in log injection
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 committed Aug 12, 2024
1 parent 77c1d07 commit babb962
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dd-trace/src/opentracing/propagation/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LogPropagator {

if (spanContext) {
if (this._config.traceId128BitLoggingEnabled && spanContext._trace.tags['_dd.p.tid']) {
carrier.dd.trace_id = spanContext._trace.tags['_dd.p.tid'] + spanContext._traceId.toString(16)
carrier.dd.trace_id = spanContext.toTraceId(true)
} else {
carrier.dd.trace_id = spanContext.toTraceId()
}
Expand Down
19 changes: 19 additions & 0 deletions packages/dd-trace/test/opentracing/propagation/log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ describe('LogPropagator', () => {
expect(carrier.dd).to.have.property('span_id', '456')
})

it('should correctly inject 128 bit trace ids when _dd.p.tid is present', () => {
config.traceId128BitLoggingEnabled = true
const carrier = {}
const traceId = id('4e2a9c1573d240b1a3b7e3c1d4c2f9a7', 16)
const traceIdTag = '8765432187654321'
const spanContext = new SpanContext({
traceId,
spanId: id('456', 10)
})

spanContext._trace.tags['_dd.p.tid'] = traceIdTag

propagator.inject(spanContext, carrier)

expect(carrier).to.have.property('dd')
expect(carrier.dd).to.have.property('trace_id', '4e2a9c1573d240b1a3b7e3c1d4c2f9a7')
expect(carrier.dd).to.have.property('span_id', '456')
})

it('should not inject 128-bit trace IDs when disabled', () => {
const carrier = {}
const traceId = id('123', 10)
Expand Down

0 comments on commit babb962

Please sign in to comment.