diff --git a/README.md b/README.md index b4787c79..0c018de5 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ This setting is independent from `LUMIGO_DEBUG`, that is, `LUMIGO_DEBUG` does no * `LUMIGO_REPORT_DEPENDENCIES=false`: This option disables the built-in dependency reporting to Lumigo SaaS. For more information, refer to the [Automated dependency reporting](#automated-dependency-reporting) section. * `LUMIGO_SWITCH_OFF=TRUE`: This option disables the Lumigo OpenTelemetry Distro entirely; no instrumentation will be injected, no tracing data will be collected. * `LUMIGO_AUTO_FILTER_EMPTY_SQS`: This option enables the automatic filtering of empty SQS messages from being sent to Lumigo SaaS. For more information, refer to the [Filtering out empty SQS messages](#filtering-out-empty-sqs-messages) section. +* `LUMIGO_DISABLE_PG_INSTRUMENTATION=true`: This option disables the automatic instrumentation of [postgres](https://www.npmjs.com/package/pg). +* `LUMIGO_DISABLE_NEST_INSTRUMENTATION=true`: This option disables the automatic instrumentation of [@nestjs/core](https://www.npmjs.com/package/@nestjs/core). * `LUMIGO_SECRET_MASKING_REGEX='["regex1", "regex2"]'`: Prevents Lumigo from sending keys that match the supplied regular expressions in process environment data, HTTP headers, payloads and queries. All regular expressions are case-insensitive. The "magic" value `all` will redact everything. By default, Lumigo applies the following regular expressions: `[".*pass.*", ".*key.*", ".*secret.*", ".*credential.*", ".*passphrase.*"]`. More fine-grained settings can be applied via the following environment variables, which will override `LUMIGO_SECRET_MASKING_REGEX` for a specific type of data: * `LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_BODIES` applies secret redaction to HTTP request bodies * `LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_HEADERS` applies secret redaction to HTTP request headers diff --git a/src/instrumentations/@nestjs/core/NestInstrumentation.ts b/src/instrumentations/@nestjs/core/NestInstrumentation.ts index c15a5f3b..d33b0f54 100644 --- a/src/instrumentations/@nestjs/core/NestInstrumentation.ts +++ b/src/instrumentations/@nestjs/core/NestInstrumentation.ts @@ -2,6 +2,13 @@ import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core' import { Instrumentor } from '../../instrumentor'; export default class LumigoNestInstrumentation extends Instrumentor { + override isApplicable(): boolean { + return ( + super.isApplicable() && + process.env.LUMIGO_DISABLE_NEST_INSTRUMENTATION?.toLocaleLowerCase() !== 'true' + ); + } + getInstrumentedModule(): string { return '@nestjs/core'; } diff --git a/src/instrumentations/pg/PgInstrumentation.test.js b/src/instrumentations/pg/PgInstrumentation.test.js index 04bc2782..57161993 100644 --- a/src/instrumentations/pg/PgInstrumentation.test.js +++ b/src/instrumentations/pg/PgInstrumentation.test.js @@ -1,12 +1,27 @@ import LumigoPgInstrumentation from './PgInstrumentation'; +import child_process from 'child_process'; describe('LumigoPgInstrumentation', () => { + const oldEnv = Object.assign({}, process.env); + beforeEach(() => { + process.env = { ...oldEnv }; + }); + afterEach(() => { jest.clearAllMocks(); + process.env = { ...oldEnv }; }); let lumigoPgInstrumentation = new LumigoPgInstrumentation(); + test('disable pg instrumentation', () => { + const child_process = require('child_process'); + child_process.execSync('npm install pg', { stdio: 'inherit' }); + + process.env.LUMIGO_DISABLE_PG_INSTRUMENTATION = 'true'; + expect(lumigoPgInstrumentation.isApplicable()).toEqual(false); + }); + test('getInstrumentedModule should return "pg"', () => { expect(lumigoPgInstrumentation.getInstrumentedModule()).toEqual('pg'); }); diff --git a/src/instrumentations/pg/PgInstrumentation.ts b/src/instrumentations/pg/PgInstrumentation.ts index 581ae3cf..fe2de7a6 100644 --- a/src/instrumentations/pg/PgInstrumentation.ts +++ b/src/instrumentations/pg/PgInstrumentation.ts @@ -2,6 +2,13 @@ import { PgInstrumentation } from '@opentelemetry/instrumentation-pg'; import { Instrumentor } from '../instrumentor'; export default class LumigoPgInstrumentation extends Instrumentor { + override isApplicable(): boolean { + return ( + super.isApplicable() && + process.env.LUMIGO_DISABLE_PG_INSTRUMENTATION?.toLocaleLowerCase() !== 'true' + ); + } + getInstrumentedModule(): string { return 'pg'; }