-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
otel drop in support for baggage #5019
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,17 @@ require('../setup/tap') | |
|
||
const { expect } = require('chai') | ||
const ContextManager = require('../../src/opentelemetry/context_manager') | ||
const { ROOT_CONTEXT } = require('@opentelemetry/api') | ||
const TracerProvider = require('../../src/opentelemetry/tracer_provider') | ||
const { context, propagation, trace, ROOT_CONTEXT } = require('@opentelemetry/api') | ||
const api = require('@opentelemetry/api') | ||
const tracer = require('../../').init() | ||
|
||
function makeSpan (...args) { | ||
const tracerProvider = new TracerProvider() | ||
tracerProvider.register() | ||
const tracer = tracerProvider.getTracer() | ||
return tracer.startSpan(...args) | ||
} | ||
|
||
describe('OTel Context Manager', () => { | ||
let contextManager | ||
|
@@ -114,4 +123,75 @@ describe('OTel Context Manager', () => { | |
}) | ||
expect(ret).to.equal('return value') | ||
}) | ||
|
||
it('should propagate baggage from an otel span to a datadog span', () => { | ||
const entries = { | ||
foo: { value: 'bar' } | ||
} | ||
const baggage = propagation.createBaggage(entries) | ||
const contextWithBaggage = propagation.setBaggage(context.active(), baggage) | ||
const span = makeSpan('otel-to-dd') | ||
const contextWithSpan = trace.setSpan(contextWithBaggage, span) | ||
api.context.with(contextWithSpan, () => { | ||
expect(tracer.scope().active().getBaggageItem('foo')).to.be.equal('bar') | ||
}) | ||
}) | ||
|
||
it('should propagate baggage from a datadog span to an otel span', () => { | ||
const baggageKey = 'raccoon' | ||
const baggageVal = 'chunky' | ||
const ddSpan = tracer.startSpan('dd-to-otel') | ||
ddSpan.setBaggageItem(baggageKey, baggageVal) | ||
tracer.scope().activate(ddSpan, () => { | ||
const baggages = propagation.getActiveBaggage().getAllEntries() | ||
expect(baggages.length).to.equal(1) | ||
const baggage = baggages[0] | ||
expect(baggage[0]).to.equal(baggageKey) | ||
expect(baggage[1].value).to.equal(baggageVal) | ||
}) | ||
}) | ||
|
||
it('should handle dd-otel baggage conflict', () => { | ||
const ddSpan = tracer.startSpan('dd') | ||
ddSpan.setBaggageItem('key1', 'dd1') | ||
let contextWithUpdatedBaggages | ||
tracer.scope().activate(ddSpan, () => { | ||
let baggages = propagation.getBaggage(api.context.active()) | ||
baggages = baggages.setEntry('key1', { value: 'otel1' }) | ||
baggages = baggages.setEntry('key2', { value: 'otel2' }) | ||
contextWithUpdatedBaggages = propagation.setBaggage(api.context.active(), baggages) | ||
}) | ||
expect(JSON.parse(ddSpan.getAllBaggageItems())).to.deep.equal({ key1: 'dd1' }) | ||
api.context.with(contextWithUpdatedBaggages, () => { | ||
expect(JSON.parse(ddSpan.getAllBaggageItems())).to.deep.equal( | ||
{ key1: 'otel1', key2: 'otel2' } | ||
) | ||
ddSpan.setBaggageItem('key2', 'dd2') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I am guessing that the changes to this span's baggage update the baggage in the OTEL active context because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup! |
||
expect(propagation.getActiveBaggage().getAllEntries()).to.deep.equal( | ||
[['key1', { value: 'otel1' }], ['key2', { value: 'dd2' }]] | ||
) | ||
}) | ||
}) | ||
|
||
it('should handle dd-otel baggage removal', () => { | ||
const ddSpan = tracer.startSpan('dd') | ||
ddSpan.setBaggageItem('key1', 'dd1') | ||
ddSpan.setBaggageItem('key2', 'dd2') | ||
let contextWithUpdatedBaggages | ||
tracer.scope().activate(ddSpan, () => { | ||
let baggages = propagation.getBaggage(api.context.active()) | ||
baggages = baggages.removeEntry('key1') | ||
contextWithUpdatedBaggages = propagation.setBaggage(api.context.active(), baggages) | ||
}) | ||
expect(JSON.parse(ddSpan.getAllBaggageItems())).to.deep.equal( | ||
{ key1: 'dd1', key2: 'dd2' } | ||
) | ||
api.context.with(contextWithUpdatedBaggages, () => { | ||
expect(JSON.parse(ddSpan.getAllBaggageItems())).to.deep.equal( | ||
{ key2: 'dd2' } | ||
) | ||
ddSpan.removeBaggageItem('key2') | ||
expect(propagation.getActiveBaggage().getAllEntries()).to.deep.equal([]) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth adding a comment here to clarify that the Datadog baggage is not updated until the
api.context.with(context, fn, thisArg, ...args)
is calledThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do