@@ -136,6 +136,7 @@ export function getNodeAutoInstrumentations(
136
136
inputConfigs : InstrumentationConfigMap = { }
137
137
) : Instrumentation [ ] {
138
138
checkManuallyProvidedInstrumentationNames ( Object . keys ( inputConfigs ) ) ;
139
+ const enabledInstrumentationsFromEnv = getEnabledInstrumentationsFromEnv ( ) ;
139
140
140
141
const instrumentations : Instrumentation [ ] = [ ] ;
141
142
@@ -146,7 +147,10 @@ export function getNodeAutoInstrumentations(
146
147
// Defaults are defined by the instrumentation itself
147
148
const userConfig : any = inputConfigs [ name ] ?? { } ;
148
149
149
- if ( userConfig . enabled === false ) {
150
+ if (
151
+ userConfig . enabled === false ||
152
+ ! enabledInstrumentationsFromEnv . includes ( name )
153
+ ) {
150
154
diag . debug ( `Disabling instrumentation for ${ name } ` ) ;
151
155
continue ;
152
156
}
@@ -172,6 +176,23 @@ function checkManuallyProvidedInstrumentationNames(
172
176
}
173
177
}
174
178
179
+ /**
180
+ * Returns the list of instrumentations that are enabled based on the environment variable.
181
+ */
182
+ function getEnabledInstrumentationsFromEnv ( ) {
183
+ if ( ! process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS ) {
184
+ return Object . keys ( InstrumentationMap ) ;
185
+ }
186
+
187
+ const instrumentationsFromEnv =
188
+ process . env . OTEL_NODE_ENABLED_INSTRUMENTATIONS . split ( ',' ) . map (
189
+ instrumentationPkgSuffix =>
190
+ `@opentelemetry/instrumentation-${ instrumentationPkgSuffix . trim ( ) } `
191
+ ) ;
192
+ checkManuallyProvidedInstrumentationNames ( instrumentationsFromEnv ) ;
193
+ return instrumentationsFromEnv ;
194
+ }
195
+
175
196
export function getResourceDetectorsFromEnv ( ) : Array < Detector | DetectorSync > {
176
197
const resourceDetectors = new Map <
177
198
string ,
0 commit comments