@@ -172,6 +172,92 @@ 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 programmatic config over OTEL_NODE_ENABLED_INSTRUMENTATIONS - user config overrides env var' , ( ) => {
194+ process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'fs,http' ;
195+ try {
196+ const instrumentations = getNodeAutoInstrumentations ( {
197+ '@opentelemetry/instrumentation-fs' : {
198+ enabled : false , // User explicitly disables - should override env var
199+ } ,
200+ '@opentelemetry/instrumentation-express' : {
201+ enabled : true , // User explicitly enables - should override env var
202+ } ,
203+ } ) ;
204+
205+ const fsInstrumentation = instrumentations . find (
206+ instr =>
207+ instr . instrumentationName === '@opentelemetry/instrumentation-fs'
208+ ) ;
209+ const httpInstrumentation = instrumentations . find (
210+ instr =>
211+ instr . instrumentationName === '@opentelemetry/instrumentation-http'
212+ ) ;
213+ const expressInstrumentation = instrumentations . find (
214+ instr =>
215+ instr . instrumentationName ===
216+ '@opentelemetry/instrumentation-express'
217+ ) ;
218+
219+ assert . strictEqual (
220+ fsInstrumentation ,
221+ undefined ,
222+ 'fs should be disabled by user config despite env var'
223+ ) ;
224+ assert . notStrictEqual (
225+ httpInstrumentation ,
226+ undefined ,
227+ 'http should be enabled by env var (no user override)'
228+ ) ;
229+ assert . notStrictEqual (
230+ expressInstrumentation ,
231+ undefined ,
232+ 'express should be enabled by user config despite not being in env var list'
233+ ) ;
234+ } finally {
235+ delete process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS ;
236+ }
237+ } ) ;
238+
239+ it ( 'should respect programmatic config over OTEL_NODE_DISABLED_INSTRUMENTATIONS - user config overrides env var' , ( ) => {
240+ process . env . OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'http' ;
241+ try {
242+ const instrumentations = getNodeAutoInstrumentations ( {
243+ '@opentelemetry/instrumentation-http' : {
244+ enabled : true , // User explicitly enables - should override env var
245+ } ,
246+ } ) ;
247+ const httpInstrumentation = instrumentations . find (
248+ instr =>
249+ instr . instrumentationName === '@opentelemetry/instrumentation-http'
250+ ) ;
251+
252+ assert . notStrictEqual (
253+ httpInstrumentation ,
254+ undefined ,
255+ 'http instrumentation should be enabled by user config despite OTEL_NODE_DISABLED_INSTRUMENTATIONS'
256+ ) ;
257+ } finally {
258+ delete process . env . OTEL_NODE_DISABLED_INSTRUMENTATIONS ;
259+ }
260+ } ) ;
175261 } ) ;
176262
177263 describe ( 'getResourceDetectorsFromEnv' , ( ) => {
0 commit comments