@chrom-ar/collector 0.3.1 → 0.5.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 +39 -0
- package/README.md +140 -22
- package/dist/chunk-42XODVHT.js +63 -0
- package/dist/collector.esm.js +7 -0
- package/dist/index.cjs +203 -42
- package/dist/index.d.cts +18 -121
- package/dist/index.d.ts +18 -121
- package/dist/index.js +187 -87
- package/dist/rum.cjs +645 -0
- package/dist/rum.d.cts +63 -0
- package/dist/rum.d.ts +63 -0
- package/dist/rum.esm.js +2 -0
- package/dist/rum.js +614 -0
- package/dist/types-ml-o_-mr.d.cts +183 -0
- package/dist/types-ml-o_-mr.d.ts +183 -0
- package/package.json +19 -5
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,20 @@ 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
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/self.ts
|
|
73
|
+
var file;
|
|
74
|
+
var sdkFile = () => file;
|
|
61
75
|
|
|
62
76
|
// src/stacktrace.ts
|
|
63
77
|
var MAX_FRAMES = 250;
|
|
@@ -144,7 +158,7 @@ function toFrames(raw, opts) {
|
|
|
144
158
|
}
|
|
145
159
|
return frames;
|
|
146
160
|
}
|
|
147
|
-
function toFrame(raw, { origin, inAppUrls }) {
|
|
161
|
+
function toFrame(raw, { origin, inAppUrls, classify, sdkFile: sdkFile2 }) {
|
|
148
162
|
let url;
|
|
149
163
|
try {
|
|
150
164
|
url = new URL(raw.url, origin);
|
|
@@ -153,10 +167,16 @@ function toFrame(raw, { origin, inAppUrls }) {
|
|
|
153
167
|
}
|
|
154
168
|
const webpackInternal = raw.url.startsWith("webpack-internal://");
|
|
155
169
|
const sameOrigin = url?.origin === origin || webpackInternal;
|
|
156
|
-
let
|
|
157
|
-
if (url && !webpackInternal)
|
|
158
|
-
const inApp =
|
|
159
|
-
|
|
170
|
+
let file2 = stripUrl(raw.url);
|
|
171
|
+
if (url && !webpackInternal) file2 = sameOrigin ? url.pathname : stripUrl(url.href);
|
|
172
|
+
const inApp = isInApp();
|
|
173
|
+
function isInApp() {
|
|
174
|
+
if (inAppUrls) return inAppUrls.some((p) => typeof p === "string" ? raw.url.includes(p) : p.test(raw.url));
|
|
175
|
+
const verdict = url === void 0 ? void 0 : classify?.(url.href);
|
|
176
|
+
if (verdict !== void 0) return verdict === "app";
|
|
177
|
+
return sameOrigin && !isExtensionUrl(raw.url) && !VENDOR_PATTERNS.some((p) => p.test(file2));
|
|
178
|
+
}
|
|
179
|
+
const frame = { module: normalizeModule(file2), function: raw.function ?? "?", file: file2, in_app: inApp };
|
|
160
180
|
if (raw.line !== void 0) frame.line = raw.line;
|
|
161
181
|
if (raw.column !== void 0) frame.column = raw.column;
|
|
162
182
|
return frame;
|
|
@@ -185,7 +205,7 @@ function errorType(error) {
|
|
|
185
205
|
function eventFromException(error, env, ctx, mechanism = "manual") {
|
|
186
206
|
const event = baseEvent(env, ctx);
|
|
187
207
|
if (isErrorLike(error)) {
|
|
188
|
-
const frames = typeof error.stack === "string" ? toFrames(parseStack(error.stack), { origin: env.origin, inAppUrls: env.options.inAppUrls }) : [];
|
|
208
|
+
const frames = typeof error.stack === "string" ? toFrames(parseStack(error.stack), { origin: env.origin, inAppUrls: env.options.inAppUrls, classify: env.classify, sdkFile: sdkFile() }) : [];
|
|
189
209
|
event.exception = { type: errorType(error), message: truncate(String(error.message), MAX_MESSAGE) };
|
|
190
210
|
if (frames.length > 0) event.exception.frames = frames;
|
|
191
211
|
} else {
|
|
@@ -211,7 +231,7 @@ function releaseOf(options) {
|
|
|
211
231
|
function environmentOf(options) {
|
|
212
232
|
return typeof options.environment === "string" && options.environment !== "" ? options.environment : void 0;
|
|
213
233
|
}
|
|
214
|
-
function baseEvent({ options, scope: scope2, href, userAgent }, ctx = {}) {
|
|
234
|
+
function baseEvent({ options, scope: scope2, href, userAgent, session }, ctx = {}) {
|
|
215
235
|
const event = {
|
|
216
236
|
v: 1,
|
|
217
237
|
uuid: uuid4(),
|
|
@@ -219,12 +239,13 @@ function baseEvent({ options, scope: scope2, href, userAgent }, ctx = {}) {
|
|
|
219
239
|
platform: "javascript",
|
|
220
240
|
level: toLevel(ctx.level),
|
|
221
241
|
request: { url: options.stripQuery === false ? href : stripUrl(href), headers: { "user-agent": userAgent } },
|
|
222
|
-
sdk: { name: SDK_NAME, version: "0.
|
|
242
|
+
sdk: { name: SDK_NAME, version: "0.5.0" }
|
|
223
243
|
};
|
|
224
244
|
const environment = environmentOf(options);
|
|
225
245
|
if (environment !== void 0) event.environment = environment;
|
|
226
246
|
const release = releaseOf(options);
|
|
227
247
|
if (release !== void 0) event.release = release;
|
|
248
|
+
if (session !== void 0) event.session = session;
|
|
228
249
|
if (ctx.fingerprint && ctx.fingerprint.length > 0) event.fingerprint = ctx.fingerprint.map(String);
|
|
229
250
|
const user = ctx.user ? { id: String(ctx.user.id) } : scope2.user;
|
|
230
251
|
if (user) event.user = user;
|
|
@@ -315,6 +336,52 @@ function errorFromLocation(e) {
|
|
|
315
336
|
return error;
|
|
316
337
|
}
|
|
317
338
|
|
|
339
|
+
// src/meta.ts
|
|
340
|
+
function readMeta(name) {
|
|
341
|
+
if (typeof document === "undefined") return void 0;
|
|
342
|
+
const content = document.querySelector(`meta[name="${name}"]`)?.content.trim();
|
|
343
|
+
return content === void 0 || content === "" ? void 0 : content;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/importmap.ts
|
|
347
|
+
var isBare = (specifier) => !/^(?:\.{0,2}\/|[a-z][a-z\d+.-]*:)/i.test(specifier);
|
|
348
|
+
function pinsOf(doc) {
|
|
349
|
+
const script = doc.querySelector('script[type="importmap"]');
|
|
350
|
+
const text = script?.textContent;
|
|
351
|
+
if (text === void 0 || text === "") return void 0;
|
|
352
|
+
let map;
|
|
353
|
+
try {
|
|
354
|
+
map = JSON.parse(text);
|
|
355
|
+
} catch {
|
|
356
|
+
return void 0;
|
|
357
|
+
}
|
|
358
|
+
const imports = typeof map === "object" && map !== null && "imports" in map ? map.imports : void 0;
|
|
359
|
+
if (typeof imports !== "object" || imports === null) return void 0;
|
|
360
|
+
const pins = [];
|
|
361
|
+
for (const [specifier, target] of Object.entries(imports)) {
|
|
362
|
+
if (typeof target !== "string" || !isBare(specifier)) continue;
|
|
363
|
+
try {
|
|
364
|
+
pins.push({ specifier, url: stripUrl(new URL(target, doc.baseURI).href), prefix: specifier.endsWith("/") });
|
|
365
|
+
} catch {
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return pins.sort((a, b) => a.prefix === b.prefix ? b.url.length - a.url.length : Number(a.prefix) - Number(b.prefix));
|
|
369
|
+
}
|
|
370
|
+
var listed = (list, specifier) => list.some((entry) => entry === specifier || entry.endsWith("/") && specifier.startsWith(entry));
|
|
371
|
+
function importMapClassifier(doc, origin) {
|
|
372
|
+
const pins = pinsOf(doc);
|
|
373
|
+
if (!pins || pins.length === 0) return void 0;
|
|
374
|
+
const own = readMeta("collector-in-app")?.split(/[\s,]+/).filter((entry) => entry !== "");
|
|
375
|
+
return (url) => {
|
|
376
|
+
const clean = stripUrl(url);
|
|
377
|
+
const pin = pins.find((p) => p.prefix ? clean.startsWith(p.url) : clean === p.url);
|
|
378
|
+
if (!pin) return void 0;
|
|
379
|
+
const specifier = pin.prefix ? pin.specifier + clean.slice(pin.url.length) : pin.specifier;
|
|
380
|
+
if (own) return listed(own, specifier) ? "app" : "dependency";
|
|
381
|
+
return specifier.startsWith("@") || !pin.url.startsWith(`${origin}/`) ? "dependency" : void 0;
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
318
385
|
// src/heartbeat.ts
|
|
319
386
|
var HEARTBEAT_DELAY_MS = 5e3;
|
|
320
387
|
var STORAGE_PREFIX = "collector:heartbeat:";
|
|
@@ -348,7 +415,7 @@ async function beat({ url, key, fetch, options, logger }) {
|
|
|
348
415
|
if (storedMark(storageKey) === mark || sentThisPage.has(storageKey + mark)) return;
|
|
349
416
|
let status;
|
|
350
417
|
try {
|
|
351
|
-
const body = JSON.stringify({ v: 1, sdk: { name: SDK_NAME, version: "0.
|
|
418
|
+
const body = JSON.stringify({ v: 1, sdk: { name: SDK_NAME, version: "0.5.0" }, environment, release });
|
|
352
419
|
const response = await fetch(url, { method: "POST", body, headers: { "Content-Type": "text/plain;charset=UTF-8" }, keepalive: true, credentials: "omit" });
|
|
353
420
|
({ status } = response);
|
|
354
421
|
} catch (error) {
|
|
@@ -363,6 +430,33 @@ async function beat({ url, key, fetch, options, logger }) {
|
|
|
363
430
|
}
|
|
364
431
|
}
|
|
365
432
|
|
|
433
|
+
// src/describe.ts
|
|
434
|
+
var MAX_KEYS = 10;
|
|
435
|
+
var MAX_STRING = 100;
|
|
436
|
+
function describeValue(value, nested = false) {
|
|
437
|
+
if (typeof value === "string") return nested ? JSON.stringify(truncate(value, MAX_STRING)) : value;
|
|
438
|
+
if (value === null || typeof value !== "object") {
|
|
439
|
+
return typeof value === "function" ? `[Function ${value.name !== "" ? value.name : "anonymous"}]` : String(value);
|
|
440
|
+
}
|
|
441
|
+
const v = value;
|
|
442
|
+
if (value instanceof Error || typeof v.message === "string" && typeof v.name === "string") {
|
|
443
|
+
return `${String(v.name)}: ${String(v.message)}`;
|
|
444
|
+
}
|
|
445
|
+
if (typeof v.nodeType === "number") return typeof v.tagName === "string" ? `<${v.tagName.toLowerCase()}>` : "[Node]";
|
|
446
|
+
if (nested) return Array.isArray(value) ? `[Array(${String(value.length)})]` : "{\u2026}";
|
|
447
|
+
if (Array.isArray(value)) {
|
|
448
|
+
const items = value.slice(0, MAX_KEYS).map((x) => describeValue(x, true));
|
|
449
|
+
return `[${items.join(", ")}${value.length > MAX_KEYS ? ", \u2026" : ""}]`;
|
|
450
|
+
}
|
|
451
|
+
try {
|
|
452
|
+
const keys = Object.keys(value);
|
|
453
|
+
const shown = keys.slice(0, MAX_KEYS).map((k) => `${k}: ${describeValue(value[k], true)}`);
|
|
454
|
+
return `{${shown.join(", ")}${keys.length > MAX_KEYS ? ", \u2026" : ""}}`;
|
|
455
|
+
} catch {
|
|
456
|
+
return "{\u2026}";
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
366
460
|
// src/instrument/common.ts
|
|
367
461
|
var ORIGINAL = "__collector_original__";
|
|
368
462
|
function wrap(obj, name, make) {
|
|
@@ -394,6 +488,15 @@ function displayUrl(win, url, stripQuery) {
|
|
|
394
488
|
}
|
|
395
489
|
return stripQuery ? stripUrl(shown) : shown;
|
|
396
490
|
}
|
|
491
|
+
function timeRequest(opts, win, method, url) {
|
|
492
|
+
const target = opts.onRequest ? rumUrl(win.location.href, url) : void 0;
|
|
493
|
+
if (target === void 0) return () => void 0;
|
|
494
|
+
const start = performance.now();
|
|
495
|
+
const token = opts.onRequestStart?.();
|
|
496
|
+
return (status) => {
|
|
497
|
+
opts.onRequest?.({ method: method.toUpperCase(), url: target, status: status ?? 0, start, end: performance.now() }, token);
|
|
498
|
+
};
|
|
499
|
+
}
|
|
397
500
|
function absoluteUrl(win, url) {
|
|
398
501
|
try {
|
|
399
502
|
return new URL(url, win.location.href).href;
|
|
@@ -411,31 +514,6 @@ function requestMessage(method, url, status) {
|
|
|
411
514
|
|
|
412
515
|
// src/instrument/console.ts
|
|
413
516
|
var LEVELS2 = { error: "error", warn: "warning", log: "info", info: "info" };
|
|
414
|
-
var MAX_KEYS = 10;
|
|
415
|
-
var MAX_STRING = 100;
|
|
416
|
-
function describeValue(value, nested = false) {
|
|
417
|
-
if (typeof value === "string") return nested ? JSON.stringify(truncate(value, MAX_STRING)) : value;
|
|
418
|
-
if (value === null || typeof value !== "object") {
|
|
419
|
-
return typeof value === "function" ? `[Function ${value.name !== "" ? value.name : "anonymous"}]` : String(value);
|
|
420
|
-
}
|
|
421
|
-
const v = value;
|
|
422
|
-
if (value instanceof Error || typeof v.message === "string" && typeof v.name === "string") {
|
|
423
|
-
return `${String(v.name)}: ${String(v.message)}`;
|
|
424
|
-
}
|
|
425
|
-
if (typeof v.nodeType === "number") return typeof v.tagName === "string" ? `<${v.tagName.toLowerCase()}>` : "[Node]";
|
|
426
|
-
if (nested) return Array.isArray(value) ? `[Array(${String(value.length)})]` : "{\u2026}";
|
|
427
|
-
if (Array.isArray(value)) {
|
|
428
|
-
const items = value.slice(0, MAX_KEYS).map((x) => describeValue(x, true));
|
|
429
|
-
return `[${items.join(", ")}${value.length > MAX_KEYS ? ", \u2026" : ""}]`;
|
|
430
|
-
}
|
|
431
|
-
try {
|
|
432
|
-
const keys = Object.keys(value);
|
|
433
|
-
const shown = keys.slice(0, MAX_KEYS).map((k) => `${k}: ${describeValue(value[k], true)}`);
|
|
434
|
-
return `{${shown.join(", ")}${keys.length > MAX_KEYS ? ", \u2026" : ""}}`;
|
|
435
|
-
} catch {
|
|
436
|
-
return "{\u2026}";
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
517
|
function instrumentConsole(win, record, _opts) {
|
|
440
518
|
const target = win.console;
|
|
441
519
|
const restores = Object.keys(LEVELS2).map(
|
|
@@ -504,8 +582,10 @@ function instrumentFetch(win, record, opts) {
|
|
|
504
582
|
const { method, url } = describe2(input, init2);
|
|
505
583
|
if (opts.skipUrl(absoluteUrl(win, url))) return;
|
|
506
584
|
const shown = displayUrl(win, url, opts.stripQuery);
|
|
585
|
+
const timing = timeRequest(opts, win, method, url);
|
|
507
586
|
done = (status) => {
|
|
508
587
|
safeRecord(() => {
|
|
588
|
+
timing(status);
|
|
509
589
|
record({ category: "fetch", level: levelForStatus(status), message: requestMessage(method, shown, status) });
|
|
510
590
|
});
|
|
511
591
|
};
|
|
@@ -547,14 +627,24 @@ function instrumentHistory(win, record, opts) {
|
|
|
547
627
|
(original) => function __collectorWrapped(...args) {
|
|
548
628
|
original.apply(this, args);
|
|
549
629
|
moved();
|
|
630
|
+
navigated();
|
|
550
631
|
}
|
|
551
632
|
);
|
|
633
|
+
const navigated = () => {
|
|
634
|
+
safeRecord(() => {
|
|
635
|
+
opts.onNavigate?.();
|
|
636
|
+
});
|
|
637
|
+
};
|
|
638
|
+
const popped = () => {
|
|
639
|
+
moved();
|
|
640
|
+
navigated();
|
|
641
|
+
};
|
|
552
642
|
const restores = [wrapState("pushState"), wrapState("replaceState")];
|
|
553
|
-
win.addEventListener("popstate",
|
|
643
|
+
win.addEventListener("popstate", popped);
|
|
554
644
|
win.addEventListener("hashchange", moved);
|
|
555
645
|
return () => {
|
|
556
646
|
if (!restores.map((restore) => restore()).every(Boolean)) return false;
|
|
557
|
-
win.removeEventListener("popstate",
|
|
647
|
+
win.removeEventListener("popstate", popped);
|
|
558
648
|
win.removeEventListener("hashchange", moved);
|
|
559
649
|
return true;
|
|
560
650
|
};
|
|
@@ -585,9 +675,11 @@ function instrumentXhr(win, record, opts) {
|
|
|
585
675
|
const request = requests.get(this);
|
|
586
676
|
if (!request || opts.skipUrl(absoluteUrl(win, request.url))) return;
|
|
587
677
|
const shown = displayUrl(win, request.url, opts.stripQuery);
|
|
678
|
+
const timing = timeRequest(opts, win, request.method, request.url);
|
|
588
679
|
this.addEventListener("loadend", () => {
|
|
589
680
|
safeRecord(() => {
|
|
590
681
|
const status = this.status !== 0 ? this.status : void 0;
|
|
682
|
+
timing(status);
|
|
591
683
|
record({ category: "xhr", level: levelForStatus(status), message: requestMessage(request.method, shown, status) });
|
|
592
684
|
});
|
|
593
685
|
}, { once: true });
|
|
@@ -891,8 +983,16 @@ var sharedOptions = {
|
|
|
891
983
|
skipUrl: (url) => active?.isOwnUrl(url) ?? false,
|
|
892
984
|
get stripQuery() {
|
|
893
985
|
return active?.options.stripQuery !== false;
|
|
986
|
+
},
|
|
987
|
+
onRequestStart: () => active?.rum?.requestStart(),
|
|
988
|
+
onRequest: (timing, token) => {
|
|
989
|
+
active?.rum?.request(timing, token);
|
|
990
|
+
},
|
|
991
|
+
onNavigate: () => {
|
|
992
|
+
active?.rum?.navigate();
|
|
894
993
|
}
|
|
895
994
|
};
|
|
995
|
+
var RUM_KINDS = /* @__PURE__ */ new Set(["fetch", "xhr", "history"]);
|
|
896
996
|
var rejected = /* @__PURE__ */ new Set();
|
|
897
997
|
var recorderFor = (kind) => (crumb) => {
|
|
898
998
|
if (active && active.options.breadcrumbs?.[kind] !== false) active.addBreadcrumb(crumb);
|
|
@@ -947,9 +1047,17 @@ var Client = class {
|
|
|
947
1047
|
)
|
|
948
1048
|
);
|
|
949
1049
|
}
|
|
1050
|
+
if (options.rum && !this.transport.disabled) {
|
|
1051
|
+
try {
|
|
1052
|
+
this.rum = options.rum.start({ win, url: endpoint.pageviewsUrl, fetch: fetchFn, logger: this.logger, options, sdk: { name: SDK_NAME, version: "0.5.0" }, environment: environmentOf(options), release: releaseOf(options) });
|
|
1053
|
+
} catch (error) {
|
|
1054
|
+
this.logger.debug("RUM didn't start", error);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
950
1057
|
active = this;
|
|
951
1058
|
for (const [kind, instrument] of Object.entries(INSTRUMENTS)) {
|
|
952
|
-
|
|
1059
|
+
const needed = options.breadcrumbs?.[kind] !== false || this.rum !== void 0 && RUM_KINDS.has(kind);
|
|
1060
|
+
if (!needed || installed.has(kind)) continue;
|
|
953
1061
|
try {
|
|
954
1062
|
installed.set(kind, instrument(win, recorderFor(kind), sharedOptions));
|
|
955
1063
|
} catch (error) {
|
|
@@ -1023,6 +1131,10 @@ var Client = class {
|
|
|
1023
1131
|
async flush(timeoutMs) {
|
|
1024
1132
|
return this.transport ? this.transport.flush(timeoutMs) : Promise.resolve(true);
|
|
1025
1133
|
}
|
|
1134
|
+
/** Names the current RUM page view. Does nothing without RUM. */
|
|
1135
|
+
setRoute(name) {
|
|
1136
|
+
this.rum?.setRoute(name);
|
|
1137
|
+
}
|
|
1026
1138
|
/** True for requests to Collector itself. */
|
|
1027
1139
|
isOwnUrl(url) {
|
|
1028
1140
|
return this.endpointBase !== void 0 && url.startsWith(`${this.endpointBase}/`);
|
|
@@ -1030,6 +1142,11 @@ var Client = class {
|
|
|
1030
1142
|
/** Removes every listener and wrapper it can. Events already queued still go out. */
|
|
1031
1143
|
close() {
|
|
1032
1144
|
this.closed = true;
|
|
1145
|
+
try {
|
|
1146
|
+
this.rum?.close();
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
this.logger.debug("RUM didn't close cleanly", error);
|
|
1149
|
+
}
|
|
1033
1150
|
if (active === this) {
|
|
1034
1151
|
active = void 0;
|
|
1035
1152
|
for (const [kind, restore] of installed) {
|
|
@@ -1049,12 +1166,15 @@ var Client = class {
|
|
|
1049
1166
|
}
|
|
1050
1167
|
env() {
|
|
1051
1168
|
const { win } = this;
|
|
1169
|
+
this.classify ?? (this.classify = { fn: importMapClassifier(win.document, win.location.origin) });
|
|
1052
1170
|
return {
|
|
1053
1171
|
options: this.options,
|
|
1054
1172
|
scope: this.scope,
|
|
1055
1173
|
origin: win.location.origin,
|
|
1056
1174
|
href: win.location.href,
|
|
1057
|
-
userAgent: win.navigator.userAgent
|
|
1175
|
+
userAgent: win.navigator.userAgent,
|
|
1176
|
+
session: this.rum?.session,
|
|
1177
|
+
classify: this.classify.fn
|
|
1058
1178
|
};
|
|
1059
1179
|
}
|
|
1060
1180
|
capture(build) {
|
|
@@ -1100,9 +1220,12 @@ var Client = class {
|
|
|
1100
1220
|
};
|
|
1101
1221
|
|
|
1102
1222
|
// src/index.ts
|
|
1103
|
-
var SDK_VERSION = "0.
|
|
1223
|
+
var SDK_VERSION = "0.5.0";
|
|
1104
1224
|
var client;
|
|
1225
|
+
var pendingRoute;
|
|
1105
1226
|
var pendingScope = new Scope();
|
|
1227
|
+
var userFromApp = false;
|
|
1228
|
+
var stopPageListener;
|
|
1106
1229
|
function scope() {
|
|
1107
1230
|
return client?.scope ?? pendingScope;
|
|
1108
1231
|
}
|
|
@@ -1114,17 +1237,43 @@ function safely(fn, fallback) {
|
|
|
1114
1237
|
return fallback;
|
|
1115
1238
|
}
|
|
1116
1239
|
}
|
|
1117
|
-
function init(options) {
|
|
1240
|
+
function init(options = {}) {
|
|
1118
1241
|
safely(() => {
|
|
1119
1242
|
if (typeof window === "undefined") return;
|
|
1120
1243
|
const kept = scope();
|
|
1121
1244
|
client?.close();
|
|
1122
|
-
|
|
1245
|
+
stopPageListener?.();
|
|
1246
|
+
client = new Client(withMeta(options), window, kept);
|
|
1247
|
+
userFromMeta();
|
|
1248
|
+
const onPageLoad = () => {
|
|
1249
|
+
safely(userFromMeta, void 0);
|
|
1250
|
+
};
|
|
1251
|
+
document.addEventListener("turbo:load", onPageLoad);
|
|
1252
|
+
stopPageListener = () => {
|
|
1253
|
+
document.removeEventListener("turbo:load", onPageLoad);
|
|
1254
|
+
};
|
|
1255
|
+
if (pendingRoute) client.setRoute(pendingRoute.name);
|
|
1256
|
+
pendingRoute = void 0;
|
|
1123
1257
|
if (options.debug === true) Object.defineProperty(window, CONSOLE_HANDLE, { value: { test }, configurable: true, writable: true });
|
|
1124
1258
|
else Reflect.deleteProperty(window, CONSOLE_HANDLE);
|
|
1125
1259
|
}, void 0);
|
|
1126
1260
|
}
|
|
1127
1261
|
var CONSOLE_HANDLE = "__collector";
|
|
1262
|
+
function withMeta(options) {
|
|
1263
|
+
const resolved = { ...options };
|
|
1264
|
+
const dsn = options.dsn ?? readMeta("collector-dsn");
|
|
1265
|
+
const environment = options.environment ?? readMeta("collector-environment");
|
|
1266
|
+
const release = options.release ?? readMeta("collector-release");
|
|
1267
|
+
if (dsn !== void 0) resolved.dsn = dsn;
|
|
1268
|
+
if (environment !== void 0) resolved.environment = environment;
|
|
1269
|
+
if (release !== void 0) resolved.release = release;
|
|
1270
|
+
return resolved;
|
|
1271
|
+
}
|
|
1272
|
+
function userFromMeta() {
|
|
1273
|
+
if (userFromApp) return;
|
|
1274
|
+
const id = readMeta("collector-user");
|
|
1275
|
+
scope().setUser(id === void 0 ? null : { id });
|
|
1276
|
+
}
|
|
1128
1277
|
async function test() {
|
|
1129
1278
|
const notInitialized = () => {
|
|
1130
1279
|
const reason = "init() hasn't run on this page (or this isn't a browser).";
|
|
@@ -1141,6 +1290,7 @@ function captureMessage(message, context) {
|
|
|
1141
1290
|
}
|
|
1142
1291
|
function setUser(user) {
|
|
1143
1292
|
safely(() => {
|
|
1293
|
+
userFromApp = true;
|
|
1144
1294
|
scope().setUser(user);
|
|
1145
1295
|
}, void 0);
|
|
1146
1296
|
}
|
|
@@ -1163,11 +1313,21 @@ function addBreadcrumb(crumb) {
|
|
|
1163
1313
|
async function flush(timeoutMs) {
|
|
1164
1314
|
return safely(async () => client?.flush(timeoutMs) ?? Promise.resolve(true), Promise.resolve(false));
|
|
1165
1315
|
}
|
|
1316
|
+
function setRoute(name) {
|
|
1317
|
+
safely(() => {
|
|
1318
|
+
if (client) client.setRoute(name);
|
|
1319
|
+
else pendingRoute = { name };
|
|
1320
|
+
}, void 0);
|
|
1321
|
+
}
|
|
1166
1322
|
function close() {
|
|
1167
1323
|
safely(() => {
|
|
1168
1324
|
client?.close();
|
|
1169
1325
|
client = void 0;
|
|
1326
|
+
stopPageListener?.();
|
|
1327
|
+
stopPageListener = void 0;
|
|
1170
1328
|
pendingScope = new Scope();
|
|
1329
|
+
pendingRoute = void 0;
|
|
1330
|
+
userFromApp = false;
|
|
1171
1331
|
if (typeof window !== "undefined") Reflect.deleteProperty(window, CONSOLE_HANDLE);
|
|
1172
1332
|
}, void 0);
|
|
1173
1333
|
}
|
|
@@ -1179,6 +1339,7 @@ exports.captureMessage = captureMessage;
|
|
|
1179
1339
|
exports.close = close;
|
|
1180
1340
|
exports.flush = flush;
|
|
1181
1341
|
exports.init = init;
|
|
1342
|
+
exports.setRoute = setRoute;
|
|
1182
1343
|
exports.setTag = setTag;
|
|
1183
1344
|
exports.setTags = setTags;
|
|
1184
1345
|
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-ml-o_-mr.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-ml-o_-mr.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;
|
|
@@ -128,10 +13,14 @@ declare const SDK_VERSION: string;
|
|
|
128
13
|
* Collector.init({ dsn: "https://clt_…@app.clt.chrom.ar" });
|
|
129
14
|
* ```
|
|
130
15
|
*
|
|
16
|
+
* Without options, it reads them from the page's meta tags:
|
|
17
|
+
* `<meta name="collector-dsn">`, `collector-environment` and
|
|
18
|
+
* `collector-release`. Options you pass win over the tags.
|
|
19
|
+
*
|
|
131
20
|
* Without a `dsn`, nothing is captured or sent. Calling it again replaces the
|
|
132
21
|
* options. Safe to import during server-side rendering: it does nothing there.
|
|
133
22
|
*/
|
|
134
|
-
declare function init(options
|
|
23
|
+
declare function init(options?: CollectorOptions): void;
|
|
135
24
|
/**
|
|
136
25
|
* Sends one test error, to check your setup end to end. Resolves to
|
|
137
26
|
* `{ ok: true, id }` once Collector accepts it, or `{ ok: false, reason }`,
|
|
@@ -146,7 +35,10 @@ declare function test(): Promise<TestResult>;
|
|
|
146
35
|
declare function captureException(error: unknown, context?: CaptureContext): string | undefined;
|
|
147
36
|
/** Reports something that isn't an error: `captureMessage("Payment slow", "warning")`. */
|
|
148
37
|
declare function captureMessage(message: string, context?: CaptureContext | Level): string | undefined;
|
|
149
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Attaches your user's id to the following events. An id, not personal data. `null` clears it.
|
|
40
|
+
* From then on, the `collector-user` meta tag is ignored.
|
|
41
|
+
*/
|
|
150
42
|
declare function setUser(user: {
|
|
151
43
|
id: string | number;
|
|
152
44
|
} | null): void;
|
|
@@ -158,8 +50,13 @@ declare function setTags(tags: Record<string, string>): void;
|
|
|
158
50
|
declare function addBreadcrumb(crumb: Breadcrumb): void;
|
|
159
51
|
/** Waits until queued events are sent. Resolves `false` if `timeoutMs` (default 2000) passes first. */
|
|
160
52
|
declare function flush(timeoutMs?: number): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Names the current page for RUM, e.g. `setRoute("/products/:id")`, so
|
|
55
|
+
* pages group by route instead of by Collector's guess. Call it after the
|
|
56
|
+
* URL changes; it names that page view only. Does nothing without RUM.
|
|
57
|
+
*/
|
|
58
|
+
declare function setRoute(name: string | undefined): void;
|
|
161
59
|
/** Stops capturing and removes everything the SDK installed. */
|
|
162
60
|
declare function close(): void;
|
|
163
61
|
|
|
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 };
|
|
62
|
+
export { Breadcrumb, CaptureContext, CollectorOptions, Level, SDK_VERSION, TestResult, addBreadcrumb, captureException, captureMessage, close, flush, init, setRoute, setTag, setTags, setUser, test };
|