repro-nest 0.0.209 → 0.0.210
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 +31 -21
- package/package.json +1 -1
- package/src/index.ts +32 -21
- package/tracer/runtime.js +34 -0
package/dist/index.js
CHANGED
|
@@ -459,8 +459,18 @@ exports.initReproTracing = initReproTracing;
|
|
|
459
459
|
/** Optional helper if users want to check it. */
|
|
460
460
|
function isReproTracingEnabled() { return __TRACER_READY; }
|
|
461
461
|
exports.isReproTracingEnabled = isReproTracingEnabled;
|
|
462
|
-
function
|
|
462
|
+
function captureSpanContext(source) {
|
|
463
463
|
try {
|
|
464
|
+
const fromSource = source && source.__repro_span_context;
|
|
465
|
+
if (fromSource) {
|
|
466
|
+
const span = {
|
|
467
|
+
traceId: fromSource.traceId ?? null,
|
|
468
|
+
spanId: fromSource.spanId ?? null,
|
|
469
|
+
parentSpanId: fromSource.parentSpanId ?? null,
|
|
470
|
+
depth: fromSource.depth ?? null,
|
|
471
|
+
};
|
|
472
|
+
return span;
|
|
473
|
+
}
|
|
464
474
|
const ctx = __TRACER__?.getCurrentSpanContext?.();
|
|
465
475
|
if (ctx) {
|
|
466
476
|
const span = {
|
|
@@ -483,10 +493,10 @@ function captureSpanContextFromTracer() {
|
|
|
483
493
|
catch { }
|
|
484
494
|
return null;
|
|
485
495
|
}
|
|
486
|
-
function attachSpanContext(target,
|
|
496
|
+
function attachSpanContext(target, spanSource, fallbackSource) {
|
|
487
497
|
if (!target)
|
|
488
498
|
return target;
|
|
489
|
-
const ctx =
|
|
499
|
+
const ctx = spanSource ?? captureSpanContext(fallbackSource);
|
|
490
500
|
if (ctx) {
|
|
491
501
|
try {
|
|
492
502
|
target.spanContext = ctx;
|
|
@@ -1572,7 +1582,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1572
1582
|
wasNew: this.isNew,
|
|
1573
1583
|
before,
|
|
1574
1584
|
collection: resolveCollectionOrWarn(this, 'doc'),
|
|
1575
|
-
spanContext:
|
|
1585
|
+
spanContext: captureSpanContext(this),
|
|
1576
1586
|
};
|
|
1577
1587
|
next();
|
|
1578
1588
|
});
|
|
@@ -1586,7 +1596,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1586
1596
|
const before = meta.before ?? null;
|
|
1587
1597
|
const after = this.toObject({ depopulate: true });
|
|
1588
1598
|
const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
|
|
1589
|
-
const spanContext = meta.spanContext ||
|
|
1599
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1590
1600
|
const query = meta.wasNew
|
|
1591
1601
|
? { op: 'insertOne', doc: after }
|
|
1592
1602
|
: { filter: { _id: this._id }, update: buildMinimalUpdate(before, after), options: { upsert: false } };
|
|
@@ -1616,7 +1626,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1616
1626
|
this.__repro_before = await model.findOne(filter).lean().exec();
|
|
1617
1627
|
this.setOptions({ new: true });
|
|
1618
1628
|
this.__repro_collection = resolveCollectionOrWarn(this, 'query');
|
|
1619
|
-
this.__repro_spanContext =
|
|
1629
|
+
this.__repro_spanContext = captureSpanContext(this);
|
|
1620
1630
|
}
|
|
1621
1631
|
catch { }
|
|
1622
1632
|
next();
|
|
@@ -1628,7 +1638,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1628
1638
|
const before = this.__repro_before ?? null;
|
|
1629
1639
|
const after = res ?? null;
|
|
1630
1640
|
const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1631
|
-
const spanContext = this.__repro_spanContext ||
|
|
1641
|
+
const spanContext = this.__repro_spanContext || captureSpanContext(this);
|
|
1632
1642
|
const pk = after?._id ?? before?._id;
|
|
1633
1643
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
|
|
1634
1644
|
entries: [{
|
|
@@ -1654,7 +1664,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1654
1664
|
this.__repro_before = await this.model.findOne(filter).lean().exec();
|
|
1655
1665
|
this.__repro_collection = resolveCollectionOrWarn(this, 'query');
|
|
1656
1666
|
this.__repro_filter = filter;
|
|
1657
|
-
this.__repro_spanContext =
|
|
1667
|
+
this.__repro_spanContext = captureSpanContext(this);
|
|
1658
1668
|
}
|
|
1659
1669
|
catch { }
|
|
1660
1670
|
next();
|
|
@@ -1668,7 +1678,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1668
1678
|
return;
|
|
1669
1679
|
const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1670
1680
|
const filter = this.__repro_filter ?? { _id: before._id };
|
|
1671
|
-
const spanContext = this.__repro_spanContext ||
|
|
1681
|
+
const spanContext = this.__repro_spanContext || captureSpanContext(this);
|
|
1672
1682
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
|
|
1673
1683
|
entries: [{
|
|
1674
1684
|
actionId: getCtx().aid,
|
|
@@ -1717,7 +1727,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1717
1727
|
t0: Date.now(),
|
|
1718
1728
|
collection: this?.model?.collection?.name || 'unknown',
|
|
1719
1729
|
op,
|
|
1720
|
-
spanContext:
|
|
1730
|
+
spanContext: captureSpanContext(this),
|
|
1721
1731
|
filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
|
|
1722
1732
|
update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
|
|
1723
1733
|
projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
|
|
@@ -1729,7 +1739,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1729
1739
|
t0: Date.now(),
|
|
1730
1740
|
collection: 'unknown',
|
|
1731
1741
|
op,
|
|
1732
|
-
spanContext:
|
|
1742
|
+
spanContext: captureSpanContext(this),
|
|
1733
1743
|
};
|
|
1734
1744
|
}
|
|
1735
1745
|
next();
|
|
@@ -1740,7 +1750,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1740
1750
|
return;
|
|
1741
1751
|
const meta = this.__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
|
|
1742
1752
|
const resultMeta = summarizeQueryResult(op, res);
|
|
1743
|
-
const spanContext = meta.spanContext ||
|
|
1753
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1744
1754
|
emitDbQuery(cfg, sid, aid, {
|
|
1745
1755
|
collection: meta.collection,
|
|
1746
1756
|
op,
|
|
@@ -1761,14 +1771,14 @@ function reproMongoosePlugin(cfg) {
|
|
|
1761
1771
|
t0: Date.now(),
|
|
1762
1772
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1763
1773
|
docs: sanitizeDbValue(docs),
|
|
1764
|
-
spanContext:
|
|
1774
|
+
spanContext: captureSpanContext(this),
|
|
1765
1775
|
};
|
|
1766
1776
|
}
|
|
1767
1777
|
catch {
|
|
1768
1778
|
this.__repro_insert_meta = {
|
|
1769
1779
|
t0: Date.now(),
|
|
1770
1780
|
collection: 'unknown',
|
|
1771
|
-
spanContext:
|
|
1781
|
+
spanContext: captureSpanContext(this),
|
|
1772
1782
|
};
|
|
1773
1783
|
}
|
|
1774
1784
|
next();
|
|
@@ -1779,7 +1789,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1779
1789
|
return;
|
|
1780
1790
|
const meta = this.__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
|
|
1781
1791
|
const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
|
|
1782
|
-
const spanContext = meta.spanContext ||
|
|
1792
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1783
1793
|
emitDbQuery(cfg, sid, aid, {
|
|
1784
1794
|
collection: meta.collection,
|
|
1785
1795
|
op: 'insertMany',
|
|
@@ -1796,14 +1806,14 @@ function reproMongoosePlugin(cfg) {
|
|
|
1796
1806
|
t0: Date.now(),
|
|
1797
1807
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1798
1808
|
ops: sanitizeDbValue(ops),
|
|
1799
|
-
spanContext:
|
|
1809
|
+
spanContext: captureSpanContext(this),
|
|
1800
1810
|
};
|
|
1801
1811
|
}
|
|
1802
1812
|
catch {
|
|
1803
1813
|
this.__repro_bulk_meta = {
|
|
1804
1814
|
t0: Date.now(),
|
|
1805
1815
|
collection: 'unknown',
|
|
1806
|
-
spanContext:
|
|
1816
|
+
spanContext: captureSpanContext(this),
|
|
1807
1817
|
};
|
|
1808
1818
|
}
|
|
1809
1819
|
next();
|
|
@@ -1815,7 +1825,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1815
1825
|
const meta = this.__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
|
|
1816
1826
|
const bulkResult = summarizeBulkResult(res);
|
|
1817
1827
|
const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
|
|
1818
|
-
const spanContext = meta.spanContext ||
|
|
1828
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1819
1829
|
emitDbQuery(cfg, sid, aid, {
|
|
1820
1830
|
collection: meta.collection,
|
|
1821
1831
|
op: 'bulkWrite',
|
|
@@ -1835,7 +1845,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1835
1845
|
this?._model?.collection?.name ||
|
|
1836
1846
|
(this?.model && this.model.collection?.name) ||
|
|
1837
1847
|
'unknown',
|
|
1838
|
-
spanContext:
|
|
1848
|
+
spanContext: captureSpanContext(this),
|
|
1839
1849
|
pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
|
|
1840
1850
|
};
|
|
1841
1851
|
}
|
|
@@ -1844,7 +1854,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1844
1854
|
t0: Date.now(),
|
|
1845
1855
|
collection: 'unknown',
|
|
1846
1856
|
pipeline: undefined,
|
|
1847
|
-
spanContext:
|
|
1857
|
+
spanContext: captureSpanContext(this),
|
|
1848
1858
|
};
|
|
1849
1859
|
}
|
|
1850
1860
|
next();
|
|
@@ -1855,7 +1865,7 @@ function reproMongoosePlugin(cfg) {
|
|
|
1855
1865
|
return;
|
|
1856
1866
|
const meta = this.__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
|
|
1857
1867
|
const resultMeta = summarizeQueryResult('aggregate', res);
|
|
1858
|
-
const spanContext = meta.spanContext ||
|
|
1868
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1859
1869
|
emitDbQuery(cfg, sid, aid, {
|
|
1860
1870
|
collection: meta.collection,
|
|
1861
1871
|
op: 'aggregate',
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -648,8 +648,19 @@ export function initReproTracing(opts?: ReproTracingInitOptions) {
|
|
|
648
648
|
/** Optional helper if users want to check it. */
|
|
649
649
|
export function isReproTracingEnabled() { return __TRACER_READY; }
|
|
650
650
|
|
|
651
|
-
function
|
|
651
|
+
function captureSpanContext(source?: any): SpanContext | null {
|
|
652
652
|
try {
|
|
653
|
+
const fromSource = source && source.__repro_span_context;
|
|
654
|
+
if (fromSource) {
|
|
655
|
+
const span: SpanContext = {
|
|
656
|
+
traceId: fromSource.traceId ?? null,
|
|
657
|
+
spanId: fromSource.spanId ?? null,
|
|
658
|
+
parentSpanId: fromSource.parentSpanId ?? null,
|
|
659
|
+
depth: fromSource.depth ?? null,
|
|
660
|
+
};
|
|
661
|
+
return span;
|
|
662
|
+
}
|
|
663
|
+
|
|
653
664
|
const ctx = __TRACER__?.getCurrentSpanContext?.();
|
|
654
665
|
if (ctx) {
|
|
655
666
|
const span: SpanContext = {
|
|
@@ -671,9 +682,9 @@ function captureSpanContextFromTracer(): SpanContext | null {
|
|
|
671
682
|
return null;
|
|
672
683
|
}
|
|
673
684
|
|
|
674
|
-
function attachSpanContext<T extends Record<string, any>>(target: T,
|
|
685
|
+
function attachSpanContext<T extends Record<string, any>>(target: T, spanSource?: SpanContext | null, fallbackSource?: any): T {
|
|
675
686
|
if (!target) return target;
|
|
676
|
-
const ctx =
|
|
687
|
+
const ctx = spanSource ?? captureSpanContext(fallbackSource);
|
|
677
688
|
if (ctx) {
|
|
678
689
|
try { (target as any).spanContext = ctx; } catch {}
|
|
679
690
|
}
|
|
@@ -1785,7 +1796,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1785
1796
|
wasNew: this.isNew,
|
|
1786
1797
|
before,
|
|
1787
1798
|
collection: resolveCollectionOrWarn(this, 'doc'),
|
|
1788
|
-
spanContext:
|
|
1799
|
+
spanContext: captureSpanContext(this),
|
|
1789
1800
|
};
|
|
1790
1801
|
next();
|
|
1791
1802
|
});
|
|
@@ -1799,7 +1810,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1799
1810
|
const before = meta.before ?? null;
|
|
1800
1811
|
const after = this.toObject({ depopulate: true });
|
|
1801
1812
|
const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
|
|
1802
|
-
const spanContext = meta.spanContext ||
|
|
1813
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1803
1814
|
|
|
1804
1815
|
const query = meta.wasNew
|
|
1805
1816
|
? { op: 'insertOne', doc: after }
|
|
@@ -1831,7 +1842,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1831
1842
|
(this as any).__repro_before = await model.findOne(filter).lean().exec();
|
|
1832
1843
|
this.setOptions({ new: true });
|
|
1833
1844
|
(this as any).__repro_collection = resolveCollectionOrWarn(this, 'query');
|
|
1834
|
-
(this as any).__repro_spanContext =
|
|
1845
|
+
(this as any).__repro_spanContext = captureSpanContext(this);
|
|
1835
1846
|
} catch {}
|
|
1836
1847
|
next();
|
|
1837
1848
|
});
|
|
@@ -1843,7 +1854,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1843
1854
|
const before = (this as any).__repro_before ?? null;
|
|
1844
1855
|
const after = res ?? null;
|
|
1845
1856
|
const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1846
|
-
const spanContext = (this as any).__repro_spanContext ||
|
|
1857
|
+
const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
|
|
1847
1858
|
const pk = after?._id ?? before?._id;
|
|
1848
1859
|
|
|
1849
1860
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
|
|
@@ -1869,7 +1880,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1869
1880
|
(this as any).__repro_before = await (this.model as Model<any>).findOne(filter).lean().exec();
|
|
1870
1881
|
(this as any).__repro_collection = resolveCollectionOrWarn(this, 'query');
|
|
1871
1882
|
(this as any).__repro_filter = filter;
|
|
1872
|
-
(this as any).__repro_spanContext =
|
|
1883
|
+
(this as any).__repro_spanContext = captureSpanContext(this);
|
|
1873
1884
|
} catch {}
|
|
1874
1885
|
next();
|
|
1875
1886
|
});
|
|
@@ -1880,7 +1891,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1880
1891
|
if (!before) return;
|
|
1881
1892
|
const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1882
1893
|
const filter = (this as any).__repro_filter ?? { _id: before._id };
|
|
1883
|
-
const spanContext = (this as any).__repro_spanContext ||
|
|
1894
|
+
const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
|
|
1884
1895
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
|
|
1885
1896
|
entries: [{
|
|
1886
1897
|
actionId: (getCtx() as Ctx).aid!,
|
|
@@ -1933,7 +1944,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1933
1944
|
t0: Date.now(),
|
|
1934
1945
|
collection: this?.model?.collection?.name || 'unknown',
|
|
1935
1946
|
op,
|
|
1936
|
-
spanContext:
|
|
1947
|
+
spanContext: captureSpanContext(this),
|
|
1937
1948
|
filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
|
|
1938
1949
|
update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
|
|
1939
1950
|
projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
|
|
@@ -1944,7 +1955,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1944
1955
|
t0: Date.now(),
|
|
1945
1956
|
collection: 'unknown',
|
|
1946
1957
|
op,
|
|
1947
|
-
spanContext:
|
|
1958
|
+
spanContext: captureSpanContext(this),
|
|
1948
1959
|
};
|
|
1949
1960
|
}
|
|
1950
1961
|
next();
|
|
@@ -1956,7 +1967,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1956
1967
|
|
|
1957
1968
|
const meta = (this as any).__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
|
|
1958
1969
|
const resultMeta = summarizeQueryResult(op, res);
|
|
1959
|
-
const spanContext = meta.spanContext ||
|
|
1970
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
1960
1971
|
|
|
1961
1972
|
emitDbQuery(cfg, sid, aid, {
|
|
1962
1973
|
collection: meta.collection,
|
|
@@ -1980,13 +1991,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1980
1991
|
t0: Date.now(),
|
|
1981
1992
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
1982
1993
|
docs: sanitizeDbValue(docs),
|
|
1983
|
-
spanContext:
|
|
1994
|
+
spanContext: captureSpanContext(this),
|
|
1984
1995
|
};
|
|
1985
1996
|
} catch {
|
|
1986
1997
|
(this as any).__repro_insert_meta = {
|
|
1987
1998
|
t0: Date.now(),
|
|
1988
1999
|
collection: 'unknown',
|
|
1989
|
-
spanContext:
|
|
2000
|
+
spanContext: captureSpanContext(this),
|
|
1990
2001
|
};
|
|
1991
2002
|
}
|
|
1992
2003
|
next();
|
|
@@ -1997,7 +2008,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1997
2008
|
if (!sid) return;
|
|
1998
2009
|
const meta = (this as any).__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
|
|
1999
2010
|
const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
|
|
2000
|
-
const spanContext = meta.spanContext ||
|
|
2011
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
2001
2012
|
|
|
2002
2013
|
emitDbQuery(cfg, sid, aid, {
|
|
2003
2014
|
collection: meta.collection,
|
|
@@ -2016,13 +2027,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2016
2027
|
t0: Date.now(),
|
|
2017
2028
|
collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
|
|
2018
2029
|
ops: sanitizeDbValue(ops),
|
|
2019
|
-
spanContext:
|
|
2030
|
+
spanContext: captureSpanContext(this),
|
|
2020
2031
|
};
|
|
2021
2032
|
} catch {
|
|
2022
2033
|
(this as any).__repro_bulk_meta = {
|
|
2023
2034
|
t0: Date.now(),
|
|
2024
2035
|
collection: 'unknown',
|
|
2025
|
-
spanContext:
|
|
2036
|
+
spanContext: captureSpanContext(this),
|
|
2026
2037
|
};
|
|
2027
2038
|
}
|
|
2028
2039
|
next();
|
|
@@ -2034,7 +2045,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2034
2045
|
const meta = (this as any).__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
|
|
2035
2046
|
const bulkResult = summarizeBulkResult(res);
|
|
2036
2047
|
const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
|
|
2037
|
-
const spanContext = meta.spanContext ||
|
|
2048
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
2038
2049
|
|
|
2039
2050
|
emitDbQuery(cfg, sid, aid, {
|
|
2040
2051
|
collection: meta.collection,
|
|
@@ -2057,7 +2068,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2057
2068
|
this?._model?.collection?.name ||
|
|
2058
2069
|
(this?.model && this.model.collection?.name) ||
|
|
2059
2070
|
'unknown',
|
|
2060
|
-
spanContext:
|
|
2071
|
+
spanContext: captureSpanContext(this),
|
|
2061
2072
|
pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
|
|
2062
2073
|
};
|
|
2063
2074
|
} catch {
|
|
@@ -2065,7 +2076,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2065
2076
|
t0: Date.now(),
|
|
2066
2077
|
collection: 'unknown',
|
|
2067
2078
|
pipeline: undefined,
|
|
2068
|
-
spanContext:
|
|
2079
|
+
spanContext: captureSpanContext(this),
|
|
2069
2080
|
};
|
|
2070
2081
|
}
|
|
2071
2082
|
next();
|
|
@@ -2077,7 +2088,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
2077
2088
|
|
|
2078
2089
|
const meta = (this as any).__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
|
|
2079
2090
|
const resultMeta = summarizeQueryResult('aggregate', res);
|
|
2080
|
-
const spanContext = meta.spanContext ||
|
|
2091
|
+
const spanContext = meta.spanContext || captureSpanContext(this);
|
|
2081
2092
|
|
|
2082
2093
|
emitDbQuery(cfg, sid, aid, {
|
|
2083
2094
|
collection: meta.collection,
|
package/tracer/runtime.js
CHANGED
|
@@ -262,6 +262,12 @@ 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
|
+
});
|
|
265
271
|
emitNow({ unawaited: forceUnawaited, returnValue: rv }, spanForExit, spanStackForExit);
|
|
266
272
|
return;
|
|
267
273
|
}
|
|
@@ -272,6 +278,12 @@ const trace = {
|
|
|
272
278
|
}
|
|
273
279
|
|
|
274
280
|
if (isQuery) {
|
|
281
|
+
setQuerySpanContext(rv, {
|
|
282
|
+
traceId: traceIdAtExit,
|
|
283
|
+
spanId: spanInfoPeek.id,
|
|
284
|
+
parentSpanId: spanInfoPeek.parentId,
|
|
285
|
+
depth: spanInfoPeek.depth ?? depthAtExit
|
|
286
|
+
});
|
|
275
287
|
emitNow({ unawaited: forceUnawaited });
|
|
276
288
|
return;
|
|
277
289
|
}
|
|
@@ -841,6 +853,28 @@ function getCurrentTraceId() {
|
|
|
841
853
|
return s && s.traceId || null;
|
|
842
854
|
}
|
|
843
855
|
|
|
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
|
+
|
|
844
878
|
function getCurrentSpanContext() {
|
|
845
879
|
try {
|
|
846
880
|
const store = als.getStore();
|