diff --git a/packages/dd-trace/src/opentracing/propagation/text_map.js b/packages/dd-trace/src/opentracing/propagation/text_map.js index 91150b61fd4..a9123c42028 100644 --- a/packages/dd-trace/src/opentracing/propagation/text_map.js +++ b/packages/dd-trace/src/opentracing/propagation/text_map.js @@ -307,7 +307,7 @@ class TextMapPropagator { if (origin) { this._addXrayBaggage(str, xrayOriginKey, origin, maxAdditionalCapacity) } - if (e2eStart !== xrayDefaultStartTime) { + if (e2eStart !== xrayDefaultE2EStartTime) { this._addXrayBaggage(str, xrayE2EStartTimeKey, e2eStart.toString(), maxAdditionalCapacity) } @@ -782,7 +782,7 @@ class TextMapPropagator { } _extractAwsXrayContext (carrier) { - if (!this._hasPropagationStyle('inject', 'xray')) { + if (!this._hasPropagationStyle('extract', 'xray')) { return null } 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 184a5aac741..0b63e3617da 100644 --- a/packages/dd-trace/test/opentracing/propagation/text_map.spec.js +++ b/packages/dd-trace/test/opentracing/propagation/text_map.spec.js @@ -430,6 +430,33 @@ describe('TextMapPropagator', () => { expect(carrier['x-amzn-trace-id']).to.equal(expectedHeader + additionalParts) }) + + it('should inject skip adding baggage to the X-Amzn-Trace-Id when exceeding the 256 byte limit', () => { + const baggageItems = { + bool: true, + a: 'b', + mySuperLongBaggageIReallyShouldLearnToPackLighter: 'datadog'.repeat(50), + shortBaggage: 'thisFits' + } + const spanContext = createContext({ + baggageItems, + sampling: { + priority: 1 + } + }) + + config.tracePropagationStyle.inject = ['xray'] + + const traceId = spanContext._traceId.toString().padStart(24, '0') + const spanId = spanContext._spanId.toString().padStart(16, '0') + const expectedHeader = `root=1-00000000-${traceId};parent=${spanId};sampled=1` + const additionalParts = ';bool=true;a=b;shortBaggage=thisFits' + const carrier = {} + + propagator.inject(spanContext, carrier) + + expect(carrier['x-amzn-trace-id']).to.equal(expectedHeader + additionalParts) + }) }) describe('extract', () => {