@ultimat3/core 31.6.1 → 31.7.0
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/CLAUDE.md +6 -2
- package/README.md +28 -2
- package/package.json +2 -2
- package/src/breaker-retry-budget.ts +48 -0
- package/src/config-cache.ts +30 -0
- package/src/config.ts +3 -12
- package/src/core-error-codes.ts +1 -0
- package/src/error-fingerprint.ts +28 -52
- package/src/error-reporter-sentry-hooks.ts +25 -9
- package/src/error-reporter-sentry.ts +22 -15
- package/src/exports/observability.ts +1 -1
- package/src/image/errors.ts +19 -0
- package/src/image/pipeline.ts +17 -136
- package/src/image/raster-pool.ts +185 -0
- package/src/image/raster-wire.ts +100 -0
- package/src/image/raster-worker-bundle.ts +85 -0
- package/src/image/raster-worker.ts +46 -0
- package/src/image/transform-inline.ts +169 -0
- package/src/index.ts +10 -1
- package/src/logger-redact.ts +222 -0
- package/src/logger.ts +99 -204
- package/src/map-bounded.ts +82 -0
- package/src/metric-series.ts +26 -3
- package/src/outbound.ts +9 -2
- package/src/retry-loop.ts +8 -0
- package/src/retry.ts +3 -0
- package/src/runtime-metrics.ts +33 -6
- package/src/sentry-frames.ts +175 -0
- package/src/type-pins.ts +10 -0
- package/src/visible-interval.ts +16 -6
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Single responsibility: a V8 stack string read as frames, once — the monitor's
|
|
2
|
+
// `exception.stacktrace.frames` and the fingerprint's application frame both parse it here. Total:
|
|
3
|
+
// it runs inside the catch of every failure path, on a string nobody validated.
|
|
4
|
+
|
|
5
|
+
/** A frame line longer than this is no frame: real ones are a name and a path, well under it. */
|
|
6
|
+
const MAX_LINE = 4096;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* What the regex's `.` refused besides `\n`. Its `\s` ADMITTED them, so only the name and the
|
|
10
|
+
* location may not hold one; a space run may (`at\r\tfn (a:1:1)` is a frame).
|
|
11
|
+
*/
|
|
12
|
+
const LINE_BREAK = /[\r\u2028\u2029]/;
|
|
13
|
+
|
|
14
|
+
const SPACE = /\s/;
|
|
15
|
+
|
|
16
|
+
/** A line and a column, or a line alone: split off the location's end. */
|
|
17
|
+
const POSITION = /:(\d+)(?::(\d+))?$/;
|
|
18
|
+
|
|
19
|
+
/** Library frames: the app's first frame names the fault, not the library under it. */
|
|
20
|
+
const LIBRARY = /(?:^|\/)(?:node_modules|@ultimat3)\//;
|
|
21
|
+
|
|
22
|
+
/** The protocol trims past this anyway; the frames KEPT are the newest, where the throw is. */
|
|
23
|
+
const MAX_FRAMES = 100;
|
|
24
|
+
|
|
25
|
+
export interface StackFrame {
|
|
26
|
+
/** `undefined` for an anonymous frame. `new ` and `async ` are not part of the name. */
|
|
27
|
+
readonly fn: string | undefined;
|
|
28
|
+
/** The location without `file://` or the position, `/` separators on every OS. */
|
|
29
|
+
readonly absPath: string;
|
|
30
|
+
/** `absPath` relative to the working directory, so two pods agree. */
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly line: number | undefined;
|
|
33
|
+
readonly column: number | undefined;
|
|
34
|
+
/** The app's own: a file location (a runtime's has no `/`), outside `node_modules`/`@ultimat3`. */
|
|
35
|
+
readonly inApp: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One `exception.stacktrace.frames` entry, the protocol's spelling. */
|
|
39
|
+
export interface SentryFrame {
|
|
40
|
+
readonly function?: string;
|
|
41
|
+
readonly filename: string;
|
|
42
|
+
readonly abs_path: string;
|
|
43
|
+
readonly lineno?: number;
|
|
44
|
+
readonly colno?: number;
|
|
45
|
+
readonly in_app: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function workingDirectory(): string | undefined {
|
|
49
|
+
try {
|
|
50
|
+
return `${process.cwd().replaceAll('\\', '/').replace(/\/$/, '')}/`;
|
|
51
|
+
} catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isSpace = (text: string, at: number): boolean => SPACE.test(text.charAt(at));
|
|
57
|
+
|
|
58
|
+
/** Past every space from `at`. */
|
|
59
|
+
function skipSpaces(text: string, at: number): number {
|
|
60
|
+
let index = at;
|
|
61
|
+
while (index < text.length && isSpace(text, index)) index += 1;
|
|
62
|
+
return index;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The index of the last line break in `text`, or -1. */
|
|
66
|
+
function lastBreakIn(text: string): number {
|
|
67
|
+
for (let index = text.length - 1; index >= 0; index -= 1) {
|
|
68
|
+
if (LINE_BREAK.test(text.charAt(index))) return index;
|
|
69
|
+
}
|
|
70
|
+
return -1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface FrameLine {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly location: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* ` at fn (path:1:2)`, ` at async fn (path:1:2)`, ` at path:1:2`, read in ONE pass — never
|
|
80
|
+
* a backtracking regex: the message above the frames is the thrower's text, and a line shaped to
|
|
81
|
+
* make `(.*?)\s+\(` backtrack is quadratic on the path that reports a failure.
|
|
82
|
+
*/
|
|
83
|
+
function parseFrameLine(line: string): FrameLine | undefined {
|
|
84
|
+
if (line.length > MAX_LINE) return undefined;
|
|
85
|
+
let index = skipSpaces(line, 0);
|
|
86
|
+
if (!line.startsWith('at', index) || !isSpace(line, index + 2)) return undefined;
|
|
87
|
+
index = skipSpaces(line, index + 2);
|
|
88
|
+
if (line.startsWith('async', index) && isSpace(line, index + 5)) {
|
|
89
|
+
index = skipSpaces(line, index + 5);
|
|
90
|
+
}
|
|
91
|
+
const rest = line.slice(index);
|
|
92
|
+
// `fn (location)`: the FIRST run of spaces followed by `(` whose name and location hold no line
|
|
93
|
+
// break — the regex's lazy `(.*?)` — with the location up to the closing `)`. The first and last
|
|
94
|
+
// break are found once, so each candidate is checked in constant time: one pass, as promised.
|
|
95
|
+
if (rest.endsWith(')')) {
|
|
96
|
+
const firstBreak = rest.search(LINE_BREAK);
|
|
97
|
+
const lastBreak = firstBreak === -1 ? -1 : lastBreakIn(rest);
|
|
98
|
+
let runStart = -1;
|
|
99
|
+
for (let at = 0; at < rest.length - 1; at += 1) {
|
|
100
|
+
if (isSpace(rest, at)) {
|
|
101
|
+
if (runStart === -1) runStart = at;
|
|
102
|
+
} else if (rest.charAt(at) === '(' && runStart !== -1) {
|
|
103
|
+
// A break in the name is in every later name too: no candidate after this one can match.
|
|
104
|
+
if (firstBreak !== -1 && firstBreak < runStart) break;
|
|
105
|
+
if (lastBreak < at)
|
|
106
|
+
return { name: rest.slice(0, runStart), location: rest.slice(at + 1, -1) };
|
|
107
|
+
runStart = -1;
|
|
108
|
+
} else {
|
|
109
|
+
runStart = -1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return LINE_BREAK.test(rest) ? undefined : { name: '', location: rest };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function frameOf(frame: FrameLine, root: string | undefined): StackFrame {
|
|
117
|
+
const location = frame.location.trim();
|
|
118
|
+
const position = POSITION.exec(location);
|
|
119
|
+
let absPath = (position === null ? location : location.slice(0, position.index)).replaceAll(
|
|
120
|
+
'\\',
|
|
121
|
+
'/',
|
|
122
|
+
);
|
|
123
|
+
if (absPath.startsWith('file://')) absPath = absPath.slice('file://'.length);
|
|
124
|
+
let path = absPath;
|
|
125
|
+
if (root !== undefined && path.startsWith(root)) path = path.slice(root.length);
|
|
126
|
+
path = path.replace(/^\.\//, '');
|
|
127
|
+
const name = frame.name.replace(/^new\s+/, '').trim();
|
|
128
|
+
return {
|
|
129
|
+
fn: name === '' ? undefined : name,
|
|
130
|
+
absPath,
|
|
131
|
+
path,
|
|
132
|
+
line: position === null ? undefined : Number(position[1]),
|
|
133
|
+
column: position?.[2] === undefined ? undefined : Number(position[2]),
|
|
134
|
+
// The ABSOLUTE location has the `/`: a runtime's (`native`) never does, and a file at the app
|
|
135
|
+
// root (`server.ts`) has none left once the working directory is cut off.
|
|
136
|
+
inApp: position !== null && absPath.includes('/') && path !== '' && !LIBRARY.test(path),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The stack's frames, NEWEST first (the order V8 prints): the trailing run of `at …` lines. Read
|
|
142
|
+
* from the end, because the header above them is the error's message, and a message may itself
|
|
143
|
+
* hold `\n at x (y:1:1)` — read top-down, its author would choose the frames.
|
|
144
|
+
*/
|
|
145
|
+
export function stackFrames(stack: string): readonly StackFrame[] {
|
|
146
|
+
const root = workingDirectory();
|
|
147
|
+
const frames: StackFrame[] = [];
|
|
148
|
+
const lines = stack.trimEnd().split('\n');
|
|
149
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
150
|
+
const frame = parseFrameLine(lines[index] ?? '');
|
|
151
|
+
if (frame === undefined) break;
|
|
152
|
+
frames.push(frameOf(frame, root));
|
|
153
|
+
}
|
|
154
|
+
// Collected oldest first; the newest MAX_FRAMES are the ones that name the throw.
|
|
155
|
+
return frames.slice(-MAX_FRAMES).reverse();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** `stack` as the monitor's frames, OLDEST first as the protocol orders them; `[]`, never a throw. */
|
|
159
|
+
export function sentryFrames(stack: unknown): readonly SentryFrame[] {
|
|
160
|
+
if (typeof stack !== 'string') return [];
|
|
161
|
+
try {
|
|
162
|
+
return stackFrames(stack)
|
|
163
|
+
.map((frame) => ({
|
|
164
|
+
...(frame.fn === undefined ? {} : { function: frame.fn }),
|
|
165
|
+
filename: frame.path,
|
|
166
|
+
abs_path: frame.absPath,
|
|
167
|
+
...(frame.line === undefined ? {} : { lineno: frame.line }),
|
|
168
|
+
...(frame.column === undefined ? {} : { colno: frame.column }),
|
|
169
|
+
in_app: frame.inApp,
|
|
170
|
+
}))
|
|
171
|
+
.reverse();
|
|
172
|
+
} catch {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
}
|
package/src/type-pins.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
import type { CtxPatch } from './context';
|
|
18
18
|
import type { Page } from './cursor-page';
|
|
19
19
|
import type { ErrorReporter, ErrorReportingOptions } from './error-reporter';
|
|
20
|
+
import type { SentryReporterHooks, SentryReporterOptions } from './error-reporter-sentry-hooks';
|
|
20
21
|
import type { HydrateStrategy, OfflineStrategy, RenderMode, Surface } from './route-vocabulary';
|
|
21
22
|
|
|
22
23
|
/** Fails to compile when `T` is anything but `true`. The whole mechanism. */
|
|
@@ -272,3 +273,12 @@ export type _LastPageHasNoCursor = Assert<
|
|
|
272
273
|
type _NoReporterOption = Assert<
|
|
273
274
|
{ readonly reporter: ErrorReporter } extends ErrorReportingOptions ? false : true
|
|
274
275
|
>;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* `SentryReporterHooks` is the name the hooks shipped under (31.0): a typed hooks object must still
|
|
279
|
+
* spread into the options beside the wiring, or an app that kept its hooks apart stops compiling.
|
|
280
|
+
*/
|
|
281
|
+
export const _HooksSpreadIntoOptions = (hooks: SentryReporterHooks): SentryReporterOptions => ({
|
|
282
|
+
dsn: 'https://public@o0.ingest.sentry.io/0',
|
|
283
|
+
...hooks,
|
|
284
|
+
});
|
package/src/visible-interval.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface VisibleIntervalOptions {
|
|
|
12
12
|
/**
|
|
13
13
|
* Back off on failure: each failed run (a throw or a rejection) doubles the wait from `ms` up to
|
|
14
14
|
* `maxMs`, with equal jitter so a fleet of tabs does not ask in lockstep; a success resets it to
|
|
15
|
-
* `ms`.
|
|
15
|
+
* `ms`. Default `8 × ms`; `maxMs: ms` opts out, and every wait is `ms`, failed or not.
|
|
16
16
|
*/
|
|
17
17
|
readonly maxMs?: number | undefined;
|
|
18
18
|
}
|
|
@@ -29,12 +29,19 @@ export interface IntervalHost {
|
|
|
29
29
|
|
|
30
30
|
const SUBJECT = 'visibleInterval';
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The default failure ceiling, as a multiple of `ms`. A default of `ms` itself (no back-off unless
|
|
34
|
+
* asked) meant every open tab polled a failing endpoint at its full healthy rate, which is the
|
|
35
|
+
* load a partial outage least needs; 8 is three doublings, so a recovery is seen within `8 × ms`.
|
|
36
|
+
*/
|
|
37
|
+
const FAILURE_BACKOFF_FACTOR = 8;
|
|
38
|
+
|
|
32
39
|
/**
|
|
33
40
|
* Call `run` every `ms` while the tab is shown. Hidden: no call; one make-up call when shown. An
|
|
34
41
|
* async `run` is never overlapped — the next wait starts when it settles; a throw or rejection is
|
|
35
|
-
* re-raised for the page's error hook.
|
|
36
|
-
* Stops on a session loss; starts afresh when a principal next signs in. Returns
|
|
37
|
-
* disposer.
|
|
42
|
+
* re-raised for the page's error hook. Failures back off to `maxMs` (default `8 × ms`); a
|
|
43
|
+
* success resets. Stops on a session loss; starts afresh when a principal next signs in. Returns
|
|
44
|
+
* an idempotent disposer.
|
|
38
45
|
*/
|
|
39
46
|
export function visibleInterval(
|
|
40
47
|
run: () => unknown,
|
|
@@ -52,8 +59,11 @@ export function visibleIntervalOn(
|
|
|
52
59
|
options: VisibleIntervalOptions = {},
|
|
53
60
|
): () => void {
|
|
54
61
|
const base = clampTimer(finiteOption(SUBJECT, 'ms', ms));
|
|
55
|
-
const max =
|
|
56
|
-
options.maxMs === undefined
|
|
62
|
+
const max = clampTimer(
|
|
63
|
+
options.maxMs === undefined
|
|
64
|
+
? base * FAILURE_BACKOFF_FACTOR
|
|
65
|
+
: finiteOption(SUBJECT, 'maxMs', options.maxMs),
|
|
66
|
+
);
|
|
57
67
|
// Stopped by a session loss, started afresh — attempt 1 — by the next signed-in principal.
|
|
58
68
|
return whileSessionHeld(() => runLoop(host, run, base, max));
|
|
59
69
|
}
|