diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index 82bc9f2b30f..fd7d32760cb 100644 --- a/packages/dd-trace/src/opentracing/propagation/text_map.js +++ b/packages/dd-trace/src/opentracing/propagation/text_map.js @@ -325,6 +325,7 @@ class TextMapPropagator { if (context === null) { context = extractedContext if (this._config.tracePropagationExtractFirst) { + this._extractBaggageItems(carrier, context) return context } } else { @@ -344,10 +345,7 @@ class TextMapPropagator { } } - if (this._hasPropagationStyle('extract', 'baggage') && carrier.baggage) { - context = context || new DatadogSpanContext() - this._extractBaggageItems(carrier, context) - } + this._extractBaggageItems(carrier, context) return context || this._extractSqsdContext(carrier) } @@ -596,6 +594,9 @@ class TextMapPropagator { } _extractBaggageItems (carrier, spanContext) { + if (!this._hasPropagationStyle('extract', 'baggage')) return + if (!carrier || !carrier.baggage) return + if (!spanContext) return const baggages = carrier.baggage.split(',') for (const keyValue of baggages) { if (!keyValue.includes('=')) { 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 3e4f6aed3e8..2c699b107a1 100644 --- a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js @@ -451,7 +451,8 @@ describe('TextMapPropagator', () => { expect(spanContextD._baggageItems).to.deep.equal({}) }) - it('should extract baggage when it is the only propagation style', () => { + // temporary test. On the contrary, it SHOULD extract baggage + it('should not extract baggage when it is the only propagation style', () => { config = new Config({ tracePropagationStyle: { extract: ['baggage'] @@ -462,7 +463,7 @@ describe('TextMapPropagator', () => { baggage: 'foo=bar' } const spanContext = propagator.extract(carrier) - expect(spanContext._baggageItems).to.deep.equal({ foo: 'bar' }) + expect(spanContext).to.be.null }) it('should convert signed IDs to unsigned', () => {