Skip to content

Commit

Permalink
fixup! feat(sdk-trace-base)!: drop ability to instantiate propagators…
Browse files Browse the repository at this point in the history
… beyond defaults
  • Loading branch information
pichlermarc committed Jan 21, 2025
1 parent fb662af commit 4072001
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
TextMapGetter,
propagation,
diag,
ContextManager,
} from '@opentelemetry/api';
import { CompositePropagator } from '@opentelemetry/core';
import { TraceState } from '@opentelemetry/core';
Expand Down Expand Up @@ -59,6 +60,7 @@ class DummyPropagator implements TextMapPropagator {
describe('BasicTracerProvider', () => {
let envSource: Record<string, any>;
let setGlobalPropagatorStub: sinon.SinonSpy<[TextMapPropagator], boolean>;
let setGlobalContextManagerStub: sinon.SinonSpy<[ContextManager], boolean>;

if (global.process?.versions?.node === undefined) {
envSource = globalThis as unknown as Record<string, any>;
Expand All @@ -70,6 +72,7 @@ describe('BasicTracerProvider', () => {
// to avoid actually registering the TraceProvider and leaking env to other tests
sinon.stub(trace, 'setGlobalTracerProvider');
setGlobalPropagatorStub = sinon.spy(propagation, 'setGlobalPropagator');
setGlobalContextManagerStub = sinon.spy(context, 'setGlobalContextManager');

context.disable();
});
Expand Down Expand Up @@ -415,6 +418,34 @@ describe('BasicTracerProvider', () => {
]);
});
});
describe('contextManager', () => {
it('should not be set if not provided', () => {
const provider = new BasicTracerProvider();
provider.register();

sinon.assert.notCalled(setGlobalContextManagerStub);
});

it('should be set if provided', () => {
const provider = new BasicTracerProvider();
const mockContextManager: ContextManager = {
active: sinon.stub(),
bind: sinon.stub(),
disable: sinon.stub(),
enable: sinon.stub(),
with: sinon.stub(),
};

provider.register({
contextManager: mockContextManager,
});

sinon.assert.calledOnceWithExactly(
setGlobalContextManagerStub,
mockContextManager
);
});
});
});

describe('.startSpan()', () => {
Expand Down

0 comments on commit 4072001

Please sign in to comment.