@reqray/register 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,74 @@
1
- # Temporary Holding Version
1
+ # @reqray/register
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
+ One flag on the command line, and a Node.js application's requests show up in
4
+ a panel as waterfalls — SQL, outgoing HTTP, cache — with N+1 queries pointed at
5
+ the file and the line. No code changes.
6
+
7
+ ![A request arrives, is flagged N+1, and one click shows the line and the fix](https://raw.githubusercontent.com/reqray/reqray/main/docs/screenshots/00-demo.gif)
8
+
9
+ ## Use
10
+
11
+ ```bash
12
+ npm install -D @reqray/register
13
+ node --import @reqray/register app.js
14
+ ```
15
+
16
+ ```
17
+ reqray instrumentation active
18
+ ✔ pg@8.23.0 SQL
19
+ ✔ ioredis@5.11.1 cache
20
+ ✔ undici (built-in) outgoing HTTP
21
+ reqray: no adapter found — panel is up at http://127.0.0.1:4310/_reqray/
22
+ ```
23
+
24
+ Works for ESM and CommonJS applications. A CommonJS application can also be
25
+ started with `node --require @reqray/register app.js`.
26
+
27
+ ## What it does
28
+
29
+ It installs loader hooks before your application loads its drivers, and
30
+ instruments them as they are imported:
31
+
32
+ | | Supported | Recorded |
33
+ |---|---|---|
34
+ | `pg` (and Prisma 7, which goes through it) | 8.x | the statement, its duration, the line that issued it — never parameter values |
35
+ | `ioredis` | 5.x | the command, the key, hit or miss — never values |
36
+ | undici and the built-in `fetch` | any | method, URL with secrets masked, status, duration |
37
+ | incoming `node:http` | any | used only when no adapter is present |
38
+
39
+ A driver outside its supported range is not patched; the startup report says
40
+ so and names the range.
41
+
42
+ ## With an adapter
43
+
44
+ Without an adapter the panel runs on a port of its own and records what
45
+ `node:http` can see. Request bodies, route names and replay need the framework's
46
+ cooperation — add [`@reqray/fastify`](https://www.npmjs.com/package/@reqray/fastify),
47
+ [`@reqray/express`](https://www.npmjs.com/package/@reqray/express) or
48
+ [`@reqray/nestjs`](https://www.npmjs.com/package/@reqray/nestjs), and the panel
49
+ moves into the application at `/_reqray/`.
50
+
51
+ ## Settings
52
+
53
+ | Variable | Default | |
54
+ |---|---|---|
55
+ | `REQRAY_PANEL_PORT` | `4310` | Port of the standalone panel |
56
+ | `REQRAY_STANDALONE` | on | `off` — instrument drivers, but start no panel of its own |
57
+
58
+ ## Limits
59
+
60
+ - The flag has to be there. Hooks installed after a driver has loaded cannot
61
+ reach it, and the startup report tells you when that happened.
62
+ - Bundled applications (esbuild, webpack, tsup) resolve imports at build time,
63
+ so loader hooks never fire. Apply an instrumentation by hand instead:
64
+ `instrumentPg().apply(pg)` from `@reqray/instrumentation-pg`.
65
+
66
+ ## More
67
+
68
+ Everything else — the detectors, security defaults, measured overhead and a
69
+ demo that runs with one command — is in the
70
+ [main README](https://github.com/reqray/reqray#readme).
71
+
72
+ ## License
73
+
74
+ [MIT](https://github.com/reqray/reqray/blob/main/LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,332 @@
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
+ enableStandalone: () => enableStandalone,
24
+ register: () => register,
25
+ registry: () => registry,
26
+ resetRegistration: () => resetRegistration,
27
+ resetStandalone: () => resetStandalone,
28
+ standalonePanelUrl: () => standalonePanelUrl
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+
32
+ // ../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.26_supports-color@7.2.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
33
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
34
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
35
+
36
+ // src/install.ts
37
+ var import_node_fs = require("fs");
38
+ var import_node_module = require("module");
39
+ var import_node_path = require("path");
40
+ var import_core = require("@reqray/core");
41
+ var import_import_in_the_middle = require("import-in-the-middle");
42
+ var import_require_in_the_middle = require("require-in-the-middle");
43
+ var import_semver = require("semver");
44
+
45
+ // src/registry.ts
46
+ var import_instrumentation_ioredis = require("@reqray/instrumentation-ioredis");
47
+ var import_instrumentation_pg = require("@reqray/instrumentation-pg");
48
+ var import_instrumentation_undici = require("@reqray/instrumentation-undici");
49
+ var registry = [
50
+ { module: "pg", supportedVersions: ">=8 <9", create: import_instrumentation_pg.instrumentPg },
51
+ { module: "ioredis", supportedVersions: ">=5 <6", create: import_instrumentation_ioredis.instrumentIoredis }
52
+ ];
53
+ var channelInstrumentations = [import_instrumentation_undici.instrumentUndici];
54
+
55
+ // src/install.ts
56
+ var requireFrom = (0, import_node_module.createRequire)(importMetaUrl);
57
+ var installed = false;
58
+ function versionAt(basedir) {
59
+ if (!basedir) return void 0;
60
+ try {
61
+ const manifest = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.join)(basedir, "package.json"), "utf8"));
62
+ return typeof manifest.version === "string" ? manifest.version : void 0;
63
+ } catch {
64
+ return void 0;
65
+ }
66
+ }
67
+ function alreadyLoaded(moduleName) {
68
+ const needle = `${import_node_path.sep}node_modules${import_node_path.sep}${moduleName}${import_node_path.sep}`;
69
+ for (const key of Object.keys(requireFrom.cache)) {
70
+ if (key.includes(needle)) return true;
71
+ }
72
+ return false;
73
+ }
74
+ var LOADED_TOO_LATE_HINT = "start with `node --import @reqray/register`";
75
+ function applyTo(instrumentation, exports2, version) {
76
+ if (version && !(0, import_semver.satisfies)(version, instrumentation.supportedVersions, { loose: true })) {
77
+ (0, import_core.reportInstrumentation)({
78
+ name: instrumentation.name,
79
+ version,
80
+ captures: instrumentation.captures ?? "",
81
+ ok: false,
82
+ reason: `version outside the supported range ${instrumentation.supportedVersions}`,
83
+ hint: "update Reqray, or patch the module yourself: `instrumentation.apply(module)` checks no version"
84
+ });
85
+ return;
86
+ }
87
+ try {
88
+ instrumentation.apply(exports2);
89
+ (0, import_core.reportInstrumentation)({
90
+ name: instrumentation.name,
91
+ version,
92
+ captures: instrumentation.captures ?? "",
93
+ ok: true
94
+ });
95
+ } catch (error) {
96
+ const reason = error instanceof Error ? error.message : String(error);
97
+ (0, import_core.reportInstrumentation)({
98
+ name: instrumentation.name,
99
+ version,
100
+ captures: instrumentation.captures ?? "",
101
+ ok: false,
102
+ reason: `failed to patch: ${reason}`
103
+ });
104
+ (0, import_core.warnOnce)(`register.${instrumentation.name}`, `${instrumentation.name}: ${reason}`);
105
+ }
106
+ }
107
+ function register() {
108
+ if (installed) return;
109
+ installed = true;
110
+ try {
111
+ const wanted = /* @__PURE__ */ new Map();
112
+ for (const entry of registry) wanted.set(entry.module, entry.create());
113
+ for (const create of channelInstrumentations) {
114
+ const instrumentation = create();
115
+ instrumentation.apply(void 0);
116
+ (0, import_core.reportInstrumentation)({
117
+ name: instrumentation.name,
118
+ builtin: true,
119
+ captures: instrumentation.captures ?? "",
120
+ ok: true
121
+ });
122
+ }
123
+ const moduleNames = [...wanted.keys()];
124
+ if (moduleNames.length === 0) return;
125
+ for (const name of moduleNames) {
126
+ if (!alreadyLoaded(name)) continue;
127
+ const target = wanted.get(name);
128
+ if (!target) continue;
129
+ wanted.delete(name);
130
+ (0, import_core.reportInstrumentation)({
131
+ name,
132
+ captures: target.captures ?? "",
133
+ ok: false,
134
+ reason: "found, but loaded before reqray",
135
+ hint: LOADED_TOO_LATE_HINT
136
+ });
137
+ }
138
+ const hookable = [...wanted.keys()];
139
+ if (hookable.length === 0) return;
140
+ const onLoad = (exports2, name, basedir) => {
141
+ const target = wanted.get(name);
142
+ if (target) applyTo(target, exports2, versionAt(basedir));
143
+ return exports2;
144
+ };
145
+ new import_require_in_the_middle.Hook(hookable, onLoad);
146
+ try {
147
+ (0, import_node_module.register)("import-in-the-middle/hook.mjs", importMetaUrl);
148
+ new import_import_in_the_middle.Hook(hookable, onLoad);
149
+ } catch (error) {
150
+ const reason = error instanceof Error ? error.message : String(error);
151
+ (0, import_core.warnOnce)("register.esm", `ESM hooks not installed (${reason}); ${LOADED_TOO_LATE_HINT}`);
152
+ }
153
+ } catch (error) {
154
+ const reason = error instanceof Error ? error.message : String(error);
155
+ (0, import_core.warnOnce)("register.install", `automatic instrumentation did not attach: ${reason}`);
156
+ }
157
+ }
158
+ function resetRegistration() {
159
+ installed = false;
160
+ }
161
+
162
+ // src/standalone.ts
163
+ var import_node_diagnostics_channel = require("diagnostics_channel");
164
+ var import_node_http = require("http");
165
+ var import_node_module2 = require("module");
166
+ var import_node_path2 = require("path");
167
+ var import_core2 = require("@reqray/core");
168
+ var import_panel = require("@reqray/core/panel");
169
+ var import_store_memory = require("@reqray/store-memory");
170
+ var CHANNEL = "http.server.request.start";
171
+ var state = {
172
+ subscribed: false,
173
+ runtime: null,
174
+ store: null,
175
+ panel: null,
176
+ panelPort: null,
177
+ panelUrl: null,
178
+ wantedPort: 4310
179
+ };
180
+ function dashboardAssets() {
181
+ try {
182
+ const manifest = (0, import_node_module2.createRequire)(importMetaUrl).resolve("@reqray/dashboard/package.json");
183
+ return (0, import_node_path2.join)((0, import_node_path2.dirname)(manifest), "dist");
184
+ } catch {
185
+ return void 0;
186
+ }
187
+ }
188
+ function splitQuery(url) {
189
+ const index = url.indexOf("?");
190
+ return index === -1 ? [url, null] : [url.slice(0, index), url.slice(index + 1)];
191
+ }
192
+ function disable() {
193
+ if (state.subscribed) {
194
+ (0, import_node_diagnostics_channel.unsubscribe)(CHANNEL, onRequestStart);
195
+ state.subscribed = false;
196
+ }
197
+ }
198
+ function ensureRuntime() {
199
+ if (state.runtime) return state.runtime;
200
+ const store = (0, import_store_memory.memoryTransport)();
201
+ const runtime = (0, import_core2.createReqray)({
202
+ // Replay needs the application's own origin, which standalone does not
203
+ // reliably know. Off, and said so in the startup line.
204
+ replay: false,
205
+ transport: store
206
+ });
207
+ if (!runtime.options.enabled || !runtime.options.isLocalDevelopment) {
208
+ disable();
209
+ return null;
210
+ }
211
+ state.runtime = runtime;
212
+ state.store = store;
213
+ return runtime;
214
+ }
215
+ function startPanel(runtime) {
216
+ if (state.panel || !state.store) return;
217
+ const handler = (0, import_panel.createPanelHandler)({
218
+ source: state.store,
219
+ options: runtime.options,
220
+ assetsDir: dashboardAssets()
221
+ });
222
+ if (!handler) return;
223
+ const server = (0, import_node_http.createServer)((request, response) => {
224
+ if (handler(request, response)) return;
225
+ if (request.url === "/" || request.url === "") {
226
+ response.writeHead(302, { location: "/_reqray/" });
227
+ response.end();
228
+ return;
229
+ }
230
+ response.writeHead(404, { "content-type": "application/json; charset=utf-8" });
231
+ response.end('{"error":"this is the reqray panel: /_reqray/"}');
232
+ });
233
+ state.panel = server;
234
+ let retried = false;
235
+ server.on("error", (error) => {
236
+ if (error.code === "EADDRINUSE" && !retried) {
237
+ retried = true;
238
+ server.listen(0, "127.0.0.1");
239
+ return;
240
+ }
241
+ (0, import_core2.warnOnce)("standalone.panel", `panel did not start: ${error.message}`);
242
+ state.panel = null;
243
+ });
244
+ server.listen(state.wantedPort, "127.0.0.1", () => {
245
+ const address = server.address();
246
+ state.panelPort = address.port;
247
+ state.panelUrl = `http://127.0.0.1:${address.port}/_reqray/`;
248
+ console.log(
249
+ `reqray: no adapter found \u2014 panel is up at ${state.panelUrl}
250
+ standalone mode: no request bodies, no Replay, paths without route normalization.
251
+ Full recording comes with an adapter: @reqray/fastify, @reqray/express, @reqray/nestjs.`
252
+ );
253
+ });
254
+ server.unref();
255
+ }
256
+ function onRequestStart(message) {
257
+ try {
258
+ if ((0, import_core2.isAdapterActive)()) {
259
+ disable();
260
+ return;
261
+ }
262
+ const { request, response } = message;
263
+ if (state.panelPort !== null && request.socket?.localPort === state.panelPort) return;
264
+ const runtime = ensureRuntime();
265
+ if (!runtime) return;
266
+ const [path, query] = splitQuery(request.url ?? "/");
267
+ const scope = runtime.begin({ method: request.method ?? "GET", path });
268
+ if (!scope) return;
269
+ startPanel(runtime);
270
+ (0, import_core2.enterScope)(scope);
271
+ const handlerSpan = scope.openSpan("handler", `${request.method} ${path}`);
272
+ let finished = false;
273
+ const complete = () => {
274
+ if (finished) return;
275
+ finished = true;
276
+ try {
277
+ scope.closeSpan(handlerSpan);
278
+ runtime.finish(scope, {
279
+ status: response.statusCode,
280
+ query,
281
+ requestHeaders: request.headers,
282
+ responseHeaders: response.getHeaders()
283
+ // Bodies are deliberately absent: consuming somebody else's stream
284
+ // is not an option, and observing it passively changes its mode.
285
+ });
286
+ } catch (error) {
287
+ const reason = error instanceof Error ? error.message : String(error);
288
+ (0, import_core2.warnOnce)("standalone.finish", `request not recorded: ${reason}`);
289
+ }
290
+ };
291
+ response.once("finish", complete);
292
+ response.once("close", complete);
293
+ } catch (error) {
294
+ const reason = error instanceof Error ? error.message : String(error);
295
+ (0, import_core2.warnOnce)("standalone.request", `standalone recording disabled after an error: ${reason}`);
296
+ disable();
297
+ }
298
+ }
299
+ function enableStandalone(options = {}) {
300
+ if (state.subscribed) return;
301
+ if (process.env["REQRAY_STANDALONE"] === "off") return;
302
+ const envPort = Number(process.env["REQRAY_PANEL_PORT"]);
303
+ state.wantedPort = options.panelPort ?? (Number.isInteger(envPort) ? envPort : 4310);
304
+ (0, import_node_diagnostics_channel.subscribe)(CHANNEL, onRequestStart);
305
+ state.subscribed = true;
306
+ }
307
+ function standalonePanelUrl() {
308
+ return state.panelUrl;
309
+ }
310
+ function resetStandalone() {
311
+ disable();
312
+ state.panel?.close();
313
+ state.panel = null;
314
+ state.panelPort = null;
315
+ state.panelUrl = null;
316
+ state.runtime = null;
317
+ state.store = null;
318
+ }
319
+
320
+ // src/index.ts
321
+ register();
322
+ enableStandalone();
323
+ // Annotate the CommonJS export names for ESM import in node:
324
+ 0 && (module.exports = {
325
+ enableStandalone,
326
+ register,
327
+ registry,
328
+ resetRegistration,
329
+ resetStandalone,
330
+ standalonePanelUrl
331
+ });
332
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../../../node_modules/.pnpm/tsup@8.5.1_postcss@8.5.26_supports-color@7.2.0_typescript@6.0.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js","../src/install.ts","../src/registry.ts","../src/standalone.ts"],"sourcesContent":["/**\n * `@reqray/register` — automatic instrumentation.\n *\n * Importing this module installs the loader hooks, so the recommended way to\n * start an application is:\n *\n * ```\n * node --import @reqray/register app.js\n * ```\n *\n * The hooks must be in place before the application loads its drivers: there is\n * no way to intercept a module that was loaded before us — Reqray reports such a\n * case honestly in the startup report.\n *\n * For bundled applications (esbuild, tsup) automatic instrumentation cannot\n * work at all: the bundler resolves imports at build time, so no loader hook\n * ever happens. There, only explicit registration remains — an\n * instrumentation applied by hand to the module the bundle already holds:\n * `instrumentPg().apply(pg)`.\n */\n\nexport { register, resetRegistration } from './install.js';\nexport { type RegistryEntry, registry } from './registry.js';\nexport {\n enableStandalone,\n resetStandalone,\n type StandaloneOptions,\n standalonePanelUrl,\n} from './standalone.js';\n\nimport { register } from './install.js';\nimport { enableStandalone } from './standalone.js';\n\nregister();\n// Zero lines of code: with no adapter around, the panel comes up by itself.\nenableStandalone();\n","// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","/**\n * Installation of the loader hooks.\n *\n * The priority order is strict and fixed:\n * 1. explicit registration by the user — always wins;\n * 2. loader hooks for packages from the registry, with a semver range check;\n * 3. `diagnostics_channel` where it exists natively — preferred over patching;\n * 4. nothing, but with a clear message at startup.\n *\n * The hooks must be installed before the drivers are loaded, hence the\n * recommended startup: `node --import @reqray/register`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport { createRequire, register as registerLoader } from 'node:module';\nimport { join, sep } from 'node:path';\nimport { type Instrumentation, reportInstrumentation, warnOnce } from '@reqray/core';\nimport { Hook as EsmHook, type HookFn as EsmHookFn } from 'import-in-the-middle';\nimport { Hook as CjsHook } from 'require-in-the-middle';\nimport { satisfies } from 'semver';\nimport { channelInstrumentations, registry } from './registry.js';\n\nconst requireFrom = createRequire(import.meta.url);\n\nlet installed = false;\n\n/** Version of the loaded module — resolved from the module's own directory. */\nfunction versionAt(basedir: string | undefined): string | undefined {\n if (!basedir) return undefined;\n try {\n const manifest = JSON.parse(readFileSync(join(basedir, 'package.json'), 'utf8')) as {\n version?: unknown;\n };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The module is already in the CJS cache — meaning the application loaded it\n * before us, and a hook on it will never fire.\n *\n * Modules loaded through ESM are not visible this way: the loader does not\n * expose their state. So this is a best-effort check, not a guarantee.\n */\nfunction alreadyLoaded(moduleName: string): boolean {\n const needle = `${sep}node_modules${sep}${moduleName}${sep}`;\n for (const key of Object.keys(requireFrom.cache)) {\n if (key.includes(needle)) return true;\n }\n return false;\n}\n\nconst LOADED_TOO_LATE_HINT = 'start with `node --import @reqray/register`';\n\nfunction applyTo(\n instrumentation: Instrumentation,\n exports: unknown,\n version: string | undefined,\n): void {\n // Silently patching an unknown major version is not allowed.\n if (version && !satisfies(version, instrumentation.supportedVersions, { loose: true })) {\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: false,\n reason: `version outside the supported range ${instrumentation.supportedVersions}`,\n hint: 'update Reqray, or patch the module yourself: `instrumentation.apply(module)` checks no version',\n });\n return;\n }\n\n try {\n instrumentation.apply(exports);\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: true,\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: false,\n reason: `failed to patch: ${reason}`,\n });\n warnOnce(`register.${instrumentation.name}`, `${instrumentation.name}: ${reason}`);\n }\n}\n\n/**\n * Installs the loader hooks and activates the instrumentations.\n *\n * Idempotent: a repeated call does nothing. Never throws — the application has\n * to start even if Reqray could not attach.\n *\n * Takes no options. It used to accept a list of instrumentations to register\n * explicitly, and never could honour it: importing this package calls\n * `register()` on the spot, so a later call with a list returned at the first\n * line. Explicit registration is an instrumentation's own `apply` — it needs\n * no loader hook, which is exactly why it works in a bundle:\n * `instrumentPg().apply(pg)`.\n */\nexport function register(): void {\n if (installed) return;\n installed = true;\n\n try {\n const wanted = new Map<string, Instrumentation>();\n for (const entry of registry) wanted.set(entry.module, entry.create());\n\n // diagnostics_channel does not depend on the loader — enable it right away.\n for (const create of channelInstrumentations) {\n const instrumentation = create();\n instrumentation.apply(undefined);\n reportInstrumentation({\n name: instrumentation.name,\n builtin: true,\n captures: instrumentation.captures ?? '',\n ok: true,\n });\n }\n\n const moduleNames = [...wanted.keys()];\n if (moduleNames.length === 0) return;\n\n // 4. Packages loaded before us cannot be hooked any more — report that\n // honestly instead of silently doing nothing.\n for (const name of moduleNames) {\n if (!alreadyLoaded(name)) continue;\n const target = wanted.get(name);\n if (!target) continue;\n wanted.delete(name);\n reportInstrumentation({\n name,\n captures: target.captures ?? '',\n ok: false,\n reason: 'found, but loaded before reqray',\n hint: LOADED_TOO_LATE_HINT,\n });\n }\n\n const hookable = [...wanted.keys()];\n if (hookable.length === 0) return;\n\n // The exports object is returned unchanged: instrumentation patches it in\n // place, the module object itself must not be substituted.\n // `import-in-the-middle` declares basedir as `string | void`, so the\n // signature accepts both that and `string | undefined` from the CJS hook.\n const onLoad = <T>(exports: T, name: string, basedir?: string): T => {\n const target = wanted.get(name);\n if (target) applyTo(target, exports, versionAt(basedir));\n return exports;\n };\n\n // 2. Loader hooks: CJS and ESM are installed independently of each other.\n new CjsHook(hookable, onLoad);\n\n try {\n registerLoader('import-in-the-middle/hook.mjs', import.meta.url);\n new EsmHook(hookable, onLoad as EsmHookFn);\n } catch (error) {\n // ESM hooks require Reqray to be loaded via `--import`. Without them the\n // CJS interception remains — not a reason to fail.\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('register.esm', `ESM hooks not installed (${reason}); ${LOADED_TOO_LATE_HINT}`);\n }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('register.install', `automatic instrumentation did not attach: ${reason}`);\n }\n}\n\n/** Resets the installed flag. Needed by tests. */\nexport function resetRegistration(): void {\n installed = false;\n}\n","/**\n * Registry of packages Reqray can instrument.\n *\n * Two lists, because there are two ways in. Packages that need module\n * interception are watched by the loader hooks. Instrumentations built on\n * `diagnostics_channel` — undici, and therefore built-in `fetch` — need no\n * loader at all and are simply switched on.\n */\n\nimport type { Instrumentation } from '@reqray/core';\nimport { instrumentIoredis } from '@reqray/instrumentation-ioredis';\nimport { instrumentPg } from '@reqray/instrumentation-pg';\nimport { instrumentUndici } from '@reqray/instrumentation-undici';\n\n/** One package the loader hooks watch for. */\nexport interface RegistryEntry {\n /** Module name exactly as the application requires it. */\n readonly module: string;\n /**\n * Versions this instrumentation has been tested against.\n *\n * Data, so deciding whether to watch a module does not mean building the\n * thing that would watch it.\n */\n readonly supportedVersions: string;\n /** Creates the instrumentation, once there is a module worth patching. */\n create(): Instrumentation;\n}\n\n/** Packages instrumented through loader hooks. */\nexport const registry: readonly RegistryEntry[] = [\n { module: 'pg', supportedVersions: '>=8 <9', create: instrumentPg },\n { module: 'ioredis', supportedVersions: '>=5 <6', create: instrumentIoredis },\n];\n\n/**\n * Instrumentations that need no loader hook.\n *\n * They subscribe to a channel the runtime already publishes, so there is no\n * module to intercept and no version to check — the channel is the contract.\n */\nexport const channelInstrumentations: readonly (() => Instrumentation)[] = [instrumentUndici];\n","/**\n * Standalone mode: the panel with zero lines of code.\n *\n * `node --import @reqray/register app.js` is enough — incoming HTTP is\n * observed through Node's own `diagnostics_channel` (no patching), and the\n * panel comes up on a side port on loopback, away from the application's own\n * routing.\n *\n * The mode knows its place:\n * - any framework adapter wins — the first request after an adapter has\n * initialized permanently disables standalone (an adapter records the same\n * requests with full fidelity);\n * - local development only: elsewhere the panel needs a gate, which requires\n * the adapter's options anyway;\n * - request and response bodies are not captured — reading somebody else's\n * stream is not allowed — and Replay is off;\n * - the route is the raw URL path: without a framework there is nothing to\n * normalize it against.\n */\n\nimport { subscribe, unsubscribe } from 'node:diagnostics_channel';\nimport { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';\nimport { createRequire } from 'node:module';\nimport type { AddressInfo } from 'node:net';\nimport { dirname, join } from 'node:path';\nimport { createReqray, enterScope, isAdapterActive, type Reqray, warnOnce } from '@reqray/core';\nimport { createPanelHandler } from '@reqray/core/panel';\nimport { type MemoryStore, memoryTransport } from '@reqray/store-memory';\n\nconst CHANNEL = 'http.server.request.start';\n\n/** Options for {@link enableStandalone}. Mostly for tests. */\nexport interface StandaloneOptions {\n /** Panel port; `0` picks a free one. Default: `REQRAY_PANEL_PORT` or 4310. */\n readonly panelPort?: number;\n}\n\ninterface StandaloneState {\n subscribed: boolean;\n runtime: Reqray | null;\n store: MemoryStore | null;\n panel: Server | null;\n panelPort: number | null;\n panelUrl: string | null;\n wantedPort: number;\n}\n\nconst state: StandaloneState = {\n subscribed: false,\n runtime: null,\n store: null,\n panel: null,\n panelPort: null,\n panelUrl: null,\n wantedPort: 4310,\n};\n\nfunction dashboardAssets(): string | undefined {\n try {\n const manifest = createRequire(import.meta.url).resolve('@reqray/dashboard/package.json');\n return join(dirname(manifest), 'dist');\n } catch {\n return undefined;\n }\n}\n\nfunction splitQuery(url: string): [path: string, query: string | null] {\n const index = url.indexOf('?');\n return index === -1 ? [url, null] : [url.slice(0, index), url.slice(index + 1)];\n}\n\n/** Permanently stands down: after this the channel costs nothing per request. */\nfunction disable(): void {\n if (state.subscribed) {\n unsubscribe(CHANNEL, onRequestStart);\n state.subscribed = false;\n }\n}\n\n/**\n * The runtime, created on the first captured request.\n *\n * `null` means standalone must not run here at all — and `disable()` has\n * already been called.\n */\nfunction ensureRuntime(): Reqray | null {\n if (state.runtime) return state.runtime;\n\n const store = memoryTransport();\n const runtime = createReqray({\n // Replay needs the application's own origin, which standalone does not\n // reliably know. Off, and said so in the startup line.\n replay: false,\n transport: store,\n });\n\n // Standalone is a local-development tool: anywhere else the panel needs a\n // gate, and a gate is configured through an adapter anyway.\n if (!runtime.options.enabled || !runtime.options.isLocalDevelopment) {\n disable();\n return null;\n }\n\n state.runtime = runtime;\n state.store = store;\n return runtime;\n}\n\nfunction startPanel(runtime: Reqray): void {\n if (state.panel || !state.store) return;\n\n const handler = createPanelHandler({\n source: state.store,\n options: runtime.options,\n assetsDir: dashboardAssets(),\n });\n if (!handler) return;\n\n const server = createServer((request, response) => {\n if (handler(request, response)) return;\n if (request.url === '/' || request.url === '') {\n response.writeHead(302, { location: '/_reqray/' });\n response.end();\n return;\n }\n response.writeHead(404, { 'content-type': 'application/json; charset=utf-8' });\n response.end('{\"error\":\"this is the reqray panel: /_reqray/\"}');\n });\n state.panel = server;\n\n let retried = false;\n server.on('error', (error: NodeJS.ErrnoException) => {\n // The chosen port is busy — most likely a second application with its\n // own standalone panel. A random port is better than no panel.\n if (error.code === 'EADDRINUSE' && !retried) {\n retried = true;\n server.listen(0, '127.0.0.1');\n return;\n }\n warnOnce('standalone.panel', `panel did not start: ${error.message}`);\n state.panel = null;\n });\n\n server.listen(state.wantedPort, '127.0.0.1', () => {\n const address = server.address() as AddressInfo;\n state.panelPort = address.port;\n state.panelUrl = `http://127.0.0.1:${address.port}/_reqray/`;\n console.log(\n `reqray: no adapter found — panel is up at ${state.panelUrl}\\n` +\n ' standalone mode: no request bodies, no Replay, paths without route normalization.\\n' +\n ' Full recording comes with an adapter: @reqray/fastify, @reqray/express, @reqray/nestjs.',\n );\n });\n // The side server must never keep the application process alive.\n server.unref();\n}\n\nfunction onRequestStart(message: unknown): void {\n try {\n // An adapter records the same requests with full fidelity — from here on\n // the channel must cost nothing.\n if (isAdapterActive()) {\n disable();\n return;\n }\n\n const { request, response } = message as {\n request: IncomingMessage;\n response: ServerResponse;\n };\n // The panel's own traffic must not appear in the list it displays.\n if (state.panelPort !== null && request.socket?.localPort === state.panelPort) return;\n\n const runtime = ensureRuntime();\n if (!runtime) return;\n\n const [path, query] = splitQuery(request.url ?? '/');\n const scope = runtime.begin({ method: request.method ?? 'GET', path });\n if (!scope) return;\n\n startPanel(runtime);\n\n // The publish happens synchronously right before the 'request' event, so\n // the scope entered here is visible to the application's handler.\n enterScope(scope);\n const handlerSpan = scope.openSpan('handler', `${request.method} ${path}`);\n\n let finished = false;\n const complete = (): void => {\n if (finished) return;\n finished = true;\n try {\n scope.closeSpan(handlerSpan);\n runtime.finish(scope, {\n status: response.statusCode,\n query,\n requestHeaders: request.headers,\n responseHeaders: response.getHeaders(),\n // Bodies are deliberately absent: consuming somebody else's stream\n // is not an option, and observing it passively changes its mode.\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('standalone.finish', `request not recorded: ${reason}`);\n }\n };\n response.once('finish', complete);\n response.once('close', complete);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('standalone.request', `standalone recording disabled after an error: ${reason}`);\n disable();\n }\n}\n\n/**\n * Enables the standalone mode.\n *\n * Called automatically when `@reqray/register` is imported. Does nothing until\n * the first incoming request, so an application with an adapter never even\n * notices it. `REQRAY_STANDALONE=off` switches it off entirely.\n */\nexport function enableStandalone(options: StandaloneOptions = {}): void {\n if (state.subscribed) return;\n if (process.env['REQRAY_STANDALONE'] === 'off') return;\n\n const envPort = Number(process.env['REQRAY_PANEL_PORT']);\n state.wantedPort = options.panelPort ?? (Number.isInteger(envPort) ? envPort : 4310);\n\n subscribe(CHANNEL, onRequestStart);\n state.subscribed = true;\n}\n\n/** Address of the standalone panel, once it is up. Needed by tests. */\nexport function standalonePanelUrl(): string | null {\n return state.panelUrl;\n}\n\n/** Shuts standalone down and forgets its state. Needed by tests. */\nexport function resetStandalone(): void {\n disable();\n state.panel?.close();\n state.panel = null;\n state.panelPort = null;\n state.panelUrl = null;\n state.runtime = null;\n state.store = null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACC9D,qBAA6B;AAC7B,yBAA0D;AAC1D,uBAA0B;AAC1B,kBAAsE;AACtE,kCAA0D;AAC1D,mCAAgC;AAChC,oBAA0B;;;ACT1B,qCAAkC;AAClC,gCAA6B;AAC7B,oCAAiC;AAkB1B,IAAM,WAAqC;AAAA,EAChD,EAAE,QAAQ,MAAM,mBAAmB,UAAU,QAAQ,uCAAa;AAAA,EAClE,EAAE,QAAQ,WAAW,mBAAmB,UAAU,QAAQ,iDAAkB;AAC9E;AAQO,IAAM,0BAA8D,CAAC,8CAAgB;;;ADnB5F,IAAM,kBAAc,kCAAc,aAAe;AAEjD,IAAI,YAAY;AAGhB,SAAS,UAAU,SAAiD;AAClE,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI;AACF,UAAM,WAAW,KAAK,UAAM,iCAAa,uBAAK,SAAS,cAAc,GAAG,MAAM,CAAC;AAG/E,WAAO,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;AAAA,EACnE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASA,SAAS,cAAc,YAA6B;AAClD,QAAM,SAAS,GAAG,oBAAG,eAAe,oBAAG,GAAG,UAAU,GAAG,oBAAG;AAC1D,aAAW,OAAO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","registerLoader","EsmHook","import_node_module","import_node_path","import_core"]}
@@ -0,0 +1,95 @@
1
+ import { Instrumentation } from '@reqray/core';
2
+
3
+ /**
4
+ * Installation of the loader hooks.
5
+ *
6
+ * The priority order is strict and fixed:
7
+ * 1. explicit registration by the user — always wins;
8
+ * 2. loader hooks for packages from the registry, with a semver range check;
9
+ * 3. `diagnostics_channel` where it exists natively — preferred over patching;
10
+ * 4. nothing, but with a clear message at startup.
11
+ *
12
+ * The hooks must be installed before the drivers are loaded, hence the
13
+ * recommended startup: `node --import @reqray/register`.
14
+ */
15
+ /**
16
+ * Installs the loader hooks and activates the instrumentations.
17
+ *
18
+ * Idempotent: a repeated call does nothing. Never throws — the application has
19
+ * to start even if Reqray could not attach.
20
+ *
21
+ * Takes no options. It used to accept a list of instrumentations to register
22
+ * explicitly, and never could honour it: importing this package calls
23
+ * `register()` on the spot, so a later call with a list returned at the first
24
+ * line. Explicit registration is an instrumentation's own `apply` — it needs
25
+ * no loader hook, which is exactly why it works in a bundle:
26
+ * `instrumentPg().apply(pg)`.
27
+ */
28
+ declare function register(): void;
29
+ /** Resets the installed flag. Needed by tests. */
30
+ declare function resetRegistration(): void;
31
+
32
+ /**
33
+ * Registry of packages Reqray can instrument.
34
+ *
35
+ * Two lists, because there are two ways in. Packages that need module
36
+ * interception are watched by the loader hooks. Instrumentations built on
37
+ * `diagnostics_channel` — undici, and therefore built-in `fetch` — need no
38
+ * loader at all and are simply switched on.
39
+ */
40
+
41
+ /** One package the loader hooks watch for. */
42
+ interface RegistryEntry {
43
+ /** Module name exactly as the application requires it. */
44
+ readonly module: string;
45
+ /**
46
+ * Versions this instrumentation has been tested against.
47
+ *
48
+ * Data, so deciding whether to watch a module does not mean building the
49
+ * thing that would watch it.
50
+ */
51
+ readonly supportedVersions: string;
52
+ /** Creates the instrumentation, once there is a module worth patching. */
53
+ create(): Instrumentation;
54
+ }
55
+ /** Packages instrumented through loader hooks. */
56
+ declare const registry: readonly RegistryEntry[];
57
+
58
+ /**
59
+ * Standalone mode: the panel with zero lines of code.
60
+ *
61
+ * `node --import @reqray/register app.js` is enough — incoming HTTP is
62
+ * observed through Node's own `diagnostics_channel` (no patching), and the
63
+ * panel comes up on a side port on loopback, away from the application's own
64
+ * routing.
65
+ *
66
+ * The mode knows its place:
67
+ * - any framework adapter wins — the first request after an adapter has
68
+ * initialized permanently disables standalone (an adapter records the same
69
+ * requests with full fidelity);
70
+ * - local development only: elsewhere the panel needs a gate, which requires
71
+ * the adapter's options anyway;
72
+ * - request and response bodies are not captured — reading somebody else's
73
+ * stream is not allowed — and Replay is off;
74
+ * - the route is the raw URL path: without a framework there is nothing to
75
+ * normalize it against.
76
+ */
77
+ /** Options for {@link enableStandalone}. Mostly for tests. */
78
+ interface StandaloneOptions {
79
+ /** Panel port; `0` picks a free one. Default: `REQRAY_PANEL_PORT` or 4310. */
80
+ readonly panelPort?: number;
81
+ }
82
+ /**
83
+ * Enables the standalone mode.
84
+ *
85
+ * Called automatically when `@reqray/register` is imported. Does nothing until
86
+ * the first incoming request, so an application with an adapter never even
87
+ * notices it. `REQRAY_STANDALONE=off` switches it off entirely.
88
+ */
89
+ declare function enableStandalone(options?: StandaloneOptions): void;
90
+ /** Address of the standalone panel, once it is up. Needed by tests. */
91
+ declare function standalonePanelUrl(): string | null;
92
+ /** Shuts standalone down and forgets its state. Needed by tests. */
93
+ declare function resetStandalone(): void;
94
+
95
+ export { type RegistryEntry, type StandaloneOptions, enableStandalone, register, registry, resetRegistration, resetStandalone, standalonePanelUrl };
@@ -0,0 +1,95 @@
1
+ import { Instrumentation } from '@reqray/core';
2
+
3
+ /**
4
+ * Installation of the loader hooks.
5
+ *
6
+ * The priority order is strict and fixed:
7
+ * 1. explicit registration by the user — always wins;
8
+ * 2. loader hooks for packages from the registry, with a semver range check;
9
+ * 3. `diagnostics_channel` where it exists natively — preferred over patching;
10
+ * 4. nothing, but with a clear message at startup.
11
+ *
12
+ * The hooks must be installed before the drivers are loaded, hence the
13
+ * recommended startup: `node --import @reqray/register`.
14
+ */
15
+ /**
16
+ * Installs the loader hooks and activates the instrumentations.
17
+ *
18
+ * Idempotent: a repeated call does nothing. Never throws — the application has
19
+ * to start even if Reqray could not attach.
20
+ *
21
+ * Takes no options. It used to accept a list of instrumentations to register
22
+ * explicitly, and never could honour it: importing this package calls
23
+ * `register()` on the spot, so a later call with a list returned at the first
24
+ * line. Explicit registration is an instrumentation's own `apply` — it needs
25
+ * no loader hook, which is exactly why it works in a bundle:
26
+ * `instrumentPg().apply(pg)`.
27
+ */
28
+ declare function register(): void;
29
+ /** Resets the installed flag. Needed by tests. */
30
+ declare function resetRegistration(): void;
31
+
32
+ /**
33
+ * Registry of packages Reqray can instrument.
34
+ *
35
+ * Two lists, because there are two ways in. Packages that need module
36
+ * interception are watched by the loader hooks. Instrumentations built on
37
+ * `diagnostics_channel` — undici, and therefore built-in `fetch` — need no
38
+ * loader at all and are simply switched on.
39
+ */
40
+
41
+ /** One package the loader hooks watch for. */
42
+ interface RegistryEntry {
43
+ /** Module name exactly as the application requires it. */
44
+ readonly module: string;
45
+ /**
46
+ * Versions this instrumentation has been tested against.
47
+ *
48
+ * Data, so deciding whether to watch a module does not mean building the
49
+ * thing that would watch it.
50
+ */
51
+ readonly supportedVersions: string;
52
+ /** Creates the instrumentation, once there is a module worth patching. */
53
+ create(): Instrumentation;
54
+ }
55
+ /** Packages instrumented through loader hooks. */
56
+ declare const registry: readonly RegistryEntry[];
57
+
58
+ /**
59
+ * Standalone mode: the panel with zero lines of code.
60
+ *
61
+ * `node --import @reqray/register app.js` is enough — incoming HTTP is
62
+ * observed through Node's own `diagnostics_channel` (no patching), and the
63
+ * panel comes up on a side port on loopback, away from the application's own
64
+ * routing.
65
+ *
66
+ * The mode knows its place:
67
+ * - any framework adapter wins — the first request after an adapter has
68
+ * initialized permanently disables standalone (an adapter records the same
69
+ * requests with full fidelity);
70
+ * - local development only: elsewhere the panel needs a gate, which requires
71
+ * the adapter's options anyway;
72
+ * - request and response bodies are not captured — reading somebody else's
73
+ * stream is not allowed — and Replay is off;
74
+ * - the route is the raw URL path: without a framework there is nothing to
75
+ * normalize it against.
76
+ */
77
+ /** Options for {@link enableStandalone}. Mostly for tests. */
78
+ interface StandaloneOptions {
79
+ /** Panel port; `0` picks a free one. Default: `REQRAY_PANEL_PORT` or 4310. */
80
+ readonly panelPort?: number;
81
+ }
82
+ /**
83
+ * Enables the standalone mode.
84
+ *
85
+ * Called automatically when `@reqray/register` is imported. Does nothing until
86
+ * the first incoming request, so an application with an adapter never even
87
+ * notices it. `REQRAY_STANDALONE=off` switches it off entirely.
88
+ */
89
+ declare function enableStandalone(options?: StandaloneOptions): void;
90
+ /** Address of the standalone panel, once it is up. Needed by tests. */
91
+ declare function standalonePanelUrl(): string | null;
92
+ /** Shuts standalone down and forgets its state. Needed by tests. */
93
+ declare function resetStandalone(): void;
94
+
95
+ export { type RegistryEntry, type StandaloneOptions, enableStandalone, register, registry, resetRegistration, resetStandalone, standalonePanelUrl };
package/dist/index.js ADDED
@@ -0,0 +1,296 @@
1
+ // src/install.ts
2
+ import { readFileSync } from "fs";
3
+ import { createRequire, register as registerLoader } from "module";
4
+ import { join, sep } from "path";
5
+ import { reportInstrumentation, warnOnce } from "@reqray/core";
6
+ import { Hook as EsmHook } from "import-in-the-middle";
7
+ import { Hook as CjsHook } from "require-in-the-middle";
8
+ import { satisfies } from "semver";
9
+
10
+ // src/registry.ts
11
+ import { instrumentIoredis } from "@reqray/instrumentation-ioredis";
12
+ import { instrumentPg } from "@reqray/instrumentation-pg";
13
+ import { instrumentUndici } from "@reqray/instrumentation-undici";
14
+ var registry = [
15
+ { module: "pg", supportedVersions: ">=8 <9", create: instrumentPg },
16
+ { module: "ioredis", supportedVersions: ">=5 <6", create: instrumentIoredis }
17
+ ];
18
+ var channelInstrumentations = [instrumentUndici];
19
+
20
+ // src/install.ts
21
+ var requireFrom = createRequire(import.meta.url);
22
+ var installed = false;
23
+ function versionAt(basedir) {
24
+ if (!basedir) return void 0;
25
+ try {
26
+ const manifest = JSON.parse(readFileSync(join(basedir, "package.json"), "utf8"));
27
+ return typeof manifest.version === "string" ? manifest.version : void 0;
28
+ } catch {
29
+ return void 0;
30
+ }
31
+ }
32
+ function alreadyLoaded(moduleName) {
33
+ const needle = `${sep}node_modules${sep}${moduleName}${sep}`;
34
+ for (const key of Object.keys(requireFrom.cache)) {
35
+ if (key.includes(needle)) return true;
36
+ }
37
+ return false;
38
+ }
39
+ var LOADED_TOO_LATE_HINT = "start with `node --import @reqray/register`";
40
+ function applyTo(instrumentation, exports, version) {
41
+ if (version && !satisfies(version, instrumentation.supportedVersions, { loose: true })) {
42
+ reportInstrumentation({
43
+ name: instrumentation.name,
44
+ version,
45
+ captures: instrumentation.captures ?? "",
46
+ ok: false,
47
+ reason: `version outside the supported range ${instrumentation.supportedVersions}`,
48
+ hint: "update Reqray, or patch the module yourself: `instrumentation.apply(module)` checks no version"
49
+ });
50
+ return;
51
+ }
52
+ try {
53
+ instrumentation.apply(exports);
54
+ reportInstrumentation({
55
+ name: instrumentation.name,
56
+ version,
57
+ captures: instrumentation.captures ?? "",
58
+ ok: true
59
+ });
60
+ } catch (error) {
61
+ const reason = error instanceof Error ? error.message : String(error);
62
+ reportInstrumentation({
63
+ name: instrumentation.name,
64
+ version,
65
+ captures: instrumentation.captures ?? "",
66
+ ok: false,
67
+ reason: `failed to patch: ${reason}`
68
+ });
69
+ warnOnce(`register.${instrumentation.name}`, `${instrumentation.name}: ${reason}`);
70
+ }
71
+ }
72
+ function register() {
73
+ if (installed) return;
74
+ installed = true;
75
+ try {
76
+ const wanted = /* @__PURE__ */ new Map();
77
+ for (const entry of registry) wanted.set(entry.module, entry.create());
78
+ for (const create of channelInstrumentations) {
79
+ const instrumentation = create();
80
+ instrumentation.apply(void 0);
81
+ reportInstrumentation({
82
+ name: instrumentation.name,
83
+ builtin: true,
84
+ captures: instrumentation.captures ?? "",
85
+ ok: true
86
+ });
87
+ }
88
+ const moduleNames = [...wanted.keys()];
89
+ if (moduleNames.length === 0) return;
90
+ for (const name of moduleNames) {
91
+ if (!alreadyLoaded(name)) continue;
92
+ const target = wanted.get(name);
93
+ if (!target) continue;
94
+ wanted.delete(name);
95
+ reportInstrumentation({
96
+ name,
97
+ captures: target.captures ?? "",
98
+ ok: false,
99
+ reason: "found, but loaded before reqray",
100
+ hint: LOADED_TOO_LATE_HINT
101
+ });
102
+ }
103
+ const hookable = [...wanted.keys()];
104
+ if (hookable.length === 0) return;
105
+ const onLoad = (exports, name, basedir) => {
106
+ const target = wanted.get(name);
107
+ if (target) applyTo(target, exports, versionAt(basedir));
108
+ return exports;
109
+ };
110
+ new CjsHook(hookable, onLoad);
111
+ try {
112
+ registerLoader("import-in-the-middle/hook.mjs", import.meta.url);
113
+ new EsmHook(hookable, onLoad);
114
+ } catch (error) {
115
+ const reason = error instanceof Error ? error.message : String(error);
116
+ warnOnce("register.esm", `ESM hooks not installed (${reason}); ${LOADED_TOO_LATE_HINT}`);
117
+ }
118
+ } catch (error) {
119
+ const reason = error instanceof Error ? error.message : String(error);
120
+ warnOnce("register.install", `automatic instrumentation did not attach: ${reason}`);
121
+ }
122
+ }
123
+ function resetRegistration() {
124
+ installed = false;
125
+ }
126
+
127
+ // src/standalone.ts
128
+ import { subscribe, unsubscribe } from "diagnostics_channel";
129
+ import { createServer } from "http";
130
+ import { createRequire as createRequire2 } from "module";
131
+ import { dirname, join as join2 } from "path";
132
+ import { createReqray, enterScope, isAdapterActive, warnOnce as warnOnce2 } from "@reqray/core";
133
+ import { createPanelHandler } from "@reqray/core/panel";
134
+ import { memoryTransport } from "@reqray/store-memory";
135
+ var CHANNEL = "http.server.request.start";
136
+ var state = {
137
+ subscribed: false,
138
+ runtime: null,
139
+ store: null,
140
+ panel: null,
141
+ panelPort: null,
142
+ panelUrl: null,
143
+ wantedPort: 4310
144
+ };
145
+ function dashboardAssets() {
146
+ try {
147
+ const manifest = createRequire2(import.meta.url).resolve("@reqray/dashboard/package.json");
148
+ return join2(dirname(manifest), "dist");
149
+ } catch {
150
+ return void 0;
151
+ }
152
+ }
153
+ function splitQuery(url) {
154
+ const index = url.indexOf("?");
155
+ return index === -1 ? [url, null] : [url.slice(0, index), url.slice(index + 1)];
156
+ }
157
+ function disable() {
158
+ if (state.subscribed) {
159
+ unsubscribe(CHANNEL, onRequestStart);
160
+ state.subscribed = false;
161
+ }
162
+ }
163
+ function ensureRuntime() {
164
+ if (state.runtime) return state.runtime;
165
+ const store = memoryTransport();
166
+ const runtime = createReqray({
167
+ // Replay needs the application's own origin, which standalone does not
168
+ // reliably know. Off, and said so in the startup line.
169
+ replay: false,
170
+ transport: store
171
+ });
172
+ if (!runtime.options.enabled || !runtime.options.isLocalDevelopment) {
173
+ disable();
174
+ return null;
175
+ }
176
+ state.runtime = runtime;
177
+ state.store = store;
178
+ return runtime;
179
+ }
180
+ function startPanel(runtime) {
181
+ if (state.panel || !state.store) return;
182
+ const handler = createPanelHandler({
183
+ source: state.store,
184
+ options: runtime.options,
185
+ assetsDir: dashboardAssets()
186
+ });
187
+ if (!handler) return;
188
+ const server = createServer((request, response) => {
189
+ if (handler(request, response)) return;
190
+ if (request.url === "/" || request.url === "") {
191
+ response.writeHead(302, { location: "/_reqray/" });
192
+ response.end();
193
+ return;
194
+ }
195
+ response.writeHead(404, { "content-type": "application/json; charset=utf-8" });
196
+ response.end('{"error":"this is the reqray panel: /_reqray/"}');
197
+ });
198
+ state.panel = server;
199
+ let retried = false;
200
+ server.on("error", (error) => {
201
+ if (error.code === "EADDRINUSE" && !retried) {
202
+ retried = true;
203
+ server.listen(0, "127.0.0.1");
204
+ return;
205
+ }
206
+ warnOnce2("standalone.panel", `panel did not start: ${error.message}`);
207
+ state.panel = null;
208
+ });
209
+ server.listen(state.wantedPort, "127.0.0.1", () => {
210
+ const address = server.address();
211
+ state.panelPort = address.port;
212
+ state.panelUrl = `http://127.0.0.1:${address.port}/_reqray/`;
213
+ console.log(
214
+ `reqray: no adapter found \u2014 panel is up at ${state.panelUrl}
215
+ standalone mode: no request bodies, no Replay, paths without route normalization.
216
+ Full recording comes with an adapter: @reqray/fastify, @reqray/express, @reqray/nestjs.`
217
+ );
218
+ });
219
+ server.unref();
220
+ }
221
+ function onRequestStart(message) {
222
+ try {
223
+ if (isAdapterActive()) {
224
+ disable();
225
+ return;
226
+ }
227
+ const { request, response } = message;
228
+ if (state.panelPort !== null && request.socket?.localPort === state.panelPort) return;
229
+ const runtime = ensureRuntime();
230
+ if (!runtime) return;
231
+ const [path, query] = splitQuery(request.url ?? "/");
232
+ const scope = runtime.begin({ method: request.method ?? "GET", path });
233
+ if (!scope) return;
234
+ startPanel(runtime);
235
+ enterScope(scope);
236
+ const handlerSpan = scope.openSpan("handler", `${request.method} ${path}`);
237
+ let finished = false;
238
+ const complete = () => {
239
+ if (finished) return;
240
+ finished = true;
241
+ try {
242
+ scope.closeSpan(handlerSpan);
243
+ runtime.finish(scope, {
244
+ status: response.statusCode,
245
+ query,
246
+ requestHeaders: request.headers,
247
+ responseHeaders: response.getHeaders()
248
+ // Bodies are deliberately absent: consuming somebody else's stream
249
+ // is not an option, and observing it passively changes its mode.
250
+ });
251
+ } catch (error) {
252
+ const reason = error instanceof Error ? error.message : String(error);
253
+ warnOnce2("standalone.finish", `request not recorded: ${reason}`);
254
+ }
255
+ };
256
+ response.once("finish", complete);
257
+ response.once("close", complete);
258
+ } catch (error) {
259
+ const reason = error instanceof Error ? error.message : String(error);
260
+ warnOnce2("standalone.request", `standalone recording disabled after an error: ${reason}`);
261
+ disable();
262
+ }
263
+ }
264
+ function enableStandalone(options = {}) {
265
+ if (state.subscribed) return;
266
+ if (process.env["REQRAY_STANDALONE"] === "off") return;
267
+ const envPort = Number(process.env["REQRAY_PANEL_PORT"]);
268
+ state.wantedPort = options.panelPort ?? (Number.isInteger(envPort) ? envPort : 4310);
269
+ subscribe(CHANNEL, onRequestStart);
270
+ state.subscribed = true;
271
+ }
272
+ function standalonePanelUrl() {
273
+ return state.panelUrl;
274
+ }
275
+ function resetStandalone() {
276
+ disable();
277
+ state.panel?.close();
278
+ state.panel = null;
279
+ state.panelPort = null;
280
+ state.panelUrl = null;
281
+ state.runtime = null;
282
+ state.store = null;
283
+ }
284
+
285
+ // src/index.ts
286
+ register();
287
+ enableStandalone();
288
+ export {
289
+ enableStandalone,
290
+ register,
291
+ registry,
292
+ resetRegistration,
293
+ resetStandalone,
294
+ standalonePanelUrl
295
+ };
296
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/install.ts","../src/registry.ts","../src/standalone.ts","../src/index.ts"],"sourcesContent":["/**\n * Installation of the loader hooks.\n *\n * The priority order is strict and fixed:\n * 1. explicit registration by the user — always wins;\n * 2. loader hooks for packages from the registry, with a semver range check;\n * 3. `diagnostics_channel` where it exists natively — preferred over patching;\n * 4. nothing, but with a clear message at startup.\n *\n * The hooks must be installed before the drivers are loaded, hence the\n * recommended startup: `node --import @reqray/register`.\n */\n\nimport { readFileSync } from 'node:fs';\nimport { createRequire, register as registerLoader } from 'node:module';\nimport { join, sep } from 'node:path';\nimport { type Instrumentation, reportInstrumentation, warnOnce } from '@reqray/core';\nimport { Hook as EsmHook, type HookFn as EsmHookFn } from 'import-in-the-middle';\nimport { Hook as CjsHook } from 'require-in-the-middle';\nimport { satisfies } from 'semver';\nimport { channelInstrumentations, registry } from './registry.js';\n\nconst requireFrom = createRequire(import.meta.url);\n\nlet installed = false;\n\n/** Version of the loaded module — resolved from the module's own directory. */\nfunction versionAt(basedir: string | undefined): string | undefined {\n if (!basedir) return undefined;\n try {\n const manifest = JSON.parse(readFileSync(join(basedir, 'package.json'), 'utf8')) as {\n version?: unknown;\n };\n return typeof manifest.version === 'string' ? manifest.version : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The module is already in the CJS cache — meaning the application loaded it\n * before us, and a hook on it will never fire.\n *\n * Modules loaded through ESM are not visible this way: the loader does not\n * expose their state. So this is a best-effort check, not a guarantee.\n */\nfunction alreadyLoaded(moduleName: string): boolean {\n const needle = `${sep}node_modules${sep}${moduleName}${sep}`;\n for (const key of Object.keys(requireFrom.cache)) {\n if (key.includes(needle)) return true;\n }\n return false;\n}\n\nconst LOADED_TOO_LATE_HINT = 'start with `node --import @reqray/register`';\n\nfunction applyTo(\n instrumentation: Instrumentation,\n exports: unknown,\n version: string | undefined,\n): void {\n // Silently patching an unknown major version is not allowed.\n if (version && !satisfies(version, instrumentation.supportedVersions, { loose: true })) {\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: false,\n reason: `version outside the supported range ${instrumentation.supportedVersions}`,\n hint: 'update Reqray, or patch the module yourself: `instrumentation.apply(module)` checks no version',\n });\n return;\n }\n\n try {\n instrumentation.apply(exports);\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: true,\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n reportInstrumentation({\n name: instrumentation.name,\n version,\n captures: instrumentation.captures ?? '',\n ok: false,\n reason: `failed to patch: ${reason}`,\n });\n warnOnce(`register.${instrumentation.name}`, `${instrumentation.name}: ${reason}`);\n }\n}\n\n/**\n * Installs the loader hooks and activates the instrumentations.\n *\n * Idempotent: a repeated call does nothing. Never throws — the application has\n * to start even if Reqray could not attach.\n *\n * Takes no options. It used to accept a list of instrumentations to register\n * explicitly, and never could honour it: importing this package calls\n * `register()` on the spot, so a later call with a list returned at the first\n * line. Explicit registration is an instrumentation's own `apply` — it needs\n * no loader hook, which is exactly why it works in a bundle:\n * `instrumentPg().apply(pg)`.\n */\nexport function register(): void {\n if (installed) return;\n installed = true;\n\n try {\n const wanted = new Map<string, Instrumentation>();\n for (const entry of registry) wanted.set(entry.module, entry.create());\n\n // diagnostics_channel does not depend on the loader — enable it right away.\n for (const create of channelInstrumentations) {\n const instrumentation = create();\n instrumentation.apply(undefined);\n reportInstrumentation({\n name: instrumentation.name,\n builtin: true,\n captures: instrumentation.captures ?? '',\n ok: true,\n });\n }\n\n const moduleNames = [...wanted.keys()];\n if (moduleNames.length === 0) return;\n\n // 4. Packages loaded before us cannot be hooked any more — report that\n // honestly instead of silently doing nothing.\n for (const name of moduleNames) {\n if (!alreadyLoaded(name)) continue;\n const target = wanted.get(name);\n if (!target) continue;\n wanted.delete(name);\n reportInstrumentation({\n name,\n captures: target.captures ?? '',\n ok: false,\n reason: 'found, but loaded before reqray',\n hint: LOADED_TOO_LATE_HINT,\n });\n }\n\n const hookable = [...wanted.keys()];\n if (hookable.length === 0) return;\n\n // The exports object is returned unchanged: instrumentation patches it in\n // place, the module object itself must not be substituted.\n // `import-in-the-middle` declares basedir as `string | void`, so the\n // signature accepts both that and `string | undefined` from the CJS hook.\n const onLoad = <T>(exports: T, name: string, basedir?: string): T => {\n const target = wanted.get(name);\n if (target) applyTo(target, exports, versionAt(basedir));\n return exports;\n };\n\n // 2. Loader hooks: CJS and ESM are installed independently of each other.\n new CjsHook(hookable, onLoad);\n\n try {\n registerLoader('import-in-the-middle/hook.mjs', import.meta.url);\n new EsmHook(hookable, onLoad as EsmHookFn);\n } catch (error) {\n // ESM hooks require Reqray to be loaded via `--import`. Without them the\n // CJS interception remains — not a reason to fail.\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('register.esm', `ESM hooks not installed (${reason}); ${LOADED_TOO_LATE_HINT}`);\n }\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('register.install', `automatic instrumentation did not attach: ${reason}`);\n }\n}\n\n/** Resets the installed flag. Needed by tests. */\nexport function resetRegistration(): void {\n installed = false;\n}\n","/**\n * Registry of packages Reqray can instrument.\n *\n * Two lists, because there are two ways in. Packages that need module\n * interception are watched by the loader hooks. Instrumentations built on\n * `diagnostics_channel` — undici, and therefore built-in `fetch` — need no\n * loader at all and are simply switched on.\n */\n\nimport type { Instrumentation } from '@reqray/core';\nimport { instrumentIoredis } from '@reqray/instrumentation-ioredis';\nimport { instrumentPg } from '@reqray/instrumentation-pg';\nimport { instrumentUndici } from '@reqray/instrumentation-undici';\n\n/** One package the loader hooks watch for. */\nexport interface RegistryEntry {\n /** Module name exactly as the application requires it. */\n readonly module: string;\n /**\n * Versions this instrumentation has been tested against.\n *\n * Data, so deciding whether to watch a module does not mean building the\n * thing that would watch it.\n */\n readonly supportedVersions: string;\n /** Creates the instrumentation, once there is a module worth patching. */\n create(): Instrumentation;\n}\n\n/** Packages instrumented through loader hooks. */\nexport const registry: readonly RegistryEntry[] = [\n { module: 'pg', supportedVersions: '>=8 <9', create: instrumentPg },\n { module: 'ioredis', supportedVersions: '>=5 <6', create: instrumentIoredis },\n];\n\n/**\n * Instrumentations that need no loader hook.\n *\n * They subscribe to a channel the runtime already publishes, so there is no\n * module to intercept and no version to check — the channel is the contract.\n */\nexport const channelInstrumentations: readonly (() => Instrumentation)[] = [instrumentUndici];\n","/**\n * Standalone mode: the panel with zero lines of code.\n *\n * `node --import @reqray/register app.js` is enough — incoming HTTP is\n * observed through Node's own `diagnostics_channel` (no patching), and the\n * panel comes up on a side port on loopback, away from the application's own\n * routing.\n *\n * The mode knows its place:\n * - any framework adapter wins — the first request after an adapter has\n * initialized permanently disables standalone (an adapter records the same\n * requests with full fidelity);\n * - local development only: elsewhere the panel needs a gate, which requires\n * the adapter's options anyway;\n * - request and response bodies are not captured — reading somebody else's\n * stream is not allowed — and Replay is off;\n * - the route is the raw URL path: without a framework there is nothing to\n * normalize it against.\n */\n\nimport { subscribe, unsubscribe } from 'node:diagnostics_channel';\nimport { createServer, type IncomingMessage, type Server, type ServerResponse } from 'node:http';\nimport { createRequire } from 'node:module';\nimport type { AddressInfo } from 'node:net';\nimport { dirname, join } from 'node:path';\nimport { createReqray, enterScope, isAdapterActive, type Reqray, warnOnce } from '@reqray/core';\nimport { createPanelHandler } from '@reqray/core/panel';\nimport { type MemoryStore, memoryTransport } from '@reqray/store-memory';\n\nconst CHANNEL = 'http.server.request.start';\n\n/** Options for {@link enableStandalone}. Mostly for tests. */\nexport interface StandaloneOptions {\n /** Panel port; `0` picks a free one. Default: `REQRAY_PANEL_PORT` or 4310. */\n readonly panelPort?: number;\n}\n\ninterface StandaloneState {\n subscribed: boolean;\n runtime: Reqray | null;\n store: MemoryStore | null;\n panel: Server | null;\n panelPort: number | null;\n panelUrl: string | null;\n wantedPort: number;\n}\n\nconst state: StandaloneState = {\n subscribed: false,\n runtime: null,\n store: null,\n panel: null,\n panelPort: null,\n panelUrl: null,\n wantedPort: 4310,\n};\n\nfunction dashboardAssets(): string | undefined {\n try {\n const manifest = createRequire(import.meta.url).resolve('@reqray/dashboard/package.json');\n return join(dirname(manifest), 'dist');\n } catch {\n return undefined;\n }\n}\n\nfunction splitQuery(url: string): [path: string, query: string | null] {\n const index = url.indexOf('?');\n return index === -1 ? [url, null] : [url.slice(0, index), url.slice(index + 1)];\n}\n\n/** Permanently stands down: after this the channel costs nothing per request. */\nfunction disable(): void {\n if (state.subscribed) {\n unsubscribe(CHANNEL, onRequestStart);\n state.subscribed = false;\n }\n}\n\n/**\n * The runtime, created on the first captured request.\n *\n * `null` means standalone must not run here at all — and `disable()` has\n * already been called.\n */\nfunction ensureRuntime(): Reqray | null {\n if (state.runtime) return state.runtime;\n\n const store = memoryTransport();\n const runtime = createReqray({\n // Replay needs the application's own origin, which standalone does not\n // reliably know. Off, and said so in the startup line.\n replay: false,\n transport: store,\n });\n\n // Standalone is a local-development tool: anywhere else the panel needs a\n // gate, and a gate is configured through an adapter anyway.\n if (!runtime.options.enabled || !runtime.options.isLocalDevelopment) {\n disable();\n return null;\n }\n\n state.runtime = runtime;\n state.store = store;\n return runtime;\n}\n\nfunction startPanel(runtime: Reqray): void {\n if (state.panel || !state.store) return;\n\n const handler = createPanelHandler({\n source: state.store,\n options: runtime.options,\n assetsDir: dashboardAssets(),\n });\n if (!handler) return;\n\n const server = createServer((request, response) => {\n if (handler(request, response)) return;\n if (request.url === '/' || request.url === '') {\n response.writeHead(302, { location: '/_reqray/' });\n response.end();\n return;\n }\n response.writeHead(404, { 'content-type': 'application/json; charset=utf-8' });\n response.end('{\"error\":\"this is the reqray panel: /_reqray/\"}');\n });\n state.panel = server;\n\n let retried = false;\n server.on('error', (error: NodeJS.ErrnoException) => {\n // The chosen port is busy — most likely a second application with its\n // own standalone panel. A random port is better than no panel.\n if (error.code === 'EADDRINUSE' && !retried) {\n retried = true;\n server.listen(0, '127.0.0.1');\n return;\n }\n warnOnce('standalone.panel', `panel did not start: ${error.message}`);\n state.panel = null;\n });\n\n server.listen(state.wantedPort, '127.0.0.1', () => {\n const address = server.address() as AddressInfo;\n state.panelPort = address.port;\n state.panelUrl = `http://127.0.0.1:${address.port}/_reqray/`;\n console.log(\n `reqray: no adapter found — panel is up at ${state.panelUrl}\\n` +\n ' standalone mode: no request bodies, no Replay, paths without route normalization.\\n' +\n ' Full recording comes with an adapter: @reqray/fastify, @reqray/express, @reqray/nestjs.',\n );\n });\n // The side server must never keep the application process alive.\n server.unref();\n}\n\nfunction onRequestStart(message: unknown): void {\n try {\n // An adapter records the same requests with full fidelity — from here on\n // the channel must cost nothing.\n if (isAdapterActive()) {\n disable();\n return;\n }\n\n const { request, response } = message as {\n request: IncomingMessage;\n response: ServerResponse;\n };\n // The panel's own traffic must not appear in the list it displays.\n if (state.panelPort !== null && request.socket?.localPort === state.panelPort) return;\n\n const runtime = ensureRuntime();\n if (!runtime) return;\n\n const [path, query] = splitQuery(request.url ?? '/');\n const scope = runtime.begin({ method: request.method ?? 'GET', path });\n if (!scope) return;\n\n startPanel(runtime);\n\n // The publish happens synchronously right before the 'request' event, so\n // the scope entered here is visible to the application's handler.\n enterScope(scope);\n const handlerSpan = scope.openSpan('handler', `${request.method} ${path}`);\n\n let finished = false;\n const complete = (): void => {\n if (finished) return;\n finished = true;\n try {\n scope.closeSpan(handlerSpan);\n runtime.finish(scope, {\n status: response.statusCode,\n query,\n requestHeaders: request.headers,\n responseHeaders: response.getHeaders(),\n // Bodies are deliberately absent: consuming somebody else's stream\n // is not an option, and observing it passively changes its mode.\n });\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('standalone.finish', `request not recorded: ${reason}`);\n }\n };\n response.once('finish', complete);\n response.once('close', complete);\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n warnOnce('standalone.request', `standalone recording disabled after an error: ${reason}`);\n disable();\n }\n}\n\n/**\n * Enables the standalone mode.\n *\n * Called automatically when `@reqray/register` is imported. Does nothing until\n * the first incoming request, so an application with an adapter never even\n * notices it. `REQRAY_STANDALONE=off` switches it off entirely.\n */\nexport function enableStandalone(options: StandaloneOptions = {}): void {\n if (state.subscribed) return;\n if (process.env['REQRAY_STANDALONE'] === 'off') return;\n\n const envPort = Number(process.env['REQRAY_PANEL_PORT']);\n state.wantedPort = options.panelPort ?? (Number.isInteger(envPort) ? envPort : 4310);\n\n subscribe(CHANNEL, onRequestStart);\n state.subscribed = true;\n}\n\n/** Address of the standalone panel, once it is up. Needed by tests. */\nexport function standalonePanelUrl(): string | null {\n return state.panelUrl;\n}\n\n/** Shuts standalone down and forgets its state. Needed by tests. */\nexport function resetStandalone(): void {\n disable();\n state.panel?.close();\n state.panel = null;\n state.panelPort = null;\n state.panelUrl = null;\n state.runtime = null;\n state.store = null;\n}\n","/**\n * `@reqray/register` — automatic instrumentation.\n *\n * Importing this module installs the loader hooks, so the recommended way to\n * start an application is:\n *\n * ```\n * node --import @reqray/register app.js\n * ```\n *\n * The hooks must be in place before the application loads its drivers: there is\n * no way to intercept a module that was loaded before us — Reqray reports such a\n * case honestly in the startup report.\n *\n * For bundled applications (esbuild, tsup) automatic instrumentation cannot\n * work at all: the bundler resolves imports at build time, so no loader hook\n * ever happens. There, only explicit registration remains — an\n * instrumentation applied by hand to the module the bundle already holds:\n * `instrumentPg().apply(pg)`.\n */\n\nexport { register, resetRegistration } from './install.js';\nexport { type RegistryEntry, registry } from './registry.js';\nexport {\n enableStandalone,\n resetStandalone,\n type StandaloneOptions,\n standalonePanelUrl,\n} from './standalone.js';\n\nimport { register } from './install.js';\nimport { enableStandalone } from './standalone.js';\n\nregister();\n// Zero lines of code: with no adapter around, the panel comes up by itself.\nenableStandalone();\n"],"mappings":";AAaA,SAAS,oBAAoB;AAC7B,SAAS,eAAe,YAAY,sBAAsB;AAC1D,SAAS,MAAM,WAAW;AAC1B,SAA+B,uBAAuB,gBAAgB;AACtE,SAAS,QAAQ,eAAyC;AAC1D,SAAS,QAAQ,eAAe;AAChC,SAAS,iBAAiB;;;ACT1B,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAkB1B,IAAM,WAAqC;AAAA,EAChD,EAAE,QAAQ,MAAM,mBAAmB,UAAU,QAAQ,aAAa;AAAA,EAClE,EAAE,QAAQ,WAAW,mBAAmB,UAAU,QAAQ,kBAAkB;AAC9E;AAQO,IAAM,0BAA8D,CAAC,gBAAgB;;;ADnB5F,IAAM,cAAc,cAAc,YAAY,GAAG;AAEjD,IAAI,YAAY;AAGhB,SAAS,UAAU,SAAiD;AAClE,MAAI,CAAC,QAAS,QAAO;AACrB,MAAI;AACF,UAAM,WAAW,KAAK,MAAM,aAAa,KAAK,SAAS,cAAc,GAAG,MAAM,CAAC;AAG/E,WAAO,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;AAAA,EACnE,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AASA,SAAS,cAAc,YAA6B;AAClD,QAAM,SAAS,GAAG,GAAG,eAAe,GAAG,GAAG,UAAU,GAAG,GAAG;AAC1D,aAAW,OAAO,OAAO,KAAK,YAAY,KAAK,GAAG;AAChD,QAAI,IAAI,SAAS,MAAM,EAAG,QAAO;AAAA,EACnC;AACA,SAAO;AACT;AAEA,IAAM,uBAAuB;AAE7B,SAAS,QACP,iBACA,SACA,SACM;AAEN,MAAI,WAAW,CAAC,UAAU,SAAS,gBAAgB,mBAAmB,EAAE,OAAO,KAAK,CAAC,GAAG;AACtF,0BAAsB;AAAA,MACpB,MAAM,gBAAgB;AAAA,MACtB;AAAA,MACA,UAAU,gBAAgB,YAAY;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jB;AAAA,UACA,gBAAgB,QAAQ;AAAA,UACxB,iBAAiB,SAAS,WAAW;AAAA;AAAA;AAAA,QAGvC,CAAC;AAAA,MACH,SAAS,OAAO;AACd,cAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACpE,QAAAA,UAAS,qBAAqB,yBAAyB,MAAM,EAAE;AAAA,MACjE;AAAA,IACF;AACA,aAAS,KAAK,UAAU,QAAQ;AAChC,aAAS,KAAK,SAAS,QAAQ;AAAA,EACjC,SAAS,OAAO;AACd,UAAM,SAAS,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AACpE,IAAAA,UAAS,sBAAsB,iDAAiD,MAAM,EAAE;AACxF,YAAQ;AAAA,EACV;AACF;AASO,SAAS,iBAAiB,UAA6B,CAAC,GAAS;AACtE,MAAI,MAAM,WAAY;AACtB,MAAI,QAAQ,IAAI,mBAAmB,MAAM,MAAO;AAEhD,QAAM,UAAU,OAAO,QAAQ,IAAI,mBAAmB,CAAC;AACvD,QAAM,aAAa,QAAQ,cAAc,OAAO,UAAU,OAAO,IAAI,UAAU;AAE/E,YAAU,SAAS,cAAc;AACjC,QAAM,aAAa;AACrB;AAGO,SAAS,qBAAoC;AAClD,SAAO,MAAM;AACf;AAGO,SAAS,kBAAwB;AACtC,UAAQ;AACR,QAAM,OAAO,MAAM;AACnB,QAAM,QAAQ;AACd,QAAM,YAAY;AAClB,QAAM,WAAW;AACjB,QAAM,UAAU;AAChB,QAAM,QAAQ;AAChB;;;ACtNA,SAAS;AAET,iBAAiB;","names":["createRequire","join","warnOnce"]}
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@reqray/register",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Start with `node --import @reqray/register` and a Node.js app's requests become waterfalls: SQL, cache and outgoing HTTP instrumented automatically, N+1 found down to the line.",
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/register"
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
+ "import-in-the-middle": "^3.3.3",
52
+ "require-in-the-middle": "^8.0.1",
53
+ "semver": "^7.8.5",
54
+ "@reqray/core": "^0.1.1",
55
+ "@reqray/instrumentation-pg": "^0.1.1",
56
+ "@reqray/instrumentation-ioredis": "^0.1.1",
57
+ "@reqray/store-memory": "^0.1.1",
58
+ "@reqray/dashboard": "^0.1.1",
59
+ "@reqray/instrumentation-undici": "^0.1.1"
60
+ },
61
+ "devDependencies": {
62
+ "@types/node": "^26.2.0",
63
+ "tsup": "^8.5.1",
64
+ "typescript": "^6.0.3",
65
+ "@types/semver": "^7.8.0",
66
+ "pg": "^8.23.0"
67
+ },
68
+ "scripts": {
69
+ "build": "tsup",
70
+ "typecheck": "tsc --noEmit"
71
+ }
6
72
  }