diff --git a/README.md b/README.md index 16f2e96e..76e94b71 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/instrumentations/redis/RedisInstrumentation.test.js b/src/instrumentations/redis/RedisInstrumentation.test.js index c9d47f11..3f951d13 100644 --- a/src/instrumentations/redis/RedisInstrumentation.test.js +++ b/src/instrumentations/redis/RedisInstrumentation.test.js @@ -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); }); }); diff --git a/src/instrumentations/redis/RedisInstrumentation.ts b/src/instrumentations/redis/RedisInstrumentation.ts index 40306764..9dbb9b8e 100644 --- a/src/instrumentations/redis/RedisInstrumentation.ts +++ b/src/instrumentations/redis/RedisInstrumentation.ts @@ -5,6 +5,13 @@ import { getSpanAttributeMaxLength } from '../../utils'; import { TracingInstrumentor } from '../instrumentor'; export default class LumigoRedisInstrumentation extends TracingInstrumentor { + override isApplicable(): boolean { + return ( + super.isApplicable() && + process.env.LUMIGO_DISABLE_REDIS_INSTRUMENTATION?.toLocaleLowerCase() !== 'true' + ); + } + getInstrumentedModule(): string { return 'redis'; }