@@ -172,6 +172,76 @@ describe('utils', () => {
172172
173173 spy . restore ( ) ;
174174 } ) ;
175+
176+ it ( 'should enable fs instrumentation when explicitly enabled and OTEL_NODE_ENABLED_INSTRUMENTATIONS is not set' , ( ) => {
177+ const instrumentations = getNodeAutoInstrumentations ( {
178+ '@opentelemetry/instrumentation-fs' : {
179+ enabled : true ,
180+ } ,
181+ } ) ;
182+ const fsInstrumentation = instrumentations . find (
183+ instr =>
184+ instr . instrumentationName === '@opentelemetry/instrumentation-fs'
185+ ) ;
186+ assert . notStrictEqual (
187+ fsInstrumentation ,
188+ undefined ,
189+ 'fs instrumentation should be included when explicitly enabled in config and env var is not set'
190+ ) ;
191+ } ) ;
192+
193+ it ( 'should respect OTEL_NODE_ENABLED_INSTRUMENTATIONS - env var overrides user config' , ( ) => {
194+ process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'fs,http' ;
195+ try {
196+ const instrumentations = getNodeAutoInstrumentations ( {
197+ '@opentelemetry/instrumentation-fs' : {
198+ enabled : false , // User tries to disable but env var overrides
199+ } ,
200+ '@opentelemetry/instrumentation-express' : {
201+ enabled : true , // User tries to enable but not in env var list
202+ } ,
203+ } ) ;
204+
205+ const fsInstrumentation = instrumentations . find (
206+ instr => instr . instrumentationName === '@opentelemetry/instrumentation-fs'
207+ ) ;
208+ const httpInstrumentation = instrumentations . find (
209+ instr => instr . instrumentationName === '@opentelemetry/instrumentation-http'
210+ ) ;
211+ const expressInstrumentation = instrumentations . find (
212+ instr => instr . instrumentationName === '@opentelemetry/instrumentation-express'
213+ ) ;
214+
215+ assert . notStrictEqual ( fsInstrumentation , undefined , 'fs should be enabled by env var despite user config' ) ;
216+ assert . notStrictEqual ( httpInstrumentation , undefined , 'http should be enabled by env var' ) ;
217+ assert . strictEqual ( expressInstrumentation , undefined , 'express should be disabled - not in env var list' ) ;
218+ } finally {
219+ delete process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS ;
220+ }
221+ } ) ;
222+
223+ it ( 'should respect OTEL_NODE_DISABLED_INSTRUMENTATIONS with absolute priority' , ( ) => {
224+ process . env . OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'http' ;
225+ try {
226+ const instrumentations = getNodeAutoInstrumentations ( {
227+ '@opentelemetry/instrumentation-http' : {
228+ enabled : true , // User tries to enable but env var disables
229+ } ,
230+ } ) ;
231+ const httpInstrumentation = instrumentations . find (
232+ instr =>
233+ instr . instrumentationName === '@opentelemetry/instrumentation-http'
234+ ) ;
235+
236+ assert . strictEqual (
237+ httpInstrumentation ,
238+ undefined ,
239+ 'http instrumentation should be disabled by OTEL_NODE_DISABLED_INSTRUMENTATIONS even when user enables it'
240+ ) ;
241+ } finally {
242+ delete process . env . OTEL_NODE_DISABLED_INSTRUMENTATIONS ;
243+ }
244+ } ) ;
175245 } ) ;
176246
177247 describe ( 'getResourceDetectorsFromEnv' , ( ) => {
0 commit comments