repro-nest 0.0.215 → 0.0.216
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.d.ts +5 -2
- package/dist/index.js +9 -2
- package/docs/tracing.md +3 -2
- package/package.json +1 -1
- package/src/index.ts +17 -7
- package/tracer/runtime.js +12 -5
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ type TracerApi = {
|
|
|
42
42
|
setFunctionLogsEnabled?: (enabled: boolean) => void;
|
|
43
43
|
};
|
|
44
44
|
type TraceEventPhase = 'enter' | 'exit';
|
|
45
|
-
export type TraceRulePattern = string | RegExp | Array<string | RegExp>;
|
|
45
|
+
export type TraceRulePattern = string | number | RegExp | Array<string | number | RegExp>;
|
|
46
46
|
export type TraceEventForFilter = {
|
|
47
47
|
type: TraceEventPhase;
|
|
48
48
|
eventType: TraceEventPhase;
|
|
@@ -50,6 +50,7 @@ export type TraceEventForFilter = {
|
|
|
50
50
|
fn?: string;
|
|
51
51
|
wrapperClass?: string | null;
|
|
52
52
|
file?: string | null;
|
|
53
|
+
line?: number | null;
|
|
53
54
|
depth?: number;
|
|
54
55
|
library?: string | null;
|
|
55
56
|
};
|
|
@@ -100,8 +101,10 @@ export type DisableFunctionTraceRule = {
|
|
|
100
101
|
className?: TraceRulePattern;
|
|
101
102
|
/** Alias for {@link wrapperClass}. */
|
|
102
103
|
owner?: TraceRulePattern;
|
|
103
|
-
/**
|
|
104
|
+
/** Source filename reported by the trace event. */
|
|
104
105
|
file?: TraceRulePattern;
|
|
106
|
+
/** Line number reported by the trace event. */
|
|
107
|
+
line?: TraceRulePattern;
|
|
105
108
|
/** Shortcut for {@link library}. */
|
|
106
109
|
lib?: TraceRulePattern;
|
|
107
110
|
/** Library/package name inferred from the file path (e.g. `"mongoose"`). */
|
package/dist/index.js
CHANGED
|
@@ -325,6 +325,8 @@ function matchesRule(rule, event) {
|
|
|
325
325
|
return false;
|
|
326
326
|
if (!matchesPattern(event.file, rule.file))
|
|
327
327
|
return false;
|
|
328
|
+
if (!matchesPattern(event.line == null ? null : String(event.line), rule.line))
|
|
329
|
+
return false;
|
|
328
330
|
const libPattern = rule.lib ?? rule.library;
|
|
329
331
|
if (!matchesPattern(event.library, libPattern))
|
|
330
332
|
return false;
|
|
@@ -385,7 +387,7 @@ function flattenTraceFilePatterns(config) {
|
|
|
385
387
|
if (Array.isArray(config)) {
|
|
386
388
|
return config.flatMap(entry => flattenTraceFilePatterns(entry));
|
|
387
389
|
}
|
|
388
|
-
if (config instanceof RegExp || typeof config === 'string') {
|
|
390
|
+
if (config instanceof RegExp || typeof config === 'string' || typeof config === 'number') {
|
|
389
391
|
return [config];
|
|
390
392
|
}
|
|
391
393
|
if (typeof config === 'object' && 'file' in config) {
|
|
@@ -1635,6 +1637,9 @@ function reproMiddleware(cfg) {
|
|
|
1635
1637
|
unsubscribe = __TRACER__.tracer.on((ev) => {
|
|
1636
1638
|
if (!ev || ev.traceId !== tidNow)
|
|
1637
1639
|
return;
|
|
1640
|
+
const sourceFileForLibrary = typeof ev.sourceFile === 'string' && ev.sourceFile
|
|
1641
|
+
? String(ev.sourceFile)
|
|
1642
|
+
: null;
|
|
1638
1643
|
const evt = {
|
|
1639
1644
|
t: alignTimestamp(ev.t),
|
|
1640
1645
|
type: ev.type,
|
|
@@ -1655,8 +1660,9 @@ function reproMiddleware(cfg) {
|
|
|
1655
1660
|
fn: evt.fn,
|
|
1656
1661
|
wrapperClass: inferWrapperClassFromFn(evt.fn),
|
|
1657
1662
|
file: evt.file ?? null,
|
|
1663
|
+
line: evt.line ?? null,
|
|
1658
1664
|
depth: evt.depth,
|
|
1659
|
-
library: inferLibraryNameFromFile(evt.file),
|
|
1665
|
+
library: inferLibraryNameFromFile(sourceFileForLibrary ?? evt.file),
|
|
1660
1666
|
};
|
|
1661
1667
|
if (ev.args !== undefined) {
|
|
1662
1668
|
evt.args = applyMasking('trace.args', sanitizeTraceArgs(ev.args), maskReq, candidate, masking);
|
|
@@ -1765,6 +1771,7 @@ function reproMiddleware(cfg) {
|
|
|
1765
1771
|
fn: chosenEndpoint.fn ?? undefined,
|
|
1766
1772
|
wrapperClass: inferWrapperClassFromFn(chosenEndpoint.fn),
|
|
1767
1773
|
file: chosenEndpoint.file ?? null,
|
|
1774
|
+
line: chosenEndpoint.line ?? null,
|
|
1768
1775
|
functionType: chosenEndpoint.functionType ?? null,
|
|
1769
1776
|
library: inferLibraryNameFromFile(chosenEndpoint.file),
|
|
1770
1777
|
};
|
package/docs/tracing.md
CHANGED
|
@@ -51,7 +51,8 @@ captured in the session payload.
|
|
|
51
51
|
| --------------- | ------------------------------------------------------------------------------------------------- |
|
|
52
52
|
| `fn`/`functionName` | Match against the instrumented function name (substring or RegExp). |
|
|
53
53
|
| `wrapper`/`wrapperClass`/`className`/`owner` | Match the wrapper/owner inferred from the function name (e.g. `"UserService"` in `"UserService.create"`). |
|
|
54
|
-
| `file` | Match the
|
|
54
|
+
| `file` | Match the filename reported by the trace event (callsite for wrapped calls; definition file for body-traced app functions). |
|
|
55
|
+
| `line` | Match the line number reported by the trace event. |
|
|
55
56
|
| `lib`/`library` | Match the npm package inferred from the file path (e.g. `"mongoose"`). |
|
|
56
57
|
| `type`/`functionType` | Match the detected function kind (e.g. `"constructor"`, `"method"`, `"arrow"`). |
|
|
57
58
|
| `event`/`eventType` | Match the trace phase (`"enter"` or `"exit"`) to suppress only specific edges of a call. |
|
|
@@ -94,7 +95,7 @@ function inputs/outputs before they are persisted.
|
|
|
94
95
|
### Rules
|
|
95
96
|
|
|
96
97
|
- `when.method` / `when.path` / `when.key` scope rules by endpoint (`key` is `"METHOD /path"` without query string).
|
|
97
|
-
- For function-specific rules, `when` supports the same fields as `disableFunctionTraces` (`fn`, `wrapperClass`, `file`, etc). This is useful when multiple functions share the same name.
|
|
98
|
+
- For function-specific rules, `when` supports the same fields as `disableFunctionTraces` (`fn`, `wrapperClass`, `file`, `line`, etc). This is useful when multiple functions share the same name.
|
|
98
99
|
- `paths` uses dot/bracket syntax and supports `*`, `[0]`, `[*]` (example: `"items[*].token"` or `"0.password"` for trace args arrays).
|
|
99
100
|
- `keys` masks matching key names anywhere in the payload (string/RegExp/array).
|
|
100
101
|
- `replacement` overrides the default replacement value (defaults to `"[REDACTED]"`).
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -229,7 +229,7 @@ let __TRACER__: TracerApi | null = null;
|
|
|
229
229
|
let __TRACER_READY = false;
|
|
230
230
|
|
|
231
231
|
type TraceEventPhase = 'enter' | 'exit';
|
|
232
|
-
export type TraceRulePattern = string | RegExp | Array<string | RegExp>;
|
|
232
|
+
export type TraceRulePattern = string | number | RegExp | Array<string | number | RegExp>;
|
|
233
233
|
|
|
234
234
|
export type TraceEventForFilter = {
|
|
235
235
|
type: TraceEventPhase; // legacy alias for eventType
|
|
@@ -238,6 +238,7 @@ export type TraceEventForFilter = {
|
|
|
238
238
|
fn?: string;
|
|
239
239
|
wrapperClass?: string | null;
|
|
240
240
|
file?: string | null;
|
|
241
|
+
line?: number | null;
|
|
241
242
|
depth?: number;
|
|
242
243
|
library?: string | null;
|
|
243
244
|
};
|
|
@@ -323,8 +324,10 @@ export type DisableFunctionTraceRule = {
|
|
|
323
324
|
className?: TraceRulePattern;
|
|
324
325
|
/** Alias for {@link wrapperClass}. */
|
|
325
326
|
owner?: TraceRulePattern;
|
|
326
|
-
/**
|
|
327
|
+
/** Source filename reported by the trace event. */
|
|
327
328
|
file?: TraceRulePattern;
|
|
329
|
+
/** Line number reported by the trace event. */
|
|
330
|
+
line?: TraceRulePattern;
|
|
328
331
|
/** Shortcut for {@link library}. */
|
|
329
332
|
lib?: TraceRulePattern;
|
|
330
333
|
/** Library/package name inferred from the file path (e.g. `"mongoose"`). */
|
|
@@ -409,8 +412,8 @@ function refreshDisabledFunctionTraceRules() {
|
|
|
409
412
|
}
|
|
410
413
|
|
|
411
414
|
let disabledFunctionTraceRules: DisableFunctionTraceConfig[] = computeDisabledFunctionTraceRules();
|
|
412
|
-
let disabledFunctionTypePatterns: Array<string | RegExp> = [];
|
|
413
|
-
let disabledTraceFilePatterns: Array<string | RegExp> = [];
|
|
415
|
+
let disabledFunctionTypePatterns: Array<string | number | RegExp> = [];
|
|
416
|
+
let disabledTraceFilePatterns: Array<string | number | RegExp> = [];
|
|
414
417
|
let __TRACE_LOG_PREF: boolean | null = null;
|
|
415
418
|
|
|
416
419
|
function setInterceptorTracingEnabled(enabled: boolean) {
|
|
@@ -489,6 +492,7 @@ function matchesRule(rule: DisableFunctionTraceRule, event: TraceEventForFilter)
|
|
|
489
492
|
if (!matchesPattern(event.wrapperClass, wrapperPattern)) return false;
|
|
490
493
|
|
|
491
494
|
if (!matchesPattern(event.file, rule.file)) return false;
|
|
495
|
+
if (!matchesPattern(event.line == null ? null : String(event.line), rule.line)) return false;
|
|
492
496
|
|
|
493
497
|
const libPattern = rule.lib ?? rule.library;
|
|
494
498
|
if (!matchesPattern(event.library, libPattern)) return false;
|
|
@@ -541,12 +545,12 @@ export function setDisabledFunctionTypes(patterns?: TraceRulePattern | null) {
|
|
|
541
545
|
disabledFunctionTypePatterns = normalizePatternArray(patterns);
|
|
542
546
|
}
|
|
543
547
|
|
|
544
|
-
function flattenTraceFilePatterns(config: DisableTraceFileConfig): Array<string | RegExp> {
|
|
548
|
+
function flattenTraceFilePatterns(config: DisableTraceFileConfig): Array<string | number | RegExp> {
|
|
545
549
|
if (config === null || config === undefined) return [];
|
|
546
550
|
if (Array.isArray(config)) {
|
|
547
551
|
return config.flatMap(entry => flattenTraceFilePatterns(entry));
|
|
548
552
|
}
|
|
549
|
-
if (config instanceof RegExp || typeof config === 'string') {
|
|
553
|
+
if (config instanceof RegExp || typeof config === 'string' || typeof config === 'number') {
|
|
550
554
|
return [config];
|
|
551
555
|
}
|
|
552
556
|
if (typeof config === 'object' && 'file' in config) {
|
|
@@ -1910,6 +1914,10 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1910
1914
|
unsubscribe = __TRACER__.tracer.on((ev: any) => {
|
|
1911
1915
|
if (!ev || ev.traceId !== tidNow) return;
|
|
1912
1916
|
|
|
1917
|
+
const sourceFileForLibrary = typeof ev.sourceFile === 'string' && ev.sourceFile
|
|
1918
|
+
? String(ev.sourceFile)
|
|
1919
|
+
: null;
|
|
1920
|
+
|
|
1913
1921
|
const evt: TraceEventRecord = {
|
|
1914
1922
|
t: alignTimestamp(ev.t),
|
|
1915
1923
|
type: ev.type,
|
|
@@ -1932,8 +1940,9 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
1932
1940
|
fn: evt.fn,
|
|
1933
1941
|
wrapperClass: inferWrapperClassFromFn(evt.fn),
|
|
1934
1942
|
file: evt.file ?? null,
|
|
1943
|
+
line: evt.line ?? null,
|
|
1935
1944
|
depth: evt.depth,
|
|
1936
|
-
library: inferLibraryNameFromFile(evt.file),
|
|
1945
|
+
library: inferLibraryNameFromFile(sourceFileForLibrary ?? evt.file),
|
|
1937
1946
|
};
|
|
1938
1947
|
|
|
1939
1948
|
if (ev.args !== undefined) {
|
|
@@ -2060,6 +2069,7 @@ export function reproMiddleware(cfg: ReproMiddlewareConfig) {
|
|
|
2060
2069
|
fn: chosenEndpoint.fn ?? undefined,
|
|
2061
2070
|
wrapperClass: inferWrapperClassFromFn(chosenEndpoint.fn),
|
|
2062
2071
|
file: chosenEndpoint.file ?? null,
|
|
2072
|
+
line: chosenEndpoint.line ?? null,
|
|
2063
2073
|
functionType: chosenEndpoint.functionType ?? null,
|
|
2064
2074
|
library: inferLibraryNameFromFile(chosenEndpoint.file),
|
|
2065
2075
|
};
|
package/tracer/runtime.js
CHANGED
|
@@ -128,6 +128,7 @@ const trace = {
|
|
|
128
128
|
fn,
|
|
129
129
|
file: meta?.file,
|
|
130
130
|
line: meta?.line,
|
|
131
|
+
sourceFile: meta?.sourceFile || null,
|
|
131
132
|
functionType: meta?.functionType || null,
|
|
132
133
|
traceId: ctx.traceId,
|
|
133
134
|
depth: ctx.depth,
|
|
@@ -144,6 +145,7 @@ const trace = {
|
|
|
144
145
|
fn: meta?.fn,
|
|
145
146
|
file: meta?.file,
|
|
146
147
|
line: meta?.line,
|
|
148
|
+
sourceFile: meta?.sourceFile || null,
|
|
147
149
|
functionType: meta?.functionType || null
|
|
148
150
|
};
|
|
149
151
|
const frameStack = ctx.__repro_frame_unawaited;
|
|
@@ -190,6 +192,7 @@ const trace = {
|
|
|
190
192
|
fn: baseMeta.fn,
|
|
191
193
|
file: baseMeta.file,
|
|
192
194
|
line: baseMeta.line,
|
|
195
|
+
sourceFile: baseMeta.sourceFile,
|
|
193
196
|
functionType: baseMeta.functionType || null,
|
|
194
197
|
traceId: traceIdAtExit,
|
|
195
198
|
depth: spanInfo.depth ?? depthAtExit,
|
|
@@ -601,10 +604,14 @@ if (!global.__repro_call) {
|
|
|
601
604
|
const name = (label && label.length) || fn.name
|
|
602
605
|
? (label && label.length ? label : fn.name)
|
|
603
606
|
: '(anonymous)';
|
|
604
|
-
const
|
|
607
|
+
const definitionFile = fn[SYM_SRC_FILE];
|
|
608
|
+
const normalizedCallFile = callFile ? String(callFile).trim() : '';
|
|
609
|
+
const callsiteFile = normalizedCallFile ? normalizedCallFile : null;
|
|
610
|
+
const callsiteLine = Number.isFinite(Number(callLine)) && Number(callLine) > 0 ? Number(callLine) : null;
|
|
605
611
|
const meta = {
|
|
606
|
-
file:
|
|
607
|
-
line:
|
|
612
|
+
file: callsiteFile || definitionFile || null,
|
|
613
|
+
line: callsiteLine,
|
|
614
|
+
sourceFile: definitionFile || null,
|
|
608
615
|
parentSpanId: forcedParentSpanId
|
|
609
616
|
};
|
|
610
617
|
|
|
@@ -638,7 +645,7 @@ if (!global.__repro_call) {
|
|
|
638
645
|
})();
|
|
639
646
|
|
|
640
647
|
const runExit = (detail) => {
|
|
641
|
-
const runner = () => trace.exit({ fn: name, file: meta.file, line: meta.line }, detail);
|
|
648
|
+
const runner = () => trace.exit({ fn: name, file: meta.file, line: meta.line, sourceFile: meta.sourceFile }, detail);
|
|
642
649
|
if (exitStore) return als.run(exitStore, runner);
|
|
643
650
|
return runner();
|
|
644
651
|
};
|
|
@@ -685,7 +692,7 @@ if (!global.__repro_call) {
|
|
|
685
692
|
runExit(exitDetailBase);
|
|
686
693
|
return out;
|
|
687
694
|
} catch (e) {
|
|
688
|
-
trace.exit({ fn: name, file: meta.file, line: meta.line }, { threw: true, error: e, args });
|
|
695
|
+
trace.exit({ fn: name, file: meta.file, line: meta.line, sourceFile: meta.sourceFile }, { threw: true, error: e, args });
|
|
689
696
|
throw e;
|
|
690
697
|
} finally {
|
|
691
698
|
if (pendingMarker) {
|