Skip to content

Commit

Permalink
fix baggage extraction (#4935)
Browse files Browse the repository at this point in the history
  • Loading branch information
ida613 authored Nov 26, 2024
1 parent 66f115c commit b456550
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/dd-trace/src/opentracing/propagation/text_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion packages/dd-trace/test/opentracing/propagation/text_map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit b456550

Please sign in to comment.