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