Skip to content

Commit

Permalink
feat: RD-13918-Disable-ioredis (#538)
Browse files Browse the repository at this point in the history
* feat: Disable ioredis instrumentation env
  • Loading branch information
eugene-lumigo authored Oct 30, 2024
1 parent dc738fe commit f7a04cd
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ This setting is independent from `LUMIGO_DEBUG`, that is, `LUMIGO_DEBUG` does no
* `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_IOREDIS_INSTRUMENTATION=true`: This option disables the automatic instrumentation of [ioredis](https://www.npmjs.com/package/ioredis).
* `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
16 changes: 16 additions & 0 deletions src/instrumentations/ioredis/IORedisInstrumentation.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import LumigoIORedisInstrumentation from './IORedisInstrumentation';
import child_process from 'child_process';

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

beforeEach(() => {
process.env = { ...oldEnv };
});

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

let lumigoIORedisInstrumentation = new LumigoIORedisInstrumentation();

test('getInstrumentedModule should return "ioredis"', () => {
expect(lumigoIORedisInstrumentation.getInstrumentedModule()).toEqual('ioredis');
});

test('disable ioredis instrumentation', () => {
const child_process = require('child_process');
child_process.execSync('npm install ioredis', { stdio: 'inherit' });

process.env.LUMIGO_DISABLE_IOREDIS_INSTRUMENTATION = 'true';
expect(lumigoIORedisInstrumentation.isApplicable()).toEqual(false);
});
});
7 changes: 7 additions & 0 deletions src/instrumentations/ioredis/IORedisInstrumentation.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 LumigoIORedisInstrumentation extends TracingInstrumentor<IORedisInstrumentation> {
override isApplicable(): boolean {
return (
super.isApplicable() &&
process.env.LUMIGO_DISABLE_IOREDIS_INSTRUMENTATION?.toLocaleLowerCase() !== 'true'
);
}

getInstrumentedModule(): string {
return 'ioredis';
}
Expand Down
31 changes: 31 additions & 0 deletions test/instrumentations/ioredis/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ describe.each(versionsToTest(INSTRUMENTATION_NAME, INSTRUMENTATION_NAME))(
});
});

itTest(
{
testName: `${INSTRUMENTATION_NAME} disable works: ${versionToTest}`,
packageName: INSTRUMENTATION_NAME,
version: versionToTest,
timeout: TEST_TIMEOUT,
},
async function () {
const exporterFile = `${SPANS_DIR}/${INSTRUMENTATION_NAME}.disable-works@${versionToTest}.json`;

testApp = new TestApp(TEST_APP_DIR, INSTRUMENTATION_NAME, {
spanDumpPath: exporterFile,
env: { OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT: '4096', LUMIGO_DISABLE_IOREDIS_INSTRUMENTATION: 'true'}
});

const key = 'test:set-and-get';
const value = 'test-set-and-get-value';
const host = redisContainer.getHost();
const port = redisContainer.getMappedPort(DEFAULT_REDIS_PORT);
await testApp.invokeGetPath(`/set?key=${key}&value=${value}&host=${host}&port=${port}`);

await testApp.invokeGetPath(`/get?key=${key}&value=${value}&host=${host}&port=${port}`);

const spans = await testApp.getFinalSpans(2);

const redisSpans = filterRedisSpans(spans);
expect(redisSpans).toHaveLength(0);

}
);

itTest(
{
testName: `${INSTRUMENTATION_NAME} set and get: ${versionToTest}`,
Expand Down
30 changes: 30 additions & 0 deletions test/instrumentations/redis/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,36 @@ describe.each(versionsToTest(INSTRUMENTATION_NAME, INSTRUMENTATION_NAME))(
});
});

itTest(
{
testName: `${INSTRUMENTATION_NAME} disable works: ${versionToTest}`,
packageName: INSTRUMENTATION_NAME,
version: versionToTest,
timeout: TEST_TIMEOUT,
},
async function () {
const exporterFile = `${SPANS_DIR}/${INSTRUMENTATION_NAME}.disable-works@${versionToTest}.json`;

testApp = new TestApp(TEST_APP_DIR, INSTRUMENTATION_NAME, { spanDumpPath: exporterFile, env: {
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT: '4096',
LUMIGO_DISABLE_REDIS_INSTRUMENTATION: 'true',
}});

const key = 'test:set-and-get';
const value = 'test-set-and-get-value';
const host = redisContainer.getHost();
const port = redisContainer.getMappedPort(DEFAULT_REDIS_PORT);
await testApp.invokeGetPath(`/set?key=${key}&value=${value}&host=${host}&port=${port}`);

await testApp.invokeGetPath(`/get?key=${key}&value=${value}&host=${host}&port=${port}`);

const spans = await testApp.getFinalSpans(2);

const redisSpans = filterRedisSpans(spans);
expect(redisSpans).toHaveLength(0);
}
);

itTest(
{
testName: `${INSTRUMENTATION_NAME} set and get: ${versionToTest}`,
Expand Down

0 comments on commit f7a04cd

Please sign in to comment.