From e83c0aeb34aafe35ad9b9ede8b7b26e4c8444c20 Mon Sep 17 00:00:00 2001 From: Jamie Danielson Date: Wed, 17 Jul 2024 17:07:48 -0400 Subject: [PATCH] update to more reliable test and update docs --- metapackages/auto-instrumentations-node/README.md | 3 +++ metapackages/auto-instrumentations-node/src/utils.ts | 2 +- .../auto-instrumentations-node/test/utils.test.ts | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/metapackages/auto-instrumentations-node/README.md b/metapackages/auto-instrumentations-node/README.md index c32df7c437..2c324438de 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/src/utils.ts b/metapackages/auto-instrumentations-node/src/utils.ts index ac8bd4b60d..a9e2b0755f 100644 --- a/metapackages/auto-instrumentations-node/src/utils.ts +++ b/metapackages/auto-instrumentations-node/src/utils.ts @@ -151,7 +151,7 @@ export function getNodeAutoInstrumentations( if (enabledInstrumentationsFromEnv && disabledInstrumentationsFromEnv) { diag.debug( - 'OTEL_NODE_ENABLED_INSTRUMENTATIONS and OTEL_NODE_DISABLED_INSTRUMENTATIONS environment variables are mutually exclusive. All instrumentations are disabled.' + 'OTEL_NODE_ENABLED_INSTRUMENTATIONS and OTEL_NODE_DISABLED_INSTRUMENTATIONS are both set.\nAny instrumentation that exists in both lists will be disabled.' ); } diff --git a/metapackages/auto-instrumentations-node/test/utils.test.ts b/metapackages/auto-instrumentations-node/test/utils.test.ts index 6a6a9b22e2..cc7cb24c68 100644 --- a/metapackages/auto-instrumentations-node/test/utils.test.ts +++ b/metapackages/auto-instrumentations-node/test/utils.test.ts @@ -114,15 +114,18 @@ describe('utils', () => { } }); - it('will disable all instrumentations if both OTEL_NODE_ENABLED_INSTRUMENTATIONS and OTEL_NODE_DISABLED_INSTRUMENTATIONS are set', () => { - process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'fs'; - process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'fs'; + 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() + new Set([ + '@opentelemetry/instrumentation-http', + '@opentelemetry/instrumentation-express', + ]) ); } finally { delete process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS;