Skip to content

Commit

Permalink
test(auto-instr-node): show result of setting both env vars (#2325)
Browse files Browse the repository at this point in the history
* 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 <amirgiraffe@gmail.com>
  • Loading branch information
JamieDanielson and blumamir committed Jul 23, 2024
1 parent 8302464 commit 8bcb561
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 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
19 changes: 19 additions & 0 deletions metapackages/auto-instrumentations-node/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 8bcb561

Please sign in to comment.