From 8907b2b6e2aaaa00155dff333ae67baaa9b29480 Mon Sep 17 00:00:00 2001 From: Max Komarychev Date: Thu, 12 Oct 2023 16:57:14 +0200 Subject: [PATCH] feat: allow disabling auto-instrumentations using env variable While I am pretty happy with provided default instrumentations I would like to be able to disable some of them based on environment variables alone without getting into business of configuring integration manually --- .../auto-instrumentations-node/src/register.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/metapackages/auto-instrumentations-node/src/register.ts b/metapackages/auto-instrumentations-node/src/register.ts index a14538da66..5b57d45d0a 100644 --- a/metapackages/auto-instrumentations-node/src/register.ts +++ b/metapackages/auto-instrumentations-node/src/register.ts @@ -25,8 +25,17 @@ diag.setLogger( opentelemetry.core.getEnv().OTEL_LOG_LEVEL ); +const disabledAutoinstrumentations = ( + process.env.OTEL_DISABLED_AUTOINSTRUMENTATIONS ?? '' +).split(','); + const sdk = new opentelemetry.NodeSDK({ - instrumentations: getNodeAutoInstrumentations(), + instrumentations: getNodeAutoInstrumentations( + Object.fromEntries( + disabledAutoinstrumentations.map(instrumentationName => + [instrumentationName, { enabled: false }] + )) + ), resourceDetectors: getResourceDetectorsFromEnv(), });