repro-nest 0.0.210 → 0.0.212

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
@@ -103,6 +103,21 @@ function patchMongooseExecCapture(targetMongoose = mongoose) {
103
103
  Qp.exec = function reproPatchedExec(...args) {
104
104
  try {
105
105
  this.__repro_is_query = true;
106
+ const ctx = __TRACER__?.getCurrentSpanContext?.();
107
+ const traceId = ctx?.traceId ?? __TRACER__?.getCurrentTraceId?.() ?? null;
108
+ if (ctx || traceId) {
109
+ Object.defineProperty(this, '__repro_span_context', {
110
+ value: {
111
+ traceId,
112
+ spanId: ctx?.spanId ?? null,
113
+ parentSpanId: ctx?.parentSpanId ?? null,
114
+ depth: ctx?.depth ?? null,
115
+ },
116
+ configurable: true,
117
+ writable: true,
118
+ enumerable: false,
119
+ });
120
+ }
106
121
  }
107
122
  catch { }
108
123
  const p = origExec.apply(this, args);
@@ -139,6 +154,21 @@ function patchMongooseExecCapture(targetMongoose = mongoose) {
139
154
  Ap.exec = function reproPatchedAggExec(...args) {
140
155
  try {
141
156
  this.__repro_is_query = true;
157
+ const ctx = __TRACER__?.getCurrentSpanContext?.();
158
+ const traceId = ctx?.traceId ?? __TRACER__?.getCurrentTraceId?.() ?? null;
159
+ if (ctx || traceId) {
160
+ Object.defineProperty(this, '__repro_span_context', {
161
+ value: {
162
+ traceId,
163
+ spanId: ctx?.spanId ?? null,
164
+ parentSpanId: ctx?.parentSpanId ?? null,
165
+ depth: ctx?.depth ?? null,
166
+ },
167
+ configurable: true,
168
+ writable: true,
169
+ enumerable: false,
170
+ });
171
+ }
142
172
  }
143
173
  catch { }
144
174
  const p = origAggExec.apply(this, args);
@@ -459,17 +489,16 @@ exports.initReproTracing = initReproTracing;
459
489
  /** Optional helper if users want to check it. */
460
490
  function isReproTracingEnabled() { return __TRACER_READY; }
461
491
  exports.isReproTracingEnabled = isReproTracingEnabled;
462
- function captureSpanContext(source) {
492
+ function captureSpanContextFromTracer(source) {
463
493
  try {
464
494
  const fromSource = source && source.__repro_span_context;
465
495
  if (fromSource) {
466
- const span = {
496
+ return {
467
497
  traceId: fromSource.traceId ?? null,
468
498
  spanId: fromSource.spanId ?? null,
469
499
  parentSpanId: fromSource.parentSpanId ?? null,
470
500
  depth: fromSource.depth ?? null,
471
501
  };
472
- return span;
473
502
  }
474
503
  const ctx = __TRACER__?.getCurrentSpanContext?.();
475
504
  if (ctx) {
@@ -493,10 +522,10 @@ function captureSpanContext(source) {
493
522
  catch { }
494
523
  return null;
495
524
  }
496
- function attachSpanContext(target, spanSource, fallbackSource) {
525
+ function attachSpanContext(target, span) {
497
526
  if (!target)
498
527
  return target;
499
- const ctx = spanSource ?? captureSpanContext(fallbackSource);
528
+ const ctx = span ?? captureSpanContextFromTracer();
500
529
  if (ctx) {
501
530
  try {
502
531
  target.spanContext = ctx;
@@ -1582,7 +1611,7 @@ function reproMongoosePlugin(cfg) {
1582
1611
  wasNew: this.isNew,
1583
1612
  before,
1584
1613
  collection: resolveCollectionOrWarn(this, 'doc'),
1585
- spanContext: captureSpanContext(this),
1614
+ spanContext: captureSpanContextFromTracer(this),
1586
1615
  };
1587
1616
  next();
1588
1617
  });
@@ -1596,7 +1625,7 @@ function reproMongoosePlugin(cfg) {
1596
1625
  const before = meta.before ?? null;
1597
1626
  const after = this.toObject({ depopulate: true });
1598
1627
  const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
1599
- const spanContext = meta.spanContext || captureSpanContext(this);
1628
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1600
1629
  const query = meta.wasNew
1601
1630
  ? { op: 'insertOne', doc: after }
1602
1631
  : { filter: { _id: this._id }, update: buildMinimalUpdate(before, after), options: { upsert: false } };
@@ -1626,7 +1655,7 @@ function reproMongoosePlugin(cfg) {
1626
1655
  this.__repro_before = await model.findOne(filter).lean().exec();
1627
1656
  this.setOptions({ new: true });
1628
1657
  this.__repro_collection = resolveCollectionOrWarn(this, 'query');
1629
- this.__repro_spanContext = captureSpanContext(this);
1658
+ this.__repro_spanContext = captureSpanContextFromTracer(this);
1630
1659
  }
1631
1660
  catch { }
1632
1661
  next();
@@ -1638,7 +1667,7 @@ function reproMongoosePlugin(cfg) {
1638
1667
  const before = this.__repro_before ?? null;
1639
1668
  const after = res ?? null;
1640
1669
  const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
1641
- const spanContext = this.__repro_spanContext || captureSpanContext(this);
1670
+ const spanContext = this.__repro_spanContext || captureSpanContextFromTracer(this);
1642
1671
  const pk = after?._id ?? before?._id;
1643
1672
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
1644
1673
  entries: [{
@@ -1664,7 +1693,7 @@ function reproMongoosePlugin(cfg) {
1664
1693
  this.__repro_before = await this.model.findOne(filter).lean().exec();
1665
1694
  this.__repro_collection = resolveCollectionOrWarn(this, 'query');
1666
1695
  this.__repro_filter = filter;
1667
- this.__repro_spanContext = captureSpanContext(this);
1696
+ this.__repro_spanContext = captureSpanContextFromTracer(this);
1668
1697
  }
1669
1698
  catch { }
1670
1699
  next();
@@ -1678,7 +1707,7 @@ function reproMongoosePlugin(cfg) {
1678
1707
  return;
1679
1708
  const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
1680
1709
  const filter = this.__repro_filter ?? { _id: before._id };
1681
- const spanContext = this.__repro_spanContext || captureSpanContext(this);
1710
+ const spanContext = this.__repro_spanContext || captureSpanContextFromTracer(this);
1682
1711
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
1683
1712
  entries: [{
1684
1713
  actionId: getCtx().aid,
@@ -1727,7 +1756,7 @@ function reproMongoosePlugin(cfg) {
1727
1756
  t0: Date.now(),
1728
1757
  collection: this?.model?.collection?.name || 'unknown',
1729
1758
  op,
1730
- spanContext: captureSpanContext(this),
1759
+ spanContext: captureSpanContextFromTracer(this),
1731
1760
  filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
1732
1761
  update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
1733
1762
  projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
@@ -1739,7 +1768,7 @@ function reproMongoosePlugin(cfg) {
1739
1768
  t0: Date.now(),
1740
1769
  collection: 'unknown',
1741
1770
  op,
1742
- spanContext: captureSpanContext(this),
1771
+ spanContext: captureSpanContextFromTracer(this),
1743
1772
  };
1744
1773
  }
1745
1774
  next();
@@ -1750,7 +1779,7 @@ function reproMongoosePlugin(cfg) {
1750
1779
  return;
1751
1780
  const meta = this.__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
1752
1781
  const resultMeta = summarizeQueryResult(op, res);
1753
- const spanContext = meta.spanContext || captureSpanContext(this);
1782
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1754
1783
  emitDbQuery(cfg, sid, aid, {
1755
1784
  collection: meta.collection,
1756
1785
  op,
@@ -1771,14 +1800,14 @@ function reproMongoosePlugin(cfg) {
1771
1800
  t0: Date.now(),
1772
1801
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1773
1802
  docs: sanitizeDbValue(docs),
1774
- spanContext: captureSpanContext(this),
1803
+ spanContext: captureSpanContextFromTracer(this),
1775
1804
  };
1776
1805
  }
1777
1806
  catch {
1778
1807
  this.__repro_insert_meta = {
1779
1808
  t0: Date.now(),
1780
1809
  collection: 'unknown',
1781
- spanContext: captureSpanContext(this),
1810
+ spanContext: captureSpanContextFromTracer(this),
1782
1811
  };
1783
1812
  }
1784
1813
  next();
@@ -1789,7 +1818,7 @@ function reproMongoosePlugin(cfg) {
1789
1818
  return;
1790
1819
  const meta = this.__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
1791
1820
  const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
1792
- const spanContext = meta.spanContext || captureSpanContext(this);
1821
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1793
1822
  emitDbQuery(cfg, sid, aid, {
1794
1823
  collection: meta.collection,
1795
1824
  op: 'insertMany',
@@ -1806,14 +1835,14 @@ function reproMongoosePlugin(cfg) {
1806
1835
  t0: Date.now(),
1807
1836
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1808
1837
  ops: sanitizeDbValue(ops),
1809
- spanContext: captureSpanContext(this),
1838
+ spanContext: captureSpanContextFromTracer(this),
1810
1839
  };
1811
1840
  }
1812
1841
  catch {
1813
1842
  this.__repro_bulk_meta = {
1814
1843
  t0: Date.now(),
1815
1844
  collection: 'unknown',
1816
- spanContext: captureSpanContext(this),
1845
+ spanContext: captureSpanContextFromTracer(this),
1817
1846
  };
1818
1847
  }
1819
1848
  next();
@@ -1825,7 +1854,7 @@ function reproMongoosePlugin(cfg) {
1825
1854
  const meta = this.__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
1826
1855
  const bulkResult = summarizeBulkResult(res);
1827
1856
  const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
1828
- const spanContext = meta.spanContext || captureSpanContext(this);
1857
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1829
1858
  emitDbQuery(cfg, sid, aid, {
1830
1859
  collection: meta.collection,
1831
1860
  op: 'bulkWrite',
@@ -1845,7 +1874,7 @@ function reproMongoosePlugin(cfg) {
1845
1874
  this?._model?.collection?.name ||
1846
1875
  (this?.model && this.model.collection?.name) ||
1847
1876
  'unknown',
1848
- spanContext: captureSpanContext(this),
1877
+ spanContext: captureSpanContextFromTracer(this),
1849
1878
  pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
1850
1879
  };
1851
1880
  }
@@ -1854,7 +1883,7 @@ function reproMongoosePlugin(cfg) {
1854
1883
  t0: Date.now(),
1855
1884
  collection: 'unknown',
1856
1885
  pipeline: undefined,
1857
- spanContext: captureSpanContext(this),
1886
+ spanContext: captureSpanContextFromTracer(this),
1858
1887
  };
1859
1888
  }
1860
1889
  next();
@@ -1865,7 +1894,7 @@ function reproMongoosePlugin(cfg) {
1865
1894
  return;
1866
1895
  const meta = this.__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
1867
1896
  const resultMeta = summarizeQueryResult('aggregate', res);
1868
- const spanContext = meta.spanContext || captureSpanContext(this);
1897
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1869
1898
  emitDbQuery(cfg, sid, aid, {
1870
1899
  collection: meta.collection,
1871
1900
  op: 'aggregate',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repro-nest",
3
- "version": "0.0.210",
3
+ "version": "0.0.212",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -95,7 +95,24 @@ function patchMongooseExecCapture(targetMongoose: any = mongoose) {
95
95
  if (typeof origExec === 'function') {
96
96
  Qp.__repro_exec_patched = true;
97
97
  Qp.exec = function reproPatchedExec(this: any, ...args: any[]) {
98
- try { (this as any).__repro_is_query = true; } catch {}
98
+ try {
99
+ (this as any).__repro_is_query = true;
100
+ const ctx = __TRACER__?.getCurrentSpanContext?.();
101
+ const traceId = ctx?.traceId ?? __TRACER__?.getCurrentTraceId?.() ?? null;
102
+ if (ctx || traceId) {
103
+ Object.defineProperty(this, '__repro_span_context', {
104
+ value: {
105
+ traceId,
106
+ spanId: ctx?.spanId ?? null,
107
+ parentSpanId: ctx?.parentSpanId ?? null,
108
+ depth: ctx?.depth ?? null,
109
+ },
110
+ configurable: true,
111
+ writable: true,
112
+ enumerable: false,
113
+ });
114
+ }
115
+ } catch {}
99
116
  const p = origExec.apply(this, args);
100
117
  try {
101
118
  if (p && typeof p.then === 'function') {
@@ -127,7 +144,24 @@ function patchMongooseExecCapture(targetMongoose: any = mongoose) {
127
144
  if (typeof origAggExec === 'function') {
128
145
  Ap.__repro_agg_exec_patched = true;
129
146
  Ap.exec = function reproPatchedAggExec(this: any, ...args: any[]) {
130
- try { (this as any).__repro_is_query = true; } catch {}
147
+ try {
148
+ (this as any).__repro_is_query = true;
149
+ const ctx = __TRACER__?.getCurrentSpanContext?.();
150
+ const traceId = ctx?.traceId ?? __TRACER__?.getCurrentTraceId?.() ?? null;
151
+ if (ctx || traceId) {
152
+ Object.defineProperty(this, '__repro_span_context', {
153
+ value: {
154
+ traceId,
155
+ spanId: ctx?.spanId ?? null,
156
+ parentSpanId: ctx?.parentSpanId ?? null,
157
+ depth: ctx?.depth ?? null,
158
+ },
159
+ configurable: true,
160
+ writable: true,
161
+ enumerable: false,
162
+ });
163
+ }
164
+ } catch {}
131
165
  const p = origAggExec.apply(this, args);
132
166
  try {
133
167
  if (p && typeof p.then === 'function') {
@@ -648,17 +682,16 @@ export function initReproTracing(opts?: ReproTracingInitOptions) {
648
682
  /** Optional helper if users want to check it. */
649
683
  export function isReproTracingEnabled() { return __TRACER_READY; }
650
684
 
651
- function captureSpanContext(source?: any): SpanContext | null {
685
+ function captureSpanContextFromTracer(source?: any): SpanContext | null {
652
686
  try {
653
687
  const fromSource = source && source.__repro_span_context;
654
688
  if (fromSource) {
655
- const span: SpanContext = {
689
+ return {
656
690
  traceId: fromSource.traceId ?? null,
657
691
  spanId: fromSource.spanId ?? null,
658
692
  parentSpanId: fromSource.parentSpanId ?? null,
659
693
  depth: fromSource.depth ?? null,
660
694
  };
661
- return span;
662
695
  }
663
696
 
664
697
  const ctx = __TRACER__?.getCurrentSpanContext?.();
@@ -682,9 +715,9 @@ function captureSpanContext(source?: any): SpanContext | null {
682
715
  return null;
683
716
  }
684
717
 
685
- function attachSpanContext<T extends Record<string, any>>(target: T, spanSource?: SpanContext | null, fallbackSource?: any): T {
718
+ function attachSpanContext<T extends Record<string, any>>(target: T, span?: SpanContext | null): T {
686
719
  if (!target) return target;
687
- const ctx = spanSource ?? captureSpanContext(fallbackSource);
720
+ const ctx = span ?? captureSpanContextFromTracer();
688
721
  if (ctx) {
689
722
  try { (target as any).spanContext = ctx; } catch {}
690
723
  }
@@ -1796,7 +1829,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1796
1829
  wasNew: this.isNew,
1797
1830
  before,
1798
1831
  collection: resolveCollectionOrWarn(this, 'doc'),
1799
- spanContext: captureSpanContext(this),
1832
+ spanContext: captureSpanContextFromTracer(this),
1800
1833
  };
1801
1834
  next();
1802
1835
  });
@@ -1810,7 +1843,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1810
1843
  const before = meta.before ?? null;
1811
1844
  const after = this.toObject({ depopulate: true });
1812
1845
  const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
1813
- const spanContext = meta.spanContext || captureSpanContext(this);
1846
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1814
1847
 
1815
1848
  const query = meta.wasNew
1816
1849
  ? { op: 'insertOne', doc: after }
@@ -1842,7 +1875,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1842
1875
  (this as any).__repro_before = await model.findOne(filter).lean().exec();
1843
1876
  this.setOptions({ new: true });
1844
1877
  (this as any).__repro_collection = resolveCollectionOrWarn(this, 'query');
1845
- (this as any).__repro_spanContext = captureSpanContext(this);
1878
+ (this as any).__repro_spanContext = captureSpanContextFromTracer(this);
1846
1879
  } catch {}
1847
1880
  next();
1848
1881
  });
@@ -1854,7 +1887,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1854
1887
  const before = (this as any).__repro_before ?? null;
1855
1888
  const after = res ?? null;
1856
1889
  const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
1857
- const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
1890
+ const spanContext = (this as any).__repro_spanContext || captureSpanContextFromTracer(this);
1858
1891
  const pk = after?._id ?? before?._id;
1859
1892
 
1860
1893
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
@@ -1880,7 +1913,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1880
1913
  (this as any).__repro_before = await (this.model as Model<any>).findOne(filter).lean().exec();
1881
1914
  (this as any).__repro_collection = resolveCollectionOrWarn(this, 'query');
1882
1915
  (this as any).__repro_filter = filter;
1883
- (this as any).__repro_spanContext = captureSpanContext(this);
1916
+ (this as any).__repro_spanContext = captureSpanContextFromTracer(this);
1884
1917
  } catch {}
1885
1918
  next();
1886
1919
  });
@@ -1891,7 +1924,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1891
1924
  if (!before) return;
1892
1925
  const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
1893
1926
  const filter = (this as any).__repro_filter ?? { _id: before._id };
1894
- const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
1927
+ const spanContext = (this as any).__repro_spanContext || captureSpanContextFromTracer(this);
1895
1928
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
1896
1929
  entries: [{
1897
1930
  actionId: (getCtx() as Ctx).aid!,
@@ -1944,7 +1977,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1944
1977
  t0: Date.now(),
1945
1978
  collection: this?.model?.collection?.name || 'unknown',
1946
1979
  op,
1947
- spanContext: captureSpanContext(this),
1980
+ spanContext: captureSpanContextFromTracer(this),
1948
1981
  filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
1949
1982
  update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
1950
1983
  projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
@@ -1955,7 +1988,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1955
1988
  t0: Date.now(),
1956
1989
  collection: 'unknown',
1957
1990
  op,
1958
- spanContext: captureSpanContext(this),
1991
+ spanContext: captureSpanContextFromTracer(this),
1959
1992
  };
1960
1993
  }
1961
1994
  next();
@@ -1967,7 +2000,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1967
2000
 
1968
2001
  const meta = (this as any).__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
1969
2002
  const resultMeta = summarizeQueryResult(op, res);
1970
- const spanContext = meta.spanContext || captureSpanContext(this);
2003
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
1971
2004
 
1972
2005
  emitDbQuery(cfg, sid, aid, {
1973
2006
  collection: meta.collection,
@@ -1991,13 +2024,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1991
2024
  t0: Date.now(),
1992
2025
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1993
2026
  docs: sanitizeDbValue(docs),
1994
- spanContext: captureSpanContext(this),
2027
+ spanContext: captureSpanContextFromTracer(this),
1995
2028
  };
1996
2029
  } catch {
1997
2030
  (this as any).__repro_insert_meta = {
1998
2031
  t0: Date.now(),
1999
2032
  collection: 'unknown',
2000
- spanContext: captureSpanContext(this),
2033
+ spanContext: captureSpanContextFromTracer(this),
2001
2034
  };
2002
2035
  }
2003
2036
  next();
@@ -2008,7 +2041,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2008
2041
  if (!sid) return;
2009
2042
  const meta = (this as any).__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
2010
2043
  const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
2011
- const spanContext = meta.spanContext || captureSpanContext(this);
2044
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
2012
2045
 
2013
2046
  emitDbQuery(cfg, sid, aid, {
2014
2047
  collection: meta.collection,
@@ -2027,13 +2060,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2027
2060
  t0: Date.now(),
2028
2061
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
2029
2062
  ops: sanitizeDbValue(ops),
2030
- spanContext: captureSpanContext(this),
2063
+ spanContext: captureSpanContextFromTracer(this),
2031
2064
  };
2032
2065
  } catch {
2033
2066
  (this as any).__repro_bulk_meta = {
2034
2067
  t0: Date.now(),
2035
2068
  collection: 'unknown',
2036
- spanContext: captureSpanContext(this),
2069
+ spanContext: captureSpanContextFromTracer(this),
2037
2070
  };
2038
2071
  }
2039
2072
  next();
@@ -2045,7 +2078,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2045
2078
  const meta = (this as any).__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
2046
2079
  const bulkResult = summarizeBulkResult(res);
2047
2080
  const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
2048
- const spanContext = meta.spanContext || captureSpanContext(this);
2081
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
2049
2082
 
2050
2083
  emitDbQuery(cfg, sid, aid, {
2051
2084
  collection: meta.collection,
@@ -2068,7 +2101,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2068
2101
  this?._model?.collection?.name ||
2069
2102
  (this?.model && this.model.collection?.name) ||
2070
2103
  'unknown',
2071
- spanContext: captureSpanContext(this),
2104
+ spanContext: captureSpanContextFromTracer(this),
2072
2105
  pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
2073
2106
  };
2074
2107
  } catch {
@@ -2076,7 +2109,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2076
2109
  t0: Date.now(),
2077
2110
  collection: 'unknown',
2078
2111
  pipeline: undefined,
2079
- spanContext: captureSpanContext(this),
2112
+ spanContext: captureSpanContextFromTracer(this),
2080
2113
  };
2081
2114
  }
2082
2115
  next();
@@ -2088,7 +2121,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2088
2121
 
2089
2122
  const meta = (this as any).__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
2090
2123
  const resultMeta = summarizeQueryResult('aggregate', res);
2091
- const spanContext = meta.spanContext || captureSpanContext(this);
2124
+ const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
2092
2125
 
2093
2126
  emitDbQuery(cfg, sid, aid, {
2094
2127
  collection: meta.collection,
package/tracer/runtime.js CHANGED
@@ -262,12 +262,6 @@ const trace = {
262
262
  return;
263
263
  }
264
264
  if (queueQueryFinalizer(rv, finalize)) return;
265
- setQuerySpanContext(rv, {
266
- traceId: traceIdAtExit,
267
- spanId: spanForExit.id,
268
- parentSpanId: spanForExit.parentId,
269
- depth: spanForExit.depth ?? depthAtExit
270
- });
271
265
  emitNow({ unawaited: forceUnawaited, returnValue: rv }, spanForExit, spanStackForExit);
272
266
  return;
273
267
  }
@@ -278,12 +272,6 @@ const trace = {
278
272
  }
279
273
 
280
274
  if (isQuery) {
281
- setQuerySpanContext(rv, {
282
- traceId: traceIdAtExit,
283
- spanId: spanInfoPeek.id,
284
- parentSpanId: spanInfoPeek.parentId,
285
- depth: spanInfoPeek.depth ?? depthAtExit
286
- });
287
275
  emitNow({ unawaited: forceUnawaited });
288
276
  return;
289
277
  }
@@ -853,28 +841,6 @@ function getCurrentTraceId() {
853
841
  return s && s.traceId || null;
854
842
  }
855
843
 
856
- function setQuerySpanContext(target, ctx) {
857
- if (!target || typeof target !== 'object' || !ctx) return;
858
- const safeCtx = {
859
- traceId: ctx.traceId || null,
860
- spanId: ctx.spanId ?? null,
861
- parentSpanId: ctx.parentSpanId ?? null,
862
- depth: ctx.depth ?? null
863
- };
864
- try {
865
- if (!target.__repro_span_context) {
866
- Object.defineProperty(target, '__repro_span_context', {
867
- value: safeCtx,
868
- configurable: true,
869
- writable: true,
870
- enumerable: false
871
- });
872
- }
873
- } catch {
874
- try { target.__repro_span_context = safeCtx; } catch {}
875
- }
876
- }
877
-
878
844
  function getCurrentSpanContext() {
879
845
  try {
880
846
  const store = als.getStore();