repro-nest 0.0.203 → 0.0.204
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/index.js +25 -24
- package/package.json +1 -1
- package/src/index.ts +24 -23
- package/tracer/runtime.js +5 -0
package/dist/index.js
CHANGED
|
@@ -92,9 +92,9 @@ function flushQueryFinalizers(query, value, threw, error) {
|
|
|
92
92
|
}
|
|
93
93
|
catch { }
|
|
94
94
|
}
|
|
95
|
-
function patchMongooseExecCapture() {
|
|
95
|
+
function patchMongooseExecCapture(targetMongoose = mongoose) {
|
|
96
96
|
try {
|
|
97
|
-
const Qp =
|
|
97
|
+
const Qp = targetMongoose?.Query?.prototype;
|
|
98
98
|
if (!Qp || Qp.__repro_exec_patched)
|
|
99
99
|
return;
|
|
100
100
|
const origExec = Qp.exec;
|
|
@@ -129,6 +129,26 @@ function patchMongooseExecCapture() {
|
|
|
129
129
|
}
|
|
130
130
|
catch { }
|
|
131
131
|
}
|
|
132
|
+
function patchAllKnownMongooseInstances() {
|
|
133
|
+
// Patch the SDK's bundled mongoose first.
|
|
134
|
+
patchMongooseExecCapture(mongoose);
|
|
135
|
+
// Also patch any other mongoose copies the host app might have installed (e.g., different versions).
|
|
136
|
+
try {
|
|
137
|
+
const cache = require?.cache || {};
|
|
138
|
+
const seen = new Set();
|
|
139
|
+
Object.keys(cache).forEach((key) => {
|
|
140
|
+
if (!/node_modules[\\/](mongoose)[\\/]/i.test(key))
|
|
141
|
+
return;
|
|
142
|
+
const mod = cache[key];
|
|
143
|
+
const exp = mod?.exports;
|
|
144
|
+
if (!exp || seen.has(exp))
|
|
145
|
+
return;
|
|
146
|
+
seen.add(exp);
|
|
147
|
+
patchMongooseExecCapture(exp);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch { }
|
|
151
|
+
}
|
|
132
152
|
const REQUEST_START_HEADER = 'x-bug-request-start';
|
|
133
153
|
function escapeRx(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
|
|
134
154
|
let __TRACER__ = null;
|
|
@@ -384,7 +404,9 @@ function initReproTracing(opts) {
|
|
|
384
404
|
tracerPkg.patchHttp?.();
|
|
385
405
|
applyTraceLogPreference(tracerPkg);
|
|
386
406
|
__TRACER_READY = true;
|
|
387
|
-
|
|
407
|
+
patchAllKnownMongooseInstances();
|
|
408
|
+
// Patch again on the next tick to catch mongoose copies that load after init (different versions/copies).
|
|
409
|
+
setImmediate(() => patchAllKnownMongooseInstances());
|
|
388
410
|
}
|
|
389
411
|
catch {
|
|
390
412
|
__TRACER__ = null; // SDK still works without tracer
|
|
@@ -1289,27 +1311,6 @@ function reproMiddleware(cfg) {
|
|
|
1289
1311
|
depth: evt.depth,
|
|
1290
1312
|
library: inferLibraryNameFromFile(evt.file),
|
|
1291
1313
|
};
|
|
1292
|
-
if (evt.type === 'exit') {
|
|
1293
|
-
// If the function returned a Mongoose Query, update the exit value when the query settles.
|
|
1294
|
-
const rv = ev.returnValue;
|
|
1295
|
-
const setReturnValue = (val) => {
|
|
1296
|
-
try {
|
|
1297
|
-
evt.returnValue = sanitizeTraceValue(val);
|
|
1298
|
-
}
|
|
1299
|
-
catch { }
|
|
1300
|
-
};
|
|
1301
|
-
const qp = rv && rv.__repro_result_promise;
|
|
1302
|
-
const hasResult = rv && Object.prototype.hasOwnProperty.call(rv, '__repro_result');
|
|
1303
|
-
if (hasResult) {
|
|
1304
|
-
setReturnValue(rv.__repro_result);
|
|
1305
|
-
}
|
|
1306
|
-
else if (qp && typeof qp.then === 'function') {
|
|
1307
|
-
try {
|
|
1308
|
-
qp.then((val) => setReturnValue(val), () => { });
|
|
1309
|
-
}
|
|
1310
|
-
catch { }
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
1314
|
const spanKey = normalizeSpanId(evt.spanId);
|
|
1314
1315
|
if (evt.type === 'enter') {
|
|
1315
1316
|
lastEventAt = Date.now();
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -86,9 +86,9 @@ function flushQueryFinalizers(query: any, value: any, threw: boolean, error: any
|
|
|
86
86
|
} catch {}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
function patchMongooseExecCapture() {
|
|
89
|
+
function patchMongooseExecCapture(targetMongoose: any = mongoose) {
|
|
90
90
|
try {
|
|
91
|
-
const Qp: any =
|
|
91
|
+
const Qp: any = targetMongoose?.Query?.prototype;
|
|
92
92
|
if (!Qp || Qp.__repro_exec_patched) return;
|
|
93
93
|
const origExec = Qp.exec;
|
|
94
94
|
if (typeof origExec !== 'function') return;
|
|
@@ -117,6 +117,25 @@ function patchMongooseExecCapture() {
|
|
|
117
117
|
} catch {}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
function patchAllKnownMongooseInstances() {
|
|
121
|
+
// Patch the SDK's bundled mongoose first.
|
|
122
|
+
patchMongooseExecCapture(mongoose as any);
|
|
123
|
+
|
|
124
|
+
// Also patch any other mongoose copies the host app might have installed (e.g., different versions).
|
|
125
|
+
try {
|
|
126
|
+
const cache = (require as any)?.cache || {};
|
|
127
|
+
const seen = new Set<any>();
|
|
128
|
+
Object.keys(cache).forEach((key) => {
|
|
129
|
+
if (!/node_modules[\\/](mongoose)[\\/]/i.test(key)) return;
|
|
130
|
+
const mod = cache[key];
|
|
131
|
+
const exp = mod?.exports;
|
|
132
|
+
if (!exp || seen.has(exp)) return;
|
|
133
|
+
seen.add(exp);
|
|
134
|
+
patchMongooseExecCapture(exp);
|
|
135
|
+
});
|
|
136
|
+
} catch {}
|
|
137
|
+
}
|
|
138
|
+
|
|
120
139
|
// ====== tiny, safe tracer auto-init (no node_modules patches) ======
|
|
121
140
|
type TracerApi = {
|
|
122
141
|
init?: (opts: any) => void;
|
|
@@ -570,7 +589,9 @@ export function initReproTracing(opts?: ReproTracingInitOptions) {
|
|
|
570
589
|
tracerPkg.patchHttp?.();
|
|
571
590
|
applyTraceLogPreference(tracerPkg);
|
|
572
591
|
__TRACER_READY = true;
|
|
573
|
-
|
|
592
|
+
patchAllKnownMongooseInstances();
|
|
593
|
+
// Patch again on the next tick to catch mongoose copies that load after init (different versions/copies).
|
|
594
|
+
setImmediate(() => patchAllKnownMongooseInstances());
|
|
574
595
|
} catch {
|
|
575
596
|
__TRACER__ = null; // SDK still works without tracer
|
|
576
597
|
} finally {
|
|
@@ -1499,26 +1520,6 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1499
1520
|
library: inferLibraryNameFromFile(evt.file),
|
|
1500
1521
|
};
|
|
1501
1522
|
|
|
1502
|
-
if (evt.type === 'exit') {
|
|
1503
|
-
// If the function returned a Mongoose Query, update the exit value when the query settles.
|
|
1504
|
-
const rv: any = ev.returnValue;
|
|
1505
|
-
const setReturnValue = (val: any) => {
|
|
1506
|
-
try { evt.returnValue = sanitizeTraceValue(val); } catch {}
|
|
1507
|
-
};
|
|
1508
|
-
const qp = rv && rv.__repro_result_promise;
|
|
1509
|
-
const hasResult = rv && Object.prototype.hasOwnProperty.call(rv, '__repro_result');
|
|
1510
|
-
if (hasResult) {
|
|
1511
|
-
setReturnValue(rv.__repro_result);
|
|
1512
|
-
} else if (qp && typeof qp.then === 'function') {
|
|
1513
|
-
try {
|
|
1514
|
-
qp.then(
|
|
1515
|
-
(val: any) => setReturnValue(val),
|
|
1516
|
-
() => {}
|
|
1517
|
-
);
|
|
1518
|
-
} catch {}
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
1523
|
const spanKey = normalizeSpanId(evt.spanId);
|
|
1523
1524
|
if (evt.type === 'enter') {
|
|
1524
1525
|
lastEventAt = Date.now();
|
package/tracer/runtime.js
CHANGED