-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node): use diagnostics_channel for redis >= 5.12.0 #20573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2caff89
feat(node): use diagnostics_channel for redis >= 5.12.0
logaretm 5097358
fix: lint and format
logaretm 7b5e466
test: add redis 5 integration test
isaacs 2b84a64
fix: hyphenation in span origin
logaretm 629eb8c
fix(test): update MGET assertion for sanitized DC args
logaretm fe58449
fix(node): stop overriding span origin in cacheResponseHook
logaretm 7cabfb8
refactor(node): set sentry.origin at span creation in vendored redis …
logaretm 3c568bb
fix(test): defer redis-5 require so DC subscriber registers before co…
logaretm 6fd04e5
fix(node): avoid double-end on error in redis dc instrumentation
isaacs 78b2244
fix(test): add unit test for redis-dc
isaacs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
15 changes: 15 additions & 0 deletions
15
dev-packages/node-integration-tests/suites/tracing/redis-dc/docker-compose.yml
This file contains hidden or 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,15 @@ | ||
| version: '3.9' | ||
|
|
||
| services: | ||
| db: | ||
| image: redis:latest | ||
| restart: always | ||
| container_name: integration-tests-redis-dc | ||
| ports: | ||
| - '6379:6379' | ||
| healthcheck: | ||
| test: ['CMD-SHELL', 'redis-cli ping | grep -q PONG'] | ||
| interval: 2s | ||
| timeout: 3s | ||
| retries: 30 | ||
| start_period: 5s |
47 changes: 47 additions & 0 deletions
47
dev-packages/node-integration-tests/suites/tracing/redis-dc/scenario-redis-5.js
This file contains hidden or 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,47 @@ | ||
| 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: ['dc-cache:'] })], | ||
| }); | ||
|
|
||
| // Stop the process from exiting before the transaction is sent | ||
| setInterval(() => {}, 1000); | ||
|
|
||
| async function run() { | ||
| // Yield a microtick so the DC subscriber (deferred via Promise.resolve().then) | ||
| // is registered before node-redis eagerly creates its native TracingChannels on require(). | ||
| await Promise.resolve(); | ||
|
|
||
| const { createClient } = require('redis-5'); | ||
| const redisClient = await createClient({ socket: { host: '127.0.0.1', port: 6379 } }).connect(); | ||
|
|
||
| await Sentry.startSpan( | ||
| { | ||
| name: 'Test Span Redis 5 DC', | ||
| op: 'test-span-redis-5-dc', | ||
| }, | ||
| async () => { | ||
| try { | ||
| await redisClient.set('dc-test-key', 'test-value'); | ||
| await redisClient.set('dc-cache:test-key', 'test-value'); | ||
|
|
||
| await redisClient.set('dc-cache:test-key-ex', 'test-value', { EX: 10 }); | ||
|
|
||
| await redisClient.get('dc-test-key'); | ||
| await redisClient.get('dc-cache:test-key'); | ||
| await redisClient.get('dc-cache:unavailable-data'); | ||
|
|
||
| await redisClient.mGet(['dc-test-key', 'dc-cache:test-key', 'dc-cache:unavailable-data']); | ||
| } finally { | ||
| await redisClient.disconnect(); | ||
| } | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| run(); |
110 changes: 110 additions & 0 deletions
110
dev-packages/node-integration-tests/suites/tracing/redis-dc/test.ts
This file contains hidden or 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,110 @@ | ||
| import { afterAll, describe, expect, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
|
||
| describe('redis v5 diagnostics_channel auto instrumentation', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('should create spans for redis v5 commands via diagnostics_channel', { timeout: 60_000 }, async () => { | ||
| const EXPECTED_TRANSACTION = { | ||
| transaction: 'Test Span Redis 5 DC', | ||
| spans: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| op: 'db.redis', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'db.redis', | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'SET dc-test-key [1 other arguments]', | ||
| }), | ||
| }), | ||
| // cache SET: span name updated to key by cacheResponseHook | ||
| expect.objectContaining({ | ||
| description: 'dc-cache:test-key', | ||
| op: 'cache.put', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.statement': 'SET dc-cache:test-key [1 other arguments]', | ||
| 'cache.key': ['dc-cache:test-key'], | ||
| 'cache.item_size': 2, | ||
| }), | ||
| }), | ||
| // cache SET with EX option: redis v5 sends SET key value EX 10 as the command | ||
| expect.objectContaining({ | ||
| description: 'dc-cache:test-key-ex', | ||
| op: 'cache.put', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.statement': 'SET dc-cache:test-key-ex [3 other arguments]', | ||
| 'cache.key': ['dc-cache:test-key-ex'], | ||
| 'cache.item_size': 2, | ||
| }), | ||
| }), | ||
| expect.objectContaining({ | ||
| op: 'db.redis', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'db.redis', | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'GET dc-test-key', | ||
| }), | ||
| }), | ||
| // cache GET (hit) | ||
| expect.objectContaining({ | ||
| description: 'dc-cache:test-key', | ||
| op: 'cache.get', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.statement': 'GET dc-cache:test-key', | ||
| 'cache.hit': true, | ||
| 'cache.key': ['dc-cache:test-key'], | ||
| 'cache.item_size': 10, | ||
| }), | ||
| }), | ||
| // cache GET (miss) | ||
| expect.objectContaining({ | ||
| description: 'dc-cache:unavailable-data', | ||
| op: 'cache.get', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.statement': 'GET dc-cache:unavailable-data', | ||
| 'cache.hit': false, | ||
| 'cache.key': ['dc-cache:unavailable-data'], | ||
| }), | ||
| }), | ||
| // MGET: node-redis sanitizes args for diagnostics_channel (keys become '?'), | ||
| // so cache detection cannot match prefixes — remains a plain db.redis span. | ||
| expect.objectContaining({ | ||
| op: 'db.redis', | ||
| origin: 'auto.db.redis.diagnostic_channel', | ||
| data: expect.objectContaining({ | ||
| 'sentry.op': 'db.redis', | ||
| 'sentry.origin': 'auto.db.redis.diagnostic_channel', | ||
| 'db.system': 'redis', | ||
| 'db.statement': 'MGET [3 other arguments]', | ||
| }), | ||
| }), | ||
| ]), | ||
| }; | ||
|
|
||
| // node-redis emits a node-redis:connect DC event for the initial connection. | ||
| // That fires before startSpan so it arrives as the first envelope. | ||
| const EXPECTED_CONNECT = { | ||
| transaction: 'redis-connect', | ||
| }; | ||
|
|
||
| await createRunner(__dirname, 'scenario-redis-5.js') | ||
| .withDockerCompose({ workingDirectory: [__dirname] }) | ||
| .expect({ transaction: EXPECTED_CONNECT }) | ||
| .expect({ transaction: EXPECTED_TRANSACTION }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.