@utk09/ui-observability 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $t as e, A as t, At as n, Bt as r, C as i, Ct as a, D as o, Dt as s, E as c, Et as l, F as u, Ft as d, G as f, Gt as p, H as m, Ht as h, I as g, It as _, J as ee, K as te, Kt as ne, Lt as re, M as ie, Mt as ae, N as oe, Nt as se, O as ce, Ot as le, Pt as ue, Qt as de, R as v, Rt as fe, S as pe, St as me, T as y, Tt as he, U as ge, V as _e, Wt as ve, Xt as ye, Y as be, Yt as xe, Zt as Se, _ as Ce, _t as we, a as b, an as Te, at as Ee, b as De, bt as Oe, c as ke, cn as Ae, ct as je, d as Me, dt as Ne, en as Pe, et as Fe, ft as Ie, g as Le, gt as Re, h as ze, ht as Be, i as Ve, in as He, it as x, j as Ue, jt as We, k as Ge, kt as Ke, l as S, lt as qe, m as Je, mt as Ye, n as C, nn as Xe, nt as w, o as Ze, on as Qe, ot as $e, p as et, pt as tt, q as nt, qt as rt, r as it, rn as at, rt as ot, s as st, sn as ct, st as lt, t as ut, tn as dt, tt as ft, u as pt, ut as mt, v as ht, vt as gt, wt as _t, x as vt, xt as yt, z as bt } from "./constants-CrU3IUyy.js";
1
+ import { $t as e, A as t, At as n, Bt as r, C as i, Ct as a, D as o, Dt as s, E as c, Et as l, F as u, Ft as d, G as f, Gt as p, H as m, Ht as h, I as g, It as _, J as ee, Jt as te, K as ne, Kt as v, Lt as re, M as ie, Mt as ae, N as oe, Nt as se, O as ce, Ot as le, Pt as ue, Qt as de, R as y, Rt as fe, S as pe, St as me, T as b, Tt as he, U as ge, V as _e, Wt as ve, Xt as ye, Y as be, Zt as xe, _ as Se, _t as Ce, a as we, an as Te, at as Ee, b as De, bt as Oe, c as ke, cn as Ae, ct as je, d as Me, dt as Ne, en as Pe, et as Fe, ft as Ie, g as Le, gt as Re, h as ze, ht as Be, i as Ve, in as He, it as x, j as Ue, jt as We, k as Ge, kt as Ke, l as S, ln as qe, lt as Je, m as Ye, mt as Xe, n as C, nn as Ze, nt as w, o as Qe, on as $e, ot as et, p as tt, pt as nt, q as rt, qt as it, r as at, rn as ot, rt as st, s as ct, sn as lt, st as ut, t as dt, tn as ft, tt as pt, u as mt, ut as ht, v as T, vt as gt, wt as _t, x as vt, xt as yt, z as bt } from "./constants-DVbpJ1tv.js";
2
2
  //#region src/utils/timer.ts
3
3
  function xt(e) {
4
4
  return Math.round((performance.now() - e) * u) / u;
@@ -46,7 +46,7 @@ function Dt(e) {
46
46
  let t = Object.getPrototypeOf(e);
47
47
  return t === null || Object.getPrototypeOf(t) === null;
48
48
  }
49
- var T = class e {
49
+ var E = class e {
50
50
  runtime;
51
51
  namespace;
52
52
  options;
@@ -133,18 +133,18 @@ var T = class e {
133
133
  };
134
134
  //#endregion
135
135
  //#region src/utils/unref.ts
136
- function E(e) {
136
+ function D(e) {
137
137
  typeof e != "number" && e.unref?.();
138
138
  }
139
139
  //#endregion
140
140
  //#region src/models/bus.ts
141
- function D(e) {
141
+ function O(e) {
142
142
  return {
143
143
  p: pe,
144
144
  m: e
145
145
  };
146
146
  }
147
- function O(e) {
147
+ function k(e) {
148
148
  if (typeof e != "object" || !e) return null;
149
149
  let t = e;
150
150
  if (t.p !== "ui-observability/1" || typeof t.m != "object" || t.m === null) return null;
@@ -179,7 +179,7 @@ function kt(e, t) {
179
179
  function At(e, t) {
180
180
  if (typeof window > "u" || window.parent === window) return null;
181
181
  let n = (t) => {
182
- let n = O(t.data);
182
+ let n = k(t.data);
183
183
  n && t.source === window.parent && e(n, {
184
184
  link: "parent",
185
185
  origin: t.origin
@@ -189,7 +189,7 @@ function At(e, t) {
189
189
  kind: "parent",
190
190
  post(e) {
191
191
  t.guard("bus.send_failed", "postMessage to parent", () => {
192
- window.parent.postMessage(D(e), "*");
192
+ window.parent.postMessage(O(e), "*");
193
193
  });
194
194
  },
195
195
  close() {
@@ -200,7 +200,7 @@ function At(e, t) {
200
200
  function jt(e, t, n) {
201
201
  if (typeof window > "u") return null;
202
202
  let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Map(), a = (t) => {
203
- let a = O(t.data);
203
+ let a = k(t.data);
204
204
  if (a) {
205
205
  if (!r.has(t.origin)) {
206
206
  n.report("bus.untrusted_origin", `ignored a bus message from ${t.origin}. Add it to bus.trustedOrigins if it is yours.`, {
@@ -225,7 +225,7 @@ function jt(e, t, n) {
225
225
  continue;
226
226
  }
227
227
  n.guard("bus.send_failed", "postMessage to child", () => {
228
- a.postMessage(D(e), r);
228
+ a.postMessage(O(e), r);
229
229
  });
230
230
  }
231
231
  },
@@ -239,7 +239,7 @@ function Mt(e, t, n) {
239
239
  if (r === void 0) return null;
240
240
  let i = n.guard("bus.send_failed", "opening BroadcastChannel", () => new r(e));
241
241
  return i ? (i.onmessage = (e) => {
242
- let n = O(e.data);
242
+ let n = k(e.data);
243
243
  n && t(n, {
244
244
  link: "broadcast",
245
245
  origin: "same-origin"
@@ -248,7 +248,7 @@ function Mt(e, t, n) {
248
248
  kind: "broadcast",
249
249
  post(e) {
250
250
  n.guard("bus.send_failed", "BroadcastChannel.postMessage", () => {
251
- i.postMessage(D(e));
251
+ i.postMessage(O(e));
252
252
  });
253
253
  },
254
254
  close() {
@@ -264,7 +264,7 @@ function Nt(e, t, n, r) {
264
264
  if (!t) return r.report("openfin.unavailable", "no OpenFin application uuid, so the InterApplicationBus link stays closed"), null;
265
265
  let a = `${e}.${t}`;
266
266
  return r.guardAsync("bus.send_failed", "InterApplicationBus.subscribe", () => i.subscribe({ uuid: t }, a, (e) => {
267
- let t = O(e);
267
+ let t = k(e);
268
268
  t && n(t, {
269
269
  link: "openfin",
270
270
  origin: "openfin"
@@ -272,7 +272,7 @@ function Nt(e, t, n, r) {
272
272
  })), {
273
273
  kind: "openfin",
274
274
  post(e) {
275
- r.guardAsync("bus.send_failed", "InterApplicationBus.publish", () => i.publish(a, D(e)));
275
+ r.guardAsync("bus.send_failed", "InterApplicationBus.publish", () => i.publish(a, O(e)));
276
276
  },
277
277
  close() {}
278
278
  };
@@ -280,7 +280,7 @@ function Nt(e, t, n, r) {
280
280
  function Pt(e, t) {
281
281
  let n = globalThis, r = n.postMessage;
282
282
  return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
283
- let n = O(t.data);
283
+ let n = k(t.data);
284
284
  n && e(n, {
285
285
  link: "owner",
286
286
  origin: "same-origin"
@@ -289,7 +289,7 @@ function Pt(e, t) {
289
289
  kind: "owner",
290
290
  post(e) {
291
291
  t.guard("bus.send_failed", "worker postMessage", () => {
292
- r(D(e));
292
+ r(O(e));
293
293
  });
294
294
  },
295
295
  close() {}
@@ -297,7 +297,7 @@ function Pt(e, t) {
297
297
  }
298
298
  function Ft(e, t, n) {
299
299
  let r = (e) => {
300
- let n = O(e.data);
300
+ let n = k(e.data);
301
301
  n && t(n, {
302
302
  link: "worker",
303
303
  origin: "same-origin"
@@ -307,7 +307,7 @@ function Ft(e, t, n) {
307
307
  kind: "worker",
308
308
  post(t) {
309
309
  n.guard("bus.send_failed", "postMessage to a worker", () => {
310
- e.postMessage(D(t));
310
+ e.postMessage(O(t));
311
311
  });
312
312
  },
313
313
  close() {
@@ -441,7 +441,7 @@ var It = {
441
441
  this.awaitingWelcome?.link === t.link && this.awaitingWelcome.settle(!0);
442
442
  break;
443
443
  case "records":
444
- this.role === "sender" ? this.handlers.onRecords(e.records) : this.upstream && t.link !== this.upstream.kind && this.upstream.post(e);
444
+ this.role === "sender" ? this.handlers.onRecords(e.records) : this.upstream && this.canRelay(t.link) && this.upstream.post(e);
445
445
  break;
446
446
  case "journey":
447
447
  this.handlers.onJourney(e.journey);
@@ -458,6 +458,9 @@ var It = {
458
458
  case "tab": t.link === "broadcast" && e.tabId === this.tabId && this.contextId > e.from && this.handlers.onTabConflict();
459
459
  }
460
460
  };
461
+ canRelay(e) {
462
+ return e === "direct" || e !== this.upstream?.kind;
463
+ }
461
464
  canOwn(e) {
462
465
  return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : Lt.includes(e) : !1;
463
466
  }
@@ -503,7 +506,7 @@ var It = {
503
506
  let i = setTimeout(() => {
504
507
  r(!1);
505
508
  }, this.handshakeOptions.timeoutMs);
506
- E(i), e.post({
509
+ D(i), e.post({
507
510
  t: "hello",
508
511
  from: this.contextId,
509
512
  tabId: this.tabId
@@ -520,28 +523,28 @@ var It = {
520
523
  from: this.contextId
521
524
  });
522
525
  }
523
- }, k = null;
524
- function A(e, t) {
526
+ }, A = null;
527
+ function j(e, t) {
525
528
  let n = e[t];
526
529
  return n !== void 0 && e instanceof n;
527
530
  }
528
531
  function zt(e) {
529
- if (k) return k;
532
+ if (A) return A;
530
533
  let t = globalThis, n = t.navigator?.userAgent ?? "", r = "browser", i, a, o = !1, s = t.fin?.me;
531
- return A(t, "ServiceWorkerGlobalScope") ? (r = "service_worker", o = !0) : A(t, "SharedWorkerGlobalScope") ? (r = "shared_worker", o = !0) : A(t, "WorkerGlobalScope") ? (r = "web_worker", o = !0) : s === void 0 ? t.Capacitor !== void 0 || t.Ionic !== void 0 ? r = "ionic" : t.cordova !== void 0 || Bt(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Re.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
534
+ return j(t, "ServiceWorkerGlobalScope") ? (r = "service_worker", o = !0) : j(t, "SharedWorkerGlobalScope") ? (r = "shared_worker", o = !0) : j(t, "WorkerGlobalScope") ? (r = "web_worker", o = !0) : s === void 0 ? t.Capacitor !== void 0 || t.Ionic !== void 0 ? r = "ionic" : t.cordova !== void 0 || Bt(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Re.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
532
535
  let e = s.identity;
533
536
  i = e?.uuid, a = e?.name;
534
- })), k = {
537
+ })), A = {
535
538
  platform: r,
536
539
  openfinUuid: i,
537
540
  openfinName: a,
538
541
  userAgent: n,
539
542
  isWorker: o,
540
543
  isTopLevelDocument: Vt()
541
- }, k;
544
+ }, A;
542
545
  }
543
546
  function Bt(e) {
544
- return ut.test(e) ? !0 : (Fe.test(e) || je.test(e) && Ne.test(e)) && e.includes("AppleWebKit") && !e.includes("Safari/");
547
+ return dt.test(e) ? !0 : (Fe.test(e) || je.test(e) && Ne.test(e)) && e.includes("AppleWebKit") && !e.includes("Safari/");
545
548
  }
546
549
  function Vt() {
547
550
  if (typeof window > "u") return !1;
@@ -558,7 +561,7 @@ function Ht() {
558
561
  return "";
559
562
  }
560
563
  }
561
- function j(e) {
564
+ function M(e) {
562
565
  let t = e.search(/[?#]/);
563
566
  return t === -1 ? e : e.slice(0, t);
564
567
  }
@@ -584,7 +587,7 @@ var Ut = class {
584
587
  let t = e.target, n = t?.src ?? t?.href ?? "";
585
588
  if (t !== null && t !== globalThis && n !== "") {
586
589
  if (!this.ctx.config.capture.resourceErrors) return;
587
- let e = this.ctx.config.capture.fullUrls ? n : j(n);
590
+ let e = this.ctx.config.capture.fullUrls ? n : M(n);
588
591
  this.ctx.breadcrumbs.push({
589
592
  t: Date.now(),
590
593
  category: "http",
@@ -645,7 +648,7 @@ function Wt(e) {
645
648
  let i = e.getAttribute("class")?.trim() ?? "";
646
649
  return i === "" ? t : `${t}.${i.split(/\s+/).slice(0, 2).join(".")}`;
647
650
  }
648
- function M() {
651
+ function N() {
649
652
  return history;
650
653
  }
651
654
  var Gt = class {
@@ -662,10 +665,10 @@ var Gt = class {
662
665
  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)));
663
666
  }
664
667
  uninstall() {
665
- this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (M().pushState = this.originalPushState), this.originalReplaceState && (M().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
668
+ this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (N().pushState = this.originalPushState), this.originalReplaceState && (N().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
666
669
  }
667
670
  onClick = (e) => {
668
- let t = e.target, n = Wt(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.innerText.trim().slice(0, 50) : "";
671
+ let t = e.target, n = Wt(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.textContent.trim().slice(0, 50) : "";
669
672
  this.ctx.tracing.rotate("interaction"), this.ctx.breadcrumbs.push({
670
673
  t: Date.now(),
671
674
  category: "click",
@@ -677,7 +680,7 @@ var Gt = class {
677
680
  let e = this.lastUrl, t = location.href;
678
681
  if (e === t) return;
679
682
  this.lastUrl = t;
680
- let n = this.ctx.config.capture.fullUrls, r = n ? e : j(e), i = n ? t : j(t);
683
+ let n = this.ctx.config.capture.fullUrls, r = n ? e : M(e), i = n ? t : M(t);
681
684
  this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
682
685
  t: Date.now(),
683
686
  category: "navigation",
@@ -686,7 +689,7 @@ var Gt = class {
686
689
  };
687
690
  installHistory() {
688
691
  if (typeof history > "u" || this.originalPushState) return;
689
- let e = M(), t = e.pushState, n = e.replaceState;
692
+ let e = N(), t = e.pushState, n = e.replaceState;
690
693
  this.originalPushState = t, this.originalReplaceState = n;
691
694
  let r = this.onNavigate;
692
695
  e.pushState = function(...e) {
@@ -703,7 +706,7 @@ function Kt(e, t) {
703
706
  }
704
707
  //#endregion
705
708
  //#region src/capture/network.ts
706
- function N() {
709
+ function P() {
707
710
  return XMLHttpRequest.prototype;
708
711
  }
709
712
  var qt = class {
@@ -719,7 +722,7 @@ var qt = class {
719
722
  this.ctx.config.capture.fetch && this.installFetch(), this.ctx.config.capture.xhr && this.installXhr();
720
723
  }
721
724
  uninstall() {
722
- this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (N().open = this.originalOpen, null), this.originalSend &&= (N().send = this.originalSend, null);
725
+ this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (P().open = this.originalOpen, null), this.originalSend &&= (P().send = this.originalSend, null);
723
726
  }
724
727
  ignored(e) {
725
728
  return Kt(e, this.ctx.config.capture.ignoreUrls);
@@ -765,7 +768,7 @@ var qt = class {
765
768
  if (typeof XMLHttpRequest > "u" || this.originalOpen) return;
766
769
  let e = (e) => this.ignored(e), t = (e, t, n, r) => {
767
770
  this.record(e, t, n, r, void 0);
768
- }, n = N(), r = n.open, i = n.send;
771
+ }, n = P(), r = n.open, i = n.send;
769
772
  this.originalOpen = r, this.originalSend = i, n.open = function(e, t, ...n) {
770
773
  this.__uiobs = {
771
774
  method: e.toUpperCase(),
@@ -784,7 +787,7 @@ var qt = class {
784
787
  };
785
788
  }
786
789
  record(e, t, n, r, i) {
787
- let a = this.ctx.config.capture.fullUrls ? t : j(t);
790
+ let a = this.ctx.config.capture.fullUrls ? t : M(t);
788
791
  this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${a}`, () => {
789
792
  let t = Math.round(r);
790
793
  this.ctx.breadcrumbs.push({
@@ -827,7 +830,7 @@ var Yt = class {
827
830
  this.ctx = e;
828
831
  }
829
832
  install() {
830
- this.installed || (this.installed = !0, this.reportNavigationTiming(), this.loadWebVitals());
833
+ this.installed || (this.installed = !0, this.reportNavigationTiming(), !this.ctx.once.webVitals && (this.ctx.once.webVitals = !0, this.loadWebVitals()));
831
834
  }
832
835
  uninstall() {
833
836
  this.installed = !1;
@@ -847,7 +850,7 @@ var Yt = class {
847
850
  t.onLCP(n("lcp", "ms")), t.onCLS(n("cls", "1")), t.onINP(n("inp", "ms")), t.onFCP(n("fcp", "ms")), t.onTTFB(n("ttfb", "ms"));
848
851
  }
849
852
  reportNavigationTiming() {
850
- this.ctx.diagnostics.guard("capture.install_failed", "reading navigation timing", () => {
853
+ this.ctx.once.navigationTiming || (this.ctx.once.navigationTiming = !0, this.ctx.diagnostics.guard("capture.install_failed", "reading navigation timing", () => {
851
854
  let e = performance.getEntriesByType("navigation")[0];
852
855
  if (!e) return;
853
856
  let t = {
@@ -860,7 +863,7 @@ var Yt = class {
860
863
  "navigation.load_ms": e.loadEventEnd
861
864
  };
862
865
  for (let [n, r] of Object.entries(t)) Number.isFinite(r) && r >= 0 && this.ctx.logger.logMetric(n, Math.round(r), "ms", "gauge", { "navigation.type": e.type });
863
- });
866
+ }));
864
867
  }
865
868
  };
866
869
  //#endregion
@@ -875,44 +878,44 @@ function Zt(e) {
875
878
  }
876
879
  //#endregion
877
880
  //#region src/utils/identity.ts
878
- function P(e) {
881
+ function F(e) {
879
882
  let t = new Uint8Array(e);
880
883
  if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") crypto.getRandomValues(t);
881
884
  else for (let n = 0; n < e; n++) t[n] = Math.floor(Math.random() * 256);
882
885
  return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
883
886
  }
884
- function F() {
887
+ function I() {
885
888
  try {
886
889
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
887
890
  } catch {}
888
- return P(16);
891
+ return F(16);
889
892
  }
890
893
  function Qt(e, t, n) {
891
894
  return n.guard("storage.unavailable", `reading ${e}Storage`, () => (e === "local" ? localStorage : sessionStorage).getItem(t)) ?? null;
892
895
  }
893
- function I(e, t, n, r) {
896
+ function L(e, t, n, r) {
894
897
  r.guard("storage.unavailable", `writing ${e}Storage`, () => {
895
898
  (e === "local" ? localStorage : sessionStorage).setItem(t, n);
896
899
  });
897
900
  }
898
- function $t(t) {
899
- let n = F(), r = Date.now(), i = F(), a = Qt("local", h, t);
900
- if (a) try {
901
- let e = JSON.parse(a);
902
- e.id && r - (e.lastSeenAt ?? 0) < 18e5 && (i = e.id);
901
+ function $t(e) {
902
+ let t = I(), n = Date.now(), r = I(), i = Qt("local", h, e);
903
+ if (i) try {
904
+ let e = JSON.parse(i);
905
+ e.id && n - (e.lastSeenAt ?? 0) < 18e5 && (r = e.id);
903
906
  } catch {
904
- t.report("storage.degraded", "session record was not JSON, starting a new session");
907
+ e.report("storage.degraded", "session record was not JSON, starting a new session");
905
908
  }
906
- let o = JSON.stringify({
907
- id: i,
908
- lastSeenAt: r
909
+ let a = JSON.stringify({
910
+ id: r,
911
+ lastSeenAt: n
909
912
  });
910
- I("local", h, o, t);
911
- let s = Qt("session", "ui-observability.tab", t) ?? "";
912
- return s || (s = F(), I("session", e, s, t)), {
913
- sessionId: i,
914
- tabId: s,
915
- contextId: n
913
+ L("local", h, a, e);
914
+ let o = Qt("session", "ui-observability.tab", e) ?? "";
915
+ return o || (o = I(), L("session", Pe, o, e)), {
916
+ sessionId: r,
917
+ tabId: o,
918
+ contextId: t
916
919
  };
917
920
  }
918
921
  var en = class {
@@ -929,7 +932,7 @@ var en = class {
929
932
  id: e,
930
933
  lastSeenAt: t
931
934
  });
932
- I("local", h, n, this.diagnostics);
935
+ L("local", h, n, this.diagnostics);
933
936
  }
934
937
  };
935
938
  //#endregion
@@ -942,7 +945,7 @@ function tn(e) {
942
945
  function nn(e) {
943
946
  if (e.records.length < 2) return null;
944
947
  let t = Math.floor(e.records.length / 2), n = (t) => ({
945
- id: F(),
948
+ id: I(),
946
949
  records: t,
947
950
  createdAt: e.createdAt,
948
951
  attempts: e.attempts
@@ -950,6 +953,19 @@ function nn(e) {
950
953
  return [n(e.records.slice(0, t)), n(e.records.slice(t))];
951
954
  }
952
955
  //#endregion
956
+ //#region src/utils/deadline.ts
957
+ function R(e, t) {
958
+ let n, r = new Promise((e, r) => {
959
+ let i = setTimeout(() => {
960
+ r(/* @__PURE__ */ Error(`timed out after ${String(t)}ms`));
961
+ }, t);
962
+ n = i, D(i);
963
+ });
964
+ return Promise.race([e, r]).finally(() => {
965
+ clearTimeout(n);
966
+ });
967
+ }
968
+ //#endregion
953
969
  //#region src/utils/lock.ts
954
970
  function rn(e, t, n, { skipIfBusy: r = !0 } = {}) {
955
971
  let i = globalThis.navigator?.locks;
@@ -957,7 +973,7 @@ function rn(e, t, n, { skipIfBusy: r = !0 } = {}) {
957
973
  }
958
974
  //#endregion
959
975
  //#region src/storage/keys.ts
960
- function L(e, t) {
976
+ function z(e, t) {
961
977
  let n = [];
962
978
  return t.guard("storage.unavailable", "enumerating localStorage", () => {
963
979
  for (let t = 0; t < localStorage.length; t++) {
@@ -970,7 +986,7 @@ function L(e, t) {
970
986
  //#region src/storage/emergency-queue.ts
971
987
  function an(e) {
972
988
  let t = String(e.createdAt).padStart(14, "0");
973
- return `${v}${t}.${e.id}`;
989
+ return `${y}${t}.${e.id}`;
974
990
  }
975
991
  function on(e, t) {
976
992
  let n = t.guard("storage.degraded", "an emergency entry was not JSON and was dropped", () => JSON.parse(e));
@@ -978,7 +994,7 @@ function on(e, t) {
978
994
  }
979
995
  async function sn(e, t) {
980
996
  let n = 0;
981
- for (let r of L(v, t)) {
997
+ for (let r of z(y, t)) {
982
998
  let i = t.guard("storage.unavailable", "reading the emergency queue", () => {
983
999
  let e = localStorage.getItem(r);
984
1000
  return localStorage.removeItem(r), e;
@@ -986,7 +1002,7 @@ async function sn(e, t) {
986
1002
  if (!i) continue;
987
1003
  let a = on(i, t);
988
1004
  if (a !== null) try {
989
- await e.save(a), n++;
1005
+ await R(e.save(a), v), n++;
990
1006
  } catch (e) {
991
1007
  t.report("storage.degraded", "an emergency batch could not be recovered", { key: r }, e);
992
1008
  }
@@ -996,7 +1012,7 @@ async function sn(e, t) {
996
1012
  function cn(e, t) {
997
1013
  let n = `writing the emergency queue, ${String(e.records.length)} records`;
998
1014
  t.guard("storage.quota_exceeded", n, () => {
999
- let n = L(v, t);
1015
+ let n = z(y, t);
1000
1016
  for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
1001
1017
  localStorage.setItem(an(e), JSON.stringify(e));
1002
1018
  });
@@ -1008,13 +1024,17 @@ async function ln(e, t) {
1008
1024
  //#region src/storage/local-storage.ts
1009
1025
  function un(e) {
1010
1026
  let t = String(e.createdAt).padStart(14, "0");
1011
- return `${ht}${t}.${e.id}`;
1027
+ return `${T}${t}.${e.id}`;
1028
+ }
1029
+ function dn(e) {
1030
+ let t = T.length, n = Number(e.slice(t, t + 14));
1031
+ return Number.isFinite(n) ? n : null;
1012
1032
  }
1013
- var dn = class {
1033
+ var fn = class {
1014
1034
  limits;
1015
1035
  diagnostics;
1016
1036
  onGap;
1017
- name = xe;
1037
+ name = ye;
1018
1038
  constructor(e, t, n) {
1019
1039
  this.limits = e, this.diagnostics = t, this.onGap = n;
1020
1040
  }
@@ -1058,28 +1078,22 @@ var dn = class {
1058
1078
  batches: 0,
1059
1079
  records: 0,
1060
1080
  reason: "expired"
1061
- }, n = (e, n) => {
1062
- this.removeKey(e), t.batches++, t.records += n;
1081
+ }, n = (e) => {
1082
+ let n = this.read(e);
1083
+ this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
1063
1084
  }, r = [];
1064
1085
  for (let t of this.keys()) {
1065
- let i = this.read(t);
1066
- if (i === null) {
1067
- n(t, 0);
1068
- continue;
1069
- }
1070
- if (i.createdAt < e) {
1071
- n(t, i.records.length);
1086
+ let i = dn(t);
1087
+ if (i === null || i < e) {
1088
+ n(t);
1072
1089
  continue;
1073
1090
  }
1074
- r.push({
1075
- key: t,
1076
- records: i.records.length
1077
- });
1091
+ r.push(t);
1078
1092
  }
1079
1093
  let i = r.length - this.limits.maxBatches;
1080
1094
  if (i > 0) {
1081
1095
  t.reason = "over_capacity";
1082
- for (let e of r.slice(0, i)) n(e.key, e.records);
1096
+ for (let e of r.slice(0, i)) n(e);
1083
1097
  }
1084
1098
  return this.reportGap(t), Promise.resolve(t);
1085
1099
  }
@@ -1128,18 +1142,18 @@ var dn = class {
1128
1142
  });
1129
1143
  }
1130
1144
  keys() {
1131
- return L(ht, this.diagnostics);
1145
+ return z(T, this.diagnostics);
1132
1146
  }
1133
1147
  };
1134
1148
  //#endregion
1135
1149
  //#region src/storage/memory-storage.ts
1136
- function fn(e) {
1150
+ function pn(e) {
1137
1151
  return e.reduce((e, t) => e + t.records.length, 0);
1138
1152
  }
1139
- var R = class {
1153
+ var B = class {
1140
1154
  limits;
1141
1155
  onGap;
1142
- name = ye;
1156
+ name = xe;
1143
1157
  batches = [];
1144
1158
  constructor(e, t) {
1145
1159
  this.limits = e, this.onGap = t;
@@ -1163,12 +1177,12 @@ var R = class {
1163
1177
  records: 0,
1164
1178
  reason: "expired"
1165
1179
  }, n = this.batches.filter((t) => t.createdAt < e);
1166
- this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += fn(n);
1180
+ this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += pn(n);
1167
1181
  let r = this.batches.length - this.limits.maxBatches;
1168
1182
  if (r > 0) {
1169
1183
  t.reason = "over_capacity";
1170
1184
  let e = this.batches.slice(0, r);
1171
- this.batches = this.batches.slice(r), t.batches += e.length, t.records += fn(e);
1185
+ this.batches = this.batches.slice(r), t.batches += e.length, t.records += pn(e);
1172
1186
  }
1173
1187
  return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
1174
1188
  }
@@ -1181,8 +1195,8 @@ var R = class {
1181
1195
  close() {
1182
1196
  return this.batches = [], Promise.resolve();
1183
1197
  }
1184
- }, pn = {
1185
- name: Se,
1198
+ }, mn = {
1199
+ name: de,
1186
1200
  save: () => Promise.resolve(),
1187
1201
  take: () => Promise.resolve([]),
1188
1202
  remove: () => Promise.resolve(),
@@ -1196,116 +1210,116 @@ var R = class {
1196
1210
  clear: () => Promise.resolve(),
1197
1211
  close: () => Promise.resolve()
1198
1212
  };
1199
- function mn(e) {
1213
+ function hn(e) {
1200
1214
  return e.guard("storage.unavailable", "reading indexedDB", () => globalThis.indexedDB != null) === !0;
1201
1215
  }
1202
- function hn(e) {
1203
- return e.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(de, "1"), localStorage.removeItem(de), !0)) === !0;
1216
+ function gn(t) {
1217
+ return t.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(e, "1"), localStorage.removeItem(e), !0)) === !0;
1204
1218
  }
1205
- async function gn(e, t, n, r, i) {
1206
- if (e === "none") return pn;
1207
- if (e === "memory") return new R(n, i);
1219
+ async function _n(e, t, n, r, i) {
1220
+ if (e === "none") return mn;
1221
+ if (e === "memory") return new B(n, i);
1208
1222
  if (e === "indexeddb" || e === "auto") {
1209
- if (mn(r)) {
1223
+ if (hn(r)) {
1210
1224
  let e = await r.guardAsync("storage.unavailable", "opening IndexedDB", async () => {
1211
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-CSaDuHGk.js");
1212
- return new e(t, n, r, i);
1225
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-B6uqejZb.js"), a = new e(t, n, r, i);
1226
+ return await a.open(), a;
1213
1227
  });
1214
1228
  if (e) return e;
1215
1229
  }
1216
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new R(n, i);
1230
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new B(n, i);
1217
1231
  }
1218
- return hn(r) ? new dn(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new R(n, i));
1232
+ return gn(r) ? new fn(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new B(n, i));
1219
1233
  }
1220
1234
  //#endregion
1221
1235
  //#region src/utils/sanitize.ts
1222
- function z(e, t) {
1236
+ function V(e, t) {
1223
1237
  if (e.length <= t) return e;
1224
- let n = _n(e.charCodeAt(t - 1)) ? t - 1 : t;
1238
+ let n = vn(e.charCodeAt(t - 1)) ? t - 1 : t;
1225
1239
  return `${e.slice(0, n)}… [truncated ${String(e.length - n)} chars]`;
1226
1240
  }
1227
- function _n(e) {
1241
+ function vn(e) {
1228
1242
  return e >= 55296 && e <= 56319;
1229
1243
  }
1230
- function vn(e) {
1244
+ function yn(e) {
1231
1245
  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(".")}` : ""}]`;
1232
1246
  }
1233
- function B(e, t) {
1247
+ function H(e, t) {
1234
1248
  let n = {
1235
1249
  bytes: 0,
1236
1250
  nodes: 0
1237
1251
  };
1238
1252
  return {
1239
- value: H(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1253
+ value: W(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1240
1254
  bytes: n.bytes
1241
1255
  };
1242
1256
  }
1243
- function V(e, t) {
1244
- return t.bytes += U(e) + 2, e;
1257
+ function U(e, t) {
1258
+ return t.bytes += G(e) + 2, e;
1245
1259
  }
1246
- function H(e, t, n, r, i) {
1247
- if (i.nodes++, i.nodes > t.maxNodes) return V("[MaxNodes]", i);
1260
+ function W(e, t, n, r, i) {
1261
+ if (i.nodes++, i.nodes > t.maxNodes) return U("[MaxNodes]", i);
1248
1262
  if (e == null) return i.bytes += 4, e;
1249
- if (typeof e == "string") return V(z(e, t.maxAttributeChars), i);
1263
+ if (typeof e == "string") return U(V(e, t.maxAttributeChars), i);
1250
1264
  if (typeof e == "number") return i.bytes += 8, Number.isFinite(e) ? e : String(e);
1251
1265
  if (typeof e == "boolean") return i.bytes += 5, e;
1252
- if (typeof e == "bigint") return V(`${e.toString()}n`, i);
1253
- if (typeof e == "symbol") return V(e.toString(), i);
1254
- if (typeof e == "function") return V(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
1255
- if (r >= t.maxDepth) return V("[MaxDepth]", i);
1256
- if (n.has(e)) return V("[Circular]", i);
1266
+ if (typeof e == "bigint") return U(`${e.toString()}n`, i);
1267
+ if (typeof e == "symbol") return U(e.toString(), i);
1268
+ if (typeof e == "function") return U(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
1269
+ if (r >= t.maxDepth) return U("[MaxDepth]", i);
1270
+ if (n.has(e)) return U("[Circular]", i);
1257
1271
  n.add(e), i.bytes += 2;
1258
1272
  try {
1259
1273
  if (e instanceof Error) return {
1260
- name: V(e.name, i),
1261
- message: V(z(e.message, t.maxAttributeChars), i),
1262
- stack: e.stack ? V(z(e.stack, t.maxStackChars), i) : void 0,
1263
- cause: e.cause ? H(e.cause, t, n, r + 1, i) : void 0
1274
+ name: U(e.name, i),
1275
+ message: U(V(e.message, t.maxAttributeChars), i),
1276
+ stack: e.stack ? U(V(e.stack, t.maxStackChars), i) : void 0,
1277
+ cause: e.cause ? W(e.cause, t, n, r + 1, i) : void 0
1264
1278
  };
1265
- if (e instanceof Date) return V(e.toISOString(), i);
1266
- if (e instanceof RegExp) return V(e.toString(), i);
1279
+ if (e instanceof Date) return U(e.toISOString(), i);
1280
+ if (e instanceof RegExp) return U(e.toString(), i);
1267
1281
  if (e instanceof Map) {
1268
1282
  let a = e, o = {}, s = 0;
1269
1283
  for (let [e, c] of a) {
1270
1284
  if (s >= t.maxArrayLength) {
1271
- o["…"] = V(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1285
+ o["…"] = U(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1272
1286
  break;
1273
1287
  }
1274
1288
  s++;
1275
1289
  let l = String(e);
1276
- i.bytes += U(l) + 4, o[l] = H(c, t, n, r + 1, i);
1290
+ i.bytes += G(l) + 4, o[l] = W(c, t, n, r + 1, i);
1277
1291
  }
1278
1292
  return o;
1279
1293
  }
1280
- if (e instanceof Set) return H([...e].slice(0, t.maxArrayLength), t, n, r, i);
1294
+ if (e instanceof Set) return W([...e].slice(0, t.maxArrayLength), t, n, r, i);
1281
1295
  if (ArrayBuffer.isView(e)) {
1282
1296
  let t = e.length ?? 0;
1283
- return V(`[${e.constructor.name}(${String(t)})]`, i);
1297
+ return U(`[${e.constructor.name}(${String(t)})]`, i);
1284
1298
  }
1285
- if (e instanceof Promise) return V("[Promise]", i);
1286
- if (typeof Node < "u" && e instanceof Node) return V(vn(e), i);
1299
+ if (e instanceof Promise) return U("[Promise]", i);
1300
+ if (typeof Node < "u" && e instanceof Node) return U(yn(e), i);
1287
1301
  if (Array.isArray(e)) {
1288
- let a = e, o = a.slice(0, t.maxArrayLength).map((e) => H(e, t, n, r + 1, i));
1289
- return a.length > t.maxArrayLength && o.push(V(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
1302
+ let a = e, o = a.slice(0, t.maxArrayLength).map((e) => W(e, t, n, r + 1, i));
1303
+ return a.length > t.maxArrayLength && o.push(U(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
1290
1304
  }
1291
1305
  let a = e.toJSON;
1292
- if (typeof a == "function") return H(a.call(e), t, n, r + 1, i);
1306
+ if (typeof a == "function") return W(a.call(e), t, n, r + 1, i);
1293
1307
  let o = e, s = Object.keys(o), c = {}, l = 0;
1294
1308
  for (let e of s) {
1295
1309
  if (l >= t.maxAttributeCount) {
1296
- c["…"] = V(`[${String(s.length - l)} more keys]`, i);
1310
+ c["…"] = U(`[${String(s.length - l)} more keys]`, i);
1297
1311
  break;
1298
1312
  }
1299
- l++, i.bytes += U(e) + 4, c[e] = H(o[e], t, n, r + 1, i);
1313
+ l++, i.bytes += G(e) + 4, c[e] = W(o[e], t, n, r + 1, i);
1300
1314
  }
1301
1315
  return c;
1302
1316
  } catch (e) {
1303
- return V(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1317
+ return U(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1304
1318
  } finally {
1305
1319
  n.delete(e);
1306
1320
  }
1307
1321
  }
1308
- function U(e) {
1322
+ function G(e) {
1309
1323
  let t = 0;
1310
1324
  for (let n = 0; n < e.length; n++) {
1311
1325
  let r = e.charCodeAt(n);
@@ -1315,7 +1329,7 @@ function U(e) {
1315
1329
  }
1316
1330
  //#endregion
1317
1331
  //#region src/transport/exit-flush.ts
1318
- var yn = class {
1332
+ var bn = class {
1319
1333
  deps;
1320
1334
  installed = !1;
1321
1335
  onVisibility = () => {
@@ -1352,27 +1366,36 @@ var yn = class {
1352
1366
  flush(e) {
1353
1367
  let { diagnostics: t } = this.deps, n = this.endpointUrl();
1354
1368
  if (n === null) return;
1355
- let r = this.deps.drainForExit();
1369
+ let r = this.drain(e);
1356
1370
  if (!r || r.records.length === 0) return;
1357
1371
  let i = t.guard("transport.serialize_failed", `the ${e} exit flush could not serialize its batch`, () => this.deps.config.serializer.serialize(r.records));
1358
1372
  if (!i) return;
1359
- if (U(i.body) > 6e4) {
1373
+ if (G(i.body) > 6e4) {
1360
1374
  cn(r, t);
1361
1375
  return;
1362
1376
  }
1363
- n.searchParams.set(we, r.id), n.searchParams.set(gt, e);
1364
- let a = n.toString();
1365
- this.beacon(a, i.body) || this.keepaliveFetch(a, i.body, e);
1377
+ n.searchParams.set(Ce, r.id), n.searchParams.set(gt, e);
1378
+ let a = n.toString(), o = this.beacon(a, i.body);
1379
+ if (o !== "sent") {
1380
+ if (o === "refused") {
1381
+ cn(r, t);
1382
+ return;
1383
+ }
1384
+ this.keepaliveFetch(a, i.body, e);
1385
+ }
1386
+ }
1387
+ drain(e) {
1388
+ return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
1366
1389
  }
1367
1390
  endpointUrl() {
1368
1391
  let { endpoint: e } = this.deps.config;
1369
1392
  return e ? this.deps.diagnostics.guard("config.invalid", `the exit flush cannot use endpoint ${e}`, () => new URL(e)) ?? null : null;
1370
1393
  }
1371
- beacon(e, n) {
1394
+ beacon(e, t) {
1372
1395
  return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
1373
- let r = globalThis.navigator;
1374
- return r?.sendBeacon ? r.sendBeacon(e, new Blob([n], { type: t })) : !1;
1375
- }) === !0;
1396
+ let n = globalThis.navigator;
1397
+ return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
1398
+ }) ?? "unavailable";
1376
1399
  }
1377
1400
  keepaliveFetch(e, n, r) {
1378
1401
  let { config: i, diagnostics: a } = this.deps;
@@ -1391,7 +1414,7 @@ var yn = class {
1391
1414
  };
1392
1415
  //#endregion
1393
1416
  //#region src/transport/compression.ts
1394
- async function bn(e) {
1417
+ async function xn(e) {
1395
1418
  let t = globalThis.CompressionStream;
1396
1419
  if (t === void 0) return null;
1397
1420
  let n = new Blob([e]).stream().pipeThrough(new t(bt)), r = await new Response(n).arrayBuffer();
@@ -1399,7 +1422,7 @@ async function bn(e) {
1399
1422
  }
1400
1423
  //#endregion
1401
1424
  //#region src/transport/errors.ts
1402
- var W = class extends Error {
1425
+ var K = class extends Error {
1403
1426
  kind;
1404
1427
  status;
1405
1428
  retryAfterMs;
@@ -1408,16 +1431,16 @@ var W = class extends Error {
1408
1431
  super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
1409
1432
  }
1410
1433
  };
1411
- function xn(e) {
1434
+ function Sn(e) {
1412
1435
  if (!e) return;
1413
1436
  let t = Number(e);
1414
- if (Number.isFinite(t)) return Math.max(0, t * mt);
1437
+ if (Number.isFinite(t)) return Math.max(0, t * ht);
1415
1438
  let n = Date.parse(e);
1416
1439
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
1417
1440
  }
1418
1441
  //#endregion
1419
1442
  //#region src/transport/http-transport.ts
1420
- var Sn = class {
1443
+ var Cn = class {
1421
1444
  config;
1422
1445
  diagnostics;
1423
1446
  throttledUntil = 0;
@@ -1439,9 +1462,9 @@ var Sn = class {
1439
1462
  return;
1440
1463
  }
1441
1464
  let r = new Headers(await this.resolveHeaders());
1442
- r.set(ee, n.contentType), r.set(te, e.id), r.set(f, String(e.attempts));
1465
+ r.set(ee, n.contentType), r.set(ne, e.id), r.set(f, String(e.attempts));
1443
1466
  let i = await this.encodeBody(n.body);
1444
- typeof i != "string" && r.set(nt, bt);
1467
+ typeof i != "string" && r.set(rt, bt);
1445
1468
  let a = await this.dispatch(r, i);
1446
1469
  if (a.ok) {
1447
1470
  this.throttledUntil = 0;
@@ -1451,13 +1474,13 @@ var Sn = class {
1451
1474
  }
1452
1475
  async encodeBody(e) {
1453
1476
  let { config: t } = this;
1454
- return t.compression !== "gzip" || U(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => bn(e)) ?? e;
1477
+ return t.compression !== "gzip" || G(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => xn(e)) ?? e;
1455
1478
  }
1456
1479
  async dispatch(e, t) {
1457
1480
  let { config: n } = this, r = new AbortController(), i = setTimeout(() => {
1458
1481
  r.abort();
1459
1482
  }, yt);
1460
- E(i);
1483
+ D(i);
1461
1484
  try {
1462
1485
  return await fetch(n.endpoint, {
1463
1486
  method: "POST",
@@ -1468,28 +1491,28 @@ var Sn = class {
1468
1491
  cache: "no-store"
1469
1492
  });
1470
1493
  } catch {
1471
- if (r.signal.aborted) throw new W("timeout", `request exceeded ${String(yt)}ms`);
1494
+ if (r.signal.aborted) throw new K("timeout", `request exceeded ${String(yt)}ms`);
1472
1495
  let e = globalThis.navigator?.onLine;
1473
- throw new W(e === !1 ? "offline" : "transient", "network error");
1496
+ throw new K(e === !1 ? "offline" : "transient", "network error");
1474
1497
  } finally {
1475
1498
  clearTimeout(i);
1476
1499
  }
1477
1500
  }
1478
1501
  async classify(e, t) {
1479
- let n = e.status, r = xn(e.headers.get(be));
1502
+ let n = e.status, r = Sn(e.headers.get(be));
1480
1503
  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.`, {
1481
1504
  status: n,
1482
1505
  endpoint: this.config.endpoint
1483
- }), new W("permanent", `rejected with ${String(n)}`, n);
1484
- if (n === 413) return new W("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
1506
+ }), new K("permanent", `rejected with ${String(n)}`, n);
1507
+ if (n === 413) return new K("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
1485
1508
  if (n === 429 || n === 503) {
1486
1509
  let e = n === 429;
1487
- return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new W("throttled", e ? "throttled" : "service unavailable", n, r);
1510
+ return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new K("throttled", e ? "throttled" : "service unavailable", n, r);
1488
1511
  }
1489
- return n === 408 || n >= 500 ? new W("transient", `server error ${String(n)}`, n) : (this.diagnostics.report("transport.dropped_permanent", `server rejected the batch with ${String(n)}, dropping it`, {
1512
+ return n === 408 || n >= 500 ? new K("transient", `server error ${String(n)}`, n) : (this.diagnostics.report("transport.dropped_permanent", `server rejected the batch with ${String(n)}, dropping it`, {
1490
1513
  batchId: t,
1491
1514
  status: n
1492
- }), new W("permanent", `rejected with ${String(n)}`, n));
1515
+ }), new K("permanent", `rejected with ${String(n)}`, n));
1493
1516
  }
1494
1517
  async readMaxBytes(e) {
1495
1518
  return this.diagnostics.guardAsync("transport.http_error", "reading the 413 body", async () => {
@@ -1501,7 +1524,7 @@ var Sn = class {
1501
1524
  let { headers: e } = this.config;
1502
1525
  return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "headers() threw", () => Promise.resolve(e())) ?? {} : e : {};
1503
1526
  }
1504
- }, Cn = class {
1527
+ }, wn = class {
1505
1528
  storage;
1506
1529
  transport;
1507
1530
  diagnostics;
@@ -1523,6 +1546,11 @@ var Sn = class {
1523
1546
  nudge() {
1524
1547
  this.draining || this.schedule(d);
1525
1548
  }
1549
+ async storeFailed(e, t) {
1550
+ let n = this.toStorable(e, t);
1551
+ for (let e of n) await this.bounded(this.storage.save(e));
1552
+ n.length > 0 && this.nudge();
1553
+ }
1526
1554
  stop() {
1527
1555
  this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
1528
1556
  }
@@ -1532,7 +1560,10 @@ var Sn = class {
1532
1560
  let t = setTimeout(() => {
1533
1561
  this.drain();
1534
1562
  }, e);
1535
- this.timer = t, E(t);
1563
+ this.timer = t, D(t);
1564
+ }
1565
+ bounded(e) {
1566
+ return R(e, v);
1536
1567
  }
1537
1568
  clearTimer() {
1538
1569
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
@@ -1554,7 +1585,7 @@ var Sn = class {
1554
1585
  async drainLocked() {
1555
1586
  try {
1556
1587
  if (globalThis.navigator?.onLine === !1) return this.schedule(_), !0;
1557
- let e = await this.storage.take(this.batchesPerDrain);
1588
+ let e = await this.bounded(this.storage.take(this.batchesPerDrain));
1558
1589
  if (e.length === 0) return this.schedule(_), !0;
1559
1590
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
1560
1591
  return this.schedule(e.length === this.batchesPerDrain ? 0 : _), !0;
@@ -1563,41 +1594,44 @@ var Sn = class {
1563
1594
  }
1564
1595
  }
1565
1596
  async deliver(e) {
1566
- if (e.attempts >= ne.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1597
+ if (e.attempts >= it.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1567
1598
  batchId: e.id,
1568
1599
  records: e.records.length
1569
- }), await this.storage.remove(e.id), !0;
1600
+ }), await this.bounded(this.storage.remove(e.id)), !0;
1570
1601
  try {
1571
- return await this.transport.send(e), await this.storage.remove(e.id), this.attempt = 0, !0;
1602
+ return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
1572
1603
  } catch (t) {
1573
- let n = t instanceof W ? t : void 0;
1574
- 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(_), !1) : (await this.storage.bumpAttempts(e.id, e.attempts + 1), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
1604
+ let n = t instanceof K ? t : void 0;
1605
+ return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(_), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
1575
1606
  }
1576
1607
  }
1577
- async splitStored(e, t) {
1578
- let n = nn(e);
1579
- if (await this.storage.remove(e.id), !n) {
1580
- this.diagnostics.report("transport.dropped_permanent", "a single record exceeds the server limit and was dropped", {
1581
- batchId: e.id,
1582
- bodies: e.records.map((e) => e.body)
1583
- });
1584
- return;
1585
- }
1586
- this.diagnostics.report("transport.batch_split", "the server refused the batch as too large", {
1608
+ async replaceStored(e, t) {
1609
+ let n = this.toStorable(e, t);
1610
+ await this.bounded(this.storage.remove(e.id));
1611
+ for (let e of n) await this.bounded(this.storage.save(e));
1612
+ }
1613
+ toStorable(e, t) {
1614
+ let n = t instanceof K ? t : void 0;
1615
+ if (n?.kind === "permanent") return [];
1616
+ if (n?.kind !== "too_large") return [e];
1617
+ let r = nn(e);
1618
+ return r ? (this.diagnostics.report("transport.batch_split", "the server refused the batch as too large", {
1587
1619
  from: e.records.length,
1588
- to: n[0].records.length,
1589
- serverMaxBytes: t
1590
- });
1591
- for (let e of n) await this.storage.save(e);
1620
+ to: r[0].records.length,
1621
+ serverMaxBytes: n.maxBytes
1622
+ }), r) : (this.diagnostics.report("transport.dropped_permanent", "a single record exceeds the server limit and was dropped", {
1623
+ batchId: e.id,
1624
+ bodies: e.records.map((e) => e.body)
1625
+ }), []);
1592
1626
  }
1593
- }, wn = {
1627
+ }, Tn = {
1594
1628
  TRACE: "debug",
1595
1629
  DEBUG: "debug",
1596
1630
  INFO: "info",
1597
1631
  WARN: "warn",
1598
1632
  ERROR: "error",
1599
1633
  FATAL: "error"
1600
- }, Tn = class {
1634
+ }, En = class {
1601
1635
  minLevel;
1602
1636
  diagnostics;
1603
1637
  constructor(e, t) {
@@ -1608,7 +1642,7 @@ var Sn = class {
1608
1642
  }
1609
1643
  write(e, t, n) {
1610
1644
  if (this.minLevel === null || x[e] < x[this.minLevel] || typeof console > "u") return;
1611
- let r = `%c${Ee}%c ${e}`, i = wn[e];
1645
+ let r = `%c${Ee}%c ${e}`, i = Tn[e];
1612
1646
  this.diagnostics.guard("handler.threw", `mirroring to console.${i}`, () => {
1613
1647
  if (n === void 0) {
1614
1648
  console[i](r, o, "", t);
@@ -1617,7 +1651,7 @@ var Sn = class {
1617
1651
  console[i](r, o, "", t, n);
1618
1652
  });
1619
1653
  }
1620
- }, En = class {
1654
+ }, Dn = class {
1621
1655
  value = 0;
1622
1656
  next() {
1623
1657
  return ++this.value;
@@ -1625,44 +1659,44 @@ var Sn = class {
1625
1659
  reset() {
1626
1660
  this.value = 0;
1627
1661
  }
1628
- }, Dn = /^[0-9a-f]{32}$/, On = /^[0-9a-f]{16}$/, kn = /[1-9a-f]/;
1629
- function An() {
1662
+ }, On = /^[0-9a-f]{32}$/, kn = /^[0-9a-f]{16}$/, An = /[1-9a-f]/;
1663
+ function jn() {
1630
1664
  return import(
1631
1665
  /* @vite-ignore */
1632
1666
  "@opentelemetry/api"
1633
1667
  );
1634
1668
  }
1635
- function jn(e) {
1636
- return Dn.test(e.traceId) && kn.test(e.traceId) && On.test(e.spanId) && kn.test(e.spanId);
1637
- }
1638
- function Mn() {
1639
- return P(16);
1669
+ function Mn(e) {
1670
+ return On.test(e.traceId) && An.test(e.traceId) && kn.test(e.spanId) && An.test(e.spanId);
1640
1671
  }
1641
1672
  function Nn() {
1642
- return P(8);
1673
+ return F(16);
1643
1674
  }
1644
1675
  function Pn() {
1676
+ return F(8);
1677
+ }
1678
+ function Fn() {
1645
1679
  return {
1646
- traceId: Mn(),
1647
- spanId: Nn(),
1680
+ traceId: Nn(),
1681
+ spanId: Pn(),
1648
1682
  traceFlags: 1,
1649
1683
  startedAt: Date.now()
1650
1684
  };
1651
1685
  }
1652
- function Fn(e) {
1686
+ function In(e) {
1653
1687
  return {
1654
1688
  traceId: e.traceId,
1655
1689
  spanId: e.spanId,
1656
1690
  traceFlags: e.traceFlags
1657
1691
  };
1658
1692
  }
1659
- var In = class {
1693
+ var Ln = class {
1660
1694
  diagnostics;
1661
1695
  maxAgeMs;
1662
1696
  load;
1663
- ambient = Pn();
1697
+ ambient = Fn();
1664
1698
  otel;
1665
- constructor(e, t = He, n = An) {
1699
+ constructor(e, t = Te, n = jn) {
1666
1700
  this.diagnostics = e, this.maxAgeMs = t, this.load = n;
1667
1701
  }
1668
1702
  async loadOtel() {
@@ -1674,7 +1708,7 @@ var In = class {
1674
1708
  }
1675
1709
  resolve() {
1676
1710
  let e = this.activeSpanContext();
1677
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), Fn(this.ambient)) : e;
1711
+ return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), In(this.ambient)) : e;
1678
1712
  }
1679
1713
  activeSpanContext() {
1680
1714
  let e = this.otel;
@@ -1682,7 +1716,7 @@ var In = class {
1682
1716
  let t = e.trace.getActiveSpan();
1683
1717
  if (t === void 0) return;
1684
1718
  let n = t.spanContext();
1685
- if (jn(n)) return {
1719
+ if (Mn(n)) return {
1686
1720
  traceId: n.traceId,
1687
1721
  spanId: n.spanId,
1688
1722
  traceFlags: n.traceFlags
@@ -1690,7 +1724,7 @@ var In = class {
1690
1724
  });
1691
1725
  }
1692
1726
  rotate(e) {
1693
- return this.ambient = Pn(), Fn(this.ambient);
1727
+ return this.ambient = Fn(), In(this.ambient);
1694
1728
  }
1695
1729
  headers() {
1696
1730
  let e = {}, t = this.otel;
@@ -1698,11 +1732,11 @@ var In = class {
1698
1732
  t.propagation.inject(t.context.active(), e);
1699
1733
  }), !e.traceparent) {
1700
1734
  let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
1701
- e[at] = `00-${t.traceId}-${t.spanId}-${n}`;
1735
+ e[He] = `00-${t.traceId}-${t.spanId}-${n}`;
1702
1736
  }
1703
1737
  return e;
1704
1738
  }
1705
- }, Ln = class {
1739
+ }, Rn = class {
1706
1740
  buffer;
1707
1741
  pointer = 0;
1708
1742
  filled = !1;
@@ -1722,13 +1756,13 @@ var In = class {
1722
1756
  };
1723
1757
  //#endregion
1724
1758
  //#region src/transport/serializers/ecs.ts
1725
- function Rn(e) {
1726
- return Ie.test(e) ? Number(BigInt(e) / tt) : Date.now();
1727
- }
1728
1759
  function zn(e) {
1760
+ return Ie.test(e) ? Number(BigInt(e) / nt) : Date.now();
1761
+ }
1762
+ function Bn(e) {
1729
1763
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
1730
1764
  }
1731
- function Bn(e, t, n) {
1765
+ function Vn(e, t, n) {
1732
1766
  let r = e[t];
1733
1767
  if (r === void 0) {
1734
1768
  e[t] = n;
@@ -1740,29 +1774,29 @@ function Bn(e, t, n) {
1740
1774
  }
1741
1775
  e[t] = [r, n];
1742
1776
  }
1743
- function G(e, t, n, r) {
1744
- let i = zn(n);
1777
+ function Hn(e, t, n, r) {
1778
+ let i = Bn(n);
1745
1779
  if (i !== null) {
1746
- Bn(e, t, i);
1780
+ Vn(e, t, i);
1747
1781
  return;
1748
1782
  }
1749
1783
  if (!(typeof n != "object" || !n || r.has(n))) {
1750
- if (r.add(n), Array.isArray(n)) for (let i of n) G(e, t, i, r);
1751
- else for (let [i, a] of Object.entries(n)) G(e, `${t}.${i}`, a, r);
1784
+ if (r.add(n), Array.isArray(n)) for (let i of n) Hn(e, t, i, r);
1785
+ else for (let [i, a] of Object.entries(n)) Hn(e, `${t}.${i}`, a, r);
1752
1786
  r.delete(n);
1753
1787
  }
1754
1788
  }
1755
- function Vn(e) {
1789
+ function Un(e) {
1756
1790
  let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
1757
- for (let [r, i] of Object.entries(e)) G(t, r, i, n);
1791
+ for (let [r, i] of Object.entries(e)) Hn(t, r, i, n);
1758
1792
  return t;
1759
1793
  }
1760
- var Hn = {
1794
+ var Wn = {
1761
1795
  name: "ecs",
1762
1796
  serialize(e) {
1763
1797
  return {
1764
1798
  body: `${e.map((e) => {
1765
- let t = Rn(e.timeUnixNano);
1799
+ let t = zn(e.timeUnixNano);
1766
1800
  return JSON.stringify({
1767
1801
  "@timestamp": new Date(t).toISOString(),
1768
1802
  message: e.body,
@@ -1777,8 +1811,8 @@ var Hn = {
1777
1811
  user_agent: { original: e.resource[me] },
1778
1812
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
1779
1813
  labels: {
1780
- ...Vn(e.resource),
1781
- ...Vn(e.attributes)
1814
+ ...Un(e.resource),
1815
+ ...Un(e.attributes)
1782
1816
  }
1783
1817
  });
1784
1818
  }).join("\n")}\n`,
@@ -1788,13 +1822,13 @@ var Hn = {
1788
1822
  };
1789
1823
  //#endregion
1790
1824
  //#region src/transport/serializers/otlp.ts
1791
- function Un(e) {
1792
- 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(Un).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
1825
+ function Gn(e) {
1826
+ 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(Gn).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: Kn(e) } } : null;
1793
1827
  }
1794
- function K(e) {
1828
+ function Kn(e) {
1795
1829
  let t = [];
1796
1830
  for (let [n, r] of Object.entries(e)) {
1797
- let e = Un(r);
1831
+ let e = Gn(r);
1798
1832
  e && t.push({
1799
1833
  key: n,
1800
1834
  value: e
@@ -1802,19 +1836,19 @@ function K(e) {
1802
1836
  }
1803
1837
  return t;
1804
1838
  }
1805
- var Wn = /* @__PURE__ */ new WeakMap();
1806
- function Gn(e) {
1807
- let t = Wn.get(e);
1839
+ var qn = /* @__PURE__ */ new WeakMap();
1840
+ function Jn(e) {
1841
+ let t = qn.get(e);
1808
1842
  if (t !== void 0) return t;
1809
1843
  let n = JSON.stringify(e);
1810
- return Wn.set(e, n), n;
1844
+ return qn.set(e, n), n;
1811
1845
  }
1812
- var q = {
1846
+ var Yn = {
1813
1847
  name: r,
1814
1848
  serialize(e) {
1815
1849
  let t = /* @__PURE__ */ new Map();
1816
1850
  for (let n of e) {
1817
- let e = Gn(n.resource), r = t.get(e);
1851
+ let e = Jn(n.resource), r = t.get(e);
1818
1852
  if (r) {
1819
1853
  r.records.push(n);
1820
1854
  continue;
@@ -1825,11 +1859,11 @@ var q = {
1825
1859
  });
1826
1860
  }
1827
1861
  let n = [...t.values()].map((e) => ({
1828
- resource: { attributes: K(e.resource) },
1862
+ resource: { attributes: Kn(e.resource) },
1829
1863
  scopeLogs: [{
1830
1864
  scope: {
1831
- name: dt,
1832
- version: Xe
1865
+ name: Ze,
1866
+ version: ot
1833
1867
  },
1834
1868
  logRecords: e.records.map((e) => ({
1835
1869
  timeUnixNano: e.timeUnixNano,
@@ -1840,7 +1874,7 @@ var q = {
1840
1874
  traceId: e.traceId,
1841
1875
  spanId: e.spanId,
1842
1876
  flags: e.traceFlags,
1843
- attributes: K(e.attributes)
1877
+ attributes: Kn(e.attributes)
1844
1878
  }))
1845
1879
  }]
1846
1880
  }));
@@ -1852,21 +1886,21 @@ var q = {
1852
1886
  };
1853
1887
  //#endregion
1854
1888
  //#region src/core/config.ts
1855
- function Kn(e) {
1889
+ function Xn(e) {
1856
1890
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
1857
1891
  }
1858
- function qn(e, t, n) {
1859
- return e === void 0 ? t ?? q : e === "otlp" ? q : e === "ecs" ? Hn : Kn(e) ? e : (n.report("config.invalid", `serializer must be "${r}", "ecs" or an implementation`), q);
1892
+ function Zn(e, t, n) {
1893
+ return e === void 0 ? t ?? Yn : e === "otlp" ? Yn : e === "ecs" ? Wn : Xn(e) ? e : (n.report("config.invalid", `serializer must be "${r}", "ecs" or an implementation`), Yn);
1860
1894
  }
1861
- function Jn(e, t) {
1895
+ function Qn(e, t) {
1862
1896
  return e === void 0 ? t : e === !1 ? null : e === !0 ? c : e;
1863
1897
  }
1864
- function Yn(e, t, n) {
1898
+ function $n(e, t, n) {
1865
1899
  let r = n ?? Ue, i = {
1866
1900
  ...r,
1867
1901
  ...e,
1868
- serializer: qn(e.serializer, n?.serializer, t),
1869
- console: Jn(e.console, r.console),
1902
+ serializer: Zn(e.serializer, n?.serializer, t),
1903
+ console: Qn(e.console, r.console),
1870
1904
  sampling: {
1871
1905
  ...r.sampling,
1872
1906
  ...e.sampling,
@@ -1890,30 +1924,30 @@ function Yn(e, t, n) {
1890
1924
  } catch (e) {
1891
1925
  t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}`, void 0, e);
1892
1926
  }
1893
- i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${Ae}'.`), Ae);
1927
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${qe}'.`), qe);
1894
1928
  let a = i.sampling.defaultRate;
1895
1929
  (typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1, got ${String(a)}`), i.sampling.defaultRate = 1);
1896
1930
  let o = Object.entries(i.sampling.rates);
1897
1931
  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);
1898
- return 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]), Xn(e, t), i;
1932
+ return 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]), er(e, t), i;
1899
1933
  }
1900
- function Xn(e, t) {
1901
- let n = /* @__PURE__ */ new Set([...Object.keys(Ue), ...Qe]);
1934
+ function er(e, t) {
1935
+ let n = /* @__PURE__ */ new Set([...Object.keys(Ue), ...lt]);
1902
1936
  for (let r of Object.keys(e)) n.has(r) || t.report("config.invalid", `unknown config key "${r}", ignored. Typo?`);
1903
- for (let n of y) {
1937
+ for (let n of b) {
1904
1938
  let r = e[n];
1905
1939
  if (typeof r != "object" || !r) continue;
1906
- let i = /* @__PURE__ */ new Set([...Object.keys(Ue[n]), ...ct[n]]);
1940
+ let i = /* @__PURE__ */ new Set([...Object.keys(Ue[n]), ...Ae[n]]);
1907
1941
  for (let e of Object.keys(r)) i.has(e) || t.report("config.invalid", `unknown config key "${n}.${e}", ignored. Typo?`);
1908
1942
  }
1909
1943
  }
1910
- function Zn(e, t) {
1911
- for (let n of Object.keys(t)) y.includes(n) || Object.assign(e, { [n]: t[n] });
1912
- for (let n of y) Object.assign(e[n], t[n]);
1944
+ function tr(e, t) {
1945
+ for (let n of Object.keys(t)) b.includes(n) || Object.assign(e, { [n]: t[n] });
1946
+ for (let n of b) Object.assign(e[n], t[n]);
1913
1947
  }
1914
1948
  //#endregion
1915
1949
  //#region src/core/context.ts
1916
- var Qn = class {
1950
+ var nr = class {
1917
1951
  map = /* @__PURE__ */ new Map();
1918
1952
  set(e, t) {
1919
1953
  this.map.set(e, t);
@@ -1933,7 +1967,7 @@ var Qn = class {
1933
1967
  getAll() {
1934
1968
  return Object.fromEntries(this.map);
1935
1969
  }
1936
- }, $n = class {
1970
+ }, rr = class {
1937
1971
  handler;
1938
1972
  throttleMs;
1939
1973
  counters = /* @__PURE__ */ new Map();
@@ -1988,59 +2022,51 @@ var Qn = class {
1988
2022
  reset() {
1989
2023
  this.counters.clear(), this.lastEmitted.clear();
1990
2024
  }
1991
- }, er = {
1992
- maxAgeMs: ft,
2025
+ }, ir = {
2026
+ maxAgeMs: pt,
1993
2027
  endOnOwnerClose: !1,
1994
- urlParam: ot
2028
+ urlParam: st
1995
2029
  };
1996
- function J(e, t) {
2030
+ function q(e, t) {
1997
2031
  let n = Reflect.get(e, t);
1998
2032
  return typeof n == "string" && n !== "" ? n : void 0;
1999
2033
  }
2000
- function tr(e, t) {
2034
+ function ar(e, t) {
2001
2035
  let n = Reflect.get(e, t);
2002
2036
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
2003
2037
  }
2004
- function nr(e) {
2038
+ function or(e) {
2005
2039
  if (typeof e != "object" || !e) return null;
2006
- let t = J(e, "id"), n = J(e, "name"), r = tr(e, "startedAt");
2040
+ let t = q(e, "id"), n = q(e, "name"), r = ar(e, "startedAt");
2007
2041
  return t === void 0 || n === void 0 || r === void 0 ? null : {
2008
2042
  id: t,
2009
2043
  name: n,
2010
2044
  startedAt: r,
2011
- parentId: J(e, "parentId"),
2012
- ownerContextId: J(e, "ownerContextId") ?? ""
2045
+ parentId: q(e, "parentId"),
2046
+ ownerContextId: q(e, "ownerContextId") ?? ""
2013
2047
  };
2014
2048
  }
2015
- function rr(e) {
2049
+ function sr(e) {
2016
2050
  if (typeof e != "object" || !e) return null;
2017
- let t = J(e, "i"), n = J(e, "n");
2051
+ let t = q(e, "i"), n = q(e, "n");
2018
2052
  return t === void 0 || n === void 0 ? null : {
2019
2053
  id: t,
2020
2054
  name: n,
2021
- startedAt: tr(e, "s") ?? Date.now(),
2055
+ startedAt: ar(e, "s") ?? Date.now(),
2022
2056
  parentId: void 0,
2023
2057
  ownerContextId: ""
2024
2058
  };
2025
2059
  }
2026
- function ir(e) {
2060
+ function cr(e) {
2027
2061
  let t = JSON.stringify({
2028
2062
  i: e.id,
2029
2063
  n: e.name.slice(0, 64),
2030
2064
  s: e.startedAt
2031
2065
  }), n = new TextEncoder().encode(t), r = "";
2032
2066
  for (let e of n) r += String.fromCharCode(e);
2033
- return btoa(r).replace(Le, "-").replace(Ce, "_").replace(ze, "");
2067
+ return btoa(r).replace(Le, "-").replace(Se, "_").replace(ze, "");
2034
2068
  }
2035
- function ar(e, t) {
2036
- let n = new Promise((e, n) => {
2037
- E(setTimeout(() => {
2038
- n(/* @__PURE__ */ Error(`timed out after ${String(t)}ms`));
2039
- }, t));
2040
- });
2041
- return Promise.race([e, n]);
2042
- }
2043
- var or = class {
2069
+ var lr = class {
2044
2070
  options;
2045
2071
  diagnostics;
2046
2072
  contextId;
@@ -2063,7 +2089,7 @@ var or = class {
2063
2089
  }
2064
2090
  start(e, t = {}) {
2065
2091
  let n = {
2066
- id: t.id ?? F(),
2092
+ id: t.id ?? I(),
2067
2093
  name: e,
2068
2094
  startedAt: Date.now(),
2069
2095
  parentId: t.parent ? this.journey?.id : void 0,
@@ -2081,7 +2107,7 @@ var or = class {
2081
2107
  getToken() {
2082
2108
  let e = this.journey;
2083
2109
  if (e === null) return;
2084
- let t = ir(e);
2110
+ let t = cr(e);
2085
2111
  if (t.length > 256) {
2086
2112
  this.diagnostics.report("journey.token_too_large", "journey token exceeded the size cap and was not issued", { length: t.length });
2087
2113
  return;
@@ -2105,7 +2131,7 @@ var or = class {
2105
2131
  this.clearTimer();
2106
2132
  }
2107
2133
  restore(e) {
2108
- let t = nr(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
2134
+ let t = or(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
2109
2135
  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}"`, {
2110
2136
  source: "sessionStorage",
2111
2137
  journeyId: t.id
@@ -2113,8 +2139,8 @@ var or = class {
2113
2139
  }
2114
2140
  decodeToken(e) {
2115
2141
  return this.diagnostics.guard("config.invalid", "decoding a seeded journey token", () => {
2116
- let t = e.replace(et, "+").replace(Je, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
2117
- return rr(JSON.parse(new TextDecoder().decode(i)));
2142
+ let t = e.replace(tt, "+").replace(Ye, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
2143
+ return sr(JSON.parse(new TextDecoder().decode(i)));
2118
2144
  }) ?? null;
2119
2145
  }
2120
2146
  setJourney(e) {
@@ -2124,7 +2150,7 @@ var or = class {
2124
2150
  let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
2125
2151
  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();
2126
2152
  }, t);
2127
- this.expiryTimer = n, E(n);
2153
+ this.expiryTimer = n, D(n);
2128
2154
  }
2129
2155
  clearStored() {
2130
2156
  this.diagnostics.guard("storage.unavailable", "clearing the persisted journey", () => {
@@ -2140,41 +2166,41 @@ var or = class {
2140
2166
  async readOpenFinToken() {
2141
2167
  let e = globalThis.fin?.me, t = e?.getOptions;
2142
2168
  if (t === void 0) return null;
2143
- let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => ar(t.call(e), Be)))?.customData?.[Ye];
2169
+ let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => R(t.call(e), Be)))?.customData?.[Xe];
2144
2170
  return typeof n == "string" ? n : null;
2145
2171
  }
2146
2172
  };
2147
2173
  //#endregion
2148
2174
  //#region src/core/sampling.ts
2149
- function sr(e) {
2175
+ function ur(e) {
2150
2176
  let t = m;
2151
2177
  for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, ge);
2152
2178
  return t >>> 0;
2153
2179
  }
2154
- function cr(e, t) {
2180
+ function J(e, t) {
2155
2181
  let n = e.attributes[t];
2156
2182
  return typeof n == "string" ? n : "";
2157
2183
  }
2158
- function lr(e, t) {
2184
+ function dr(e, t) {
2159
2185
  let { rates: n, defaultRate: r } = t.sampling, i, a = -1;
2160
2186
  for (let [t, r] of Object.entries(n)) (e === t || e.startsWith(`${t}.`)) && t.length > a && (i = r, a = t.length);
2161
2187
  return i ?? r;
2162
2188
  }
2163
- function ur(e, t) {
2189
+ function fr(e, t) {
2164
2190
  if (e.level === "ERROR" || e.level === "FATAL" || t.sampling.alwaysSampleTypes.includes(e.type)) return !0;
2165
- let n = lr(e.namespace, t);
2166
- return n >= 1 ? !0 : n <= 0 ? !1 : sr(e.journeyId || e.traceId) / Te < n;
2191
+ let n = dr(e.namespace, t);
2192
+ return n >= 1 ? !0 : n <= 0 ? !1 : ur(e.journeyId || e.traceId) / $e < n;
2167
2193
  }
2168
- function dr(e, t) {
2169
- return ur({
2194
+ function pr(e, t) {
2195
+ return fr({
2170
2196
  level: e.severityText,
2171
- type: cr(e, S),
2172
- namespace: cr(e, C),
2173
- journeyId: cr(e, b),
2197
+ type: J(e, S),
2198
+ namespace: J(e, C),
2199
+ journeyId: J(e, we),
2174
2200
  traceId: e.traceId
2175
2201
  }, t);
2176
2202
  }
2177
- var fr = class {
2203
+ var mr = class {
2178
2204
  windowStart = 0;
2179
2205
  count = 0;
2180
2206
  allow(e) {
@@ -2185,19 +2211,19 @@ var fr = class {
2185
2211
  };
2186
2212
  //#endregion
2187
2213
  //#region src/core/pipeline.ts
2188
- function pr(e) {
2189
- return e.attributes[S] === lt;
2214
+ function hr(e) {
2215
+ return e.attributes[S] === ut;
2190
2216
  }
2191
- var mr = {
2217
+ var gr = {
2192
2218
  logs: {
2193
- flushIntervalMs: $e,
2219
+ flushIntervalMs: et,
2194
2220
  batchSize: 100
2195
2221
  },
2196
2222
  metrics: {
2197
- flushIntervalMs: qe,
2223
+ flushIntervalMs: Je,
2198
2224
  batchSize: 500
2199
2225
  }
2200
- }, hr = class {
2226
+ }, _r = class {
2201
2227
  options;
2202
2228
  onFlush;
2203
2229
  pending = [];
@@ -2225,12 +2251,12 @@ var mr = {
2225
2251
  let e = setTimeout(() => {
2226
2252
  this.timer = null, this.onFlush(this);
2227
2253
  }, this.options.flushIntervalMs);
2228
- this.timer = e, E(e);
2254
+ this.timer = e, D(e);
2229
2255
  }
2230
2256
  clearTimer() {
2231
2257
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
2232
2258
  }
2233
- }, gr = class {
2259
+ }, vr = class {
2234
2260
  transport;
2235
2261
  storage;
2236
2262
  retry;
@@ -2238,18 +2264,18 @@ var mr = {
2238
2264
  streams;
2239
2265
  unconfirmed = /* @__PURE__ */ new Map();
2240
2266
  queue = [];
2241
- ceiling = new fr();
2267
+ ceiling = new mr();
2242
2268
  inFlight = 0;
2243
2269
  pumpScheduled = !1;
2244
2270
  stopped = !1;
2245
- constructor(e, t, n, r, i = mr) {
2271
+ constructor(e, t, n, r, i = gr) {
2246
2272
  this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
2247
2273
  let a = (e) => {
2248
2274
  this.claim(e);
2249
2275
  };
2250
2276
  this.streams = {
2251
- logs: new hr(i.logs, a),
2252
- metrics: new hr(i.metrics, a)
2277
+ logs: new _r(i.logs, a),
2278
+ metrics: new _r(i.metrics, a)
2253
2279
  };
2254
2280
  }
2255
2281
  push(e) {
@@ -2271,7 +2297,7 @@ var mr = {
2271
2297
  }
2272
2298
  toBatch(e) {
2273
2299
  return e.length === 0 ? null : {
2274
- id: F(),
2300
+ id: I(),
2275
2301
  records: e,
2276
2302
  createdAt: Date.now(),
2277
2303
  attempts: 0
@@ -2279,7 +2305,7 @@ var mr = {
2279
2305
  }
2280
2306
  route(e) {
2281
2307
  try {
2282
- let t = pr(e) ? this.streams.metrics : this.streams.logs;
2308
+ let t = hr(e) ? this.streams.metrics : this.streams.logs;
2283
2309
  if (!this.ceiling.allow(e)) {
2284
2310
  this.diagnostics.count("record.dropped_by_ceiling");
2285
2311
  return;
@@ -2291,7 +2317,7 @@ var mr = {
2291
2317
  }
2292
2318
  claim(e) {
2293
2319
  let t = e.take(), n = {
2294
- id: F(),
2320
+ id: I(),
2295
2321
  records: t,
2296
2322
  createdAt: Date.now(),
2297
2323
  attempts: 0
@@ -2333,10 +2359,10 @@ var mr = {
2333
2359
  try {
2334
2360
  await this.transport.send(e);
2335
2361
  } catch (t) {
2336
- await this.store({
2362
+ await this.storeFailed({
2337
2363
  ...e,
2338
2364
  attempts: e.attempts + 1
2339
- }), this.diagnostics.report("transport.http_error", "batch was stored for retry instead of being delivered", {
2365
+ }, t), this.diagnostics.report("transport.http_error", "batch was stored for retry instead of being delivered", {
2340
2366
  batchId: e.id,
2341
2367
  records: e.records.length
2342
2368
  }, t);
@@ -2345,9 +2371,14 @@ var mr = {
2345
2371
  this.unconfirmed.delete(e.id);
2346
2372
  }
2347
2373
  }
2374
+ async storeFailed(e, t) {
2375
+ await this.diagnostics.guardAsync("storage.degraded", "persisting an undelivered batch", async () => {
2376
+ await this.retry.storeFailed(e, t);
2377
+ });
2378
+ }
2348
2379
  async store(e) {
2349
2380
  await this.diagnostics.guardAsync("storage.degraded", "persisting an undelivered batch", async () => {
2350
- await this.storage.save(e), this.retry.nudge();
2381
+ await R(this.storage.save(e), v), this.retry.nudge();
2351
2382
  });
2352
2383
  }
2353
2384
  };
@@ -2356,7 +2387,7 @@ var mr = {
2356
2387
  function Y(e) {
2357
2388
  return e;
2358
2389
  }
2359
- var _r = class {
2390
+ var yr = class {
2360
2391
  deps;
2361
2392
  resourceCache = null;
2362
2393
  constructor(e) {
@@ -2376,7 +2407,7 @@ var _r = class {
2376
2407
  dropped: "level"
2377
2408
  };
2378
2409
  let s = r.resolve(), c = i.current();
2379
- if (!ur({
2410
+ if (!fr({
2380
2411
  level: e.level,
2381
2412
  type: e.type,
2382
2413
  namespace: e.namespace,
@@ -2386,9 +2417,9 @@ var _r = class {
2386
2417
  record: null,
2387
2418
  dropped: "sampling"
2388
2419
  };
2389
- let l = a.next(), u = Ht(), d = t.capture.fullUrls ? u : j(u), f, p = 0;
2420
+ let l = a.next(), u = Ht(), d = t.capture.fullUrls ? u : M(u), f, p = 0;
2390
2421
  try {
2391
- let t = B(this.deps.context.getAll(), o), n = B(e.scoped ?? {}, o), r = B(e.payload ?? {}, o);
2422
+ let t = H(this.deps.context.getAll(), o), n = H(e.scoped ?? {}, o), r = H(e.payload ?? {}, o);
2392
2423
  p = t.bytes + n.bytes + r.bytes, f = {
2393
2424
  ...Y(t.value),
2394
2425
  ...Y(n.value),
@@ -2397,8 +2428,8 @@ var _r = class {
2397
2428
  } catch (e) {
2398
2429
  n.report("record.sanitize_failed", "attributes could not be sanitized", void 0, e), f = { [Me]: !0 };
2399
2430
  }
2400
- f[S] = e.type, f[ke] = l, f[C] = e.namespace, f[pt] = d, c && (f[b] = c.id, f[Ze] = c.name, c.parentId !== void 0 && (f[st] = c.parentId));
2401
- let m = z(e.body, o.maxBodyChars);
2431
+ f[S] = e.type, f[ke] = l, f[C] = e.namespace, f[mt] = d, c && (f[we] = c.id, f[Qe] = c.name, c.parentId !== void 0 && (f[ct] = c.parentId));
2432
+ let m = V(e.body, o.maxBodyChars);
2402
2433
  m !== e.body && n.count("record.truncated");
2403
2434
  let h = {
2404
2435
  timeUnixNano: Xt(),
@@ -2419,7 +2450,7 @@ var _r = class {
2419
2450
  };
2420
2451
  if (e !== void 0 && e !== h) {
2421
2452
  if (Zt(e)) {
2422
- let t = B(e.attributes, o);
2453
+ let t = H(e.attributes, o);
2423
2454
  h = {
2424
2455
  ...e,
2425
2456
  attributes: Y(t.value)
@@ -2436,11 +2467,11 @@ var _r = class {
2436
2467
  [S]: e.type,
2437
2468
  [ke]: l,
2438
2469
  [C]: e.namespace,
2439
- [pt]: d,
2470
+ [mt]: d,
2440
2471
  [Ve]: !0,
2441
- [it]: p
2472
+ [at]: p
2442
2473
  };
2443
- c && (t[b] = c.id, t[Ze] = c.name), h.attributes = t;
2474
+ c && (t[we] = c.id, t[Qe] = c.name), h.attributes = t;
2444
2475
  }
2445
2476
  return { record: h };
2446
2477
  }
@@ -2451,9 +2482,9 @@ var _r = class {
2451
2482
  [le]: e.serviceName,
2452
2483
  [Ke]: e.serviceVersion,
2453
2484
  [_t]: e.environment,
2454
- [se]: dt,
2455
- [ue]: Xe,
2456
- [ae]: Pe,
2485
+ [se]: Ze,
2486
+ [ue]: ot,
2487
+ [ae]: ft,
2457
2488
  [he]: r.platform,
2458
2489
  [n]: t.sessionId,
2459
2490
  [We]: t.tabId,
@@ -2463,16 +2494,16 @@ var _r = class {
2463
2494
  ...r.openfinName === void 0 ? {} : { [l]: r.openfinName }
2464
2495
  }, this.resourceCache;
2465
2496
  }
2466
- }, vr = Symbol.for(fe), X = class t {
2497
+ }, br = Symbol.for(fe), X = class e {
2467
2498
  diagnostics;
2468
2499
  config;
2469
2500
  platform;
2470
2501
  identity;
2471
2502
  sessionTouch;
2472
- context = new Qn();
2503
+ context = new nr();
2473
2504
  breadcrumbs;
2474
2505
  tracing;
2475
- sequence = new En();
2506
+ sequence = new Dn();
2476
2507
  journey;
2477
2508
  builder;
2478
2509
  console;
@@ -2484,6 +2515,10 @@ var _r = class {
2484
2515
  pipeline;
2485
2516
  exitFlush;
2486
2517
  captures = [];
2518
+ captureOnce = {
2519
+ webVitals: !1,
2520
+ navigationTiming: !1
2521
+ };
2487
2522
  bootBuffer = [];
2488
2523
  forwardBuffer = [];
2489
2524
  forwardScheduled = !1;
@@ -2491,9 +2526,9 @@ var _r = class {
2491
2526
  destroyed = !1;
2492
2527
  lastGapAt = 0;
2493
2528
  constructor(e) {
2494
- this.diagnostics = new $n(e.onDiagnostic), this.platform = zt(this.diagnostics), this.config = Yn(e, this.diagnostics), this.identity = $t(this.diagnostics), this.sessionTouch = new en(this.diagnostics), this.breadcrumbs = new Ln(50), this.tracing = new In(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new Tn(this.config.console, this.diagnostics), this.journey = new or(er, this.diagnostics, this.identity.contextId, (e) => {
2529
+ this.diagnostics = new rr(e.onDiagnostic), this.platform = zt(this.diagnostics), this.config = $n(e, this.diagnostics), this.identity = $t(this.diagnostics), this.sessionTouch = new en(this.diagnostics), this.breadcrumbs = new Rn(50), this.tracing = new Ln(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new En(this.config.console, this.diagnostics), this.journey = new lr(ir, this.diagnostics, this.identity.contextId, (e) => {
2495
2530
  this.bus.broadcastJourney(e);
2496
- }), this.builder = new _r({
2531
+ }), this.builder = new yr({
2497
2532
  config: this.config,
2498
2533
  limits: Oe,
2499
2534
  diagnostics: this.diagnostics,
@@ -2522,16 +2557,16 @@ var _r = class {
2522
2557
  });
2523
2558
  };
2524
2559
  static current() {
2525
- return globalThis[vr] ?? null;
2560
+ return globalThis[br] ?? null;
2526
2561
  }
2527
- static configure(e) {
2528
- let n = t.current();
2529
- if (n && !n.destroyed) return n.reconfigure(e), n;
2530
- let r = new t(e);
2531
- return globalThis[vr] = r, r.init(), r;
2562
+ static configure(t) {
2563
+ let n = e.current();
2564
+ if (n && !n.destroyed) return n.reconfigure(t), n;
2565
+ let r = new e(t);
2566
+ return globalThis[br] = r, r.init(), r;
2532
2567
  }
2533
2568
  reconfigure(e) {
2534
- Zn(this.config, Yn(e, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.ready && this.reinstallCaptures(), this.diagnostics.report("config.reconfigured", "configure() was called again, the existing runtime was updated");
2569
+ tr(this.config, $n(e, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.ready && this.reinstallCaptures(), this.diagnostics.report("config.reconfigured", "configure() was called again, the existing runtime was updated");
2535
2570
  }
2536
2571
  keepBuiltStorage() {
2537
2572
  let e = this.storageBuiltAs;
@@ -2548,10 +2583,11 @@ var _r = class {
2548
2583
  }
2549
2584
  }
2550
2585
  async becomeSender() {
2551
- this.storageBuiltAs = this.config.storage, this.storage = await gn(this.config.storage, p, ne, this.diagnostics, this.reportGap), this.transport = new Sn(this.config, this.diagnostics), this.retry = new Cn(this.storage, this.transport, this.diagnostics, this.config), this.pipeline = new gr(this.transport, this.storage, this.retry, this.diagnostics), this.exitFlush = new yn({
2586
+ this.storageBuiltAs = this.config.storage, this.storage = await _n(this.config.storage, p, it, this.diagnostics, this.reportGap), this.transport = new Cn(this.config, this.diagnostics), this.retry = new wn(this.storage, this.transport, this.diagnostics, this.config), this.pipeline = new vr(this.transport, this.storage, this.retry, this.diagnostics), this.exitFlush = new bn({
2552
2587
  config: this.config,
2553
2588
  diagnostics: this.diagnostics,
2554
- drainForExit: () => this.pipeline?.drainForExit() ?? null
2589
+ drainForExit: () => this.pipeline?.drainForExit() ?? null,
2590
+ drainPending: () => this.pipeline?.drainPending() ?? null
2555
2591
  }), await ln(this.storage, this.diagnostics), this.retry.start(), this.exitFlush.install();
2556
2592
  }
2557
2593
  installCaptures() {
@@ -2560,7 +2596,8 @@ var _r = class {
2560
2596
  diagnostics: this.diagnostics,
2561
2597
  breadcrumbs: this.breadcrumbs,
2562
2598
  tracing: this.tracing,
2563
- logger: new T(this, i)
2599
+ logger: new E(this, i),
2600
+ once: this.captureOnce
2564
2601
  }, t = this.config.capture;
2565
2602
  (t.errors || t.rejections || t.resourceErrors) && this.captures.push(new Ut(e)), (t.fetch || t.xhr) && this.captures.push(new qt(e)), (t.interactions || t.navigation) && this.captures.push(new Gt(e)), t.webVitals && this.captures.push(new Yt(e));
2566
2603
  for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `installing ${e.name}`, () => {
@@ -2582,7 +2619,7 @@ var _r = class {
2582
2619
  if (!this.destroyed) {
2583
2620
  this.destroyed = !0;
2584
2621
  for (let e of this.captures) e.uninstall();
2585
- this.captures.length = 0, this.exitFlush?.flush("shutdown"), this.exitFlush?.uninstall(), this.retry?.stop(), this.pipeline?.destroy(), this.journey.destroy(), this.bus.destroy(), this.forwardBuffer = [], await this.storage?.close(), t.current() === this && Reflect.deleteProperty(globalThis, vr);
2622
+ this.captures.length = 0, this.exitFlush?.flush("shutdown"), this.exitFlush?.uninstall(), this.retry?.stop(), this.pipeline?.destroy(), this.journey.destroy(), this.bus.destroy(), this.forwardBuffer = [], await this.storage?.close(), e.current() === this && Reflect.deleteProperty(globalThis, br);
2586
2623
  }
2587
2624
  }
2588
2625
  emit(e) {
@@ -2618,7 +2655,7 @@ var _r = class {
2618
2655
  this.diagnostics.count("record.dropped_malformed");
2619
2656
  continue;
2620
2657
  }
2621
- if (!dr(t, this.config)) {
2658
+ if (!pr(t, this.config)) {
2622
2659
  this.diagnostics.count("record.dropped_by_sampling");
2623
2660
  continue;
2624
2661
  }
@@ -2633,19 +2670,19 @@ var _r = class {
2633
2670
  }
2634
2671
  reportGap = (e) => {
2635
2672
  let t = Date.now();
2636
- t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new T(this, rt).warn("stored records were dropped before delivery", {
2673
+ t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new E(this, te).warn("stored records were dropped before delivery", {
2637
2674
  "gap.batches": e.batches,
2638
2675
  "gap.records": e.records,
2639
2676
  "gap.reason": e.reason
2640
2677
  }));
2641
2678
  };
2642
2679
  regenerateTabId() {
2643
- let t = F();
2680
+ let e = I();
2644
2681
  this.diagnostics.report("bus.role_resolved", "another context claimed this tab id, most likely a duplicated tab. Regenerating.", {
2645
2682
  was: this.identity.tabId,
2646
- now: t
2647
- }), this.identity.tabId = t, this.diagnostics.guard("storage.unavailable", "persisting the new tab id", () => {
2648
- sessionStorage.setItem(e, t);
2683
+ now: e
2684
+ }), this.identity.tabId = e, this.diagnostics.guard("storage.unavailable", "persisting the new tab id", () => {
2685
+ sessionStorage.setItem(Pe, e);
2649
2686
  }), this.builder.invalidateResource();
2650
2687
  }
2651
2688
  async queueDepth() {
@@ -2662,10 +2699,10 @@ var _r = class {
2662
2699
  await this.transport.send(e);
2663
2700
  } catch (t) {
2664
2701
  await this.diagnostics.guardAsync("storage.degraded", "persisting the batch drained by flush()", async () => {
2665
- await this.storage?.save({
2702
+ await this.retry?.storeFailed({
2666
2703
  ...e,
2667
- attempts: 1
2668
- }), this.retry?.nudge();
2704
+ attempts: e.attempts + 1
2705
+ }, t);
2669
2706
  }), this.diagnostics.report("transport.http_error", "the batch drained by flush() was stored for retry instead of being delivered", {
2670
2707
  batchId: e.id,
2671
2708
  records: e.records.length
@@ -2676,94 +2713,94 @@ var _r = class {
2676
2713
  function Q() {
2677
2714
  return X.current() || X.configure({});
2678
2715
  }
2679
- function yr(e) {
2716
+ function xr(e) {
2680
2717
  X.configure(e), Z.clear();
2681
2718
  }
2682
- function br(e, t) {
2683
- if (t) return new T(Q(), e, t);
2719
+ function Sr(e, t) {
2720
+ if (t) return new E(Q(), e, t);
2684
2721
  let n = Z.get(e);
2685
- return n || (n = new T(Q(), e), Z.set(e, n)), n;
2722
+ return n || (n = new E(Q(), e), Z.set(e, n)), n;
2686
2723
  }
2687
2724
  function $() {
2688
- return br("app");
2725
+ return Sr("app");
2689
2726
  }
2690
- function xr(e, t) {
2727
+ function Cr(e, t) {
2691
2728
  $().trace(e, t);
2692
2729
  }
2693
- function Sr(e, t) {
2730
+ function wr(e, t) {
2694
2731
  $().debug(e, t);
2695
2732
  }
2696
- function Cr(e, t) {
2733
+ function Tr(e, t) {
2697
2734
  $().info(e, t);
2698
2735
  }
2699
- function wr(e, t) {
2736
+ function Er(e, t) {
2700
2737
  $().warn(e, t);
2701
2738
  }
2702
- function Tr(e, t, n) {
2739
+ function Dr(e, t, n) {
2703
2740
  $().error(e, t, n);
2704
2741
  }
2705
- function Er(e, t) {
2742
+ function Or(e, t) {
2706
2743
  $().logAction(e, t);
2707
2744
  }
2708
- function Dr(e, t) {
2745
+ function kr(e, t) {
2709
2746
  $().logEvent(e, t);
2710
2747
  }
2711
- function Or(e, t, n, r, i) {
2748
+ function Ar(e, t, n, r, i) {
2712
2749
  $().logMetric(e, t, n, r, i);
2713
2750
  }
2714
- function kr(e, t, n) {
2751
+ function jr(e, t, n) {
2715
2752
  return $().timeSync(e, t, n);
2716
2753
  }
2717
- function Ar(e, t, n) {
2754
+ function Mr(e, t, n) {
2718
2755
  return $().timeAsync(e, t, n);
2719
2756
  }
2720
- function jr(e, t) {
2757
+ function Nr(e, t) {
2721
2758
  Q().context.set(e, t);
2722
2759
  }
2723
- function Mr(e) {
2760
+ function Pr(e) {
2724
2761
  Q().context.setMany(e);
2725
2762
  }
2726
- function Nr(e) {
2763
+ function Fr(e) {
2727
2764
  Q().context.remove(e);
2728
2765
  }
2729
- function Pr(e, t) {
2766
+ function Ir(e, t) {
2730
2767
  return Q().journey.start(e, t);
2731
2768
  }
2732
- function Fr() {
2769
+ function Lr() {
2733
2770
  Q().journey.end();
2734
2771
  }
2735
- function Ir() {
2772
+ function Rr() {
2736
2773
  return Q().journey.current();
2737
2774
  }
2738
- function Lr() {
2775
+ function zr() {
2739
2776
  return Q().journey.getToken();
2740
2777
  }
2741
- function Rr(e) {
2778
+ function Br(e) {
2742
2779
  return Q().journey.adopt(e, "manual", !0);
2743
2780
  }
2744
- function zr(e) {
2781
+ function Vr(e) {
2745
2782
  Q().registerWorker(e);
2746
2783
  }
2747
- function Br() {
2784
+ function Hr() {
2748
2785
  Q().tracing.rotate("explicit");
2749
2786
  }
2750
- function Vr() {
2787
+ function Ur() {
2751
2788
  return Q().tracing.headers();
2752
2789
  }
2753
- function Hr() {
2790
+ function Wr() {
2754
2791
  return Q().flush();
2755
2792
  }
2756
- function Ur() {
2793
+ function Gr() {
2757
2794
  return Q().queueDepth();
2758
2795
  }
2759
- function Wr() {
2796
+ function Kr() {
2760
2797
  return Q().diagnostics.snapshot();
2761
2798
  }
2762
- async function Gr() {
2799
+ async function qr() {
2763
2800
  let e = X.current();
2764
2801
  Z.clear(), await e?.destroy();
2765
2802
  }
2766
2803
  //#endregion
2767
- export { T as OneLogger, Rr as adoptJourney, yr as configure, Ir as currentJourney, Sr as debug, Fr as endJourney, Tr as error, Hr as flush, Wr as getDiagnosticCounters, Lr as getJourneyToken, br as getLogger, Ur as getQueueDepth, Vr as getTraceHeaders, Cr as info, Er as logAction, Dr as logEvent, Or as logMetric, zr as registerWorker, Nr as removeContext, jr as setContext, Mr as setContextMap, Gr as shutdown, Pr as startJourney, Br as startTrace, Ar as timeAsync, kr as timeSync, xr as trace, wr as warn };
2804
+ export { E as OneLogger, Br as adoptJourney, xr as configure, Rr as currentJourney, wr as debug, Lr as endJourney, Dr as error, Wr as flush, Kr as getDiagnosticCounters, zr as getJourneyToken, Sr as getLogger, Gr as getQueueDepth, Ur as getTraceHeaders, Tr as info, Or as logAction, kr as logEvent, Ar as logMetric, Vr as registerWorker, Fr as removeContext, Nr as setContext, Pr as setContextMap, qr as shutdown, Ir as startJourney, Hr as startTrace, Mr as timeAsync, jr as timeSync, Cr as trace, Er as warn };
2768
2805
 
2769
2806
  //# sourceMappingURL=index.js.map