@rootcat/node 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm.mjs CHANGED
@@ -17,22 +17,38 @@ async function main() {
17
17
  return; // the loader hooks thread runs the same preloads; nothing to do there
18
18
  }
19
19
  let waitForAllMessagesAcknowledged = async () => undefined;
20
- try {
21
- const { hookedPackages, esmHookMarker } = require('./esmhook.js');
22
- const iitmPath = createRequire(require.resolve('@opentelemetry/instrumentation/package.json')).resolve('import-in-the-middle');
23
- const iitm = await import(pathToFileURL(iitmPath).href);
24
- const channel = iitm.createAddHookMessageChannel();
25
- // The channel lists only the packages the instrumentations name, by
26
- // bare specifier; a package patched through one of its internal files
27
- // (Drizzle's query classes) must be matched by path as well.
28
- channel.registerOptions.data.include.push(hookedPackages);
29
- const hook = require.resolve('@opentelemetry/instrumentation/hook.mjs');
30
- register(pathToFileURL(hook).href, import.meta.url, channel.registerOptions);
31
- globalThis[esmHookMarker] = true;
32
- waitForAllMessagesAcknowledged = channel.waitForAllMessagesAcknowledged;
33
- } catch (error) {
34
- const reason = error instanceof Error ? error.message : String(error);
35
- process.stderr.write(`rootcat: ES module hook not registered (${reason.slice(0, 200)}); CommonJS modules are still traced\n`);
20
+ // An application whose tracer sets up OpenTelemetry when it initialises
21
+ // (Sentry) starts Rootcat after it (startAlongside); this entry runs
22
+ // before it, so it registers nothing and register.js says what to do
23
+ // instead.
24
+ const { providerRegistered, tracerDependency } = require('./coexist.js');
25
+ const waitsForTracer = !providerRegistered() && tracerDependency(process.cwd()) !== undefined;
26
+ if (!waitsForTracer) {
27
+ try {
28
+ const { hookedPackages, esmHookMarker, ownInstancePossible, noInstanceLine } = require('./esmhook.js');
29
+ if (!ownInstancePossible()) {
30
+ throw Object.assign(new Error('no create-hook.mjs'), { line: noInstanceLine });
31
+ }
32
+ const iitmPath = createRequire(require.resolve('@opentelemetry/instrumentation/package.json')).resolve('import-in-the-middle');
33
+ const iitm = await import(pathToFileURL(iitmPath).href);
34
+ const channel = iitm.createAddHookMessageChannel();
35
+ // The channel lists only the packages the instrumentations name, by
36
+ // bare specifier; a package patched through one of its internal files
37
+ // (Drizzle's query classes) must be matched by path as well.
38
+ channel.registerOptions.data.include.push(hookedPackages);
39
+ // The package's own import-in-the-middle instance (iitm-hook.mjs),
40
+ // never a second registration of a hook another SDK registered.
41
+ register(new URL('./iitm-hook.mjs', import.meta.url).href, import.meta.url, channel.registerOptions);
42
+ globalThis[esmHookMarker] = true;
43
+ waitForAllMessagesAcknowledged = channel.waitForAllMessagesAcknowledged;
44
+ } catch (error) {
45
+ if (typeof error?.line === 'string') {
46
+ process.stderr.write(error.line);
47
+ } else {
48
+ const reason = error instanceof Error ? error.message : String(error);
49
+ process.stderr.write(`rootcat: ES module hook not registered (${reason.slice(0, 200)}); CommonJS modules are still traced\n`);
50
+ }
51
+ }
36
52
  }
37
53
  require('./register.js');
38
54
  await waitForAllMessagesAcknowledged();
package/dist/esmhook.d.ts CHANGED
@@ -1,12 +1,52 @@
1
1
  /** esmHookMarker is set on globalThis once a hook is registered. */
2
2
  export declare const esmHookMarker: unique symbol;
3
- /** hookedPackages are the packages the loader wraps for the instrumentations. */
3
+ /**
4
+ * hookedPackages are the modules the loader wraps for the
5
+ * instrumentations. The CommonJS packages are matched whole (their
6
+ * internal files load through require, never through the loader). Of
7
+ * the ES module packages only the files the instrumentations patch are
8
+ * wrapped: postgres.js's entry, and Drizzle's two query classes. Wrapping
9
+ * every file of postgres.js would also hand its internal query.js to any
10
+ * other SDK's hook for it: Sentry patches that file to trace the
11
+ * driver's own connection queries, which it otherwise does only in
12
+ * CommonJS.
13
+ */
4
14
  export declare const hookedPackages: RegExp;
15
+ /**
16
+ * noInstanceLine is said when the installed import-in-the-middle has no
17
+ * create-hook.mjs: the package cannot make a hook instance of its own,
18
+ * and a second registration of the shared hook.mjs would replace the
19
+ * options of another SDK that registered it (Sentry's, behind its request
20
+ * isolation), so it registers none: CommonJS modules are still traced.
21
+ */
22
+ export declare const noInstanceLine = "rootcat: the installed import-in-the-middle has no create-hook.mjs; the ES module hook is not registered (ES modules are not traced; CommonJS modules are)\n";
23
+ /**
24
+ * ownInstancePossible reports whether the import-in-the-middle copy
25
+ * @opentelemetry/instrumentation uses has create-hook.mjs (see
26
+ * iitm-hook.mjs).
27
+ */
28
+ export declare function ownInstancePossible(): boolean;
29
+ /**
30
+ * ownedModules are the ES module files only the package patches:
31
+ * postgres.js's entry and Drizzle's two query classes. Beside a tracer
32
+ * that records nothing, the package's hook takes them over from another
33
+ * import-in-the-middle hook that marked them (see iitm-hook.mjs); inside
34
+ * a tracer that records spans, Drizzle's only (that tracer may
35
+ * instrument postgres.js itself).
36
+ */
37
+ export declare const ownedModules: RegExp;
38
+ export declare const drizzleModules: RegExp;
5
39
  /** ESMHook says whether the hook was registered. */
6
40
  export type ESMHook = 'on' | 'off';
41
+ /**
42
+ * quietESMHook makes the package's loader hook pass every module through
43
+ * from now on: a loader hook cannot be removed once registered, so a
44
+ * stopped package leaves it in place, idle.
45
+ */
46
+ export declare function quietESMHook(): void;
7
47
  /**
8
48
  * registerESMHook registers the instrumentation loader hook once and
9
49
  * reports whether it is in place. A failure to register never reaches the
10
50
  * application.
11
51
  */
12
- export declare function registerESMHook(report?: (reason: string) => void): ESMHook;
52
+ export declare function registerESMHook(report?: (reason: string) => void, takeOver?: RegExp, include?: RegExp): ESMHook;
package/dist/esmhook.js CHANGED
@@ -33,31 +33,93 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.hookedPackages = exports.esmHookMarker = void 0;
36
+ exports.drizzleModules = exports.ownedModules = exports.noInstanceLine = exports.hookedPackages = exports.esmHookMarker = void 0;
37
+ exports.ownInstancePossible = ownInstancePossible;
38
+ exports.quietESMHook = quietESMHook;
37
39
  exports.registerESMHook = registerESMHook;
38
40
  // The ES module loader hook from the CommonJS entry. A CommonJS
39
41
  // application still loads ES module packages through the ESM loader
40
42
  // (postgres.js is ESM first; Next.js imports its external packages as
41
43
  // ES modules), and only a loader hook can patch those. The hook watches
42
- // a fixed list of packages, so nothing else pays for it.
44
+ // a fixed list of modules, so nothing else pays for it.
43
45
  //
44
46
  // It runs on the loader's hooks thread (module.register), which costs
45
47
  // about 0.2 s of startup (every module load waits on the thread; see the
46
48
  // benchmark). The in-thread synchronous hooks (module.registerHooks) save
47
49
  // most of that, but in a Next.js standalone server they left postgres.js
48
50
  // and Drizzle unpatched.
51
+ const fs = __importStar(require("node:fs"));
49
52
  const nodeModule = __importStar(require("node:module"));
50
53
  const node_url_1 = require("node:url");
54
+ const node_worker_threads_1 = require("node:worker_threads");
51
55
  /** esmHookMarker is set on globalThis once a hook is registered. */
52
56
  exports.esmHookMarker = Symbol.for('rootcat.node.esmHook');
53
- /** hookedPackages are the packages the loader wraps for the instrumentations. */
54
- exports.hookedPackages = /[\\/]node_modules[\\/](pg|pg-pool|postgres|drizzle-orm|mysql2|mongodb|ioredis|redis|@redis|undici|@prisma)[\\/]/;
57
+ /**
58
+ * hookedPackages are the modules the loader wraps for the
59
+ * instrumentations. The CommonJS packages are matched whole (their
60
+ * internal files load through require, never through the loader). Of
61
+ * the ES module packages only the files the instrumentations patch are
62
+ * wrapped: postgres.js's entry, and Drizzle's two query classes. Wrapping
63
+ * every file of postgres.js would also hand its internal query.js to any
64
+ * other SDK's hook for it: Sentry patches that file to trace the
65
+ * driver's own connection queries, which it otherwise does only in
66
+ * CommonJS.
67
+ */
68
+ exports.hookedPackages = /[\\/]node_modules[\\/](?:(?:pg|pg-pool|mysql2|mongodb|ioredis|redis|@redis|undici|@prisma)[\\/]|postgres[\\/](?:cjs[\\/])?src[\\/]index\.js(?:[?#].*)?$|drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs)(?:[?#].*)?$)/;
69
+ /**
70
+ * noInstanceLine is said when the installed import-in-the-middle has no
71
+ * create-hook.mjs: the package cannot make a hook instance of its own,
72
+ * and a second registration of the shared hook.mjs would replace the
73
+ * options of another SDK that registered it (Sentry's, behind its request
74
+ * isolation), so it registers none: CommonJS modules are still traced.
75
+ */
76
+ exports.noInstanceLine = 'rootcat: the installed import-in-the-middle has no create-hook.mjs; the ES module hook is not registered (ES modules are not traced; CommonJS modules are)\n';
77
+ /**
78
+ * ownInstancePossible reports whether the import-in-the-middle copy
79
+ * @opentelemetry/instrumentation uses has create-hook.mjs (see
80
+ * iitm-hook.mjs).
81
+ */
82
+ function ownInstancePossible() {
83
+ try {
84
+ const fromInstrumentation = nodeModule.createRequire(require.resolve('@opentelemetry/instrumentation/package.json'));
85
+ const hookPath = fromInstrumentation.resolve('import-in-the-middle/hook.mjs');
86
+ return fs.statSync(hookPath.replace(/hook\.mjs$/, 'create-hook.mjs')).isFile();
87
+ }
88
+ catch {
89
+ return false;
90
+ }
91
+ }
92
+ /**
93
+ * ownedModules are the ES module files only the package patches:
94
+ * postgres.js's entry and Drizzle's two query classes. Beside a tracer
95
+ * that records nothing, the package's hook takes them over from another
96
+ * import-in-the-middle hook that marked them (see iitm-hook.mjs); inside
97
+ * a tracer that records spans, Drizzle's only (that tracer may
98
+ * instrument postgres.js itself).
99
+ */
100
+ exports.ownedModules = /[\\/]node_modules[\\/](?:postgres[\\/](?:cjs[\\/])?src[\\/]index\.js|drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs))(?:[?#].*)?$/;
101
+ exports.drizzleModules = /[\\/]node_modules[\\/]drizzle-orm[\\/](?:query-promise|query-builders[\\/]query-builder)\.(?:js|cjs|mjs)(?:[?#].*)?$/;
102
+ /** control is the port the package's hook listens on (see quietESMHook). */
103
+ let control;
104
+ /**
105
+ * quietESMHook makes the package's loader hook pass every module through
106
+ * from now on: a loader hook cannot be removed once registered, so a
107
+ * stopped package leaves it in place, idle.
108
+ */
109
+ function quietESMHook() {
110
+ try {
111
+ control?.postMessage('off');
112
+ }
113
+ catch {
114
+ // the hook stays as it was
115
+ }
116
+ }
55
117
  /**
56
118
  * registerESMHook registers the instrumentation loader hook once and
57
119
  * reports whether it is in place. A failure to register never reaches the
58
120
  * application.
59
121
  */
60
- function registerESMHook(report = () => undefined) {
122
+ function registerESMHook(report = () => undefined, takeOver, include = exports.hookedPackages) {
61
123
  const global = globalThis;
62
124
  if (global[exports.esmHookMarker]) {
63
125
  return 'on';
@@ -68,11 +130,23 @@ function registerESMHook(report = () => undefined) {
68
130
  return 'off';
69
131
  }
70
132
  try {
71
- // Resolved here, by path: a file tracer (Next.js standalone output)
72
- // follows require.resolve and ships the hook with the package, which
73
- // a bare specifier handed to module.register alone would not get.
74
- const hook = require.resolve('@opentelemetry/instrumentation/hook.mjs');
75
- registrar.register((0, node_url_1.pathToFileURL)(hook).href, (0, node_url_1.pathToFileURL)(__filename).href, { data: { include: [exports.hookedPackages] } });
133
+ // The package's own instance of import-in-the-middle (see
134
+ // iitm-hook.mjs). Both files are resolved here, by path: a file tracer
135
+ // (Next.js standalone output) follows require.resolve and ships them,
136
+ // and import-in-the-middle's hook.mjs with them.
137
+ require.resolve('@opentelemetry/instrumentation/hook.mjs');
138
+ if (!ownInstancePossible()) {
139
+ process.stderr.write(exports.noInstanceLine);
140
+ return 'off';
141
+ }
142
+ const hook = require.resolve('./iitm-hook.mjs');
143
+ const channel = new node_worker_threads_1.MessageChannel();
144
+ channel.port1.unref();
145
+ control = channel.port1;
146
+ registrar.register((0, node_url_1.pathToFileURL)(hook).href, (0, node_url_1.pathToFileURL)(__filename).href, {
147
+ data: { include: [include], control: channel.port2, ...(takeOver ? { takeOver } : {}) },
148
+ transferList: [channel.port2],
149
+ });
76
150
  global[exports.esmHookMarker] = true;
77
151
  return 'on';
78
152
  }
@@ -1 +1 @@
1
- {"version":3,"file":"esmhook.js","sourceRoot":"","sources":["../src/esmhook.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,0CAsBC;AApDD,g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,CAAC,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;YACvF,YAAY,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;SAC9B,CAAC,CAAC;QACH,MAAM,CAAC,qBAAa,CAAC,GAAG,IAAI,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/D,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,83 @@
1
+ // The package's ES module loader hook: import-in-the-middle, as an
2
+ // instance of its own. import-in-the-middle's hook.mjs creates one hook
3
+ // at module level, so two registrations of the same file (Sentry's and
4
+ // the package's, when the package manager installed one copy for both)
5
+ // are one instance, and the second initialize() replaces the first one's
6
+ // options: Sentry's list of modules to wrap was lost, and with it Sentry's
7
+ // instrumentation of node:http. This module builds a separate instance
8
+ // with createHook, pointed at the same copy (so the wrapped modules call
9
+ // the register.js the package's instrumentations listen on). It also
10
+ // clears the flag import-in-the-middle sets on the hooks thread around
11
+ // its own initialize, so neither hook warns about the other.
12
+ import { createRequire } from 'node:module';
13
+ import { pathToFileURL } from 'node:url';
14
+
15
+ const require = createRequire(import.meta.url);
16
+ // The copy @opentelemetry/instrumentation depends on.
17
+ const fromInstrumentation = createRequire(require.resolve('@opentelemetry/instrumentation/package.json'));
18
+ const hookPath = fromInstrumentation.resolve('import-in-the-middle/hook.mjs');
19
+
20
+ // No fallback to the shared hook.mjs: registering it a second time
21
+ // replaces the options of whoever registered it first (Sentry's list of
22
+ // modules, and with it the instrumentation behind its request
23
+ // isolation). Without create-hook.mjs this module fails to load, and the
24
+ // package's main thread, which checks first, says so and goes on without
25
+ // the hook.
26
+ const { createHook } = await import(pathToFileURL(createHookPath(hookPath)).href);
27
+ const hook = createHook({ url: pathToFileURL(hookPath).href });
28
+
29
+ function createHookPath(path) {
30
+ return path.replace(/hook\.mjs$/, 'create-hook.mjs');
31
+ }
32
+
33
+ /**
34
+ * takeOver names the modules this hook wraps even when another
35
+ * import-in-the-middle hook registered before it marked them for itself:
36
+ * Sentry 8's hook (import-in-the-middle 1.x, a copy of its own) marks
37
+ * every ES module, and the wrapper its copy generates never calls this
38
+ * copy's hooks, so postgres.js and Drizzle went unpatched. Set by the
39
+ * package only for modules the other SDK does not instrument (see
40
+ * esmhook.ts).
41
+ */
42
+ let takeOver;
43
+
44
+ /** off is set when the package stopped (quietESMHook): every module passes through. */
45
+ let off = false;
46
+
47
+ export async function initialize(data) {
48
+ takeOver = data?.takeOver instanceof RegExp ? data.takeOver : undefined;
49
+ const control = data?.control;
50
+ if (control && typeof control.on === 'function') {
51
+ control.on('message', (message) => {
52
+ if (message === 'off') {
53
+ off = true;
54
+ }
55
+ });
56
+ control.unref?.();
57
+ }
58
+ globalThis.__import_in_the_middle_initialized__ = false;
59
+ try {
60
+ await hook.initialize?.(data);
61
+ } finally {
62
+ globalThis.__import_in_the_middle_initialized__ = false;
63
+ }
64
+ }
65
+
66
+ export async function resolve(specifier, context, nextResolve) {
67
+ if (off) {
68
+ return nextResolve(specifier, context);
69
+ }
70
+ if (!takeOver) {
71
+ return hook.resolve(specifier, context, nextResolve);
72
+ }
73
+ return hook.resolve(specifier, context, async (next, nextContext) => {
74
+ const result = await nextResolve(next, nextContext);
75
+ if (result && typeof result.url === 'string' && result.url.includes('iitm') && takeOver.test(result.url)) {
76
+ const url = new URL(result.url);
77
+ url.searchParams.delete('iitm');
78
+ return { ...result, url: url.href };
79
+ }
80
+ return result;
81
+ });
82
+ }
83
+ export const load = hook.load;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { start, current, curatedInstrumentations, instrumentationNames, otlpExporter, redisStatement, type Started, type StartOptions } from './sdk.js';
1
+ export { start, startAlongside, rootcatSpanProcessors, current, curatedInstrumentations, instrumentationNames, otlpExporter, redisStatement, type Mode, type Started, type StartOptions } from './sdk.js';
2
2
  export { rootcatSampler } from './sampler.js';
3
3
  export { readConfig, serviceIdentity, tracesURL, type Config } from './config.js';
4
4
  export { discoverIntake, defaultGateway, inContainer, type Files } from './intake.js';
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.statementKeyword = exports.stripQuery = exports.scrubbed = exports.hookedPackages = exports.registerESMHook = exports.DrizzleEntryInstrumentation = exports.PgPoolEntryInstrumentation = exports.PostgresJsInstrumentation = exports.PgInstrumentation = exports.eligible = exports.callSiteContextKey = exports.CallSiteSampling = exports.CallSiteProcessor = exports.isAppFile = exports.resolveLocation = exports.parseStack = exports.firstAppFrame = exports.captureFrames = exports.captureCallSite = exports.inContainer = exports.defaultGateway = exports.discoverIntake = exports.tracesURL = exports.serviceIdentity = exports.readConfig = exports.rootcatSampler = exports.redisStatement = exports.otlpExporter = exports.instrumentationNames = exports.curatedInstrumentations = exports.current = exports.start = void 0;
3
+ exports.statementKeyword = exports.stripQuery = exports.scrubbed = exports.hookedPackages = exports.registerESMHook = exports.DrizzleEntryInstrumentation = exports.PgPoolEntryInstrumentation = exports.PostgresJsInstrumentation = exports.PgInstrumentation = exports.eligible = exports.callSiteContextKey = exports.CallSiteSampling = exports.CallSiteProcessor = exports.isAppFile = exports.resolveLocation = exports.parseStack = exports.firstAppFrame = exports.captureFrames = exports.captureCallSite = exports.inContainer = exports.defaultGateway = exports.discoverIntake = exports.tracesURL = exports.serviceIdentity = exports.readConfig = exports.rootcatSampler = exports.redisStatement = exports.otlpExporter = exports.instrumentationNames = exports.curatedInstrumentations = exports.current = exports.rootcatSpanProcessors = exports.startAlongside = exports.start = void 0;
4
4
  // Programmatic surface (@rootcat/node/sdk): the same start the entries
5
5
  // call, and the pieces an application or a test may want on their own.
6
6
  var sdk_js_1 = require("./sdk.js");
7
7
  Object.defineProperty(exports, "start", { enumerable: true, get: function () { return sdk_js_1.start; } });
8
+ Object.defineProperty(exports, "startAlongside", { enumerable: true, get: function () { return sdk_js_1.startAlongside; } });
9
+ Object.defineProperty(exports, "rootcatSpanProcessors", { enumerable: true, get: function () { return sdk_js_1.rootcatSpanProcessors; } });
8
10
  Object.defineProperty(exports, "current", { enumerable: true, get: function () { return sdk_js_1.current; } });
9
11
  Object.defineProperty(exports, "curatedInstrumentations", { enumerable: true, get: function () { return sdk_js_1.curatedInstrumentations; } });
10
12
  Object.defineProperty(exports, "instrumentationNames", { enumerable: true, get: function () { return sdk_js_1.instrumentationNames; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,uEAAuE;AACvE,mCAAwJ;AAA/I,+FAAA,KAAK,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,iHAAA,uBAAuB,OAAA;AAAE,8GAAA,oBAAoB,OAAA;AAAE,sGAAA,YAAY,OAAA;AAAE,wGAAA,cAAc,OAAA;AACpG,2CAA8C;AAArC,4GAAA,cAAc,OAAA;AACvB,yCAAkF;AAAzE,uGAAA,UAAU,OAAA;AAAE,4GAAA,eAAe,OAAA;AAAE,sGAAA,SAAS,OAAA;AAC/C,yCAAsF;AAA7E,2GAAA,cAAc,OAAA;AAAE,2GAAA,cAAc,OAAA;AAAE,wGAAA,WAAW,OAAA;AACpD,6CAA6I;AAApI,8GAAA,eAAe,OAAA;AAAE,4GAAA,aAAa,OAAA;AAAE,4GAAA,aAAa,OAAA;AAAE,yGAAA,UAAU,OAAA;AAAE,8GAAA,eAAe,OAAA;AAAE,wGAAA,SAAS,OAAA;AAC9F,+CAAkI;AAAzH,iHAAA,iBAAiB,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAAE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,OAAA;AAC1B,iDAA4D;AAAnD,0HAAA,yBAAyB,OAAA;AAClC,yCAAyD;AAAhD,uHAAA,0BAA0B,OAAA;AACnC,2CAA2D;AAAlD,yHAAA,2BAA2B,OAAA;AACpC,2CAA6E;AAApE,6GAAA,eAAe,OAAA;AAAE,4GAAA,cAAc,OAAA;AACxC,2CAAsE;AAA7D,sGAAA,QAAQ,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,8GAAA,gBAAgB,OAAA"}
package/dist/keys.d.ts CHANGED
@@ -7,3 +7,14 @@ export declare const callSiteContextKey: symbol;
7
7
  * match).
8
8
  */
9
9
  export declare const rootDecisionKey: symbol;
10
+ /**
11
+ * ownWrapper marks the functions the package's instrumentations wrap a
12
+ * module's methods with. A wrapper found on a method is unwrapped only
13
+ * when it is the package's own (a second enable): another SDK's (Sentry's
14
+ * pg instrumentation) stays, and the package's goes around it.
15
+ */
16
+ export declare const ownWrapper: unique symbol;
17
+ /** mine reports whether a method is one of the package's own wrappers. */
18
+ export declare function mine(method: unknown): boolean;
19
+ /** marked marks a wrapper as the package's own and returns it. */
20
+ export declare function marked<T extends Function>(wrapper: T): T;
package/dist/keys.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rootDecisionKey = exports.callSiteContextKey = void 0;
3
+ exports.ownWrapper = exports.rootDecisionKey = exports.callSiteContextKey = void 0;
4
+ exports.mine = mine;
5
+ exports.marked = marked;
4
6
  // Context keys shared by the processor, the sampler and the entry wrappers.
5
7
  const api_1 = require("@opentelemetry/api");
6
8
  /** callSiteContextKey carries a call site through the active context. */
@@ -12,4 +14,20 @@ exports.callSiteContextKey = (0, api_1.createContextKey)('rootcat.callsite');
12
14
  * match).
13
15
  */
14
16
  exports.rootDecisionKey = (0, api_1.createContextKey)('rootcat.root-decision');
17
+ /**
18
+ * ownWrapper marks the functions the package's instrumentations wrap a
19
+ * module's methods with. A wrapper found on a method is unwrapped only
20
+ * when it is the package's own (a second enable): another SDK's (Sentry's
21
+ * pg instrumentation) stays, and the package's goes around it.
22
+ */
23
+ exports.ownWrapper = Symbol.for('rootcat.node.wrapper');
24
+ /** mine reports whether a method is one of the package's own wrappers. */
25
+ function mine(method) {
26
+ return typeof method === 'function' && method[exports.ownWrapper] === true;
27
+ }
28
+ /** marked marks a wrapper as the package's own and returns it. */
29
+ function marked(wrapper) {
30
+ wrapper[exports.ownWrapper] = true;
31
+ return wrapper;
32
+ }
15
33
  //# sourceMappingURL=keys.js.map
package/dist/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAAA,4EAA4E;AAC5E,4CAAsD;AAEtD,yEAAyE;AAC5D,QAAA,kBAAkB,GAAG,IAAA,sBAAgB,EAAC,kBAAkB,CAAC,CAAC;AAEvE;;;;;GAKG;AACU,QAAA,eAAe,GAAG,IAAA,sBAAgB,EAAC,uBAAuB,CAAC,CAAC"}
1
+ {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";;;AAuBA,oBAEC;AAGD,wBAGC;AA/BD,4EAA4E;AAC5E,4CAAsD;AAEtD,yEAAyE;AAC5D,QAAA,kBAAkB,GAAG,IAAA,sBAAgB,EAAC,kBAAkB,CAAC,CAAC;AAEvE;;;;;GAKG;AACU,QAAA,eAAe,GAAG,IAAA,sBAAgB,EAAC,uBAAuB,CAAC,CAAC;AAEzE;;;;;GAKG;AACU,QAAA,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAE7D,0EAA0E;AAC1E,SAAgB,IAAI,CAAC,MAAe;IAClC,OAAO,OAAO,MAAM,KAAK,UAAU,IAAK,MAA6C,CAAC,kBAAU,CAAC,KAAK,IAAI,CAAC;AAC7G,CAAC;AAED,kEAAkE;AAClE,SAAgB,MAAM,CAAqB,OAAU;IAClD,OAA8C,CAAC,kBAAU,CAAC,GAAG,IAAI,CAAC;IACnE,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/dist/pg.js CHANGED
@@ -13,27 +13,32 @@ exports.PgInstrumentation = void 0;
13
13
  const api_1 = require("@opentelemetry/api");
14
14
  const instrumentation_1 = require("@opentelemetry/instrumentation");
15
15
  const callsite_js_1 = require("./callsite.js");
16
+ const keys_js_1 = require("./keys.js");
16
17
  const privacy_js_1 = require("./privacy.js");
17
18
  const processor_js_1 = require("./processor.js");
18
19
  const maxStatementBytes = 4096;
19
20
  const supportedVersions = ['>=8.0.0 <9'];
20
21
  class PgInstrumentation extends instrumentation_1.InstrumentationBase {
21
22
  constructor(options) {
22
- super('@rootcat/node/pg', '0.1.0', options);
23
+ super('@rootcat/node/pg', '0.2.0', options);
23
24
  }
24
25
  init() {
25
26
  return new instrumentation_1.InstrumentationNodeModuleDefinition('pg', supportedVersions, (moduleExports) => {
26
27
  const proto = clientPrototype(moduleExports);
27
28
  if (proto) {
28
- if ((0, instrumentation_1.isWrapped)(proto.query)) {
29
+ if ((0, instrumentation_1.isWrapped)(proto.query) && (0, keys_js_1.mine)(proto.query)) {
29
30
  this._unwrap(proto, 'query');
30
31
  }
32
+ const before = proto.query;
31
33
  this._wrap(proto, 'query', this.wrapQuery);
34
+ if (proto.query !== before) {
35
+ (0, keys_js_1.marked)(proto.query); // not when a guard kept another SDK's wrapper
36
+ }
32
37
  }
33
38
  return moduleExports;
34
39
  }, (moduleExports) => {
35
40
  const proto = clientPrototype(moduleExports);
36
- if (proto && (0, instrumentation_1.isWrapped)(proto.query)) {
41
+ if (proto && (0, instrumentation_1.isWrapped)(proto.query) && (0, keys_js_1.mine)(proto.query)) {
37
42
  this._unwrap(proto, 'query');
38
43
  }
39
44
  });
package/dist/pg.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pg.js","sourceRoot":"","sources":["../src/pg.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACrE,yEAAyE;AACzE,sEAAsE;AACtE,mEA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I,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,CAAC,CAAC,CAAE,KAAkC,CAAC,CAAC,CAAC,SAAS,CAAC;AACtG,CAAC"}
package/dist/pgpool.d.ts CHANGED
@@ -5,6 +5,13 @@ export interface PgPoolEntryOptions extends InstrumentationConfig {
5
5
  depth: number;
6
6
  sampling: CallSiteSampling;
7
7
  isApp?: (file: string) => boolean;
8
+ /**
9
+ * connect false leaves Pool.prototype.connect alone: inside a tracing
10
+ * Sentry, whose pg instrumentation spans the pool's connect under the
11
+ * caller's span (and drops it without one), the root context the
12
+ * package runs connect in would change Sentry's spans.
13
+ */
14
+ connect?: boolean;
8
15
  }
9
16
  export declare class PgPoolEntryInstrumentation extends InstrumentationBase<PgPoolEntryOptions> {
10
17
  constructor(options: PgPoolEntryOptions);
package/dist/pgpool.js CHANGED
@@ -14,6 +14,7 @@ exports.PgPoolEntryInstrumentation = void 0;
14
14
  const api_1 = require("@opentelemetry/api");
15
15
  const instrumentation_1 = require("@opentelemetry/instrumentation");
16
16
  const callsite_js_1 = require("./callsite.js");
17
+ const keys_js_1 = require("./keys.js");
17
18
  const processor_js_1 = require("./processor.js");
18
19
  function poolPrototype(moduleExports) {
19
20
  const proto = moduleExports?.prototype;
@@ -21,26 +22,39 @@ function poolPrototype(moduleExports) {
21
22
  }
22
23
  class PgPoolEntryInstrumentation extends instrumentation_1.InstrumentationBase {
23
24
  constructor(options) {
24
- super('@rootcat/node/pg-pool-entry', '0.1.0', options);
25
+ super('@rootcat/node/pg-pool-entry', '0.2.0', options);
25
26
  }
26
27
  init() {
27
28
  return new instrumentation_1.InstrumentationNodeModuleDefinition('pg-pool', ['>=2.0.0 <4'], (moduleExports) => {
28
29
  const proto = poolPrototype(moduleExports);
29
30
  if (proto) {
30
31
  for (const name of ['query', 'connect']) {
31
- if ((0, instrumentation_1.isWrapped)(proto[name])) {
32
+ if ((0, instrumentation_1.isWrapped)(proto[name]) && (0, keys_js_1.mine)(proto[name])) {
32
33
  this._unwrap(proto, name);
33
34
  }
34
35
  }
36
+ const beforeQuery = proto.query;
35
37
  this._wrap(proto, 'query', this.wrapQuery);
36
- this._wrap(proto, 'connect', wrapConnect);
38
+ if (proto.query !== beforeQuery) {
39
+ (0, keys_js_1.marked)(proto.query); // not when a guard kept another SDK's wrapper
40
+ }
41
+ if (this.getConfig().connect !== false) {
42
+ const beforeConnect = proto.connect;
43
+ this._wrap(proto, 'connect', wrapConnect);
44
+ if (proto.connect !== beforeConnect) {
45
+ (0, keys_js_1.marked)(proto.connect);
46
+ }
47
+ }
37
48
  }
38
49
  return moduleExports;
39
50
  }, (moduleExports) => {
40
51
  const proto = poolPrototype(moduleExports);
41
52
  if (proto) {
42
- this._unwrap(proto, 'query');
43
- this._unwrap(proto, 'connect');
53
+ for (const name of ['query', 'connect']) {
54
+ if ((0, instrumentation_1.isWrapped)(proto[name]) && (0, keys_js_1.mine)(proto[name])) {
55
+ this._unwrap(proto, name);
56
+ }
57
+ }
44
58
  }
45
59
  });
46
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pgpool.js","sourceRoot":"","sources":["../src/pgpool.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,wEAAwE;AACxE,wEAAwE;AACxE,sEAAsE;AACtE,EAAE;AACF,uEAAuE;AACvE,mEAAmE;AACnE,uEAAuE;AACvE,qEAAqE;AACrE,wDAAwD;AACxD,4CAA2D;AAC3D,oEAAiJ;AACjJ,+CAAgD;AAChD,iDAAmE;AAYnE,SAAS,aAAa,CAAC,aAAsB;IAC3C,MAAM,KAAK,GAAI,aAA+D,EAAE,SAAS,CAAC;IAC1F,OAAO,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAE,KAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;AAClI,CAAC;AAED,MAAa,0BAA2B,SAAQ,qCAAuC;IACrF,YAAY,OAA2B;QACrC,KAAK,C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umentationConfig, InstrumentationNodeModuleDefinition } from '@opentelemetry/instrumentation';
2
+ import { type CallSiteLocation } from './callsite.js';
2
3
  import { type CallSiteSampling } from './processor.js';
3
4
  /** PostgresJsOptions configures the instrumentation. */
4
5
  export interface PostgresJsOptions extends InstrumentationConfig {
5
6
  /** sampling gates the origin parsing, like any capture. */
6
7
  sampling: CallSiteSampling;
8
+ /**
9
+ * spans false starts no span: another SDK (Sentry, tracing on) has
10
+ * already started one for the query when handle() runs, and onSite is
11
+ * handed the query's origin to give that span its call site.
12
+ */
13
+ spans?: boolean;
14
+ /** onSite receives a query's call site when spans is false. */
15
+ onSite?: (site: CallSiteLocation) => void;
7
16
  }
8
17
  export declare class PostgresJsInstrumentation extends InstrumentationBase<PostgresJsOptions> {
9
18
  private readonly patched;
10
19
  /** origins remembers the parsed call site per template, null for none. */
11
20
  private readonly origins;
21
+ /** recording maps a sql function to its site-recording proxy (spans false). */
22
+ private readonly recording;
23
+ /** templateSites remembers the captured call site per template (spans false). */
24
+ private readonly templateSites;
25
+ /** querySites holds the call site captured for a query until it is handled (spans false). */
26
+ private readonly querySites;
12
27
  constructor(options: PostgresJsOptions);
13
28
  protected init(): InstrumentationNodeModuleDefinition;
14
29
  /**
@@ -19,6 +34,18 @@ export declare class PostgresJsInstrumentation extends InstrumentationBase<Postg
19
34
  private patchModule;
20
35
  private unpatchModule;
21
36
  private wrapFactory;
37
+ /**
38
+ * siteRecording is the sql function as the application gets it when
39
+ * another SDK (Sentry) spans the queries: the driver's own origin then
40
+ * cannot name the application, as it keeps four frames and Sentry's
41
+ * wrapper of the sql function takes the last one. The call site is
42
+ * captured here instead, where the application calls: once per tagged
43
+ * template (a template is one place in the source, as the driver's own
44
+ * origin cache assumes), and per unsafe() call unless an outer layer
45
+ * (Drizzle) already carries one; queries inside sql.begin() get the
46
+ * same treatment through the transaction's sql function.
47
+ */
48
+ private siteRecording;
22
49
  /** patchQueryClass finds Query.prototype through an unexecuted query. */
23
50
  private patchQueryClass;
24
51
  private readonly wrapHandle;