@ericminassian/platform-core 0.3.0 → 0.4.1
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/api.d.ts +1225 -45
- package/dist/api.js +471 -13
- package/dist/api.js.map +1 -1
- package/dist/auth.js +5 -2
- package/dist/auth.js.map +1 -1
- package/dist/base64url.d.ts +3 -0
- package/dist/base64url.js +15 -0
- package/dist/base64url.js.map +1 -0
- package/dist/bindings.d.ts +62 -12
- package/dist/bindings.js +1 -1
- package/dist/bindings.js.map +1 -1
- package/dist/cloudfront-function.d.ts +5 -1
- package/dist/cloudfront-function.js +64 -2
- package/dist/cloudfront-function.js.map +1 -1
- package/dist/compute.d.ts +52 -0
- package/dist/compute.js +65 -0
- package/dist/compute.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.js +9 -0
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +56 -1
- package/dist/constants.js +56 -1
- package/dist/constants.js.map +1 -1
- package/dist/email.d.ts +84 -0
- package/dist/email.js +111 -0
- package/dist/email.js.map +1 -0
- package/dist/explore.d.ts +365 -0
- package/dist/explore.js +440 -0
- package/dist/explore.js.map +1 -0
- package/dist/fingerprint.d.ts +9 -0
- package/dist/fingerprint.js +19 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +111 -0
- package/dist/jobs.js +214 -0
- package/dist/jobs.js.map +1 -0
- package/dist/manifest.d.ts +270 -29
- package/dist/manifest.js +190 -22
- package/dist/manifest.js.map +1 -1
- package/dist/naming.d.ts +83 -7
- package/dist/naming.js +89 -8
- package/dist/naming.js.map +1 -1
- package/dist/platform-api.d.ts +5897 -1672
- package/dist/platform-api.js +218 -8
- package/dist/platform-api.js.map +1 -1
- package/dist/realtime.d.ts +139 -0
- package/dist/realtime.js +201 -0
- package/dist/realtime.js.map +1 -0
- package/dist/router/decide.d.ts +2 -0
- package/dist/router/decide.js +38 -6
- package/dist/router.d.ts +35 -13
- package/dist/router.js +36 -0
- package/dist/router.js.map +1 -1
- package/dist/runtime-config.d.ts +57 -0
- package/dist/runtime-config.js +12 -0
- package/dist/runtime-config.js.map +1 -1
- package/dist/storage.d.ts +65 -0
- package/dist/storage.js +122 -0
- package/dist/storage.js.map +1 -0
- package/dist/telemetry.d.ts +135 -20
- package/dist/telemetry.js +108 -22
- package/dist/telemetry.js.map +1 -1
- package/dist/web-compute.d.ts +191 -0
- package/dist/web-compute.js +257 -0
- package/dist/web-compute.js.map +1 -0
- package/package.json +19 -7
- package/src/api.ts +564 -15
- package/src/auth.ts +6 -2
- package/src/base64url.ts +13 -0
- package/src/bindings.ts +67 -6
- package/src/cloudfront-function.ts +64 -2
- package/src/compute.ts +86 -0
- package/src/config.ts +31 -1
- package/src/constants.ts +64 -1
- package/src/email.ts +168 -0
- package/src/explore.ts +504 -0
- package/src/fingerprint.ts +20 -0
- package/src/index.ts +7 -0
- package/src/jobs.ts +281 -0
- package/src/manifest.ts +415 -45
- package/src/naming.ts +93 -9
- package/src/platform-api.ts +249 -8
- package/src/realtime.ts +298 -0
- package/src/router/decide.d.ts +2 -0
- package/src/router/decide.js +38 -6
- package/src/router.ts +33 -13
- package/src/runtime-config.ts +70 -0
- package/src/storage.ts +131 -0
- package/src/telemetry.ts +115 -22
- package/src/web-compute.ts +342 -0
package/dist/storage.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File stores (`storage` in `plat.config.ts`). Every stage's stores share the
|
|
3
|
+
* platform's storage bucket:
|
|
4
|
+
*
|
|
5
|
+
* - a private store is `<app>/<stage>/<store>/` (`names.storagePrefix`);
|
|
6
|
+
* browsers reach its files only through presigned URLs;
|
|
7
|
+
* - a public store is `_public/<app>/<stage>/<store>/`, which the edge serves
|
|
8
|
+
* at `/__platform/storage/<store>/<key>` on the app's own host. The router
|
|
9
|
+
* distribution may read `_public/*` and nothing else, so a routing mistake
|
|
10
|
+
* can't expose a private store. `_` can't start an app name, so no app's
|
|
11
|
+
* prefix collides with it.
|
|
12
|
+
*
|
|
13
|
+
* Isomorphic: the SDK, its browser client, the CLI and the engine share it.
|
|
14
|
+
*/
|
|
15
|
+
/** Where the edge serves public stores on every app host: `/__platform/storage/<store>/<key>`. */
|
|
16
|
+
export const STORAGE_PATH = '/__platform/storage/';
|
|
17
|
+
/** Top-level prefix of public stores in the storage bucket. */
|
|
18
|
+
export const PUBLIC_STORAGE_ROOT = '_public/';
|
|
19
|
+
/**
|
|
20
|
+
* Headers the edge adds to every public-store response (the router
|
|
21
|
+
* distribution's response headers policy; `plat dev` sends the same).
|
|
22
|
+
* `script-src 'none'` keeps an uploaded HTML or SVG file from running script
|
|
23
|
+
* on the app's origin, where its session cookie lives (`sandbox` would also
|
|
24
|
+
* stop PDFs from opening in Chrome).
|
|
25
|
+
*/
|
|
26
|
+
export const STORAGE_RESPONSE_HEADERS = {
|
|
27
|
+
'x-content-type-options': 'nosniff',
|
|
28
|
+
'content-security-policy': "script-src 'none'",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The router's `x-platform-host` for a public store's file, in place of the
|
|
32
|
+
* host. CloudFront's cache key is the rewritten URI plus that header, not the
|
|
33
|
+
* behavior or origin, and an app's server could be asked for the same path
|
|
34
|
+
* (`/<app>/<stage>/<store>/<key>`) on the app's host: with the host in both,
|
|
35
|
+
* its response would be served for the file, and the file for that path. No
|
|
36
|
+
* routed host has this value.
|
|
37
|
+
*/
|
|
38
|
+
export const STORAGE_CACHE_HOST = '__storage';
|
|
39
|
+
/** `Cache-Control` the edge adds to a public file that carries none: browsers revalidate it. */
|
|
40
|
+
export const STORAGE_DEFAULT_CACHE_CONTROL = 'no-cache';
|
|
41
|
+
/**
|
|
42
|
+
* `plat dev` only: where its router relays browser uploads to the AWS Emulator,
|
|
43
|
+
* with the presigned URL in `?to=`. The emulator refuses a presigned request
|
|
44
|
+
* that carries an `Origin` header (`InvalidAccessKeyId`), which every browser
|
|
45
|
+
* upload sends and S3 accepts; the router forwards the PUT without it. The SDK
|
|
46
|
+
* returns relay URLs when `DEV_UPLOAD_RELAY_ENV` is set, which only `plat dev`
|
|
47
|
+
* does (`plat test` and deployed stages get the presigned URL itself).
|
|
48
|
+
*/
|
|
49
|
+
export const DEV_UPLOAD_PATH = '/__plat_dev/upload';
|
|
50
|
+
export const DEV_UPLOAD_RELAY_ENV = 'PLATFORM_DEV_UPLOAD_RELAY';
|
|
51
|
+
/**
|
|
52
|
+
* Whether the edge serves `key` (as it appears in a URL path, so still
|
|
53
|
+
* percent-encoded): not empty, and without `.` or `..` segments. S3 decodes
|
|
54
|
+
* the key once, so `%2e` counts as a dot and `%2f` as a slash. The router
|
|
55
|
+
* inlines the same check (`router/decide.js`).
|
|
56
|
+
*/
|
|
57
|
+
export function isServableKey(key) {
|
|
58
|
+
if (!key)
|
|
59
|
+
return false;
|
|
60
|
+
return key
|
|
61
|
+
.replace(/%2e/gi, '.')
|
|
62
|
+
.replace(/%2f/gi, '/')
|
|
63
|
+
.split('/')
|
|
64
|
+
.every((part) => part !== '.' && part !== '..');
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The path the edge serves a public store's file at, with each key segment
|
|
68
|
+
* percent-encoded: `storagePath('snapshots', 'fires/today 1.json')` →
|
|
69
|
+
* `/__platform/storage/snapshots/fires/today%201.json`.
|
|
70
|
+
*/
|
|
71
|
+
export function storagePath(store, key) {
|
|
72
|
+
const k = key.replace(/^\/+/, '');
|
|
73
|
+
const path = k.split('/').map(encodeURIComponent).join('/');
|
|
74
|
+
if (!isServableKey(path))
|
|
75
|
+
throw new Error(`Storage key "${key}" can't be served from the edge`);
|
|
76
|
+
return `${STORAGE_PATH}${store}/${path}`;
|
|
77
|
+
}
|
|
78
|
+
/** Content types by file extension: static files, and store files put without one. */
|
|
79
|
+
const CONTENT_TYPES = {
|
|
80
|
+
html: 'text/html; charset=utf-8',
|
|
81
|
+
htm: 'text/html; charset=utf-8',
|
|
82
|
+
css: 'text/css; charset=utf-8',
|
|
83
|
+
js: 'text/javascript; charset=utf-8',
|
|
84
|
+
mjs: 'text/javascript; charset=utf-8',
|
|
85
|
+
cjs: 'text/javascript; charset=utf-8',
|
|
86
|
+
map: 'application/json; charset=utf-8',
|
|
87
|
+
json: 'application/json; charset=utf-8',
|
|
88
|
+
geojson: 'application/geo+json',
|
|
89
|
+
ndjson: 'application/x-ndjson',
|
|
90
|
+
webmanifest: 'application/manifest+json',
|
|
91
|
+
txt: 'text/plain; charset=utf-8',
|
|
92
|
+
csv: 'text/csv; charset=utf-8',
|
|
93
|
+
md: 'text/markdown; charset=utf-8',
|
|
94
|
+
xml: 'application/xml; charset=utf-8',
|
|
95
|
+
svg: 'image/svg+xml',
|
|
96
|
+
png: 'image/png',
|
|
97
|
+
jpg: 'image/jpeg',
|
|
98
|
+
jpeg: 'image/jpeg',
|
|
99
|
+
gif: 'image/gif',
|
|
100
|
+
webp: 'image/webp',
|
|
101
|
+
avif: 'image/avif',
|
|
102
|
+
ico: 'image/x-icon',
|
|
103
|
+
woff: 'font/woff',
|
|
104
|
+
woff2: 'font/woff2',
|
|
105
|
+
ttf: 'font/ttf',
|
|
106
|
+
otf: 'font/otf',
|
|
107
|
+
wasm: 'application/wasm',
|
|
108
|
+
pdf: 'application/pdf',
|
|
109
|
+
zip: 'application/zip',
|
|
110
|
+
gz: 'application/gzip',
|
|
111
|
+
mp4: 'video/mp4',
|
|
112
|
+
webm: 'video/webm',
|
|
113
|
+
mp3: 'audio/mpeg',
|
|
114
|
+
wav: 'audio/wav',
|
|
115
|
+
};
|
|
116
|
+
/** The content type for a file name (or key), `application/octet-stream` when the extension is unknown. */
|
|
117
|
+
export function contentTypeFor(path) {
|
|
118
|
+
const file = path.slice(path.lastIndexOf('/') + 1);
|
|
119
|
+
const dot = file.lastIndexOf('.');
|
|
120
|
+
return ((dot === -1 ? undefined : CONTENT_TYPES[file.slice(dot + 1).toLowerCase()]) ?? 'application/octet-stream');
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"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"}
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -4,9 +4,13 @@
|
|
|
4
4
|
* filter forwards the interesting kinds to the telemetry processor, which
|
|
5
5
|
* aggregates rollups into the telemetry table. Logs Insights covers the rest
|
|
6
6
|
* (search, traces) on demand. No CloudWatch custom metrics are ever created.
|
|
7
|
+
*
|
|
8
|
+
* CloudWatch Logs bills every byte ingested, so lines leave out what a reader
|
|
9
|
+
* can tell without it (a `path` equal to its `route`, a first `attempt`), and
|
|
10
|
+
* most requests and jobs fold their spans into a count (`traceSampled`).
|
|
7
11
|
*/
|
|
8
12
|
import { Schema } from 'effect';
|
|
9
|
-
export declare const TelemetryKind: Schema.Literals<readonly ["req", "err", "job", "span", "log", "metric", "env"]>;
|
|
13
|
+
export declare const TelemetryKind: Schema.Literals<readonly ["req", "err", "job", "span", "log", "metric", "limit", "env"]>;
|
|
10
14
|
export type TelemetryKind = typeof TelemetryKind.Type;
|
|
11
15
|
export declare const RequestEvent: Schema.Struct<{
|
|
12
16
|
readonly _p: Schema.Literal<1>;
|
|
@@ -17,11 +21,14 @@ export declare const RequestEvent: Schema.Struct<{
|
|
|
17
21
|
readonly trace: Schema.optional<Schema.String>;
|
|
18
22
|
readonly span: Schema.optional<Schema.String>;
|
|
19
23
|
readonly parent: Schema.optional<Schema.String>;
|
|
24
|
+
readonly calls: Schema.optional<Schema.Finite>;
|
|
25
|
+
readonly callMs: Schema.optional<Schema.Finite>;
|
|
20
26
|
readonly t: Schema.Literal<"req">;
|
|
21
27
|
readonly method: Schema.String;
|
|
22
|
-
/** Route pattern when known (`/api/todos/:id`), else the raw path
|
|
28
|
+
/** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
|
|
23
29
|
readonly route: Schema.String;
|
|
24
|
-
|
|
30
|
+
/** The raw path, when it isn't `route`. */
|
|
31
|
+
readonly path: Schema.optional<Schema.String>;
|
|
25
32
|
readonly status: Schema.Finite;
|
|
26
33
|
/** Duration in ms. */
|
|
27
34
|
readonly dur: Schema.Finite;
|
|
@@ -42,7 +49,8 @@ export declare const ErrorEvent: Schema.Struct<{
|
|
|
42
49
|
readonly span: Schema.optional<Schema.String>;
|
|
43
50
|
readonly parent: Schema.optional<Schema.String>;
|
|
44
51
|
readonly t: Schema.Literal<"err">;
|
|
45
|
-
|
|
52
|
+
/** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
|
|
53
|
+
readonly source: Schema.Literals<readonly ["http", "job", "unhandled", "log", "service"]>;
|
|
46
54
|
readonly name: Schema.String;
|
|
47
55
|
readonly message: Schema.String;
|
|
48
56
|
readonly stack: Schema.optional<Schema.String>;
|
|
@@ -51,6 +59,11 @@ export declare const ErrorEvent: Schema.Struct<{
|
|
|
51
59
|
readonly fingerprint: Schema.String;
|
|
52
60
|
}>;
|
|
53
61
|
export type ErrorEvent = typeof ErrorEvent.Type;
|
|
62
|
+
/**
|
|
63
|
+
* One unit of work. `service` jobs come from long-running services: `<service>`
|
|
64
|
+
* is a run of the service that ended (it is rerun; `dur` is how long it ran),
|
|
65
|
+
* `<service>/<unit>` a unit of work it marked with `traced`.
|
|
66
|
+
*/
|
|
54
67
|
export declare const JobEvent: Schema.Struct<{
|
|
55
68
|
readonly _p: Schema.Literal<1>;
|
|
56
69
|
readonly ts: Schema.Finite;
|
|
@@ -60,14 +73,23 @@ export declare const JobEvent: Schema.Struct<{
|
|
|
60
73
|
readonly trace: Schema.optional<Schema.String>;
|
|
61
74
|
readonly span: Schema.optional<Schema.String>;
|
|
62
75
|
readonly parent: Schema.optional<Schema.String>;
|
|
76
|
+
readonly calls: Schema.optional<Schema.Finite>;
|
|
77
|
+
readonly callMs: Schema.optional<Schema.Finite>;
|
|
63
78
|
readonly t: Schema.Literal<"job">;
|
|
64
|
-
readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke"]>;
|
|
79
|
+
readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke", "service"]>;
|
|
65
80
|
readonly name: Schema.String;
|
|
66
81
|
readonly status: Schema.Literals<readonly ["ok", "error"]>;
|
|
67
82
|
readonly dur: Schema.Finite;
|
|
83
|
+
/** A queue message's, event's or cron run's attempt, when it isn't the first. */
|
|
68
84
|
readonly attempt: Schema.optional<Schema.Finite>;
|
|
85
|
+
/** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
|
|
86
|
+
readonly next: Schema.optional<Schema.Literals<readonly ["retry", "dead"]>>;
|
|
69
87
|
}>;
|
|
70
88
|
export type JobEvent = typeof JobEvent.Type;
|
|
89
|
+
/**
|
|
90
|
+
* A call a request or job made, written only when its request or job keeps its
|
|
91
|
+
* spans (`TRACE_SAMPLE_RATE`); `parent` is that request's or job's `span`.
|
|
92
|
+
*/
|
|
71
93
|
export declare const SpanEvent: Schema.Struct<{
|
|
72
94
|
readonly _p: Schema.Literal<1>;
|
|
73
95
|
readonly ts: Schema.Finite;
|
|
@@ -117,6 +139,23 @@ export declare const MetricEvent: Schema.Struct<{
|
|
|
117
139
|
readonly unit: Schema.optional<Schema.String>;
|
|
118
140
|
}>;
|
|
119
141
|
export type MetricEvent = typeof MetricEvent.Type;
|
|
142
|
+
/** One `RateLimits` check, and whether the limit let it through. */
|
|
143
|
+
export declare const LimitEvent: Schema.Struct<{
|
|
144
|
+
readonly _p: Schema.Literal<1>;
|
|
145
|
+
readonly ts: Schema.Finite;
|
|
146
|
+
readonly app: Schema.String;
|
|
147
|
+
readonly stage: Schema.String;
|
|
148
|
+
readonly rev: Schema.String;
|
|
149
|
+
readonly trace: Schema.optional<Schema.String>;
|
|
150
|
+
readonly span: Schema.optional<Schema.String>;
|
|
151
|
+
readonly parent: Schema.optional<Schema.String>;
|
|
152
|
+
readonly t: Schema.Literal<"limit">;
|
|
153
|
+
/** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
|
|
154
|
+
readonly name: Schema.String;
|
|
155
|
+
readonly ok: Schema.Boolean;
|
|
156
|
+
}>;
|
|
157
|
+
export type LimitEvent = typeof LimitEvent.Type;
|
|
158
|
+
/** A runtime process starting or stopping (`service`: a container of a long-running service). */
|
|
120
159
|
export declare const EnvEvent: Schema.Struct<{
|
|
121
160
|
readonly _p: Schema.Literal<1>;
|
|
122
161
|
readonly ts: Schema.Finite;
|
|
@@ -128,7 +167,16 @@ export declare const EnvEvent: Schema.Struct<{
|
|
|
128
167
|
readonly parent: Schema.optional<Schema.String>;
|
|
129
168
|
readonly t: Schema.Literal<"env">;
|
|
130
169
|
readonly event: Schema.Literals<readonly ["start", "stop"]>;
|
|
131
|
-
readonly runtime: Schema.Literals<readonly ["web", "worker"]>;
|
|
170
|
+
readonly runtime: Schema.Literals<readonly ["web", "worker", "service"]>;
|
|
171
|
+
/**
|
|
172
|
+
* How a deployed server runs (`runtime: 'web'`): `request`, a function per
|
|
173
|
+
* request, or `instance`, a Web Function environment. Absent under `plat dev`.
|
|
174
|
+
*/
|
|
175
|
+
readonly compute: Schema.optional<Schema.Literals<readonly ["request", "instance"]>>;
|
|
176
|
+
/** The service's name (`runtime: 'service'`). */
|
|
177
|
+
readonly name: Schema.optional<Schema.String>;
|
|
178
|
+
/** Why it stopped, e.g. `SIGTERM`. */
|
|
179
|
+
readonly reason: Schema.optional<Schema.String>;
|
|
132
180
|
readonly initMs: Schema.optional<Schema.Finite>;
|
|
133
181
|
}>;
|
|
134
182
|
export type EnvEvent = typeof EnvEvent.Type;
|
|
@@ -142,11 +190,14 @@ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
142
190
|
readonly trace: Schema.optional<Schema.String>;
|
|
143
191
|
readonly span: Schema.optional<Schema.String>;
|
|
144
192
|
readonly parent: Schema.optional<Schema.String>;
|
|
193
|
+
readonly calls: Schema.optional<Schema.Finite>;
|
|
194
|
+
readonly callMs: Schema.optional<Schema.Finite>;
|
|
145
195
|
readonly t: Schema.Literal<"req">;
|
|
146
196
|
readonly method: Schema.String;
|
|
147
|
-
/** Route pattern when known (`/api/todos/:id`), else the raw path
|
|
197
|
+
/** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
|
|
148
198
|
readonly route: Schema.String;
|
|
149
|
-
|
|
199
|
+
/** The raw path, when it isn't `route`. */
|
|
200
|
+
readonly path: Schema.optional<Schema.String>;
|
|
150
201
|
readonly status: Schema.Finite;
|
|
151
202
|
/** Duration in ms. */
|
|
152
203
|
readonly dur: Schema.Finite;
|
|
@@ -165,7 +216,8 @@ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
165
216
|
readonly span: Schema.optional<Schema.String>;
|
|
166
217
|
readonly parent: Schema.optional<Schema.String>;
|
|
167
218
|
readonly t: Schema.Literal<"err">;
|
|
168
|
-
|
|
219
|
+
/** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
|
|
220
|
+
readonly source: Schema.Literals<readonly ["http", "job", "unhandled", "log", "service"]>;
|
|
169
221
|
readonly name: Schema.String;
|
|
170
222
|
readonly message: Schema.String;
|
|
171
223
|
readonly stack: Schema.optional<Schema.String>;
|
|
@@ -181,12 +233,17 @@ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
181
233
|
readonly trace: Schema.optional<Schema.String>;
|
|
182
234
|
readonly span: Schema.optional<Schema.String>;
|
|
183
235
|
readonly parent: Schema.optional<Schema.String>;
|
|
236
|
+
readonly calls: Schema.optional<Schema.Finite>;
|
|
237
|
+
readonly callMs: Schema.optional<Schema.Finite>;
|
|
184
238
|
readonly t: Schema.Literal<"job">;
|
|
185
|
-
readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke"]>;
|
|
239
|
+
readonly kind: Schema.Literals<readonly ["queue", "event", "cron", "invoke", "service"]>;
|
|
186
240
|
readonly name: Schema.String;
|
|
187
241
|
readonly status: Schema.Literals<readonly ["ok", "error"]>;
|
|
188
242
|
readonly dur: Schema.Finite;
|
|
243
|
+
/** A queue message's, event's or cron run's attempt, when it isn't the first. */
|
|
189
244
|
readonly attempt: Schema.optional<Schema.Finite>;
|
|
245
|
+
/** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
|
|
246
|
+
readonly next: Schema.optional<Schema.Literals<readonly ["retry", "dead"]>>;
|
|
190
247
|
}>, Schema.Struct<{
|
|
191
248
|
readonly _p: Schema.Literal<1>;
|
|
192
249
|
readonly ts: Schema.Finite;
|
|
@@ -229,6 +286,19 @@ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
229
286
|
readonly name: Schema.String;
|
|
230
287
|
readonly value: Schema.Finite;
|
|
231
288
|
readonly unit: Schema.optional<Schema.String>;
|
|
289
|
+
}>, Schema.Struct<{
|
|
290
|
+
readonly _p: Schema.Literal<1>;
|
|
291
|
+
readonly ts: Schema.Finite;
|
|
292
|
+
readonly app: Schema.String;
|
|
293
|
+
readonly stage: Schema.String;
|
|
294
|
+
readonly rev: Schema.String;
|
|
295
|
+
readonly trace: Schema.optional<Schema.String>;
|
|
296
|
+
readonly span: Schema.optional<Schema.String>;
|
|
297
|
+
readonly parent: Schema.optional<Schema.String>;
|
|
298
|
+
readonly t: Schema.Literal<"limit">;
|
|
299
|
+
/** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
|
|
300
|
+
readonly name: Schema.String;
|
|
301
|
+
readonly ok: Schema.Boolean;
|
|
232
302
|
}>, Schema.Struct<{
|
|
233
303
|
readonly _p: Schema.Literal<1>;
|
|
234
304
|
readonly ts: Schema.Finite;
|
|
@@ -240,12 +310,36 @@ export declare const TelemetryEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
240
310
|
readonly parent: Schema.optional<Schema.String>;
|
|
241
311
|
readonly t: Schema.Literal<"env">;
|
|
242
312
|
readonly event: Schema.Literals<readonly ["start", "stop"]>;
|
|
243
|
-
readonly runtime: Schema.Literals<readonly ["web", "worker"]>;
|
|
313
|
+
readonly runtime: Schema.Literals<readonly ["web", "worker", "service"]>;
|
|
314
|
+
/**
|
|
315
|
+
* How a deployed server runs (`runtime: 'web'`): `request`, a function per
|
|
316
|
+
* request, or `instance`, a Web Function environment. Absent under `plat dev`.
|
|
317
|
+
*/
|
|
318
|
+
readonly compute: Schema.optional<Schema.Literals<readonly ["request", "instance"]>>;
|
|
319
|
+
/** The service's name (`runtime: 'service'`). */
|
|
320
|
+
readonly name: Schema.optional<Schema.String>;
|
|
321
|
+
/** Why it stopped, e.g. `SIGTERM`. */
|
|
322
|
+
readonly reason: Schema.optional<Schema.String>;
|
|
244
323
|
readonly initMs: Schema.optional<Schema.Finite>;
|
|
245
324
|
}>]>;
|
|
246
325
|
export type TelemetryEvent = typeof TelemetryEvent.Type;
|
|
247
326
|
/** Account-level subscription filter: only aggregate-worthy kinds reach the processor. */
|
|
248
|
-
export declare const TELEMETRY_FILTER_PATTERN = "{ ($._p = 1) && (($.t = \"req\") || ($.t = \"err\") || ($.t = \"job\") || ($.t = \"metric\") || ($.t = \"env\")) }";
|
|
327
|
+
export declare const TELEMETRY_FILTER_PATTERN = "{ ($._p = 1) && (($.t = \"req\") || ($.t = \"err\") || ($.t = \"job\") || ($.t = \"metric\") || ($.t = \"limit\") || ($.t = \"env\")) }";
|
|
328
|
+
/**
|
|
329
|
+
* A request or job writes its spans when it fails (a 5xx, a failed job, or an
|
|
330
|
+
* `err` line while it runs), takes `SLOW_TRACE_MS` or longer, or its trace is
|
|
331
|
+
* in this share of traces (`traceSampled`). The rest write only their own
|
|
332
|
+
* line, with the spans counted on it (`calls`, `callMs`).
|
|
333
|
+
*/
|
|
334
|
+
export declare const TRACE_SAMPLE_RATE: number;
|
|
335
|
+
/** A request or job that takes this long (ms) or longer writes its spans. */
|
|
336
|
+
export declare const SLOW_TRACE_MS = 1000;
|
|
337
|
+
/**
|
|
338
|
+
* Whether `trace` is one of the sampled traces. It depends on the trace id
|
|
339
|
+
* alone, so every hop of a trace (server → queue → worker) makes the same
|
|
340
|
+
* choice. Any string works: a client can send its own `x-platform-trace`.
|
|
341
|
+
*/
|
|
342
|
+
export declare function traceSampled(trace: string): boolean;
|
|
249
343
|
export declare function isTelemetryEvent(v: unknown): v is TelemetryEvent;
|
|
250
344
|
/** Upper bounds in ms; the last bucket is open-ended. */
|
|
251
345
|
export declare const LATENCY_BUCKETS_MS: readonly [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000];
|
|
@@ -263,26 +357,47 @@ export declare function bucketStart(ts: number, res: Resolution): number;
|
|
|
263
357
|
* resolution; `sk` starts with the bucket time so a Query with `BETWEEN`
|
|
264
358
|
* returns a time range.
|
|
265
359
|
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
360
|
+
* Every rollup family is written at `1m`, `1h` and `1d` (`RESOLUTION_TTL_DAYS`).
|
|
361
|
+
* Route, job, custom metric and rate limit rows have had minute buckets only
|
|
362
|
+
* since November 2026; before, they started at `1h`.
|
|
363
|
+
*
|
|
364
|
+
* - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold,
|
|
365
|
+
* dur (ms handling them, summed), and process starts:
|
|
366
|
+
* webStarts (webInits of them reported webInitMs, summed),
|
|
367
|
+
* workerStarts, serviceStarts
|
|
368
|
+
* - `r#<app>#<stage>#<res>` sk `<iso>#<METHOD> <route>` per-route HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[],
|
|
369
|
+
* cold, method, route. Rows from before November 2026 have no
|
|
370
|
+
* s2xx, s3xx or cold: their req − s4xx − s5xx were 2xx
|
|
371
|
+
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]; `service:<name>` rows also
|
|
372
|
+
* count `starts` (containers of that service starting)
|
|
373
|
+
* - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum, max (and the unit); rows from
|
|
374
|
+
* before November 2026 have no max
|
|
375
|
+
* - `l#<app>#<stage>#<res>` sk `<iso>#<limit>` rate limit checks: allowed, denied
|
|
270
376
|
* - `e#<app>#<stage>` sk `<fingerprint>` error groups: count, firstSeen, lastSeen, sample, status
|
|
271
|
-
* - `u#<app>#<stage>` sk `<iso>` uptime
|
|
377
|
+
* - `u#<app>#<stage>` sk `<iso>` uptime: ok, source (`traffic`: req, s5xx; `check`, or none on
|
|
378
|
+
* rows before traffic counted: status, ms)
|
|
379
|
+
* - `a#<app>#<stage>` sk `<iso>#<ruleId>` alert rule state changes (`AlertEvent` fields but `ts`),
|
|
380
|
+
* kept `ALERT_HISTORY_DAYS`
|
|
272
381
|
*/
|
|
273
382
|
export declare const telemetryKeys: {
|
|
274
383
|
readonly stage: (app: string, stage: string, res: Resolution) => string;
|
|
275
384
|
readonly route: (app: string, stage: string, res: Resolution) => string;
|
|
276
385
|
readonly job: (app: string, stage: string, res: Resolution) => string;
|
|
277
386
|
readonly metric: (app: string, stage: string, res: Resolution) => string;
|
|
387
|
+
readonly limit: (app: string, stage: string, res: Resolution) => string;
|
|
278
388
|
readonly errors: (app: string, stage: string) => string;
|
|
279
389
|
readonly uptime: (app: string, stage: string) => string;
|
|
390
|
+
readonly alerts: (app: string, stage: string) => string;
|
|
391
|
+
/**
|
|
392
|
+
* Email usage: sk `YYYY-MM-DD` (UTC), `n` recipients sent. The SDK writes it
|
|
393
|
+
* with the stage role, whose IAM grant covers only this partition.
|
|
394
|
+
*/
|
|
395
|
+
readonly email: (app: string, stage: string) => string;
|
|
280
396
|
readonly time: (ts: number) => string;
|
|
281
397
|
};
|
|
282
|
-
/** Normalize volatile parts (ids, numbers, quoted values) so similar errors group together. */
|
|
398
|
+
/** Normalize volatile parts (ARNs, ids, numbers, quoted values) so similar errors group together. */
|
|
283
399
|
export declare function normalizeErrorMessage(message: string): string;
|
|
284
400
|
/** First stack frame that is app code (not node internals or node_modules). */
|
|
285
401
|
export declare function topFrame(stack: string | undefined): string;
|
|
286
|
-
|
|
287
|
-
export declare function fingerprint(parts: readonly string[]): string;
|
|
402
|
+
export { fingerprint } from './fingerprint.ts';
|
|
288
403
|
export declare function errorFingerprint(name: string, message: string, stack?: string): string;
|
package/dist/telemetry.js
CHANGED
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
* filter forwards the interesting kinds to the telemetry processor, which
|
|
5
5
|
* aggregates rollups into the telemetry table. Logs Insights covers the rest
|
|
6
6
|
* (search, traces) on demand. No CloudWatch custom metrics are ever created.
|
|
7
|
+
*
|
|
8
|
+
* CloudWatch Logs bills every byte ingested, so lines leave out what a reader
|
|
9
|
+
* can tell without it (a `path` equal to its `route`, a first `attempt`), and
|
|
10
|
+
* most requests and jobs fold their spans into a count (`traceSampled`).
|
|
7
11
|
*/
|
|
8
12
|
import { Schema } from 'effect';
|
|
9
|
-
|
|
13
|
+
import { fingerprint, fnv1a } from './fingerprint.js';
|
|
14
|
+
export const TelemetryKind = Schema.Literals(['req', 'err', 'job', 'span', 'log', 'metric', 'limit', 'env']);
|
|
10
15
|
const base = {
|
|
11
16
|
/** Marker so the subscription filter only matches platform lines. */
|
|
12
17
|
_p: Schema.Literal(1),
|
|
@@ -20,13 +25,23 @@ const base = {
|
|
|
20
25
|
span: Schema.optional(Schema.String),
|
|
21
26
|
parent: Schema.optional(Schema.String),
|
|
22
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* On a `req` or `job` line: the spans it made (SDK calls, `fetch`es, `traced`
|
|
30
|
+
* units) that weren't written as `span` lines, how many and their total ms.
|
|
31
|
+
* Absent when every span was written. See `TRACE_SAMPLE_RATE`.
|
|
32
|
+
*/
|
|
33
|
+
const unwrittenSpans = {
|
|
34
|
+
calls: Schema.optional(Schema.Finite),
|
|
35
|
+
callMs: Schema.optional(Schema.Finite),
|
|
36
|
+
};
|
|
23
37
|
export const RequestEvent = Schema.Struct({
|
|
24
38
|
...base,
|
|
25
39
|
t: Schema.Literal('req'),
|
|
26
40
|
method: Schema.String,
|
|
27
|
-
/** Route pattern when known (`/api/todos/:id`), else the raw path
|
|
41
|
+
/** Route pattern when known (`/api/todos/:id`), else the raw path with ids as `:id`. */
|
|
28
42
|
route: Schema.String,
|
|
29
|
-
path
|
|
43
|
+
/** The raw path, when it isn't `route`. */
|
|
44
|
+
path: Schema.optional(Schema.String),
|
|
30
45
|
status: Schema.Finite,
|
|
31
46
|
/** Duration in ms. */
|
|
32
47
|
dur: Schema.Finite,
|
|
@@ -35,11 +50,13 @@ export const RequestEvent = Schema.Struct({
|
|
|
35
50
|
/** Hashed user id when signed in. */
|
|
36
51
|
user: Schema.optional(Schema.String),
|
|
37
52
|
cold: Schema.optional(Schema.Boolean),
|
|
53
|
+
...unwrittenSpans,
|
|
38
54
|
});
|
|
39
55
|
export const ErrorEvent = Schema.Struct({
|
|
40
56
|
...base,
|
|
41
57
|
t: Schema.Literal('err'),
|
|
42
|
-
|
|
58
|
+
/** `service`: a long-running service's `run` failed (it is rerun after a backoff). */
|
|
59
|
+
source: Schema.Literals(['http', 'job', 'unhandled', 'log', 'service']),
|
|
43
60
|
name: Schema.String,
|
|
44
61
|
message: Schema.String,
|
|
45
62
|
stack: Schema.optional(Schema.String),
|
|
@@ -47,15 +64,28 @@ export const ErrorEvent = Schema.Struct({
|
|
|
47
64
|
job: Schema.optional(Schema.String),
|
|
48
65
|
fingerprint: Schema.String,
|
|
49
66
|
});
|
|
67
|
+
/**
|
|
68
|
+
* One unit of work. `service` jobs come from long-running services: `<service>`
|
|
69
|
+
* is a run of the service that ended (it is rerun; `dur` is how long it ran),
|
|
70
|
+
* `<service>/<unit>` a unit of work it marked with `traced`.
|
|
71
|
+
*/
|
|
50
72
|
export const JobEvent = Schema.Struct({
|
|
51
73
|
...base,
|
|
52
74
|
t: Schema.Literal('job'),
|
|
53
|
-
kind: Schema.Literals(['queue', 'event', 'cron', 'invoke']),
|
|
75
|
+
kind: Schema.Literals(['queue', 'event', 'cron', 'invoke', 'service']),
|
|
54
76
|
name: Schema.String,
|
|
55
77
|
status: Schema.Literals(['ok', 'error']),
|
|
56
78
|
dur: Schema.Finite,
|
|
79
|
+
/** A queue message's, event's or cron run's attempt, when it isn't the first. */
|
|
57
80
|
attempt: Schema.optional(Schema.Finite),
|
|
81
|
+
/** What happens after a failed run: tried again later, or moved to the dead-letter queue. */
|
|
82
|
+
next: Schema.optional(Schema.Literals(['retry', 'dead'])),
|
|
83
|
+
...unwrittenSpans,
|
|
58
84
|
});
|
|
85
|
+
/**
|
|
86
|
+
* A call a request or job made, written only when its request or job keeps its
|
|
87
|
+
* spans (`TRACE_SAMPLE_RATE`); `parent` is that request's or job's `span`.
|
|
88
|
+
*/
|
|
59
89
|
export const SpanEvent = Schema.Struct({
|
|
60
90
|
...base,
|
|
61
91
|
t: Schema.Literal('span'),
|
|
@@ -81,11 +111,29 @@ export const MetricEvent = Schema.Struct({
|
|
|
81
111
|
value: Schema.Finite,
|
|
82
112
|
unit: Schema.optional(Schema.String),
|
|
83
113
|
});
|
|
114
|
+
/** One `RateLimits` check, and whether the limit let it through. */
|
|
115
|
+
export const LimitEvent = Schema.Struct({
|
|
116
|
+
...base,
|
|
117
|
+
t: Schema.Literal('limit'),
|
|
118
|
+
/** The limit's name (`signups`). Its key (whom it counts) is never sent: it can be a client address. */
|
|
119
|
+
name: Schema.String,
|
|
120
|
+
ok: Schema.Boolean,
|
|
121
|
+
});
|
|
122
|
+
/** A runtime process starting or stopping (`service`: a container of a long-running service). */
|
|
84
123
|
export const EnvEvent = Schema.Struct({
|
|
85
124
|
...base,
|
|
86
125
|
t: Schema.Literal('env'),
|
|
87
126
|
event: Schema.Literals(['start', 'stop']),
|
|
88
|
-
runtime: Schema.Literals(['web', 'worker']),
|
|
127
|
+
runtime: Schema.Literals(['web', 'worker', 'service']),
|
|
128
|
+
/**
|
|
129
|
+
* How a deployed server runs (`runtime: 'web'`): `request`, a function per
|
|
130
|
+
* request, or `instance`, a Web Function environment. Absent under `plat dev`.
|
|
131
|
+
*/
|
|
132
|
+
compute: Schema.optional(Schema.Literals(['request', 'instance'])),
|
|
133
|
+
/** The service's name (`runtime: 'service'`). */
|
|
134
|
+
name: Schema.optional(Schema.String),
|
|
135
|
+
/** Why it stopped, e.g. `SIGTERM`. */
|
|
136
|
+
reason: Schema.optional(Schema.String),
|
|
89
137
|
initMs: Schema.optional(Schema.Finite),
|
|
90
138
|
});
|
|
91
139
|
/** One telemetry line, as the SDK writes it and the telemetry processor reads it. */
|
|
@@ -96,10 +144,33 @@ export const TelemetryEvent = Schema.Union([
|
|
|
96
144
|
SpanEvent,
|
|
97
145
|
LogEvent,
|
|
98
146
|
MetricEvent,
|
|
147
|
+
LimitEvent,
|
|
99
148
|
EnvEvent,
|
|
100
149
|
]);
|
|
101
150
|
/** Account-level subscription filter: only aggregate-worthy kinds reach the processor. */
|
|
102
|
-
export const TELEMETRY_FILTER_PATTERN = '{ ($._p = 1) && (($.t = "req") || ($.t = "err") || ($.t = "job") || ($.t = "metric") || ($.t = "env")) }';
|
|
151
|
+
export const TELEMETRY_FILTER_PATTERN = '{ ($._p = 1) && (($.t = "req") || ($.t = "err") || ($.t = "job") || ($.t = "metric") || ($.t = "limit") || ($.t = "env")) }';
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Span sampling
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
/**
|
|
156
|
+
* A request or job writes its spans when it fails (a 5xx, a failed job, or an
|
|
157
|
+
* `err` line while it runs), takes `SLOW_TRACE_MS` or longer, or its trace is
|
|
158
|
+
* in this share of traces (`traceSampled`). The rest write only their own
|
|
159
|
+
* line, with the spans counted on it (`calls`, `callMs`).
|
|
160
|
+
*/
|
|
161
|
+
export const TRACE_SAMPLE_RATE = 1 / 20;
|
|
162
|
+
/** A request or job that takes this long (ms) or longer writes its spans. */
|
|
163
|
+
export const SLOW_TRACE_MS = 1_000;
|
|
164
|
+
/**
|
|
165
|
+
* Whether `trace` is one of the sampled traces. It depends on the trace id
|
|
166
|
+
* alone, so every hop of a trace (server → queue → worker) makes the same
|
|
167
|
+
* choice. Any string works: a client can send its own `x-platform-trace`.
|
|
168
|
+
*/
|
|
169
|
+
export function traceSampled(trace) {
|
|
170
|
+
// Comparing the hash with a threshold (not `% 20`) keeps a trace sampled at
|
|
171
|
+
// one rate sampled at any higher rate.
|
|
172
|
+
return fnv1a(trace) < TRACE_SAMPLE_RATE * 2 ** 32;
|
|
173
|
+
}
|
|
103
174
|
export function isTelemetryEvent(v) {
|
|
104
175
|
return (typeof v === 'object' &&
|
|
105
176
|
v !== null &&
|
|
@@ -146,28 +217,51 @@ export function bucketStart(ts, res) {
|
|
|
146
217
|
* resolution; `sk` starts with the bucket time so a Query with `BETWEEN`
|
|
147
218
|
* returns a time range.
|
|
148
219
|
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
220
|
+
* Every rollup family is written at `1m`, `1h` and `1d` (`RESOLUTION_TTL_DAYS`).
|
|
221
|
+
* Route, job, custom metric and rate limit rows have had minute buckets only
|
|
222
|
+
* since November 2026; before, they started at `1h`.
|
|
223
|
+
*
|
|
224
|
+
* - `m#<app>#<stage>#<res>` sk `<iso>` whole-stage HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[], cold,
|
|
225
|
+
* dur (ms handling them, summed), and process starts:
|
|
226
|
+
* webStarts (webInits of them reported webInitMs, summed),
|
|
227
|
+
* workerStarts, serviceStarts
|
|
228
|
+
* - `r#<app>#<stage>#<res>` sk `<iso>#<METHOD> <route>` per-route HTTP: req, s2xx, s3xx, s4xx, s5xx, lat[],
|
|
229
|
+
* cold, method, route. Rows from before November 2026 have no
|
|
230
|
+
* s2xx, s3xx or cold: their req − s4xx − s5xx were 2xx
|
|
231
|
+
* - `j#<app>#<stage>#<res>` sk `<iso>#<kind>:<name>` jobs: ok, error, lat[]; `service:<name>` rows also
|
|
232
|
+
* count `starts` (containers of that service starting)
|
|
233
|
+
* - `c#<app>#<stage>#<res>` sk `<iso>#<metric>` custom metrics: count, sum, max (and the unit); rows from
|
|
234
|
+
* before November 2026 have no max
|
|
235
|
+
* - `l#<app>#<stage>#<res>` sk `<iso>#<limit>` rate limit checks: allowed, denied
|
|
153
236
|
* - `e#<app>#<stage>` sk `<fingerprint>` error groups: count, firstSeen, lastSeen, sample, status
|
|
154
|
-
* - `u#<app>#<stage>` sk `<iso>` uptime
|
|
237
|
+
* - `u#<app>#<stage>` sk `<iso>` uptime: ok, source (`traffic`: req, s5xx; `check`, or none on
|
|
238
|
+
* rows before traffic counted: status, ms)
|
|
239
|
+
* - `a#<app>#<stage>` sk `<iso>#<ruleId>` alert rule state changes (`AlertEvent` fields but `ts`),
|
|
240
|
+
* kept `ALERT_HISTORY_DAYS`
|
|
155
241
|
*/
|
|
156
242
|
export const telemetryKeys = {
|
|
157
243
|
stage: (app, stage, res) => `m#${app}#${stage}#${res}`,
|
|
158
244
|
route: (app, stage, res) => `r#${app}#${stage}#${res}`,
|
|
159
245
|
job: (app, stage, res) => `j#${app}#${stage}#${res}`,
|
|
160
246
|
metric: (app, stage, res) => `c#${app}#${stage}#${res}`,
|
|
247
|
+
limit: (app, stage, res) => `l#${app}#${stage}#${res}`,
|
|
161
248
|
errors: (app, stage) => `e#${app}#${stage}`,
|
|
162
249
|
uptime: (app, stage) => `u#${app}#${stage}`,
|
|
250
|
+
alerts: (app, stage) => `a#${app}#${stage}`,
|
|
251
|
+
/**
|
|
252
|
+
* Email usage: sk `YYYY-MM-DD` (UTC), `n` recipients sent. The SDK writes it
|
|
253
|
+
* with the stage role, whose IAM grant covers only this partition.
|
|
254
|
+
*/
|
|
255
|
+
email: (app, stage) => `mail#${app}#${stage}`,
|
|
163
256
|
time: (ts) => new Date(ts).toISOString(),
|
|
164
257
|
};
|
|
165
258
|
// ---------------------------------------------------------------------------
|
|
166
259
|
// Error fingerprinting (Sentry-style grouping)
|
|
167
260
|
// ---------------------------------------------------------------------------
|
|
168
|
-
/** Normalize volatile parts (ids, numbers, quoted values) so similar errors group together. */
|
|
261
|
+
/** Normalize volatile parts (ARNs, ids, numbers, quoted values) so similar errors group together. */
|
|
169
262
|
export function normalizeErrorMessage(message) {
|
|
170
263
|
return message
|
|
264
|
+
.replace(/\barn:aws[\w-]*:[^\s"'`,()]+/g, '<arn>')
|
|
171
265
|
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, '<uuid>')
|
|
172
266
|
.replace(/\b[0-9a-f]{16,}\b/gi, '<hex>')
|
|
173
267
|
.replace(/(["'`]).*?\1/g, '<str>')
|
|
@@ -188,15 +282,7 @@ export function topFrame(stack) {
|
|
|
188
282
|
}
|
|
189
283
|
return '';
|
|
190
284
|
}
|
|
191
|
-
|
|
192
|
-
export function fingerprint(parts) {
|
|
193
|
-
let h = 0x811c9dc5;
|
|
194
|
-
for (const ch of parts.join('|')) {
|
|
195
|
-
h ^= ch.codePointAt(0);
|
|
196
|
-
h = Math.imul(h, 0x01000193) >>> 0;
|
|
197
|
-
}
|
|
198
|
-
return h.toString(16).padStart(8, '0');
|
|
199
|
-
}
|
|
285
|
+
export { fingerprint } from './fingerprint.js';
|
|
200
286
|
export function errorFingerprint(name, message, stack) {
|
|
201
287
|
return fingerprint([name, normalizeErrorMessage(message), topFrame(stack)]);
|
|
202
288
|
}
|