Skip to content

Commit

Permalink
feat: allow disabling postgres, nestjs automatic instrumentation thro…
Browse files Browse the repository at this point in the history
…ugh env-var (#355)
  • Loading branch information
GuyMoses authored May 16, 2024
1 parent 7c9eaa6 commit b4d505f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/instrumentations/@nestjs/core/NestInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core'
import { Instrumentor } from '../../instrumentor';

export default class LumigoNestInstrumentation extends Instrumentor<NestInstrumentation> {
override isApplicable(): boolean {
return (
super.isApplicable() &&
process.env.LUMIGO_DISABLE_NEST_INSTRUMENTATION?.toLocaleLowerCase() !== 'true'
);
}

getInstrumentedModule(): string {
return '@nestjs/core';
}
Expand Down
15 changes: 15 additions & 0 deletions src/instrumentations/pg/PgInstrumentation.test.js
Original file line number Diff line number Diff line change
@@ -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');
});
Expand Down
7 changes: 7 additions & 0 deletions src/instrumentations/pg/PgInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
import { Instrumentor } from '../instrumentor';

export default class LumigoPgInstrumentation extends Instrumentor<PgInstrumentation> {
override isApplicable(): boolean {
return (
super.isApplicable() &&
process.env.LUMIGO_DISABLE_PG_INSTRUMENTATION?.toLocaleLowerCase() !== 'true'
);
}

getInstrumentedModule(): string {
return 'pg';
}
Expand Down

0 comments on commit b4d505f

Please sign in to comment.