Skip to content

Commit 8bcb561

Browse files
test(auto-instr-node): show result of setting both env vars (#2325)
* test(auto-instr-node): show result of setting both env vars OTEL_NODE_ENABLED_INSTRUMENTATIONS and OTEL_NODE_DISABLED_INSTRUMENTATIONS environment variables are mutually exclusive. All instrumentations are disabled when both are set. * update to more reliable test and update docs * remove unnecessary debug line --------- Co-authored-by: Amir Blum <[email protected]>
1 parent 8302464 commit 8bcb561

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

metapackages/auto-instrumentations-node/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ To disable only [@opentelemetry/instrumentation-fs](https://github.com/open-tele
9797
export OTEL_NODE_DISABLED_INSTRUMENTATIONS="fs"
9898
```
9999

100+
If both environment variables are set, `OTEL_NODE_ENABLED_INSTRUMENTATIONS` is applied first, and then `OTEL_NODE_DISABLED_INSTRUMENTATIONS` is applied to that list.
101+
Therefore, if the same instrumentation is included in both lists, that instrumentation will be disabled.
102+
100103
To enable logging for troubleshooting, set the log level by setting the `OTEL_LOG_LEVEL` environment variable to one of the following:
101104

102105
- `none`

metapackages/auto-instrumentations-node/test/utils.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ describe('utils', () => {
114114
}
115115
});
116116

117+
it('should disable any instrumentations from OTEL_NODE_ENABLED_INSTRUMENTATIONS if set in OTEL_NODE_DISABLED_INSTRUMENTATIONS', () => {
118+
process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS = 'http,express,net';
119+
process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS = 'fs,net'; // fs is no-op here, already disabled
120+
try {
121+
const instrumentations = getNodeAutoInstrumentations();
122+
123+
assert.deepStrictEqual(
124+
new Set(instrumentations.map(i => i.instrumentationName)),
125+
new Set([
126+
'@opentelemetry/instrumentation-http',
127+
'@opentelemetry/instrumentation-express',
128+
])
129+
);
130+
} finally {
131+
delete process.env.OTEL_NODE_DISABLED_INSTRUMENTATIONS;
132+
delete process.env.OTEL_NODE_ENABLED_INSTRUMENTATIONS;
133+
}
134+
});
135+
117136
it('should show error for none existing instrumentation', () => {
118137
const spy = sinon.stub(diag, 'error');
119138
const name = '@opentelemetry/instrumentation-http2';

0 commit comments

Comments
 (0)