-
-
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
base: isaacs/vendor-redis
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,224 @@ | ||||||||
| import type { Span } from '@opentelemetry/api'; | ||||||||
| import { | ||||||||
| SEMANTIC_ATTRIBUTE_SENTRY_OP, | ||||||||
| SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, | ||||||||
| SPAN_STATUS_ERROR, | ||||||||
| startSpanManual, | ||||||||
| } from '@sentry/core'; | ||||||||
| import { tracingChannel, type TracingChannelContextWithSpan } from '@sentry/opentelemetry/tracing-channel'; | ||||||||
| import { defaultDbStatementSerializer } from './vendored/redis-common'; | ||||||||
| import { | ||||||||
| ATTR_DB_STATEMENT, | ||||||||
| ATTR_DB_SYSTEM, | ||||||||
| ATTR_NET_PEER_NAME, | ||||||||
| ATTR_NET_PEER_PORT, | ||||||||
| DB_SYSTEM_VALUE_REDIS, | ||||||||
| } from './vendored/semconv'; | ||||||||
| import type { IORedisInstrumentationConfig } from './vendored/types'; | ||||||||
|
|
||||||||
| // Channel names as published by node-redis >= 5.12.0. | ||||||||
| // Hardcoded so we don't import `redis` at module-load time. | ||||||||
| const CHANNEL_COMMAND = 'node-redis:command'; | ||||||||
| const CHANNEL_BATCH = 'node-redis:batch'; | ||||||||
| const CHANNEL_CONNECT = 'node-redis:connect'; | ||||||||
|
|
||||||||
| const ORIGIN = 'auto.db.redis.diagnostic-channel'; | ||||||||
|
|
||||||||
| interface CommandData { | ||||||||
| command: string; | ||||||||
| args: Array<string | Buffer>; | ||||||||
| database?: number; | ||||||||
| serverAddress?: string; | ||||||||
| serverPort?: number; | ||||||||
| result?: unknown; | ||||||||
| error?: Error; | ||||||||
| } | ||||||||
|
|
||||||||
| interface BatchData { | ||||||||
| batchMode?: 'MULTI' | 'PIPELINE'; | ||||||||
| batchSize?: number; | ||||||||
| database?: number; | ||||||||
| clientId?: string | number; | ||||||||
| serverAddress?: string; | ||||||||
| serverPort?: number; | ||||||||
| result?: unknown[]; | ||||||||
| error?: Error; | ||||||||
| } | ||||||||
|
|
||||||||
| interface ConnectData { | ||||||||
| serverAddress?: string; | ||||||||
| serverPort?: number; | ||||||||
| url?: string; | ||||||||
| error?: Error; | ||||||||
| } | ||||||||
|
|
||||||||
| const NOOP = (): void => {}; | ||||||||
|
|
||||||||
| let subscribed = false; | ||||||||
| let currentResponseHook: IORedisInstrumentationConfig['responseHook'] | undefined; | ||||||||
|
|
||||||||
| /** | ||||||||
| * Subscribe Sentry handlers to node-redis diagnostics_channel events (>= 5.12.0). | ||||||||
| * | ||||||||
| * Uses `@sentry/opentelemetry/tracing-channel` so OTel AsyncLocalStorage context propagates | ||||||||
| * automatically via `bindStore` — without it, spans created in `start` would not become | ||||||||
| * the active context for subsequent operations. | ||||||||
| * | ||||||||
| * Safe on every runtime that exposes `node:diagnostics_channel` (Node, Bun, Deno, Workers). | ||||||||
|
||||||||
| * Safe on every runtime that exposes `node:diagnostics_channel` (Node, Bun, Deno, Workers). | |
| * Intended for Node environments where `node:diagnostics_channel` is available. | |
| * On runtimes without the required Node builtins, setup fails closed and no subscribers are registered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No integration or E2E test for new feature
Low Severity
This is a feat PR adding a new diagnostics_channel-based Redis tracing path, but there doesn't appear to be any integration or E2E test covering the new subscribeRedisDiagnosticChannels functionality. The review rules recommend that feat PRs include at least one integration or E2E test.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 291507c. Configure here.
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runResponseHook currently needs an unsafe cast for args to match the hook signature. Since CommandArgs already includes string | Buffer elements, this should be type-compatible without a cast (or you can type currentResponseHook as the redis response hook type). Removing the cast avoids masking real type mismatches.
| hook(span, command, args as unknown as Parameters<typeof hook>[2], result); | |
| hook(span, command, args, result); |
Copilot
AI
Apr 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file exposes _resetRedisDiagnosticChannelsForTesting(), but it only flips flags and does not unsubscribe any handlers already registered with diagnostics_channel. If tests call subscribeRedisDiagnosticChannels() again after a reset, you'll end up with duplicate subscribers (and duplicated spans). Consider keeping references to the subscriber objects (or channel instances) and calling channel.unsubscribe(...) during reset.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Origin value contains invalid hyphen character
Medium Severity
The
ORIGINconstant'auto.db.redis.diagnostic-channel'contains a hyphen (-), which is not permitted in span origins. Per the trace origin specification, origin parts may only contain[a-z],[A-Z],[0-9], and_characters. The hyphen indiagnostic-channelmakes this non-conforming — it likely needs to bediagnostic_channelinstead.Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 291507c. Configure here.