repro-nest 0.0.213 → 0.0.214
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 +39 -3
- package/package.json +1 -1
- package/src/index.ts +30 -4
- package/tracer/runtime.js +7 -1
package/dist/index.js
CHANGED
|
@@ -542,6 +542,26 @@ function captureSpanContextFromTracer(source) {
|
|
|
542
542
|
catch { }
|
|
543
543
|
return null;
|
|
544
544
|
}
|
|
545
|
+
function isExcludedSpanId(spanId) {
|
|
546
|
+
if (spanId === null || spanId === undefined)
|
|
547
|
+
return false;
|
|
548
|
+
try {
|
|
549
|
+
const excluded = getCtx().excludedSpanIds;
|
|
550
|
+
if (!excluded || excluded.size === 0)
|
|
551
|
+
return false;
|
|
552
|
+
return excluded.has(String(spanId));
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
function shouldCaptureDbSpan(span) {
|
|
559
|
+
if (!span || span.spanId === null || span.spanId === undefined)
|
|
560
|
+
return false;
|
|
561
|
+
if (isExcludedSpanId(span.spanId))
|
|
562
|
+
return false;
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
545
565
|
function attachSpanContext(target, span) {
|
|
546
566
|
if (!target)
|
|
547
567
|
return target;
|
|
@@ -1294,7 +1314,7 @@ function reproMiddleware(cfg) {
|
|
|
1294
1314
|
}
|
|
1295
1315
|
return fn();
|
|
1296
1316
|
};
|
|
1297
|
-
runInTrace(() => als.run({ sid, aid, clockSkewMs }, () => {
|
|
1317
|
+
runInTrace(() => als.run({ sid, aid, clockSkewMs, excludedSpanIds: new Set() }, () => {
|
|
1298
1318
|
const events = [];
|
|
1299
1319
|
let endpointTrace = null;
|
|
1300
1320
|
let preferredAppTrace = null;
|
|
@@ -1443,6 +1463,7 @@ function reproMiddleware(cfg) {
|
|
|
1443
1463
|
depth: evt.depth,
|
|
1444
1464
|
library: inferLibraryNameFromFile(evt.file),
|
|
1445
1465
|
};
|
|
1466
|
+
const dropEvent = shouldDropTraceEvent(candidate);
|
|
1446
1467
|
const spanKey = normalizeSpanId(evt.spanId);
|
|
1447
1468
|
if (evt.type === 'enter') {
|
|
1448
1469
|
lastEventAt = Date.now();
|
|
@@ -1462,7 +1483,13 @@ function reproMiddleware(cfg) {
|
|
|
1462
1483
|
anonymousSpanDepth = Math.max(0, anonymousSpanDepth - 1);
|
|
1463
1484
|
}
|
|
1464
1485
|
}
|
|
1465
|
-
if (
|
|
1486
|
+
if (dropEvent) {
|
|
1487
|
+
if (evt.type === 'enter' && spanKey) {
|
|
1488
|
+
try {
|
|
1489
|
+
getCtx().excludedSpanIds?.add(spanKey);
|
|
1490
|
+
}
|
|
1491
|
+
catch { }
|
|
1492
|
+
}
|
|
1466
1493
|
if (finished) {
|
|
1467
1494
|
scheduleIdleFlush();
|
|
1468
1495
|
}
|
|
@@ -1646,6 +1673,8 @@ function reproMongoosePlugin(cfg) {
|
|
|
1646
1673
|
const after = this.toObject({ depopulate: true });
|
|
1647
1674
|
const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
|
|
1648
1675
|
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1676
|
+
if (!shouldCaptureDbSpan(spanContext))
|
|
1677
|
+
return;
|
|
1649
1678
|
const query = meta.wasNew
|
|
1650
1679
|
? { op: 'insertOne', doc: after }
|
|
1651
1680
|
: { filter: { _id: this._id }, update: buildMinimalUpdate(before, after), options: { upsert: false } };
|
|
@@ -1688,6 +1717,8 @@ function reproMongoosePlugin(cfg) {
|
|
|
1688
1717
|
const after = res ?? null;
|
|
1689
1718
|
const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1690
1719
|
const spanContext = this.__repro_spanContext || captureSpanContextFromTracer(this);
|
|
1720
|
+
if (!shouldCaptureDbSpan(spanContext))
|
|
1721
|
+
return;
|
|
1691
1722
|
const pk = after?._id ?? before?._id;
|
|
1692
1723
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
|
|
1693
1724
|
entries: [{
|
|
@@ -1728,6 +1759,8 @@ function reproMongoosePlugin(cfg) {
|
|
|
1728
1759
|
const collection = this.__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1729
1760
|
const filter = this.__repro_filter ?? { _id: before._id };
|
|
1730
1761
|
const spanContext = this.__repro_spanContext || captureSpanContextFromTracer(this);
|
|
1762
|
+
if (!shouldCaptureDbSpan(spanContext))
|
|
1763
|
+
return;
|
|
1731
1764
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, getCtx().sid, {
|
|
1732
1765
|
entries: [{
|
|
1733
1766
|
actionId: getCtx().aid,
|
|
@@ -2039,6 +2072,9 @@ function dehydrateComplexValue(value) {
|
|
|
2039
2072
|
function emitDbQuery(cfg, sid, aid, payload) {
|
|
2040
2073
|
if (!sid)
|
|
2041
2074
|
return;
|
|
2075
|
+
const spanContext = payload?.spanContext ?? captureSpanContextFromTracer();
|
|
2076
|
+
if (!shouldCaptureDbSpan(spanContext))
|
|
2077
|
+
return;
|
|
2042
2078
|
const dbEntry = attachSpanContext({
|
|
2043
2079
|
collection: payload.collection,
|
|
2044
2080
|
op: payload.op,
|
|
@@ -2047,7 +2083,7 @@ function emitDbQuery(cfg, sid, aid, payload) {
|
|
|
2047
2083
|
durMs: payload.durMs ?? undefined,
|
|
2048
2084
|
pk: null, before: null, after: null,
|
|
2049
2085
|
error: payload.error ?? undefined,
|
|
2050
|
-
},
|
|
2086
|
+
}, spanContext);
|
|
2051
2087
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
|
|
2052
2088
|
entries: [{
|
|
2053
2089
|
actionId: aid ?? null,
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -736,6 +736,23 @@ function captureSpanContextFromTracer(source?: any): SpanContext | null {
|
|
|
736
736
|
return null;
|
|
737
737
|
}
|
|
738
738
|
|
|
739
|
+
function isExcludedSpanId(spanId: string | number | null | undefined): boolean {
|
|
740
|
+
if (spanId === null || spanId === undefined) return false;
|
|
741
|
+
try {
|
|
742
|
+
const excluded = (getCtx() as Ctx).excludedSpanIds;
|
|
743
|
+
if (!excluded || excluded.size === 0) return false;
|
|
744
|
+
return excluded.has(String(spanId));
|
|
745
|
+
} catch {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function shouldCaptureDbSpan(span: SpanContext | null | undefined): span is SpanContext {
|
|
751
|
+
if (!span || span.spanId === null || span.spanId === undefined) return false;
|
|
752
|
+
if (isExcludedSpanId(span.spanId)) return false;
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
|
|
739
756
|
function attachSpanContext<T extends Record<string, any>>(target: T, span?: SpanContext | null): T {
|
|
740
757
|
if (!target) return target;
|
|
741
758
|
const ctx = span ?? captureSpanContextFromTracer();
|
|
@@ -745,7 +762,7 @@ function attachSpanContext<T extends Record<string, any>>(target: T, span?: Span
|
|
|
745
762
|
return target;
|
|
746
763
|
}
|
|
747
764
|
|
|
748
|
-
type Ctx = { sid?: string; aid?: string; clockSkewMs?: number };
|
|
765
|
+
type Ctx = { sid?: string; aid?: string; clockSkewMs?: number; excludedSpanIds?: Set<string> };
|
|
749
766
|
const als = new AsyncLocalStorage<Ctx>();
|
|
750
767
|
const getCtx = () => als.getStore() || {};
|
|
751
768
|
|
|
@@ -1525,7 +1542,7 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1525
1542
|
return fn();
|
|
1526
1543
|
};
|
|
1527
1544
|
|
|
1528
|
-
runInTrace(() => als.run({ sid, aid, clockSkewMs }, () => {
|
|
1545
|
+
runInTrace(() => als.run({ sid, aid, clockSkewMs, excludedSpanIds: new Set<string>() }, () => {
|
|
1529
1546
|
const events: TraceEventRecord[] = [];
|
|
1530
1547
|
let endpointTrace: EndpointTraceInfo | null = null;
|
|
1531
1548
|
let preferredAppTrace: EndpointTraceInfo | null = null;
|
|
@@ -1660,6 +1677,7 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1660
1677
|
library: inferLibraryNameFromFile(evt.file),
|
|
1661
1678
|
};
|
|
1662
1679
|
|
|
1680
|
+
const dropEvent = shouldDropTraceEvent(candidate);
|
|
1663
1681
|
const spanKey = normalizeSpanId(evt.spanId);
|
|
1664
1682
|
if (evt.type === 'enter') {
|
|
1665
1683
|
lastEventAt = Date.now();
|
|
@@ -1677,7 +1695,10 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1677
1695
|
}
|
|
1678
1696
|
}
|
|
1679
1697
|
|
|
1680
|
-
if (
|
|
1698
|
+
if (dropEvent) {
|
|
1699
|
+
if (evt.type === 'enter' && spanKey) {
|
|
1700
|
+
try { (getCtx() as Ctx).excludedSpanIds?.add(spanKey); } catch {}
|
|
1701
|
+
}
|
|
1681
1702
|
if (finished) {
|
|
1682
1703
|
scheduleIdleFlush();
|
|
1683
1704
|
}
|
|
@@ -1865,6 +1886,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1865
1886
|
const after = this.toObject({ depopulate: true });
|
|
1866
1887
|
const collection = meta.collection || resolveCollectionOrWarn(this, 'doc');
|
|
1867
1888
|
const spanContext = meta.spanContext || captureSpanContextFromTracer(this);
|
|
1889
|
+
if (!shouldCaptureDbSpan(spanContext)) return;
|
|
1868
1890
|
|
|
1869
1891
|
const query = meta.wasNew
|
|
1870
1892
|
? { op: 'insertOne', doc: after }
|
|
@@ -1909,6 +1931,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1909
1931
|
const after = res ?? null;
|
|
1910
1932
|
const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1911
1933
|
const spanContext = (this as any).__repro_spanContext || captureSpanContextFromTracer(this);
|
|
1934
|
+
if (!shouldCaptureDbSpan(spanContext)) return;
|
|
1912
1935
|
const pk = after?._id ?? before?._id;
|
|
1913
1936
|
|
|
1914
1937
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
|
|
@@ -1946,6 +1969,7 @@ export function reproMongoosePlugin(cfg: { appId: string; tenantId: string; appS
|
|
|
1946
1969
|
const collection = (this as any).__repro_collection || resolveCollectionOrWarn(this, 'query');
|
|
1947
1970
|
const filter = (this as any).__repro_filter ?? { _id: before._id };
|
|
1948
1971
|
const spanContext = (this as any).__repro_spanContext || captureSpanContextFromTracer(this);
|
|
1972
|
+
if (!shouldCaptureDbSpan(spanContext)) return;
|
|
1949
1973
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, (getCtx() as Ctx).sid!, {
|
|
1950
1974
|
entries: [{
|
|
1951
1975
|
actionId: (getCtx() as Ctx).aid!,
|
|
@@ -2261,6 +2285,8 @@ function dehydrateComplexValue(value: any) {
|
|
|
2261
2285
|
|
|
2262
2286
|
function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
|
|
2263
2287
|
if (!sid) return;
|
|
2288
|
+
const spanContext = payload?.spanContext ?? captureSpanContextFromTracer();
|
|
2289
|
+
if (!shouldCaptureDbSpan(spanContext)) return;
|
|
2264
2290
|
const dbEntry = attachSpanContext({
|
|
2265
2291
|
collection: payload.collection,
|
|
2266
2292
|
op: payload.op,
|
|
@@ -2269,7 +2295,7 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
|
|
|
2269
2295
|
durMs: payload.durMs ?? undefined,
|
|
2270
2296
|
pk: null, before: null, after: null,
|
|
2271
2297
|
error: payload.error ?? undefined,
|
|
2272
|
-
},
|
|
2298
|
+
}, spanContext);
|
|
2273
2299
|
post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
|
|
2274
2300
|
entries: [{
|
|
2275
2301
|
actionId: aid ?? null,
|
package/tracer/runtime.js
CHANGED
|
@@ -545,7 +545,13 @@ if (!global.__repro_call) {
|
|
|
545
545
|
const perCallStore = cloneStore(baseStoreSnapshot);
|
|
546
546
|
let result;
|
|
547
547
|
als.run(perCallStore, () => {
|
|
548
|
-
|
|
548
|
+
// Support both callbacks and constructors: some libraries (e.g., class-transformer)
|
|
549
|
+
// pass class constructors as args and invoke them with `new`.
|
|
550
|
+
if (new.target) {
|
|
551
|
+
result = Reflect.construct(arg, arguments, arg);
|
|
552
|
+
} else {
|
|
553
|
+
result = arg.apply(this, arguments);
|
|
554
|
+
}
|
|
549
555
|
});
|
|
550
556
|
return result;
|
|
551
557
|
};
|