Skip to content

Commit 0e4fded

Browse files
authored
skip extraction of upper bits for 64-bit trace id (#2974)
1 parent 8731ea0 commit 0e4fded

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/dd-trace/src/opentracing/propagation/text_map.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,11 @@ class TextMapPropagator {
495495

496496
if (buffer.length !== 16) return
497497

498-
spanContext._trace.tags['_dd.p.tid'] = traceId.substring(0, 16)
498+
const tid = traceId.substring(0, 16)
499+
500+
if (tid === '0000000000000000') return
501+
502+
spanContext._trace.tags['_dd.p.tid'] = tid
499503
}
500504

501505
_validateTagKey (key) {

packages/dd-trace/test/opentracing/propagation/text_map.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,20 @@ describe('TextMapPropagator', () => {
659659
}
660660
}))
661661
})
662+
663+
it('should skip extracting upper bits for 64-bit trace IDs', () => {
664+
textMap['b3'] = '00000000000000000000000000000123-0000000000000456'
665+
666+
config.traceId128BitGenerationEnabled = true
667+
668+
const carrier = textMap
669+
const spanContext = propagator.extract(carrier)
670+
671+
expect(spanContext).to.deep.equal(createContext({
672+
traceId: id('00000000000000000000000000000123', 16),
673+
spanId: id('456', 16)
674+
}))
675+
})
662676
})
663677

664678
describe('With traceparent propagation as single header', () => {
@@ -704,6 +718,18 @@ describe('TextMapPropagator', () => {
704718
expect(spanContext._trace.tags).to.have.property('_dd.p.tid', '1111aaaa2222bbbb')
705719
})
706720

721+
it('should skip extracting upper bits for 64-bit trace IDs', () => {
722+
textMap['traceparent'] = '00-00000000000000003333cccc4444dddd-5555eeee6666ffff-01'
723+
config.tracePropagationStyle.extract = ['tracecontext']
724+
config.traceId128BitGenerationEnabled = true
725+
726+
const carrier = textMap
727+
const spanContext = propagator.extract(carrier)
728+
729+
expect(spanContext._traceId.toString(16)).to.equal('00000000000000003333cccc4444dddd')
730+
expect(spanContext._trace.tags).to.not.have.property('_dd.p.tid')
731+
})
732+
707733
it('should propagate the version', () => {
708734
textMap['traceparent'] = '01-1111aaaa2222bbbb3333cccc4444dddd-5555eeee6666ffff-01'
709735
textMap['tracestate'] = 'other=bleh,dd=t.foo_bar_baz_:abc_!@#$%^&*()_+`-~;s:2;o:foo;t.dm:-4'

0 commit comments

Comments
 (0)