@reqray/instrumentation-ioredis 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ruslan Kryklyvyi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # @reqray/instrumentation-ioredis
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Records every Redis command made through `ioredis` into the request that issued it: standalone and cluster clients, pipelines included.
4
+
5
+ Part of [Reqray](https://github.com/reqray/reqray) — a dev panel and request inspector for Node.js. It
6
+ instruments HTTP, SQL, outgoing calls and cache on its own, shows every
7
+ request as a waterfall, and finds N+1 down to the file and the line.
8
+
9
+ ## You probably do not need to install this
10
+
11
+ [`@reqray/register`](https://www.npmjs.com/package/@reqray/register) depends on
12
+ it and applies it automatically:
13
+
14
+ ```bash
15
+ node --import @reqray/register app.js
16
+ ```
17
+
18
+ ```
19
+ reqray instrumentation active
20
+ ✔ ioredis@5.11.1 cache
21
+ ```
22
+
23
+ ## What is recorded
24
+
25
+ For each command: its name, the key, whether a read was a hit or a miss, and the duration. That is what lets Reqray flag the same key being read twice in one request.
26
+
27
+ **Values are never recorded**, and there is no opt-in: `SET session:9 <jwt>` is stored as `SET session:9`. A command Reqray does not recognise — a custom one, `AUTH` — records its name and nothing else.
28
+
29
+ Supported: `ioredis` 5.x. Outside that range nothing is patched, and the startup
30
+ report says so.
31
+
32
+ ## Applying it by hand
33
+
34
+ In a bundled application (esbuild, webpack, tsup) imports are resolved at build
35
+ time and loader hooks never fire. Apply the instrumentation yourself, before
36
+ the first call:
37
+
38
+ ```js
39
+ import Redis from 'ioredis';
40
+ import { instrumentIoredis } from '@reqray/instrumentation-ioredis';
41
+
42
+ instrumentIoredis().apply(Redis);
43
+ ```
44
+
45
+ No version range is checked on this path — the choice was yours.
46
+
47
+ The `redis` package (node-redis) is a different client and is not covered.
48
+
49
+ ## More
50
+
51
+ Everything else — the detectors, security defaults, measured overhead and a
52
+ demo that runs with one command — is in the
53
+ [main README](https://github.com/reqray/reqray#readme).
54
+
55
+ ## License
56
+
57
+ [MIT](https://github.com/reqray/reqray/blob/main/LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,255 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ instrumentIoredis: () => instrumentIoredis
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_core = require("@reqray/core");
27
+
28
+ // src/commands.ts
29
+ var ALL = -1;
30
+ var READ = { operation: "get", keys: ALL };
31
+ var WRITE = { operation: "set", keys: 1 };
32
+ var DELETE = { operation: "del", keys: ALL };
33
+ var TAKE = { operation: "other", keys: 1 };
34
+ var SHAPES = new Map([
35
+ // Reads of a value under a key. Their arguments select inside the key —
36
+ // a field, a range, a second key — and are part of what was read.
37
+ ...[
38
+ "GET",
39
+ "GETEX",
40
+ "GETRANGE",
41
+ "MGET",
42
+ "STRLEN",
43
+ "EXISTS",
44
+ "TTL",
45
+ "PTTL",
46
+ "TYPE",
47
+ "HGET",
48
+ "HMGET",
49
+ "HGETALL",
50
+ "HKEYS",
51
+ "HVALS",
52
+ "HLEN",
53
+ "HEXISTS",
54
+ "HSTRLEN",
55
+ "LRANGE",
56
+ "LINDEX",
57
+ "LLEN",
58
+ "SMEMBERS",
59
+ "SCARD",
60
+ "SDIFF",
61
+ "SINTER",
62
+ "SUNION",
63
+ "ZRANGE",
64
+ "ZRANGEBYSCORE",
65
+ "ZREVRANGE",
66
+ "ZREVRANGEBYSCORE",
67
+ "ZCARD",
68
+ "ZCOUNT",
69
+ "BITCOUNT",
70
+ "GETBIT"
71
+ ].map((name) => [name, READ]),
72
+ // Writes. Only the key is recorded — what is being stored is the user's data.
73
+ ...[
74
+ "SET",
75
+ "SETNX",
76
+ "SETEX",
77
+ "PSETEX",
78
+ "SETRANGE",
79
+ "SETBIT",
80
+ "GETSET",
81
+ "APPEND",
82
+ "INCR",
83
+ "INCRBY",
84
+ "INCRBYFLOAT",
85
+ "DECR",
86
+ "DECRBY",
87
+ "MSET",
88
+ "MSETNX",
89
+ "HSET",
90
+ "HSETNX",
91
+ "HMSET",
92
+ "HINCRBY",
93
+ "HINCRBYFLOAT",
94
+ "LPUSH",
95
+ "RPUSH",
96
+ "LPUSHX",
97
+ "RPUSHX",
98
+ "LSET",
99
+ "LINSERT",
100
+ "SADD",
101
+ "ZADD",
102
+ "ZINCRBY",
103
+ "EXPIRE",
104
+ "PEXPIRE",
105
+ "EXPIREAT",
106
+ "PEXPIREAT",
107
+ "PERSIST",
108
+ "RESTORE"
109
+ ].map((name) => [name, WRITE]),
110
+ // Removals whose every argument is a key or a field name.
111
+ ...["DEL", "UNLINK", "HDEL"].map((name) => [name, DELETE]),
112
+ // Removals that name what to remove — `SREM banned <email>`, `LREM q 1
113
+ // <payload>`. The key is enough; the rest is data.
114
+ ...["GETDEL", "SREM", "ZREM", "LREM"].map(
115
+ (name) => [name, { operation: "del", keys: 1 }]
116
+ ),
117
+ // Reads that name a member: `ZSCORE leaderboard <user>`, `SISMEMBER
118
+ // banned <email>`. The member is data, so it is not recorded — and without
119
+ // it two of these cannot be told apart, so they are not offered to the
120
+ // duplicate detector either.
121
+ ...["SISMEMBER", "SMISMEMBER", "ZSCORE", "ZMSCORE", "ZRANK", "ZREVRANK", "LPOS"].map(
122
+ (name) => [name, TAKE]
123
+ ),
124
+ // Read and remove at once. Calling either half of that a duplicate would be
125
+ // wrong, so they stay out of the detector's way.
126
+ ...["LPOP", "RPOP", "SPOP", "BLPOP", "BRPOP"].map((name) => [name, TAKE])
127
+ ]);
128
+ var UNKNOWN = { operation: "other", keys: 0 };
129
+ function shapeOf(command) {
130
+ return SHAPES.get(command) ?? UNKNOWN;
131
+ }
132
+ var MAX_KEY_ARGS = 12;
133
+ var MAX_KEY_CHARS = 200;
134
+ function keyOf(command, args) {
135
+ const { keys } = shapeOf(command);
136
+ if (keys === 0 || args.length === 0) return "";
137
+ const wanted = keys === ALL ? Math.min(args.length, MAX_KEY_ARGS) : Math.min(keys, args.length);
138
+ let key = "";
139
+ for (let index = 0; index < wanted; index++) {
140
+ const argument = args[index];
141
+ key += (index === 0 ? "" : " ") + String(argument);
142
+ if (key.length > MAX_KEY_CHARS) break;
143
+ }
144
+ if (args.length > wanted && keys === ALL) key += ` \u2026 +${args.length - wanted}`;
145
+ return key.length > MAX_KEY_CHARS ? `${key.slice(0, MAX_KEY_CHARS)}\u2026` : key;
146
+ }
147
+ var HEX_RUN = /[0-9a-f]{8,}/gi;
148
+ var DIGITS = /\d+/g;
149
+ function keyShape(key) {
150
+ return key.replace(HEX_RUN, "?").replace(DIGITS, "?");
151
+ }
152
+ var PRESENCE = /* @__PURE__ */ new Set(["GET", "GETEX", "GETDEL", "HGET", "LINDEX", "ZSCORE", "LPOP", "RPOP"]);
153
+ var COUNTING = /* @__PURE__ */ new Set(["EXISTS", "HEXISTS", "SISMEMBER"]);
154
+ var MULTI = /* @__PURE__ */ new Set(["MGET", "HMGET"]);
155
+ function hitOf(command, reply) {
156
+ if (PRESENCE.has(command)) return reply !== null && reply !== void 0;
157
+ if (COUNTING.has(command)) return Number(reply) > 0;
158
+ if (command === "HGETALL") return Array.isArray(reply) ? reply.length > 0 : null;
159
+ if (MULTI.has(command) && Array.isArray(reply)) {
160
+ const present = reply.filter((value) => value !== null && value !== void 0).length;
161
+ if (present === reply.length) return true;
162
+ if (present === 0) return false;
163
+ return null;
164
+ }
165
+ return null;
166
+ }
167
+
168
+ // src/index.ts
169
+ var TRACKED = /* @__PURE__ */ Symbol.for("reqray.tracked.ioredis");
170
+ function patchSendCommand(proto) {
171
+ (0, import_core.patchMethod)(
172
+ proto,
173
+ "sendCommand",
174
+ (original) => function reqraySendCommand(...args) {
175
+ const scope = (0, import_core.current)();
176
+ if (!scope) return original.apply(this, args);
177
+ const command = args[0];
178
+ if (!command || typeof command !== "object" || command[TRACKED]) {
179
+ return original.apply(this, args);
180
+ }
181
+ const { name, resolve, reject } = command;
182
+ if (typeof name !== "string" || typeof resolve !== "function" || typeof reject !== "function") {
183
+ return original.apply(this, args);
184
+ }
185
+ const upper = name.toUpperCase();
186
+ const key = keyOf(upper, Array.isArray(command.args) ? command.args : []);
187
+ const startTime = performance.now();
188
+ const fingerprint = scope.options.stack.maxPerFingerprint === Number.POSITIVE_INFINITY ? upper : `${upper} ${keyShape(key)}`;
189
+ const callsite = (0, import_core.resolveCallsite)(scope, fingerprint, reqraySendCommand);
190
+ command[TRACKED] = true;
191
+ let recorded = false;
192
+ const finish = (reply, error) => {
193
+ if (recorded) return;
194
+ recorded = true;
195
+ try {
196
+ (0, import_core.record)(scope, {
197
+ kind: "cache",
198
+ operation: shapeOf(upper).operation,
199
+ command: upper,
200
+ key,
201
+ hit: error === void 0 ? hitOf(upper, reply) : null,
202
+ duration: performance.now() - startTime,
203
+ startTime,
204
+ callsite,
205
+ error: (0, import_core.toSpanError)(error)
206
+ });
207
+ } catch {
208
+ }
209
+ };
210
+ command.resolve = function reqrayResolve(reply) {
211
+ finish(reply, void 0);
212
+ return resolve.call(this, reply);
213
+ };
214
+ command.reject = function reqrayReject(error) {
215
+ finish(void 0, error);
216
+ return reject.call(this, error);
217
+ };
218
+ return original.apply(this, args);
219
+ }
220
+ );
221
+ }
222
+ function prototypes(exports2) {
223
+ return [
224
+ exports2?.prototype,
225
+ exports2?.default?.prototype,
226
+ exports2?.Redis?.prototype,
227
+ exports2?.Cluster?.prototype,
228
+ exports2?.default?.Cluster?.prototype
229
+ ].filter((proto) => proto && typeof proto.sendCommand === "function");
230
+ }
231
+ function instrumentIoredis() {
232
+ return {
233
+ name: "ioredis",
234
+ // `<6` rather than `<7`: ioredis 6 does not exist, and an upper bound
235
+ // that reaches past what has been tested would silently patch an
236
+ // unvalidated major — the exact thing the version check is for.
237
+ supportedVersions: ">=5 <6",
238
+ captures: "cache",
239
+ apply(exports2) {
240
+ (0, import_core.guarded)("ioredis", () => {
241
+ for (const proto of prototypes(exports2)) patchSendCommand(proto);
242
+ });
243
+ },
244
+ unapply(exports2) {
245
+ (0, import_core.guarded)("ioredis", () => {
246
+ for (const proto of prototypes(exports2)) (0, import_core.unpatchMethod)(proto, "sendCommand");
247
+ });
248
+ }
249
+ };
250
+ }
251
+ // Annotate the CommonJS export names for ESM import in node:
252
+ 0 && (module.exports = {
253
+ instrumentIoredis
254
+ });
255
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/commands.ts"],"sourcesContent":["/**\n * `@reqray/instrumentation-ioredis` — interception of Redis calls made\n * through `ioredis`.\n *\n * **Interception method: prototype patching.** The more preferred option was\n * available and turned out to be insufficient: since 5.11 ioredis publishes a\n * `diagnostics_channel` tracing channel (`ioredis:command`), but the arguments\n * it carries are sanitized before publication, and the sanitizer keeps the key\n * only for the commands on its own list — `HGET`, `HGETALL` and `MGET` arrive\n * with the key replaced by `?`. Keys are the entire point of the cache view\n * and of the duplicate-read detector, and a detector that groups by `?` would\n * report every hash read in a request as one duplicate. So the arguments are\n * read where they are still real, and the value positions are dropped here\n * instead — see `commands.ts`, which decides what may be recorded.\n *\n * `sendCommand` is the single funnel every call goes through: `redis.get()`,\n * `pipeline.exec()` and `multi()` all end there, so one patch covers them and\n * none of them is recorded twice.\n *\n * Cache **values are never recorded**, in any mode and under any option. A\n * span holds the command, the key, how long it took and whether it hit.\n */\n\nimport {\n current,\n guarded,\n type Instrumentation,\n patchMethod,\n record,\n resolveCallsite,\n toSpanError,\n unpatchMethod,\n} from '@reqray/core';\nimport { hitOf, keyOf, keyShape, shapeOf } from './commands.js';\n\n/**\n * \"This command is already being timed\" marker, on the command itself.\n *\n * A command can pass through `sendCommand` more than once — the offline queue\n * is flushed on reconnect, the previous queue is resent — and each pass would\n * otherwise wrap the same callbacks again and record the same call twice. The\n * first pass wins, so the span spans the whole wait, queueing included.\n */\nconst TRACKED = Symbol.for('reqray.tracked.ioredis');\n\n/**\n * The ioredis command object, in the part this depends on.\n *\n * `resolve` and `reject` are how a command finishes: ioredis hands them to the\n * reply handler, so wrapping them is what makes the end of the call\n * observable. Both are plain closures over the promise, so `this` is irrelevant\n * to them.\n */\ninterface RedisCommand {\n name?: unknown;\n args?: unknown;\n resolve?: unknown;\n reject?: unknown;\n [TRACKED]?: boolean;\n}\n\nfunction patchSendCommand(proto: any): void {\n patchMethod(\n proto,\n 'sendCommand',\n (original: any) =>\n function reqraySendCommand(this: unknown, ...args: any[]) {\n const scope = current();\n // Outside a request nothing is touched: no allocations, no branching\n // beyond this check.\n if (!scope) return original.apply(this, args);\n\n const command = args[0] as RedisCommand | undefined;\n if (!command || typeof command !== 'object' || command[TRACKED]) {\n return original.apply(this, args);\n }\n\n const { name, resolve, reject } = command;\n // Without both hooks the end of the call is invisible, and a span with an\n // invented duration would be worse than no span.\n if (\n typeof name !== 'string' ||\n typeof resolve !== 'function' ||\n typeof reject !== 'function'\n ) {\n return original.apply(this, args);\n }\n\n const upper = name.toUpperCase();\n const key = keyOf(upper, Array.isArray(command.args) ? command.args : []);\n const startTime = performance.now();\n\n // In development every stack is captured and the fingerprint is unused, so\n // the key is not even shaped; elsewhere it groups the callsite budget.\n const fingerprint =\n scope.options.stack.maxPerFingerprint === Number.POSITIVE_INFINITY\n ? upper\n : `${upper} ${keyShape(key)}`;\n // The wrapper itself is the boundary: otherwise the top frame would be\n // Reqray code instead of the line the application called from.\n const callsite = resolveCallsite(scope, fingerprint, reqraySendCommand);\n\n command[TRACKED] = true;\n\n // ioredis settles a command once, but a driver is not a contract: a second\n // call must not turn into a second span.\n let recorded = false;\n const finish = (reply: unknown, error: unknown): void => {\n if (recorded) return;\n recorded = true;\n try {\n record(scope, {\n kind: 'cache',\n operation: shapeOf(upper).operation,\n command: upper,\n key,\n hit: error === undefined ? hitOf(upper, reply) : null,\n duration: performance.now() - startTime,\n startTime,\n callsite,\n error: toSpanError(error),\n });\n } catch {\n // Instrumentation must never break the host command.\n }\n };\n\n command.resolve = function reqrayResolve(this: unknown, reply: unknown) {\n finish(reply, undefined);\n return (resolve as (value: unknown) => unknown).call(this, reply);\n };\n command.reject = function reqrayReject(this: unknown, error: unknown) {\n finish(undefined, error);\n // The original error is passed on unchanged.\n return (reject as (error: unknown) => unknown).call(this, error);\n };\n\n return original.apply(this, args);\n },\n );\n}\n\n/**\n * Every class in the module that speaks to a server.\n *\n * The module object is both the `Redis` class and a namespace holding it, and\n * which of the two an application receives depends on how it imported: hence\n * the several paths to the same prototype. Patching is idempotent, so\n * arriving twice costs nothing.\n */\nfunction prototypes(exports: any): any[] {\n return [\n exports?.prototype,\n exports?.default?.prototype,\n exports?.Redis?.prototype,\n exports?.Cluster?.prototype,\n exports?.default?.Cluster?.prototype,\n ].filter((proto) => proto && typeof proto.sendCommand === 'function');\n}\n\nexport function instrumentIoredis(): Instrumentation {\n return {\n name: 'ioredis',\n // `<6` rather than `<7`: ioredis 6 does not exist, and an upper bound\n // that reaches past what has been tested would silently patch an\n // unvalidated major — the exact thing the version check is for.\n supportedVersions: '>=5 <6',\n captures: 'cache',\n\n apply(exports: any) {\n guarded('ioredis', () => {\n for (const proto of prototypes(exports)) patchSendCommand(proto);\n });\n },\n\n unapply(exports: any) {\n guarded('ioredis', () => {\n for (const proto of prototypes(exports)) unpatchMethod(proto, 'sendCommand');\n });\n },\n };\n}\n","/**\n * What a Redis command means, and which of its arguments may be recorded.\n *\n * Two things are decided here, and both are safety decisions.\n *\n * **How many arguments are a key.** Everything after that is a value, and a\n * value never reaches a span: `SET session:9 <jwt>` is recorded as\n * `SET session:9`. An unknown command is treated as all-value — the same\n * safe-by-default rule the Redis clients use for their own tracing, and the\n * reason `AUTH` cannot leak a password through here.\n *\n * **Which operation it is.** Only a read that returns the value of a named\n * key counts as `get`, because that is the one the duplicate detector acts\n * on, and its advice — \"read it once and pass the value down\" — has to be\n * true for every command in the set.\n */\n\nimport type { CacheOperation } from '@reqray/core';\n\n/** Every argument identifies what is read; none of them is a value. */\nconst ALL = -1;\n\ninterface Shape {\n readonly operation: CacheOperation;\n /** How many leading arguments may be recorded. {@link ALL} for all of them. */\n readonly keys: number;\n}\n\nconst READ: Shape = { operation: 'get', keys: ALL };\nconst WRITE: Shape = { operation: 'set', keys: 1 };\nconst DELETE: Shape = { operation: 'del', keys: ALL };\n/** The key may be recorded, but nothing that follows it, and it is no plain read. */\nconst TAKE: Shape = { operation: 'other', keys: 1 };\n\n/**\n * Commands Reqray understands. Anything missing is `other` with no arguments\n * recorded — visible in the waterfall, never guessed about.\n */\nconst SHAPES = new Map<string, Shape>([\n // Reads of a value under a key. Their arguments select inside the key —\n // a field, a range, a second key — and are part of what was read.\n ...(\n [\n 'GET',\n 'GETEX',\n 'GETRANGE',\n 'MGET',\n 'STRLEN',\n 'EXISTS',\n 'TTL',\n 'PTTL',\n 'TYPE',\n 'HGET',\n 'HMGET',\n 'HGETALL',\n 'HKEYS',\n 'HVALS',\n 'HLEN',\n 'HEXISTS',\n 'HSTRLEN',\n 'LRANGE',\n 'LINDEX',\n 'LLEN',\n 'SMEMBERS',\n 'SCARD',\n 'SDIFF',\n 'SINTER',\n 'SUNION',\n 'ZRANGE',\n 'ZRANGEBYSCORE',\n 'ZREVRANGE',\n 'ZREVRANGEBYSCORE',\n 'ZCARD',\n 'ZCOUNT',\n 'BITCOUNT',\n 'GETBIT',\n ] as const\n ).map((name) => [name, READ] as const),\n\n // Writes. Only the key is recorded — what is being stored is the user's data.\n ...(\n [\n 'SET',\n 'SETNX',\n 'SETEX',\n 'PSETEX',\n 'SETRANGE',\n 'SETBIT',\n 'GETSET',\n 'APPEND',\n 'INCR',\n 'INCRBY',\n 'INCRBYFLOAT',\n 'DECR',\n 'DECRBY',\n 'MSET',\n 'MSETNX',\n 'HSET',\n 'HSETNX',\n 'HMSET',\n 'HINCRBY',\n 'HINCRBYFLOAT',\n 'LPUSH',\n 'RPUSH',\n 'LPUSHX',\n 'RPUSHX',\n 'LSET',\n 'LINSERT',\n 'SADD',\n 'ZADD',\n 'ZINCRBY',\n 'EXPIRE',\n 'PEXPIRE',\n 'EXPIREAT',\n 'PEXPIREAT',\n 'PERSIST',\n 'RESTORE',\n ] as const\n ).map((name) => [name, WRITE] as const),\n\n // Removals whose every argument is a key or a field name.\n ...(['DEL', 'UNLINK', 'HDEL'] as const).map((name) => [name, DELETE] as const),\n // Removals that name what to remove — `SREM banned <email>`, `LREM q 1\n // <payload>`. The key is enough; the rest is data.\n ...(['GETDEL', 'SREM', 'ZREM', 'LREM'] as const).map(\n (name) => [name, { operation: 'del', keys: 1 } as Shape] as const,\n ),\n\n // Reads that name a member: `ZSCORE leaderboard <user>`, `SISMEMBER\n // banned <email>`. The member is data, so it is not recorded — and without\n // it two of these cannot be told apart, so they are not offered to the\n // duplicate detector either.\n ...(['SISMEMBER', 'SMISMEMBER', 'ZSCORE', 'ZMSCORE', 'ZRANK', 'ZREVRANK', 'LPOS'] as const).map(\n (name) => [name, TAKE] as const,\n ),\n\n // Read and remove at once. Calling either half of that a duplicate would be\n // wrong, so they stay out of the detector's way.\n ...(['LPOP', 'RPOP', 'SPOP', 'BLPOP', 'BRPOP'] as const).map((name) => [name, TAKE] as const),\n]);\n\nconst UNKNOWN: Shape = { operation: 'other', keys: 0 };\n\n/** Operation and recordable key for one command. */\nexport function shapeOf(command: string): Shape {\n return SHAPES.get(command) ?? UNKNOWN;\n}\n\nconst MAX_KEY_ARGS = 12;\nconst MAX_KEY_CHARS = 200;\n\n/**\n * The recordable part of a command's arguments, as one string.\n *\n * Long lists and long keys are cut: a span is a label on a screen, not a copy\n * of the traffic.\n */\nexport function keyOf(command: string, args: readonly unknown[]): string {\n const { keys } = shapeOf(command);\n if (keys === 0 || args.length === 0) return '';\n\n const wanted = keys === ALL ? Math.min(args.length, MAX_KEY_ARGS) : Math.min(keys, args.length);\n let key = '';\n for (let index = 0; index < wanted; index++) {\n const argument = args[index];\n // Buffers are how ioredis carries binary keys; `String()` on one is the\n // text it holds, which is what a key normally is.\n key += (index === 0 ? '' : ' ') + String(argument);\n if (key.length > MAX_KEY_CHARS) break;\n }\n // The count keeps two different long lists from looking like one call.\n if (args.length > wanted && keys === ALL) key += ` … +${args.length - wanted}`;\n return key.length > MAX_KEY_CHARS ? `${key.slice(0, MAX_KEY_CHARS)}…` : key;\n}\n\n/** Long hexadecimal runs — a uuid, a hash, a session id. */\nconst HEX_RUN = /[0-9a-f]{8,}/gi;\nconst DIGITS = /\\d+/g;\n\n/**\n * The shape of a key, for grouping stacks in production: `user:42:cart`\n * becomes `user:?:cart`.\n *\n * Without this every key would be its own fingerprint and the callsite budget\n * would be spent on the first request.\n */\nexport function keyShape(key: string): string {\n return key.replace(HEX_RUN, '?').replace(DIGITS, '?');\n}\n\n/** Commands whose reply says, on its own, whether the value was there. */\nconst PRESENCE = new Set(['GET', 'GETEX', 'GETDEL', 'HGET', 'LINDEX', 'ZSCORE', 'LPOP', 'RPOP']);\n/** Commands that answer with a count of what exists. */\nconst COUNTING = new Set(['EXISTS', 'HEXISTS', 'SISMEMBER']);\n/** Commands that read several keys at once, so a reply can be a partial hit. */\nconst MULTI = new Set(['MGET', 'HMGET']);\n\n/**\n * Whether the reply means the value was in the cache.\n *\n * `null` is the honest answer for everything the reply does not settle — a\n * partial `MGET`, a write, a command that returns a count. The panel prints\n * that as \"OK\" rather than inventing a miss.\n *\n * The reply here is raw, straight off the wire: strings arrive as buffers and\n * a missing key as `null`, which is exactly what this needs.\n */\nexport function hitOf(command: string, reply: unknown): boolean | null {\n if (PRESENCE.has(command)) return reply !== null && reply !== undefined;\n if (COUNTING.has(command)) return Number(reply) > 0;\n if (command === 'HGETALL') return Array.isArray(reply) ? reply.length > 0 : null;\n if (MULTI.has(command) && Array.isArray(reply)) {\n const present = reply.filter((value) => value !== null && value !== undefined).length;\n if (present === reply.length) return true;\n if (present === 0) return false;\n // Some of it was there and some was not: neither word is true.\n return null;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBA,k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BA,UAAS,SAAS,SAAS;AAAA,EAC7B,EAAE,OAAO,CAAC,UAAU,SAAS,OAAO,MAAM,gBAAgB,UAAU;AACtE;AAEO,SAAS,oBAAqC;AACnD,SAAO;AAAA,IACL,MAAM;AAAA;AAAA;AAAA;AAAA,IAIN,mBAAmB;AAAA,IACnB,UAAU;AAAA,IAEV,MAAMA,UAAc;AAClB,+BAAQ,WAAW,MAAM;AACvB,mBAAW,SAAS,WAAWA,QAAO,EAAG,kBAAiB,KAAK;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,IAEA,QAAQA,UAAc;AACpB,+BAAQ,WAAW,MAAM;AACvB,mBAAW,SAAS,WAAWA,QAAO,EAAG,gCAAc,OAAO,aAAa;AAAA,MAC7E,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":["exports"]}
@@ -0,0 +1,28 @@
1
+ import { Instrumentation } from '@reqray/core';
2
+
3
+ /**
4
+ * `@reqray/instrumentation-ioredis` — interception of Redis calls made
5
+ * through `ioredis`.
6
+ *
7
+ * **Interception method: prototype patching.** The more preferred option was
8
+ * available and turned out to be insufficient: since 5.11 ioredis publishes a
9
+ * `diagnostics_channel` tracing channel (`ioredis:command`), but the arguments
10
+ * it carries are sanitized before publication, and the sanitizer keeps the key
11
+ * only for the commands on its own list — `HGET`, `HGETALL` and `MGET` arrive
12
+ * with the key replaced by `?`. Keys are the entire point of the cache view
13
+ * and of the duplicate-read detector, and a detector that groups by `?` would
14
+ * report every hash read in a request as one duplicate. So the arguments are
15
+ * read where they are still real, and the value positions are dropped here
16
+ * instead — see `commands.ts`, which decides what may be recorded.
17
+ *
18
+ * `sendCommand` is the single funnel every call goes through: `redis.get()`,
19
+ * `pipeline.exec()` and `multi()` all end there, so one patch covers them and
20
+ * none of them is recorded twice.
21
+ *
22
+ * Cache **values are never recorded**, in any mode and under any option. A
23
+ * span holds the command, the key, how long it took and whether it hit.
24
+ */
25
+
26
+ declare function instrumentIoredis(): Instrumentation;
27
+
28
+ export { instrumentIoredis };
@@ -0,0 +1,28 @@
1
+ import { Instrumentation } from '@reqray/core';
2
+
3
+ /**
4
+ * `@reqray/instrumentation-ioredis` — interception of Redis calls made
5
+ * through `ioredis`.
6
+ *
7
+ * **Interception method: prototype patching.** The more preferred option was
8
+ * available and turned out to be insufficient: since 5.11 ioredis publishes a
9
+ * `diagnostics_channel` tracing channel (`ioredis:command`), but the arguments
10
+ * it carries are sanitized before publication, and the sanitizer keeps the key
11
+ * only for the commands on its own list — `HGET`, `HGETALL` and `MGET` arrive
12
+ * with the key replaced by `?`. Keys are the entire point of the cache view
13
+ * and of the duplicate-read detector, and a detector that groups by `?` would
14
+ * report every hash read in a request as one duplicate. So the arguments are
15
+ * read where they are still real, and the value positions are dropped here
16
+ * instead — see `commands.ts`, which decides what may be recorded.
17
+ *
18
+ * `sendCommand` is the single funnel every call goes through: `redis.get()`,
19
+ * `pipeline.exec()` and `multi()` all end there, so one patch covers them and
20
+ * none of them is recorded twice.
21
+ *
22
+ * Cache **values are never recorded**, in any mode and under any option. A
23
+ * span holds the command, the key, how long it took and whether it hit.
24
+ */
25
+
26
+ declare function instrumentIoredis(): Instrumentation;
27
+
28
+ export { instrumentIoredis };
package/dist/index.js ADDED
@@ -0,0 +1,238 @@
1
+ // src/index.ts
2
+ import {
3
+ current,
4
+ guarded,
5
+ patchMethod,
6
+ record,
7
+ resolveCallsite,
8
+ toSpanError,
9
+ unpatchMethod
10
+ } from "@reqray/core";
11
+
12
+ // src/commands.ts
13
+ var ALL = -1;
14
+ var READ = { operation: "get", keys: ALL };
15
+ var WRITE = { operation: "set", keys: 1 };
16
+ var DELETE = { operation: "del", keys: ALL };
17
+ var TAKE = { operation: "other", keys: 1 };
18
+ var SHAPES = new Map([
19
+ // Reads of a value under a key. Their arguments select inside the key —
20
+ // a field, a range, a second key — and are part of what was read.
21
+ ...[
22
+ "GET",
23
+ "GETEX",
24
+ "GETRANGE",
25
+ "MGET",
26
+ "STRLEN",
27
+ "EXISTS",
28
+ "TTL",
29
+ "PTTL",
30
+ "TYPE",
31
+ "HGET",
32
+ "HMGET",
33
+ "HGETALL",
34
+ "HKEYS",
35
+ "HVALS",
36
+ "HLEN",
37
+ "HEXISTS",
38
+ "HSTRLEN",
39
+ "LRANGE",
40
+ "LINDEX",
41
+ "LLEN",
42
+ "SMEMBERS",
43
+ "SCARD",
44
+ "SDIFF",
45
+ "SINTER",
46
+ "SUNION",
47
+ "ZRANGE",
48
+ "ZRANGEBYSCORE",
49
+ "ZREVRANGE",
50
+ "ZREVRANGEBYSCORE",
51
+ "ZCARD",
52
+ "ZCOUNT",
53
+ "BITCOUNT",
54
+ "GETBIT"
55
+ ].map((name) => [name, READ]),
56
+ // Writes. Only the key is recorded — what is being stored is the user's data.
57
+ ...[
58
+ "SET",
59
+ "SETNX",
60
+ "SETEX",
61
+ "PSETEX",
62
+ "SETRANGE",
63
+ "SETBIT",
64
+ "GETSET",
65
+ "APPEND",
66
+ "INCR",
67
+ "INCRBY",
68
+ "INCRBYFLOAT",
69
+ "DECR",
70
+ "DECRBY",
71
+ "MSET",
72
+ "MSETNX",
73
+ "HSET",
74
+ "HSETNX",
75
+ "HMSET",
76
+ "HINCRBY",
77
+ "HINCRBYFLOAT",
78
+ "LPUSH",
79
+ "RPUSH",
80
+ "LPUSHX",
81
+ "RPUSHX",
82
+ "LSET",
83
+ "LINSERT",
84
+ "SADD",
85
+ "ZADD",
86
+ "ZINCRBY",
87
+ "EXPIRE",
88
+ "PEXPIRE",
89
+ "EXPIREAT",
90
+ "PEXPIREAT",
91
+ "PERSIST",
92
+ "RESTORE"
93
+ ].map((name) => [name, WRITE]),
94
+ // Removals whose every argument is a key or a field name.
95
+ ...["DEL", "UNLINK", "HDEL"].map((name) => [name, DELETE]),
96
+ // Removals that name what to remove — `SREM banned <email>`, `LREM q 1
97
+ // <payload>`. The key is enough; the rest is data.
98
+ ...["GETDEL", "SREM", "ZREM", "LREM"].map(
99
+ (name) => [name, { operation: "del", keys: 1 }]
100
+ ),
101
+ // Reads that name a member: `ZSCORE leaderboard <user>`, `SISMEMBER
102
+ // banned <email>`. The member is data, so it is not recorded — and without
103
+ // it two of these cannot be told apart, so they are not offered to the
104
+ // duplicate detector either.
105
+ ...["SISMEMBER", "SMISMEMBER", "ZSCORE", "ZMSCORE", "ZRANK", "ZREVRANK", "LPOS"].map(
106
+ (name) => [name, TAKE]
107
+ ),
108
+ // Read and remove at once. Calling either half of that a duplicate would be
109
+ // wrong, so they stay out of the detector's way.
110
+ ...["LPOP", "RPOP", "SPOP", "BLPOP", "BRPOP"].map((name) => [name, TAKE])
111
+ ]);
112
+ var UNKNOWN = { operation: "other", keys: 0 };
113
+ function shapeOf(command) {
114
+ return SHAPES.get(command) ?? UNKNOWN;
115
+ }
116
+ var MAX_KEY_ARGS = 12;
117
+ var MAX_KEY_CHARS = 200;
118
+ function keyOf(command, args) {
119
+ const { keys } = shapeOf(command);
120
+ if (keys === 0 || args.length === 0) return "";
121
+ const wanted = keys === ALL ? Math.min(args.length, MAX_KEY_ARGS) : Math.min(keys, args.length);
122
+ let key = "";
123
+ for (let index = 0; index < wanted; index++) {
124
+ const argument = args[index];
125
+ key += (index === 0 ? "" : " ") + String(argument);
126
+ if (key.length > MAX_KEY_CHARS) break;
127
+ }
128
+ if (args.length > wanted && keys === ALL) key += ` \u2026 +${args.length - wanted}`;
129
+ return key.length > MAX_KEY_CHARS ? `${key.slice(0, MAX_KEY_CHARS)}\u2026` : key;
130
+ }
131
+ var HEX_RUN = /[0-9a-f]{8,}/gi;
132
+ var DIGITS = /\d+/g;
133
+ function keyShape(key) {
134
+ return key.replace(HEX_RUN, "?").replace(DIGITS, "?");
135
+ }
136
+ var PRESENCE = /* @__PURE__ */ new Set(["GET", "GETEX", "GETDEL", "HGET", "LINDEX", "ZSCORE", "LPOP", "RPOP"]);
137
+ var COUNTING = /* @__PURE__ */ new Set(["EXISTS", "HEXISTS", "SISMEMBER"]);
138
+ var MULTI = /* @__PURE__ */ new Set(["MGET", "HMGET"]);
139
+ function hitOf(command, reply) {
140
+ if (PRESENCE.has(command)) return reply !== null && reply !== void 0;
141
+ if (COUNTING.has(command)) return Number(reply) > 0;
142
+ if (command === "HGETALL") return Array.isArray(reply) ? reply.length > 0 : null;
143
+ if (MULTI.has(command) && Array.isArray(reply)) {
144
+ const present = reply.filter((value) => value !== null && value !== void 0).length;
145
+ if (present === reply.length) return true;
146
+ if (present === 0) return false;
147
+ return null;
148
+ }
149
+ return null;
150
+ }
151
+
152
+ // src/index.ts
153
+ var TRACKED = /* @__PURE__ */ Symbol.for("reqray.tracked.ioredis");
154
+ function patchSendCommand(proto) {
155
+ patchMethod(
156
+ proto,
157
+ "sendCommand",
158
+ (original) => function reqraySendCommand(...args) {
159
+ const scope = current();
160
+ if (!scope) return original.apply(this, args);
161
+ const command = args[0];
162
+ if (!command || typeof command !== "object" || command[TRACKED]) {
163
+ return original.apply(this, args);
164
+ }
165
+ const { name, resolve, reject } = command;
166
+ if (typeof name !== "string" || typeof resolve !== "function" || typeof reject !== "function") {
167
+ return original.apply(this, args);
168
+ }
169
+ const upper = name.toUpperCase();
170
+ const key = keyOf(upper, Array.isArray(command.args) ? command.args : []);
171
+ const startTime = performance.now();
172
+ const fingerprint = scope.options.stack.maxPerFingerprint === Number.POSITIVE_INFINITY ? upper : `${upper} ${keyShape(key)}`;
173
+ const callsite = resolveCallsite(scope, fingerprint, reqraySendCommand);
174
+ command[TRACKED] = true;
175
+ let recorded = false;
176
+ const finish = (reply, error) => {
177
+ if (recorded) return;
178
+ recorded = true;
179
+ try {
180
+ record(scope, {
181
+ kind: "cache",
182
+ operation: shapeOf(upper).operation,
183
+ command: upper,
184
+ key,
185
+ hit: error === void 0 ? hitOf(upper, reply) : null,
186
+ duration: performance.now() - startTime,
187
+ startTime,
188
+ callsite,
189
+ error: toSpanError(error)
190
+ });
191
+ } catch {
192
+ }
193
+ };
194
+ command.resolve = function reqrayResolve(reply) {
195
+ finish(reply, void 0);
196
+ return resolve.call(this, reply);
197
+ };
198
+ command.reject = function reqrayReject(error) {
199
+ finish(void 0, error);
200
+ return reject.call(this, error);
201
+ };
202
+ return original.apply(this, args);
203
+ }
204
+ );
205
+ }
206
+ function prototypes(exports) {
207
+ return [
208
+ exports?.prototype,
209
+ exports?.default?.prototype,
210
+ exports?.Redis?.prototype,
211
+ exports?.Cluster?.prototype,
212
+ exports?.default?.Cluster?.prototype
213
+ ].filter((proto) => proto && typeof proto.sendCommand === "function");
214
+ }
215
+ function instrumentIoredis() {
216
+ return {
217
+ name: "ioredis",
218
+ // `<6` rather than `<7`: ioredis 6 does not exist, and an upper bound
219
+ // that reaches past what has been tested would silently patch an
220
+ // unvalidated major — the exact thing the version check is for.
221
+ supportedVersions: ">=5 <6",
222
+ captures: "cache",
223
+ apply(exports) {
224
+ guarded("ioredis", () => {
225
+ for (const proto of prototypes(exports)) patchSendCommand(proto);
226
+ });
227
+ },
228
+ unapply(exports) {
229
+ guarded("ioredis", () => {
230
+ for (const proto of prototypes(exports)) unpatchMethod(proto, "sendCommand");
231
+ });
232
+ }
233
+ };
234
+ }
235
+ export {
236
+ instrumentIoredis
237
+ };
238
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/commands.ts"],"sourcesContent":["/**\n * `@reqray/instrumentation-ioredis` — interception of Redis calls made\n * through `ioredis`.\n *\n * **Interception method: prototype patching.** The more preferred option was\n * available and turned out to be insufficient: since 5.11 ioredis publishes a\n * `diagnostics_channel` tracing channel (`ioredis:command`), but the arguments\n * it carries are sanitized before publication, and the sanitizer keeps the key\n * only for the commands on its own list — `HGET`, `HGETALL` and `MGET` arrive\n * with the key replaced by `?`. Keys are the entire point of the cache view\n * and of the duplicate-read detector, and a detector that groups by `?` would\n * report every hash read in a request as one duplicate. So the arguments are\n * read where they are still real, and the value positions are dropped here\n * instead — see `commands.ts`, which decides what may be recorded.\n *\n * `sendCommand` is the single funnel every call goes through: `redis.get()`,\n * `pipeline.exec()` and `multi()` all end there, so one patch covers them and\n * none of them is recorded twice.\n *\n * Cache **values are never recorded**, in any mode and under any option. A\n * span holds the command, the key, how long it took and whether it hit.\n */\n\nimport {\n current,\n guarded,\n type Instrumentation,\n patchMethod,\n record,\n resolveCallsite,\n toSpanError,\n unpatchMethod,\n} from '@reqray/core';\nimport { hitOf, keyOf, keyShape, shapeOf } from './commands.js';\n\n/**\n * \"This command is already being timed\" marker, on the command itself.\n *\n * A command can pass through `sendCommand` more than once — the offline queue\n * is flushed on reconnect, the previous queue is resent — and each pass would\n * otherwise wrap the same callbacks again and record the same call twice. The\n * first pass wins, so the span spans the whole wait, queueing included.\n */\nconst TRACKED = Symbol.for('reqray.tracked.ioredis');\n\n/**\n * The ioredis command object, in the part this depends on.\n *\n * `resolve` and `reject` are how a command finishes: ioredis hands them to the\n * reply handler, so wrapping them is what makes the end of the call\n * observable. Both are plain closures over the promise, so `this` is irrelevant\n * to them.\n */\ninterface RedisCommand {\n name?: unknown;\n args?: unknown;\n resolve?: unknown;\n reject?: unknown;\n [TRACKED]?: boolean;\n}\n\nfunction patchSendCommand(proto: any): void {\n patchMethod(\n proto,\n 'sendCommand',\n (original: any) =>\n function reqraySendCommand(this: unknown, ...args: any[]) {\n const scope = current();\n // Outside a request nothing is touched: no allocations, no branching\n // beyond this check.\n if (!scope) return original.apply(this, args);\n\n const command = args[0] as RedisCommand | undefined;\n if (!command || typeof command !== 'object' || command[TRACKED]) {\n return original.apply(this, args);\n }\n\n const { name, resolve, reject } = command;\n // Without both hooks the end of the call is invisible, and a span with an\n // invented duration would be worse than no span.\n if (\n typeof name !== 'string' ||\n typeof resolve !== 'function' ||\n typeof reject !== 'function'\n ) {\n return original.apply(this, args);\n }\n\n const upper = name.toUpperCase();\n const key = keyOf(upper, Array.isArray(command.args) ? command.args : []);\n const startTime = performance.now();\n\n // In development every stack is captured and the fingerprint is unused, so\n // the key is not even shaped; elsewhere it groups the callsite budget.\n const fingerprint =\n scope.options.stack.maxPerFingerprint === Number.POSITIVE_INFINITY\n ? upper\n : `${upper} ${keyShape(key)}`;\n // The wrapper itself is the boundary: otherwise the top frame would be\n // Reqray code instead of the line the application called from.\n const callsite = resolveCallsite(scope, fingerprint, reqraySendCommand);\n\n command[TRACKED] = true;\n\n // ioredis settles a command once, but a driver is not a contract: a second\n // call must not turn into a second span.\n let recorded = false;\n const finish = (reply: unknown, error: unknown): void => {\n if (recorded) return;\n recorded = true;\n try {\n record(scope, {\n kind: 'cache',\n operation: shapeOf(upper).operation,\n command: upper,\n key,\n hit: error === undefined ? hitOf(upper, reply) : null,\n duration: performance.now() - startTime,\n startTime,\n callsite,\n error: toSpanError(error),\n });\n } catch {\n // Instrumentation must never break the host command.\n }\n };\n\n command.resolve = function reqrayResolve(this: unknown, reply: unknown) {\n finish(reply, undefined);\n return (resolve as (value: unknown) => unknown).call(this, reply);\n };\n command.reject = function reqrayReject(this: unknown, error: unknown) {\n finish(undefined, error);\n // The original error is passed on unchanged.\n return (reject as (error: unknown) => unknown).call(this, error);\n };\n\n return original.apply(this, args);\n },\n );\n}\n\n/**\n * Every class in the module that speaks to a server.\n *\n * The module object is both the `Redis` class and a namespace holding it, and\n * which of the two an application receives depends on how it imported: hence\n * the several paths to the same prototype. Patching is idempotent, so\n * arriving twice costs nothing.\n */\nfunction prototypes(exports: any): any[] {\n return [\n exports?.prototype,\n exports?.default?.prototype,\n exports?.Redis?.prototype,\n exports?.Cluster?.prototype,\n exports?.default?.Cluster?.prototype,\n ].filter((proto) => proto && typeof proto.sendCommand === 'function');\n}\n\nexport function instrumentIoredis(): Instrumentation {\n return {\n name: 'ioredis',\n // `<6` rather than `<7`: ioredis 6 does not exist, and an upper bound\n // that reaches past what has been tested would silently patch an\n // unvalidated major — the exact thing the version check is for.\n supportedVersions: '>=5 <6',\n captures: 'cache',\n\n apply(exports: any) {\n guarded('ioredis', () => {\n for (const proto of prototypes(exports)) patchSendCommand(proto);\n });\n },\n\n unapply(exports: any) {\n guarded('ioredis', () => {\n for (const proto of prototypes(exports)) unpatchMethod(proto, 'sendCommand');\n });\n },\n };\n}\n","/**\n * What a Redis command means, and which of its arguments may be recorded.\n *\n * Two things are decided here, and both are safety decisions.\n *\n * **How many arguments are a key.** Everything after that is a value, and a\n * value never reaches a span: `SET session:9 <jwt>` is recorded as\n * `SET session:9`. An unknown command is treated as all-value — the same\n * safe-by-default rule the Redis clients use for their own tracing, and the\n * reason `AUTH` cannot leak a password through here.\n *\n * **Which operation it is.** Only a read that returns the value of a named\n * key counts as `get`, because that is the one the duplicate detector acts\n * on, and its advice — \"read it once and pass the value down\" — has to be\n * true for every command in the set.\n */\n\nimport type { CacheOperation } from '@reqray/core';\n\n/** Every argument identifies what is read; none of them is a value. */\nconst ALL = -1;\n\ninterface Shape {\n readonly operation: CacheOperation;\n /** How many leading arguments may be recorded. {@link ALL} for all of them. */\n readonly keys: number;\n}\n\nconst READ: Shape = { operation: 'get', keys: ALL };\nconst WRITE: Shape = { operation: 'set', keys: 1 };\nconst DELETE: Shape = { operation: 'del', keys: ALL };\n/** The key may be recorded, but nothing that follows it, and it is no plain read. */\nconst TAKE: Shape = { operation: 'other', keys: 1 };\n\n/**\n * Commands Reqray understands. Anything missing is `other` with no arguments\n * recorded — visible in the waterfall, never guessed about.\n */\nconst SHAPES = new Map<string, Shape>([\n // Reads of a value under a key. Their arguments select inside the key —\n // a field, a range, a second key — and are part of what was read.\n ...(\n [\n 'GET',\n 'GETEX',\n 'GETRANGE',\n 'MGET',\n 'STRLEN',\n 'EXISTS',\n 'TTL',\n 'PTTL',\n 'TYPE',\n 'HGET',\n 'HMGET',\n 'HGETALL',\n 'HKEYS',\n 'HVALS',\n 'HLEN',\n 'HEXISTS',\n 'HSTRLEN',\n 'LRANGE',\n 'LINDEX',\n 'LLEN',\n 'SMEMBERS',\n 'SCARD',\n 'SDIFF',\n 'SINTER',\n 'SUNION',\n 'ZRANGE',\n 'ZRANGEBYSCORE',\n 'ZREVRANGE',\n 'ZREVRANGEBYSCORE',\n 'ZCARD',\n 'ZCOUNT',\n 'BITCOUNT',\n 'GETBIT',\n ] as const\n ).map((name) => [name, READ] as const),\n\n // Writes. Only the key is recorded — what is being stored is the user's data.\n ...(\n [\n 'SET',\n 'SETNX',\n 'SETEX',\n 'PSETEX',\n 'SETRANGE',\n 'SETBIT',\n 'GETSET',\n 'APPEND',\n 'INCR',\n 'INCRBY',\n 'INCRBYFLOAT',\n 'DECR',\n 'DECRBY',\n 'MSET',\n 'MSETNX',\n 'HSET',\n 'HSETNX',\n 'HMSET',\n 'HINCRBY',\n 'HINCRBYFLOAT',\n 'LPUSH',\n 'RPUSH',\n 'LPUSHX',\n 'RPUSHX',\n 'LSET',\n 'LINSERT',\n 'SADD',\n 'ZADD',\n 'ZINCRBY',\n 'EXPIRE',\n 'PEXPIRE',\n 'EXPIREAT',\n 'PEXPIREAT',\n 'PERSIST',\n 'RESTORE',\n ] as const\n ).map((name) => [name, WRITE] as const),\n\n // Removals whose every argument is a key or a field name.\n ...(['DEL', 'UNLINK', 'HDEL'] as const).map((name) => [name, DELETE] as const),\n // Removals that name what to remove — `SREM banned <email>`, `LREM q 1\n // <payload>`. The key is enough; the rest is data.\n ...(['GETDEL', 'SREM', 'ZREM', 'LREM'] as const).map(\n (name) => [name, { operation: 'del', keys: 1 } as Shape] as const,\n ),\n\n // Reads that name a member: `ZSCORE leaderboard <user>`, `SISMEMBER\n // banned <email>`. The member is data, so it is not recorded — and without\n // it two of these cannot be told apart, so they are not offered to the\n // duplicate detector either.\n ...(['SISMEMBER', 'SMISMEMBER', 'ZSCORE', 'ZMSCORE', 'ZRANK', 'ZREVRANK', 'LPOS'] as const).map(\n (name) => [name, TAKE] as const,\n ),\n\n // Read and remove at once. Calling either half of that a duplicate would be\n // wrong, so they stay out of the detector's way.\n ...(['LPOP', 'RPOP', 'SPOP', 'BLPOP', 'BRPOP'] as const).map((name) => [name, TAKE] as const),\n]);\n\nconst UNKNOWN: Shape = { operation: 'other', keys: 0 };\n\n/** Operation and recordable key for one command. */\nexport function shapeOf(command: string): Shape {\n return SHAPES.get(command) ?? UNKNOWN;\n}\n\nconst MAX_KEY_ARGS = 12;\nconst MAX_KEY_CHARS = 200;\n\n/**\n * The recordable part of a command's arguments, as one string.\n *\n * Long lists and long keys are cut: a span is a label on a screen, not a copy\n * of the traffic.\n */\nexport function keyOf(command: string, args: readonly unknown[]): string {\n const { keys } = shapeOf(command);\n if (keys === 0 || args.length === 0) return '';\n\n const wanted = keys === ALL ? Math.min(args.length, MAX_KEY_ARGS) : Math.min(keys, args.length);\n let key = '';\n for (let index = 0; index < wanted; index++) {\n const argument = args[index];\n // Buffers are how ioredis carries binary keys; `String()` on one is the\n // text it holds, which is what a key normally is.\n key += (index === 0 ? '' : ' ') + String(argument);\n if (key.length > MAX_KEY_CHARS) break;\n }\n // The count keeps two different long lists from looking like one call.\n if (args.length > wanted && keys === ALL) key += ` … +${args.length - wanted}`;\n return key.length > MAX_KEY_CHARS ? `${key.slice(0, MAX_KEY_CHARS)}…` : key;\n}\n\n/** Long hexadecimal runs — a uuid, a hash, a session id. */\nconst HEX_RUN = /[0-9a-f]{8,}/gi;\nconst DIGITS = /\\d+/g;\n\n/**\n * The shape of a key, for grouping stacks in production: `user:42:cart`\n * becomes `user:?:cart`.\n *\n * Without this every key would be its own fingerprint and the callsite budget\n * would be spent on the first request.\n */\nexport function keyShape(key: string): string {\n return key.replace(HEX_RUN, '?').replace(DIGITS, '?');\n}\n\n/** Commands whose reply says, on its own, whether the value was there. */\nconst PRESENCE = new Set(['GET', 'GETEX', 'GETDEL', 'HGET', 'LINDEX', 'ZSCORE', 'LPOP', 'RPOP']);\n/** Commands that answer with a count of what exists. */\nconst COUNTING = new Set(['EXISTS', 'HEXISTS', 'SISMEMBER']);\n/** Commands that read several keys at once, so a reply can be a partial hit. */\nconst MULTI = new Set(['MGET', 'HMGET']);\n\n/**\n * Whether the reply means the value was in the cache.\n *\n * `null` is the honest answer for everything the reply does not settle — a\n * partial `MGET`, a write, a command that returns a count. The panel prints\n * that as \"OK\" rather than inventing a miss.\n *\n * The reply here is raw, straight off the wire: strings arrive as buffers and\n * a missing key as `null`, which is exactly what this needs.\n */\nexport function hitOf(command: string, reply: unknown): boolean | null {\n if (PRESENCE.has(command)) return reply !== null && reply !== undefined;\n if (COUNTING.has(command)) return Number(reply) > 0;\n if (command === 'HGETALL') return Array.isArray(reply) ? reply.length > 0 : null;\n if (MULTI.has(command) && Array.isArray(reply)) {\n const present = reply.filter((value) => value !== null && value !== undefined).length;\n if (present === reply.length) return true;\n if (present === 0) return false;\n // Some of it was there and some was not: neither word is true.\n return null;\n }\n return null;\n}\n"],"mappings":";AAuBA;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACZP,IAAM,MAAM;AAQZ,IAAM,OAAc,EAAE,WAAW,OAAO,MAAM,IAAI;AAClD,IAAM,QAAe,EAAE,WAAW,OAAO,MAAM,EAAE;AACjD,IAAM,SAAgB,EAAE,WAAW,OAAO,MAAM,IAAI;AAEpD,IAAM,OAAc,EAAE,WAAW,SAAS,MAAM,EAAE;AAMlD,IAAM,SAAS,IAAI,IAAmB;AAAA;AAAA;AAAA,EAGpC,GACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,EACA,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAU;AAAA;AAAA,EAGrC,GACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA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,QAAQ;AAAA,QAER;AAAA,MACF;AAEA,cAAQ,UAAU,SAAS,cAA6B,OAAgB;AACtE,eAAO,OAAO,MAAS;AACvB,eAAQ,QAAwC,KAAK,MAAM,KAAK;AAAA,MAClE;AACA,cAAQ,SAAS,SAAS,aAA4B,OAAgB;AACpE,eAAO,QAAW,KAAK;AAEvB,eAAQ,OAAuC,KAAK,MAAM,KAAK;AAAA,MACjE;AAEA,aAAO,SAAS,MAAM,MAAM,IAAI;AAAA,IAClC;AAAA,EACJ;AACF;AAUA,SAAS,WAAW,SAAqB;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,IACT,SAAS,SAAS;AAAA,IAClB,SAAS,OAAO;AAAA,IAChB,SAAS,SAAS;AAAA,IAClB,SAAS,SAAS,SAAS;AAAA,EAC7B,EAAE,OAAO,CAAC,UAAU,SAAS,OAAO,MAAM,gBAAgB,UAAU;AACtE;AAEO,SAAS,oBAAqC;AACnD,SAAO;AAAA,IACL,MAAM;AAAA;AAAA;AAAA;AAAA,IAIN,mBAAmB;AAAA,IACnB,UAAU;AAAA,IAEV,MAAM,SAAc;AAClB,cAAQ,WAAW,MAAM;AACvB,mBAAW,SAAS,WAAW,OAAO,EAAG,kBAAiB,KAAK;AAAA,MACjE,CAAC;AAAA,IACH;AAAA,IAEA,QAAQ,SAAc;AACpB,cAAQ,WAAW,MAAM;AACvB,mBAAW,SAAS,WAAW,OAAO,EAAG,eAAc,OAAO,aAAa;AAAA,MAC7E,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@reqray/instrumentation-ioredis",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "ioredis driver instrumentation for Reqray.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "nodejs",
8
+ "debugging",
9
+ "profiling",
10
+ "n+1",
11
+ "sql",
12
+ "observability",
13
+ "devtools",
14
+ "fastify",
15
+ "express",
16
+ "nestjs"
17
+ ],
18
+ "homepage": "https://github.com/reqray/reqray#readme",
19
+ "bugs": "https://github.com/reqray/reqray/issues",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/reqray/reqray.git",
23
+ "directory": "packages/instrumentation-ioredis"
24
+ },
25
+ "type": "module",
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "main": "./dist/index.cjs",
42
+ "module": "./dist/index.js",
43
+ "types": "./dist/index.d.ts",
44
+ "files": [
45
+ "dist"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "@reqray/core": "^0.1.1"
52
+ },
53
+ "peerDependencies": {
54
+ "ioredis": ">=5 <6"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "ioredis": {
58
+ "optional": true
59
+ }
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^26.2.0",
63
+ "tsup": "^8.5.1",
64
+ "typescript": "^6.0.3",
65
+ "@testcontainers/redis": "^12.1.0",
66
+ "ioredis": "^5.11.1"
67
+ },
68
+ "scripts": {
69
+ "build": "tsup",
70
+ "typecheck": "tsc --noEmit"
71
+ }
6
72
  }