From 22e40824091c1b2333ac2dd0e5eb8239a88f671b Mon Sep 17 00:00:00 2001 From: "Ida.Liu" Date: Sun, 24 Nov 2024 19:13:12 -0500 Subject: [PATCH 1/3] fix extraction of baggage --- packages/dd-trace/src/opentracing/propagation/text_map.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index afca1081110..596d42bf734 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._config.tracePropagationStyle.extract.includes('baggage') && carrier.baggage) { + context = context || new DatadogSpanContext() + this._extractBaggageItems(carrier, context) } return context || this._extractSqsdContext(carrier) From 7a53c38e83faa0b8663cd558657332509a4cc224 Mon Sep 17 00:00:00 2001 From: "Ida.Liu" Date: Mon, 25 Nov 2024 14:54:22 -0500 Subject: [PATCH 2/3] add unit test and clean up code --- .../src/opentracing/propagation/text_map.js | 2 +- .../test/opentracing/propagation/text_map.spec.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index 596d42bf734..b117ae0ae5e 100644 --- a/packages/dd-trace/src/opentracing/propagation/text_map.js +++ b/packages/dd-trace/src/opentracing/propagation/text_map.js @@ -341,7 +341,7 @@ class TextMapPropagator { } } - if (this._config.tracePropagationStyle.extract.includes('baggage') && carrier.baggage) { + if (this._hasPropagationStyle('extract', 'baggage') && carrier.baggage) { context = context || new DatadogSpanContext() this._extractBaggageItems(carrier, context) } 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 4598ffeda76..6654dff4491 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,18 @@ 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' From 20b7a9d8cb91fe3e2d6799dc8b9aacca30484308 Mon Sep 17 00:00:00 2001 From: "Ida.Liu" Date: Mon, 25 Nov 2024 15:27:08 -0500 Subject: [PATCH 3/3] fix linter errors --- .../test/opentracing/propagation/text_map.spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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 6654dff4491..c6247330a69 100644 --- a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js @@ -452,15 +452,17 @@ describe('TextMapPropagator', () => { }) it('should extract baggage when it is the only propagation style', () => { - config = new Config({tracePropagationStyle: { - extract: [ 'baggage' ] - }}) + 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' }) + expect(spanContext._baggageItems).to.deep.equal({ foo: 'bar' }) }) it('should convert signed IDs to unsigned', () => {