@utk09/ui-observability 0.1.2 → 0.3.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +58 -46
  3. package/dist/bus/bus.d.ts +11 -23
  4. package/dist/capture/network.d.ts +1 -1
  5. package/dist/constants-BmO0GRWM.cjs +2 -0
  6. package/dist/constants-BmO0GRWM.cjs.map +1 -0
  7. package/dist/constants-CQr0wwbQ.js +69 -0
  8. package/dist/constants-CQr0wwbQ.js.map +1 -0
  9. package/dist/constants.d.ts +80 -7
  10. package/dist/core/breadcrumbs.d.ts +1 -6
  11. package/dist/core/diagnostics.d.ts +1 -1
  12. package/dist/core/journey.d.ts +11 -1
  13. package/dist/core/pipeline.d.ts +56 -22
  14. package/dist/core/record.d.ts +10 -0
  15. package/dist/core/runtime.d.ts +3 -1
  16. package/dist/core/sampling.d.ts +42 -1
  17. package/dist/index.cjs +3 -3
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +2 -2
  20. package/dist/index.js +645 -565
  21. package/dist/index.js.map +1 -1
  22. package/dist/indexeddb-storage-DeEh8Ag-.cjs +2 -0
  23. package/dist/indexeddb-storage-DeEh8Ag-.cjs.map +1 -0
  24. package/dist/indexeddb-storage-bibcl7ZS.js +154 -0
  25. package/dist/indexeddb-storage-bibcl7ZS.js.map +1 -0
  26. package/dist/models/config.d.ts +76 -253
  27. package/dist/storage/idb-driver.d.ts +67 -0
  28. package/dist/storage/indexeddb-storage.d.ts +1 -1
  29. package/dist/transport/exit-flush.d.ts +1 -1
  30. package/dist/utils/console.d.ts +5 -8
  31. package/dist/utils/platform.d.ts +7 -0
  32. package/dist/utils/tracing.d.ts +17 -1
  33. package/package.json +10 -8
  34. package/dist/constants-CYedFKrL.js +0 -110
  35. package/dist/constants-CYedFKrL.js.map +0 -1
  36. package/dist/constants-CeqjB0Aa.cjs +0 -2
  37. package/dist/constants-CeqjB0Aa.cjs.map +0 -1
  38. package/dist/indexeddb-storage-3oT4si-p.js +0 -88
  39. package/dist/indexeddb-storage-3oT4si-p.js.map +0 -1
  40. package/dist/indexeddb-storage-K3DhJWgu.cjs +0 -2
  41. package/dist/indexeddb-storage-K3DhJWgu.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,44 +1,42 @@
1
- import { $ as e, At as t, B as n, Bt as r, C as i, Ct as a, D as o, Dt as s, E as c, F as l, Ft as u, H as d, I as f, It as p, J as m, K as h, L as g, Lt as ee, Mt as te, N as _, Nt as ne, O as re, Ot as ie, P as ae, Pt as oe, Q as se, Rt as ce, S as le, T as ue, Tt as v, U as de, V as fe, Vt as pe, X as me, Y as he, Z as ge, _ as _e, _t as ve, a as ye, at as be, b as xe, bt as Se, c as Ce, ct as we, d as Te, dt as Ee, et as De, ft as Oe, g as ke, gt as Ae, h as je, ht as Me, i as Ne, it as Pe, j as Fe, jt as Ie, k as Le, l as y, lt as Re, m as ze, mt as Be, n as b, nt as Ve, o as He, ot as Ue, p as We, pt as Ge, q as x, r as Ke, rt as qe, s as Je, t as Ye, tt as Xe, u as Ze, ut as Qe, v as $e, vt as et, w as tt, x as nt, xt as rt, yt as it, z as at, zt as ot } from "./constants-CYedFKrL.js";
2
- import { context as st, isSpanContextValid as ct, propagation as lt, trace as ut } from "@opentelemetry/api";
3
- import { EMPTY as dt, Subject as ft, asapScheduler as pt, bufferTime as mt, catchError as ht, filter as S, from as gt, map as _t, merge as vt, mergeMap as yt, observeOn as bt, partition as xt, tap as St } from "rxjs";
1
+ import { $ as e, $t as t, A as n, At as r, B as i, C as a, Ct as o, D as s, Dt as c, E as l, Et as u, F as d, Ft as f, G as p, Gt as m, H as h, It as g, J as ee, Jt as te, K as ne, Kt as re, L as _, Lt as ie, M as ae, Mt as oe, N as se, Nt as ce, O as le, Ot as ue, Pt as de, Qt as fe, R as pe, S as me, St as he, T as ge, Tt as _e, Ut as ve, V as ye, Vt as v, W as be, Wt as xe, Xt as Se, Yt as Ce, Zt as we, _ as Te, _t as Ee, a as y, an as De, at as Oe, b as ke, bt as Ae, c as je, ct as Me, d as Ne, dt as Pe, en as Fe, et as Ie, ft as Le, g as Re, gt as ze, h as Be, ht as Ve, i as He, in as Ue, it as We, j as Ge, jt as Ke, k as qe, kt as Je, l as b, lt as Ye, m as Xe, mt as Ze, n as x, nn as Qe, nt as $e, o as et, on as tt, ot as nt, p as rt, pt as it, q as at, r as ot, rn as st, rt as S, s as ct, st as lt, t as ut, tn as dt, tt as C, u as ft, ut as pt, v as mt, wt as ht, x as gt, xt as _t, yt as vt, zt as yt } from "./constants-CQr0wwbQ.js";
4
2
  //#region src/utils/timer.ts
5
- function C(e) {
6
- return Math.round((performance.now() - e) * Fe) / Fe;
3
+ function bt(e) {
4
+ return Math.round((performance.now() - e) * d) / d;
7
5
  }
8
- function Ct(e, t, n, r, i) {
9
- e.logMetric(`${t}.duration`, C(n), "ms", "histogram", {
6
+ function xt(e, t, n, r, i) {
7
+ e.logMetric(`${t}.duration`, bt(n), "ms", "histogram", {
10
8
  status: r,
11
9
  ...i
12
10
  });
13
11
  }
14
- function wt(e, t, n, r, i) {
12
+ function St(e, t, n, r, i) {
15
13
  e.error(`${t} failed`, r, {
16
- "action.duration_ms": C(n),
14
+ "action.duration_ms": bt(n),
17
15
  status: "FAILURE",
18
16
  ...i
19
17
  });
20
18
  }
21
- function Tt(e, t, n, r) {
19
+ function Ct(e, t, n, r) {
22
20
  let i = performance.now();
23
21
  try {
24
22
  let a = n();
25
- return Ct(e, t, i, "SUCCESS", r), a;
23
+ return xt(e, t, i, "SUCCESS", r), a;
26
24
  } catch (n) {
27
- throw wt(e, t, i, n, r), n;
25
+ throw St(e, t, i, n, r), n;
28
26
  }
29
27
  }
30
- async function Et(e, t, n, r) {
28
+ async function wt(e, t, n, r) {
31
29
  let i = performance.now();
32
30
  try {
33
31
  let a = await n();
34
- return Ct(e, t, i, "SUCCESS", r), a;
32
+ return xt(e, t, i, "SUCCESS", r), a;
35
33
  } catch (n) {
36
- throw wt(e, t, i, n, r), n;
34
+ throw St(e, t, i, n, r), n;
37
35
  }
38
36
  }
39
37
  //#endregion
40
38
  //#region src/core/logger.ts
41
- function Dt(e) {
39
+ function Tt(e) {
42
40
  return e instanceof Error ? e : Error(String(e));
43
41
  }
44
42
  var w = class e {
@@ -78,7 +76,7 @@ var w = class e {
78
76
  logEvent = (e, t) => {
79
77
  this.write("INFO", "event", e, t);
80
78
  };
81
- logMetric = (e, t, n = re, r = "gauge", i) => {
79
+ logMetric = (e, t, n = ae, r = "gauge", i) => {
82
80
  this.write("INFO", "metric", e, {
83
81
  "metric.name": e,
84
82
  "metric.value": t,
@@ -87,8 +85,8 @@ var w = class e {
87
85
  ...i
88
86
  });
89
87
  };
90
- timeSync = (e, t, n) => Tt(this, e, t, n);
91
- timeAsync = (e, t, n) => Et(this, e, t, n);
88
+ timeSync = (e, t, n) => Ct(this, e, t, n);
89
+ timeAsync = (e, t, n) => wt(this, e, t, n);
92
90
  write(e, t, n, r) {
93
91
  if (!this.runtime.builder.isEnabled(e)) return;
94
92
  let i = this.runtime.builder.build({
@@ -107,7 +105,7 @@ var w = class e {
107
105
  }
108
106
  writeError(e, t, n, r) {
109
107
  if (!this.runtime.builder.isEnabled(e)) return;
110
- let i = n === void 0 ? void 0 : Dt(n), a = this.runtime.builder.build({
108
+ let i = n === void 0 ? void 0 : Tt(n), a = this.runtime.builder.build({
111
109
  level: e,
112
110
  type: "system",
113
111
  body: t,
@@ -135,7 +133,7 @@ function T(e) {
135
133
  //#region src/models/bus.ts
136
134
  function E(e) {
137
135
  return {
138
- p: xe,
136
+ p: me,
139
137
  m: e
140
138
  };
141
139
  }
@@ -148,12 +146,12 @@ function D(e) {
148
146
  }
149
147
  //#endregion
150
148
  //#region src/bus/links.ts
151
- var Ot = Symbol.for(rt);
152
- function kt(e, t) {
149
+ var Et = Symbol.for(ie);
150
+ function Dt(e, t) {
153
151
  if (typeof window > "u" || window.parent === window) return null;
154
152
  let n;
155
153
  try {
156
- n = window.parent[Ot];
154
+ n = window.parent[Et];
157
155
  } catch {
158
156
  return null;
159
157
  }
@@ -171,7 +169,7 @@ function kt(e, t) {
171
169
  }
172
170
  };
173
171
  }
174
- function At(e, t) {
172
+ function Ot(e, t) {
175
173
  if (typeof window > "u" || window.parent === window) return null;
176
174
  let n = (t) => {
177
175
  let n = D(t.data);
@@ -192,9 +190,9 @@ function At(e, t) {
192
190
  }
193
191
  };
194
192
  }
195
- function jt(e, t, n) {
193
+ function kt(e, t, n) {
196
194
  if (typeof window > "u") return null;
197
- let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Set(), a = (t) => {
195
+ let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Map(), a = (t) => {
198
196
  let a = D(t.data);
199
197
  if (a) {
200
198
  if (!r.has(t.origin)) {
@@ -204,7 +202,7 @@ function jt(e, t, n) {
204
202
  });
205
203
  return;
206
204
  }
207
- t.source && i.add(t.source), e(a, {
205
+ t.source && i.set(t.source, t.origin), e(a, {
208
206
  link: "children",
209
207
  origin: t.origin
210
208
  });
@@ -213,14 +211,14 @@ function jt(e, t, n) {
213
211
  return addEventListener("message", a), {
214
212
  kind: "children",
215
213
  post(e) {
216
- for (let t of i) {
217
- let r = t;
218
- if (r.closed) {
214
+ for (let [t, r] of i) {
215
+ let a = t;
216
+ if (a.closed) {
219
217
  i.delete(t);
220
218
  continue;
221
219
  }
222
220
  n.guard("bus.send_failed", "postMessage to child", () => {
223
- r.postMessage(E(e), "*");
221
+ a.postMessage(E(e), r);
224
222
  });
225
223
  }
226
224
  },
@@ -229,7 +227,7 @@ function jt(e, t, n) {
229
227
  }
230
228
  };
231
229
  }
232
- function Mt(e, t, n) {
230
+ function At(e, t, n) {
233
231
  let r = globalThis.BroadcastChannel;
234
232
  if (r === void 0) return null;
235
233
  let i = n.guard("bus.send_failed", "opening BroadcastChannel", () => new r(e));
@@ -253,7 +251,7 @@ function Mt(e, t, n) {
253
251
  }
254
252
  }) : null;
255
253
  }
256
- function Nt(e, t, n) {
254
+ function jt(e, t, n) {
257
255
  let r = globalThis.fin?.InterApplicationBus;
258
256
  return r ? (n.guardAsync("bus.send_failed", "InterApplicationBus.subscribe", () => r.subscribe({ uuid: "*" }, e, (e) => {
259
257
  let n = D(e);
@@ -269,7 +267,7 @@ function Nt(e, t, n) {
269
267
  close() {}
270
268
  }) : null;
271
269
  }
272
- function Pt(e, t) {
270
+ function Mt(e, t) {
273
271
  let n = globalThis, r = n.postMessage;
274
272
  return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
275
273
  let n = D(t.data);
@@ -287,7 +285,7 @@ function Pt(e, t) {
287
285
  close() {}
288
286
  });
289
287
  }
290
- function Ft(e, t, n) {
288
+ function Nt(e, t, n) {
291
289
  let r = (e) => {
292
290
  let n = D(e.data);
293
291
  n && t(n, {
@@ -309,17 +307,21 @@ function Ft(e, t, n) {
309
307
  }
310
308
  //#endregion
311
309
  //#region src/bus/bus.ts
312
- var It = [
310
+ var Pt = {
311
+ timeoutMs: gt,
312
+ maxAttempts: 3
313
+ }, Ft = [
313
314
  "children",
314
315
  "direct",
315
316
  "worker"
316
- ], Lt = class {
317
+ ], It = class {
317
318
  config;
318
319
  diagnostics;
319
320
  platform;
320
321
  contextId;
321
322
  tabId;
322
323
  handlers;
324
+ handshakeOptions;
323
325
  role = "sender";
324
326
  upstream = null;
325
327
  links = [];
@@ -327,8 +329,8 @@ var It = [
327
329
  isOpenFinProvider = !1;
328
330
  resolved = !1;
329
331
  awaitingWelcome = null;
330
- constructor(e, t, n, r, i, a) {
331
- this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a;
332
+ constructor(e, t, n, r, i, a, o = Pt) {
333
+ this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
332
334
  }
333
335
  getRole() {
334
336
  return this.role;
@@ -341,16 +343,16 @@ var It = [
341
343
  if (e.mode === "off") return this.role = "sender", this.resolved = !0, this.role;
342
344
  if (this.isOpenFinProvider = this.resolveOpenFinProvider(), e.mode === "sender" || e.mode === "forwarder") return this.role = e.mode, this.openControlLinks(), this.role === "forwarder" && (this.upstream = this.candidateUpstream(), this.upstream || this.diagnostics.report("bus.no_owner", "bus.mode is \"forwarder\" but there is no owner to forward to. Records will be dropped.")), this.resolved = !0, this.announce(), this.role;
343
345
  this.openControlLinks();
344
- let t = kt(this.receive, this.diagnostics);
346
+ let t = Dt(this.receive, this.diagnostics);
345
347
  if (t) return this.role = "forwarder", this.upstream = t, this.resolved = !0, this.diagnostics.report("bus.role_resolved", "attached directly to the same-origin parent runtime", {
346
348
  role: "forwarder",
347
349
  via: "direct"
348
350
  }), this.announce(), this.role;
349
351
  let n = this.candidateUpstream();
350
352
  if (!n) return this.role = "sender", this.resolved = !0, this.diagnostics.report("bus.role_resolved", "no owner to forward to, sending directly", { role: "sender" }), this.announce(), this.role;
351
- let r = this.orphanPolicy() === "retry" ? this.config.bus.maxHandshakeAttempts : 1, i = !1;
353
+ let r = this.orphanPolicy() === "retry" ? this.handshakeOptions.maxAttempts : 1, i = !1;
352
354
  for (let e = 0; e < r && !i; e++) i = await this.handshake(n);
353
- return this.role = i ? "forwarder" : "sender", this.upstream = i ? n : null, i || (n !== this.openFinLink && n.close(), this.diagnostics.report("bus.handshake_timeout", `no owner answered after ${String(r)} attempt(s) of ${String(this.config.bus.handshakeTimeoutMs)}ms, promoting to sender`, {
355
+ return this.role = i ? "forwarder" : "sender", this.upstream = i ? n : null, i || (n !== this.openFinLink && n.close(), this.diagnostics.report("bus.handshake_timeout", `no owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)}ms, promoting to sender`, {
354
356
  via: n.kind,
355
357
  crossOrigin: this.isCrossOriginFrame()
356
358
  })), this.diagnostics.report("bus.role_resolved", `role is ${this.role}`, {
@@ -392,7 +394,7 @@ var It = [
392
394
  this.receive(e, n);
393
395
  }
394
396
  attachWorker(e) {
395
- this.links.push(Ft(e, this.receive, this.diagnostics));
397
+ this.links.push(Nt(e, this.receive, this.diagnostics));
396
398
  }
397
399
  broadcastJourney(e) {
398
400
  this.post({
@@ -447,7 +449,7 @@ var It = [
447
449
  }
448
450
  };
449
451
  canOwn(e) {
450
- return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : It.includes(e) : !1;
452
+ return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : Ft.includes(e) : !1;
451
453
  }
452
454
  resolveOpenFinProvider() {
453
455
  let e = this.config.bus.openFinRole;
@@ -457,8 +459,7 @@ var It = [
457
459
  return !t?.identity || t.isView ? !1 : !!(t.identity.name && t.identity.name === t.identity.uuid);
458
460
  }
459
461
  orphanPolicy() {
460
- let e = this.config.bus.orphanPolicy;
461
- return e === "auto" ? this.isCrossOriginFrame() ? "retry" : "promote" : e;
462
+ return this.isCrossOriginFrame() ? "retry" : "promote";
462
463
  }
463
464
  isCrossOriginFrame() {
464
465
  if (typeof window > "u" || window.parent === window) return !1;
@@ -469,16 +470,16 @@ var It = [
469
470
  }
470
471
  }
471
472
  candidateUpstream() {
472
- return this.platform.isWorker ? Pt(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && this.config.bus.openFinHost === "provider" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : At(this.receive, this.diagnostics);
473
+ return this.platform.isWorker ? Mt(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : Ot(this.receive, this.diagnostics);
473
474
  }
474
475
  openControlLinks() {
475
476
  let e = (e) => {
476
477
  e && this.links.push(e);
477
478
  };
478
- this.platform.isTopLevelDocument && (e(jt(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), e(Mt(this.config.bus.channelName, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
479
+ this.platform.isTopLevelDocument && (e(kt(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), e(At(ke, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
479
480
  }
480
481
  ensureOpenFinLink() {
481
- return this.openFinLink ??= Nt(this.config.bus.channelName, this.receive, this.diagnostics), this.openFinLink;
482
+ return this.openFinLink ??= jt(ke, this.receive, this.diagnostics), this.openFinLink;
482
483
  }
483
484
  handshake(e) {
484
485
  return new Promise((t) => {
@@ -491,7 +492,7 @@ var It = [
491
492
  };
492
493
  let i = setTimeout(() => {
493
494
  r(!1);
494
- }, this.config.bus.handshakeTimeoutMs);
495
+ }, this.handshakeOptions.timeoutMs);
495
496
  T(i), e.post({
496
497
  t: "hello",
497
498
  from: this.contextId,
@@ -509,7 +510,51 @@ var It = [
509
510
  from: this.contextId
510
511
  });
511
512
  }
512
- }, Rt = class {
513
+ }, O = null;
514
+ function k(e, t) {
515
+ let n = e[t];
516
+ return n !== void 0 && e instanceof n;
517
+ }
518
+ function Lt(e) {
519
+ if (O) return O;
520
+ let t = globalThis, n = t.navigator?.userAgent ?? "", r = "browser", i, a, o = !1, s = t.fin?.me;
521
+ return k(t, "ServiceWorkerGlobalScope") ? (r = "service_worker", o = !0) : k(t, "SharedWorkerGlobalScope") ? (r = "shared_worker", o = !0) : k(t, "WorkerGlobalScope") ? (r = "web_worker", o = !0) : s === void 0 ? t.Capacitor !== void 0 || t.Ionic !== void 0 ? r = "ionic" : t.cordova !== void 0 || Rt(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Ve.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
522
+ let e = s.identity;
523
+ i = e?.uuid, a = e?.name;
524
+ })), O = {
525
+ platform: r,
526
+ openfinUuid: i,
527
+ openfinName: a,
528
+ userAgent: n,
529
+ isWorker: o,
530
+ isTopLevelDocument: zt()
531
+ }, O;
532
+ }
533
+ function Rt(t) {
534
+ return ut.test(t) ? !0 : (e.test(t) || lt.test(t) && pt.test(t)) && t.includes("AppleWebKit") && !t.includes("Safari/");
535
+ }
536
+ function zt() {
537
+ if (typeof window > "u") return !1;
538
+ try {
539
+ return window.self === window.top;
540
+ } catch {
541
+ return !1;
542
+ }
543
+ }
544
+ function Bt() {
545
+ try {
546
+ return typeof location < "u" ? location.href : "";
547
+ } catch {
548
+ return "";
549
+ }
550
+ }
551
+ function A(e) {
552
+ let t = e.search(/[?#]/);
553
+ return t === -1 ? e : e.slice(0, t);
554
+ }
555
+ //#endregion
556
+ //#region src/capture/errors.ts
557
+ var Vt = class {
513
558
  ctx;
514
559
  name = "errors";
515
560
  installed = !1;
@@ -529,13 +574,14 @@ var It = [
529
574
  let t = e.target, n = t?.src ?? t?.href ?? "";
530
575
  if (t !== null && t !== globalThis && n !== "") {
531
576
  if (!this.ctx.config.capture.resourceErrors) return;
577
+ let e = this.ctx.config.capture.fullUrls ? n : A(n);
532
578
  this.ctx.breadcrumbs.push({
533
579
  t: Date.now(),
534
580
  category: "http",
535
- message: `resource failed: ${n}`
581
+ message: `resource failed: ${e}`
536
582
  }), this.ctx.logger.warn("resource failed to load", {
537
583
  "error.type": "resource",
538
- "resource.url": n,
584
+ "resource.url": e,
539
585
  "resource.tag": t.tagName.toLowerCase()
540
586
  });
541
587
  return;
@@ -554,32 +600,32 @@ var It = [
554
600
  report(e, t, n) {
555
601
  let r = Date.now();
556
602
  if (r - this.windowStart > 1e4 && (this.windowStart = r, this.windowCount = 0), this.windowCount++, this.windowCount > 20) {
557
- this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(l)}ms, suppressing the rest of this window`);
603
+ this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(i)}ms, suppressing the rest of this window`);
558
604
  return;
559
605
  }
560
- let i = t instanceof Error ? t : Error(String(t)), a = (i.stack ?? "").split("\n")[1] ?? "", o = `${i.name}|${i.message}|${a}`, s = this.seen.get(o);
561
- if (s && r - s.at < this.ctx.config.capture.errorDedupeMs) {
562
- s.count++, s.at = r;
606
+ let a = t instanceof Error ? t : Error(String(t)), o = (a.stack ?? "").split("\n")[1] ?? "", s = `${a.name}|${a.message}|${o}`, c = this.seen.get(s);
607
+ if (c && r - c.at < 5e3) {
608
+ c.count++, c.at = r;
563
609
  return;
564
610
  }
565
- let c = s ? s.count - 1 : 0;
566
- if (this.seen.delete(o), this.seen.set(o, {
611
+ let l = c ? c.count - 1 : 0;
612
+ if (this.seen.delete(s), this.seen.set(s, {
567
613
  at: r,
568
614
  count: 1
569
615
  }), this.seen.size > 200) {
570
616
  let [e] = this.seen.keys();
571
617
  this.seen.delete(e);
572
618
  }
573
- this.ctx.logger.error(i.message === "" ? e : i.message, i, {
619
+ this.ctx.logger.error(a.message === "" ? e : a.message, a, {
574
620
  ...n,
575
621
  "error.captured_by": e,
576
- "error.suppressed_count": c
622
+ "error.suppressed_count": l
577
623
  });
578
624
  }
579
625
  };
580
626
  //#endregion
581
627
  //#region src/capture/interactions.ts
582
- function zt(e) {
628
+ function Ht(e) {
583
629
  if (e === null) return "unknown";
584
630
  let t = e.tagName.toLowerCase(), n = e.getAttribute("data-testid") ?? e.getAttribute("data-test-id");
585
631
  if (n !== null) return `[data-testid="${n}"]`;
@@ -589,10 +635,10 @@ function zt(e) {
589
635
  let i = e.getAttribute("class")?.trim() ?? "";
590
636
  return i === "" ? t : `${t}.${i.split(/\s+/).slice(0, 2).join(".")}`;
591
637
  }
592
- function O() {
638
+ function j() {
593
639
  return history;
594
640
  }
595
- var Bt = class {
641
+ var Ut = class {
596
642
  ctx;
597
643
  name = "interactions";
598
644
  installed = !1;
@@ -606,10 +652,10 @@ var Bt = class {
606
652
  this.installed || typeof document > "u" || (this.installed = !0, this.lastUrl = location.href, this.ctx.config.capture.interactions && addEventListener("click", this.onClick, !0), this.ctx.config.capture.navigation && (this.installHistory(), addEventListener("popstate", this.onNavigate), addEventListener("hashchange", this.onNavigate)));
607
653
  }
608
654
  uninstall() {
609
- this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (O().pushState = this.originalPushState), this.originalReplaceState && (O().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
655
+ this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (j().pushState = this.originalPushState), this.originalReplaceState && (j().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
610
656
  }
611
657
  onClick = (e) => {
612
- let t = e.target, n = zt(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.innerText.trim().slice(0, 50) : "";
658
+ let t = e.target, n = Ht(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.innerText.trim().slice(0, 50) : "";
613
659
  this.ctx.tracing.rotate("interaction"), this.ctx.breadcrumbs.push({
614
660
  t: Date.now(),
615
661
  category: "click",
@@ -619,15 +665,18 @@ var Bt = class {
619
665
  };
620
666
  onNavigate = () => {
621
667
  let e = this.lastUrl, t = location.href;
622
- e !== t && (this.lastUrl = t, this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
668
+ if (e === t) return;
669
+ this.lastUrl = t;
670
+ let n = this.ctx.config.capture.fullUrls, r = n ? e : A(e), i = n ? t : A(t);
671
+ this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
623
672
  t: Date.now(),
624
673
  category: "navigation",
625
- message: `${e} -> ${t}`
626
- }), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": e }));
674
+ message: `${r} -> ${i}`
675
+ }), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": r });
627
676
  };
628
677
  installHistory() {
629
678
  if (typeof history > "u" || this.originalPushState) return;
630
- let e = O(), t = e.pushState, n = e.replaceState;
679
+ let e = j(), t = e.pushState, n = e.replaceState;
631
680
  this.originalPushState = t, this.originalReplaceState = n;
632
681
  let r = this.onNavigate;
633
682
  e.pushState = function(...e) {
@@ -639,15 +688,15 @@ var Bt = class {
639
688
  };
640
689
  //#endregion
641
690
  //#region src/capture/types.ts
642
- function Vt(e, t) {
691
+ function Wt(e, t) {
643
692
  return t.some((t) => typeof t == "string" ? e.includes(t) : t.test(e));
644
693
  }
645
694
  //#endregion
646
695
  //#region src/capture/network.ts
647
- function k() {
696
+ function M() {
648
697
  return XMLHttpRequest.prototype;
649
698
  }
650
- var Ht = class {
699
+ var Gt = class {
651
700
  ctx;
652
701
  name = "network";
653
702
  originalFetch = null;
@@ -660,10 +709,10 @@ var Ht = class {
660
709
  this.ctx.config.capture.fetch && this.installFetch(), this.ctx.config.capture.xhr && this.installXhr();
661
710
  }
662
711
  uninstall() {
663
- this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (k().open = this.originalOpen, null), this.originalSend &&= (k().send = this.originalSend, null);
712
+ this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (M().open = this.originalOpen, null), this.originalSend &&= (M().send = this.originalSend, null);
664
713
  }
665
714
  ignored(e) {
666
- return Vt(e, this.ctx.config.capture.ignoreUrls);
715
+ return Wt(e, this.ctx.config.capture.ignoreUrls);
667
716
  }
668
717
  installFetch() {
669
718
  if (typeof globalThis.fetch != "function" || this.originalFetch) return;
@@ -676,7 +725,7 @@ var Ht = class {
676
725
  let o = typeof i == "string" ? i : i instanceof URL ? i.href : i.url, s = (a?.method ?? (i instanceof Request ? i.method : "GET")).toUpperCase();
677
726
  if (n(o)) return e(i, a);
678
727
  let c = i, l = a;
679
- if (Vt(o, t.config.capture.propagateTraceHeaderTo)) try {
728
+ if (Wt(o, t.config.capture.propagateTraceHeaderTo)) try {
680
729
  let e = Object.entries(t.tracing.headers());
681
730
  if (i instanceof Request) {
682
731
  let t = new Headers(i.headers);
@@ -706,7 +755,7 @@ var Ht = class {
706
755
  if (typeof XMLHttpRequest > "u" || this.originalOpen) return;
707
756
  let e = (e) => this.ignored(e), t = (e, t, n, r) => {
708
757
  this.record(e, t, n, r, void 0);
709
- }, n = k(), r = n.open, i = n.send;
758
+ }, n = M(), r = n.open, i = n.send;
710
759
  this.originalOpen = r, this.originalSend = i, n.open = function(e, t, ...n) {
711
760
  this.__uiobs = {
712
761
  method: e.toUpperCase(),
@@ -725,41 +774,42 @@ var Ht = class {
725
774
  };
726
775
  }
727
776
  record(e, t, n, r, i) {
728
- this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${t}`, () => {
729
- let a = Math.round(r);
777
+ let a = this.ctx.config.capture.fullUrls ? t : A(t);
778
+ this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${a}`, () => {
779
+ let t = Math.round(r);
730
780
  this.ctx.breadcrumbs.push({
731
781
  t: Date.now(),
732
782
  category: "http",
733
- message: `${e} ${t} ${n === 0 ? "failed" : String(n)}`,
734
- data: { durationMs: a }
783
+ message: `${e} ${a} ${n === 0 ? "failed" : String(n)}`,
784
+ data: { durationMs: t }
735
785
  });
736
786
  let o = {
737
787
  "http.request.method": e,
738
- "url.full": t,
788
+ "url.full": a,
739
789
  "http.response.status_code": n,
740
- "http.duration_ms": a
790
+ "http.duration_ms": t
741
791
  };
742
792
  if (n === 0) {
743
- this.ctx.logger.error(`${e} ${t} failed`, i, o);
793
+ this.ctx.logger.error(`${e} ${a} failed`, i, o);
744
794
  return;
745
795
  }
746
796
  if (n >= 400) {
747
- this.ctx.logger.warn(`${e} ${t} returned ${String(n)}`, o);
797
+ this.ctx.logger.warn(`${e} ${a} returned ${String(n)}`, o);
748
798
  return;
749
799
  }
750
- this.ctx.logger.debug(`${e} ${t}`, o);
800
+ this.ctx.logger.debug(`${e} ${a}`, o);
751
801
  });
752
802
  }
753
803
  };
754
804
  //#endregion
755
805
  //#region src/capture/web-vitals.ts
756
- function Ut() {
806
+ function Kt() {
757
807
  return import(
758
808
  /* @vite-ignore */
759
809
  "web-vitals"
760
810
  );
761
811
  }
762
- var Wt = class {
812
+ var qt = class {
763
813
  ctx;
764
814
  name = "web-vitals";
765
815
  installed = !1;
@@ -773,7 +823,7 @@ var Wt = class {
773
823
  this.installed = !1;
774
824
  }
775
825
  async loadWebVitals() {
776
- let e = this.ctx.config.capture.webVitalsLoader ?? Ut, t = await this.ctx.diagnostics.guardAsync("capture.install_failed", "loading web-vitals", e);
826
+ let e = this.ctx.config.capture.webVitalsLoader ?? Kt, t = await this.ctx.diagnostics.guardAsync("capture.install_failed", "loading web-vitals", e);
777
827
  if (!t) {
778
828
  this.ctx.diagnostics.report("capture.install_failed", "web-vitals is not available, so LCP, CLS and INP are unavailable. Navigation timing still works.");
779
829
  return;
@@ -805,38 +855,38 @@ var Wt = class {
805
855
  };
806
856
  //#endregion
807
857
  //#region src/models/log-record.ts
808
- function Gt() {
858
+ function Jt() {
809
859
  return `${String(Date.now())}000000`;
810
860
  }
811
- function A(e) {
861
+ function Yt(e) {
812
862
  if (typeof e != "object" || !e) return !1;
813
863
  let t = e;
814
864
  return typeof t.body == "string" && typeof t.severityText == "string" && typeof t.timeUnixNano == "string" && typeof t.attributes == "object" && t.attributes !== null && typeof t.resource == "object" && t.resource !== null;
815
865
  }
816
866
  //#endregion
817
867
  //#region src/utils/identity.ts
818
- function j(e) {
868
+ function N(e) {
819
869
  let t = new Uint8Array(e);
820
870
  if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") crypto.getRandomValues(t);
821
871
  else for (let n = 0; n < e; n++) t[n] = Math.floor(Math.random() * 256);
822
872
  return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
823
873
  }
824
- function M() {
874
+ function P() {
825
875
  try {
826
876
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
827
877
  } catch {}
828
- return j(16);
878
+ return N(16);
829
879
  }
830
- function Kt(e, t, n) {
880
+ function Xt(e, t, n) {
831
881
  return n.guard("storage.unavailable", `reading ${e}Storage`, () => (e === "local" ? localStorage : sessionStorage).getItem(t)) ?? null;
832
882
  }
833
- function N(e, t, n, r) {
883
+ function F(e, t, n, r) {
834
884
  r.guard("storage.unavailable", `writing ${e}Storage`, () => {
835
885
  (e === "local" ? localStorage : sessionStorage).setItem(t, n);
836
886
  });
837
887
  }
838
- function qt(e) {
839
- let t = M(), n = Date.now(), r = M(), i = Kt("local", v, e);
888
+ function Zt(e) {
889
+ let t = P(), n = Date.now(), r = P(), i = Xt("local", v, e);
840
890
  if (i) try {
841
891
  let e = JSON.parse(i);
842
892
  e.id && n - (e.lastSeenAt ?? 0) < 18e5 && (r = e.id);
@@ -847,36 +897,36 @@ function qt(e) {
847
897
  id: r,
848
898
  lastSeenAt: n
849
899
  });
850
- N("local", v, a, e);
851
- let o = Kt("session", "ui-observability.tab", e) ?? "";
852
- return o || (o = M(), N("session", oe, o, e)), {
900
+ F("local", v, a, e);
901
+ let o = Xt("session", "ui-observability.tab", e) ?? "";
902
+ return o || (o = P(), F("session", fe, o, e)), {
853
903
  sessionId: r,
854
904
  tabId: o,
855
905
  contextId: t
856
906
  };
857
907
  }
858
- var Jt = 0;
859
- function Yt(e, t) {
908
+ var Qt = 0;
909
+ function $t(e, t) {
860
910
  let n = Date.now();
861
- if (n - Jt < 6e4) return;
862
- Jt = n;
911
+ if (n - Qt < 6e4) return;
912
+ Qt = n;
863
913
  let r = JSON.stringify({
864
914
  id: e,
865
915
  lastSeenAt: n
866
916
  });
867
- N("local", v, r, t);
917
+ F("local", v, r, t);
868
918
  }
869
919
  //#endregion
870
920
  //#region src/models/batch.ts
871
- function Xt(e) {
921
+ function en(e) {
872
922
  if (typeof e != "object" || !e) return !1;
873
923
  let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
874
924
  return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
875
925
  }
876
- function Zt(e) {
926
+ function tn(e) {
877
927
  if (e.records.length < 2) return null;
878
928
  let t = Math.floor(e.records.length / 2), n = (t) => ({
879
- id: M(),
929
+ id: P(),
880
930
  records: t,
881
931
  createdAt: e.createdAt,
882
932
  attempts: e.attempts
@@ -885,13 +935,13 @@ function Zt(e) {
885
935
  }
886
936
  //#endregion
887
937
  //#region src/utils/lock.ts
888
- function Qt(e, t, n, { skipIfBusy: r = !0 } = {}) {
938
+ function nn(e, t, n, { skipIfBusy: r = !0 } = {}) {
889
939
  let i = globalThis.navigator?.locks;
890
940
  return i?.request ? t.guardAsync("storage.degraded", `acquiring lock ${e}`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
891
941
  }
892
942
  //#endregion
893
943
  //#region src/storage/keys.ts
894
- function P(e, t) {
944
+ function I(e, t) {
895
945
  let n = [];
896
946
  return t.guard("storage.unavailable", "enumerating localStorage", () => {
897
947
  for (let t = 0; t < localStorage.length; t++) {
@@ -902,23 +952,23 @@ function P(e, t) {
902
952
  }
903
953
  //#endregion
904
954
  //#region src/storage/emergency-queue.ts
905
- function $t(e) {
955
+ function rn(e) {
906
956
  let t = String(e.createdAt).padStart(14, "0");
907
957
  return `${_}${t}.${e.id}`;
908
958
  }
909
- function en(e, t) {
959
+ function an(e, t) {
910
960
  let n = t.guard("storage.degraded", "an emergency entry was not JSON and was dropped", () => JSON.parse(e));
911
- return n === void 0 ? null : Xt(n) ? n : (t.report("storage.degraded", "an emergency entry was not a batch and was dropped"), null);
961
+ return n === void 0 ? null : en(n) ? n : (t.report("storage.degraded", "an emergency entry was not a batch and was dropped"), null);
912
962
  }
913
- async function tn(e, t) {
963
+ async function on(e, t) {
914
964
  let n = 0;
915
- for (let r of P(_, t)) {
965
+ for (let r of I(_, t)) {
916
966
  let i = t.guard("storage.unavailable", "reading the emergency queue", () => {
917
967
  let e = localStorage.getItem(r);
918
968
  return localStorage.removeItem(r), e;
919
969
  });
920
970
  if (!i) continue;
921
- let a = en(i, t);
971
+ let a = an(i, t);
922
972
  if (a !== null) try {
923
973
  await e.save(a), n++;
924
974
  } catch (e) {
@@ -927,33 +977,33 @@ async function tn(e, t) {
927
977
  }
928
978
  return n;
929
979
  }
930
- function nn(e, t) {
980
+ function sn(e, t) {
931
981
  let n = `writing the emergency queue, ${String(e.records.length)} records`;
932
982
  t.guard("storage.quota_exceeded", n, () => {
933
- let n = P(_, t);
983
+ let n = I(_, t);
934
984
  for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
935
- localStorage.setItem($t(e), JSON.stringify(e));
985
+ localStorage.setItem(rn(e), JSON.stringify(e));
936
986
  });
937
987
  }
938
- async function rn(e, t) {
939
- return await Qt("ui-observability.emergency", t, () => tn(e, t), { skipIfBusy: !1 }) ?? 0;
988
+ async function cn(e, t) {
989
+ return await nn("ui-observability.emergency", t, () => on(e, t), { skipIfBusy: !1 }) ?? 0;
940
990
  }
941
991
  //#endregion
942
992
  //#region src/storage/local-storage.ts
943
- function an(e) {
993
+ function ln(e) {
944
994
  let t = String(e.createdAt).padStart(14, "0");
945
- return `${$e}${t}.${e.id}`;
995
+ return `${mt}${t}.${e.id}`;
946
996
  }
947
- var on = class {
997
+ var un = class {
948
998
  limits;
949
999
  diagnostics;
950
1000
  onGap;
951
- name = t;
1001
+ name = te;
952
1002
  constructor(e, t, n) {
953
1003
  this.limits = e, this.diagnostics = t, this.onGap = n;
954
1004
  }
955
1005
  async save(e) {
956
- if (this.diagnostics.guard("storage.quota_exceeded", "localStorage refused a batch, evicting the oldest", () => (localStorage.setItem(an(e), JSON.stringify(e)), !0)) !== !0) {
1006
+ if (this.diagnostics.guard("storage.quota_exceeded", "localStorage refused a batch, evicting the oldest", () => (localStorage.setItem(ln(e), JSON.stringify(e)), !0)) !== !0) {
957
1007
  let e = this.keys();
958
1008
  this.evict(e.slice(0, Math.ceil(e.length / 4)));
959
1009
  return;
@@ -1027,7 +1077,7 @@ var on = class {
1027
1077
  let t = this.diagnostics.guard("storage.unavailable", "reading a stored batch", () => localStorage.getItem(e));
1028
1078
  if (!t) return null;
1029
1079
  let n = this.diagnostics.guard("storage.degraded", "a stored batch was corrupt and was removed", () => JSON.parse(t));
1030
- return n === void 0 ? null : Xt(n) ? n : (this.diagnostics.report("storage.degraded", "a stored entry was not a batch and was dropped"), null);
1080
+ return n === void 0 ? null : en(n) ? n : (this.diagnostics.report("storage.degraded", "a stored entry was not a batch and was dropped"), null);
1031
1081
  }
1032
1082
  keyOf(e) {
1033
1083
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -1041,18 +1091,18 @@ var on = class {
1041
1091
  });
1042
1092
  }
1043
1093
  keys() {
1044
- return P($e, this.diagnostics);
1094
+ return I(mt, this.diagnostics);
1045
1095
  }
1046
1096
  };
1047
1097
  //#endregion
1048
1098
  //#region src/storage/memory-storage.ts
1049
- function sn(e) {
1099
+ function dn(e) {
1050
1100
  return e.reduce((e, t) => e + t.records.length, 0);
1051
1101
  }
1052
- var F = class {
1102
+ var L = class {
1053
1103
  limits;
1054
1104
  onGap;
1055
- name = Ie;
1105
+ name = Ce;
1056
1106
  batches = [];
1057
1107
  constructor(e, t) {
1058
1108
  this.limits = e, this.onGap = t;
@@ -1076,12 +1126,12 @@ var F = class {
1076
1126
  records: 0,
1077
1127
  reason: "expired"
1078
1128
  }, n = this.batches.filter((t) => t.createdAt < e);
1079
- this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += sn(n);
1129
+ this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += dn(n);
1080
1130
  let r = this.batches.length - this.limits.maxBatches;
1081
1131
  if (r > 0) {
1082
1132
  t.reason = "over_capacity";
1083
1133
  let e = this.batches.slice(0, r);
1084
- this.batches = this.batches.slice(r), t.batches += e.length, t.records += sn(e);
1134
+ this.batches = this.batches.slice(r), t.batches += e.length, t.records += dn(e);
1085
1135
  }
1086
1136
  return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
1087
1137
  }
@@ -1094,8 +1144,8 @@ var F = class {
1094
1144
  close() {
1095
1145
  return this.batches = [], Promise.resolve();
1096
1146
  }
1097
- }, cn = {
1098
- name: te,
1147
+ }, fn = {
1148
+ name: Se,
1099
1149
  save: () => Promise.resolve(),
1100
1150
  take: () => Promise.resolve([]),
1101
1151
  remove: () => Promise.resolve(),
@@ -1109,112 +1159,112 @@ var F = class {
1109
1159
  clear: () => Promise.resolve(),
1110
1160
  close: () => Promise.resolve()
1111
1161
  };
1112
- function ln(e) {
1162
+ function pn(e) {
1113
1163
  return e.guard("storage.unavailable", "reading indexedDB", () => globalThis.indexedDB != null) === !0;
1114
1164
  }
1115
- function un(e) {
1116
- return e.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(ne, "1"), localStorage.removeItem(ne), !0)) === !0;
1165
+ function mn(e) {
1166
+ return e.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(we, "1"), localStorage.removeItem(we), !0)) === !0;
1117
1167
  }
1118
- async function dn(e, t, n, r, i) {
1119
- if (e === "none") return cn;
1120
- if (e === "memory") return new F(n, i);
1168
+ async function hn(e, t, n, r, i) {
1169
+ if (e === "none") return fn;
1170
+ if (e === "memory") return new L(n, i);
1121
1171
  if (e === "indexeddb" || e === "auto") {
1122
- if (ln(r)) {
1172
+ if (pn(r)) {
1123
1173
  let e = await r.guardAsync("storage.unavailable", "opening IndexedDB", async () => {
1124
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-3oT4si-p.js");
1174
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-bibcl7ZS.js");
1125
1175
  return new e(t, n, r, i);
1126
1176
  });
1127
1177
  if (e) return e;
1128
1178
  }
1129
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new F(n, i);
1179
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new L(n, i);
1130
1180
  }
1131
- return un(r) ? new on(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new F(n, i));
1181
+ return mn(r) ? new un(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new L(n, i));
1132
1182
  }
1133
1183
  //#endregion
1134
1184
  //#region src/utils/sanitize.ts
1135
- function I(e, t) {
1185
+ function R(e, t) {
1136
1186
  if (e.length <= t) return e;
1137
- let n = fn(e.charCodeAt(t - 1)) ? t - 1 : t;
1187
+ let n = gn(e.charCodeAt(t - 1)) ? t - 1 : t;
1138
1188
  return `${e.slice(0, n)}… [truncated ${String(e.length - n)} chars]`;
1139
1189
  }
1140
- function fn(e) {
1190
+ function gn(e) {
1141
1191
  return e >= 55296 && e <= 56319;
1142
1192
  }
1143
- function pn(e) {
1193
+ function _n(e) {
1144
1194
  return `[Element ${(e.nodeName ?? "NODE").toLowerCase()}${e.id ? `#${e.id}` : ""}${typeof e.className == "string" && e.className ? `.${e.className.trim().split(/\s+/).slice(0, 3).join(".")}` : ""}]`;
1145
1195
  }
1146
- function L(e, t) {
1196
+ function z(e, t) {
1147
1197
  let n = { bytes: 0 };
1148
1198
  return {
1149
- value: z(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1199
+ value: V(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1150
1200
  bytes: n.bytes
1151
1201
  };
1152
1202
  }
1153
- function R(e, t) {
1154
- return t.bytes += B(e) + 2, e;
1203
+ function B(e, t) {
1204
+ return t.bytes += H(e) + 2, e;
1155
1205
  }
1156
- function z(e, t, n, r, i) {
1206
+ function V(e, t, n, r, i) {
1157
1207
  if (e == null) return i.bytes += 4, e;
1158
- if (typeof e == "string") return R(I(e, t.maxAttributeChars), i);
1208
+ if (typeof e == "string") return B(R(e, t.maxAttributeChars), i);
1159
1209
  if (typeof e == "number") return i.bytes += 8, Number.isFinite(e) ? e : String(e);
1160
1210
  if (typeof e == "boolean") return i.bytes += 5, e;
1161
- if (typeof e == "bigint") return R(`${e.toString()}n`, i);
1162
- if (typeof e == "symbol") return R(e.toString(), i);
1163
- if (typeof e == "function") return R(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
1164
- if (r >= t.maxDepth) return R("[MaxDepth]", i);
1165
- if (n.has(e)) return R("[Circular]", i);
1211
+ if (typeof e == "bigint") return B(`${e.toString()}n`, i);
1212
+ if (typeof e == "symbol") return B(e.toString(), i);
1213
+ if (typeof e == "function") return B(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
1214
+ if (r >= t.maxDepth) return B("[MaxDepth]", i);
1215
+ if (n.has(e)) return B("[Circular]", i);
1166
1216
  n.add(e), i.bytes += 2;
1167
1217
  try {
1168
1218
  if (e instanceof Error) return {
1169
- name: R(e.name, i),
1170
- message: R(I(e.message, t.maxAttributeChars), i),
1171
- stack: e.stack ? R(I(e.stack, t.maxStackChars), i) : void 0,
1172
- cause: e.cause ? z(e.cause, t, n, r + 1, i) : void 0
1219
+ name: B(e.name, i),
1220
+ message: B(R(e.message, t.maxAttributeChars), i),
1221
+ stack: e.stack ? B(R(e.stack, t.maxStackChars), i) : void 0,
1222
+ cause: e.cause ? V(e.cause, t, n, r + 1, i) : void 0
1173
1223
  };
1174
- if (e instanceof Date) return R(e.toISOString(), i);
1175
- if (e instanceof RegExp) return R(e.toString(), i);
1224
+ if (e instanceof Date) return B(e.toISOString(), i);
1225
+ if (e instanceof RegExp) return B(e.toString(), i);
1176
1226
  if (e instanceof Map) {
1177
1227
  let a = e, o = {}, s = 0;
1178
1228
  for (let [e, c] of a) {
1179
1229
  if (s >= t.maxArrayLength) {
1180
- o["…"] = R(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1230
+ o["…"] = B(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1181
1231
  break;
1182
1232
  }
1183
1233
  s++;
1184
1234
  let l = String(e);
1185
- i.bytes += B(l) + 4, o[l] = z(c, t, n, r + 1, i);
1235
+ i.bytes += H(l) + 4, o[l] = V(c, t, n, r + 1, i);
1186
1236
  }
1187
1237
  return o;
1188
1238
  }
1189
- if (e instanceof Set) return z([...e].slice(0, t.maxArrayLength), t, n, r, i);
1239
+ if (e instanceof Set) return V([...e].slice(0, t.maxArrayLength), t, n, r, i);
1190
1240
  if (ArrayBuffer.isView(e)) {
1191
1241
  let t = e.length ?? 0;
1192
- return R(`[${e.constructor.name}(${String(t)})]`, i);
1242
+ return B(`[${e.constructor.name}(${String(t)})]`, i);
1193
1243
  }
1194
- if (e instanceof Promise) return R("[Promise]", i);
1195
- if (typeof Node < "u" && e instanceof Node) return R(pn(e), i);
1244
+ if (e instanceof Promise) return B("[Promise]", i);
1245
+ if (typeof Node < "u" && e instanceof Node) return B(_n(e), i);
1196
1246
  if (Array.isArray(e)) {
1197
- let a = e, o = a.slice(0, t.maxArrayLength).map((e) => z(e, t, n, r + 1, i));
1198
- return a.length > t.maxArrayLength && o.push(R(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
1247
+ let a = e, o = a.slice(0, t.maxArrayLength).map((e) => V(e, t, n, r + 1, i));
1248
+ return a.length > t.maxArrayLength && o.push(B(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
1199
1249
  }
1200
1250
  let a = e.toJSON;
1201
- if (typeof a == "function") return z(a.call(e), t, n, r + 1, i);
1251
+ if (typeof a == "function") return V(a.call(e), t, n, r + 1, i);
1202
1252
  let o = e, s = Object.keys(o), c = {}, l = 0;
1203
1253
  for (let e of s) {
1204
1254
  if (l >= t.maxAttributeCount) {
1205
- c["…"] = R(`[${String(s.length - l)} more keys]`, i);
1255
+ c["…"] = B(`[${String(s.length - l)} more keys]`, i);
1206
1256
  break;
1207
1257
  }
1208
- l++, i.bytes += B(e) + 4, c[e] = z(o[e], t, n, r + 1, i);
1258
+ l++, i.bytes += H(e) + 4, c[e] = V(o[e], t, n, r + 1, i);
1209
1259
  }
1210
1260
  return c;
1211
1261
  } catch (e) {
1212
- return R(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1262
+ return B(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1213
1263
  } finally {
1214
1264
  n.delete(e);
1215
1265
  }
1216
1266
  }
1217
- function B(e) {
1267
+ function H(e) {
1218
1268
  let t = 0;
1219
1269
  for (let n = 0; n < e.length; n++) {
1220
1270
  let r = e.charCodeAt(n);
@@ -1224,7 +1274,7 @@ function B(e) {
1224
1274
  }
1225
1275
  //#endregion
1226
1276
  //#region src/transport/exit-flush.ts
1227
- var mn = class {
1277
+ var vn = class {
1228
1278
  deps;
1229
1279
  installed = !1;
1230
1280
  onVisibility = () => {
@@ -1261,15 +1311,15 @@ var mn = class {
1261
1311
  flush(e) {
1262
1312
  let { diagnostics: t } = this.deps, n = this.endpointUrl();
1263
1313
  if (n === null) return;
1264
- let r = this.deps.drainPending();
1314
+ let r = this.deps.drainForExit();
1265
1315
  if (!r || r.records.length === 0) return;
1266
1316
  let i = t.guard("transport.serialize_failed", `the ${e} exit flush could not serialize its batch`, () => this.deps.config.serializer.serialize(r.records));
1267
1317
  if (!i) return;
1268
- if (B(i.body) > 6e4) {
1269
- nn(r, t);
1318
+ if (H(i.body) > 6e4) {
1319
+ sn(r, t);
1270
1320
  return;
1271
1321
  }
1272
- n.searchParams.set(be, r.id), n.searchParams.set(Ue, e);
1322
+ n.searchParams.set(ze, r.id), n.searchParams.set(Ee, e);
1273
1323
  let a = n.toString();
1274
1324
  this.beacon(a, i.body) || this.keepaliveFetch(a, i.body, e);
1275
1325
  }
@@ -1279,36 +1329,36 @@ var mn = class {
1279
1329
  }
1280
1330
  beacon(e, t) {
1281
1331
  return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
1282
- let n = globalThis.navigator;
1283
- return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: c })) : !1;
1332
+ let r = globalThis.navigator;
1333
+ return r?.sendBeacon ? r.sendBeacon(e, new Blob([t], { type: n })) : !1;
1284
1334
  }) === !0;
1285
1335
  }
1286
- keepaliveFetch(e, t, n) {
1287
- let { config: r, diagnostics: i } = this.deps;
1288
- i.guard("transport.http_error", "the keepalive fetch fallback", () => {
1336
+ keepaliveFetch(e, t, r) {
1337
+ let { config: i, diagnostics: a } = this.deps;
1338
+ a.guard("transport.http_error", "the keepalive fetch fallback", () => {
1289
1339
  fetch(e, {
1290
1340
  method: "POST",
1291
1341
  body: t,
1292
- headers: { [d]: c },
1293
- credentials: r.credentials,
1342
+ headers: { [at]: n },
1343
+ credentials: i.credentials,
1294
1344
  keepalive: !0
1295
1345
  }).catch((e) => {
1296
- i.report("transport.http_error", "the exit flush failed", { reason: n }, e);
1346
+ a.report("transport.http_error", "the exit flush failed", { reason: r }, e);
1297
1347
  });
1298
1348
  });
1299
1349
  }
1300
1350
  };
1301
1351
  //#endregion
1302
1352
  //#region src/transport/compression.ts
1303
- async function hn(e) {
1353
+ async function yn(e) {
1304
1354
  let t = globalThis.CompressionStream;
1305
1355
  if (t === void 0) return null;
1306
- let n = new Blob([e]).stream().pipeThrough(new t(ae)), r = await new Response(n).arrayBuffer();
1356
+ let n = new Blob([e]).stream().pipeThrough(new t(pe)), r = await new Response(n).arrayBuffer();
1307
1357
  return new Uint8Array(r);
1308
1358
  }
1309
1359
  //#endregion
1310
1360
  //#region src/transport/errors.ts
1311
- var V = class extends Error {
1361
+ var U = class extends Error {
1312
1362
  kind;
1313
1363
  status;
1314
1364
  retryAfterMs;
@@ -1317,16 +1367,16 @@ var V = class extends Error {
1317
1367
  super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
1318
1368
  }
1319
1369
  };
1320
- function gn(e) {
1370
+ function bn(e) {
1321
1371
  if (!e) return;
1322
1372
  let t = Number(e);
1323
- if (Number.isFinite(t)) return Math.max(0, t * se);
1373
+ if (Number.isFinite(t)) return Math.max(0, t * Ye);
1324
1374
  let n = Date.parse(e);
1325
1375
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
1326
1376
  }
1327
1377
  //#endregion
1328
1378
  //#region src/transport/http-transport.ts
1329
- var _n = class {
1379
+ var xn = class {
1330
1380
  config;
1331
1381
  diagnostics;
1332
1382
  throttledUntil = 0;
@@ -1340,32 +1390,32 @@ var _n = class {
1340
1390
  return Math.max(0, this.throttledUntil - Date.now());
1341
1391
  }
1342
1392
  async post(e) {
1343
- let { config: t } = this, r;
1393
+ let { config: t } = this, n;
1344
1394
  try {
1345
- r = t.serializer.serialize(e.records);
1395
+ n = t.serializer.serialize(e.records);
1346
1396
  } catch (t) {
1347
1397
  this.diagnostics.report("transport.serialize_failed", "serializer threw, dropping the batch", { batchId: e.id }, t);
1348
1398
  return;
1349
1399
  }
1350
- let i = new Headers(await this.resolveHeaders());
1351
- i.set(d, r.contentType), i.set(n, e.id), i.set(at, String(e.attempts));
1352
- let a = await this.encodeBody(r.body);
1353
- typeof a != "string" && i.set(fe, ae);
1354
- let o = await this.dispatch(i, a);
1355
- if (o.ok) {
1400
+ let r = new Headers(await this.resolveHeaders());
1401
+ r.set(at, n.contentType), r.set(p, e.id), r.set(be, String(e.attempts));
1402
+ let i = await this.encodeBody(n.body);
1403
+ typeof i != "string" && r.set(ne, pe);
1404
+ let a = await this.dispatch(r, i);
1405
+ if (a.ok) {
1356
1406
  this.throttledUntil = 0;
1357
1407
  return;
1358
1408
  }
1359
- throw await this.classify(o, e.id);
1409
+ throw await this.classify(a, e.id);
1360
1410
  }
1361
1411
  async encodeBody(e) {
1362
1412
  let { config: t } = this;
1363
- return t.compression !== "gzip" || B(e) < t.compressionThresholdBytes ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => hn(e)) ?? e;
1413
+ return t.compression !== "gzip" || H(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => yn(e)) ?? e;
1364
1414
  }
1365
1415
  async dispatch(e, t) {
1366
1416
  let { config: n } = this, r = new AbortController(), i = setTimeout(() => {
1367
1417
  r.abort();
1368
- }, n.requestTimeoutMs);
1418
+ }, Ae);
1369
1419
  T(i);
1370
1420
  try {
1371
1421
  return await fetch(n.endpoint, {
@@ -1377,28 +1427,28 @@ var _n = class {
1377
1427
  cache: "no-store"
1378
1428
  });
1379
1429
  } catch {
1380
- if (r.signal.aborted) throw new V("timeout", `request exceeded ${String(n.requestTimeoutMs)}ms`);
1430
+ if (r.signal.aborted) throw new U("timeout", `request exceeded ${String(Ae)}ms`);
1381
1431
  let e = globalThis.navigator?.onLine;
1382
- throw new V(e === !1 ? "offline" : "transient", "network error");
1432
+ throw new U(e === !1 ? "offline" : "transient", "network error");
1383
1433
  } finally {
1384
1434
  clearTimeout(i);
1385
1435
  }
1386
1436
  }
1387
1437
  async classify(e, t) {
1388
- let n = e.status, r = gn(e.headers.get(de));
1438
+ let n = e.status, r = bn(e.headers.get(ee));
1389
1439
  if (n === 401 || n === 403) return this.diagnostics.report("transport.rejected_credentials", `server returned ${String(n)}. In a cross-origin iframe the session cookie is a third-party cookie and is very likely blocked. Forward to the platform document instead of promoting to sender, or issue the cookie with the Partitioned attribute.`, {
1390
1440
  status: n,
1391
1441
  endpoint: this.config.endpoint
1392
- }), new V("permanent", `rejected with ${String(n)}`, n);
1393
- if (n === 413) return new V("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
1442
+ }), new U("permanent", `rejected with ${String(n)}`, n);
1443
+ if (n === 413) return new U("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
1394
1444
  if (n === 429 || n === 503) {
1395
1445
  let e = n === 429;
1396
- return this.throttledUntil = Date.now() + (r ?? this.config.retry.baseDelayMs), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new V("throttled", e ? "throttled" : "service unavailable", n, r);
1446
+ return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new U("throttled", e ? "throttled" : "service unavailable", n, r);
1397
1447
  }
1398
- return n === 408 || n >= 500 ? new V("transient", `server error ${String(n)}`, n) : (this.diagnostics.report("transport.dropped_permanent", `server rejected the batch with ${String(n)}, dropping it`, {
1448
+ return n === 408 || n >= 500 ? new U("transient", `server error ${String(n)}`, n) : (this.diagnostics.report("transport.dropped_permanent", `server rejected the batch with ${String(n)}, dropping it`, {
1399
1449
  batchId: t,
1400
1450
  status: n
1401
- }), new V("permanent", `rejected with ${String(n)}`, n));
1451
+ }), new U("permanent", `rejected with ${String(n)}`, n));
1402
1452
  }
1403
1453
  async readMaxBytes(e) {
1404
1454
  return this.diagnostics.guardAsync("transport.http_error", "reading the 413 body", async () => {
@@ -1410,7 +1460,7 @@ var _n = class {
1410
1460
  let { headers: e } = this.config;
1411
1461
  return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "headers() threw", () => Promise.resolve(e())) ?? {} : e : {};
1412
1462
  }
1413
- }, vn = class {
1463
+ }, Sn = class {
1414
1464
  storage;
1415
1465
  transport;
1416
1466
  diagnostics;
@@ -1427,10 +1477,10 @@ var _n = class {
1427
1477
  this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
1428
1478
  }
1429
1479
  start() {
1430
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(this.config.retry.idleDelayMs);
1480
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(f);
1431
1481
  }
1432
1482
  nudge() {
1433
- this.draining || this.schedule(this.config.retry.baseDelayMs);
1483
+ this.draining || this.schedule(de);
1434
1484
  }
1435
1485
  stop() {
1436
1486
  this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
@@ -1447,14 +1497,14 @@ var _n = class {
1447
1497
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1448
1498
  }
1449
1499
  backoffMs() {
1450
- let e = Math.min(this.config.retry.baseDelayMs * 2 ** this.attempt, this.config.retry.maxDelayMs);
1500
+ let e = Math.min(de * 2 ** this.attempt, g);
1451
1501
  return Math.random() * e;
1452
1502
  }
1453
1503
  async drain() {
1454
1504
  if (!this.draining) {
1455
1505
  this.draining = !0;
1456
1506
  try {
1457
- await Qt("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(this.config.retry.idleDelayMs);
1507
+ await nn("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(f);
1458
1508
  } finally {
1459
1509
  this.draining = !1;
1460
1510
  }
@@ -1462,29 +1512,29 @@ var _n = class {
1462
1512
  }
1463
1513
  async drainLocked() {
1464
1514
  try {
1465
- if (globalThis.navigator?.onLine === !1) return this.schedule(this.config.retry.idleDelayMs), !0;
1515
+ if (globalThis.navigator?.onLine === !1) return this.schedule(f), !0;
1466
1516
  let e = await this.storage.take(this.batchesPerDrain);
1467
- if (e.length === 0) return this.schedule(this.config.retry.idleDelayMs), !0;
1517
+ if (e.length === 0) return this.schedule(f), !0;
1468
1518
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
1469
- return this.schedule(e.length === this.batchesPerDrain ? 0 : this.config.retry.idleDelayMs), !0;
1519
+ return this.schedule(e.length === this.batchesPerDrain ? 0 : f), !0;
1470
1520
  } catch (e) {
1471
1521
  return this.diagnostics.report("storage.degraded", "the drain loop threw", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
1472
1522
  }
1473
1523
  }
1474
1524
  async deliver(e) {
1475
- if (e.attempts >= this.config.storage.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1525
+ if (e.attempts >= m.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1476
1526
  batchId: e.id,
1477
1527
  records: e.records.length
1478
1528
  }), await this.storage.remove(e.id), !0;
1479
1529
  try {
1480
1530
  return await this.transport.send(e), await this.storage.remove(e.id), this.attempt = 0, !0;
1481
1531
  } catch (t) {
1482
- let n = t instanceof V ? t : void 0;
1483
- return n?.kind === "permanent" ? (await this.storage.remove(e.id), !0) : n?.kind === "too_large" ? (await this.splitStored(e, n.maxBytes), !0) : n?.kind === "offline" ? (this.schedule(this.config.retry.idleDelayMs), !1) : (await this.storage.bumpAttempts(e.id, e.attempts + 1), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
1532
+ let n = t instanceof U ? t : void 0;
1533
+ return n?.kind === "permanent" ? (await this.storage.remove(e.id), !0) : n?.kind === "too_large" ? (await this.splitStored(e, n.maxBytes), !0) : n?.kind === "offline" ? (this.schedule(f), !1) : (await this.storage.bumpAttempts(e.id, e.attempts + 1), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
1484
1534
  }
1485
1535
  }
1486
1536
  async splitStored(e, t) {
1487
- let n = Zt(e);
1537
+ let n = tn(e);
1488
1538
  if (await this.storage.remove(e.id), !n) {
1489
1539
  this.diagnostics.report("transport.dropped_permanent", "a single record exceeds the server limit and was dropped", {
1490
1540
  batchId: e.id,
@@ -1499,72 +1549,31 @@ var _n = class {
1499
1549
  });
1500
1550
  for (let e of n) await this.storage.save(e);
1501
1551
  }
1502
- }, yn = {
1552
+ }, Cn = {
1503
1553
  TRACE: "debug",
1504
1554
  DEBUG: "debug",
1505
1555
  INFO: "info",
1506
1556
  WARN: "warn",
1507
1557
  ERROR: "error",
1508
1558
  FATAL: "error"
1509
- }, bn = class {
1510
- enabled;
1559
+ }, wn = class {
1511
1560
  minLevel;
1512
- constructor(e, t) {
1513
- this.enabled = e, this.minLevel = t;
1561
+ constructor(e) {
1562
+ this.minLevel = e;
1514
1563
  }
1515
- update(e, t) {
1516
- this.enabled = e, this.minLevel = t;
1564
+ update(e) {
1565
+ this.minLevel = e;
1517
1566
  }
1518
1567
  write(e, t, n) {
1519
- if (!this.enabled || m[e] < m[this.minLevel] || typeof console > "u") return;
1520
- let r = `%c${he}%c ${e}`;
1568
+ if (this.minLevel === null || S[e] < S[this.minLevel] || typeof console > "u") return;
1569
+ let r = `%c${We}%c ${e}`;
1521
1570
  if (n === void 0) {
1522
- console[yn[e]](r, i, "", t);
1571
+ console[Cn[e]](r, s, "", t);
1523
1572
  return;
1524
1573
  }
1525
- console[yn[e]](r, i, "", t, n);
1526
- }
1527
- }, H = null;
1528
- function U(e, t) {
1529
- let n = e[t];
1530
- return n !== void 0 && e instanceof n;
1531
- }
1532
- function xn(e) {
1533
- if (H) return H;
1534
- let t = globalThis, n = t.navigator?.userAgent ?? "", r = "browser", i, a, o = !1, s = t.fin?.me;
1535
- return U(t, "ServiceWorkerGlobalScope") ? (r = "service_worker", o = !0) : U(t, "SharedWorkerGlobalScope") ? (r = "shared_worker", o = !0) : U(t, "WorkerGlobalScope") ? (r = "web_worker", o = !0) : s === void 0 ? t.Capacitor !== void 0 || t.Ionic !== void 0 ? r = "ionic" : t.cordova !== void 0 || Sn(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Pe.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
1536
- let e = s.identity;
1537
- i = e?.uuid, a = e?.name;
1538
- })), H = {
1539
- platform: r,
1540
- openfinUuid: i,
1541
- openfinName: a,
1542
- userAgent: n,
1543
- isWorker: o,
1544
- isTopLevelDocument: Cn()
1545
- }, H;
1546
- }
1547
- function Sn(t) {
1548
- return Ye.test(t) ? !0 : (h.test(t) || ge.test(t) && e.test(t)) && t.includes("AppleWebKit") && !t.includes("Safari/");
1549
- }
1550
- function Cn() {
1551
- if (typeof window > "u") return !1;
1552
- try {
1553
- return window.self === window.top;
1554
- } catch {
1555
- return !1;
1574
+ console[Cn[e]](r, s, "", t, n);
1556
1575
  }
1557
- }
1558
- function wn() {
1559
- try {
1560
- return typeof location < "u" ? location.href : "";
1561
- } catch {
1562
- return "";
1563
- }
1564
- }
1565
- //#endregion
1566
- //#region src/utils/sequence.ts
1567
- var Tn = class {
1576
+ }, Tn = class {
1568
1577
  value = 0;
1569
1578
  next() {
1570
1579
  return ++this.value;
@@ -1572,64 +1581,84 @@ var Tn = class {
1572
1581
  reset() {
1573
1582
  this.value = 0;
1574
1583
  }
1575
- };
1576
- //#endregion
1577
- //#region src/utils/tracing.ts
1578
- function En() {
1579
- return j(16);
1584
+ }, En = /^[0-9a-f]{32}$/, Dn = /^[0-9a-f]{16}$/, On = /[1-9a-f]/;
1585
+ function kn() {
1586
+ return import(
1587
+ /* @vite-ignore */
1588
+ "@opentelemetry/api"
1589
+ );
1590
+ }
1591
+ function An(e) {
1592
+ return En.test(e.traceId) && On.test(e.traceId) && Dn.test(e.spanId) && On.test(e.spanId);
1580
1593
  }
1581
- function Dn() {
1582
- return j(8);
1594
+ function jn() {
1595
+ return N(16);
1583
1596
  }
1584
- function On() {
1597
+ function Mn() {
1598
+ return N(8);
1599
+ }
1600
+ function Nn() {
1585
1601
  return {
1586
- traceId: En(),
1587
- spanId: Dn(),
1602
+ traceId: jn(),
1603
+ spanId: Mn(),
1588
1604
  traceFlags: 1,
1589
1605
  startedAt: Date.now()
1590
1606
  };
1591
1607
  }
1592
- function kn(e) {
1608
+ function Pn(e) {
1593
1609
  return {
1594
1610
  traceId: e.traceId,
1595
1611
  spanId: e.spanId,
1596
1612
  traceFlags: e.traceFlags
1597
1613
  };
1598
1614
  }
1599
- var An = class {
1615
+ var Fn = class {
1600
1616
  diagnostics;
1601
1617
  maxAgeMs;
1602
- ambient = On();
1603
- constructor(e, t = ce) {
1604
- this.diagnostics = e, this.maxAgeMs = t;
1618
+ load;
1619
+ ambient = Nn();
1620
+ otel;
1621
+ constructor(e, t = st, n = kn) {
1622
+ this.diagnostics = e, this.maxAgeMs = t, this.load = n;
1623
+ }
1624
+ async loadOtel() {
1625
+ try {
1626
+ this.otel = await this.load();
1627
+ } catch (e) {
1628
+ this.diagnostics.report("trace.otel_failed", "@opentelemetry/api is not available, so records carry this library's own trace ids", void 0, e);
1629
+ }
1605
1630
  }
1606
1631
  resolve() {
1607
- let e = this.diagnostics.guard("trace.otel_failed", "reading the active OpenTelemetry span", () => {
1608
- let e = ut.getActiveSpan();
1609
- if (e === void 0) return;
1610
- let t = e.spanContext();
1611
- if (ct(t)) return {
1612
- traceId: t.traceId,
1613
- spanId: t.spanId,
1614
- traceFlags: t.traceFlags
1632
+ let e = this.activeSpanContext();
1633
+ return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), Pn(this.ambient)) : e;
1634
+ }
1635
+ activeSpanContext() {
1636
+ let e = this.otel;
1637
+ if (e) return this.diagnostics.guard("trace.otel_failed", "reading the active OpenTelemetry span", () => {
1638
+ let t = e.trace.getActiveSpan();
1639
+ if (t === void 0) return;
1640
+ let n = t.spanContext();
1641
+ if (An(n)) return {
1642
+ traceId: n.traceId,
1643
+ spanId: n.spanId,
1644
+ traceFlags: n.traceFlags
1615
1645
  };
1616
1646
  });
1617
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), kn(this.ambient)) : e;
1618
1647
  }
1619
1648
  rotate(e) {
1620
- return this.ambient = On(), kn(this.ambient);
1649
+ return this.ambient = Nn(), Pn(this.ambient);
1621
1650
  }
1622
1651
  headers() {
1623
- let e = {};
1624
- if (this.diagnostics.guard("trace.otel_failed", "injecting OpenTelemetry headers", () => {
1625
- lt.inject(st.active(), e);
1652
+ let e = {}, t = this.otel;
1653
+ if (t && this.diagnostics.guard("trace.otel_failed", "injecting OpenTelemetry headers", () => {
1654
+ t.propagation.inject(t.context.active(), e);
1626
1655
  }), !e.traceparent) {
1627
1656
  let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
1628
- e.traceparent = `00-${t.traceId}-${t.spanId}-${n}`;
1657
+ e[Qe] = `00-${t.traceId}-${t.spanId}-${n}`;
1629
1658
  }
1630
1659
  return e;
1631
1660
  }
1632
- }, jn = class {
1661
+ }, In = class {
1633
1662
  buffer;
1634
1663
  pointer = 0;
1635
1664
  filled = !1;
@@ -1637,13 +1666,6 @@ var An = class {
1637
1666
  constructor(e) {
1638
1667
  this.capacity = Math.max(e, 1), this.buffer = Array(this.capacity);
1639
1668
  }
1640
- resize(e) {
1641
- let t = Math.max(e, 1);
1642
- if (t === this.capacity) return;
1643
- let n = this.snapshot().slice(-t);
1644
- this.capacity = t, this.clear();
1645
- for (let e of n) this.push(e);
1646
- }
1647
1669
  push(e) {
1648
1670
  this.buffer[this.pointer] = e, this.pointer = (this.pointer + 1) % this.capacity, this.pointer === 0 && (this.filled = !0);
1649
1671
  }
@@ -1656,15 +1678,15 @@ var An = class {
1656
1678
  };
1657
1679
  //#endregion
1658
1680
  //#region src/transport/serializers/ecs.ts
1659
- function Mn(e) {
1660
- return De.test(e) ? Number(BigInt(e) / Xe) : Date.now();
1681
+ function Ln(e) {
1682
+ return Pe.test(e) ? Number(BigInt(e) / Le) : Date.now();
1661
1683
  }
1662
- var Nn = {
1684
+ var Rn = {
1663
1685
  name: "ecs",
1664
1686
  serialize(e) {
1665
1687
  return {
1666
1688
  body: `${e.map((e) => {
1667
- let t = Mn(e.timeUnixNano);
1689
+ let t = Ln(e.timeUnixNano);
1668
1690
  return JSON.stringify({
1669
1691
  "@timestamp": new Date(t).toISOString(),
1670
1692
  message: e.body,
@@ -1672,11 +1694,11 @@ var Nn = {
1672
1694
  trace: { id: e.traceId },
1673
1695
  span: { id: e.spanId },
1674
1696
  service: {
1675
- name: e.resource[Be],
1676
- version: e.resource[Me],
1677
- environment: e.resource[Qe]
1697
+ name: e.resource[c],
1698
+ version: e.resource[ue],
1699
+ environment: e.resource[o]
1678
1700
  },
1679
- user_agent: { original: e.resource[we] },
1701
+ user_agent: { original: e.resource[_t] },
1680
1702
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
1681
1703
  labels: {
1682
1704
  ...e.resource,
@@ -1684,19 +1706,19 @@ var Nn = {
1684
1706
  }
1685
1707
  });
1686
1708
  }).join("\n")}\n`,
1687
- contentType: ue
1709
+ contentType: qe
1688
1710
  };
1689
1711
  }
1690
1712
  };
1691
1713
  //#endregion
1692
1714
  //#region src/transport/serializers/otlp.ts
1693
- function Pn(e) {
1694
- return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(Pn).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: W(e) } } : null;
1715
+ function zn(e) {
1716
+ return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(zn).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: W(e) } } : null;
1695
1717
  }
1696
1718
  function W(e) {
1697
1719
  let t = [];
1698
1720
  for (let [n, r] of Object.entries(e)) {
1699
- let e = Pn(r);
1721
+ let e = zn(r);
1700
1722
  e && t.push({
1701
1723
  key: n,
1702
1724
  value: e
@@ -1704,19 +1726,19 @@ function W(e) {
1704
1726
  }
1705
1727
  return t;
1706
1728
  }
1707
- var Fn = /* @__PURE__ */ new WeakMap();
1708
- function In(e) {
1709
- let t = Fn.get(e);
1729
+ var Bn = /* @__PURE__ */ new WeakMap();
1730
+ function Vn(e) {
1731
+ let t = Bn.get(e);
1710
1732
  if (t !== void 0) return t;
1711
1733
  let n = JSON.stringify(e);
1712
- return Fn.set(e, n), n;
1734
+ return Bn.set(e, n), n;
1713
1735
  }
1714
1736
  var G = {
1715
- name: a,
1737
+ name: yt,
1716
1738
  serialize(e) {
1717
1739
  let t = /* @__PURE__ */ new Map();
1718
1740
  for (let n of e) {
1719
- let e = In(n.resource), r = t.get(e);
1741
+ let e = Vn(n.resource), r = t.get(e);
1720
1742
  if (r) {
1721
1743
  r.records.push(n);
1722
1744
  continue;
@@ -1730,8 +1752,8 @@ var G = {
1730
1752
  resource: { attributes: W(e.resource) },
1731
1753
  scopeLogs: [{
1732
1754
  scope: {
1733
- name: p,
1734
- version: ee
1755
+ name: Fe,
1756
+ version: dt
1735
1757
  },
1736
1758
  logRecords: e.records.map((e) => ({
1737
1759
  timeUnixNano: e.timeUnixNano,
@@ -1748,93 +1770,67 @@ var G = {
1748
1770
  }));
1749
1771
  return {
1750
1772
  body: JSON.stringify({ resourceLogs: n }),
1751
- contentType: tt
1773
+ contentType: le
1752
1774
  };
1753
1775
  }
1754
1776
  };
1755
1777
  //#endregion
1756
1778
  //#region src/core/config.ts
1757
- function Ln(e) {
1779
+ function Hn(e) {
1758
1780
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
1759
1781
  }
1760
- function Rn(e, t, n) {
1761
- return e === void 0 ? t ?? G : e === "otlp" ? G : e === "ecs" ? Nn : Ln(e) ? e : (n.report("config.invalid", `serializer must be "${a}", "ecs" or an implementation`), G);
1782
+ function Un(e, t, n) {
1783
+ return e === void 0 ? t ?? G : e === "otlp" ? G : e === "ecs" ? Rn : Hn(e) ? e : (n.report("config.invalid", `serializer must be "${yt}", "ecs" or an implementation`), G);
1784
+ }
1785
+ function Wn(e, t) {
1786
+ return e === void 0 ? t : e === !1 ? null : e === !0 ? l : e;
1762
1787
  }
1763
- function zn(e, t, n) {
1764
- let i = n ?? o, a = {
1765
- ...i,
1788
+ function Gn(e, t, n) {
1789
+ let r = n ?? Ge, i = {
1790
+ ...r,
1766
1791
  ...e,
1767
- serializer: Rn(e.serializer, n?.serializer, t),
1768
- streams: {
1769
- logs: {
1770
- ...i.streams.logs,
1771
- ...e.streams?.logs
1772
- },
1773
- metrics: {
1774
- ...i.streams.metrics,
1775
- ...e.streams?.metrics
1776
- }
1777
- },
1778
- storage: {
1779
- ...i.storage,
1780
- ...e.storage
1781
- },
1782
- retry: {
1783
- ...i.retry,
1784
- ...e.retry
1785
- },
1792
+ serializer: Un(e.serializer, n?.serializer, t),
1793
+ console: Wn(e.console, r.console),
1786
1794
  sampling: {
1787
- ...i.sampling,
1795
+ ...r.sampling,
1788
1796
  ...e.sampling,
1789
1797
  rates: {
1790
- ...i.sampling.rates,
1798
+ ...r.sampling.rates,
1791
1799
  ...e.sampling?.rates
1792
1800
  }
1793
1801
  },
1794
- journey: {
1795
- ...i.journey,
1796
- ...e.journey
1797
- },
1798
1802
  bus: {
1799
- ...i.bus,
1803
+ ...r.bus,
1800
1804
  ...e.bus
1801
1805
  },
1802
1806
  capture: {
1803
- ...i.capture,
1807
+ ...r.capture,
1804
1808
  ...e.capture
1805
- },
1806
- limits: {
1807
- ...i.limits,
1808
- ...e.limits
1809
- },
1810
- console: {
1811
- ...i.console,
1812
- ...e.console
1813
1809
  }
1814
1810
  };
1815
- if (!a.endpoint) t.report("config.invalid", "endpoint is missing. Records will be built and dropped, never sent.");
1811
+ if (!i.endpoint) t.report("config.invalid", "endpoint is missing. Records will be built and dropped, never sent.");
1816
1812
  else try {
1817
- new URL(a.endpoint);
1813
+ new URL(i.endpoint);
1818
1814
  } catch (e) {
1819
- t.report("config.invalid", `endpoint is not a valid absolute URL: ${a.endpoint}`, void 0, e);
1820
- }
1821
- a.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${pe}'.`), pe);
1822
- let s = a.sampling.defaultRate;
1823
- (typeof s != "number" || s < 0 || s > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1, got ${String(s)}`), a.sampling.defaultRate = 1);
1824
- let c = Object.entries(a.sampling.rates);
1825
- for (let [e, n] of c) (typeof n != "number" || n < 0 || n > 1) && (t.report("config.invalid", `sampling.rates["${e}"] must be 0..1, got ${String(n)}`), a.sampling.rates[e] = 1);
1826
- a.capture.ignoreUrls = a.capture.ignoreUrls.filter((e) => e !== n?.endpoint), a.endpoint && !a.capture.ignoreUrls.includes(a.endpoint) && (a.capture.ignoreUrls = [...a.capture.ignoreUrls, a.endpoint]);
1827
- let l = /* @__PURE__ */ new Set([...Object.keys(o), ...r]);
1828
- for (let n of Object.keys(e)) l.has(n) || t.report("config.invalid", `unknown config key "${n}", ignored. Typo?`);
1829
- return a;
1830
- }
1831
- function Bn(e, t) {
1832
- for (let n of Object.keys(t)) le.includes(n) || Object.assign(e, { [n]: t[n] });
1833
- for (let n of le) Object.assign(e[n], t[n]);
1815
+ t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}`, void 0, e);
1816
+ }
1817
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${tt}'.`), tt);
1818
+ let a = i.sampling.defaultRate;
1819
+ (typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1, got ${String(a)}`), i.sampling.defaultRate = 1);
1820
+ let o = Object.entries(i.sampling.rates);
1821
+ for (let [e, n] of o) (typeof n != "number" || n < 0 || n > 1) && (t.report("config.invalid", `sampling.rates["${e}"] must be 0..1, got ${String(n)}`), i.sampling.rates[e] = 1);
1822
+ i.capture.ignoreUrls = i.capture.ignoreUrls.filter((e) => e !== n?.endpoint), i.endpoint && !i.capture.ignoreUrls.includes(i.endpoint) && (i.capture.ignoreUrls = [...i.capture.ignoreUrls, i.endpoint]);
1823
+ let s = /* @__PURE__ */ new Set([...Object.keys(Ge), ...De]);
1824
+ for (let n of Object.keys(e)) s.has(n) || t.report("config.invalid", `unknown config key "${n}", ignored. Typo?`);
1825
+ return i;
1826
+ }
1827
+ function Kn(e, t) {
1828
+ for (let n of Object.keys(t)) ge.includes(n) || Object.assign(e, { [n]: t[n] });
1829
+ for (let n of ge) Object.assign(e[n], t[n]);
1834
1830
  }
1835
1831
  //#endregion
1836
1832
  //#region src/core/context.ts
1837
- var Vn = class {
1833
+ var qn = class {
1838
1834
  map = /* @__PURE__ */ new Map();
1839
1835
  set(e, t) {
1840
1836
  this.map.set(e, t);
@@ -1854,12 +1850,12 @@ var Vn = class {
1854
1850
  getAll() {
1855
1851
  return Object.fromEntries(this.map);
1856
1852
  }
1857
- }, Hn = class {
1853
+ }, Jn = class {
1858
1854
  handler;
1859
1855
  throttleMs;
1860
1856
  counters = /* @__PURE__ */ new Map();
1861
1857
  lastEmitted = /* @__PURE__ */ new Map();
1862
- constructor(e, t = Le) {
1858
+ constructor(e, t = se) {
1863
1859
  this.handler = e, this.throttleMs = t;
1864
1860
  }
1865
1861
  setHandler(e) {
@@ -1884,7 +1880,7 @@ var Vn = class {
1884
1880
  if (this.handler) try {
1885
1881
  this.handler(o);
1886
1882
  } catch (e) {
1887
- this.count("handler.threw"), typeof console < "u" && console.warn(`${he} onDiagnostic handler threw`, e);
1883
+ this.count("handler.threw"), typeof console < "u" && console.warn(`${We} onDiagnostic handler threw`, e);
1888
1884
  }
1889
1885
  }
1890
1886
  guard(e, t, n) {
@@ -1909,20 +1905,22 @@ var Vn = class {
1909
1905
  reset() {
1910
1906
  this.counters.clear(), this.lastEmitted.clear();
1911
1907
  }
1908
+ }, Yn = {
1909
+ maxAgeMs: Ie,
1910
+ endOnOwnerClose: !1,
1911
+ urlParam: $e
1912
1912
  };
1913
- //#endregion
1914
- //#region src/core/journey.ts
1915
1913
  function K(e, t) {
1916
1914
  let n = Reflect.get(e, t);
1917
1915
  return typeof n == "string" && n !== "" ? n : void 0;
1918
1916
  }
1919
- function Un(e, t) {
1917
+ function Xn(e, t) {
1920
1918
  let n = Reflect.get(e, t);
1921
1919
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
1922
1920
  }
1923
- function Wn(e) {
1921
+ function Zn(e) {
1924
1922
  if (typeof e != "object" || !e) return null;
1925
- let t = K(e, "id"), n = K(e, "name"), r = Un(e, "startedAt");
1923
+ let t = K(e, "id"), n = K(e, "name"), r = Xn(e, "startedAt");
1926
1924
  return t === void 0 || n === void 0 || r === void 0 ? null : {
1927
1925
  id: t,
1928
1926
  name: n,
@@ -1931,27 +1929,27 @@ function Wn(e) {
1931
1929
  ownerContextId: K(e, "ownerContextId") ?? ""
1932
1930
  };
1933
1931
  }
1934
- function Gn(e) {
1932
+ function Qn(e) {
1935
1933
  if (typeof e != "object" || !e) return null;
1936
1934
  let t = K(e, "i"), n = K(e, "n");
1937
1935
  return t === void 0 || n === void 0 ? null : {
1938
1936
  id: t,
1939
1937
  name: n,
1940
- startedAt: Un(e, "s") ?? Date.now(),
1938
+ startedAt: Xn(e, "s") ?? Date.now(),
1941
1939
  parentId: void 0,
1942
1940
  ownerContextId: ""
1943
1941
  };
1944
1942
  }
1945
- function Kn(e) {
1943
+ function $n(e) {
1946
1944
  let t = JSON.stringify({
1947
1945
  i: e.id,
1948
1946
  n: e.name.slice(0, 64),
1949
1947
  s: e.startedAt
1950
1948
  }), n = new TextEncoder().encode(t), r = "";
1951
1949
  for (let e of n) r += String.fromCharCode(e);
1952
- return btoa(r).replace(ke, "-").replace(_e, "_").replace(je, "");
1950
+ return btoa(r).replace(Re, "-").replace(Te, "_").replace(Be, "");
1953
1951
  }
1954
- function qn(e, t) {
1952
+ function er(e, t) {
1955
1953
  let n = new Promise((e, n) => {
1956
1954
  T(setTimeout(() => {
1957
1955
  n(/* @__PURE__ */ Error(`timed out after ${String(t)}ms`));
@@ -1959,7 +1957,7 @@ function qn(e, t) {
1959
1957
  });
1960
1958
  return Promise.race([e, n]);
1961
1959
  }
1962
- var Jn = class {
1960
+ var tr = class {
1963
1961
  options;
1964
1962
  diagnostics;
1965
1963
  contextId;
@@ -1975,14 +1973,14 @@ var Jn = class {
1975
1973
  async bootstrap() {
1976
1974
  let e = this.readUrlToken();
1977
1975
  if (e && this.adopt(e, "url")) return;
1978
- let t = this.diagnostics.guard("storage.unavailable", "reading the persisted journey", () => sessionStorage.getItem(x));
1976
+ let t = this.diagnostics.guard("storage.unavailable", "reading the persisted journey", () => sessionStorage.getItem(C));
1979
1977
  if (t && this.restore(t)) return;
1980
1978
  let n = await this.readOpenFinToken();
1981
1979
  n !== null && this.adopt(n, "openfin.customData");
1982
1980
  }
1983
1981
  start(e, t = {}) {
1984
1982
  let n = {
1985
- id: t.id ?? M(),
1983
+ id: t.id ?? P(),
1986
1984
  name: e,
1987
1985
  startedAt: Date.now(),
1988
1986
  parentId: t.parent ? this.journey?.id : void 0,
@@ -2000,7 +1998,7 @@ var Jn = class {
2000
1998
  getToken() {
2001
1999
  let e = this.journey;
2002
2000
  if (e === null) return;
2003
- let t = Kn(e);
2001
+ let t = $n(e);
2004
2002
  if (t.length > 256) {
2005
2003
  this.diagnostics.report("journey.token_too_large", "journey token exceeded the size cap and was not issued", { length: t.length });
2006
2004
  return;
@@ -2024,7 +2022,7 @@ var Jn = class {
2024
2022
  this.clearTimer();
2025
2023
  }
2026
2024
  restore(e) {
2027
- let t = Wn(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
2025
+ let t = Zn(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
2028
2026
  return t === null ? !1 : Date.now() - t.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "discarded a persisted journey older than maxAgeMs", { name: t.name }), this.clearStored(), !1) : (this.setJourney(t), this.diagnostics.report("journey.adopted", `resumed journey "${t.name}"`, {
2029
2027
  source: "sessionStorage",
2030
2028
  journeyId: t.id
@@ -2032,13 +2030,13 @@ var Jn = class {
2032
2030
  }
2033
2031
  decodeToken(e) {
2034
2032
  return this.diagnostics.guard("config.invalid", "decoding a seeded journey token", () => {
2035
- let t = e.replace(We, "+").replace(ze, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
2036
- return Gn(JSON.parse(new TextDecoder().decode(i)));
2033
+ let t = e.replace(rt, "+").replace(Xe, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
2034
+ return Qn(JSON.parse(new TextDecoder().decode(i)));
2037
2035
  }) ?? null;
2038
2036
  }
2039
2037
  setJourney(e) {
2040
2038
  if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "persisting the journey", () => {
2041
- e === null ? sessionStorage.removeItem(x) : sessionStorage.setItem(x, JSON.stringify(e));
2039
+ e === null ? sessionStorage.removeItem(C) : sessionStorage.setItem(C, JSON.stringify(e));
2042
2040
  }), e === null) return;
2043
2041
  let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
2044
2042
  this.diagnostics.report("journey.expired", `journey "${e.name}" hit maxAgeMs and was ended automatically`, { journeyId: e.id }), this.journey = null, this.expiryTimer = null, this.clearStored();
@@ -2047,7 +2045,7 @@ var Jn = class {
2047
2045
  }
2048
2046
  clearStored() {
2049
2047
  this.diagnostics.guard("storage.unavailable", "clearing the persisted journey", () => {
2050
- sessionStorage.removeItem(x);
2048
+ sessionStorage.removeItem(C);
2051
2049
  });
2052
2050
  }
2053
2051
  clearTimer() {
@@ -2059,116 +2057,184 @@ var Jn = class {
2059
2057
  async readOpenFinToken() {
2060
2058
  let e = globalThis.fin?.me, t = e?.getOptions;
2061
2059
  if (t === void 0) return null;
2062
- let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => qn(t.call(e), qe)))?.customData?.[Ve];
2060
+ let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => er(t.call(e), Ze)))?.customData?.[it];
2063
2061
  return typeof n == "string" ? n : null;
2064
2062
  }
2065
2063
  };
2066
2064
  //#endregion
2067
2065
  //#region src/core/sampling.ts
2068
- function Yn(e) {
2069
- let t = f;
2070
- for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, g);
2066
+ function nr(e) {
2067
+ let t = ye;
2068
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, h);
2071
2069
  return t >>> 0;
2072
2070
  }
2073
2071
  function q(e, t) {
2074
2072
  let n = e.attributes[t];
2075
2073
  return typeof n == "string" ? n : "";
2076
2074
  }
2077
- function Xn(e, t) {
2075
+ function rr(e, t) {
2078
2076
  let { rates: n, defaultRate: r } = t.sampling, i, a = -1;
2079
2077
  for (let [t, r] of Object.entries(n)) (e === t || e.startsWith(`${t}.`)) && t.length > a && (i = r, a = t.length);
2080
2078
  return i ?? r;
2081
2079
  }
2082
- function Zn(e, t) {
2083
- if (e.severityText === "ERROR" || e.severityText === "FATAL" || t.sampling.alwaysSampleTypes.includes(q(e, "log.type"))) return !0;
2084
- let n = Xn(q(e, b), t);
2085
- return n >= 1 ? !0 : n <= 0 ? !1 : Yn(q(e, "journey.id") || e.traceId) / ot < n;
2080
+ function ir(e, t) {
2081
+ if (e.level === "ERROR" || e.level === "FATAL" || t.sampling.alwaysSampleTypes.includes(e.type)) return !0;
2082
+ let n = rr(e.namespace, t);
2083
+ return n >= 1 ? !0 : n <= 0 ? !1 : nr(e.journeyId || e.traceId) / Ue < n;
2086
2084
  }
2085
+ function ar(e, t) {
2086
+ return ir({
2087
+ level: e.severityText,
2088
+ type: q(e, b),
2089
+ namespace: q(e, x),
2090
+ journeyId: q(e, y),
2091
+ traceId: e.traceId
2092
+ }, t);
2093
+ }
2094
+ var or = class {
2095
+ windowStart = 0;
2096
+ count = 0;
2097
+ allow(e) {
2098
+ if (e.severityText !== "ERROR" && e.severityText !== "FATAL") return !0;
2099
+ let t = Date.now();
2100
+ return t - this.windowStart > 1e4 && (this.windowStart = t, this.count = 0), this.count++, this.count <= 500;
2101
+ }
2102
+ };
2087
2103
  //#endregion
2088
2104
  //#region src/core/pipeline.ts
2089
- function Qn(e) {
2090
- return e.attributes[y] === me;
2091
- }
2092
- var $n = class {
2093
- config;
2094
- name;
2095
- diagnostics;
2105
+ function sr(e) {
2106
+ return e.attributes[b] === nt;
2107
+ }
2108
+ var cr = {
2109
+ logs: {
2110
+ flushIntervalMs: Oe,
2111
+ batchSize: 100
2112
+ },
2113
+ metrics: {
2114
+ flushIntervalMs: Me,
2115
+ batchSize: 500
2116
+ }
2117
+ }, lr = class {
2118
+ options;
2119
+ onFlush;
2096
2120
  pending = [];
2097
- constructor(e, t, n) {
2098
- this.config = e, this.name = t, this.diagnostics = n;
2099
- }
2100
- get options() {
2101
- return this.config.streams[this.name];
2102
- }
2103
- get capacity() {
2104
- return Math.max(this.options.batchSize, 1) * 10;
2121
+ timer = null;
2122
+ constructor(e, t) {
2123
+ this.options = e, this.onFlush = t;
2105
2124
  }
2106
2125
  add(e) {
2107
- this.pending.length >= this.capacity && (this.pending.shift(), this.diagnostics.count("record.dropped_pending_full")), this.pending.push(e);
2126
+ if (this.pending.push(e), this.pending.length >= this.options.batchSize) {
2127
+ this.onFlush(this);
2128
+ return;
2129
+ }
2130
+ this.arm();
2108
2131
  }
2109
2132
  take() {
2133
+ this.clearTimer();
2110
2134
  let e = this.pending;
2111
2135
  return this.pending = [], e;
2112
2136
  }
2113
- }, er = class {
2114
- config;
2137
+ stop() {
2138
+ this.clearTimer();
2139
+ }
2140
+ arm() {
2141
+ if (this.timer !== null) return;
2142
+ let e = setTimeout(() => {
2143
+ this.timer = null, this.onFlush(this);
2144
+ }, this.options.flushIntervalMs);
2145
+ this.timer = e, T(e);
2146
+ }
2147
+ clearTimer() {
2148
+ this.timer !== null && (clearTimeout(this.timer), this.timer = null);
2149
+ }
2150
+ }, ur = class {
2115
2151
  transport;
2116
2152
  storage;
2117
2153
  retry;
2118
2154
  diagnostics;
2119
- records$ = new ft();
2120
2155
  streams;
2121
- subscription = null;
2122
2156
  unconfirmed = /* @__PURE__ */ new Map();
2157
+ queue = [];
2158
+ ceiling = new or();
2159
+ inFlight = 0;
2160
+ pumpScheduled = !1;
2123
2161
  stopped = !1;
2124
- constructor(e, t, n, r, i) {
2125
- this.config = e, this.transport = t, this.storage = n, this.retry = r, this.diagnostics = i, this.streams = {
2126
- logs: new $n(e, "logs", i),
2127
- metrics: new $n(e, "metrics", i)
2128
- }, this.subscribe();
2162
+ constructor(e, t, n, r, i = cr) {
2163
+ this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
2164
+ let a = (e) => {
2165
+ this.claim(e);
2166
+ };
2167
+ this.streams = {
2168
+ logs: new lr(i.logs, a),
2169
+ metrics: new lr(i.metrics, a)
2170
+ };
2129
2171
  }
2130
2172
  push(e) {
2131
- this.stopped || (e.observedTimeUnixNano = Gt(), this.records$.next(e));
2173
+ this.stopped || (e.observedTimeUnixNano = Jt(), this.route(e));
2132
2174
  }
2133
2175
  drainPending() {
2134
- let e = [
2135
- ...[...this.unconfirmed.values()].flatMap((e) => e.records),
2176
+ return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
2177
+ }
2178
+ drainForExit() {
2179
+ let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
2180
+ return this.unconfirmed.clear(), this.toBatch([
2181
+ ...e,
2136
2182
  ...this.streams.metrics.take(),
2137
2183
  ...this.streams.logs.take()
2138
- ];
2139
- return this.unconfirmed.clear(), e.length === 0 ? null : {
2140
- id: M(),
2184
+ ]);
2185
+ }
2186
+ destroy() {
2187
+ this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
2188
+ }
2189
+ toBatch(e) {
2190
+ return e.length === 0 ? null : {
2191
+ id: P(),
2141
2192
  records: e,
2142
2193
  createdAt: Date.now(),
2143
2194
  attempts: 0
2144
2195
  };
2145
2196
  }
2146
- refresh() {
2147
- this.subscription?.unsubscribe(), this.subscribe();
2148
- }
2149
- destroy() {
2150
- this.stopped = !0, this.subscription?.unsubscribe(), this.subscription = null, this.records$.complete();
2151
- }
2152
- subscribe() {
2153
- if (this.stopped) return;
2154
- let [e, t] = xt(this.records$, Qn);
2155
- this.subscription = vt(this.batches(e, this.streams.metrics), this.batches(t, this.streams.logs)).pipe(ht((e) => (this.diagnostics.report("pipeline.crashed", "the pipeline errored and was restarted", void 0, e), this.subscribe(), dt)), bt(pt), yt((e) => gt(this.dispatch(e)).pipe(ht((t) => (this.diagnostics.report("pipeline.crashed", "dispatch rejected, which it is written never to do", { batchId: e.id }, t), dt))), this.config.maxConcurrentRequests)).subscribe();
2156
- }
2157
- batches(e, t) {
2158
- return e.pipe(S((e) => Zn(e, this.config) ? !0 : (this.diagnostics.count("record.dropped_by_sampling"), !1)), St((e) => {
2197
+ route(e) {
2198
+ try {
2199
+ let t = sr(e) ? this.streams.metrics : this.streams.logs;
2200
+ if (!this.ceiling.allow(e)) {
2201
+ this.diagnostics.count("record.dropped_by_ceiling");
2202
+ return;
2203
+ }
2159
2204
  t.add(e);
2160
- }), mt(t.options.flushIntervalMs, null, t.options.batchSize), _t(() => this.claim(t)), S((e) => e !== null));
2205
+ } catch (e) {
2206
+ this.diagnostics.report("pipeline.crashed", "a record was dropped on its way into a stream", void 0, e);
2207
+ }
2161
2208
  }
2162
2209
  claim(e) {
2163
- let t = e.take();
2164
- if (t.length === 0) return null;
2165
- let n = {
2166
- id: M(),
2210
+ let t = e.take(), n = {
2211
+ id: P(),
2167
2212
  records: t,
2168
2213
  createdAt: Date.now(),
2169
2214
  attempts: 0
2170
2215
  };
2171
- return this.unconfirmed.set(n.id, n), n;
2216
+ this.unconfirmed.set(n.id, n), this.enqueue(n);
2217
+ }
2218
+ enqueue(e) {
2219
+ this.queue.push(e), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
2220
+ this.pumpScheduled = !1, this.pump();
2221
+ }));
2222
+ }
2223
+ pump() {
2224
+ for (; this.inFlight < 2;) {
2225
+ let e = this.queue.shift();
2226
+ if (!e) return;
2227
+ this.inFlight++, this.run(e);
2228
+ }
2229
+ }
2230
+ async run(e) {
2231
+ try {
2232
+ await this.dispatch(e);
2233
+ } catch (t) {
2234
+ this.diagnostics.report("pipeline.crashed", "dispatch rejected, which it is written never to do", { batchId: e.id }, t);
2235
+ } finally {
2236
+ this.inFlight--, this.pump();
2237
+ }
2172
2238
  }
2173
2239
  async dispatch(e) {
2174
2240
  try {
@@ -2207,7 +2273,7 @@ var $n = class {
2207
2273
  function J(e) {
2208
2274
  return e;
2209
2275
  }
2210
- var tr = class {
2276
+ var dr = class {
2211
2277
  deps;
2212
2278
  resourceCache = null;
2213
2279
  constructor(e) {
@@ -2218,31 +2284,39 @@ var tr = class {
2218
2284
  }
2219
2285
  isEnabled(e) {
2220
2286
  let { config: t } = this.deps;
2221
- return t.enabled ? m[e] >= m[t.minLevel] : !1;
2287
+ return t.enabled ? S[e] >= S[t.minLevel] : !1;
2222
2288
  }
2223
2289
  build(e) {
2224
- let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a } = this.deps;
2290
+ let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o } = this.deps;
2225
2291
  if (!this.isEnabled(e.level)) return n.count("record.dropped_by_level"), null;
2226
- let o = t.limits, c = r.resolve(), l = i.current(), u = a.next(), d = wn(), f, p = 0;
2292
+ let s = r.resolve(), c = i.current();
2293
+ if (!ir({
2294
+ level: e.level,
2295
+ type: e.type,
2296
+ namespace: e.namespace,
2297
+ journeyId: c?.id ?? "",
2298
+ traceId: s.traceId
2299
+ }, t)) return n.count("record.dropped_by_sampling"), null;
2300
+ let l = a.next(), u = Bt(), d = t.capture.fullUrls ? u : A(u), f, p = 0;
2227
2301
  try {
2228
- let t = L(this.deps.context.getAll(), o), n = L(e.scoped ?? {}, o), r = L(e.payload ?? {}, o);
2302
+ let t = z(this.deps.context.getAll(), o), n = z(e.scoped ?? {}, o), r = z(e.payload ?? {}, o);
2229
2303
  p = t.bytes + n.bytes + r.bytes, f = {
2230
2304
  ...J(t.value),
2231
2305
  ...J(n.value),
2232
2306
  ...J(r.value)
2233
2307
  };
2234
2308
  } catch (e) {
2235
- n.report("record.sanitize_failed", "attributes could not be sanitized", void 0, e), f = { [Te]: !0 };
2309
+ n.report("record.sanitize_failed", "attributes could not be sanitized", void 0, e), f = { [Ne]: !0 };
2236
2310
  }
2237
- f[y] = e.type, f[Ce] = u, f[b] = e.namespace, f[Ze] = d, l && (f[ye] = l.id, f[He] = l.name, l.parentId !== void 0 && (f[Je] = l.parentId));
2238
- let m = I(e.body, o.maxBodyChars);
2311
+ f[b] = e.type, f[je] = l, f[x] = e.namespace, f[ft] = d, c && (f[y] = c.id, f[et] = c.name, c.parentId !== void 0 && (f[ct] = c.parentId));
2312
+ let m = R(e.body, o.maxBodyChars);
2239
2313
  m !== e.body && n.count("record.truncated");
2240
2314
  let h = {
2241
- timeUnixNano: Gt(),
2242
- traceId: c.traceId,
2243
- spanId: c.spanId,
2244
- traceFlags: c.traceFlags,
2245
- severityNumber: s[e.level],
2315
+ timeUnixNano: Jt(),
2316
+ traceId: s.traceId,
2317
+ spanId: s.spanId,
2318
+ traceFlags: s.traceFlags,
2319
+ severityNumber: ve[e.level],
2246
2320
  severityText: e.level,
2247
2321
  body: m,
2248
2322
  attributes: f,
@@ -2252,8 +2326,8 @@ var tr = class {
2252
2326
  let e = n.guard("record.sanitize_failed", "redact hook threw", () => g(h));
2253
2327
  if (e === null) return n.count("record.dropped_by_redact"), null;
2254
2328
  if (e !== void 0 && e !== h) {
2255
- if (A(e)) {
2256
- let t = L(e.attributes, o);
2329
+ if (Yt(e)) {
2330
+ let t = z(e.attributes, o);
2257
2331
  h = {
2258
2332
  ...e,
2259
2333
  attributes: J(t.value)
@@ -2267,42 +2341,42 @@ var tr = class {
2267
2341
  body: h.body
2268
2342
  });
2269
2343
  let t = {
2270
- [y]: e.type,
2271
- [Ce]: u,
2272
- [b]: e.namespace,
2273
- [Ze]: d,
2274
- [Ne]: !0,
2275
- [Ke]: p
2344
+ [b]: e.type,
2345
+ [je]: l,
2346
+ [x]: e.namespace,
2347
+ [ft]: d,
2348
+ [He]: !0,
2349
+ [ot]: p
2276
2350
  };
2277
- l && (t[ye] = l.id, t[He] = l.name), h.attributes = t;
2351
+ c && (t[y] = c.id, t[et] = c.name), h.attributes = t;
2278
2352
  }
2279
2353
  return h;
2280
2354
  }
2281
2355
  resource() {
2282
2356
  if (this.resourceCache) return this.resourceCache;
2283
- let { config: e, identity: t, platform: n } = this.deps;
2357
+ let { config: e, identity: n, platform: i } = this.deps;
2284
2358
  return this.resourceCache = {
2285
- [Be]: e.serviceName,
2286
- [Me]: e.serviceVersion,
2287
- [Qe]: e.environment,
2288
- [it]: p,
2289
- [Se]: ee,
2290
- [et]: u,
2291
- [Ee]: n.platform,
2292
- [Ae]: t.sessionId,
2293
- [ve]: t.tabId,
2294
- [Re]: t.contextId,
2295
- [we]: n.userAgent,
2296
- ...n.openfinUuid === void 0 ? {} : { [Ge]: n.openfinUuid },
2297
- ...n.openfinName === void 0 ? {} : { [Oe]: n.openfinName }
2359
+ [c]: e.serviceName,
2360
+ [ue]: e.serviceVersion,
2361
+ [o]: e.environment,
2362
+ [oe]: Fe,
2363
+ [ce]: dt,
2364
+ [Ke]: t,
2365
+ [ht]: i.platform,
2366
+ [Je]: n.sessionId,
2367
+ [r]: n.tabId,
2368
+ [he]: n.contextId,
2369
+ [_t]: i.userAgent,
2370
+ ...i.openfinUuid === void 0 ? {} : { [u]: i.openfinUuid },
2371
+ ...i.openfinName === void 0 ? {} : { [_e]: i.openfinName }
2298
2372
  }, this.resourceCache;
2299
2373
  }
2300
- }, Y = Symbol.for(rt), X = class e {
2374
+ }, Y = Symbol.for(ie), X = class e {
2301
2375
  diagnostics;
2302
2376
  config;
2303
2377
  platform;
2304
2378
  identity;
2305
- context = new Vn();
2379
+ context = new qn();
2306
2380
  breadcrumbs;
2307
2381
  tracing;
2308
2382
  sequence = new Tn();
@@ -2323,10 +2397,11 @@ var tr = class {
2323
2397
  destroyed = !1;
2324
2398
  lastGapAt = 0;
2325
2399
  constructor(e) {
2326
- this.diagnostics = new Hn(e.onDiagnostic), this.platform = xn(this.diagnostics), this.config = zn(e, this.diagnostics), this.identity = qt(this.diagnostics), this.breadcrumbs = new jn(this.config.capture.maxBreadcrumbs), this.tracing = new An(this.diagnostics), this.console = new bn(this.config.console.enabled, this.config.console.level), this.journey = new Jn(this.config.journey, this.diagnostics, this.identity.contextId, (e) => {
2400
+ this.diagnostics = new Jn(e.onDiagnostic), this.platform = Lt(this.diagnostics), this.config = Gn(e, this.diagnostics), this.identity = Zt(this.diagnostics), this.breadcrumbs = new In(50), this.tracing = new Fn(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new wn(this.config.console), this.journey = new tr(Yn, this.diagnostics, this.identity.contextId, (e) => {
2327
2401
  this.bus.broadcastJourney(e);
2328
- }), this.builder = new tr({
2402
+ }), this.builder = new dr({
2329
2403
  config: this.config,
2404
+ limits: vt,
2330
2405
  diagnostics: this.diagnostics,
2331
2406
  context: this.context,
2332
2407
  journey: this.journey,
@@ -2334,7 +2409,7 @@ var tr = class {
2334
2409
  sequence: this.sequence,
2335
2410
  identity: this.identity,
2336
2411
  platform: this.platform
2337
- }), this.bus = new Lt(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
2412
+ }), this.bus = new It(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
2338
2413
  onRecords: (e) => {
2339
2414
  this.ingestForwarded(e);
2340
2415
  },
@@ -2362,7 +2437,7 @@ var tr = class {
2362
2437
  return globalThis[Y] = r, r.init(), r;
2363
2438
  }
2364
2439
  reconfigure(e) {
2365
- Bn(this.config, zn(e, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console.enabled, this.config.console.level), this.breadcrumbs.resize(this.config.capture.maxBreadcrumbs), this.pipeline?.refresh(), this.ready && this.reinstallCaptures(), this.diagnostics.report("config.reconfigured", "configure() was called again, the existing runtime was updated");
2440
+ Kn(this.config, Gn(e, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.ready && this.reinstallCaptures(), this.diagnostics.report("config.reconfigured", "configure() was called again, the existing runtime was updated");
2366
2441
  }
2367
2442
  async init() {
2368
2443
  try {
@@ -2375,11 +2450,11 @@ var tr = class {
2375
2450
  }
2376
2451
  }
2377
2452
  async becomeSender() {
2378
- this.storage = await dn(this.config.storage.strategy, this.config.storage.dbName, this.config.storage, this.diagnostics, this.reportGap), this.transport = new _n(this.config, this.diagnostics), this.retry = new vn(this.storage, this.transport, this.diagnostics, this.config), this.pipeline = new er(this.config, this.transport, this.storage, this.retry, this.diagnostics), this.exitFlush = new mn({
2453
+ this.storage = await hn(this.config.storage, xe, m, this.diagnostics, this.reportGap), this.transport = new xn(this.config, this.diagnostics), this.retry = new Sn(this.storage, this.transport, this.diagnostics, this.config), this.pipeline = new ur(this.transport, this.storage, this.retry, this.diagnostics), this.exitFlush = new vn({
2379
2454
  config: this.config,
2380
2455
  diagnostics: this.diagnostics,
2381
- drainPending: () => this.pipeline?.drainPending() ?? null
2382
- }), await rn(this.storage, this.diagnostics), this.retry.start(), this.exitFlush.install();
2456
+ drainForExit: () => this.pipeline?.drainForExit() ?? null
2457
+ }), await cn(this.storage, this.diagnostics), this.retry.start(), this.exitFlush.install();
2383
2458
  }
2384
2459
  installCaptures() {
2385
2460
  let e = {
@@ -2387,9 +2462,9 @@ var tr = class {
2387
2462
  diagnostics: this.diagnostics,
2388
2463
  breadcrumbs: this.breadcrumbs,
2389
2464
  tracing: this.tracing,
2390
- logger: new w(this, nt)
2465
+ logger: new w(this, a)
2391
2466
  }, t = this.config.capture;
2392
- (t.errors || t.rejections || t.resourceErrors) && this.captures.push(new Rt(e)), (t.fetch || t.xhr) && this.captures.push(new Ht(e)), (t.interactions || t.navigation) && this.captures.push(new Bt(e)), t.webVitals && this.captures.push(new Wt(e));
2467
+ (t.errors || t.rejections || t.resourceErrors) && this.captures.push(new Vt(e)), (t.fetch || t.xhr) && this.captures.push(new Gt(e)), (t.interactions || t.navigation) && this.captures.push(new Ut(e)), t.webVitals && this.captures.push(new qt(e));
2393
2468
  for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `installing ${e.name}`, () => {
2394
2469
  e.install();
2395
2470
  });
@@ -2414,8 +2489,8 @@ var tr = class {
2414
2489
  }
2415
2490
  emit(e) {
2416
2491
  if (!(!e || this.destroyed)) {
2417
- if (Yt(this.identity.sessionId, this.diagnostics), !this.ready) {
2418
- this.bootBuffer.length >= this.config.bus.maxBootBufferRecords && (this.bootBuffer.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), this.bootBuffer.push(e);
2492
+ if ($t(this.identity.sessionId, this.diagnostics), !this.ready) {
2493
+ this.bootBuffer.length >= 500 && (this.bootBuffer.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), this.bootBuffer.push(e);
2419
2494
  return;
2420
2495
  }
2421
2496
  this.route(e);
@@ -2441,10 +2516,14 @@ var tr = class {
2441
2516
  return;
2442
2517
  }
2443
2518
  for (let t of e) {
2444
- if (!A(t)) {
2519
+ if (!Yt(t)) {
2445
2520
  this.diagnostics.count("record.dropped_malformed");
2446
2521
  continue;
2447
2522
  }
2523
+ if (!ar(t, this.config)) {
2524
+ this.diagnostics.count("record.dropped_by_sampling");
2525
+ continue;
2526
+ }
2448
2527
  this.pipeline?.push(t);
2449
2528
  }
2450
2529
  }
@@ -2456,19 +2535,19 @@ var tr = class {
2456
2535
  }
2457
2536
  reportGap = (e) => {
2458
2537
  let t = Date.now();
2459
- t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new w(this, ie).warn("stored records were dropped before delivery", {
2538
+ t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new w(this, re).warn("stored records were dropped before delivery", {
2460
2539
  "gap.batches": e.batches,
2461
2540
  "gap.records": e.records,
2462
2541
  "gap.reason": e.reason
2463
2542
  }));
2464
2543
  };
2465
2544
  regenerateTabId() {
2466
- let e = M();
2545
+ let e = P();
2467
2546
  this.diagnostics.report("bus.role_resolved", "another context claimed this tab id, most likely a duplicated tab. Regenerating.", {
2468
2547
  was: this.identity.tabId,
2469
2548
  now: e
2470
2549
  }), this.identity.tabId = e, this.diagnostics.guard("storage.unavailable", "persisting the new tab id", () => {
2471
- sessionStorage.setItem(oe, e);
2550
+ sessionStorage.setItem(fe, e);
2472
2551
  }), this.builder.invalidateResource();
2473
2552
  }
2474
2553
  async queueDepth() {
@@ -2499,93 +2578,94 @@ var tr = class {
2499
2578
  function Q() {
2500
2579
  return X.current() || X.configure({});
2501
2580
  }
2502
- function nr(e) {
2581
+ function fr(e) {
2503
2582
  X.configure(e), Z.clear();
2504
2583
  }
2505
- function rr(e, t) {
2506
- let n = t ? `${e}::${JSON.stringify(t)}` : e, r = Z.get(n);
2507
- return r || (r = new w(Q(), e, t), Z.set(n, r)), r;
2584
+ function pr(e, t) {
2585
+ if (t) return new w(Q(), e, t);
2586
+ let n = Z.get(e);
2587
+ return n || (n = new w(Q(), e), Z.set(e, n)), n;
2508
2588
  }
2509
2589
  function $() {
2510
- return rr("app");
2590
+ return pr("app");
2511
2591
  }
2512
- function ir(e, t) {
2592
+ function mr(e, t) {
2513
2593
  $().trace(e, t);
2514
2594
  }
2515
- function ar(e, t) {
2595
+ function hr(e, t) {
2516
2596
  $().debug(e, t);
2517
2597
  }
2518
- function or(e, t) {
2598
+ function gr(e, t) {
2519
2599
  $().info(e, t);
2520
2600
  }
2521
- function sr(e, t) {
2601
+ function _r(e, t) {
2522
2602
  $().warn(e, t);
2523
2603
  }
2524
- function cr(e, t, n) {
2604
+ function vr(e, t, n) {
2525
2605
  $().error(e, t, n);
2526
2606
  }
2527
- function lr(e, t) {
2607
+ function yr(e, t) {
2528
2608
  $().logAction(e, t);
2529
2609
  }
2530
- function ur(e, t) {
2610
+ function br(e, t) {
2531
2611
  $().logEvent(e, t);
2532
2612
  }
2533
- function dr(e, t, n, r, i) {
2613
+ function xr(e, t, n, r, i) {
2534
2614
  $().logMetric(e, t, n, r, i);
2535
2615
  }
2536
- function fr(e, t, n) {
2616
+ function Sr(e, t, n) {
2537
2617
  return $().timeSync(e, t, n);
2538
2618
  }
2539
- function pr(e, t, n) {
2619
+ function Cr(e, t, n) {
2540
2620
  return $().timeAsync(e, t, n);
2541
2621
  }
2542
- function mr(e, t) {
2622
+ function wr(e, t) {
2543
2623
  Q().context.set(e, t);
2544
2624
  }
2545
- function hr(e) {
2625
+ function Tr(e) {
2546
2626
  Q().context.setMany(e);
2547
2627
  }
2548
- function gr(e) {
2628
+ function Er(e) {
2549
2629
  Q().context.remove(e);
2550
2630
  }
2551
- function _r(e, t) {
2631
+ function Dr(e, t) {
2552
2632
  return Q().journey.start(e, t);
2553
2633
  }
2554
- function vr() {
2634
+ function Or() {
2555
2635
  Q().journey.end();
2556
2636
  }
2557
- function yr() {
2637
+ function kr() {
2558
2638
  return Q().journey.current();
2559
2639
  }
2560
- function br() {
2640
+ function Ar() {
2561
2641
  return Q().journey.getToken();
2562
2642
  }
2563
- function xr(e) {
2643
+ function jr(e) {
2564
2644
  return Q().journey.adopt(e, "manual", !0);
2565
2645
  }
2566
- function Sr(e) {
2646
+ function Mr(e) {
2567
2647
  Q().registerWorker(e);
2568
2648
  }
2569
- function Cr() {
2649
+ function Nr() {
2570
2650
  Q().tracing.rotate("explicit");
2571
2651
  }
2572
- function wr() {
2652
+ function Pr() {
2573
2653
  return Q().tracing.headers();
2574
2654
  }
2575
- function Tr() {
2655
+ function Fr() {
2576
2656
  return Q().flush();
2577
2657
  }
2578
- function Er() {
2658
+ function Ir() {
2579
2659
  return Q().queueDepth();
2580
2660
  }
2581
- function Dr() {
2661
+ function Lr() {
2582
2662
  return Q().diagnostics.snapshot();
2583
2663
  }
2584
- async function Or() {
2664
+ async function Rr() {
2585
2665
  let e = X.current();
2586
2666
  Z.clear(), await e?.destroy();
2587
2667
  }
2588
2668
  //#endregion
2589
- export { w as OneLogger, xr as adoptJourney, nr as configure, yr as currentJourney, ar as debug, vr as endJourney, cr as error, Tr as flush, Dr as getDiagnosticCounters, br as getJourneyToken, rr as getLogger, Er as getQueueDepth, wr as getTraceHeaders, or as info, lr as logAction, ur as logEvent, dr as logMetric, Sr as registerWorker, gr as removeContext, mr as setContext, hr as setContextMap, Or as shutdown, _r as startJourney, Cr as startTrace, pr as timeAsync, fr as timeSync, ir as trace, sr as warn };
2669
+ export { w as OneLogger, jr as adoptJourney, fr as configure, kr as currentJourney, hr as debug, Or as endJourney, vr as error, Fr as flush, Lr as getDiagnosticCounters, Ar as getJourneyToken, pr as getLogger, Ir as getQueueDepth, Pr as getTraceHeaders, gr as info, yr as logAction, br as logEvent, xr as logMetric, Mr as registerWorker, Er as removeContext, wr as setContext, Tr as setContextMap, Rr as shutdown, Dr as startJourney, Nr as startTrace, Cr as timeAsync, Sr as timeSync, mr as trace, _r as warn };
2590
2670
 
2591
2671
  //# sourceMappingURL=index.js.map