Skip to content

Commit ac59e7e

Browse files
s1gr1dmydea
andauthored
feat(ioredis): Add integration for ioredis (#11856)
Integration for Node `integrations: [Sentry.experimental_redisIntegration()]` --------- Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
1 parent 85da8cf commit ac59e7e

File tree

15 files changed

+221
-1
lines changed

15 files changed

+221
-1
lines changed

MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ We now support the following integrations out of the box without extra configura
351351
- `mongooseIntegration`: Automatically instruments Mongoose
352352
- `mysqlIntegration`: Automatically instruments MySQL
353353
- `mysql2Integration`: Automatically instruments MySQL2
354+
- `redisIntegration`: Automatically instruments Redis (supported clients: ioredis)
354355
- `nestIntegration`: Automatically instruments Nest.js
355356
- `postgresIntegration`: Automatically instruments PostgreSQL
356357
- `prismaIntegration`: Automatically instruments Prisma

dev-packages/node-integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"express": "^4.17.3",
4545
"graphql": "^16.3.0",
4646
"http-terminator": "^3.2.0",
47+
"ioredis": "^5.4.1",
4748
"mongodb": "^3.7.3",
4849
"mongodb-memory-server-global": "^7.6.3",
4950
"mongoose": "^5.13.22",
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3.9'
2+
3+
services:
4+
db:
5+
image: redis:latest
6+
restart: always
7+
container_name: integration-tests-redis
8+
ports:
9+
- '6379:6379'
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2+
const Sentry = require('@sentry/node');
3+
4+
Sentry.init({
5+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});
10+
11+
// Stop the process from exiting before the transaction is sent
12+
setInterval(() => {}, 1000);
13+
14+
const Redis = require('ioredis');
15+
16+
const redis = new Redis({ port: 6379 });
17+
18+
async function run() {
19+
await Sentry.startSpan(
20+
{
21+
name: 'Test Transaction',
22+
op: 'transaction',
23+
},
24+
async () => {
25+
try {
26+
await redis.set('test-key', 'test-value');
27+
28+
await redis.get('test-key');
29+
} finally {
30+
await redis.disconnect();
31+
}
32+
},
33+
);
34+
}
35+
36+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
37+
run();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
2+
3+
describe('redis auto instrumentation', () => {
4+
afterAll(() => {
5+
cleanupChildProcesses();
6+
});
7+
8+
test('should auto-instrument `ioredis` package when using redis.set() and redis.get()', done => {
9+
const EXPECTED_TRANSACTION = {
10+
transaction: 'Test Transaction',
11+
spans: expect.arrayContaining([
12+
expect.objectContaining({
13+
description: 'set test-key [1 other arguments]',
14+
op: 'db',
15+
data: expect.objectContaining({
16+
'db.system': 'redis',
17+
'net.peer.name': 'localhost',
18+
'net.peer.port': 6379,
19+
'db.statement': 'set test-key [1 other arguments]',
20+
}),
21+
}),
22+
expect.objectContaining({
23+
description: 'get test-key',
24+
op: 'db',
25+
data: expect.objectContaining({
26+
'db.system': 'redis',
27+
'net.peer.name': 'localhost',
28+
'net.peer.port': 6379,
29+
'db.statement': 'get test-key',
30+
}),
31+
}),
32+
]),
33+
};
34+
35+
createRunner(__dirname, 'scenario-ioredis.js')
36+
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port=6379'] })
37+
.expect({ transaction: EXPECTED_TRANSACTION })
38+
.start(done);
39+
});
40+
});

packages/astro/src/index.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export {
8080
mongooseIntegration,
8181
mysqlIntegration,
8282
mysql2Integration,
83+
redisIntegration,
8384
nestIntegration,
8485
setupNestErrorHandler,
8586
postgresIntegration,

packages/aws-serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export {
8585
mongooseIntegration,
8686
mysqlIntegration,
8787
mysql2Integration,
88+
redisIntegration,
8889
nestIntegration,
8990
setupNestErrorHandler,
9091
postgresIntegration,

packages/bun/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export {
106106
mongooseIntegration,
107107
mysqlIntegration,
108108
mysql2Integration,
109+
redisIntegration,
109110
nestIntegration,
110111
setupNestErrorHandler,
111112
postgresIntegration,

packages/google-cloud-serverless/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export {
8585
mongooseIntegration,
8686
mysqlIntegration,
8787
mysql2Integration,
88+
redisIntegration,
8889
nestIntegration,
8990
setupNestErrorHandler,
9091
postgresIntegration,

packages/node/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"@opentelemetry/instrumentation-graphql": "0.39.0",
6464
"@opentelemetry/instrumentation-hapi": "0.36.0",
6565
"@opentelemetry/instrumentation-http": "0.48.0",
66+
"@opentelemetry/instrumentation-ioredis": "0.40.0",
6667
"@opentelemetry/instrumentation-koa": "0.39.0",
6768
"@opentelemetry/instrumentation-mongodb": "0.39.0",
6869
"@opentelemetry/instrumentation-mongoose": "0.37.0",

0 commit comments

Comments
 (0)