Skip to content

Commit

Permalink
update to more reliable test and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieDanielson committed Jul 17, 2024
1 parent 3f930c3 commit e83c0ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions metapackages/auto-instrumentations-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion metapackages/auto-instrumentations-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}

Expand Down
11 changes: 7 additions & 4 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e83c0ae

Please sign in to comment.