Skip to content
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

fix: preventing double enable for instrumentation that has been already enabled #2610

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ export function enableInstrumentations(
if (meterProvider) {
instrumentation.setMeterProvider(meterProvider);
}
instrumentation.enable();
// instrumentations have been already enabled during creation
// so enable only if user prevented that by setting enabled to false
// this is to prevent double enabling but when calling register all
// instrumentations should be now enabled
if (!instrumentation.getConfig().enabled) {
instrumentation.enable();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,30 @@ describe('autoLoader', () => {
}
});

it('should enable instrumentation', () => {
it('should enable disabled instrumentation', () => {
if (typeof unload === 'function') {
unload();
unload = undefined;
}
instrumentation = new FooInstrumentation(
'foo',
'1',
{ enabled: false }
);
enableSpy = sinon.spy(instrumentation, 'enable');
setTracerProviderSpy = sinon.stub(instrumentation, 'setTracerProvider');
unload = registerInstrumentations({
instrumentations: [instrumentation],
tracerProvider,
meterProvider,
});
assert.strictEqual(enableSpy.callCount, 1);
});

it('should NOT enable enabled instrumentation', () => {
assert.strictEqual(enableSpy.callCount, 0);
});

it('should set TracerProvider', () => {
assert.strictEqual(setTracerProviderSpy.callCount, 1);
assert.ok(setTracerProviderSpy.lastCall.args[0] === tracerProvider);
Expand Down