Skip to content

Commit d073ef7

Browse files
chargomeclaude
andcommitted
feat(server-utils): Migrate @opentelemetry/instrumentation-redis to orchestrion
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 851edb3 commit d073ef7

10 files changed

Lines changed: 928 additions & 105 deletions

File tree

dev-packages/node-integration-tests/suites/tracing/redis-cache/test.ts

Lines changed: 107 additions & 88 deletions
Large diffs are not rendered by default.

packages/node/src/integrations/tracing/redis/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const instrumentRedisModule = generateInstrumentOnce(`${INTEGRATION_NAME}.Redis`
3333
*/
3434
export const instrumentRedis = Object.assign(
3535
(): void => {
36-
// When diagnostics-channel injection is opted in, orchestrion owns ioredis
37-
// `<5.11.0`, so skip the OTel ioredis monkey-patch to avoid double instrumentation.
38-
// On Node without `tracingChannel` (<18.19) orchestrion can't run, so keep the
39-
// OTel patch there — otherwise ioredis `<5.11.0` would not be traced at all.
36+
// When diagnostics-channel injection is opted in, orchestrion fully owns the older
37+
// ioredis (`<5.11.0`) and redis/node-redis (`<5.12.0`) ranges — commands, connect, and
38+
// batches — so skip both OTel monkey-patches to avoid double instrumentation. On Node
39+
// without `tracingChannel` (<18.19) orchestrion can't run, so keep the OTel patches there.
4040
if (!isDiagnosticsChannelInjectionEnabled() || !dc.tracingChannel) {
4141
instrumentIORedis();
42+
instrumentRedisModule();
4243
}
43-
instrumentRedisModule();
4444
// node-redis >= 5.12.0 and ioredis >= 5.11.0 publish via diagnostics_channel.
4545
// `bindTracingChannelToSpan` (inside the subscriber) makes the span the active
4646
// OTel context via `bindStore`, which needs the Sentry OTel context manager to

packages/node/src/sdk/experimentalUseDiagnosticsChannelInjection.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
channelIntegrations,
33
ioredisChannelIntegration,
4+
redisChannelIntegration,
45
detectOrchestrionSetup,
56
} from '@sentry/server-utils/orchestrion';
67
import { registerDiagnosticsChannelInjection } from '@sentry/server-utils/orchestrion/register';
@@ -51,12 +52,14 @@ export function experimentalUseDiagnosticsChannelInjection(): void {
5152
const replacedOtelIntegrationNames = integrations.map(i => i.name);
5253

5354
return {
54-
// ioredis is wired here rather than in the shared `channelIntegrations` registry: it needs
55-
// the node redis cache `responseHook`, and it only partially replaces the composite OTel
56-
// `Redis` integration (which also covers node-redis and ioredis >=5.11 native diagnostics_channel).
57-
// So it's added to the integration set but kept OUT of `replacedOtelIntegrationNames` — `Redis`
58-
// must stay; its ioredis <5.11 monkey-patch is gated off in `redisIntegration` instead.
59-
integrations: [...integrations, ioredisChannelIntegration({ responseHook: cacheResponseHook })],
55+
// ioredis and redis are wired separately (not in `channelIntegrations`): they need the node
56+
// redis cache `responseHook` and only partially replace the composite OTel `Redis` integration,
57+
// so they're kept OUT of `replacedOtelIntegrationNames` — `Redis` must stay (batch + >=5.11 native DC).
58+
integrations: [
59+
...integrations,
60+
ioredisChannelIntegration({ responseHook: cacheResponseHook }),
61+
redisChannelIntegration({ responseHook: cacheResponseHook }),
62+
],
6063
replacedOtelIntegrationNames,
6164
register: registerDiagnosticsChannelInjection,
6265
detect: detectOrchestrionSetup,

packages/node/test/integrations/tracing/redis-ioredis-gating.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ describe('instrumentRedis ioredis gating', () => {
4242
expect(instrumentCalls).toContain('Redis.Redis');
4343
});
4444

45-
it('skips the OTel ioredis monkey-patch when diagnostics-channel injection is enabled', () => {
45+
it('skips both OTel monkey-patches when diagnostics-channel injection is enabled', () => {
4646
injection.enabled = true;
4747

4848
instrumentRedis();
4949

50-
// ioredis is owned by orchestrion; node-redis is still instrumented by OTel.
5150
expect(instrumentCalls).not.toContain('Redis.IORedis');
52-
expect(instrumentCalls).toContain('Redis.Redis');
51+
expect(instrumentCalls).not.toContain('Redis.Redis');
5352
});
5453
});

0 commit comments

Comments
 (0)