repro-nest 0.0.202 → 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 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 = mongoose.Query?.prototype;
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
- patchMongooseExecCapture();
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repro-nest",
3
- "version": "0.0.202",
3
+ "version": "0.0.204",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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 = (mongoose as any).Query?.prototype;
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
- patchMongooseExecCapture();
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 {
package/tracer/runtime.js CHANGED
@@ -645,6 +645,11 @@ if (!global.__repro_call) {
645
645
  }
646
646
  } catch {}
647
647
 
648
+ if (isQuery) {
649
+ runExit(exitDetailBase);
650
+ return out;
651
+ }
652
+
648
653
  let settled = false;
649
654
  const finalize = (value, threw, error) => {
650
655
  if (settled) return value;