-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redis-cache): Create cache-span with prefixed keys (get/set comm…
…ands) (#12070) Populates the OTel span with cache attributes. Currently, `get` and `set` commands are considered. --------- Co-authored-by: Francesco Novy <francesco.novy@sentry.io>
- Loading branch information
Showing
7 changed files
with
231 additions
and
6 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/redis-cache/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: '3.9' | ||
|
||
services: | ||
db: | ||
image: redis:latest | ||
restart: always | ||
container_name: integration-tests-redis | ||
ports: | ||
- '6379:6379' |
41 changes: 41 additions & 0 deletions
41
dev-packages/node-integration-tests/suites/tracing/redis-cache/scenario-ioredis.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { loggingTransport } = require('@sentry-internal/node-integration-tests'); | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
release: '1.0', | ||
tracesSampleRate: 1.0, | ||
transport: loggingTransport, | ||
integrations: [Sentry.redisIntegration({ cachePrefixes: ['ioredis-cache:'] })], | ||
}); | ||
|
||
// Stop the process from exiting before the transaction is sent | ||
setInterval(() => {}, 1000); | ||
|
||
const Redis = require('ioredis'); | ||
|
||
const redis = new Redis({ port: 6379 }); | ||
|
||
async function run() { | ||
await Sentry.startSpan( | ||
{ | ||
name: 'Test Span', | ||
op: 'test-span', | ||
}, | ||
async () => { | ||
try { | ||
await redis.set('test-key', 'test-value'); | ||
await redis.set('ioredis-cache:test-key', 'test-value'); | ||
|
||
await redis.get('test-key'); | ||
await redis.get('ioredis-cache:test-key'); | ||
await redis.get('ioredis-cache:unavailable-data'); | ||
} finally { | ||
await redis.disconnect(); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
run(); |
92 changes: 92 additions & 0 deletions
92
dev-packages/node-integration-tests/suites/tracing/redis-cache/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
||
describe('redis auto instrumentation', () => { | ||
afterAll(() => { | ||
cleanupChildProcesses(); | ||
}); | ||
|
||
test('should not add cache spans when key is not prefixed', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Span', | ||
spans: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
description: 'set test-key [1 other arguments]', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'sentry.op': 'db', | ||
'db.system': 'redis', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 6379, | ||
'db.statement': 'set test-key [1 other arguments]', | ||
}), | ||
}), | ||
expect.objectContaining({ | ||
description: 'get test-key', | ||
op: 'db', | ||
data: expect.objectContaining({ | ||
'sentry.op': 'db', | ||
'db.system': 'redis', | ||
'net.peer.name': 'localhost', | ||
'net.peer.port': 6379, | ||
'db.statement': 'get test-key', | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario-ioredis.js') | ||
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port=6379'] }) | ||
.expect({ transaction: EXPECTED_TRANSACTION }) | ||
.start(done); | ||
}); | ||
|
||
test('should create cache spans for prefixed keys', done => { | ||
const EXPECTED_TRANSACTION = { | ||
transaction: 'Test Span', | ||
spans: expect.arrayContaining([ | ||
// SET | ||
expect.objectContaining({ | ||
description: 'set ioredis-cache:test-key [1 other arguments]', | ||
op: 'cache.put', | ||
data: expect.objectContaining({ | ||
'db.statement': 'set ioredis-cache:test-key [1 other arguments]', | ||
'cache.key': 'ioredis-cache:test-key', | ||
'cache.item_size': 2, | ||
'network.peer.address': 'localhost', | ||
'network.peer.port': 6379, | ||
}), | ||
}), | ||
// GET | ||
expect.objectContaining({ | ||
description: 'get ioredis-cache:test-key', | ||
op: 'cache.get_item', // todo: will be changed to cache.get | ||
data: expect.objectContaining({ | ||
'db.statement': 'get ioredis-cache:test-key', | ||
'cache.hit': true, | ||
'cache.key': 'ioredis-cache:test-key', | ||
'cache.item_size': 10, | ||
'network.peer.address': 'localhost', | ||
'network.peer.port': 6379, | ||
}), | ||
}), | ||
// GET (unavailable) | ||
expect.objectContaining({ | ||
description: 'get ioredis-cache:unavailable-data', | ||
op: 'cache.get_item', // todo: will be changed to cache.get | ||
data: expect.objectContaining({ | ||
'db.statement': 'get ioredis-cache:unavailable-data', | ||
'cache.hit': false, | ||
'cache.key': 'ioredis-cache:unavailable-data', | ||
'network.peer.address': 'localhost', | ||
'network.peer.port': 6379, | ||
}), | ||
}), | ||
]), | ||
}; | ||
|
||
createRunner(__dirname, 'scenario-ioredis.js') | ||
.withDockerCompose({ workingDirectory: [__dirname], readyMatches: ['port=6379'] }) | ||
.expect({ transaction: EXPECTED_TRANSACTION }) | ||
.start(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters