repro-nest 0.0.210 → 0.0.211

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.
Files changed (3) hide show
  1. package/dist/index.js +20 -16
  2. package/package.json +1 -1
  3. package/src/index.ts +20 -16
package/dist/index.js CHANGED
@@ -1596,7 +1596,7 @@ function reproMongoosePlugin(cfg) {
1596
1596
  const before = meta.before ?? null;
1597
1597
  const after = this.toObject({ depopulate: true });
1598
1598
  const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
1599
- const spanContext = meta.spanContext || captureSpanContext(this);
1599
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1600
1600
  const query = meta.wasNew
1601
1601
  ? { op: 'insertOne', doc: after }
1602
1602
  : { filter: { _id: this._id }, update: buildMinimalUpdate(before, after), options: { upsert: false } };
@@ -1638,7 +1638,7 @@ function reproMongoosePlugin(cfg) {
1638
1638
  const before = this.__repro_before ?? null;
1639
1639
  const after = res ?? null;
1640
1640
  const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
1641
- const spanContext = this.__repro_spanContext || captureSpanContext(this);
1641
+ const spanContext = captureSpanContext(this) || this.__repro_spanContext || captureSpanContext();
1642
1642
  const pk = after?._id ?? before?._id;
1643
1643
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
1644
1644
  entries: [{
@@ -1678,7 +1678,7 @@ function reproMongoosePlugin(cfg) {
1678
1678
  return;
1679
1679
  const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
1680
1680
  const filter = this.__repro_filter ?? { _id: before._id };
1681
- const spanContext = this.__repro_spanContext || captureSpanContext(this);
1681
+ const spanContext = captureSpanContext(this) || this.__repro_spanContext || captureSpanContext();
1682
1682
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
1683
1683
  entries: [{
1684
1684
  actionId: getCtx().aid,
@@ -1727,7 +1727,7 @@ function reproMongoosePlugin(cfg) {
1727
1727
  t0: Date.now(),
1728
1728
  collection: this?.model?.collection?.name || 'unknown',
1729
1729
  op,
1730
- spanContext: captureSpanContext(this),
1730
+ spanContext: null,
1731
1731
  filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
1732
1732
  update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
1733
1733
  projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
@@ -1739,7 +1739,7 @@ function reproMongoosePlugin(cfg) {
1739
1739
  t0: Date.now(),
1740
1740
  collection: 'unknown',
1741
1741
  op,
1742
- spanContext: captureSpanContext(this),
1742
+ spanContext: null,
1743
1743
  };
1744
1744
  }
1745
1745
  next();
@@ -1750,7 +1750,7 @@ function reproMongoosePlugin(cfg) {
1750
1750
  return;
1751
1751
  const meta = this.__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
1752
1752
  const resultMeta = summarizeQueryResult(op, res);
1753
- const spanContext = meta.spanContext || captureSpanContext(this);
1753
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1754
1754
  emitDbQuery(cfg, sid, aid, {
1755
1755
  collection: meta.collection,
1756
1756
  op,
@@ -1759,6 +1759,7 @@ function reproMongoosePlugin(cfg) {
1759
1759
  durMs: Date.now() - meta.t0,
1760
1760
  t: alignedNow(),
1761
1761
  spanContext,
1762
+ spanSource: this,
1762
1763
  });
1763
1764
  });
1764
1765
  }
@@ -1771,14 +1772,14 @@ function reproMongoosePlugin(cfg) {
1771
1772
  t0: Date.now(),
1772
1773
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1773
1774
  docs: sanitizeDbValue(docs),
1774
- spanContext: captureSpanContext(this),
1775
+ spanContext: null,
1775
1776
  };
1776
1777
  }
1777
1778
  catch {
1778
1779
  this.__repro_insert_meta = {
1779
1780
  t0: Date.now(),
1780
1781
  collection: 'unknown',
1781
- spanContext: captureSpanContext(this),
1782
+ spanContext: null,
1782
1783
  };
1783
1784
  }
1784
1785
  next();
@@ -1789,7 +1790,7 @@ function reproMongoosePlugin(cfg) {
1789
1790
  return;
1790
1791
  const meta = this.__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
1791
1792
  const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
1792
- const spanContext = meta.spanContext || captureSpanContext(this);
1793
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1793
1794
  emitDbQuery(cfg, sid, aid, {
1794
1795
  collection: meta.collection,
1795
1796
  op: 'insertMany',
@@ -1798,6 +1799,7 @@ function reproMongoosePlugin(cfg) {
1798
1799
  durMs: Date.now() - meta.t0,
1799
1800
  t: alignedNow(),
1800
1801
  spanContext,
1802
+ spanSource: this,
1801
1803
  });
1802
1804
  });
1803
1805
  schema.pre('bulkWrite', { document: false, query: false }, function (next, ops) {
@@ -1806,14 +1808,14 @@ function reproMongoosePlugin(cfg) {
1806
1808
  t0: Date.now(),
1807
1809
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1808
1810
  ops: sanitizeDbValue(ops),
1809
- spanContext: captureSpanContext(this),
1811
+ spanContext: null,
1810
1812
  };
1811
1813
  }
1812
1814
  catch {
1813
1815
  this.__repro_bulk_meta = {
1814
1816
  t0: Date.now(),
1815
1817
  collection: 'unknown',
1816
- spanContext: captureSpanContext(this),
1818
+ spanContext: null,
1817
1819
  };
1818
1820
  }
1819
1821
  next();
@@ -1825,7 +1827,7 @@ function reproMongoosePlugin(cfg) {
1825
1827
  const meta = this.__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
1826
1828
  const bulkResult = summarizeBulkResult(res);
1827
1829
  const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
1828
- const spanContext = meta.spanContext || captureSpanContext(this);
1830
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1829
1831
  emitDbQuery(cfg, sid, aid, {
1830
1832
  collection: meta.collection,
1831
1833
  op: 'bulkWrite',
@@ -1834,6 +1836,7 @@ function reproMongoosePlugin(cfg) {
1834
1836
  durMs: Date.now() - meta.t0,
1835
1837
  t: alignedNow(),
1836
1838
  spanContext,
1839
+ spanSource: this,
1837
1840
  });
1838
1841
  });
1839
1842
  // Aggregate middleware (non-intrusive)
@@ -1845,7 +1848,7 @@ function reproMongoosePlugin(cfg) {
1845
1848
  this?._model?.collection?.name ||
1846
1849
  (this?.model && this.model.collection?.name) ||
1847
1850
  'unknown',
1848
- spanContext: captureSpanContext(this),
1851
+ spanContext: null,
1849
1852
  pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
1850
1853
  };
1851
1854
  }
@@ -1854,7 +1857,7 @@ function reproMongoosePlugin(cfg) {
1854
1857
  t0: Date.now(),
1855
1858
  collection: 'unknown',
1856
1859
  pipeline: undefined,
1857
- spanContext: captureSpanContext(this),
1860
+ spanContext: null,
1858
1861
  };
1859
1862
  }
1860
1863
  next();
@@ -1865,7 +1868,7 @@ function reproMongoosePlugin(cfg) {
1865
1868
  return;
1866
1869
  const meta = this.__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
1867
1870
  const resultMeta = summarizeQueryResult('aggregate', res);
1868
- const spanContext = meta.spanContext || captureSpanContext(this);
1871
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1869
1872
  emitDbQuery(cfg, sid, aid, {
1870
1873
  collection: meta.collection,
1871
1874
  op: 'aggregate',
@@ -1874,6 +1877,7 @@ function reproMongoosePlugin(cfg) {
1874
1877
  durMs: Date.now() - meta.t0,
1875
1878
  t: alignedNow(),
1876
1879
  spanContext,
1880
+ spanSource: this,
1877
1881
  });
1878
1882
  });
1879
1883
  };
@@ -1998,7 +2002,7 @@ function emitDbQuery(cfg, sid, aid, payload) {
1998
2002
  durMs: payload.durMs ?? undefined,
1999
2003
  pk: null, before: null, after: null,
2000
2004
  error: payload.error ?? undefined,
2001
- }, payload?.spanContext);
2005
+ }, payload?.spanContext, payload?.spanSource);
2002
2006
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
2003
2007
  entries: [{
2004
2008
  actionId: aid ?? null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repro-nest",
3
- "version": "0.0.210",
3
+ "version": "0.0.211",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1810,7 +1810,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1810
1810
  const before = meta.before ?? null;
1811
1811
  const after = this.toObject({ depopulate: true });
1812
1812
  const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
1813
- const spanContext = meta.spanContext || captureSpanContext(this);
1813
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1814
1814
 
1815
1815
  const query = meta.wasNew
1816
1816
  ? { op: 'insertOne', doc: after }
@@ -1854,7 +1854,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1854
1854
  const before = (this as any).__repro_before ?? null;
1855
1855
  const after = res ?? null;
1856
1856
  const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
1857
- const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
1857
+ const spanContext = captureSpanContext(this) || (this as any).__repro_spanContext || captureSpanContext();
1858
1858
  const pk = after?._id ?? before?._id;
1859
1859
 
1860
1860
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
@@ -1891,7 +1891,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1891
1891
  if (!before) return;
1892
1892
  const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
1893
1893
  const filter = (this as any).__repro_filter ?? { _id: before._id };
1894
- const spanContext = (this as any).__repro_spanContext || captureSpanContext(this);
1894
+ const spanContext = captureSpanContext(this) || (this as any).__repro_spanContext || captureSpanContext();
1895
1895
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
1896
1896
  entries: [{
1897
1897
  actionId: (getCtx() as Ctx).aid!,
@@ -1944,7 +1944,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1944
1944
  t0: Date.now(),
1945
1945
  collection: this?.model?.collection?.name || 'unknown',
1946
1946
  op,
1947
- spanContext: captureSpanContext(this),
1947
+ spanContext: null,
1948
1948
  filter: sanitizeDbValue(this.getFilter?.() ?? this._conditions ?? undefined),
1949
1949
  update: sanitizeDbValue(this.getUpdate?.() ?? this._update ?? undefined),
1950
1950
  projection: sanitizeDbValue(this.projection?.() ?? this._fields ?? undefined),
@@ -1955,7 +1955,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1955
1955
  t0: Date.now(),
1956
1956
  collection: 'unknown',
1957
1957
  op,
1958
- spanContext: captureSpanContext(this),
1958
+ spanContext: null,
1959
1959
  };
1960
1960
  }
1961
1961
  next();
@@ -1967,7 +1967,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1967
1967
 
1968
1968
  const meta = (this as any).__repro_qmeta || { t0: Date.now(), collection: 'unknown', op };
1969
1969
  const resultMeta = summarizeQueryResult(op, res);
1970
- const spanContext = meta.spanContext || captureSpanContext(this);
1970
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
1971
1971
 
1972
1972
  emitDbQuery(cfg, sid, aid, {
1973
1973
  collection: meta.collection,
@@ -1977,6 +1977,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1977
1977
  durMs: Date.now() - meta.t0,
1978
1978
  t: alignedNow(),
1979
1979
  spanContext,
1980
+ spanSource: this,
1980
1981
  });
1981
1982
  });
1982
1983
  }
@@ -1991,13 +1992,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
1991
1992
  t0: Date.now(),
1992
1993
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
1993
1994
  docs: sanitizeDbValue(docs),
1994
- spanContext: captureSpanContext(this),
1995
+ spanContext: null,
1995
1996
  };
1996
1997
  } catch {
1997
1998
  (this as any).__repro_insert_meta = {
1998
1999
  t0: Date.now(),
1999
2000
  collection: 'unknown',
2000
- spanContext: captureSpanContext(this),
2001
+ spanContext: null,
2001
2002
  };
2002
2003
  }
2003
2004
  next();
@@ -2008,7 +2009,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2008
2009
  if (!sid) return;
2009
2010
  const meta = (this as any).__repro_insert_meta || { t0: Date.now(), collection: 'unknown' };
2010
2011
  const resultMeta = Array.isArray(docs) ? { inserted: docs.length } : summarizeQueryResult('insertMany', docs);
2011
- const spanContext = meta.spanContext || captureSpanContext(this);
2012
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
2012
2013
 
2013
2014
  emitDbQuery(cfg, sid, aid, {
2014
2015
  collection: meta.collection,
@@ -2018,6 +2019,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2018
2019
  durMs: Date.now() - meta.t0,
2019
2020
  t: alignedNow(),
2020
2021
  spanContext,
2022
+ spanSource: this,
2021
2023
  });
2022
2024
  } as any);
2023
2025
 
@@ -2027,13 +2029,13 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2027
2029
  t0: Date.now(),
2028
2030
  collection: this?.collection?.name || this?.model?.collection?.name || 'unknown',
2029
2031
  ops: sanitizeDbValue(ops),
2030
- spanContext: captureSpanContext(this),
2032
+ spanContext: null,
2031
2033
  };
2032
2034
  } catch {
2033
2035
  (this as any).__repro_bulk_meta = {
2034
2036
  t0: Date.now(),
2035
2037
  collection: 'unknown',
2036
- spanContext: captureSpanContext(this),
2038
+ spanContext: null,
2037
2039
  };
2038
2040
  }
2039
2041
  next();
@@ -2045,7 +2047,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2045
2047
  const meta = (this as any).__repro_bulk_meta || { t0: Date.now(), collection: 'unknown' };
2046
2048
  const bulkResult = summarizeBulkResult(res);
2047
2049
  const resultMeta = { ...bulkResult, result: sanitizeResultForMeta(res?.result ?? res) };
2048
- const spanContext = meta.spanContext || captureSpanContext(this);
2050
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
2049
2051
 
2050
2052
  emitDbQuery(cfg, sid, aid, {
2051
2053
  collection: meta.collection,
@@ -2055,6 +2057,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2055
2057
  durMs: Date.now() - meta.t0,
2056
2058
  t: alignedNow(),
2057
2059
  spanContext,
2060
+ spanSource: this,
2058
2061
  });
2059
2062
  } as any);
2060
2063
 
@@ -2068,7 +2071,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2068
2071
  this?._model?.collection?.name ||
2069
2072
  (this?.model && this.model.collection?.name) ||
2070
2073
  'unknown',
2071
- spanContext: captureSpanContext(this),
2074
+ spanContext: null,
2072
2075
  pipeline: sanitizeDbValue(this.pipeline?.() ?? this._pipeline ?? undefined),
2073
2076
  };
2074
2077
  } catch {
@@ -2076,7 +2079,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2076
2079
  t0: Date.now(),
2077
2080
  collection: 'unknown',
2078
2081
  pipeline: undefined,
2079
- spanContext: captureSpanContext(this),
2082
+ spanContext: null,
2080
2083
  };
2081
2084
  }
2082
2085
  next();
@@ -2088,7 +2091,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2088
2091
 
2089
2092
  const meta = (this as any).__repro_aggmeta || { t0: Date.now(), collection: 'unknown' };
2090
2093
  const resultMeta = summarizeQueryResult('aggregate', res);
2091
- const spanContext = meta.spanContext || captureSpanContext(this);
2094
+ const spanContext = captureSpanContext(this) || meta.spanContext || captureSpanContext();
2092
2095
 
2093
2096
  emitDbQuery(cfg, sid, aid, {
2094
2097
  collection: meta.collection,
@@ -2098,6 +2101,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
2098
2101
  durMs: Date.now() - meta.t0,
2099
2102
  t: alignedNow(),
2100
2103
  spanContext,
2104
+ spanSource: this,
2101
2105
  });
2102
2106
  });
2103
2107
  };
@@ -2215,7 +2219,7 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
2215
2219
  durMs: payload.durMs ?? undefined,
2216
2220
  pk: null, before: null, after: null,
2217
2221
  error: payload.error ?? undefined,
2218
- }, payload?.spanContext);
2222
+ }, payload?.spanContext, payload?.spanSource);
2219
2223
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
2220
2224
  entries: [{
2221
2225
  actionId: aid ?? null,