From babb962fa5705a11e009148b6c861aa5c33f2594 Mon Sep 17 00:00:00 2001 From: Ayan Khan Date: Mon, 12 Aug 2024 17:55:08 -0400 Subject: [PATCH] correctly handle 128 bits traceids in log injection --- .../src/opentracing/propagation/log.js | 2 +- .../test/opentracing/propagation/log.spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/dd-trace/src/opentracing/propagation/log.js b/packages/dd-trace/src/opentracing/propagation/log.js index 957bfc113d2..2203f253fb6 100644 --- a/packages/dd-trace/src/opentracing/propagation/log.js +++ b/packages/dd-trace/src/opentracing/propagation/log.js @@ -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() } diff --git a/packages/dd-trace/test/opentracing/propagation/log.spec.js b/packages/dd-trace/test/opentracing/propagation/log.spec.js index 95ff1ce82ac..50c815f1b7c 100644 --- a/packages/dd-trace/test/opentracing/propagation/log.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/log.spec.js @@ -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)