File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
experimental/packages/opentelemetry-instrumentation Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,13 @@ export function enableInstrumentations(
6262 if ( meterProvider ) {
6363 instrumentation . setMeterProvider ( meterProvider ) ;
6464 }
65- instrumentation . enable ( ) ;
65+ // instrumentations have been already enabled during creation
66+ // so enable only if user prevented that by setting enabled to false
67+ // this is to prevent double enabling but when calling register all
68+ // instrumentations should be now enabled
69+ if ( ! instrumentation . getConfig ( ) . enabled ) {
70+ instrumentation . enable ( ) ;
71+ }
6672 }
6773}
6874
Original file line number Diff line number Diff line change @@ -72,10 +72,30 @@ describe('autoLoader', () => {
7272 }
7373 } ) ;
7474
75- it ( 'should enable instrumentation' , ( ) => {
75+ it ( 'should enable disabled instrumentation' , ( ) => {
76+ if ( typeof unload === 'function' ) {
77+ unload ( ) ;
78+ unload = undefined ;
79+ }
80+ instrumentation = new FooInstrumentation (
81+ 'foo' ,
82+ '1' ,
83+ { enabled : false }
84+ ) ;
85+ enableSpy = sinon . spy ( instrumentation , 'enable' ) ;
86+ setTracerProviderSpy = sinon . stub ( instrumentation , 'setTracerProvider' ) ;
87+ unload = registerInstrumentations ( {
88+ instrumentations : [ instrumentation ] ,
89+ tracerProvider,
90+ meterProvider,
91+ } ) ;
7692 assert . strictEqual ( enableSpy . callCount , 1 ) ;
7793 } ) ;
7894
95+ it ( 'should NOT enable enabled instrumentation' , ( ) => {
96+ assert . strictEqual ( enableSpy . callCount , 0 ) ;
97+ } ) ;
98+
7999 it ( 'should set TracerProvider' , ( ) => {
80100 assert . strictEqual ( setTracerProviderSpy . callCount , 1 ) ;
81101 assert . ok ( setTracerProviderSpy . lastCall . args [ 0 ] === tracerProvider ) ;
You can’t perform that action at this time.
0 commit comments