repro-nest 0.0.211 → 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 +53 -28
- package/package.json +1 -1
- package/src/index.ts +59 -30
- package/tracer/runtime.js +0 -34
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
|
|
492
|
+
function captureSpanContextFromTracer(source) {
|
|
463
493
|
try {
|
|
464
494
|
const fromSource = source && source.__repro_span_context;
|
|
465
495
|
if (fromSource) {
|
|
466
|
-
|
|
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,
|
|
525
|
+
function attachSpanContext(target, span) {
|
|
497
526
|
if (!target)
|
|
498
527
|
return target;
|
|
499
|
-
const ctx =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
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:
|
|
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 =
|
|
1782
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1754
1783
|
emitDbQuery(cfg, sid, aid, {
|
|
1755
1784
|
collection: meta.collection,
|
|
1756
1785
|
op,
|
|
@@ -1759,7 +1788,6 @@ function reproMongoosePlugin(cfg) {
|
|
|
1759
1788
|
durMs: Date.now() - meta.t0,
|
|
1760
1789
|
t: alignedNow(),
|
|
1761
1790
|
spanContext,
|
|
1762
|
-
spanSource: this,
|
|
1763
1791
|
});
|
|
1764
1792
|
});
|
|
1765
1793
|
}
|
|
@@ -1772,14 +1800,14 @@ function reproMongoosePlugin(cfg) {
|
|
|
1772
1800
|
t0: Date.now(),
|
|
1773
1801
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1774
1802
|
docs: sanitizeDbValue(docs),
|
|
1775
|
-
spanContext:
|
|
1803
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1776
1804
|
};
|
|
1777
1805
|
}
|
|
1778
1806
|
catch {
|
|
1779
1807
|
this.__repro_insert_meta = {
|
|
1780
1808
|
t0: Date.now(),
|
|
1781
1809
|
collection: 'unknown',
|
|
1782
|
-
spanContext:
|
|
1810
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1783
1811
|
};
|
|
1784
1812
|
}
|
|
1785
1813
|
next();
|
|
@@ -1790,7 +1818,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1790
1818
|
return;
|
|
1791
1819
|
const meta = this.__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
|
|
1792
1820
|
const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
|
|
1793
|
-
const spanContext =
|
|
1821
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1794
1822
|
emitDbQuery(cfg, sid, aid, {
|
|
1795
1823
|
collection: meta.collection,
|
|
1796
1824
|
op: 'insertMany',
|
|
@@ -1799,7 +1827,6 @@ function reproMongoosePlugin(cfg) {
|
|
|
1799
1827
|
durMs: Date.now() - meta.t0,
|
|
1800
1828
|
t: alignedNow(),
|
|
1801
1829
|
spanContext,
|
|
1802
|
-
spanSource: this,
|
|
1803
1830
|
});
|
|
1804
1831
|
});
|
|
1805
1832
|
schema.pre('bulkWrite', { document: false, query: false }, function (next, ops) {
|
|
@@ -1808,14 +1835,14 @@ function reproMongoosePlugin(cfg) {
|
|
|
1808
1835
|
t0: Date.now(),
|
|
1809
1836
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1810
1837
|
ops: sanitizeDbValue(ops),
|
|
1811
|
-
spanContext:
|
|
1838
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1812
1839
|
};
|
|
1813
1840
|
}
|
|
1814
1841
|
catch {
|
|
1815
1842
|
this.__repro_bulk_meta = {
|
|
1816
1843
|
t0: Date.now(),
|
|
1817
1844
|
collection: 'unknown',
|
|
1818
|
-
spanContext:
|
|
1845
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1819
1846
|
};
|
|
1820
1847
|
}
|
|
1821
1848
|
next();
|
|
@@ -1827,7 +1854,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1827
1854
|
const meta = this.__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
|
|
1828
1855
|
const bulkResult = summarizeBulkResult(res);
|
|
1829
1856
|
const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
|
|
1830
|
-
const spanContext =
|
|
1857
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1831
1858
|
emitDbQuery(cfg, sid, aid, {
|
|
1832
1859
|
collection: meta.collection,
|
|
1833
1860
|
op: 'bulkWrite',
|
|
@@ -1836,7 +1863,6 @@ function reproMongoosePlugin(cfg) {
|
|
|
1836
1863
|
durMs: Date.now() - meta.t0,
|
|
1837
1864
|
t: alignedNow(),
|
|
1838
1865
|
spanContext,
|
|
1839
|
-
spanSource: this,
|
|
1840
1866
|
});
|
|
1841
1867
|
});
|
|
1842
1868
|
// Aggregate middleware (non-intrusive)
|
|
@@ -1848,7 +1874,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1848
1874
|
this?._model?.collection?.name ||
|
|
1849
1875
|
(this?.model && this.model.collection?.name) ||
|
|
1850
1876
|
'unknown',
|
|
1851
|
-
spanContext:
|
|
1877
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1852
1878
|
pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
|
|
1853
1879
|
};
|
|
1854
1880
|
}
|
|
@@ -1857,7 +1883,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1857
1883
|
t0: Date.now(),
|
|
1858
1884
|
collection: 'unknown',
|
|
1859
1885
|
pipeline: undefined,
|
|
1860
|
-
spanContext:
|
|
1886
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1861
1887
|
};
|
|
1862
1888
|
}
|
|
1863
1889
|
next();
|
|
@@ -1868,7 +1894,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1868
1894
|
return;
|
|
1869
1895
|
const meta = this.__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
|
|
1870
1896
|
const resultMeta = summarizeQueryResult('aggregate', res);
|
|
1871
|
-
const spanContext =
|
|
1897
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1872
1898
|
emitDbQuery(cfg, sid, aid, {
|
|
1873
1899
|
collection: meta.collection,
|
|
1874
1900
|
op: 'aggregate',
|
|
@@ -1877,7 +1903,6 @@ function reproMongoosePlugin(cfg) {
|
|
|
1877
1903
|
durMs: Date.now() - meta.t0,
|
|
1878
1904
|
t: alignedNow(),
|
|
1879
1905
|
spanContext,
|
|
1880
|
-
spanSource: this,
|
|
1881
1906
|
});
|
|
1882
1907
|
});
|
|
1883
1908
|
};
|
|
@@ -2002,7 +2027,7 @@ function emitDbQuery(cfg, sid, aid, payload) {
|
|
|
2002
2027
|
durMs: payload.durMs ?? undefined,
|
|
2003
2028
|
pk: null, before: null, after: null,
|
|
2004
2029
|
error: payload.error ?? undefined,
|
|
2005
|
-
}, payload?.spanContext
|
|
2030
|
+
}, payload?.spanContext);
|
|
2006
2031
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
|
|
2007
2032
|
entries: [{
|
|
2008
2033
|
actionId: aid ?? null,
|
package/package.json
CHANGED
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 {
|
|
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 {
|
|
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
|
|
685
|
+
function captureSpanContextFromTracer(source?: any): SpanContext | null {
|
|
652
686
|
try {
|
|
653
687
|
const fromSource = source && source.__repro_span_context;
|
|
654
688
|
if (fromSource) {
|
|
655
|
-
|
|
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,
|
|
718
|
+
function attachSpanContext<T extends Record<string, any>>(target: T, span?: SpanContext | null): T {
|
|
686
719
|
if (!target) return target;
|
|
687
|
-
const ctx =
|
|
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:
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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:
|
|
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:
|
|
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 =
|
|
2003
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1971
2004
|
|
|
1972
2005
|
emitDbQuery(cfg, sid, aid, {
|
|
1973
2006
|
collection: meta.collection,
|
|
@@ -1977,7 +2010,6 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1977
2010
|
durMs: Date.now() - meta.t0,
|
|
1978
2011
|
t: alignedNow(),
|
|
1979
2012
|
spanContext,
|
|
1980
|
-
spanSource: this,
|
|
1981
2013
|
});
|
|
1982
2014
|
});
|
|
1983
2015
|
}
|
|
@@ -1992,13 +2024,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1992
2024
|
t0: Date.now(),
|
|
1993
2025
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1994
2026
|
docs: sanitizeDbValue(docs),
|
|
1995
|
-
spanContext:
|
|
2027
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
1996
2028
|
};
|
|
1997
2029
|
} catch {
|
|
1998
2030
|
(this as any).__repro_insert_meta = {
|
|
1999
2031
|
t0: Date.now(),
|
|
2000
2032
|
collection: 'unknown',
|
|
2001
|
-
spanContext:
|
|
2033
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
2002
2034
|
};
|
|
2003
2035
|
}
|
|
2004
2036
|
next();
|
|
@@ -2009,7 +2041,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2009
2041
|
if (!sid) return;
|
|
2010
2042
|
const meta = (this as any).__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
|
|
2011
2043
|
const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
|
|
2012
|
-
const spanContext =
|
|
2044
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
2013
2045
|
|
|
2014
2046
|
emitDbQuery(cfg, sid, aid, {
|
|
2015
2047
|
collection: meta.collection,
|
|
@@ -2019,7 +2051,6 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2019
2051
|
durMs: Date.now() - meta.t0,
|
|
2020
2052
|
t: alignedNow(),
|
|
2021
2053
|
spanContext,
|
|
2022
|
-
spanSource: this,
|
|
2023
2054
|
});
|
|
2024
2055
|
} as any);
|
|
2025
2056
|
|
|
@@ -2029,13 +2060,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2029
2060
|
t0: Date.now(),
|
|
2030
2061
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
2031
2062
|
ops: sanitizeDbValue(ops),
|
|
2032
|
-
spanContext:
|
|
2063
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
2033
2064
|
};
|
|
2034
2065
|
} catch {
|
|
2035
2066
|
(this as any).__repro_bulk_meta = {
|
|
2036
2067
|
t0: Date.now(),
|
|
2037
2068
|
collection: 'unknown',
|
|
2038
|
-
spanContext:
|
|
2069
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
2039
2070
|
};
|
|
2040
2071
|
}
|
|
2041
2072
|
next();
|
|
@@ -2047,7 +2078,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2047
2078
|
const meta = (this as any).__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
|
|
2048
2079
|
const bulkResult = summarizeBulkResult(res);
|
|
2049
2080
|
const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
|
|
2050
|
-
const spanContext =
|
|
2081
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
2051
2082
|
|
|
2052
2083
|
emitDbQuery(cfg, sid, aid, {
|
|
2053
2084
|
collection: meta.collection,
|
|
@@ -2057,7 +2088,6 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2057
2088
|
durMs: Date.now() - meta.t0,
|
|
2058
2089
|
t: alignedNow(),
|
|
2059
2090
|
spanContext,
|
|
2060
|
-
spanSource: this,
|
|
2061
2091
|
});
|
|
2062
2092
|
} as any);
|
|
2063
2093
|
|
|
@@ -2071,7 +2101,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2071
2101
|
this?._model?.collection?.name ||
|
|
2072
2102
|
(this?.model && this.model.collection?.name) ||
|
|
2073
2103
|
'unknown',
|
|
2074
|
-
spanContext:
|
|
2104
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
2075
2105
|
pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
|
|
2076
2106
|
};
|
|
2077
2107
|
} catch {
|
|
@@ -2079,7 +2109,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2079
2109
|
t0: Date.now(),
|
|
2080
2110
|
collection: 'unknown',
|
|
2081
2111
|
pipeline: undefined,
|
|
2082
|
-
spanContext:
|
|
2112
|
+
spanContext: captureSpanContextFromTracer(this),
|
|
2083
2113
|
};
|
|
2084
2114
|
}
|
|
2085
2115
|
next();
|
|
@@ -2091,7 +2121,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2091
2121
|
|
|
2092
2122
|
const meta = (this as any).__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
|
|
2093
2123
|
const resultMeta = summarizeQueryResult('aggregate', res);
|
|
2094
|
-
const spanContext =
|
|
2124
|
+
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
2095
2125
|
|
|
2096
2126
|
emitDbQuery(cfg, sid, aid, {
|
|
2097
2127
|
collection: meta.collection,
|
|
@@ -2101,7 +2131,6 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2101
2131
|
durMs: Date.now() - meta.t0,
|
|
2102
2132
|
t: alignedNow(),
|
|
2103
2133
|
spanContext,
|
|
2104
|
-
spanSource: this,
|
|
2105
2134
|
});
|
|
2106
2135
|
});
|
|
2107
2136
|
};
|
|
@@ -2219,7 +2248,7 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
|
|
|
2219
2248
|
durMs: payload.durMs ?? undefined,
|
|
2220
2249
|
pk: null, before: null, after: null,
|
|
2221
2250
|
error: payload.error ?? undefined,
|
|
2222
|
-
}, payload?.spanContext
|
|
2251
|
+
}, payload?.spanContext);
|
|
2223
2252
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
|
|
2224
2253
|
entries: [{
|
|
2225
2254
|
actionId: aid ?? null,
|
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();
|