@chrom-ar/collector 0.3.1 → 0.4.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/CHANGELOG.md +11 -0
- package/README.md +47 -0
- package/dist/chunk-YN5N3X7X.js +56 -0
- package/dist/index.cjs +80 -9
- package/dist/index.d.cts +9 -119
- package/dist/index.d.ts +9 -119
- package/dist/index.js +72 -55
- package/dist/rum.cjs +615 -0
- package/dist/rum.d.cts +57 -0
- package/dist/rum.d.ts +57 -0
- package/dist/rum.js +591 -0
- package/dist/types-CTnanJxh.d.cts +178 -0
- package/dist/types-CTnanJxh.d.ts +178 -0
- package/package.json +11 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0 (2026-11-09)
|
|
4
|
+
|
|
5
|
+
- Page speed (RUM), opt-in and in its own import:
|
|
6
|
+
`import { rum } from "@chrom-ar/collector/rum"`, then
|
|
7
|
+
`init({ rum: rum({ sampleRate: 0.1 }) })`. It measures Web Vitals,
|
|
8
|
+
in-app navigation time, requests and slow resources, and sends page views
|
|
9
|
+
in batches (gzipped over 1 KB) when the tab is hidden. Apps without it
|
|
10
|
+
don't ship it.
|
|
11
|
+
- `setRoute(name)` names the current page for RUM.
|
|
12
|
+
- Errors from tabs RUM measures carry the visit's `session`.
|
|
13
|
+
|
|
3
14
|
## 0.3.1 (2026-11-07)
|
|
4
15
|
|
|
5
16
|
- `Collector.test()` sends one test error and resolves to `{ ok: true, id }`
|
package/README.md
CHANGED
|
@@ -165,6 +165,53 @@ Other functions: `setTags(tags)`, `addBreadcrumb({ message, category?, level? })
|
|
|
165
165
|
`flush(timeoutMs?)` (waits until queued events are sent) and `close()`
|
|
166
166
|
(removes everything the SDK installed).
|
|
167
167
|
|
|
168
|
+
## Page speed (RUM)
|
|
169
|
+
|
|
170
|
+
Real User Monitoring shows how fast your pages are for the people using
|
|
171
|
+
them: Web Vitals per page, the slow requests pages make, and single
|
|
172
|
+
visits. It's off by default and ships as a separate import, so apps that
|
|
173
|
+
don't use it don't download it (about 4.5 KB gzipped):
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import * as Collector from "@chrom-ar/collector";
|
|
177
|
+
import { rum } from "@chrom-ar/collector/rum";
|
|
178
|
+
|
|
179
|
+
Collector.init({ dsn: "…", rum: rum({ sampleRate: 0.1 }) });
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
- **Sampling:** `sampleRate` is the share of browser tabs measured,
|
|
183
|
+
decided once per tab. A measured tab sends all its page views.
|
|
184
|
+
- **What's measured:** for page loads, LCP, INP, CLS, TTFB and FCP; for
|
|
185
|
+
in-app navigations to a new path (pushState, LiveView; a new query
|
|
186
|
+
string alone, like a filter or a search box, stays the same page view),
|
|
187
|
+
INP, CLS and a navigation
|
|
188
|
+
time, from the click until the page's requests have finished and the DOM
|
|
189
|
+
has been quiet for half a second (at most 10 s). Plus the page's fetch
|
|
190
|
+
and XHR calls, and for slow pages the slowest resources it loaded.
|
|
191
|
+
- **When it sends:** in batches, when the tab is hidden or closed, and
|
|
192
|
+
every 10 page views or 5 minutes while it stays open. Batches over 1 KB
|
|
193
|
+
are gzipped. If Collector is down or slow, page views are dropped
|
|
194
|
+
quietly; nothing is retried.
|
|
195
|
+
- **Privacy:** no cookies, no user id, no query strings or fragments. A
|
|
196
|
+
random id for the tab's visit, and the tab's sampling decision, are kept
|
|
197
|
+
in `sessionStorage` (key `collector:rum`) and end with the tab. Errors
|
|
198
|
+
from a measured tab carry the visit's id, so an issue links to the visit.
|
|
199
|
+
Collector derives the country and browser and doesn't store the IP or
|
|
200
|
+
user agent. Whether you need consent for analytics is your call.
|
|
201
|
+
- **Routes:** Collector groups pages by guessing which path segments are
|
|
202
|
+
ids (`/orders/81` → `/orders/:id`). If your router knows the route, say
|
|
203
|
+
it after each navigation:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
Collector.setRoute("/orders/:id");
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
or pass `route: (location) => …` to `rum()`. Apps that route in the
|
|
210
|
+
`#hash` need this: fragments are never sent, so every page would
|
|
211
|
+
otherwise be `/`.
|
|
212
|
+
- **Editing or dropping page views:** `rum({ sampleRate, beforeSendPageview(pv) { … return pv; } })`;
|
|
213
|
+
return `null` to drop one.
|
|
214
|
+
|
|
168
215
|
## How errors are grouped
|
|
169
216
|
|
|
170
217
|
Collector groups events into issues by the error type and the functions
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/util.ts
|
|
2
|
+
function uuid4() {
|
|
3
|
+
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
4
|
+
const b = crypto.getRandomValues(new Uint8Array(16));
|
|
5
|
+
b[6] = (b[6] ?? 0) & 15 | 64;
|
|
6
|
+
b[8] = (b[8] ?? 0) & 63 | 128;
|
|
7
|
+
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
8
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
9
|
+
}
|
|
10
|
+
function truncate(s, max) {
|
|
11
|
+
if (s.length <= max) return s;
|
|
12
|
+
const last = s.charCodeAt(max - 1);
|
|
13
|
+
return s.slice(0, last >= 55296 && last <= 56319 ? max - 1 : max);
|
|
14
|
+
}
|
|
15
|
+
function safeStringify(value, max = 8192) {
|
|
16
|
+
return truncate(stringify(value), max);
|
|
17
|
+
}
|
|
18
|
+
function stringify(value) {
|
|
19
|
+
if (typeof value === "string") return value;
|
|
20
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
24
|
+
try {
|
|
25
|
+
return JSON.stringify(value, (_key, v) => {
|
|
26
|
+
if (typeof v === "bigint") return v.toString();
|
|
27
|
+
if (typeof v === "object" && v !== null) {
|
|
28
|
+
if (seen.has(v)) return "[Circular]";
|
|
29
|
+
seen.add(v);
|
|
30
|
+
}
|
|
31
|
+
return v;
|
|
32
|
+
});
|
|
33
|
+
} catch {
|
|
34
|
+
try {
|
|
35
|
+
return String(value);
|
|
36
|
+
} catch {
|
|
37
|
+
return "[unserializable]";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function stripUrl(url) {
|
|
42
|
+
const i = url.search(/[?#]/);
|
|
43
|
+
return i === -1 ? url : url.slice(0, i);
|
|
44
|
+
}
|
|
45
|
+
var MAX_URL = 500;
|
|
46
|
+
function rumUrl(base, url) {
|
|
47
|
+
try {
|
|
48
|
+
const parsed = new URL(url, base);
|
|
49
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
|
|
50
|
+
return (parsed.origin + parsed.pathname).slice(0, MAX_URL);
|
|
51
|
+
} catch {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { rumUrl, safeStringify, stripUrl, truncate, uuid4 };
|
package/dist/index.cjs
CHANGED
|
@@ -11,7 +11,7 @@ function parseDsn(dsn) {
|
|
|
11
11
|
if (parsed.protocol !== "https:" && parsed.protocol !== "http:" || parsed.username === "") return null;
|
|
12
12
|
const base = parsed.origin + parsed.pathname.replace(/\/+$/, "");
|
|
13
13
|
const key = parsed.username;
|
|
14
|
-
return { url: `${base}/api/events?key=${key}`, heartbeatUrl: `${base}/api/heartbeats?key=${key}`, base, key };
|
|
14
|
+
return { url: `${base}/api/events?key=${key}`, heartbeatUrl: `${base}/api/heartbeats?key=${key}`, pageviewsUrl: `${base}/api/pageviews?key=${key}`, base, key };
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// src/util.ts
|
|
@@ -58,6 +58,16 @@ function stripUrl(url) {
|
|
|
58
58
|
const i = url.search(/[?#]/);
|
|
59
59
|
return i === -1 ? url : url.slice(0, i);
|
|
60
60
|
}
|
|
61
|
+
var MAX_URL = 500;
|
|
62
|
+
function rumUrl(base, url) {
|
|
63
|
+
try {
|
|
64
|
+
const parsed = new URL(url, base);
|
|
65
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
|
|
66
|
+
return (parsed.origin + parsed.pathname).slice(0, MAX_URL);
|
|
67
|
+
} catch {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
61
71
|
|
|
62
72
|
// src/stacktrace.ts
|
|
63
73
|
var MAX_FRAMES = 250;
|
|
@@ -211,7 +221,7 @@ function releaseOf(options) {
|
|
|
211
221
|
function environmentOf(options) {
|
|
212
222
|
return typeof options.environment === "string" && options.environment !== "" ? options.environment : void 0;
|
|
213
223
|
}
|
|
214
|
-
function baseEvent({ options, scope: scope2, href, userAgent }, ctx = {}) {
|
|
224
|
+
function baseEvent({ options, scope: scope2, href, userAgent, session }, ctx = {}) {
|
|
215
225
|
const event = {
|
|
216
226
|
v: 1,
|
|
217
227
|
uuid: uuid4(),
|
|
@@ -219,12 +229,13 @@ function baseEvent({ options, scope: scope2, href, userAgent }, ctx = {}) {
|
|
|
219
229
|
platform: "javascript",
|
|
220
230
|
level: toLevel(ctx.level),
|
|
221
231
|
request: { url: options.stripQuery === false ? href : stripUrl(href), headers: { "user-agent": userAgent } },
|
|
222
|
-
sdk: { name: SDK_NAME, version: "0.
|
|
232
|
+
sdk: { name: SDK_NAME, version: "0.4.0" }
|
|
223
233
|
};
|
|
224
234
|
const environment = environmentOf(options);
|
|
225
235
|
if (environment !== void 0) event.environment = environment;
|
|
226
236
|
const release = releaseOf(options);
|
|
227
237
|
if (release !== void 0) event.release = release;
|
|
238
|
+
if (session !== void 0) event.session = session;
|
|
228
239
|
if (ctx.fingerprint && ctx.fingerprint.length > 0) event.fingerprint = ctx.fingerprint.map(String);
|
|
229
240
|
const user = ctx.user ? { id: String(ctx.user.id) } : scope2.user;
|
|
230
241
|
if (user) event.user = user;
|
|
@@ -348,7 +359,7 @@ async function beat({ url, key, fetch, options, logger }) {
|
|
|
348
359
|
if (storedMark(storageKey) === mark || sentThisPage.has(storageKey + mark)) return;
|
|
349
360
|
let status;
|
|
350
361
|
try {
|
|
351
|
-
const body = JSON.stringify({ v: 1, sdk: { name: SDK_NAME, version: "0.
|
|
362
|
+
const body = JSON.stringify({ v: 1, sdk: { name: SDK_NAME, version: "0.4.0" }, environment, release });
|
|
352
363
|
const response = await fetch(url, { method: "POST", body, headers: { "Content-Type": "text/plain;charset=UTF-8" }, keepalive: true, credentials: "omit" });
|
|
353
364
|
({ status } = response);
|
|
354
365
|
} catch (error) {
|
|
@@ -394,6 +405,15 @@ function displayUrl(win, url, stripQuery) {
|
|
|
394
405
|
}
|
|
395
406
|
return stripQuery ? stripUrl(shown) : shown;
|
|
396
407
|
}
|
|
408
|
+
function timeRequest(opts, win, method, url) {
|
|
409
|
+
const target = opts.onRequest ? rumUrl(win.location.href, url) : void 0;
|
|
410
|
+
if (target === void 0) return () => void 0;
|
|
411
|
+
const start = performance.now();
|
|
412
|
+
const token = opts.onRequestStart?.();
|
|
413
|
+
return (status) => {
|
|
414
|
+
opts.onRequest?.({ method: method.toUpperCase(), url: target, status: status ?? 0, start, end: performance.now() }, token);
|
|
415
|
+
};
|
|
416
|
+
}
|
|
397
417
|
function absoluteUrl(win, url) {
|
|
398
418
|
try {
|
|
399
419
|
return new URL(url, win.location.href).href;
|
|
@@ -504,8 +524,10 @@ function instrumentFetch(win, record, opts) {
|
|
|
504
524
|
const { method, url } = describe2(input, init2);
|
|
505
525
|
if (opts.skipUrl(absoluteUrl(win, url))) return;
|
|
506
526
|
const shown = displayUrl(win, url, opts.stripQuery);
|
|
527
|
+
const timing = timeRequest(opts, win, method, url);
|
|
507
528
|
done = (status) => {
|
|
508
529
|
safeRecord(() => {
|
|
530
|
+
timing(status);
|
|
509
531
|
record({ category: "fetch", level: levelForStatus(status), message: requestMessage(method, shown, status) });
|
|
510
532
|
});
|
|
511
533
|
};
|
|
@@ -547,14 +569,24 @@ function instrumentHistory(win, record, opts) {
|
|
|
547
569
|
(original) => function __collectorWrapped(...args) {
|
|
548
570
|
original.apply(this, args);
|
|
549
571
|
moved();
|
|
572
|
+
navigated();
|
|
550
573
|
}
|
|
551
574
|
);
|
|
575
|
+
const navigated = () => {
|
|
576
|
+
safeRecord(() => {
|
|
577
|
+
opts.onNavigate?.();
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
const popped = () => {
|
|
581
|
+
moved();
|
|
582
|
+
navigated();
|
|
583
|
+
};
|
|
552
584
|
const restores = [wrapState("pushState"), wrapState("replaceState")];
|
|
553
|
-
win.addEventListener("popstate",
|
|
585
|
+
win.addEventListener("popstate", popped);
|
|
554
586
|
win.addEventListener("hashchange", moved);
|
|
555
587
|
return () => {
|
|
556
588
|
if (!restores.map((restore) => restore()).every(Boolean)) return false;
|
|
557
|
-
win.removeEventListener("popstate",
|
|
589
|
+
win.removeEventListener("popstate", popped);
|
|
558
590
|
win.removeEventListener("hashchange", moved);
|
|
559
591
|
return true;
|
|
560
592
|
};
|
|
@@ -585,9 +617,11 @@ function instrumentXhr(win, record, opts) {
|
|
|
585
617
|
const request = requests.get(this);
|
|
586
618
|
if (!request || opts.skipUrl(absoluteUrl(win, request.url))) return;
|
|
587
619
|
const shown = displayUrl(win, request.url, opts.stripQuery);
|
|
620
|
+
const timing = timeRequest(opts, win, request.method, request.url);
|
|
588
621
|
this.addEventListener("loadend", () => {
|
|
589
622
|
safeRecord(() => {
|
|
590
623
|
const status = this.status !== 0 ? this.status : void 0;
|
|
624
|
+
timing(status);
|
|
591
625
|
record({ category: "xhr", level: levelForStatus(status), message: requestMessage(request.method, shown, status) });
|
|
592
626
|
});
|
|
593
627
|
}, { once: true });
|
|
@@ -891,8 +925,16 @@ var sharedOptions = {
|
|
|
891
925
|
skipUrl: (url) => active?.isOwnUrl(url) ?? false,
|
|
892
926
|
get stripQuery() {
|
|
893
927
|
return active?.options.stripQuery !== false;
|
|
928
|
+
},
|
|
929
|
+
onRequestStart: () => active?.rum?.requestStart(),
|
|
930
|
+
onRequest: (timing, token) => {
|
|
931
|
+
active?.rum?.request(timing, token);
|
|
932
|
+
},
|
|
933
|
+
onNavigate: () => {
|
|
934
|
+
active?.rum?.navigate();
|
|
894
935
|
}
|
|
895
936
|
};
|
|
937
|
+
var RUM_KINDS = /* @__PURE__ */ new Set(["fetch", "xhr", "history"]);
|
|
896
938
|
var rejected = /* @__PURE__ */ new Set();
|
|
897
939
|
var recorderFor = (kind) => (crumb) => {
|
|
898
940
|
if (active && active.options.breadcrumbs?.[kind] !== false) active.addBreadcrumb(crumb);
|
|
@@ -947,9 +989,17 @@ var Client = class {
|
|
|
947
989
|
)
|
|
948
990
|
);
|
|
949
991
|
}
|
|
992
|
+
if (options.rum && !this.transport.disabled) {
|
|
993
|
+
try {
|
|
994
|
+
this.rum = options.rum.start({ win, url: endpoint.pageviewsUrl, fetch: fetchFn, logger: this.logger, options, sdk: { name: SDK_NAME, version: "0.4.0" }, environment: environmentOf(options), release: releaseOf(options) });
|
|
995
|
+
} catch (error) {
|
|
996
|
+
this.logger.debug("RUM didn't start", error);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
950
999
|
active = this;
|
|
951
1000
|
for (const [kind, instrument] of Object.entries(INSTRUMENTS)) {
|
|
952
|
-
|
|
1001
|
+
const needed = options.breadcrumbs?.[kind] !== false || this.rum !== void 0 && RUM_KINDS.has(kind);
|
|
1002
|
+
if (!needed || installed.has(kind)) continue;
|
|
953
1003
|
try {
|
|
954
1004
|
installed.set(kind, instrument(win, recorderFor(kind), sharedOptions));
|
|
955
1005
|
} catch (error) {
|
|
@@ -1023,6 +1073,10 @@ var Client = class {
|
|
|
1023
1073
|
async flush(timeoutMs) {
|
|
1024
1074
|
return this.transport ? this.transport.flush(timeoutMs) : Promise.resolve(true);
|
|
1025
1075
|
}
|
|
1076
|
+
/** Names the current RUM page view. Does nothing without RUM. */
|
|
1077
|
+
setRoute(name) {
|
|
1078
|
+
this.rum?.setRoute(name);
|
|
1079
|
+
}
|
|
1026
1080
|
/** True for requests to Collector itself. */
|
|
1027
1081
|
isOwnUrl(url) {
|
|
1028
1082
|
return this.endpointBase !== void 0 && url.startsWith(`${this.endpointBase}/`);
|
|
@@ -1030,6 +1084,11 @@ var Client = class {
|
|
|
1030
1084
|
/** Removes every listener and wrapper it can. Events already queued still go out. */
|
|
1031
1085
|
close() {
|
|
1032
1086
|
this.closed = true;
|
|
1087
|
+
try {
|
|
1088
|
+
this.rum?.close();
|
|
1089
|
+
} catch (error) {
|
|
1090
|
+
this.logger.debug("RUM didn't close cleanly", error);
|
|
1091
|
+
}
|
|
1033
1092
|
if (active === this) {
|
|
1034
1093
|
active = void 0;
|
|
1035
1094
|
for (const [kind, restore] of installed) {
|
|
@@ -1054,7 +1113,8 @@ var Client = class {
|
|
|
1054
1113
|
scope: this.scope,
|
|
1055
1114
|
origin: win.location.origin,
|
|
1056
1115
|
href: win.location.href,
|
|
1057
|
-
userAgent: win.navigator.userAgent
|
|
1116
|
+
userAgent: win.navigator.userAgent,
|
|
1117
|
+
session: this.rum?.session
|
|
1058
1118
|
};
|
|
1059
1119
|
}
|
|
1060
1120
|
capture(build) {
|
|
@@ -1100,8 +1160,9 @@ var Client = class {
|
|
|
1100
1160
|
};
|
|
1101
1161
|
|
|
1102
1162
|
// src/index.ts
|
|
1103
|
-
var SDK_VERSION = "0.
|
|
1163
|
+
var SDK_VERSION = "0.4.0";
|
|
1104
1164
|
var client;
|
|
1165
|
+
var pendingRoute;
|
|
1105
1166
|
var pendingScope = new Scope();
|
|
1106
1167
|
function scope() {
|
|
1107
1168
|
return client?.scope ?? pendingScope;
|
|
@@ -1120,6 +1181,8 @@ function init(options) {
|
|
|
1120
1181
|
const kept = scope();
|
|
1121
1182
|
client?.close();
|
|
1122
1183
|
client = new Client(options, window, kept);
|
|
1184
|
+
if (pendingRoute) client.setRoute(pendingRoute.name);
|
|
1185
|
+
pendingRoute = void 0;
|
|
1123
1186
|
if (options.debug === true) Object.defineProperty(window, CONSOLE_HANDLE, { value: { test }, configurable: true, writable: true });
|
|
1124
1187
|
else Reflect.deleteProperty(window, CONSOLE_HANDLE);
|
|
1125
1188
|
}, void 0);
|
|
@@ -1163,11 +1226,18 @@ function addBreadcrumb(crumb) {
|
|
|
1163
1226
|
async function flush(timeoutMs) {
|
|
1164
1227
|
return safely(async () => client?.flush(timeoutMs) ?? Promise.resolve(true), Promise.resolve(false));
|
|
1165
1228
|
}
|
|
1229
|
+
function setRoute(name) {
|
|
1230
|
+
safely(() => {
|
|
1231
|
+
if (client) client.setRoute(name);
|
|
1232
|
+
else pendingRoute = { name };
|
|
1233
|
+
}, void 0);
|
|
1234
|
+
}
|
|
1166
1235
|
function close() {
|
|
1167
1236
|
safely(() => {
|
|
1168
1237
|
client?.close();
|
|
1169
1238
|
client = void 0;
|
|
1170
1239
|
pendingScope = new Scope();
|
|
1240
|
+
pendingRoute = void 0;
|
|
1171
1241
|
if (typeof window !== "undefined") Reflect.deleteProperty(window, CONSOLE_HANDLE);
|
|
1172
1242
|
}, void 0);
|
|
1173
1243
|
}
|
|
@@ -1179,6 +1249,7 @@ exports.captureMessage = captureMessage;
|
|
|
1179
1249
|
exports.close = close;
|
|
1180
1250
|
exports.flush = flush;
|
|
1181
1251
|
exports.init = init;
|
|
1252
|
+
exports.setRoute = setRoute;
|
|
1182
1253
|
exports.setTag = setTag;
|
|
1183
1254
|
exports.setTags = setTags;
|
|
1184
1255
|
exports.setUser = setUser;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,120 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** One stack frame, innermost first, as the protocol defines it. */
|
|
4
|
-
interface Frame {
|
|
5
|
-
/** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
|
|
6
|
-
module: string;
|
|
7
|
-
/** Function name, or `"?"` for anonymous functions. */
|
|
8
|
-
function: string;
|
|
9
|
-
/** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
|
|
10
|
-
file: string;
|
|
11
|
-
line?: number;
|
|
12
|
-
column?: number;
|
|
13
|
-
/** True for the app's own code; this decides how errors group into issues. */
|
|
14
|
-
in_app: boolean;
|
|
15
|
-
}
|
|
16
|
-
/** Something that happened before an error: a click, a request, a log line. */
|
|
17
|
-
interface Breadcrumb {
|
|
18
|
-
/** ISO 8601; set to now when missing. */
|
|
19
|
-
timestamp?: string;
|
|
20
|
-
level?: Level;
|
|
21
|
-
/** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
|
|
22
|
-
category?: string;
|
|
23
|
-
message: string;
|
|
24
|
-
}
|
|
25
|
-
/** An event as sent to Collector (protocol v1). */
|
|
26
|
-
interface CollectorEvent {
|
|
27
|
-
v: 1;
|
|
28
|
-
uuid: string;
|
|
29
|
-
timestamp: string;
|
|
30
|
-
platform: "javascript";
|
|
31
|
-
level: Level;
|
|
32
|
-
environment?: string;
|
|
33
|
-
release?: string;
|
|
34
|
-
exception?: {
|
|
35
|
-
type: string;
|
|
36
|
-
message?: string;
|
|
37
|
-
frames?: Frame[];
|
|
38
|
-
};
|
|
39
|
-
message?: string;
|
|
40
|
-
fingerprint?: string[];
|
|
41
|
-
request?: {
|
|
42
|
-
url: string;
|
|
43
|
-
headers: Record<string, string>;
|
|
44
|
-
};
|
|
45
|
-
user?: {
|
|
46
|
-
id: string;
|
|
47
|
-
};
|
|
48
|
-
tags?: Record<string, string>;
|
|
49
|
-
breadcrumbs?: Breadcrumb[];
|
|
50
|
-
sdk: {
|
|
51
|
-
name: string;
|
|
52
|
-
version: string;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
|
|
56
|
-
interface CaptureContext {
|
|
57
|
-
level?: Level;
|
|
58
|
-
tags?: Record<string, string>;
|
|
59
|
-
/** Overrides how Collector groups this event into an issue. */
|
|
60
|
-
fingerprint?: string[];
|
|
61
|
-
user?: {
|
|
62
|
-
id: string | number;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/** What `test()` resolves to: the event's id, or why it wasn't accepted. */
|
|
66
|
-
type TestResult = {
|
|
67
|
-
ok: true;
|
|
68
|
-
id: string;
|
|
69
|
-
} | {
|
|
70
|
-
ok: false;
|
|
71
|
-
reason: string;
|
|
72
|
-
};
|
|
73
|
-
type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
|
|
74
|
-
interface CollectorOptions {
|
|
75
|
-
/** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
|
|
76
|
-
dsn?: string;
|
|
77
|
-
/** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
|
|
78
|
-
environment?: string;
|
|
79
|
-
/** Your app's version or git sha, e.g. `"web@1.4.2"`. */
|
|
80
|
-
release?: string;
|
|
81
|
-
/** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
|
|
82
|
-
debug?: boolean;
|
|
83
|
-
/** Set to `false` to turn the SDK off entirely. Default `true`. */
|
|
84
|
-
enabled?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Last chance to edit or drop an event before it's sent. Return the event
|
|
87
|
-
* (changed or not) to send it, or `null` to drop it.
|
|
88
|
-
*/
|
|
89
|
-
beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
|
|
90
|
-
/**
|
|
91
|
-
* Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
|
|
92
|
-
* tested against it. Added to the built-in list of well-known browser noise.
|
|
93
|
-
*/
|
|
94
|
-
ignoreErrors?: (string | RegExp)[];
|
|
95
|
-
/**
|
|
96
|
-
* Which script URLs are your app's own code. When set, a frame is in-app only
|
|
97
|
-
* if its URL matches. Default: same origin as the page, except vendor chunks.
|
|
98
|
-
*/
|
|
99
|
-
inAppUrls?: (string | RegExp)[];
|
|
100
|
-
/** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
|
|
101
|
-
stripQuery?: boolean;
|
|
102
|
-
/** Which breadcrumbs to record automatically. All on by default. */
|
|
103
|
-
breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
|
|
104
|
-
/** How many breadcrumbs to keep. Default `50`. */
|
|
105
|
-
maxBreadcrumbs?: number;
|
|
106
|
-
/**
|
|
107
|
-
* Tell Collector once a day that the app is running (its release and
|
|
108
|
-
* environment, nothing about the user), so it shows as set up before any
|
|
109
|
-
* error. Default `true`.
|
|
110
|
-
*/
|
|
111
|
-
heartbeat?: boolean;
|
|
112
|
-
/** Report uncaught errors and unhandled promise rejections. Default: both on. */
|
|
113
|
-
autoCapture?: false | {
|
|
114
|
-
onerror?: boolean;
|
|
115
|
-
onunhandledrejection?: boolean;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
import { B as Breadcrumb, C as CaptureContext, L as Level, a as CollectorOptions, T as TestResult } from './types-CTnanJxh.cjs';
|
|
2
|
+
export { b as BreadcrumbKind, c as CollectorEvent, F as Frame, R as RequestTiming, d as RumContext, e as RumHandle, f as RumPlugin } from './types-CTnanJxh.cjs';
|
|
118
3
|
|
|
119
4
|
/** The version of this SDK, as sent in every event's `sdk.version`. */
|
|
120
5
|
declare const SDK_VERSION: string;
|
|
@@ -158,8 +43,13 @@ declare function setTags(tags: Record<string, string>): void;
|
|
|
158
43
|
declare function addBreadcrumb(crumb: Breadcrumb): void;
|
|
159
44
|
/** Waits until queued events are sent. Resolves `false` if `timeoutMs` (default 2000) passes first. */
|
|
160
45
|
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Names the current page for RUM, e.g. `setRoute("/products/:id")`, so
|
|
48
|
+
* pages group by route instead of by Collector's guess. Call it after the
|
|
49
|
+
* URL changes; it names that page view only. Does nothing without RUM.
|
|
50
|
+
*/
|
|
51
|
+
declare function setRoute(name: string | undefined): void;
|
|
161
52
|
/** Stops capturing and removes everything the SDK installed. */
|
|
162
53
|
declare function close(): void;
|
|
163
54
|
|
|
164
|
-
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, init, setTag, setTags, setUser, test };
|
|
165
|
-
export type { Breadcrumb, BreadcrumbKind, CaptureContext, CollectorEvent, CollectorOptions, Frame, Level, TestResult };
|
|
55
|
+
export { Breadcrumb, CaptureContext, CollectorOptions, Level, SDK_VERSION, TestResult, addBreadcrumb, captureException, captureMessage, close, flush, init, setRoute, setTag, setTags, setUser, test };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,120 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** One stack frame, innermost first, as the protocol defines it. */
|
|
4
|
-
interface Frame {
|
|
5
|
-
/** Script path with content hashes removed, e.g. `/assets/index.js`. Used for grouping. */
|
|
6
|
-
module: string;
|
|
7
|
-
/** Function name, or `"?"` for anonymous functions. */
|
|
8
|
-
function: string;
|
|
9
|
-
/** Script path as loaded, e.g. `/assets/index-a1b2c3d4.js`. Shown, not grouped on. */
|
|
10
|
-
file: string;
|
|
11
|
-
line?: number;
|
|
12
|
-
column?: number;
|
|
13
|
-
/** True for the app's own code; this decides how errors group into issues. */
|
|
14
|
-
in_app: boolean;
|
|
15
|
-
}
|
|
16
|
-
/** Something that happened before an error: a click, a request, a log line. */
|
|
17
|
-
interface Breadcrumb {
|
|
18
|
-
/** ISO 8601; set to now when missing. */
|
|
19
|
-
timestamp?: string;
|
|
20
|
-
level?: Level;
|
|
21
|
-
/** e.g. `ui.click`, `fetch`, `xhr`, `navigation`, `console`. */
|
|
22
|
-
category?: string;
|
|
23
|
-
message: string;
|
|
24
|
-
}
|
|
25
|
-
/** An event as sent to Collector (protocol v1). */
|
|
26
|
-
interface CollectorEvent {
|
|
27
|
-
v: 1;
|
|
28
|
-
uuid: string;
|
|
29
|
-
timestamp: string;
|
|
30
|
-
platform: "javascript";
|
|
31
|
-
level: Level;
|
|
32
|
-
environment?: string;
|
|
33
|
-
release?: string;
|
|
34
|
-
exception?: {
|
|
35
|
-
type: string;
|
|
36
|
-
message?: string;
|
|
37
|
-
frames?: Frame[];
|
|
38
|
-
};
|
|
39
|
-
message?: string;
|
|
40
|
-
fingerprint?: string[];
|
|
41
|
-
request?: {
|
|
42
|
-
url: string;
|
|
43
|
-
headers: Record<string, string>;
|
|
44
|
-
};
|
|
45
|
-
user?: {
|
|
46
|
-
id: string;
|
|
47
|
-
};
|
|
48
|
-
tags?: Record<string, string>;
|
|
49
|
-
breadcrumbs?: Breadcrumb[];
|
|
50
|
-
sdk: {
|
|
51
|
-
name: string;
|
|
52
|
-
version: string;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
/** Extra details for one captured event. They merge over what `setUser`/`setTag` set. */
|
|
56
|
-
interface CaptureContext {
|
|
57
|
-
level?: Level;
|
|
58
|
-
tags?: Record<string, string>;
|
|
59
|
-
/** Overrides how Collector groups this event into an issue. */
|
|
60
|
-
fingerprint?: string[];
|
|
61
|
-
user?: {
|
|
62
|
-
id: string | number;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/** What `test()` resolves to: the event's id, or why it wasn't accepted. */
|
|
66
|
-
type TestResult = {
|
|
67
|
-
ok: true;
|
|
68
|
-
id: string;
|
|
69
|
-
} | {
|
|
70
|
-
ok: false;
|
|
71
|
-
reason: string;
|
|
72
|
-
};
|
|
73
|
-
type BreadcrumbKind = "console" | "dom" | "fetch" | "xhr" | "history";
|
|
74
|
-
interface CollectorOptions {
|
|
75
|
-
/** Your project's DSN, from its setup page in Collector. Without it, nothing is sent. */
|
|
76
|
-
dsn?: string;
|
|
77
|
-
/** e.g. `"production"`, `"staging"`. Issues are counted per environment. */
|
|
78
|
-
environment?: string;
|
|
79
|
-
/** Your app's version or git sha, e.g. `"web@1.4.2"`. */
|
|
80
|
-
release?: string;
|
|
81
|
-
/** Logs what the SDK does to the console, prefixed `[collector]`. Default `false`. */
|
|
82
|
-
debug?: boolean;
|
|
83
|
-
/** Set to `false` to turn the SDK off entirely. Default `true`. */
|
|
84
|
-
enabled?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Last chance to edit or drop an event before it's sent. Return the event
|
|
87
|
-
* (changed or not) to send it, or `null` to drop it.
|
|
88
|
-
*/
|
|
89
|
-
beforeSend?: (event: CollectorEvent) => CollectorEvent | null;
|
|
90
|
-
/**
|
|
91
|
-
* Errors to ignore: strings match anywhere in `"Type: message"`, regexps are
|
|
92
|
-
* tested against it. Added to the built-in list of well-known browser noise.
|
|
93
|
-
*/
|
|
94
|
-
ignoreErrors?: (string | RegExp)[];
|
|
95
|
-
/**
|
|
96
|
-
* Which script URLs are your app's own code. When set, a frame is in-app only
|
|
97
|
-
* if its URL matches. Default: same origin as the page, except vendor chunks.
|
|
98
|
-
*/
|
|
99
|
-
inAppUrls?: (string | RegExp)[];
|
|
100
|
-
/** Remove `?query` and `#hash` from URLs sent to Collector. Default `true`. */
|
|
101
|
-
stripQuery?: boolean;
|
|
102
|
-
/** Which breadcrumbs to record automatically. All on by default. */
|
|
103
|
-
breadcrumbs?: Partial<Record<BreadcrumbKind, boolean>>;
|
|
104
|
-
/** How many breadcrumbs to keep. Default `50`. */
|
|
105
|
-
maxBreadcrumbs?: number;
|
|
106
|
-
/**
|
|
107
|
-
* Tell Collector once a day that the app is running (its release and
|
|
108
|
-
* environment, nothing about the user), so it shows as set up before any
|
|
109
|
-
* error. Default `true`.
|
|
110
|
-
*/
|
|
111
|
-
heartbeat?: boolean;
|
|
112
|
-
/** Report uncaught errors and unhandled promise rejections. Default: both on. */
|
|
113
|
-
autoCapture?: false | {
|
|
114
|
-
onerror?: boolean;
|
|
115
|
-
onunhandledrejection?: boolean;
|
|
116
|
-
};
|
|
117
|
-
}
|
|
1
|
+
import { B as Breadcrumb, C as CaptureContext, L as Level, a as CollectorOptions, T as TestResult } from './types-CTnanJxh.js';
|
|
2
|
+
export { b as BreadcrumbKind, c as CollectorEvent, F as Frame, R as RequestTiming, d as RumContext, e as RumHandle, f as RumPlugin } from './types-CTnanJxh.js';
|
|
118
3
|
|
|
119
4
|
/** The version of this SDK, as sent in every event's `sdk.version`. */
|
|
120
5
|
declare const SDK_VERSION: string;
|
|
@@ -158,8 +43,13 @@ declare function setTags(tags: Record<string, string>): void;
|
|
|
158
43
|
declare function addBreadcrumb(crumb: Breadcrumb): void;
|
|
159
44
|
/** Waits until queued events are sent. Resolves `false` if `timeoutMs` (default 2000) passes first. */
|
|
160
45
|
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Names the current page for RUM, e.g. `setRoute("/products/:id")`, so
|
|
48
|
+
* pages group by route instead of by Collector's guess. Call it after the
|
|
49
|
+
* URL changes; it names that page view only. Does nothing without RUM.
|
|
50
|
+
*/
|
|
51
|
+
declare function setRoute(name: string | undefined): void;
|
|
161
52
|
/** Stops capturing and removes everything the SDK installed. */
|
|
162
53
|
declare function close(): void;
|
|
163
54
|
|
|
164
|
-
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, init, setTag, setTags, setUser, test };
|
|
165
|
-
export type { Breadcrumb, BreadcrumbKind, CaptureContext, CollectorEvent, CollectorOptions, Frame, Level, TestResult };
|
|
55
|
+
export { Breadcrumb, CaptureContext, CollectorOptions, Level, SDK_VERSION, TestResult, addBreadcrumb, captureException, captureMessage, close, flush, init, setRoute, setTag, setTags, setUser, test };
|