diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index 0c71574801..2674dfd4fe 100644 --- a/metapackages/auto-instrumentations-node/README.md +++ b/metapackages/auto-instrumentations-node/README.md @@ -97,6 +97,9 @@ To disable only [@opentelemetry/instrumentation-fs](https://github.com/open-tele export OTEL_NODE_DISABLED_INSTRUMENTATIONS="fs" ``` +If both environment variables are set, `OTEL_NODE_ENABLED_INSTRUMENTATIONS` is applied first, and then `OTEL_NODE_DISABLED_INSTRUMENTATIONS` is applied to that list. +Therefore, if the same instrumentation is included in both lists, that instrumentation will be disabled. + To enable logging for troubleshooting, set the log level by setting the `OTEL_LOG_LEVEL` environment variable to one of the following: - `none` diff --git a/metapackages/auto-instrumentations-node/test/utils.test.ts b/metapackages/auto-instrumentations-node/test/utils.test.ts index ceea3262a8..cc7cb24c68 100644 --- a/metapackages/auto-instrumentations-node/test/utils.test.ts +++ b/metapackages/auto-instrumentations-node/test/utils.test.ts @@ -114,6 +114,25 @@ describe('utils', () => { } }); + it('should disable any instrumentations from OTEL_NODE_ENABLED_INSTRUMENTATIONS if set in OTEL_NODE_DISABLED_INSTRUMENTATIONS', () => { + process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'http,express,net'; + process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'fs,net'; // fs is no-op here, already disabled + try { + const instrumentations = getNodeAutoInstrumentations(); + + assert.deepStrictEqual( + new Set(instrumentations.map(i => i.instrumentationName)), + new Set([ + '@opentelemetry/instrumentation-http', + '@opentelemetry/instrumentation-express', + ]) + ); + } finally { + delete process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS; + delete process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS; + } + }); + it('should show error for none existing instrumentation', () => { const spy = sinon.stub(diag, 'error'); const name = '@opentelemetry/instrumentation-http2';