@ultimat3/core 30.9.0 → 31.0.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 +54 -58
- package/README.md +70 -27
- package/package.json +3 -2
- package/src/adapter-slot.ts +42 -0
- package/src/adapter.ts +24 -0
- package/src/audit.ts +31 -14
- package/src/aws-sigv4.ts +9 -3
- package/src/cache-vocabulary.ts +1 -1
- package/src/client-problem.ts +10 -3
- package/src/clock.ts +68 -14
- package/src/config-defaults.ts +4 -4
- package/src/config-keys.ts +1 -1
- package/src/config-removed.ts +11 -1
- package/src/config.ts +16 -20
- package/src/context.ts +2 -2
- package/src/cursor.ts +3 -11
- package/src/der.ts +65 -0
- package/src/error-render.ts +27 -1
- package/src/error-reporter-chain.ts +1 -1
- package/src/error-reporter-sentry-hooks.ts +85 -0
- package/src/error-reporter-sentry.ts +99 -7
- package/src/error-reporter.ts +39 -11
- package/src/errors.ts +3 -1
- package/src/exports/error-contract.ts +4 -14
- package/src/exports/observability.ts +57 -17
- package/src/exports/secrets.ts +4 -18
- package/src/failure-capture.ts +22 -13
- package/src/gate-shapes.ts +88 -0
- package/src/host-rules.ts +13 -1
- package/src/html-escape.ts +7 -1
- package/src/ids.ts +59 -10
- package/src/image/png-pixels.ts +14 -8
- package/src/index.ts +123 -136
- package/src/instrument-events.ts +272 -0
- package/src/instrument-semconv.ts +65 -0
- package/src/instrument-stacks.ts +38 -0
- package/src/instrument.ts +194 -0
- package/src/keyed-fingerprint.ts +7 -11
- package/src/lifecycle-signals.ts +5 -3
- package/src/lifecycle.ts +27 -0
- package/src/logger-record.ts +35 -0
- package/src/logger.ts +24 -16
- package/src/mcp-exposure.ts +17 -0
- package/src/metrics-semconv.ts +124 -0
- package/src/metrics.ts +19 -16
- package/src/otlp-batch.ts +78 -0
- package/src/otlp-log-exporter.ts +180 -0
- package/src/otlp-metric-exporter.ts +2 -1
- package/src/otlp-post.ts +22 -2
- package/src/otlp-span-exporter.ts +10 -59
- package/src/otlp.ts +27 -9
- package/src/outbound-instrument.ts +82 -0
- package/src/outbound.ts +5 -4
- package/src/page-meta.ts +6 -0
- package/src/page.ts +23 -5
- package/src/registrar.ts +269 -0
- package/src/route-vocabulary.ts +11 -2
- package/src/safe-url.ts +10 -8
- package/src/seal-errors.ts +14 -4
- package/src/seal-keys.ts +11 -7
- package/src/secret-source.ts +125 -0
- package/src/secrets-errors.ts +32 -12
- package/src/secrets-store.ts +30 -26
- package/src/sleep-clock.ts +70 -0
- package/src/telemetry.ts +90 -31
- package/src/type-pins.ts +19 -16
- package/src/log-tee.ts +0 -73
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Single responsibility: the adopter's say over what the Sentry transport sends — drop by code,
|
|
2
|
+
// sample, regroup, scrub. Functions of the report or the event, decided per report; the envelope
|
|
3
|
+
// format stays `error-reporter-sentry.ts`'s alone.
|
|
4
|
+
|
|
5
|
+
import { renderThrowable } from './error-render';
|
|
6
|
+
import type { ErrorReport } from './error-reporter';
|
|
7
|
+
import { ConfigInvalidError } from './errors';
|
|
8
|
+
import { logger } from './logger';
|
|
9
|
+
|
|
10
|
+
/** The event payload as the envelope will carry it: the third line, before serialisation. */
|
|
11
|
+
export type SentryEvent = Readonly<Record<string, unknown>>;
|
|
12
|
+
|
|
13
|
+
export interface SentryReporterHooks {
|
|
14
|
+
/**
|
|
15
|
+
* The last word on an event: return it (changed or not) to send, `null` to drop. Scrub by VALUE
|
|
16
|
+
* here — `redactFields` already masked by key. A hook that throws drops the event: an event the
|
|
17
|
+
* scrubber failed on is exactly the one that must not leave unscrubbed.
|
|
18
|
+
*/
|
|
19
|
+
readonly beforeSend?: ((event: SentryEvent) => SentryEvent | null) | undefined;
|
|
20
|
+
/** `true` drops every report with this code, before the event is even built. */
|
|
21
|
+
readonly ignore?: ((code: string) => boolean) | undefined;
|
|
22
|
+
/** The monitor's grouping, replacing `errorFingerprint`'s one-element default. */
|
|
23
|
+
readonly fingerprint?: ((report: ErrorReport) => readonly string[]) | undefined;
|
|
24
|
+
/** The share of reports sent, `0..1` inclusive. Default 1: every report. */
|
|
25
|
+
readonly sampleRate?: number | undefined;
|
|
26
|
+
/** `[0, 1)`, the sampling roll. Injected by tests; default `Math.random`. */
|
|
27
|
+
readonly random?: (() => number) | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Refused at wiring time, like the DSN: a rate past 1 or below 0 is a monitor nobody configured. */
|
|
31
|
+
export function screenSampleRate(rate: number | undefined): number {
|
|
32
|
+
if (rate === undefined) return 1;
|
|
33
|
+
if (Number.isFinite(rate) && rate >= 0 && rate <= 1) return rate;
|
|
34
|
+
throw new ConfigInvalidError({
|
|
35
|
+
cause: `sentryErrorReporter sampleRate is ${String(rate)}; it is the share of reports sent, from 0 to 1`,
|
|
36
|
+
fix: 'sentryErrorReporter({ dsn, sampleRate: 0.25 }) # 0..1 inclusive, or omit it to send every report',
|
|
37
|
+
meta: { sampleRate: rate },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Calls an adopter's hook without letting it throw into `report()`, which runs inside the catch
|
|
43
|
+
* blocks of every failure path. A throwing filter or grouping falls back to the default.
|
|
44
|
+
*/
|
|
45
|
+
function guarded<T>(hook: string, run: () => T, fallback: T): T {
|
|
46
|
+
try {
|
|
47
|
+
return run();
|
|
48
|
+
} catch (thrown) {
|
|
49
|
+
logger.warn(`error reporter ${hook} threw; the default was used`, {
|
|
50
|
+
error: renderThrowable(thrown),
|
|
51
|
+
});
|
|
52
|
+
return fallback;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Whether this report is sent at all: the code filter first, then the roll. */
|
|
57
|
+
export function admitted(report: ErrorReport, hooks: SentryReporterHooks, rate: number): boolean {
|
|
58
|
+
const { ignore } = hooks;
|
|
59
|
+
if (ignore !== undefined && guarded('ignore', () => ignore(report.code), false)) return false;
|
|
60
|
+
if (rate >= 1) return true;
|
|
61
|
+
return (hooks.random ?? Math.random)() < rate;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The adopter's grouping, or `undefined` for the default one. */
|
|
65
|
+
export function customFingerprint(
|
|
66
|
+
report: ErrorReport,
|
|
67
|
+
hooks: SentryReporterHooks,
|
|
68
|
+
): readonly string[] | undefined {
|
|
69
|
+
const { fingerprint } = hooks;
|
|
70
|
+
if (fingerprint === undefined) return undefined;
|
|
71
|
+
return guarded('fingerprint', () => [...fingerprint(report)], undefined);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `beforeSend`'s verdict, total: a throwing hook is a dropped event and one warn line. */
|
|
75
|
+
export function finalEvent(event: SentryEvent, hooks: SentryReporterHooks): SentryEvent | null {
|
|
76
|
+
if (hooks.beforeSend === undefined) return event;
|
|
77
|
+
try {
|
|
78
|
+
return hooks.beforeSend(event);
|
|
79
|
+
} catch (thrown) {
|
|
80
|
+
logger.warn('error reporter beforeSend threw; the event was dropped', {
|
|
81
|
+
error: renderThrowable(thrown),
|
|
82
|
+
});
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
import { errorFingerprint } from './error-fingerprint';
|
|
7
7
|
import { renderThrowable } from './error-render';
|
|
8
8
|
import type { ErrorReport, ErrorReporter, ErrorSeverity } from './error-reporter';
|
|
9
|
+
import {
|
|
10
|
+
admitted,
|
|
11
|
+
customFingerprint,
|
|
12
|
+
finalEvent,
|
|
13
|
+
type SentryEvent,
|
|
14
|
+
type SentryReporterHooks,
|
|
15
|
+
screenSampleRate,
|
|
16
|
+
} from './error-reporter-sentry-hooks';
|
|
9
17
|
import { type CodedErrorInit, UltimateError } from './errors';
|
|
10
18
|
import { traceId } from './ids';
|
|
11
19
|
import { logger, redactFields } from './logger';
|
|
@@ -75,9 +83,20 @@ export interface SentryEnvelopeOptions {
|
|
|
75
83
|
readonly dsn: string;
|
|
76
84
|
/** 32 lowercase hex, no dashes. `traceId()` already produces exactly that shape. */
|
|
77
85
|
readonly eventId: string;
|
|
86
|
+
/** The monitor's grouping. Default: `[errorFingerprint(report)]`. */
|
|
87
|
+
readonly fingerprint?: readonly string[] | undefined;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
|
-
|
|
90
|
+
/** The event an envelope carries, before `beforeSend` and serialisation. Pure. */
|
|
91
|
+
export function sentryEvent(report: ErrorReport, options: SentryEnvelopeOptions): SentryEvent {
|
|
92
|
+
return payloadOf(report, options.eventId, options.fingerprint);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function payloadOf(
|
|
96
|
+
report: ErrorReport,
|
|
97
|
+
eventId: string,
|
|
98
|
+
fingerprint: readonly string[] | undefined,
|
|
99
|
+
): Record<string, unknown> {
|
|
81
100
|
return {
|
|
82
101
|
event_id: eventId,
|
|
83
102
|
// Seconds, as the protocol spells a timestamp. `new Date` here converts a number the caller
|
|
@@ -92,7 +111,7 @@ function payloadOf(report: ErrorReport, eventId: string): Record<string, unknown
|
|
|
92
111
|
...(report.scope.operation === undefined ? {} : { transaction: report.scope.operation }),
|
|
93
112
|
// The group. Without it the monitor groups on its own reading of the exception, which is the
|
|
94
113
|
// code, so every unclassified throw in the app was one issue (`errorFingerprint`).
|
|
95
|
-
fingerprint: [errorFingerprint(report)],
|
|
114
|
+
fingerprint: fingerprint ?? [errorFingerprint(report)],
|
|
96
115
|
// Tags are the monitor's facets, so only bounded values go here — the same rule metric labels
|
|
97
116
|
// follow. `requestId` and `actorId` are unbounded and live in `extra`.
|
|
98
117
|
tags: {
|
|
@@ -132,10 +151,15 @@ function payloadOf(report: ErrorReport, eventId: string): Record<string, unknown
|
|
|
132
151
|
|
|
133
152
|
/** Pure, so the wire format is a unit test rather than a thing discovered in production. */
|
|
134
153
|
export function sentryEnvelope(report: ErrorReport, options: SentryEnvelopeOptions): string {
|
|
135
|
-
|
|
154
|
+
return envelopeOf(sentryEvent(report, options), options, report.at);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The three lines around one event. The item `length` is measured off THIS payload. */
|
|
158
|
+
function envelopeOf(event: SentryEvent, options: SentryEnvelopeOptions, at: number): string {
|
|
159
|
+
const payload = JSON.stringify(event);
|
|
136
160
|
const header = JSON.stringify({
|
|
137
161
|
event_id: options.eventId,
|
|
138
|
-
sent_at: new Date(
|
|
162
|
+
sent_at: new Date(at).toISOString(),
|
|
139
163
|
dsn: options.dsn,
|
|
140
164
|
});
|
|
141
165
|
const item = JSON.stringify({
|
|
@@ -146,7 +170,7 @@ export function sentryEnvelope(report: ErrorReport, options: SentryEnvelopeOptio
|
|
|
146
170
|
return `${header}\n${item}\n${payload}\n`;
|
|
147
171
|
}
|
|
148
172
|
|
|
149
|
-
export interface SentryReporterOptions {
|
|
173
|
+
export interface SentryReporterOptions extends SentryReporterHooks {
|
|
150
174
|
/** From the app's typed env. The framework declares no default and ships no constant. */
|
|
151
175
|
readonly dsn: string;
|
|
152
176
|
/** Injected by tests; the preload seals the real one. */
|
|
@@ -154,18 +178,84 @@ export interface SentryReporterOptions {
|
|
|
154
178
|
readonly clientName?: string | undefined;
|
|
155
179
|
}
|
|
156
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Every reporter that is an app's Sentry transport: built by `sentryErrorReporter`, or marked by
|
|
183
|
+
* `sentryTransport`. Identity, never shape: a reporter is `{ report }`, and the boot must tell an
|
|
184
|
+
* app's own transport from its `errorGroupsSink` exactly.
|
|
185
|
+
*/
|
|
186
|
+
const built = new WeakSet<ErrorReporter>();
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Whether `reporter` is the app's Sentry transport — built by `sentryErrorReporter` or marked by
|
|
190
|
+
* `sentryTransport` — not a chain holding one (`errorReportersOf` flattens a chain to ask its
|
|
191
|
+
* members). The `SENTRY_DSN` boot asks it so an app's transport is the only one, never doubled.
|
|
192
|
+
*/
|
|
193
|
+
export function isSentryErrorReporter(reporter: ErrorReporter): boolean {
|
|
194
|
+
return built.has(reporter);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The one way to WRAP the Sentry transport: `sentryTransport({ report: (r) => inner.report(tag(r)) })`.
|
|
199
|
+
* Marks `reporter` as the app's Sentry transport and returns it, so a boot with `SENTRY_DSN` set
|
|
200
|
+
* adds no second, unscrubbed one beside it — a wrapper is `{ report }` and could be anything else.
|
|
201
|
+
*/
|
|
202
|
+
export function sentryTransport<R extends ErrorReporter>(reporter: R): R {
|
|
203
|
+
built.add(reporter);
|
|
204
|
+
return reporter;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Every reporter marked by `localErrorSink`: its reports stay on the box. */
|
|
208
|
+
const local = new WeakSet<ErrorReporter>();
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Marks `reporter` as a LOCAL sink — it keeps reports on the box (a table, memory, the log) and
|
|
212
|
+
* sends nothing to a monitor — and returns it. The `SENTRY_DSN` boot still adds its transport
|
|
213
|
+
* beside reporters that are all local sinks; an unmarked one might be a transport, so it does not.
|
|
214
|
+
* The framework's own are marked: `memoryErrorReporter`, `@ultimat3/admin`'s `errorGroupsSink`.
|
|
215
|
+
*/
|
|
216
|
+
export function localErrorSink<R extends ErrorReporter>(reporter: R): R {
|
|
217
|
+
local.add(reporter);
|
|
218
|
+
return reporter;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Whether `localErrorSink` marked `reporter` — a single reporter, never a chain. */
|
|
222
|
+
export function isLocalErrorSink(reporter: ErrorReporter): boolean {
|
|
223
|
+
return local.has(reporter);
|
|
224
|
+
}
|
|
225
|
+
|
|
157
226
|
/**
|
|
158
227
|
* Fire-and-forget on purpose. A report is not the request, and awaiting the monitor would add its
|
|
159
228
|
* latency — and its outages — to every failure the app already knows how to answer.
|
|
160
229
|
*/
|
|
161
230
|
export function sentryErrorReporter(options: SentryReporterOptions): ErrorReporter {
|
|
162
231
|
const dsn = parseSentryDsn(options.dsn);
|
|
232
|
+
const rate = screenSampleRate(options.sampleRate);
|
|
163
233
|
const send = options.fetch ?? globalThis.fetch;
|
|
164
234
|
const client = options.clientName ?? 'ultimate';
|
|
165
235
|
const auth = `Sentry sentry_version=7, sentry_client=${client}, sentry_key=${dsn.publicKey}`;
|
|
166
|
-
|
|
236
|
+
const reporter: ErrorReporter = {
|
|
167
237
|
report(report: ErrorReport): void {
|
|
168
|
-
|
|
238
|
+
if (!admitted(report, options, rate)) return;
|
|
239
|
+
const envelope = {
|
|
240
|
+
dsn: options.dsn,
|
|
241
|
+
eventId: traceId(),
|
|
242
|
+
fingerprint: customFingerprint(report, options),
|
|
243
|
+
};
|
|
244
|
+
const event = finalEvent(sentryEvent(report, envelope), options);
|
|
245
|
+
if (event === null) return;
|
|
246
|
+
// The event may now hold a hook's value — `beforeSend`'s rewrite, `fingerprint`'s list — and
|
|
247
|
+
// a `bigint` or a cycle there throws in `JSON.stringify`. `report()` runs inside every failure
|
|
248
|
+
// path's catch, so that is a dropped event and a warn line, never a second throw.
|
|
249
|
+
let body: string;
|
|
250
|
+
try {
|
|
251
|
+
body = envelopeOf(event, envelope, report.at);
|
|
252
|
+
} catch (thrown) {
|
|
253
|
+
logger.warn('error reporter event could not be serialised; the event was dropped', {
|
|
254
|
+
code: report.code,
|
|
255
|
+
error: renderThrowable(thrown),
|
|
256
|
+
});
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
169
259
|
void send(dsn.envelopeUrl, {
|
|
170
260
|
method: 'POST',
|
|
171
261
|
headers: { 'content-type': 'application/x-sentry-envelope', 'x-sentry-auth': auth },
|
|
@@ -180,4 +270,6 @@ export function sentryErrorReporter(options: SentryReporterOptions): ErrorReport
|
|
|
180
270
|
});
|
|
181
271
|
},
|
|
182
272
|
};
|
|
273
|
+
built.add(reporter);
|
|
274
|
+
return reporter;
|
|
183
275
|
}
|
package/src/error-reporter.ts
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
// driver by default, and the wire format supplied by a transport, never here. The framework names
|
|
4
4
|
// no vendor (axiom 7); a transport takes its endpoint from the app's typed env.
|
|
5
5
|
|
|
6
|
+
import { adapterSlot } from './adapter-slot';
|
|
6
7
|
import { type Clock, systemClock } from './clock';
|
|
7
8
|
import { tryUseContext } from './context';
|
|
8
9
|
import { DEFAULT_ENVIRONMENT, type Environment, tryResolveEnvironment } from './environment';
|
|
9
10
|
import { renderThrowable } from './error-render';
|
|
11
|
+
import { localErrorSink } from './error-reporter-sentry';
|
|
10
12
|
import { failureStack } from './error-stack';
|
|
11
|
-
import { toUltimateError } from './errors';
|
|
13
|
+
import { ConfigInvalidError, toUltimateError } from './errors';
|
|
12
14
|
import { releaseHeldFailure } from './failure-capture-flush';
|
|
13
15
|
import { logger } from './logger';
|
|
14
16
|
import type { Role } from './roles';
|
|
@@ -82,7 +84,8 @@ export interface MemoryErrorReporter extends ErrorReporter {
|
|
|
82
84
|
/** For tests, and for a `x dev` process that shows its own failures without leaving the box. */
|
|
83
85
|
export function memoryErrorReporter(): MemoryErrorReporter {
|
|
84
86
|
const events: ErrorReport[] = [];
|
|
85
|
-
|
|
87
|
+
// Local: what it holds never leaves the process, so a boot with `SENTRY_DSN` still adds its own.
|
|
88
|
+
return localErrorSink({
|
|
86
89
|
events,
|
|
87
90
|
report(event: ErrorReport): void {
|
|
88
91
|
events.push(event);
|
|
@@ -90,11 +93,16 @@ export function memoryErrorReporter(): MemoryErrorReporter {
|
|
|
90
93
|
reset(): void {
|
|
91
94
|
events.length = 0;
|
|
92
95
|
},
|
|
93
|
-
};
|
|
96
|
+
});
|
|
94
97
|
}
|
|
95
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The settings around the port — never the reporter itself: that is the `errorReporter` port's,
|
|
101
|
+
* installed by the boot from `runtime.ts` through `installErrorReporter` (`@ultimat3/core/adapter`).
|
|
102
|
+
*/
|
|
96
103
|
export interface ErrorReportingOptions {
|
|
97
|
-
|
|
104
|
+
/** Removed in 31.0.0: `runtime.ts`'s `errorReporter` field, or `installErrorReporter` in a boot. */
|
|
105
|
+
readonly reporter?: never;
|
|
98
106
|
readonly clock?: Clock | undefined;
|
|
99
107
|
/** The deploy's build id. `serve.ts` passes the one it already computed; never a second one. */
|
|
100
108
|
readonly release?: string | null | undefined;
|
|
@@ -102,31 +110,51 @@ export interface ErrorReportingOptions {
|
|
|
102
110
|
readonly enabled?: boolean | undefined;
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
/** Core's one slot shape: installs stack, each release removes its own frame (`adapter-slot.ts`). */
|
|
114
|
+
const reporters = /* @__PURE__ */ adapterSlot<ErrorReporter>(() => noopErrorReporter);
|
|
106
115
|
let clock: Clock = systemClock;
|
|
107
116
|
let release: string | null = null;
|
|
108
117
|
let environment: Environment | undefined;
|
|
109
118
|
let enabled = true;
|
|
110
119
|
|
|
111
120
|
export function configureErrorReporting(options: ErrorReportingOptions): void {
|
|
112
|
-
|
|
121
|
+
// `never` stops a typed caller; this stops the rest (a `.js` module, a cast) — ignored, its
|
|
122
|
+
// reporter would never hear a report and nothing would say so.
|
|
123
|
+
if (Object.hasOwn(options, 'reporter')) {
|
|
124
|
+
throw new ConfigInvalidError({
|
|
125
|
+
cause:
|
|
126
|
+
'configureErrorReporting({ reporter }) was removed in 31.0.0: the reporter is the errorReporter port, and a reporter passed here would never receive a report',
|
|
127
|
+
fix: 'errorReporter: sentryErrorReporter({ dsn }) # your reporter, in export const runtime = { … }, apps/<app>/runtime.ts — or installErrorReporter(reporter) from @ultimat3/core/adapter in a test',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
113
130
|
if (options.clock !== undefined) clock = options.clock;
|
|
114
131
|
if (options.release !== undefined) release = options.release;
|
|
115
132
|
if (options.environment !== undefined) environment = options.environment;
|
|
116
133
|
if (options.enabled !== undefined) enabled = options.enabled;
|
|
117
134
|
}
|
|
118
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The `errorReporter` port's installer — on `@ultimat3/core/adapter` only. The boot installs
|
|
138
|
+
* `runtime.ts`'s reporter before `loadApp`, then its `SENTRY_DSN` transport as a frame above it
|
|
139
|
+
* that chains whatever is installed (`@ultimat3/cli`'s `configureReporting`). Answers the release
|
|
140
|
+
* that removes THIS install and no other, in any order.
|
|
141
|
+
*/
|
|
142
|
+
export function installErrorReporter(next: ErrorReporter): () => void {
|
|
143
|
+
return reporters.install(next);
|
|
144
|
+
}
|
|
145
|
+
|
|
119
146
|
/**
|
|
120
147
|
* The reporter installed now. Read by a boot that adds its own (`@ultimat3/cli`'s `SENTRY_DSN`
|
|
121
|
-
* transport) so it composes with
|
|
122
|
-
* replacing it —
|
|
148
|
+
* transport) so it composes with the app's reporter through `chainErrorReporters` instead of
|
|
149
|
+
* replacing it — `runtime.ts`'s `errorReporter` is installed before that boot line runs.
|
|
123
150
|
*/
|
|
124
151
|
export function installedErrorReporter(): ErrorReporter {
|
|
125
|
-
return
|
|
152
|
+
return reporters.current();
|
|
126
153
|
}
|
|
127
154
|
|
|
155
|
+
/** Test seam: every install dropped and every setting back to its default. */
|
|
128
156
|
export function resetErrorReporting(): void {
|
|
129
|
-
|
|
157
|
+
reporters.reset();
|
|
130
158
|
clock = systemClock;
|
|
131
159
|
release = null;
|
|
132
160
|
environment = undefined;
|
|
@@ -213,7 +241,7 @@ export function reportError(error: unknown, options: ReportErrorOptions): void {
|
|
|
213
241
|
releaseHeldFailure(error, () => errorReport(error, options));
|
|
214
242
|
if (!enabled) return;
|
|
215
243
|
try {
|
|
216
|
-
|
|
244
|
+
reporters.current().report(errorReport(error, options));
|
|
217
245
|
} catch (failure) {
|
|
218
246
|
logger.warn('error reporter failed', {
|
|
219
247
|
source: options.source,
|
package/src/errors.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { ULTIMATE_ERROR_BRAND } from '@ultimat3/schema';
|
|
12
12
|
import { describeErrorCode, hasErrorCode } from './error-codes';
|
|
13
13
|
import {
|
|
14
|
+
boundedCause,
|
|
14
15
|
isThrownError,
|
|
15
16
|
renderCauseValue,
|
|
16
17
|
renderMetaRecord,
|
|
@@ -121,7 +122,8 @@ export class UltimateError extends Error {
|
|
|
121
122
|
const code = singleLine(init.code);
|
|
122
123
|
const remote = init.remoteTitle !== undefined && !hasErrorCode(init.code);
|
|
123
124
|
const title = singleLine(remote ? (init.remoteTitle ?? described.title) : described.title);
|
|
124
|
-
|
|
125
|
+
// Bounded after escaping: the cap is on what is WRITTEN, and an escape only ever grows it.
|
|
126
|
+
const cause = boundedCause(singleLine(init.cause));
|
|
125
127
|
// `message` carries the cause because it is the ONLY field a runtime prints when an
|
|
126
128
|
// error escapes uncaught — a worker log, a CI transcript, a stack trace. A message of
|
|
127
129
|
// just `code: title` tells an operator which rule fired but not which row, column or
|
|
@@ -5,18 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
export type { CoreErrorCode } from '../core-error-codes';
|
|
7
7
|
export { CORE_ERROR_CODES } from '../core-error-codes';
|
|
8
|
-
export type {
|
|
9
|
-
DefinedError,
|
|
10
|
-
DefinedErrorExtra,
|
|
11
|
-
DefineErrorSpec,
|
|
12
|
-
ErrorText,
|
|
13
|
-
} from '../define-error';
|
|
8
|
+
export type { DefinedError, DefinedErrorExtra, DefineErrorSpec } from '../define-error';
|
|
14
9
|
export { defineError } from '../define-error';
|
|
15
|
-
export type {
|
|
16
|
-
ErrorCodeDeclaration,
|
|
17
|
-
ErrorCodeDescriptor,
|
|
18
|
-
ErrorCodeEntry,
|
|
19
|
-
} from '../error-codes';
|
|
10
|
+
export type { ErrorCodeDeclaration, ErrorCodeDescriptor, ErrorCodeEntry } from '../error-codes';
|
|
20
11
|
export {
|
|
21
12
|
describeErrorCode,
|
|
22
13
|
ERROR_DOCS_URL,
|
|
@@ -27,10 +18,11 @@ export {
|
|
|
27
18
|
resetErrorCodes,
|
|
28
19
|
} from '../error-codes';
|
|
29
20
|
export {
|
|
21
|
+
boundedCause,
|
|
30
22
|
describeValue,
|
|
31
23
|
isFixShellSafe,
|
|
32
24
|
isThrownError,
|
|
33
|
-
|
|
25
|
+
MAX_CAUSE_LENGTH,
|
|
34
26
|
renderCauseValue,
|
|
35
27
|
renderFixLiteral,
|
|
36
28
|
renderFixShellArg,
|
|
@@ -44,7 +36,6 @@ export {
|
|
|
44
36
|
DEFAULT_ERROR_RETRY,
|
|
45
37
|
declaredErrorRetry,
|
|
46
38
|
ERROR_RETRY_KINDS,
|
|
47
|
-
isErrorRetry,
|
|
48
39
|
registerErrorRetry,
|
|
49
40
|
registeredErrorRetry,
|
|
50
41
|
resetErrorRetry,
|
|
@@ -65,7 +56,6 @@ export {
|
|
|
65
56
|
EnvMissingError,
|
|
66
57
|
errorRetry,
|
|
67
58
|
fixFor,
|
|
68
|
-
formatError,
|
|
69
59
|
InternalError,
|
|
70
60
|
isUltimateError,
|
|
71
61
|
NotImplementedError,
|
|
@@ -32,32 +32,77 @@ export type {
|
|
|
32
32
|
} from '../error-reporter-sentry';
|
|
33
33
|
export {
|
|
34
34
|
ErrorReporterDsnInvalidError,
|
|
35
|
+
isLocalErrorSink,
|
|
36
|
+
isSentryErrorReporter,
|
|
37
|
+
localErrorSink,
|
|
35
38
|
parseSentryDsn,
|
|
36
39
|
sentryEnvelope,
|
|
37
40
|
sentryErrorReporter,
|
|
41
|
+
sentryEvent,
|
|
42
|
+
sentryTransport,
|
|
38
43
|
} from '../error-reporter-sentry';
|
|
44
|
+
export type { SentryEvent, SentryReporterHooks } from '../error-reporter-sentry-hooks';
|
|
39
45
|
export type {
|
|
40
|
-
FailureActor,
|
|
41
46
|
FailureBundle,
|
|
42
|
-
FailureCaptureLimits,
|
|
43
47
|
FailureFact,
|
|
44
48
|
FailurePrimitive,
|
|
45
49
|
FailureRead,
|
|
46
50
|
FailureStore,
|
|
47
|
-
HeldFailure,
|
|
48
51
|
} from '../failure-capture';
|
|
49
52
|
export {
|
|
50
53
|
failureCaptureActive,
|
|
51
|
-
failureCaptureLimits,
|
|
52
54
|
installedFailureStore,
|
|
53
55
|
recordFailureFact,
|
|
54
56
|
recordFailureInput,
|
|
55
|
-
setFailureStore,
|
|
56
57
|
withFailureCapture,
|
|
57
58
|
} from '../failure-capture';
|
|
58
|
-
export {
|
|
59
|
+
export { settleFailureCaptures } from '../failure-capture-flush';
|
|
59
60
|
export type { CapturedValue } from '../failure-capture-mask';
|
|
60
61
|
export { captureValue } from '../failure-capture-mask';
|
|
62
|
+
export type {
|
|
63
|
+
InstrumentEvent,
|
|
64
|
+
InstrumentHandler,
|
|
65
|
+
InstrumentName,
|
|
66
|
+
InstrumentPattern,
|
|
67
|
+
MatchedName,
|
|
68
|
+
} from '../instrument';
|
|
69
|
+
export {
|
|
70
|
+
instrument,
|
|
71
|
+
resetInstrumentation,
|
|
72
|
+
subscribe,
|
|
73
|
+
subscribed,
|
|
74
|
+
subscriberCount,
|
|
75
|
+
subscriberFailures,
|
|
76
|
+
} from '../instrument';
|
|
77
|
+
export type {
|
|
78
|
+
ActionInvokeEvent,
|
|
79
|
+
AiLlmEvent,
|
|
80
|
+
CacheInvalidateEvent,
|
|
81
|
+
CacheLookupEvent,
|
|
82
|
+
CacheTierFailureEvent,
|
|
83
|
+
DbStatementEvent,
|
|
84
|
+
EntityBulkEvent,
|
|
85
|
+
EntityCrossTenantEvent,
|
|
86
|
+
EntityRowEvent,
|
|
87
|
+
EntityRowOp,
|
|
88
|
+
HttpRequestEvent,
|
|
89
|
+
InstrumentEventMap,
|
|
90
|
+
InstrumentEventSpec,
|
|
91
|
+
InstrumentSpan,
|
|
92
|
+
JobEnqueueEvent,
|
|
93
|
+
JobPerformEvent,
|
|
94
|
+
MailDeliverEvent,
|
|
95
|
+
PolicyDecisionEvent,
|
|
96
|
+
QueryReadEvent,
|
|
97
|
+
RenderHoleEvent,
|
|
98
|
+
RenderPageEvent,
|
|
99
|
+
StatementAttribution,
|
|
100
|
+
StorageEvent,
|
|
101
|
+
TimedEvent,
|
|
102
|
+
} from '../instrument-events';
|
|
103
|
+
export { INSTRUMENT_EVENTS } from '../instrument-events';
|
|
104
|
+
export { SEMCONV, SEMCONV_METRICS, SEMCONV_VALUES } from '../instrument-semconv';
|
|
105
|
+
export { callerStack, captureStatementStacks, resetStatementStacks } from '../instrument-stacks';
|
|
61
106
|
export type { LogFields, Logger, LoggerOptions, LogLevel } from '../logger';
|
|
62
107
|
export {
|
|
63
108
|
isRedactedKey,
|
|
@@ -93,7 +138,6 @@ export {
|
|
|
93
138
|
configureMetrics,
|
|
94
139
|
counter,
|
|
95
140
|
DEFAULT_HISTOGRAM_BOUNDS,
|
|
96
|
-
DEFAULT_MAX_SERIES,
|
|
97
141
|
exportMetrics,
|
|
98
142
|
gauge,
|
|
99
143
|
histogram,
|
|
@@ -101,13 +145,13 @@ export {
|
|
|
101
145
|
MetricNameInvalidError,
|
|
102
146
|
MetricValueInvalidError,
|
|
103
147
|
memoryMetricExporter,
|
|
104
|
-
noopMetricExporter,
|
|
105
148
|
OVERFLOW_ATTRIBUTE,
|
|
106
149
|
resetMetrics,
|
|
107
150
|
startMetricExport,
|
|
108
151
|
} from '../metrics';
|
|
152
|
+
export { subscribeSemconvMetrics } from '../metrics-semconv';
|
|
109
153
|
export { METRICS_CONTENT_TYPE, METRICS_PATH, metricsText } from '../metrics-text';
|
|
110
|
-
export type {
|
|
154
|
+
export type { OtlpSignal } from '../otlp';
|
|
111
155
|
export {
|
|
112
156
|
OTLP_ENDPOINT_KEY,
|
|
113
157
|
OTLP_HEADERS_KEY,
|
|
@@ -118,12 +162,14 @@ export {
|
|
|
118
162
|
OtlpHeadersInvalidError,
|
|
119
163
|
OtlpProtocolUnsupportedError,
|
|
120
164
|
otlpAttributes,
|
|
121
|
-
|
|
165
|
+
otlpEndpointLabel,
|
|
122
166
|
otlpHeaders,
|
|
123
167
|
otlpResource,
|
|
124
168
|
tryOtlpEndpoint,
|
|
125
169
|
unixNano,
|
|
126
170
|
} from '../otlp';
|
|
171
|
+
export type { OtlpLogExporter, OtlpLogExporterOptions } from '../otlp-log-exporter';
|
|
172
|
+
export { otlpLogExporter } from '../otlp-log-exporter';
|
|
127
173
|
export type { OtlpMetricExporter, OtlpMetricExporterOptions } from '../otlp-metric-exporter';
|
|
128
174
|
export { otlpMetricExporter, otlpMetricsRequest } from '../otlp-metric-exporter';
|
|
129
175
|
export type { OtlpSpanExporter, OtlpSpanExporterOptions } from '../otlp-span-exporter';
|
|
@@ -147,14 +193,10 @@ export type { Sampler } from '../sampler';
|
|
|
147
193
|
export {
|
|
148
194
|
alwaysOffSampler,
|
|
149
195
|
alwaysOnSampler,
|
|
150
|
-
DEFAULT_SAMPLE_RATIO,
|
|
151
|
-
defaultSampler,
|
|
152
196
|
OTEL_SAMPLER_ARG_KEY,
|
|
153
197
|
OTEL_SAMPLER_KEY,
|
|
154
198
|
parentBasedRatioSampler,
|
|
155
|
-
ratioSampler,
|
|
156
199
|
resetDefaultSampler,
|
|
157
|
-
samplerFromEnv,
|
|
158
200
|
} from '../sampler';
|
|
159
201
|
export type {
|
|
160
202
|
AttributeValue,
|
|
@@ -177,13 +219,11 @@ export {
|
|
|
177
219
|
currentSampler,
|
|
178
220
|
currentSpan,
|
|
179
221
|
currentSpanContext,
|
|
222
|
+
MAX_SPAN_EVENTS,
|
|
180
223
|
memoryExporter,
|
|
181
|
-
noopExporter,
|
|
182
224
|
parseTraceparent,
|
|
183
225
|
resetTelemetry,
|
|
184
|
-
serviceResource,
|
|
185
226
|
startSpan,
|
|
186
227
|
traceparent,
|
|
187
228
|
withSpan,
|
|
188
|
-
withSpanContext,
|
|
189
229
|
} from '../telemetry';
|
package/src/exports/secrets.ts
CHANGED
|
@@ -11,12 +11,9 @@ export {
|
|
|
11
11
|
SECRET_BRAND,
|
|
12
12
|
secret,
|
|
13
13
|
} from '../secret';
|
|
14
|
-
export type {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
SecretsLocation,
|
|
18
|
-
SecretValues,
|
|
19
|
-
} from '../secrets';
|
|
14
|
+
export type { MasterKeyRef } from '../secret-source';
|
|
15
|
+
export { masterKeyPath, SECRETS_KEY_ENV, SECRETS_KEY_FILE } from '../secret-source';
|
|
16
|
+
export type { SecretSummary, SecretsLocation, SecretValues } from '../secrets';
|
|
20
17
|
export {
|
|
21
18
|
assertSecretValues,
|
|
22
19
|
describeSecrets,
|
|
@@ -38,7 +35,6 @@ export {
|
|
|
38
35
|
} from '../secrets';
|
|
39
36
|
export type { SecretsErrorCode } from '../secrets-errors';
|
|
40
37
|
export {
|
|
41
|
-
SECRETS_ERROR_CODES,
|
|
42
38
|
SecretsFileInvalidError,
|
|
43
39
|
SecretsFileMissingError,
|
|
44
40
|
SecretsKeyInvalidError,
|
|
@@ -48,26 +44,16 @@ export {
|
|
|
48
44
|
SecretsTamperedError,
|
|
49
45
|
} from '../secrets-errors';
|
|
50
46
|
export { SecretsKeyAclError } from '../secrets-key-file';
|
|
51
|
-
export type {
|
|
52
|
-
MasterKeyRef,
|
|
53
|
-
MasterKeySource,
|
|
54
|
-
SecretsInstallOptions,
|
|
55
|
-
SecretsInstallReport,
|
|
56
|
-
} from '../secrets-store';
|
|
47
|
+
export type { SecretsInstallOptions, SecretsInstallReport } from '../secrets-store';
|
|
57
48
|
export {
|
|
58
49
|
findMasterKey,
|
|
59
50
|
installSecrets,
|
|
60
51
|
masterKeyIdOf,
|
|
61
|
-
masterKeyPath,
|
|
62
52
|
promoteStagedMasterKey,
|
|
63
53
|
readSecretsFile,
|
|
64
54
|
requireMasterKey,
|
|
65
55
|
SECRETS_FILE,
|
|
66
|
-
SECRETS_KEY_ENV,
|
|
67
|
-
SECRETS_KEY_FILE,
|
|
68
|
-
SECRETS_KEY_MODE,
|
|
69
56
|
secretsFileExists,
|
|
70
|
-
secretsPath,
|
|
71
57
|
stagedMasterKeyPath,
|
|
72
58
|
stageMasterKeyFile,
|
|
73
59
|
writeMasterKeyFile,
|