Skip to content

Commit

Permalink
feat: Disable redis instrumentation env
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Orlovsky committed Oct 17, 2024
1 parent d2a63e0 commit 16c8db8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ This setting is independent from `LUMIGO_DEBUG`, that is, `LUMIGO_DEBUG` does no
* `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_REDIS_INSTRUMENTATION=true`: This option disables the automatic instrumentation of [redis](https://www.npmjs.com/package/redis).
* `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
Expand Down
18 changes: 17 additions & 1 deletion src/instrumentations/redis/RedisInstrumentation.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import LumigoRedisInstrumentation from './RedisInstrumentation';
import child_process from 'child_process';

describe('LumigoRedisInstrumentation', () => {
const oldEnv = Object.assign({}, process.env);
beforeEach(() => {
process.env = { ...oldEnv };
});

afterEach(() => {
jest.clearAllMocks();
process.env = { ...oldEnv };
});

let lumigoRedisInstrumentation = new LumigoRedisInstrumentation();

test('getInstrumentedModule should return "redis"', () => {
test('disable redis instrumentation', () => {
const child_process = require('child_process');
child_process.execSync('npm install redis@4.0.0', { stdio: 'inherit' });

process.env.LUMIGO_DISABLE_REDIS_INSTRUMENTATION = 'true';
expect(lumigoRedisInstrumentation.isApplicable()).toEqual(false);
});

test('getInstrumentedModule should return "redis and be applicable"', () => {
expect(lumigoRedisInstrumentation.getInstrumentedModule()).toEqual('redis');
expect(lumigoRedisInstrumentation.isApplicable()).toEqual(true);
});
});
7 changes: 7 additions & 0 deletions src/instrumentations/redis/RedisInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { getSpanAttributeMaxLength } from '../../utils';
import { TracingInstrumentor } from '../instrumentor';

export default class LumigoRedisInstrumentation extends TracingInstrumentor<RedisInstrumentation> {
override isApplicable(): boolean {
return (
super.isApplicable() &&
process.env.LUMIGO_DISABLE_REDIS_INSTRUMENTATION?.toLocaleLowerCase() !== 'true'
);
}

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

0 comments on commit 16c8db8

Please sign in to comment.