Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions metapackages/auto-instrumentations-node/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ export function getNodeAutoInstrumentations(
const enabledInstrumentationsFromEnv = getEnabledInstrumentationsFromEnv();
const disabledInstrumentationsFromEnv = getDisabledInstrumentationsFromEnv();

if (enabledInstrumentationsFromEnv && disabledInstrumentationsFromEnv) {
diag.debug(
'OTEL_NODE_ENABLED_INSTRUMENTATIONS and OTEL_NODE_DISABLED_INSTRUMENTATIONS environment variables are mutually exclusive. All instrumentations are disabled.'
);
}

const instrumentations: Instrumentation[] = [];

for (const name of Object.keys(InstrumentationMap) as Array<
Expand Down
16 changes: 16 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,22 @@ 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';
try {
const instrumentations = getNodeAutoInstrumentations();

assert.deepStrictEqual(
new Set(instrumentations.map(i => i.instrumentationName)),
new Set()
);
} 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