@sentry/server-utils 10.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ <p align="center">
2
+ <a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank">
3
+ <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84">
4
+ </a>
5
+ </p>
6
+
7
+ # Sentry JavaScript SDK Server Utilities
8
+
9
+ [![npm version](https://img.shields.io/npm/v/@sentry/server-utils.svg)](https://www.npmjs.com/package/@sentry/server-utils)
10
+ [![npm dm](https://img.shields.io/npm/dm/@sentry/server-utils.svg)](https://www.npmjs.com/package/@sentry/server-utils)
11
+ [![npm dt](https://img.shields.io/npm/dt/@sentry/server-utils.svg)](https://www.npmjs.com/package/@sentry/server-utils)
12
+
13
+ > [!NOTE]
14
+ > This package is an internal library published for use by Sentry-owned JavaScript SDK packages. It is not part of the
15
+ > public API contract and may change in any release. Do not rely on SemVer compatibility if you depend on it directly.
16
+
17
+ ## Links
18
+
19
+ - [Official SDK Docs](https://docs.sentry.io/quickstart/)
20
+
21
+ ## General
22
+
23
+ Common server-only utilities used by the Sentry JavaScript server SDKs (node, node-core, bun, deno, cloudflare,
24
+ aws-serverless, google-cloud-serverless, vercel-edge).
@@ -0,0 +1,6 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
4
+
5
+ exports.DEBUG_BUILD = DEBUG_BUILD;
6
+ //# sourceMappingURL=debug-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":";;AAOO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
@@ -0,0 +1,13 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const redisDcSubscriber = require('./redis/redis-dc-subscriber.js');
4
+
5
+
6
+
7
+ exports.IOREDIS_DC_CHANNEL_COMMAND = redisDcSubscriber.IOREDIS_DC_CHANNEL_COMMAND;
8
+ exports.IOREDIS_DC_CHANNEL_CONNECT = redisDcSubscriber.IOREDIS_DC_CHANNEL_CONNECT;
9
+ exports.REDIS_DC_CHANNEL_BATCH = redisDcSubscriber.REDIS_DC_CHANNEL_BATCH;
10
+ exports.REDIS_DC_CHANNEL_COMMAND = redisDcSubscriber.REDIS_DC_CHANNEL_COMMAND;
11
+ exports.REDIS_DC_CHANNEL_CONNECT = redisDcSubscriber.REDIS_DC_CHANNEL_CONNECT;
12
+ exports.subscribeRedisDiagnosticChannels = redisDcSubscriber.subscribeRedisDiagnosticChannels;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
@@ -0,0 +1,163 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const core = require('@sentry/core');
4
+ const debugBuild = require('../debug-build.js');
5
+
6
+ const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
7
+ const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
8
+ const REDIS_DC_CHANNEL_CONNECT = "node-redis:connect";
9
+ const IOREDIS_DC_CHANNEL_COMMAND = "ioredis:command";
10
+ const IOREDIS_DC_CHANNEL_CONNECT = "ioredis:connect";
11
+ const ORIGIN = "auto.db.redis.diagnostic_channel";
12
+ const ATTR_DB_QUERY_TEXT = "db.query.text";
13
+ const ATTR_DB_SYSTEM_NAME = "db.system.name";
14
+ const ATTR_DB_OPERATION_BATCH_SIZE = "db.operation.batch.size";
15
+ const ATTR_SERVER_ADDRESS = "server.address";
16
+ const ATTR_SERVER_PORT = "server.port";
17
+ const DB_SYSTEM_NAME_VALUE_REDIS = "redis";
18
+ const NOOP = () => {
19
+ };
20
+ let subscribed = false;
21
+ let currentResponseHook;
22
+ function subscribeRedisDiagnosticChannels(tracingChannel, responseHook) {
23
+ currentResponseHook = responseHook;
24
+ if (subscribed) return;
25
+ subscribed = true;
26
+ try {
27
+ setupCommandChannel(tracingChannel, REDIS_DC_CHANNEL_COMMAND, (data) => data.args.slice(1));
28
+ setupBatchChannel(
29
+ tracingChannel,
30
+ REDIS_DC_CHANNEL_BATCH,
31
+ (data) => data.batchMode === "PIPELINE" ? "PIPELINE" : "MULTI"
32
+ );
33
+ setupConnectChannel(tracingChannel, REDIS_DC_CHANNEL_CONNECT);
34
+ setupCommandChannel(tracingChannel, IOREDIS_DC_CHANNEL_COMMAND, (data) => data.args);
35
+ setupConnectChannel(tracingChannel, IOREDIS_DC_CHANNEL_CONNECT);
36
+ } catch {
37
+ debugBuild.DEBUG_BUILD && core.debug.log("Redis node:diagnostics_channel subscription failed.");
38
+ }
39
+ }
40
+ function setupCommandChannel(tracingChannel, channelName, getCommandArgs) {
41
+ const channel = tracingChannel(channelName, (data) => {
42
+ const args = getCommandArgs(data);
43
+ const statement = args.length ? `${data.command} ${args.join(" ")}` : data.command;
44
+ return core.startSpanManual(
45
+ {
46
+ name: `redis-${data.command}`,
47
+ attributes: {
48
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
49
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis",
50
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
51
+ [ATTR_DB_QUERY_TEXT]: statement,
52
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
53
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
54
+ }
55
+ },
56
+ (span) => span
57
+ );
58
+ });
59
+ channel.subscribe({
60
+ start: NOOP,
61
+ asyncStart: NOOP,
62
+ end: NOOP,
63
+ asyncEnd: (data) => {
64
+ const span = data._sentrySpan;
65
+ if (!span || data.error) return;
66
+ runResponseHook(span, data.command, getCommandArgs(data), data.result);
67
+ span.end();
68
+ },
69
+ error: (data) => {
70
+ const span = data._sentrySpan;
71
+ if (!span) return;
72
+ if (data.error) {
73
+ span.setStatus({ code: core.SPAN_STATUS_ERROR, message: data.error.message });
74
+ }
75
+ span.end();
76
+ }
77
+ });
78
+ }
79
+ function setupBatchChannel(tracingChannel, channelName, getOperationName) {
80
+ const channel = tracingChannel(channelName, (data) => {
81
+ return core.startSpanManual(
82
+ {
83
+ name: getOperationName(data),
84
+ attributes: {
85
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
86
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis",
87
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
88
+ // should only include batch size greater than 1,
89
+ // or else it isn't properly considered a "batch"
90
+ ...Number(data.batchSize) > 1 ? { [ATTR_DB_OPERATION_BATCH_SIZE]: data.batchSize } : {},
91
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
92
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
93
+ }
94
+ },
95
+ (span) => span
96
+ );
97
+ });
98
+ channel.subscribe({
99
+ start: NOOP,
100
+ asyncStart: NOOP,
101
+ end: NOOP,
102
+ asyncEnd: (data) => {
103
+ if (!data.error) data._sentrySpan?.end();
104
+ },
105
+ error: (data) => {
106
+ const span = data._sentrySpan;
107
+ if (!span) return;
108
+ if (data.error) {
109
+ span.setStatus({ code: core.SPAN_STATUS_ERROR, message: data.error.message });
110
+ }
111
+ span.end();
112
+ }
113
+ });
114
+ }
115
+ function setupConnectChannel(tracingChannel, channelName) {
116
+ const channel = tracingChannel(channelName, (data) => {
117
+ return core.startSpanManual(
118
+ {
119
+ name: "redis-connect",
120
+ attributes: {
121
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
122
+ [core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis.connect",
123
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
124
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
125
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
126
+ }
127
+ },
128
+ (span) => span
129
+ );
130
+ });
131
+ channel.subscribe({
132
+ start: NOOP,
133
+ asyncStart: NOOP,
134
+ end: NOOP,
135
+ asyncEnd: (data) => {
136
+ if (!data.error) data._sentrySpan?.end();
137
+ },
138
+ error: (data) => {
139
+ const span = data._sentrySpan;
140
+ if (!span) return;
141
+ if (data.error) {
142
+ span.setStatus({ code: core.SPAN_STATUS_ERROR, message: data.error.message });
143
+ }
144
+ span.end();
145
+ }
146
+ });
147
+ }
148
+ function runResponseHook(span, command, args, result) {
149
+ const hook = currentResponseHook;
150
+ if (!hook) return;
151
+ try {
152
+ hook(span, command, args, result);
153
+ } catch {
154
+ }
155
+ }
156
+
157
+ exports.IOREDIS_DC_CHANNEL_COMMAND = IOREDIS_DC_CHANNEL_COMMAND;
158
+ exports.IOREDIS_DC_CHANNEL_CONNECT = IOREDIS_DC_CHANNEL_CONNECT;
159
+ exports.REDIS_DC_CHANNEL_BATCH = REDIS_DC_CHANNEL_BATCH;
160
+ exports.REDIS_DC_CHANNEL_COMMAND = REDIS_DC_CHANNEL_COMMAND;
161
+ exports.REDIS_DC_CHANNEL_CONNECT = REDIS_DC_CHANNEL_CONNECT;
162
+ exports.subscribeRedisDiagnosticChannels = subscribeRedisDiagnosticChannels;
163
+ //# sourceMappingURL=redis-dc-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-dc-subscriber.js","sources":["../../../src/redis/redis-dc-subscriber.ts"],"sourcesContent":["import type { Span } from '@sentry/core';\nimport {\n debug,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startSpanManual,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\n// Channel names published by node-redis >= 5.12.0 and ioredis >= 5.11.0.\n// Hardcoded so the subscriber does not have to import either library — the\n// channels just have to be subscribed to before the user's redis code\n// publishes.\nexport const REDIS_DC_CHANNEL_COMMAND = 'node-redis:command';\nexport const REDIS_DC_CHANNEL_BATCH = 'node-redis:batch';\nexport const REDIS_DC_CHANNEL_CONNECT = 'node-redis:connect';\nexport const IOREDIS_DC_CHANNEL_COMMAND = 'ioredis:command';\nexport const IOREDIS_DC_CHANNEL_CONNECT = 'ioredis:connect';\n\nconst ORIGIN = 'auto.db.redis.diagnostic_channel';\n\n// Inlined stable semconv attribute keys — these are plain strings, no need to\n// depend on @opentelemetry/semantic-conventions for them. We use the stable\n// OTel names (matching `@sentry/core`'s postgresjs integration) rather than the\n// deprecated `db.statement`/`db.system`/`net.peer.*` forms.\nconst ATTR_DB_QUERY_TEXT = 'db.query.text';\nconst ATTR_DB_SYSTEM_NAME = 'db.system.name';\nconst ATTR_DB_OPERATION_BATCH_SIZE = 'db.operation.batch.size';\nconst ATTR_SERVER_ADDRESS = 'server.address';\nconst ATTR_SERVER_PORT = 'server.port';\nconst DB_SYSTEM_NAME_VALUE_REDIS = 'redis';\n\nconst NOOP = (): void => {};\n\n/**\n * Shape of the `node-redis:command` channel payload published by node-redis.\n *\n * Both `command` and `args` are already redacted by node-redis itself (see\n * `sanitizeArgs` in @redis/client) using the OTel `redis-common` rules. The\n * arg array is `[<command>, <safe arg>, ..., '?', ...]` — `?` replaces any\n * value the library considers sensitive. Subscribers can emit `args` directly\n * as `db.query.text` without further serialization.\n */\nexport interface RedisCommandData {\n command: string;\n /** First arg is the command name itself; consumers should slice it off. */\n args: string[];\n database?: number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown;\n error?: Error;\n}\n\n/**\n * Shape of the `ioredis:command` channel payload published by ioredis >= 5.11.0.\n *\n * As with node-redis, args are already sanitized by ioredis (`sanitizeArgs` in\n * `lib/tracing.ts`) before publishing. Unlike node-redis, the command name is\n * NOT prepended to `args`.\n */\nexport interface IORedisCommandData {\n command: string;\n args: string[];\n batchMode?: 'MULTI';\n batchSize?: number;\n database?: number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown;\n error?: Error;\n}\n\n/** Shape of the `node-redis:batch` channel payload published by node-redis. */\nexport interface RedisBatchData {\n batchMode?: 'MULTI' | 'PIPELINE';\n batchSize?: number;\n database?: number;\n clientId?: string | number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown[];\n error?: Error;\n}\n\n/** Shape of the `*:connect` channel payload published by node-redis and ioredis. */\nexport interface RedisConnectData {\n serverAddress?: string;\n serverPort?: number;\n url?: string;\n error?: Error;\n}\n\n/**\n * Optional callback invoked once the redis command response arrives. Useful\n * for attaching response-derived attributes (e.g. cache hit/miss, payload size).\n *\n * Mirrors `@opentelemetry/instrumentation-ioredis`' response hook so existing\n * Sentry node code (`cacheResponseHook`) can be reused unchanged.\n */\nexport type RedisDiagnosticChannelResponseHook = (\n span: Span,\n cmdName: string,\n cmdArgs: string[],\n result: unknown,\n) => void;\n\n/**\n * Payload type observed by tracing-channel subscribers — the channel payload\n * with `_sentrySpan` stamped on it by the start handler so async/error\n * handlers downstream can read it back.\n */\nexport type RedisTracingChannelContextWithSpan<T> = T & { _sentrySpan?: Span };\n\n/** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */\nexport interface RedisTracingChannelSubscribers<T> {\n start: (data: RedisTracingChannelContextWithSpan<T>) => void;\n asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;\n asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;\n end: (data: RedisTracingChannelContextWithSpan<T>) => void;\n error: (data: RedisTracingChannelContextWithSpan<T>) => void;\n}\n\n/** Minimal tracing-channel surface the subscriber depends on. */\nexport interface RedisTracingChannel<T extends object> {\n subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;\n}\n\n/**\n * Platform-provided factory that returns a tracing channel for the given\n * channel name. Implementations are responsible for ensuring that, when the\n * channel's `start` event fires, the span returned by `transformStart(data)`\n * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`\n * handlers can read it.\n *\n * - Node passes `@sentry/opentelemetry/tracing-channel` which uses\n * `bindStore` to also propagate the span as the active OTel context.\n * - Deno (and other non-OTel runtimes) pass a portable wrapper around\n * `node:diagnostics_channel.tracingChannel` that just stamps\n * `data._sentrySpan` in `start` without `bindStore`.\n */\nexport type RedisTracingChannelFactory = <T extends object>(\n name: string,\n transformStart: (data: T) => Span,\n) => RedisTracingChannel<T>;\n\nlet subscribed = false;\nlet currentResponseHook: RedisDiagnosticChannelResponseHook | undefined;\n\n/**\n * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel\n * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis\n * >= 5.12.0) and `ioredis:command`/`:connect` (published by ioredis >= 5.11.0).\n *\n * On older client versions the channels are never published to, so subscribers\n * are inert — there is no double-instrumentation against any IITM-based\n * patcher gated to those older versions.\n *\n * Idempotent: subsequent calls update the response hook but do not\n * re-subscribe.\n */\nexport function subscribeRedisDiagnosticChannels(\n tracingChannel: RedisTracingChannelFactory,\n responseHook?: RedisDiagnosticChannelResponseHook,\n): void {\n currentResponseHook = responseHook;\n if (subscribed) return;\n subscribed = true;\n\n try {\n // node-redis: command name appears as args[0] in the channel payload, so\n // strip it before the statement and response hook see it.\n setupCommandChannel<RedisCommandData>(tracingChannel, REDIS_DC_CHANNEL_COMMAND, data => data.args.slice(1));\n setupBatchChannel(tracingChannel, REDIS_DC_CHANNEL_BATCH, data =>\n data.batchMode === 'PIPELINE' ? 'PIPELINE' : 'MULTI',\n );\n setupConnectChannel(tracingChannel, REDIS_DC_CHANNEL_CONNECT);\n\n // ioredis: args already exclude the command name; no slicing needed. And\n // ioredis has no separate batch channel — pipeline/MULTI metadata rides\n // on the per-command payload via `batchMode`/`batchSize`.\n setupCommandChannel<IORedisCommandData>(tracingChannel, IOREDIS_DC_CHANNEL_COMMAND, data => data.args);\n setupConnectChannel(tracingChannel, IOREDIS_DC_CHANNEL_CONNECT);\n } catch {\n // The factory may rely on `node:diagnostics_channel`, which isn't always\n // available. Fail closed; the SDK simply won't emit redis spans here.\n DEBUG_BUILD && debug.log('Redis node:diagnostics_channel subscription failed.');\n }\n}\n\nfunction setupCommandChannel<T extends RedisCommandData | IORedisCommandData>(\n tracingChannel: RedisTracingChannelFactory,\n channelName: string,\n getCommandArgs: (data: T) => string[],\n): void {\n const channel = tracingChannel<T>(channelName, data => {\n // `args` is already sanitized by the publishing library (node-redis /\n // ioredis call their own `sanitizeArgs` before publishing). Join with\n // spaces to mirror the format the libraries themselves intend.\n const args = getCommandArgs(data);\n const statement = args.length ? `${data.command} ${args.join(' ')}` : data.command;\n return startSpanManual(\n {\n name: `redis-${data.command}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n [ATTR_DB_QUERY_TEXT]: statement,\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n const span = data._sentrySpan;\n // Only end here if the error handler isn't going to.\n if (!span || data.error) return;\n runResponseHook(span, data.command, getCommandArgs(data), data.result);\n span.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction setupBatchChannel(\n tracingChannel: RedisTracingChannelFactory,\n channelName: string,\n getOperationName: (data: RedisBatchData) => string,\n): void {\n const channel = tracingChannel<RedisBatchData>(channelName, data => {\n return startSpanManual(\n {\n name: getOperationName(data),\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n // should only include batch size greater than 1,\n // or else it isn't properly considered a \"batch\"\n ...(Number(data.batchSize) > 1 ? { [ATTR_DB_OPERATION_BATCH_SIZE]: data.batchSize } : {}),\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n if (!data.error) data._sentrySpan?.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction setupConnectChannel(tracingChannel: RedisTracingChannelFactory, channelName: string): void {\n const channel = tracingChannel<RedisConnectData>(channelName, data => {\n return startSpanManual(\n {\n name: 'redis-connect',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis.connect',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n if (!data.error) data._sentrySpan?.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction runResponseHook(span: Span, command: string, args: string[], result: unknown): void {\n const hook = currentResponseHook;\n if (!hook) return;\n try {\n hook(span, command, args, result);\n } catch {\n // never let user hooks break instrumentation\n }\n}\n\n/** Test-only: reset module-local subscribe state. */\nexport function _resetRedisDiagnosticChannelsForTesting(): void {\n subscribed = false;\n currentResponseHook = undefined;\n}\n"],"names":["DEBUG_BUILD","debug","startSpanManual","SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN","SEMANTIC_ATTRIBUTE_SENTRY_OP","SPAN_STATUS_ERROR"],"mappings":";;;;;AAcO,MAAM,wBAAA,GAA2B;AACjC,MAAM,sBAAA,GAAyB;AAC/B,MAAM,wBAAA,GAA2B;AACjC,MAAM,0BAAA,GAA6B;AACnC,MAAM,0BAAA,GAA6B;AAE1C,MAAM,MAAA,GAAS,kCAAA;AAMf,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,mBAAA,GAAsB,gBAAA;AAC5B,MAAM,4BAAA,GAA+B,yBAAA;AACrC,MAAM,mBAAA,GAAsB,gBAAA;AAC5B,MAAM,gBAAA,GAAmB,aAAA;AACzB,MAAM,0BAAA,GAA6B,OAAA;AAEnC,MAAM,OAAO,MAAY;AAAC,CAAA;AAkH1B,IAAI,UAAA,GAAa,KAAA;AACjB,IAAI,mBAAA;AAcG,SAAS,gCAAA,CACd,gBACA,YAAA,EACM;AACN,EAAA,mBAAA,GAAsB,YAAA;AACtB,EAAA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AA,CAAK,GAAA,EAAI;AAAA,IACX;AAAA,GACD,CAAA;AACH;AAEA,SAAS,eAAA,CAAgB,IAAA,EAAY,OAAA,EAAiB,IAAA,EAAgB,MAAA,EAAuB;AAC3F,EAAA,MAAM,IAAA,GAAO,mBAAA;AACb,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,IAAI;AACF,IAAA,IAAA,CAAK,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,MAAM,CAAA;AAAA,EAClC,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
2
+
3
+ export { DEBUG_BUILD };
4
+ //# sourceMappingURL=debug-build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-build.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":"AAOO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
@@ -0,0 +1,2 @@
1
+ export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels } from './redis/redis-dc-subscriber.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"type":"module","version":"10.58.0","sideEffects":false}
@@ -0,0 +1,156 @@
1
+ import { debug, startSpanManual, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SPAN_STATUS_ERROR } from '@sentry/core';
2
+ import { DEBUG_BUILD } from '../debug-build.js';
3
+
4
+ const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
5
+ const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
6
+ const REDIS_DC_CHANNEL_CONNECT = "node-redis:connect";
7
+ const IOREDIS_DC_CHANNEL_COMMAND = "ioredis:command";
8
+ const IOREDIS_DC_CHANNEL_CONNECT = "ioredis:connect";
9
+ const ORIGIN = "auto.db.redis.diagnostic_channel";
10
+ const ATTR_DB_QUERY_TEXT = "db.query.text";
11
+ const ATTR_DB_SYSTEM_NAME = "db.system.name";
12
+ const ATTR_DB_OPERATION_BATCH_SIZE = "db.operation.batch.size";
13
+ const ATTR_SERVER_ADDRESS = "server.address";
14
+ const ATTR_SERVER_PORT = "server.port";
15
+ const DB_SYSTEM_NAME_VALUE_REDIS = "redis";
16
+ const NOOP = () => {
17
+ };
18
+ let subscribed = false;
19
+ let currentResponseHook;
20
+ function subscribeRedisDiagnosticChannels(tracingChannel, responseHook) {
21
+ currentResponseHook = responseHook;
22
+ if (subscribed) return;
23
+ subscribed = true;
24
+ try {
25
+ setupCommandChannel(tracingChannel, REDIS_DC_CHANNEL_COMMAND, (data) => data.args.slice(1));
26
+ setupBatchChannel(
27
+ tracingChannel,
28
+ REDIS_DC_CHANNEL_BATCH,
29
+ (data) => data.batchMode === "PIPELINE" ? "PIPELINE" : "MULTI"
30
+ );
31
+ setupConnectChannel(tracingChannel, REDIS_DC_CHANNEL_CONNECT);
32
+ setupCommandChannel(tracingChannel, IOREDIS_DC_CHANNEL_COMMAND, (data) => data.args);
33
+ setupConnectChannel(tracingChannel, IOREDIS_DC_CHANNEL_CONNECT);
34
+ } catch {
35
+ DEBUG_BUILD && debug.log("Redis node:diagnostics_channel subscription failed.");
36
+ }
37
+ }
38
+ function setupCommandChannel(tracingChannel, channelName, getCommandArgs) {
39
+ const channel = tracingChannel(channelName, (data) => {
40
+ const args = getCommandArgs(data);
41
+ const statement = args.length ? `${data.command} ${args.join(" ")}` : data.command;
42
+ return startSpanManual(
43
+ {
44
+ name: `redis-${data.command}`,
45
+ attributes: {
46
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
47
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis",
48
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
49
+ [ATTR_DB_QUERY_TEXT]: statement,
50
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
51
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
52
+ }
53
+ },
54
+ (span) => span
55
+ );
56
+ });
57
+ channel.subscribe({
58
+ start: NOOP,
59
+ asyncStart: NOOP,
60
+ end: NOOP,
61
+ asyncEnd: (data) => {
62
+ const span = data._sentrySpan;
63
+ if (!span || data.error) return;
64
+ runResponseHook(span, data.command, getCommandArgs(data), data.result);
65
+ span.end();
66
+ },
67
+ error: (data) => {
68
+ const span = data._sentrySpan;
69
+ if (!span) return;
70
+ if (data.error) {
71
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });
72
+ }
73
+ span.end();
74
+ }
75
+ });
76
+ }
77
+ function setupBatchChannel(tracingChannel, channelName, getOperationName) {
78
+ const channel = tracingChannel(channelName, (data) => {
79
+ return startSpanManual(
80
+ {
81
+ name: getOperationName(data),
82
+ attributes: {
83
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
84
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis",
85
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
86
+ // should only include batch size greater than 1,
87
+ // or else it isn't properly considered a "batch"
88
+ ...Number(data.batchSize) > 1 ? { [ATTR_DB_OPERATION_BATCH_SIZE]: data.batchSize } : {},
89
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
90
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
91
+ }
92
+ },
93
+ (span) => span
94
+ );
95
+ });
96
+ channel.subscribe({
97
+ start: NOOP,
98
+ asyncStart: NOOP,
99
+ end: NOOP,
100
+ asyncEnd: (data) => {
101
+ if (!data.error) data._sentrySpan?.end();
102
+ },
103
+ error: (data) => {
104
+ const span = data._sentrySpan;
105
+ if (!span) return;
106
+ if (data.error) {
107
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });
108
+ }
109
+ span.end();
110
+ }
111
+ });
112
+ }
113
+ function setupConnectChannel(tracingChannel, channelName) {
114
+ const channel = tracingChannel(channelName, (data) => {
115
+ return startSpanManual(
116
+ {
117
+ name: "redis-connect",
118
+ attributes: {
119
+ [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
120
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: "db.redis.connect",
121
+ [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,
122
+ ...data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {},
123
+ ...data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}
124
+ }
125
+ },
126
+ (span) => span
127
+ );
128
+ });
129
+ channel.subscribe({
130
+ start: NOOP,
131
+ asyncStart: NOOP,
132
+ end: NOOP,
133
+ asyncEnd: (data) => {
134
+ if (!data.error) data._sentrySpan?.end();
135
+ },
136
+ error: (data) => {
137
+ const span = data._sentrySpan;
138
+ if (!span) return;
139
+ if (data.error) {
140
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });
141
+ }
142
+ span.end();
143
+ }
144
+ });
145
+ }
146
+ function runResponseHook(span, command, args, result) {
147
+ const hook = currentResponseHook;
148
+ if (!hook) return;
149
+ try {
150
+ hook(span, command, args, result);
151
+ } catch {
152
+ }
153
+ }
154
+
155
+ export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels };
156
+ //# sourceMappingURL=redis-dc-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-dc-subscriber.js","sources":["../../../src/redis/redis-dc-subscriber.ts"],"sourcesContent":["import type { Span } from '@sentry/core';\nimport {\n debug,\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SPAN_STATUS_ERROR,\n startSpanManual,\n} from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\n\n// Channel names published by node-redis >= 5.12.0 and ioredis >= 5.11.0.\n// Hardcoded so the subscriber does not have to import either library — the\n// channels just have to be subscribed to before the user's redis code\n// publishes.\nexport const REDIS_DC_CHANNEL_COMMAND = 'node-redis:command';\nexport const REDIS_DC_CHANNEL_BATCH = 'node-redis:batch';\nexport const REDIS_DC_CHANNEL_CONNECT = 'node-redis:connect';\nexport const IOREDIS_DC_CHANNEL_COMMAND = 'ioredis:command';\nexport const IOREDIS_DC_CHANNEL_CONNECT = 'ioredis:connect';\n\nconst ORIGIN = 'auto.db.redis.diagnostic_channel';\n\n// Inlined stable semconv attribute keys — these are plain strings, no need to\n// depend on @opentelemetry/semantic-conventions for them. We use the stable\n// OTel names (matching `@sentry/core`'s postgresjs integration) rather than the\n// deprecated `db.statement`/`db.system`/`net.peer.*` forms.\nconst ATTR_DB_QUERY_TEXT = 'db.query.text';\nconst ATTR_DB_SYSTEM_NAME = 'db.system.name';\nconst ATTR_DB_OPERATION_BATCH_SIZE = 'db.operation.batch.size';\nconst ATTR_SERVER_ADDRESS = 'server.address';\nconst ATTR_SERVER_PORT = 'server.port';\nconst DB_SYSTEM_NAME_VALUE_REDIS = 'redis';\n\nconst NOOP = (): void => {};\n\n/**\n * Shape of the `node-redis:command` channel payload published by node-redis.\n *\n * Both `command` and `args` are already redacted by node-redis itself (see\n * `sanitizeArgs` in @redis/client) using the OTel `redis-common` rules. The\n * arg array is `[<command>, <safe arg>, ..., '?', ...]` — `?` replaces any\n * value the library considers sensitive. Subscribers can emit `args` directly\n * as `db.query.text` without further serialization.\n */\nexport interface RedisCommandData {\n command: string;\n /** First arg is the command name itself; consumers should slice it off. */\n args: string[];\n database?: number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown;\n error?: Error;\n}\n\n/**\n * Shape of the `ioredis:command` channel payload published by ioredis >= 5.11.0.\n *\n * As with node-redis, args are already sanitized by ioredis (`sanitizeArgs` in\n * `lib/tracing.ts`) before publishing. Unlike node-redis, the command name is\n * NOT prepended to `args`.\n */\nexport interface IORedisCommandData {\n command: string;\n args: string[];\n batchMode?: 'MULTI';\n batchSize?: number;\n database?: number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown;\n error?: Error;\n}\n\n/** Shape of the `node-redis:batch` channel payload published by node-redis. */\nexport interface RedisBatchData {\n batchMode?: 'MULTI' | 'PIPELINE';\n batchSize?: number;\n database?: number;\n clientId?: string | number;\n serverAddress?: string;\n serverPort?: number;\n result?: unknown[];\n error?: Error;\n}\n\n/** Shape of the `*:connect` channel payload published by node-redis and ioredis. */\nexport interface RedisConnectData {\n serverAddress?: string;\n serverPort?: number;\n url?: string;\n error?: Error;\n}\n\n/**\n * Optional callback invoked once the redis command response arrives. Useful\n * for attaching response-derived attributes (e.g. cache hit/miss, payload size).\n *\n * Mirrors `@opentelemetry/instrumentation-ioredis`' response hook so existing\n * Sentry node code (`cacheResponseHook`) can be reused unchanged.\n */\nexport type RedisDiagnosticChannelResponseHook = (\n span: Span,\n cmdName: string,\n cmdArgs: string[],\n result: unknown,\n) => void;\n\n/**\n * Payload type observed by tracing-channel subscribers — the channel payload\n * with `_sentrySpan` stamped on it by the start handler so async/error\n * handlers downstream can read it back.\n */\nexport type RedisTracingChannelContextWithSpan<T> = T & { _sentrySpan?: Span };\n\n/** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */\nexport interface RedisTracingChannelSubscribers<T> {\n start: (data: RedisTracingChannelContextWithSpan<T>) => void;\n asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;\n asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;\n end: (data: RedisTracingChannelContextWithSpan<T>) => void;\n error: (data: RedisTracingChannelContextWithSpan<T>) => void;\n}\n\n/** Minimal tracing-channel surface the subscriber depends on. */\nexport interface RedisTracingChannel<T extends object> {\n subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;\n}\n\n/**\n * Platform-provided factory that returns a tracing channel for the given\n * channel name. Implementations are responsible for ensuring that, when the\n * channel's `start` event fires, the span returned by `transformStart(data)`\n * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`\n * handlers can read it.\n *\n * - Node passes `@sentry/opentelemetry/tracing-channel` which uses\n * `bindStore` to also propagate the span as the active OTel context.\n * - Deno (and other non-OTel runtimes) pass a portable wrapper around\n * `node:diagnostics_channel.tracingChannel` that just stamps\n * `data._sentrySpan` in `start` without `bindStore`.\n */\nexport type RedisTracingChannelFactory = <T extends object>(\n name: string,\n transformStart: (data: T) => Span,\n) => RedisTracingChannel<T>;\n\nlet subscribed = false;\nlet currentResponseHook: RedisDiagnosticChannelResponseHook | undefined;\n\n/**\n * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel\n * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis\n * >= 5.12.0) and `ioredis:command`/`:connect` (published by ioredis >= 5.11.0).\n *\n * On older client versions the channels are never published to, so subscribers\n * are inert — there is no double-instrumentation against any IITM-based\n * patcher gated to those older versions.\n *\n * Idempotent: subsequent calls update the response hook but do not\n * re-subscribe.\n */\nexport function subscribeRedisDiagnosticChannels(\n tracingChannel: RedisTracingChannelFactory,\n responseHook?: RedisDiagnosticChannelResponseHook,\n): void {\n currentResponseHook = responseHook;\n if (subscribed) return;\n subscribed = true;\n\n try {\n // node-redis: command name appears as args[0] in the channel payload, so\n // strip it before the statement and response hook see it.\n setupCommandChannel<RedisCommandData>(tracingChannel, REDIS_DC_CHANNEL_COMMAND, data => data.args.slice(1));\n setupBatchChannel(tracingChannel, REDIS_DC_CHANNEL_BATCH, data =>\n data.batchMode === 'PIPELINE' ? 'PIPELINE' : 'MULTI',\n );\n setupConnectChannel(tracingChannel, REDIS_DC_CHANNEL_CONNECT);\n\n // ioredis: args already exclude the command name; no slicing needed. And\n // ioredis has no separate batch channel — pipeline/MULTI metadata rides\n // on the per-command payload via `batchMode`/`batchSize`.\n setupCommandChannel<IORedisCommandData>(tracingChannel, IOREDIS_DC_CHANNEL_COMMAND, data => data.args);\n setupConnectChannel(tracingChannel, IOREDIS_DC_CHANNEL_CONNECT);\n } catch {\n // The factory may rely on `node:diagnostics_channel`, which isn't always\n // available. Fail closed; the SDK simply won't emit redis spans here.\n DEBUG_BUILD && debug.log('Redis node:diagnostics_channel subscription failed.');\n }\n}\n\nfunction setupCommandChannel<T extends RedisCommandData | IORedisCommandData>(\n tracingChannel: RedisTracingChannelFactory,\n channelName: string,\n getCommandArgs: (data: T) => string[],\n): void {\n const channel = tracingChannel<T>(channelName, data => {\n // `args` is already sanitized by the publishing library (node-redis /\n // ioredis call their own `sanitizeArgs` before publishing). Join with\n // spaces to mirror the format the libraries themselves intend.\n const args = getCommandArgs(data);\n const statement = args.length ? `${data.command} ${args.join(' ')}` : data.command;\n return startSpanManual(\n {\n name: `redis-${data.command}`,\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n [ATTR_DB_QUERY_TEXT]: statement,\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n const span = data._sentrySpan;\n // Only end here if the error handler isn't going to.\n if (!span || data.error) return;\n runResponseHook(span, data.command, getCommandArgs(data), data.result);\n span.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction setupBatchChannel(\n tracingChannel: RedisTracingChannelFactory,\n channelName: string,\n getOperationName: (data: RedisBatchData) => string,\n): void {\n const channel = tracingChannel<RedisBatchData>(channelName, data => {\n return startSpanManual(\n {\n name: getOperationName(data),\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n // should only include batch size greater than 1,\n // or else it isn't properly considered a \"batch\"\n ...(Number(data.batchSize) > 1 ? { [ATTR_DB_OPERATION_BATCH_SIZE]: data.batchSize } : {}),\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n if (!data.error) data._sentrySpan?.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction setupConnectChannel(tracingChannel: RedisTracingChannelFactory, channelName: string): void {\n const channel = tracingChannel<RedisConnectData>(channelName, data => {\n return startSpanManual(\n {\n name: 'redis-connect',\n attributes: {\n [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,\n [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.redis.connect',\n [ATTR_DB_SYSTEM_NAME]: DB_SYSTEM_NAME_VALUE_REDIS,\n ...(data.serverAddress != null ? { [ATTR_SERVER_ADDRESS]: data.serverAddress } : {}),\n ...(data.serverPort != null ? { [ATTR_SERVER_PORT]: data.serverPort } : {}),\n },\n },\n span => span,\n );\n });\n\n channel.subscribe({\n start: NOOP,\n asyncStart: NOOP,\n end: NOOP,\n asyncEnd: data => {\n if (!data.error) data._sentrySpan?.end();\n },\n error: data => {\n const span = data._sentrySpan;\n if (!span) return;\n if (data.error) {\n span.setStatus({ code: SPAN_STATUS_ERROR, message: data.error.message });\n }\n span.end();\n },\n });\n}\n\nfunction runResponseHook(span: Span, command: string, args: string[], result: unknown): void {\n const hook = currentResponseHook;\n if (!hook) return;\n try {\n hook(span, command, args, result);\n } catch {\n // never let user hooks break instrumentation\n }\n}\n\n/** Test-only: reset module-local subscribe state. */\nexport function _resetRedisDiagnosticChannelsForTesting(): void {\n subscribed = false;\n currentResponseHook = undefined;\n}\n"],"names":[],"mappings":";;;AAcO,MAAM,wBAAA,GAA2B;AACjC,MAAM,sBAAA,GAAyB;AAC/B,MAAM,wBAAA,GAA2B;AACjC,MAAM,0BAAA,GAA6B;AACnC,MAAM,0BAAA,GAA6B;AAE1C,MAAM,MAAA,GAAS,kCAAA;AAMf,MAAM,kBAAA,GAAqB,eAAA;AAC3B,MAAM,mBAAA,GAAsB,gBAAA;AAC5B,MAAM,4BAAA,GAA+B,yBAAA;AACrC,MAAM,mBAAA,GAAsB,gBAAA;AAC5B,MAAM,gBAAA,GAAmB,aAAA;AACzB,MAAM,0BAAA,GAA6B,OAAA;AAEnC,MAAM,OAAO,MAAY;AAAC,CAAA;AAkH1B,IAAI,UAAA,GAAa,KAAA;AACjB,IAAI,mBAAA;AAcG,SAAS,gCAAA,CACd,g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CAAM,SAAS,CAAA;AAAA,MACzE;AACA,MAAA,IAAA,CAAK,GAAA,EAAI;AAAA,IACX;AAAA,GACD,CAAA;AACH;AAEA,SAAS,eAAA,CAAgB,IAAA,EAAY,OAAA,EAAiB,IAAA,EAAgB,MAAA,EAAuB;AAC3F,EAAA,MAAM,IAAA,GAAO,mBAAA;AACb,EAAA,IAAI,CAAC,IAAA,EAAM;AACX,EAAA,IAAI;AACF,IAAA,IAAA,CAAK,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,MAAM,CAAA;AAAA,EAClC,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
3
+ *
4
+ * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
5
+ */
6
+ export declare const DEBUG_BUILD: boolean;
7
+ //# sourceMappingURL=debug-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-build.d.ts","sourceRoot":"","sources":["../../src/debug-build.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,WAAW,SAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Server-only utilities shared across Sentry server SDKs.
3
+ *
4
+ * @module
5
+ */
6
+ export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels, } from './redis/redis-dc-subscriber';
7
+ export type { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannel, RedisTracingChannelContextWithSpan, RedisTracingChannelFactory, RedisTracingChannelSubscribers, } from './redis/redis-dc-subscriber';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,gCAAgC,GACjC,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,kCAAkC,EAClC,mBAAmB,EACnB,kCAAkC,EAClC,0BAA0B,EAC1B,8BAA8B,GAC/B,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,119 @@
1
+ import type { Span } from '@sentry/core';
2
+ export declare const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
3
+ export declare const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
4
+ export declare const REDIS_DC_CHANNEL_CONNECT = "node-redis:connect";
5
+ export declare const IOREDIS_DC_CHANNEL_COMMAND = "ioredis:command";
6
+ export declare const IOREDIS_DC_CHANNEL_CONNECT = "ioredis:connect";
7
+ /**
8
+ * Shape of the `node-redis:command` channel payload published by node-redis.
9
+ *
10
+ * Both `command` and `args` are already redacted by node-redis itself (see
11
+ * `sanitizeArgs` in @redis/client) using the OTel `redis-common` rules. The
12
+ * arg array is `[<command>, <safe arg>, ..., '?', ...]` — `?` replaces any
13
+ * value the library considers sensitive. Subscribers can emit `args` directly
14
+ * as `db.query.text` without further serialization.
15
+ */
16
+ export interface RedisCommandData {
17
+ command: string;
18
+ /** First arg is the command name itself; consumers should slice it off. */
19
+ args: string[];
20
+ database?: number;
21
+ serverAddress?: string;
22
+ serverPort?: number;
23
+ result?: unknown;
24
+ error?: Error;
25
+ }
26
+ /**
27
+ * Shape of the `ioredis:command` channel payload published by ioredis >= 5.11.0.
28
+ *
29
+ * As with node-redis, args are already sanitized by ioredis (`sanitizeArgs` in
30
+ * `lib/tracing.ts`) before publishing. Unlike node-redis, the command name is
31
+ * NOT prepended to `args`.
32
+ */
33
+ export interface IORedisCommandData {
34
+ command: string;
35
+ args: string[];
36
+ batchMode?: 'MULTI';
37
+ batchSize?: number;
38
+ database?: number;
39
+ serverAddress?: string;
40
+ serverPort?: number;
41
+ result?: unknown;
42
+ error?: Error;
43
+ }
44
+ /** Shape of the `node-redis:batch` channel payload published by node-redis. */
45
+ export interface RedisBatchData {
46
+ batchMode?: 'MULTI' | 'PIPELINE';
47
+ batchSize?: number;
48
+ database?: number;
49
+ clientId?: string | number;
50
+ serverAddress?: string;
51
+ serverPort?: number;
52
+ result?: unknown[];
53
+ error?: Error;
54
+ }
55
+ /** Shape of the `*:connect` channel payload published by node-redis and ioredis. */
56
+ export interface RedisConnectData {
57
+ serverAddress?: string;
58
+ serverPort?: number;
59
+ url?: string;
60
+ error?: Error;
61
+ }
62
+ /**
63
+ * Optional callback invoked once the redis command response arrives. Useful
64
+ * for attaching response-derived attributes (e.g. cache hit/miss, payload size).
65
+ *
66
+ * Mirrors `@opentelemetry/instrumentation-ioredis`' response hook so existing
67
+ * Sentry node code (`cacheResponseHook`) can be reused unchanged.
68
+ */
69
+ export type RedisDiagnosticChannelResponseHook = (span: Span, cmdName: string, cmdArgs: string[], result: unknown) => void;
70
+ /**
71
+ * Payload type observed by tracing-channel subscribers — the channel payload
72
+ * with `_sentrySpan` stamped on it by the start handler so async/error
73
+ * handlers downstream can read it back.
74
+ */
75
+ export type RedisTracingChannelContextWithSpan<T> = T & {
76
+ _sentrySpan?: Span;
77
+ };
78
+ /** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */
79
+ export interface RedisTracingChannelSubscribers<T> {
80
+ start: (data: RedisTracingChannelContextWithSpan<T>) => void;
81
+ asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;
82
+ asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;
83
+ end: (data: RedisTracingChannelContextWithSpan<T>) => void;
84
+ error: (data: RedisTracingChannelContextWithSpan<T>) => void;
85
+ }
86
+ /** Minimal tracing-channel surface the subscriber depends on. */
87
+ export interface RedisTracingChannel<T extends object> {
88
+ subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;
89
+ }
90
+ /**
91
+ * Platform-provided factory that returns a tracing channel for the given
92
+ * channel name. Implementations are responsible for ensuring that, when the
93
+ * channel's `start` event fires, the span returned by `transformStart(data)`
94
+ * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`
95
+ * handlers can read it.
96
+ *
97
+ * - Node passes `@sentry/opentelemetry/tracing-channel` which uses
98
+ * `bindStore` to also propagate the span as the active OTel context.
99
+ * - Deno (and other non-OTel runtimes) pass a portable wrapper around
100
+ * `node:diagnostics_channel.tracingChannel` that just stamps
101
+ * `data._sentrySpan` in `start` without `bindStore`.
102
+ */
103
+ export type RedisTracingChannelFactory = <T extends object>(name: string, transformStart: (data: T) => Span) => RedisTracingChannel<T>;
104
+ /**
105
+ * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel
106
+ * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis
107
+ * >= 5.12.0) and `ioredis:command`/`:connect` (published by ioredis >= 5.11.0).
108
+ *
109
+ * On older client versions the channels are never published to, so subscribers
110
+ * are inert — there is no double-instrumentation against any IITM-based
111
+ * patcher gated to those older versions.
112
+ *
113
+ * Idempotent: subsequent calls update the response hook but do not
114
+ * re-subscribe.
115
+ */
116
+ export declare function subscribeRedisDiagnosticChannels(tracingChannel: RedisTracingChannelFactory, responseHook?: RedisDiagnosticChannelResponseHook): void;
117
+ /** Test-only: reset module-local subscribe state. */
118
+ export declare function _resetRedisDiagnosticChannelsForTesting(): void;
119
+ //# sourceMappingURL=redis-dc-subscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis-dc-subscriber.d.ts","sourceRoot":"","sources":["../../../src/redis/redis-dc-subscriber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAczC,eAAO,MAAM,wBAAwB,uBAAuB,CA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AE,CAAC,KAAK,IAAI,KAC9B,mBAAmB,CAAC,CAAC,CAAC,CAAC;AAK5B;;;;;;;;;;;GAWG;AACH,wBAAgB,gCAAgC,CAC9C,cAAc,EAAE,0BAA0B,EAC1C,YAAY,CAAC,EAAE,kCAAkC,GAChD,IAAI,CAwBN;AA0ID,qDAAqD;AACrD,wBAAgB,uCAAuC,IAAI,IAAI,CAG9D"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
3
+ *
4
+ * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
5
+ */
6
+ export declare const DEBUG_BUILD: boolean;
7
+ //# sourceMappingURL=debug-build.d.ts.map
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Server-only utilities shared across Sentry server SDKs.
3
+ *
4
+ * @module
5
+ */
6
+ export { IOREDIS_DC_CHANNEL_COMMAND, IOREDIS_DC_CHANNEL_CONNECT, REDIS_DC_CHANNEL_BATCH, REDIS_DC_CHANNEL_COMMAND, REDIS_DC_CHANNEL_CONNECT, subscribeRedisDiagnosticChannels, } from './redis/redis-dc-subscriber';
7
+ export { IORedisCommandData, RedisBatchData, RedisCommandData, RedisConnectData, RedisDiagnosticChannelResponseHook, RedisTracingChannel, RedisTracingChannelContextWithSpan, RedisTracingChannelFactory, RedisTracingChannelSubscribers, } from './redis/redis-dc-subscriber';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,119 @@
1
+ import { Span } from '@sentry/core';
2
+ export declare const REDIS_DC_CHANNEL_COMMAND = "node-redis:command";
3
+ export declare const REDIS_DC_CHANNEL_BATCH = "node-redis:batch";
4
+ export declare const REDIS_DC_CHANNEL_CONNECT = "node-redis:connect";
5
+ export declare const IOREDIS_DC_CHANNEL_COMMAND = "ioredis:command";
6
+ export declare const IOREDIS_DC_CHANNEL_CONNECT = "ioredis:connect";
7
+ /**
8
+ * Shape of the `node-redis:command` channel payload published by node-redis.
9
+ *
10
+ * Both `command` and `args` are already redacted by node-redis itself (see
11
+ * `sanitizeArgs` in @redis/client) using the OTel `redis-common` rules. The
12
+ * arg array is `[<command>, <safe arg>, ..., '?', ...]` — `?` replaces any
13
+ * value the library considers sensitive. Subscribers can emit `args` directly
14
+ * as `db.query.text` without further serialization.
15
+ */
16
+ export interface RedisCommandData {
17
+ command: string;
18
+ /** First arg is the command name itself; consumers should slice it off. */
19
+ args: string[];
20
+ database?: number;
21
+ serverAddress?: string;
22
+ serverPort?: number;
23
+ result?: unknown;
24
+ error?: Error;
25
+ }
26
+ /**
27
+ * Shape of the `ioredis:command` channel payload published by ioredis >= 5.11.0.
28
+ *
29
+ * As with node-redis, args are already sanitized by ioredis (`sanitizeArgs` in
30
+ * `lib/tracing.ts`) before publishing. Unlike node-redis, the command name is
31
+ * NOT prepended to `args`.
32
+ */
33
+ export interface IORedisCommandData {
34
+ command: string;
35
+ args: string[];
36
+ batchMode?: 'MULTI';
37
+ batchSize?: number;
38
+ database?: number;
39
+ serverAddress?: string;
40
+ serverPort?: number;
41
+ result?: unknown;
42
+ error?: Error;
43
+ }
44
+ /** Shape of the `node-redis:batch` channel payload published by node-redis. */
45
+ export interface RedisBatchData {
46
+ batchMode?: 'MULTI' | 'PIPELINE';
47
+ batchSize?: number;
48
+ database?: number;
49
+ clientId?: string | number;
50
+ serverAddress?: string;
51
+ serverPort?: number;
52
+ result?: unknown[];
53
+ error?: Error;
54
+ }
55
+ /** Shape of the `*:connect` channel payload published by node-redis and ioredis. */
56
+ export interface RedisConnectData {
57
+ serverAddress?: string;
58
+ serverPort?: number;
59
+ url?: string;
60
+ error?: Error;
61
+ }
62
+ /**
63
+ * Optional callback invoked once the redis command response arrives. Useful
64
+ * for attaching response-derived attributes (e.g. cache hit/miss, payload size).
65
+ *
66
+ * Mirrors `@opentelemetry/instrumentation-ioredis`' response hook so existing
67
+ * Sentry node code (`cacheResponseHook`) can be reused unchanged.
68
+ */
69
+ export type RedisDiagnosticChannelResponseHook = (span: Span, cmdName: string, cmdArgs: string[], result: unknown) => void;
70
+ /**
71
+ * Payload type observed by tracing-channel subscribers — the channel payload
72
+ * with `_sentrySpan` stamped on it by the start handler so async/error
73
+ * handlers downstream can read it back.
74
+ */
75
+ export type RedisTracingChannelContextWithSpan<T> = T & {
76
+ _sentrySpan?: Span;
77
+ };
78
+ /** Subscriber object accepted by {@link RedisTracingChannel.subscribe}. */
79
+ export interface RedisTracingChannelSubscribers<T> {
80
+ start: (data: RedisTracingChannelContextWithSpan<T>) => void;
81
+ asyncStart: (data: RedisTracingChannelContextWithSpan<T>) => void;
82
+ asyncEnd: (data: RedisTracingChannelContextWithSpan<T>) => void;
83
+ end: (data: RedisTracingChannelContextWithSpan<T>) => void;
84
+ error: (data: RedisTracingChannelContextWithSpan<T>) => void;
85
+ }
86
+ /** Minimal tracing-channel surface the subscriber depends on. */
87
+ export interface RedisTracingChannel<T extends object> {
88
+ subscribe(subs: Partial<RedisTracingChannelSubscribers<T>>): void;
89
+ }
90
+ /**
91
+ * Platform-provided factory that returns a tracing channel for the given
92
+ * channel name. Implementations are responsible for ensuring that, when the
93
+ * channel's `start` event fires, the span returned by `transformStart(data)`
94
+ * ends up stored on `data._sentrySpan` so the subscriber's `asyncEnd`/`error`
95
+ * handlers can read it.
96
+ *
97
+ * - Node passes `@sentry/opentelemetry/tracing-channel` which uses
98
+ * `bindStore` to also propagate the span as the active OTel context.
99
+ * - Deno (and other non-OTel runtimes) pass a portable wrapper around
100
+ * `node:diagnostics_channel.tracingChannel` that just stamps
101
+ * `data._sentrySpan` in `start` without `bindStore`.
102
+ */
103
+ export type RedisTracingChannelFactory = <T extends object>(name: string, transformStart: (data: T) => Span) => RedisTracingChannel<T>;
104
+ /**
105
+ * Subscribe Sentry span handlers to node-redis and ioredis diagnostics-channel
106
+ * events: `node-redis:command`/`:batch`/`:connect` (published by node-redis
107
+ * >= 5.12.0) and `ioredis:command`/`:connect` (published by ioredis >= 5.11.0).
108
+ *
109
+ * On older client versions the channels are never published to, so subscribers
110
+ * are inert — there is no double-instrumentation against any IITM-based
111
+ * patcher gated to those older versions.
112
+ *
113
+ * Idempotent: subsequent calls update the response hook but do not
114
+ * re-subscribe.
115
+ */
116
+ export declare function subscribeRedisDiagnosticChannels(tracingChannel: RedisTracingChannelFactory, responseHook?: RedisDiagnosticChannelResponseHook): void;
117
+ /** Test-only: reset module-local subscribe state. */
118
+ export declare function _resetRedisDiagnosticChannelsForTesting(): void;
119
+ //# sourceMappingURL=redis-dc-subscriber.d.ts.map
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@sentry/server-utils",
3
+ "version": "10.58.0",
4
+ "description": "Server Utilities for all Sentry JavaScript SDKs",
5
+ "repository": "git://github.com/getsentry/sentry-javascript.git",
6
+ "homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/server-utils",
7
+ "author": "Sentry",
8
+ "license": "MIT",
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "files": [
13
+ "/build"
14
+ ],
15
+ "main": "build/cjs/index.js",
16
+ "module": "build/esm/index.js",
17
+ "types": "build/types/index.d.ts",
18
+ "exports": {
19
+ "./package.json": "./package.json",
20
+ ".": {
21
+ "import": {
22
+ "types": "./build/types/index.d.ts",
23
+ "default": "./build/esm/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./build/types/index.d.ts",
27
+ "default": "./build/cjs/index.js"
28
+ }
29
+ }
30
+ },
31
+ "typesVersions": {
32
+ "<5.0": {
33
+ "build/types/index.d.ts": [
34
+ "build/types-ts3.8/index.d.ts"
35
+ ]
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@sentry/core": "10.58.0"
43
+ },
44
+ "scripts": {
45
+ "build": "run-p build:transpile build:types",
46
+ "build:dev": "yarn build",
47
+ "build:transpile": "rollup -c rollup.npm.config.mjs",
48
+ "build:types": "run-s build:types:core build:types:downlevel",
49
+ "build:types:core": "tsc -p tsconfig.types.json",
50
+ "build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8",
51
+ "build:watch": "run-p build:transpile:watch",
52
+ "build:dev:watch": "run-p build:transpile:watch",
53
+ "build:transpile:watch": "rollup -c rollup.npm.config.mjs --watch",
54
+ "build:tarball": "npm pack",
55
+ "clean": "rimraf build coverage sentry-server-utils-*.tgz",
56
+ "lint:fix": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --fix --type-aware",
57
+ "lint": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --type-aware",
58
+ "lint:es-compatibility": "es-check es2020 ./build/cjs/*.js && es-check es2020 ./build/esm/*.js --module",
59
+ "test:unit": "vitest run",
60
+ "test": "vitest run",
61
+ "test:watch": "vitest --watch",
62
+ "yalc:publish": "yalc publish --push --sig"
63
+ },
64
+ "volta": {
65
+ "extends": "../../package.json"
66
+ },
67
+ "sideEffects": false
68
+ }