From b456550ce0a4867433688bb572f6bb940fe4f485 Mon Sep 17 00:00:00 2001 From: Ida Liu <119438987+ida613@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:39:07 -0500 Subject: [PATCH] fix baggage extraction (#4935) --- .../src/opentracing/propagation/text_map.js | 8 ++++---- .../test/opentracing/propagation/text_map.spec.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index afca108111..b117ae0ae5 100644 --- a/packages/dd-trace/src/opentracing/propagation/text_map.js +++ b/packages/dd-trace/src/opentracing/propagation/text_map.js @@ -339,11 +339,11 @@ class TextMapPropagator { context._links.push(link) } } + } - if (this._config.tracePropagationStyle.extract.includes('baggage') && carrier.baggage) { - context = context || new DatadogSpanContext() - this._extractBaggageItems(carrier, context) - } + if (this._hasPropagationStyle('extract', 'baggage') && carrier.baggage) { + context = context || new DatadogSpanContext() + this._extractBaggageItems(carrier, context) } return context || this._extractSqsdContext(carrier) diff --git a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js index 4598ffeda7..c6247330a6 100644 --- a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js @@ -406,7 +406,6 @@ describe('TextMapPropagator', () => { }) it('should extract otel baggage items with special characters', () => { - process.env.DD_TRACE_BAGGAGE_ENABLED = true config = new Config() propagator = new TextMapPropagator(config) const carrier = { @@ -452,6 +451,20 @@ describe('TextMapPropagator', () => { expect(spanContextD._baggageItems).to.deep.equal({}) }) + it('should extract baggage when it is the only propagation style', () => { + config = new Config({ + tracePropagationStyle: { + extract: ['baggage'] + } + }) + propagator = new TextMapPropagator(config) + const carrier = { + baggage: 'foo=bar' + } + const spanContext = propagator.extract(carrier) + expect(spanContext._baggageItems).to.deep.equal({ foo: 'bar' }) + }) + it('should convert signed IDs to unsigned', () => { textMap['x-datadog-trace-id'] = '-123' textMap['x-datadog-parent-id'] = '-456'