@utk09/ui-observability 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +67 -15
  2. package/README.md +94 -82
  3. package/dist/bus/links.d.ts +5 -4
  4. package/dist/capture/network.d.ts +1 -1
  5. package/dist/constants-BpFlszME.cjs +2 -0
  6. package/dist/constants-BpFlszME.cjs.map +1 -0
  7. package/dist/constants-CrU3IUyy.js +74 -0
  8. package/dist/constants-CrU3IUyy.js.map +1 -0
  9. package/dist/constants.d.ts +20 -2
  10. package/dist/core/diagnostics.d.ts +1 -1
  11. package/dist/core/logger.d.ts +7 -5
  12. package/dist/core/pipeline.d.ts +19 -6
  13. package/dist/core/record.d.ts +11 -2
  14. package/dist/core/runtime.d.ts +13 -1
  15. package/dist/core/sampling.d.ts +42 -1
  16. package/dist/index.cjs +3 -3
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.js +728 -565
  20. package/dist/index.js.map +1 -1
  21. package/dist/{indexeddb-storage-DAoHV_oL.js → indexeddb-storage-CSaDuHGk.js} +19 -15
  22. package/dist/indexeddb-storage-CSaDuHGk.js.map +1 -0
  23. package/dist/indexeddb-storage-DIJIbFnp.cjs +2 -0
  24. package/dist/indexeddb-storage-DIJIbFnp.cjs.map +1 -0
  25. package/dist/models/config.d.ts +69 -2
  26. package/dist/storage/local-storage.d.ts +14 -0
  27. package/dist/transport/exit-flush.d.ts +1 -1
  28. package/dist/utils/console.d.ts +4 -1
  29. package/dist/utils/identity.d.ts +17 -6
  30. package/dist/utils/platform.d.ts +7 -0
  31. package/dist/utils/sanitize.d.ts +2 -0
  32. package/dist/utils/tracing.d.ts +17 -1
  33. package/package.json +10 -8
  34. package/dist/constants-DkrpC_xK.cjs +0 -2
  35. package/dist/constants-DkrpC_xK.cjs.map +0 -1
  36. package/dist/constants-NJNXpfPi.js +0 -67
  37. package/dist/constants-NJNXpfPi.js.map +0 -1
  38. package/dist/indexeddb-storage-CH9NocOC.cjs +0 -2
  39. package/dist/indexeddb-storage-CH9NocOC.cjs.map +0 -1
  40. package/dist/indexeddb-storage-DAoHV_oL.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,46 +1,52 @@
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 ee, J as te, Jt as ne, K as re, Kt as ie, L as g, Lt as ae, M as oe, Mt as se, N as ce, Nt as le, O as ue, Ot as de, Pt as fe, Qt as pe, R as me, S as he, St as ge, T as _e, Tt as ve, Ut as ye, V as be, Vt as _, W as xe, Wt as Se, Xt as Ce, Yt as we, Zt as Te, _ as Ee, _t as De, a as Oe, an as ke, at as Ae, b as je, bt as Me, c as Ne, ct as Pe, d as Fe, dt as Ie, en as Le, et as Re, ft as ze, g as Be, gt as Ve, h as He, ht as Ue, i as We, in as Ge, it as Ke, j as qe, jt as Je, k as Ye, kt as Xe, l as v, lt as Ze, m as Qe, mt as $e, n as y, nn as et, nt as tt, o as nt, on as rt, ot as it, p as at, pt as ot, q as st, r as ct, rn as lt, rt as b, s as ut, st as dt, t as ft, tn as pt, tt as x, u as mt, ut as ht, v as gt, wt as _t, x as vt, xt as yt, yt as bt, zt as xt } from "./constants-NJNXpfPi.js";
2
- import { context as St, isSpanContextValid as Ct, propagation as wt, trace as Tt } from "@opentelemetry/api";
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";
3
2
  //#region src/utils/timer.ts
4
- function Et(e) {
5
- return Math.round((performance.now() - e) * d) / d;
3
+ function xt(e) {
4
+ return Math.round((performance.now() - e) * u) / u;
6
5
  }
7
- function Dt(e, t, n, r, i) {
8
- e.logMetric(`${t}.duration`, Et(n), "ms", "histogram", {
6
+ function St(e, t, n, r, i) {
7
+ e.logMetric(`${t}.duration`, xt(n), "ms", "histogram", {
9
8
  status: r,
10
9
  ...i
11
10
  });
12
11
  }
13
- function Ot(e, t, n, r, i) {
12
+ function Ct(e, t, n, r, i) {
14
13
  e.error(`${t} failed`, r, {
15
- "action.duration_ms": Et(n),
14
+ "action.duration_ms": xt(n),
16
15
  status: "FAILURE",
17
16
  ...i
18
17
  });
19
18
  }
20
- function kt(e, t, n, r) {
19
+ function wt(e, t, n, r) {
21
20
  let i = performance.now();
22
21
  try {
23
22
  let a = n();
24
- return Dt(e, t, i, "SUCCESS", r), a;
23
+ return St(e, t, i, "SUCCESS", r), a;
25
24
  } catch (n) {
26
- throw Ot(e, t, i, n, r), n;
25
+ throw Ct(e, t, i, n, r), n;
27
26
  }
28
27
  }
29
- async function At(e, t, n, r) {
28
+ async function Tt(e, t, n, r) {
30
29
  let i = performance.now();
31
30
  try {
32
31
  let a = await n();
33
- return Dt(e, t, i, "SUCCESS", r), a;
32
+ return St(e, t, i, "SUCCESS", r), a;
34
33
  } catch (n) {
35
- throw Ot(e, t, i, n, r), n;
34
+ throw Ct(e, t, i, n, r), n;
36
35
  }
37
36
  }
38
37
  //#endregion
39
38
  //#region src/core/logger.ts
40
- function jt(e) {
41
- return e instanceof Error ? e : Error(String(e));
39
+ function Et(e, t) {
40
+ if (e instanceof Error) return e;
41
+ let n = t.guard("record.sanitize_failed", "describing an error reason", () => String(e));
42
+ return Error(n ?? typeof e);
42
43
  }
43
- var S = class e {
44
+ function Dt(e) {
45
+ if (typeof e != "object" || !e || Array.isArray(e) || e instanceof Error) return !1;
46
+ let t = Object.getPrototypeOf(e);
47
+ return t === null || Object.getPrototypeOf(t) === null;
48
+ }
49
+ var T = class e {
44
50
  runtime;
45
51
  namespace;
46
52
  options;
@@ -77,7 +83,7 @@ var S = class e {
77
83
  logEvent = (e, t) => {
78
84
  this.write("INFO", "event", e, t);
79
85
  };
80
- logMetric = (e, t, n = oe, r = "gauge", i) => {
86
+ logMetric = (e, t, n = ie, r = "gauge", i) => {
81
87
  this.write("INFO", "metric", e, {
82
88
  "metric.name": e,
83
89
  "metric.value": t,
@@ -86,11 +92,11 @@ var S = class e {
86
92
  ...i
87
93
  });
88
94
  };
89
- timeSync = (e, t, n) => kt(this, e, t, n);
90
- timeAsync = (e, t, n) => At(this, e, t, n);
95
+ timeSync = (e, t, n) => wt(this, e, t, n);
96
+ timeAsync = (e, t, n) => Tt(this, e, t, n);
91
97
  write(e, t, n, r) {
92
98
  if (!this.runtime.builder.isEnabled(e)) return;
93
- let i = this.runtime.builder.build({
99
+ let { record: i, dropped: a } = this.runtime.builder.build({
94
100
  level: e,
95
101
  type: t,
96
102
  body: n,
@@ -98,7 +104,7 @@ var S = class e {
98
104
  scoped: this.options.scopedContext,
99
105
  payload: r
100
106
  });
101
- i && t !== "metric" && this.runtime.breadcrumbs.push({
107
+ t !== "metric" && a !== "redact" && this.runtime.breadcrumbs.push({
102
108
  t: Date.now(),
103
109
  category: t === "action" ? "action" : t === "event" ? "event" : "log",
104
110
  message: n
@@ -106,39 +112,39 @@ var S = class e {
106
112
  }
107
113
  writeError(e, t, n, r) {
108
114
  if (!this.runtime.builder.isEnabled(e)) return;
109
- let i = n === void 0 ? void 0 : jt(n), a = this.runtime.builder.build({
115
+ let i = r === void 0 && Dt(n), a = i ? n : r, o = i || n === void 0 ? void 0 : Et(n, this.runtime.diagnostics), { record: s } = this.runtime.builder.build({
110
116
  level: e,
111
117
  type: "system",
112
118
  body: t,
113
119
  namespace: this.namespace,
114
120
  scoped: this.options.scopedContext,
115
121
  payload: {
116
- ...r,
117
- ...i ? {
118
- "error.type": i.name,
119
- "error.message": i.message,
120
- "error.stack_trace": i.stack
122
+ ...a,
123
+ ...o ? {
124
+ "error.type": o.name,
125
+ "error.message": o.message,
126
+ "error.stack_trace": o.stack
121
127
  } : {},
122
128
  breadcrumbs: this.runtime.breadcrumbs.snapshot()
123
129
  }
124
130
  });
125
- this.runtime.console.write(e, t, i ?? a?.attributes), this.runtime.emit(a);
131
+ this.runtime.console.write(e, t, o ?? s?.attributes), this.runtime.emit(s);
126
132
  }
127
133
  };
128
134
  //#endregion
129
135
  //#region src/utils/unref.ts
130
- function C(e) {
136
+ function E(e) {
131
137
  typeof e != "number" && e.unref?.();
132
138
  }
133
139
  //#endregion
134
140
  //#region src/models/bus.ts
135
- function w(e) {
141
+ function D(e) {
136
142
  return {
137
- p: he,
143
+ p: pe,
138
144
  m: e
139
145
  };
140
146
  }
141
- function T(e) {
147
+ function O(e) {
142
148
  if (typeof e != "object" || !e) return null;
143
149
  let t = e;
144
150
  if (t.p !== "ui-observability/1" || typeof t.m != "object" || t.m === null) return null;
@@ -147,12 +153,12 @@ function T(e) {
147
153
  }
148
154
  //#endregion
149
155
  //#region src/bus/links.ts
150
- var Mt = Symbol.for(ae);
151
- function Nt(e, t) {
156
+ var Ot = Symbol.for(fe);
157
+ function kt(e, t) {
152
158
  if (typeof window > "u" || window.parent === window) return null;
153
159
  let n;
154
160
  try {
155
- n = window.parent[Mt];
161
+ n = window.parent[Ot];
156
162
  } catch {
157
163
  return null;
158
164
  }
@@ -170,10 +176,10 @@ function Nt(e, t) {
170
176
  }
171
177
  };
172
178
  }
173
- function Pt(e, t) {
179
+ function At(e, t) {
174
180
  if (typeof window > "u" || window.parent === window) return null;
175
181
  let n = (t) => {
176
- let n = T(t.data);
182
+ let n = O(t.data);
177
183
  n && t.source === window.parent && e(n, {
178
184
  link: "parent",
179
185
  origin: t.origin
@@ -183,7 +189,7 @@ function Pt(e, t) {
183
189
  kind: "parent",
184
190
  post(e) {
185
191
  t.guard("bus.send_failed", "postMessage to parent", () => {
186
- window.parent.postMessage(w(e), "*");
192
+ window.parent.postMessage(D(e), "*");
187
193
  });
188
194
  },
189
195
  close() {
@@ -191,10 +197,10 @@ function Pt(e, t) {
191
197
  }
192
198
  };
193
199
  }
194
- function Ft(e, t, n) {
200
+ function jt(e, t, n) {
195
201
  if (typeof window > "u") return null;
196
- let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Set(), a = (t) => {
197
- let a = T(t.data);
202
+ let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Map(), a = (t) => {
203
+ let a = O(t.data);
198
204
  if (a) {
199
205
  if (!r.has(t.origin)) {
200
206
  n.report("bus.untrusted_origin", `ignored a bus message from ${t.origin}. Add it to bus.trustedOrigins if it is yours.`, {
@@ -203,7 +209,7 @@ function Ft(e, t, n) {
203
209
  });
204
210
  return;
205
211
  }
206
- t.source && i.add(t.source), e(a, {
212
+ t.source && i.set(t.source, t.origin), e(a, {
207
213
  link: "children",
208
214
  origin: t.origin
209
215
  });
@@ -212,14 +218,14 @@ function Ft(e, t, n) {
212
218
  return addEventListener("message", a), {
213
219
  kind: "children",
214
220
  post(e) {
215
- for (let t of i) {
216
- let r = t;
217
- if (r.closed) {
221
+ for (let [t, r] of i) {
222
+ let a = t;
223
+ if (a.closed) {
218
224
  i.delete(t);
219
225
  continue;
220
226
  }
221
227
  n.guard("bus.send_failed", "postMessage to child", () => {
222
- r.postMessage(w(e), "*");
228
+ a.postMessage(D(e), r);
223
229
  });
224
230
  }
225
231
  },
@@ -228,12 +234,12 @@ function Ft(e, t, n) {
228
234
  }
229
235
  };
230
236
  }
231
- function It(e, t, n) {
237
+ function Mt(e, t, n) {
232
238
  let r = globalThis.BroadcastChannel;
233
239
  if (r === void 0) return null;
234
240
  let i = n.guard("bus.send_failed", "opening BroadcastChannel", () => new r(e));
235
241
  return i ? (i.onmessage = (e) => {
236
- let n = T(e.data);
242
+ let n = O(e.data);
237
243
  n && t(n, {
238
244
  link: "broadcast",
239
245
  origin: "same-origin"
@@ -242,7 +248,7 @@ function It(e, t, n) {
242
248
  kind: "broadcast",
243
249
  post(e) {
244
250
  n.guard("bus.send_failed", "BroadcastChannel.postMessage", () => {
245
- i.postMessage(w(e));
251
+ i.postMessage(D(e));
246
252
  });
247
253
  },
248
254
  close() {
@@ -252,26 +258,29 @@ function It(e, t, n) {
252
258
  }
253
259
  }) : null;
254
260
  }
255
- function Lt(e, t, n) {
256
- let r = globalThis.fin?.InterApplicationBus;
257
- return r ? (n.guardAsync("bus.send_failed", "InterApplicationBus.subscribe", () => r.subscribe({ uuid: "*" }, e, (e) => {
258
- let n = T(e);
259
- n && t(n, {
261
+ function Nt(e, t, n, r) {
262
+ let i = globalThis.fin?.InterApplicationBus;
263
+ if (!i) return null;
264
+ if (!t) return r.report("openfin.unavailable", "no OpenFin application uuid, so the InterApplicationBus link stays closed"), null;
265
+ let a = `${e}.${t}`;
266
+ return r.guardAsync("bus.send_failed", "InterApplicationBus.subscribe", () => i.subscribe({ uuid: t }, a, (e) => {
267
+ let t = O(e);
268
+ t && n(t, {
260
269
  link: "openfin",
261
270
  origin: "openfin"
262
271
  });
263
272
  })), {
264
273
  kind: "openfin",
265
- post(t) {
266
- n.guardAsync("bus.send_failed", "InterApplicationBus.publish", () => r.publish(e, w(t)));
274
+ post(e) {
275
+ r.guardAsync("bus.send_failed", "InterApplicationBus.publish", () => i.publish(a, D(e)));
267
276
  },
268
277
  close() {}
269
- }) : null;
278
+ };
270
279
  }
271
- function Rt(e, t) {
280
+ function Pt(e, t) {
272
281
  let n = globalThis, r = n.postMessage;
273
282
  return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
274
- let n = T(t.data);
283
+ let n = O(t.data);
275
284
  n && e(n, {
276
285
  link: "owner",
277
286
  origin: "same-origin"
@@ -280,15 +289,15 @@ function Rt(e, t) {
280
289
  kind: "owner",
281
290
  post(e) {
282
291
  t.guard("bus.send_failed", "worker postMessage", () => {
283
- r(w(e));
292
+ r(D(e));
284
293
  });
285
294
  },
286
295
  close() {}
287
296
  });
288
297
  }
289
- function zt(e, t, n) {
298
+ function Ft(e, t, n) {
290
299
  let r = (e) => {
291
- let n = T(e.data);
300
+ let n = O(e.data);
292
301
  n && t(n, {
293
302
  link: "worker",
294
303
  origin: "same-origin"
@@ -298,7 +307,7 @@ function zt(e, t, n) {
298
307
  kind: "worker",
299
308
  post(t) {
300
309
  n.guard("bus.send_failed", "postMessage to a worker", () => {
301
- e.postMessage(w(t));
310
+ e.postMessage(D(t));
302
311
  });
303
312
  },
304
313
  close() {
@@ -308,14 +317,14 @@ function zt(e, t, n) {
308
317
  }
309
318
  //#endregion
310
319
  //#region src/bus/bus.ts
311
- var Bt = {
320
+ var It = {
312
321
  timeoutMs: vt,
313
322
  maxAttempts: 3
314
- }, Vt = [
323
+ }, Lt = [
315
324
  "children",
316
325
  "direct",
317
326
  "worker"
318
- ], Ht = class {
327
+ ], Rt = class {
319
328
  config;
320
329
  diagnostics;
321
330
  platform;
@@ -330,7 +339,7 @@ var Bt = {
330
339
  isOpenFinProvider = !1;
331
340
  resolved = !1;
332
341
  awaitingWelcome = null;
333
- constructor(e, t, n, r, i, a, o = Bt) {
342
+ constructor(e, t, n, r, i, a, o = It) {
334
343
  this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
335
344
  }
336
345
  getRole() {
@@ -344,7 +353,7 @@ var Bt = {
344
353
  if (e.mode === "off") return this.role = "sender", this.resolved = !0, this.role;
345
354
  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;
346
355
  this.openControlLinks();
347
- let t = Nt(this.receive, this.diagnostics);
356
+ let t = kt(this.receive, this.diagnostics);
348
357
  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", {
349
358
  role: "forwarder",
350
359
  via: "direct"
@@ -395,7 +404,7 @@ var Bt = {
395
404
  this.receive(e, n);
396
405
  }
397
406
  attachWorker(e) {
398
- this.links.push(zt(e, this.receive, this.diagnostics));
407
+ this.links.push(Ft(e, this.receive, this.diagnostics));
399
408
  }
400
409
  broadcastJourney(e) {
401
410
  this.post({
@@ -450,7 +459,7 @@ var Bt = {
450
459
  }
451
460
  };
452
461
  canOwn(e) {
453
- return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : Vt.includes(e) : !1;
462
+ return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : Lt.includes(e) : !1;
454
463
  }
455
464
  resolveOpenFinProvider() {
456
465
  let e = this.config.bus.openFinRole;
@@ -465,22 +474,22 @@ var Bt = {
465
474
  isCrossOriginFrame() {
466
475
  if (typeof window > "u" || window.parent === window) return !1;
467
476
  try {
468
- return window.parent.location, !1;
477
+ return Reflect.get(window.parent, "location"), !1;
469
478
  } catch {
470
479
  return !0;
471
480
  }
472
481
  }
473
482
  candidateUpstream() {
474
- return this.platform.isWorker ? Rt(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : Pt(this.receive, this.diagnostics);
483
+ return this.platform.isWorker ? Pt(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : At(this.receive, this.diagnostics);
475
484
  }
476
485
  openControlLinks() {
477
486
  let e = (e) => {
478
487
  e && this.links.push(e);
479
488
  };
480
- this.platform.isTopLevelDocument && (e(Ft(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), e(It(je, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
489
+ this.platform.isTopLevelDocument && (e(jt(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), e(Mt(De, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
481
490
  }
482
491
  ensureOpenFinLink() {
483
- return this.openFinLink ??= Lt(je, this.receive, this.diagnostics), this.openFinLink;
492
+ return this.openFinLink ??= Nt(De, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
484
493
  }
485
494
  handshake(e) {
486
495
  return new Promise((t) => {
@@ -494,7 +503,7 @@ var Bt = {
494
503
  let i = setTimeout(() => {
495
504
  r(!1);
496
505
  }, this.handshakeOptions.timeoutMs);
497
- C(i), e.post({
506
+ E(i), e.post({
498
507
  t: "hello",
499
508
  from: this.contextId,
500
509
  tabId: this.tabId
@@ -511,7 +520,51 @@ var Bt = {
511
520
  from: this.contextId
512
521
  });
513
522
  }
514
- }, Ut = class {
523
+ }, k = null;
524
+ function A(e, t) {
525
+ let n = e[t];
526
+ return n !== void 0 && e instanceof n;
527
+ }
528
+ function zt(e) {
529
+ if (k) return k;
530
+ 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", () => {
532
+ let e = s.identity;
533
+ i = e?.uuid, a = e?.name;
534
+ })), k = {
535
+ platform: r,
536
+ openfinUuid: i,
537
+ openfinName: a,
538
+ userAgent: n,
539
+ isWorker: o,
540
+ isTopLevelDocument: Vt()
541
+ }, k;
542
+ }
543
+ function Bt(e) {
544
+ return ut.test(e) ? !0 : (Fe.test(e) || je.test(e) && Ne.test(e)) && e.includes("AppleWebKit") && !e.includes("Safari/");
545
+ }
546
+ function Vt() {
547
+ if (typeof window > "u") return !1;
548
+ try {
549
+ return window.self === window.top;
550
+ } catch {
551
+ return !1;
552
+ }
553
+ }
554
+ function Ht() {
555
+ try {
556
+ return typeof location < "u" ? location.href : "";
557
+ } catch {
558
+ return "";
559
+ }
560
+ }
561
+ function j(e) {
562
+ let t = e.search(/[?#]/);
563
+ return t === -1 ? e : e.slice(0, t);
564
+ }
565
+ //#endregion
566
+ //#region src/capture/errors.ts
567
+ var Ut = class {
515
568
  ctx;
516
569
  name = "errors";
517
570
  installed = !1;
@@ -531,13 +584,14 @@ var Bt = {
531
584
  let t = e.target, n = t?.src ?? t?.href ?? "";
532
585
  if (t !== null && t !== globalThis && n !== "") {
533
586
  if (!this.ctx.config.capture.resourceErrors) return;
587
+ let e = this.ctx.config.capture.fullUrls ? n : j(n);
534
588
  this.ctx.breadcrumbs.push({
535
589
  t: Date.now(),
536
590
  category: "http",
537
- message: `resource failed: ${n}`
591
+ message: `resource failed: ${e}`
538
592
  }), this.ctx.logger.warn("resource failed to load", {
539
593
  "error.type": "resource",
540
- "resource.url": n,
594
+ "resource.url": e,
541
595
  "resource.tag": t.tagName.toLowerCase()
542
596
  });
543
597
  return;
@@ -556,26 +610,26 @@ var Bt = {
556
610
  report(e, t, n) {
557
611
  let r = Date.now();
558
612
  if (r - this.windowStart > 1e4 && (this.windowStart = r, this.windowCount = 0), this.windowCount++, this.windowCount > 20) {
559
- this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(i)}ms, suppressing the rest of this window`);
613
+ this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(_e)}ms, suppressing the rest of this window`);
560
614
  return;
561
615
  }
562
- 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);
563
- if (c && r - c.at < 5e3) {
564
- c.count++, c.at = r;
616
+ 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);
617
+ if (s && r - s.at < 5e3) {
618
+ s.count++, s.at = r;
565
619
  return;
566
620
  }
567
- let l = c ? c.count - 1 : 0;
568
- if (this.seen.delete(s), this.seen.set(s, {
621
+ let c = s ? s.count - 1 : 0;
622
+ if (this.seen.delete(o), this.seen.set(o, {
569
623
  at: r,
570
624
  count: 1
571
625
  }), this.seen.size > 200) {
572
626
  let [e] = this.seen.keys();
573
627
  this.seen.delete(e);
574
628
  }
575
- this.ctx.logger.error(a.message === "" ? e : a.message, a, {
629
+ this.ctx.logger.error(i.message === "" ? e : i.message, i, {
576
630
  ...n,
577
631
  "error.captured_by": e,
578
- "error.suppressed_count": l
632
+ "error.suppressed_count": c
579
633
  });
580
634
  }
581
635
  };
@@ -591,7 +645,7 @@ function Wt(e) {
591
645
  let i = e.getAttribute("class")?.trim() ?? "";
592
646
  return i === "" ? t : `${t}.${i.split(/\s+/).slice(0, 2).join(".")}`;
593
647
  }
594
- function E() {
648
+ function M() {
595
649
  return history;
596
650
  }
597
651
  var Gt = class {
@@ -608,7 +662,7 @@ var Gt = class {
608
662
  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)));
609
663
  }
610
664
  uninstall() {
611
- this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (E().pushState = this.originalPushState), this.originalReplaceState && (E().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
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);
612
666
  }
613
667
  onClick = (e) => {
614
668
  let t = e.target, n = Wt(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.innerText.trim().slice(0, 50) : "";
@@ -621,15 +675,18 @@ var Gt = class {
621
675
  };
622
676
  onNavigate = () => {
623
677
  let e = this.lastUrl, t = location.href;
624
- e !== t && (this.lastUrl = t, this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
678
+ if (e === t) return;
679
+ this.lastUrl = t;
680
+ let n = this.ctx.config.capture.fullUrls, r = n ? e : j(e), i = n ? t : j(t);
681
+ this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
625
682
  t: Date.now(),
626
683
  category: "navigation",
627
- message: `${e} -> ${t}`
628
- }), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": e }));
684
+ message: `${r} -> ${i}`
685
+ }), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": r });
629
686
  };
630
687
  installHistory() {
631
688
  if (typeof history > "u" || this.originalPushState) return;
632
- let e = E(), t = e.pushState, n = e.replaceState;
689
+ let e = M(), t = e.pushState, n = e.replaceState;
633
690
  this.originalPushState = t, this.originalReplaceState = n;
634
691
  let r = this.onNavigate;
635
692
  e.pushState = function(...e) {
@@ -646,7 +703,7 @@ function Kt(e, t) {
646
703
  }
647
704
  //#endregion
648
705
  //#region src/capture/network.ts
649
- function D() {
706
+ function N() {
650
707
  return XMLHttpRequest.prototype;
651
708
  }
652
709
  var qt = class {
@@ -662,7 +719,7 @@ var qt = class {
662
719
  this.ctx.config.capture.fetch && this.installFetch(), this.ctx.config.capture.xhr && this.installXhr();
663
720
  }
664
721
  uninstall() {
665
- this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (D().open = this.originalOpen, null), this.originalSend &&= (D().send = this.originalSend, null);
722
+ this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (N().open = this.originalOpen, null), this.originalSend &&= (N().send = this.originalSend, null);
666
723
  }
667
724
  ignored(e) {
668
725
  return Kt(e, this.ctx.config.capture.ignoreUrls);
@@ -708,7 +765,7 @@ var qt = class {
708
765
  if (typeof XMLHttpRequest > "u" || this.originalOpen) return;
709
766
  let e = (e) => this.ignored(e), t = (e, t, n, r) => {
710
767
  this.record(e, t, n, r, void 0);
711
- }, n = D(), r = n.open, i = n.send;
768
+ }, n = N(), r = n.open, i = n.send;
712
769
  this.originalOpen = r, this.originalSend = i, n.open = function(e, t, ...n) {
713
770
  this.__uiobs = {
714
771
  method: e.toUpperCase(),
@@ -727,29 +784,30 @@ var qt = class {
727
784
  };
728
785
  }
729
786
  record(e, t, n, r, i) {
730
- this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${t}`, () => {
731
- let a = Math.round(r);
787
+ let a = this.ctx.config.capture.fullUrls ? t : j(t);
788
+ this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${a}`, () => {
789
+ let t = Math.round(r);
732
790
  this.ctx.breadcrumbs.push({
733
791
  t: Date.now(),
734
792
  category: "http",
735
- message: `${e} ${t} ${n === 0 ? "failed" : String(n)}`,
736
- data: { durationMs: a }
793
+ message: `${e} ${a} ${n === 0 ? "failed" : String(n)}`,
794
+ data: { durationMs: t }
737
795
  });
738
796
  let o = {
739
797
  "http.request.method": e,
740
- "url.full": t,
798
+ "url.full": a,
741
799
  "http.response.status_code": n,
742
- "http.duration_ms": a
800
+ "http.duration_ms": t
743
801
  };
744
802
  if (n === 0) {
745
- this.ctx.logger.error(`${e} ${t} failed`, i, o);
803
+ this.ctx.logger.error(`${e} ${a} failed`, i, o);
746
804
  return;
747
805
  }
748
806
  if (n >= 400) {
749
- this.ctx.logger.warn(`${e} ${t} returned ${String(n)}`, o);
807
+ this.ctx.logger.warn(`${e} ${a} returned ${String(n)}`, o);
750
808
  return;
751
809
  }
752
- this.ctx.logger.debug(`${e} ${t}`, o);
810
+ this.ctx.logger.debug(`${e} ${a}`, o);
753
811
  });
754
812
  }
755
813
  };
@@ -807,78 +865,84 @@ var Yt = class {
807
865
  };
808
866
  //#endregion
809
867
  //#region src/models/log-record.ts
810
- function O() {
868
+ function Xt() {
811
869
  return `${String(Date.now())}000000`;
812
870
  }
813
- function k(e) {
871
+ function Zt(e) {
814
872
  if (typeof e != "object" || !e) return !1;
815
873
  let t = e;
816
874
  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;
817
875
  }
818
876
  //#endregion
819
877
  //#region src/utils/identity.ts
820
- function A(e) {
878
+ function P(e) {
821
879
  let t = new Uint8Array(e);
822
880
  if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") crypto.getRandomValues(t);
823
881
  else for (let n = 0; n < e; n++) t[n] = Math.floor(Math.random() * 256);
824
882
  return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
825
883
  }
826
- function j() {
884
+ function F() {
827
885
  try {
828
886
  if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
829
887
  } catch {}
830
- return A(16);
888
+ return P(16);
831
889
  }
832
- function Xt(e, t, n) {
890
+ function Qt(e, t, n) {
833
891
  return n.guard("storage.unavailable", `reading ${e}Storage`, () => (e === "local" ? localStorage : sessionStorage).getItem(t)) ?? null;
834
892
  }
835
- function M(e, t, n, r) {
893
+ function I(e, t, n, r) {
836
894
  r.guard("storage.unavailable", `writing ${e}Storage`, () => {
837
895
  (e === "local" ? localStorage : sessionStorage).setItem(t, n);
838
896
  });
839
897
  }
840
- function Zt(e) {
841
- let t = j(), n = Date.now(), r = j(), i = Xt("local", _, e);
842
- if (i) try {
843
- let e = JSON.parse(i);
844
- e.id && n - (e.lastSeenAt ?? 0) < 18e5 && (r = e.id);
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);
845
903
  } catch {
846
- e.report("storage.degraded", "session record was not JSON, starting a new session");
904
+ t.report("storage.degraded", "session record was not JSON, starting a new session");
847
905
  }
848
- let a = JSON.stringify({
849
- id: r,
850
- lastSeenAt: n
906
+ let o = JSON.stringify({
907
+ id: i,
908
+ lastSeenAt: r
851
909
  });
852
- M("local", _, a, e);
853
- let o = Xt("session", "ui-observability.tab", e) ?? "";
854
- return o || (o = j(), M("session", pe, o, e)), {
855
- sessionId: r,
856
- tabId: o,
857
- contextId: t
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
858
916
  };
859
917
  }
860
- var Qt = 0;
861
- function $t(e, t) {
862
- let n = Date.now();
863
- if (n - Qt < 6e4) return;
864
- Qt = n;
865
- let r = JSON.stringify({
866
- id: e,
867
- lastSeenAt: n
868
- });
869
- M("local", _, r, t);
870
- }
918
+ var en = class {
919
+ diagnostics;
920
+ lastTouchAt = 0;
921
+ constructor(e) {
922
+ this.diagnostics = e;
923
+ }
924
+ touch(e) {
925
+ let t = Date.now();
926
+ if (t - this.lastTouchAt < 6e4) return;
927
+ this.lastTouchAt = t;
928
+ let n = JSON.stringify({
929
+ id: e,
930
+ lastSeenAt: t
931
+ });
932
+ I("local", h, n, this.diagnostics);
933
+ }
934
+ };
871
935
  //#endregion
872
936
  //#region src/models/batch.ts
873
- function en(e) {
937
+ function tn(e) {
874
938
  if (typeof e != "object" || !e) return !1;
875
939
  let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
876
940
  return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
877
941
  }
878
- function tn(e) {
942
+ function nn(e) {
879
943
  if (e.records.length < 2) return null;
880
944
  let t = Math.floor(e.records.length / 2), n = (t) => ({
881
- id: j(),
945
+ id: F(),
882
946
  records: t,
883
947
  createdAt: e.createdAt,
884
948
  attempts: e.attempts
@@ -887,13 +951,13 @@ function tn(e) {
887
951
  }
888
952
  //#endregion
889
953
  //#region src/utils/lock.ts
890
- function nn(e, t, n, { skipIfBusy: r = !0 } = {}) {
954
+ function rn(e, t, n, { skipIfBusy: r = !0 } = {}) {
891
955
  let i = globalThis.navigator?.locks;
892
956
  return i?.request ? t.guardAsync("storage.degraded", `acquiring lock ${e}`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
893
957
  }
894
958
  //#endregion
895
959
  //#region src/storage/keys.ts
896
- function N(e, t) {
960
+ function L(e, t) {
897
961
  let n = [];
898
962
  return t.guard("storage.unavailable", "enumerating localStorage", () => {
899
963
  for (let t = 0; t < localStorage.length; t++) {
@@ -904,23 +968,23 @@ function N(e, t) {
904
968
  }
905
969
  //#endregion
906
970
  //#region src/storage/emergency-queue.ts
907
- function rn(e) {
971
+ function an(e) {
908
972
  let t = String(e.createdAt).padStart(14, "0");
909
- return `${g}${t}.${e.id}`;
973
+ return `${v}${t}.${e.id}`;
910
974
  }
911
- function an(e, t) {
975
+ function on(e, t) {
912
976
  let n = t.guard("storage.degraded", "an emergency entry was not JSON and was dropped", () => JSON.parse(e));
913
- return n === void 0 ? null : en(n) ? n : (t.report("storage.degraded", "an emergency entry was not a batch and was dropped"), null);
977
+ return n === void 0 ? null : tn(n) ? n : (t.report("storage.degraded", "an emergency entry was not a batch and was dropped"), null);
914
978
  }
915
- async function on(e, t) {
979
+ async function sn(e, t) {
916
980
  let n = 0;
917
- for (let r of N(g, t)) {
981
+ for (let r of L(v, t)) {
918
982
  let i = t.guard("storage.unavailable", "reading the emergency queue", () => {
919
983
  let e = localStorage.getItem(r);
920
984
  return localStorage.removeItem(r), e;
921
985
  });
922
986
  if (!i) continue;
923
- let a = an(i, t);
987
+ let a = on(i, t);
924
988
  if (a !== null) try {
925
989
  await e.save(a), n++;
926
990
  } catch (e) {
@@ -929,38 +993,41 @@ async function on(e, t) {
929
993
  }
930
994
  return n;
931
995
  }
932
- function sn(e, t) {
996
+ function cn(e, t) {
933
997
  let n = `writing the emergency queue, ${String(e.records.length)} records`;
934
998
  t.guard("storage.quota_exceeded", n, () => {
935
- let n = N(g, t);
999
+ let n = L(v, t);
936
1000
  for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
937
- localStorage.setItem(rn(e), JSON.stringify(e));
1001
+ localStorage.setItem(an(e), JSON.stringify(e));
938
1002
  });
939
1003
  }
940
- async function cn(e, t) {
941
- return await nn("ui-observability.emergency", t, () => on(e, t), { skipIfBusy: !1 }) ?? 0;
1004
+ async function ln(e, t) {
1005
+ return await rn("ui-observability.emergency", t, () => sn(e, t), { skipIfBusy: !1 }) ?? 0;
942
1006
  }
943
1007
  //#endregion
944
1008
  //#region src/storage/local-storage.ts
945
- function ln(e) {
1009
+ function un(e) {
946
1010
  let t = String(e.createdAt).padStart(14, "0");
947
- return `${gt}${t}.${e.id}`;
1011
+ return `${ht}${t}.${e.id}`;
948
1012
  }
949
- var un = class {
1013
+ var dn = class {
950
1014
  limits;
951
1015
  diagnostics;
952
1016
  onGap;
953
- name = ne;
1017
+ name = xe;
954
1018
  constructor(e, t, n) {
955
1019
  this.limits = e, this.diagnostics = t, this.onGap = n;
956
1020
  }
957
1021
  async save(e) {
958
- if (this.diagnostics.guard("storage.quota_exceeded", "localStorage refused a batch, evicting the oldest", () => (localStorage.setItem(ln(e), JSON.stringify(e)), !0)) !== !0) {
959
- let e = this.keys();
960
- this.evict(e.slice(0, Math.ceil(e.length / 4)));
1022
+ if (this.write(e, "localStorage refused a batch, evicting the oldest")) {
1023
+ await this.prune();
961
1024
  return;
962
1025
  }
963
- await this.prune();
1026
+ this.evictForQuota(), this.write(e, "localStorage refused a batch even after evicting") || this.reportGap({
1027
+ batches: 1,
1028
+ records: e.records.length,
1029
+ reason: "quota"
1030
+ });
964
1031
  }
965
1032
  take(e) {
966
1033
  let t = [];
@@ -1014,7 +1081,7 @@ var un = class {
1014
1081
  t.reason = "over_capacity";
1015
1082
  for (let e of r.slice(0, i)) n(e.key, e.records);
1016
1083
  }
1017
- return t.batches > 0 && (this.diagnostics.report("storage.evicted", `dropped ${String(t.batches)} stored batches (${String(t.records)} records)`, { ...t }), this.onGap?.(t)), Promise.resolve(t);
1084
+ return this.reportGap(t), Promise.resolve(t);
1018
1085
  }
1019
1086
  count() {
1020
1087
  return Promise.resolve(this.keys().length);
@@ -1025,11 +1092,29 @@ var un = class {
1025
1092
  close() {
1026
1093
  return Promise.resolve();
1027
1094
  }
1095
+ write(e, t) {
1096
+ return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(un(e), JSON.stringify(e)), !0)) === !0;
1097
+ }
1098
+ evictForQuota() {
1099
+ let e = this.keys(), t = {
1100
+ batches: 0,
1101
+ records: 0,
1102
+ reason: "quota"
1103
+ };
1104
+ for (let n of e.slice(0, Math.ceil(e.length / 4))) {
1105
+ let e = this.read(n);
1106
+ this.removeKey(n), t.batches++, t.records += e?.records.length ?? 0;
1107
+ }
1108
+ this.reportGap(t);
1109
+ }
1110
+ reportGap(e) {
1111
+ e.batches !== 0 && (this.diagnostics.report("storage.evicted", `dropped ${String(e.batches)} stored batches (${String(e.records)} records)`, { ...e }), this.onGap?.(e));
1112
+ }
1028
1113
  read(e) {
1029
1114
  let t = this.diagnostics.guard("storage.unavailable", "reading a stored batch", () => localStorage.getItem(e));
1030
1115
  if (!t) return null;
1031
1116
  let n = this.diagnostics.guard("storage.degraded", "a stored batch was corrupt and was removed", () => JSON.parse(t));
1032
- return n === void 0 ? null : en(n) ? n : (this.diagnostics.report("storage.degraded", "a stored entry was not a batch and was dropped"), null);
1117
+ return n === void 0 ? null : tn(n) ? n : (this.diagnostics.report("storage.degraded", "a stored entry was not a batch and was dropped"), null);
1033
1118
  }
1034
1119
  keyOf(e) {
1035
1120
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -1043,18 +1128,18 @@ var un = class {
1043
1128
  });
1044
1129
  }
1045
1130
  keys() {
1046
- return N(gt, this.diagnostics);
1131
+ return L(ht, this.diagnostics);
1047
1132
  }
1048
1133
  };
1049
1134
  //#endregion
1050
1135
  //#region src/storage/memory-storage.ts
1051
- function P(e) {
1136
+ function fn(e) {
1052
1137
  return e.reduce((e, t) => e + t.records.length, 0);
1053
1138
  }
1054
- var F = class {
1139
+ var R = class {
1055
1140
  limits;
1056
1141
  onGap;
1057
- name = we;
1142
+ name = ye;
1058
1143
  batches = [];
1059
1144
  constructor(e, t) {
1060
1145
  this.limits = e, this.onGap = t;
@@ -1078,12 +1163,12 @@ var F = class {
1078
1163
  records: 0,
1079
1164
  reason: "expired"
1080
1165
  }, n = this.batches.filter((t) => t.createdAt < e);
1081
- this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += P(n);
1166
+ this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += fn(n);
1082
1167
  let r = this.batches.length - this.limits.maxBatches;
1083
1168
  if (r > 0) {
1084
1169
  t.reason = "over_capacity";
1085
1170
  let e = this.batches.slice(0, r);
1086
- this.batches = this.batches.slice(r), t.batches += e.length, t.records += P(e);
1171
+ this.batches = this.batches.slice(r), t.batches += e.length, t.records += fn(e);
1087
1172
  }
1088
1173
  return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
1089
1174
  }
@@ -1096,8 +1181,8 @@ var F = class {
1096
1181
  close() {
1097
1182
  return this.batches = [], Promise.resolve();
1098
1183
  }
1099
- }, dn = {
1100
- name: Ce,
1184
+ }, pn = {
1185
+ name: Se,
1101
1186
  save: () => Promise.resolve(),
1102
1187
  take: () => Promise.resolve([]),
1103
1188
  remove: () => Promise.resolve(),
@@ -1111,112 +1196,116 @@ var F = class {
1111
1196
  clear: () => Promise.resolve(),
1112
1197
  close: () => Promise.resolve()
1113
1198
  };
1114
- function fn(e) {
1199
+ function mn(e) {
1115
1200
  return e.guard("storage.unavailable", "reading indexedDB", () => globalThis.indexedDB != null) === !0;
1116
1201
  }
1117
- function pn(e) {
1118
- return e.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(Te, "1"), localStorage.removeItem(Te), !0)) === !0;
1202
+ function hn(e) {
1203
+ return e.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(de, "1"), localStorage.removeItem(de), !0)) === !0;
1119
1204
  }
1120
- async function mn(e, t, n, r, i) {
1121
- if (e === "none") return dn;
1122
- if (e === "memory") return new F(n, i);
1205
+ async function gn(e, t, n, r, i) {
1206
+ if (e === "none") return pn;
1207
+ if (e === "memory") return new R(n, i);
1123
1208
  if (e === "indexeddb" || e === "auto") {
1124
- if (fn(r)) {
1209
+ if (mn(r)) {
1125
1210
  let e = await r.guardAsync("storage.unavailable", "opening IndexedDB", async () => {
1126
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-DAoHV_oL.js");
1211
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-CSaDuHGk.js");
1127
1212
  return new e(t, n, r, i);
1128
1213
  });
1129
1214
  if (e) return e;
1130
1215
  }
1131
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new F(n, i);
1216
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new R(n, i);
1132
1217
  }
1133
- return pn(r) ? new un(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new F(n, i));
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));
1134
1219
  }
1135
1220
  //#endregion
1136
1221
  //#region src/utils/sanitize.ts
1137
- function I(e, t) {
1222
+ function z(e, t) {
1138
1223
  if (e.length <= t) return e;
1139
- let n = hn(e.charCodeAt(t - 1)) ? t - 1 : t;
1224
+ let n = _n(e.charCodeAt(t - 1)) ? t - 1 : t;
1140
1225
  return `${e.slice(0, n)}… [truncated ${String(e.length - n)} chars]`;
1141
1226
  }
1142
- function hn(e) {
1227
+ function _n(e) {
1143
1228
  return e >= 55296 && e <= 56319;
1144
1229
  }
1145
- function gn(e) {
1230
+ function vn(e) {
1146
1231
  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(".")}` : ""}]`;
1147
1232
  }
1148
- function L(e, t) {
1149
- let n = { bytes: 0 };
1233
+ function B(e, t) {
1234
+ let n = {
1235
+ bytes: 0,
1236
+ nodes: 0
1237
+ };
1150
1238
  return {
1151
- value: z(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1239
+ value: H(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
1152
1240
  bytes: n.bytes
1153
1241
  };
1154
1242
  }
1155
- function R(e, t) {
1156
- return t.bytes += B(e) + 2, e;
1243
+ function V(e, t) {
1244
+ return t.bytes += U(e) + 2, e;
1157
1245
  }
1158
- function z(e, t, n, r, i) {
1246
+ function H(e, t, n, r, i) {
1247
+ if (i.nodes++, i.nodes > t.maxNodes) return V("[MaxNodes]", i);
1159
1248
  if (e == null) return i.bytes += 4, e;
1160
- if (typeof e == "string") return R(I(e, t.maxAttributeChars), i);
1249
+ if (typeof e == "string") return V(z(e, t.maxAttributeChars), i);
1161
1250
  if (typeof e == "number") return i.bytes += 8, Number.isFinite(e) ? e : String(e);
1162
1251
  if (typeof e == "boolean") return i.bytes += 5, e;
1163
- if (typeof e == "bigint") return R(`${e.toString()}n`, i);
1164
- if (typeof e == "symbol") return R(e.toString(), i);
1165
- if (typeof e == "function") return R(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
1166
- if (r >= t.maxDepth) return R("[MaxDepth]", i);
1167
- if (n.has(e)) return R("[Circular]", i);
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);
1168
1257
  n.add(e), i.bytes += 2;
1169
1258
  try {
1170
1259
  if (e instanceof Error) return {
1171
- name: R(e.name, i),
1172
- message: R(I(e.message, t.maxAttributeChars), i),
1173
- stack: e.stack ? R(I(e.stack, t.maxStackChars), i) : void 0,
1174
- cause: e.cause ? z(e.cause, t, n, r + 1, i) : void 0
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
1175
1264
  };
1176
- if (e instanceof Date) return R(e.toISOString(), i);
1177
- if (e instanceof RegExp) return R(e.toString(), i);
1265
+ if (e instanceof Date) return V(e.toISOString(), i);
1266
+ if (e instanceof RegExp) return V(e.toString(), i);
1178
1267
  if (e instanceof Map) {
1179
1268
  let a = e, o = {}, s = 0;
1180
1269
  for (let [e, c] of a) {
1181
1270
  if (s >= t.maxArrayLength) {
1182
- o["…"] = R(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1271
+ o["…"] = V(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
1183
1272
  break;
1184
1273
  }
1185
1274
  s++;
1186
1275
  let l = String(e);
1187
- i.bytes += B(l) + 4, o[l] = z(c, t, n, r + 1, i);
1276
+ i.bytes += U(l) + 4, o[l] = H(c, t, n, r + 1, i);
1188
1277
  }
1189
1278
  return o;
1190
1279
  }
1191
- if (e instanceof Set) return z([...e].slice(0, t.maxArrayLength), t, n, r, i);
1280
+ if (e instanceof Set) return H([...e].slice(0, t.maxArrayLength), t, n, r, i);
1192
1281
  if (ArrayBuffer.isView(e)) {
1193
1282
  let t = e.length ?? 0;
1194
- return R(`[${e.constructor.name}(${String(t)})]`, i);
1283
+ return V(`[${e.constructor.name}(${String(t)})]`, i);
1195
1284
  }
1196
- if (e instanceof Promise) return R("[Promise]", i);
1197
- if (typeof Node < "u" && e instanceof Node) return R(gn(e), i);
1285
+ if (e instanceof Promise) return V("[Promise]", i);
1286
+ if (typeof Node < "u" && e instanceof Node) return V(vn(e), i);
1198
1287
  if (Array.isArray(e)) {
1199
- let a = e, o = a.slice(0, t.maxArrayLength).map((e) => z(e, t, n, r + 1, i));
1200
- return a.length > t.maxArrayLength && o.push(R(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
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;
1201
1290
  }
1202
1291
  let a = e.toJSON;
1203
- if (typeof a == "function") return z(a.call(e), t, n, r + 1, i);
1292
+ if (typeof a == "function") return H(a.call(e), t, n, r + 1, i);
1204
1293
  let o = e, s = Object.keys(o), c = {}, l = 0;
1205
1294
  for (let e of s) {
1206
1295
  if (l >= t.maxAttributeCount) {
1207
- c["…"] = R(`[${String(s.length - l)} more keys]`, i);
1296
+ c["…"] = V(`[${String(s.length - l)} more keys]`, i);
1208
1297
  break;
1209
1298
  }
1210
- l++, i.bytes += B(e) + 4, c[e] = z(o[e], t, n, r + 1, i);
1299
+ l++, i.bytes += U(e) + 4, c[e] = H(o[e], t, n, r + 1, i);
1211
1300
  }
1212
1301
  return c;
1213
1302
  } catch (e) {
1214
- return R(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1303
+ return V(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
1215
1304
  } finally {
1216
1305
  n.delete(e);
1217
1306
  }
1218
1307
  }
1219
- function B(e) {
1308
+ function U(e) {
1220
1309
  let t = 0;
1221
1310
  for (let n = 0; n < e.length; n++) {
1222
1311
  let r = e.charCodeAt(n);
@@ -1226,7 +1315,7 @@ function B(e) {
1226
1315
  }
1227
1316
  //#endregion
1228
1317
  //#region src/transport/exit-flush.ts
1229
- var _n = class {
1318
+ var yn = class {
1230
1319
  deps;
1231
1320
  installed = !1;
1232
1321
  onVisibility = () => {
@@ -1263,15 +1352,15 @@ var _n = class {
1263
1352
  flush(e) {
1264
1353
  let { diagnostics: t } = this.deps, n = this.endpointUrl();
1265
1354
  if (n === null) return;
1266
- let r = this.deps.drainPending();
1355
+ let r = this.deps.drainForExit();
1267
1356
  if (!r || r.records.length === 0) return;
1268
1357
  let i = t.guard("transport.serialize_failed", `the ${e} exit flush could not serialize its batch`, () => this.deps.config.serializer.serialize(r.records));
1269
1358
  if (!i) return;
1270
- if (B(i.body) > 6e4) {
1271
- sn(r, t);
1359
+ if (U(i.body) > 6e4) {
1360
+ cn(r, t);
1272
1361
  return;
1273
1362
  }
1274
- n.searchParams.set(Ve, r.id), n.searchParams.set(De, e);
1363
+ n.searchParams.set(we, r.id), n.searchParams.set(gt, e);
1275
1364
  let a = n.toString();
1276
1365
  this.beacon(a, i.body) || this.keepaliveFetch(a, i.body, e);
1277
1366
  }
@@ -1279,19 +1368,19 @@ var _n = class {
1279
1368
  let { endpoint: e } = this.deps.config;
1280
1369
  return e ? this.deps.diagnostics.guard("config.invalid", `the exit flush cannot use endpoint ${e}`, () => new URL(e)) ?? null : null;
1281
1370
  }
1282
- beacon(e, t) {
1371
+ beacon(e, n) {
1283
1372
  return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
1284
1373
  let r = globalThis.navigator;
1285
- return r?.sendBeacon ? r.sendBeacon(e, new Blob([t], { type: n })) : !1;
1374
+ return r?.sendBeacon ? r.sendBeacon(e, new Blob([n], { type: t })) : !1;
1286
1375
  }) === !0;
1287
1376
  }
1288
- keepaliveFetch(e, t, r) {
1377
+ keepaliveFetch(e, n, r) {
1289
1378
  let { config: i, diagnostics: a } = this.deps;
1290
1379
  a.guard("transport.http_error", "the keepalive fetch fallback", () => {
1291
1380
  fetch(e, {
1292
1381
  method: "POST",
1293
- body: t,
1294
- headers: { [st]: n },
1382
+ body: n,
1383
+ headers: { [ee]: t },
1295
1384
  credentials: i.credentials,
1296
1385
  keepalive: !0
1297
1386
  }).catch((e) => {
@@ -1302,15 +1391,15 @@ var _n = class {
1302
1391
  };
1303
1392
  //#endregion
1304
1393
  //#region src/transport/compression.ts
1305
- async function vn(e) {
1394
+ async function bn(e) {
1306
1395
  let t = globalThis.CompressionStream;
1307
1396
  if (t === void 0) return null;
1308
- let n = new Blob([e]).stream().pipeThrough(new t(me)), r = await new Response(n).arrayBuffer();
1397
+ let n = new Blob([e]).stream().pipeThrough(new t(bt)), r = await new Response(n).arrayBuffer();
1309
1398
  return new Uint8Array(r);
1310
1399
  }
1311
1400
  //#endregion
1312
1401
  //#region src/transport/errors.ts
1313
- var V = class extends Error {
1402
+ var W = class extends Error {
1314
1403
  kind;
1315
1404
  status;
1316
1405
  retryAfterMs;
@@ -1319,16 +1408,16 @@ var V = class extends Error {
1319
1408
  super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
1320
1409
  }
1321
1410
  };
1322
- function yn(e) {
1411
+ function xn(e) {
1323
1412
  if (!e) return;
1324
1413
  let t = Number(e);
1325
- if (Number.isFinite(t)) return Math.max(0, t * Ze);
1414
+ if (Number.isFinite(t)) return Math.max(0, t * mt);
1326
1415
  let n = Date.parse(e);
1327
1416
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
1328
1417
  }
1329
1418
  //#endregion
1330
1419
  //#region src/transport/http-transport.ts
1331
- var bn = class {
1420
+ var Sn = class {
1332
1421
  config;
1333
1422
  diagnostics;
1334
1423
  throttledUntil = 0;
@@ -1350,9 +1439,9 @@ var bn = class {
1350
1439
  return;
1351
1440
  }
1352
1441
  let r = new Headers(await this.resolveHeaders());
1353
- r.set(st, n.contentType), r.set(p, e.id), r.set(xe, String(e.attempts));
1442
+ r.set(ee, n.contentType), r.set(te, e.id), r.set(f, String(e.attempts));
1354
1443
  let i = await this.encodeBody(n.body);
1355
- typeof i != "string" && r.set(re, me);
1444
+ typeof i != "string" && r.set(nt, bt);
1356
1445
  let a = await this.dispatch(r, i);
1357
1446
  if (a.ok) {
1358
1447
  this.throttledUntil = 0;
@@ -1362,13 +1451,13 @@ var bn = class {
1362
1451
  }
1363
1452
  async encodeBody(e) {
1364
1453
  let { config: t } = this;
1365
- return t.compression !== "gzip" || B(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => vn(e)) ?? e;
1454
+ return t.compression !== "gzip" || U(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "gzipping the payload", () => bn(e)) ?? e;
1366
1455
  }
1367
1456
  async dispatch(e, t) {
1368
1457
  let { config: n } = this, r = new AbortController(), i = setTimeout(() => {
1369
1458
  r.abort();
1370
- }, Me);
1371
- C(i);
1459
+ }, yt);
1460
+ E(i);
1372
1461
  try {
1373
1462
  return await fetch(n.endpoint, {
1374
1463
  method: "POST",
@@ -1379,28 +1468,28 @@ var bn = class {
1379
1468
  cache: "no-store"
1380
1469
  });
1381
1470
  } catch {
1382
- if (r.signal.aborted) throw new V("timeout", `request exceeded ${String(Me)}ms`);
1471
+ if (r.signal.aborted) throw new W("timeout", `request exceeded ${String(yt)}ms`);
1383
1472
  let e = globalThis.navigator?.onLine;
1384
- throw new V(e === !1 ? "offline" : "transient", "network error");
1473
+ throw new W(e === !1 ? "offline" : "transient", "network error");
1385
1474
  } finally {
1386
1475
  clearTimeout(i);
1387
1476
  }
1388
1477
  }
1389
1478
  async classify(e, t) {
1390
- let n = e.status, r = yn(e.headers.get(te));
1479
+ let n = e.status, r = xn(e.headers.get(be));
1391
1480
  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.`, {
1392
1481
  status: n,
1393
1482
  endpoint: this.config.endpoint
1394
- }), new V("permanent", `rejected with ${String(n)}`, n);
1395
- if (n === 413) return new V("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
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));
1396
1485
  if (n === 429 || n === 503) {
1397
1486
  let e = n === 429;
1398
- return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new V("throttled", e ? "throttled" : "service unavailable", n, r);
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);
1399
1488
  }
1400
- 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`, {
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`, {
1401
1490
  batchId: t,
1402
1491
  status: n
1403
- }), new V("permanent", `rejected with ${String(n)}`, n));
1492
+ }), new W("permanent", `rejected with ${String(n)}`, n));
1404
1493
  }
1405
1494
  async readMaxBytes(e) {
1406
1495
  return this.diagnostics.guardAsync("transport.http_error", "reading the 413 body", async () => {
@@ -1412,7 +1501,7 @@ var bn = class {
1412
1501
  let { headers: e } = this.config;
1413
1502
  return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "headers() threw", () => Promise.resolve(e())) ?? {} : e : {};
1414
1503
  }
1415
- }, xn = class {
1504
+ }, Cn = class {
1416
1505
  storage;
1417
1506
  transport;
1418
1507
  diagnostics;
@@ -1429,10 +1518,10 @@ var bn = class {
1429
1518
  this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
1430
1519
  }
1431
1520
  start() {
1432
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(f);
1521
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(_);
1433
1522
  }
1434
1523
  nudge() {
1435
- this.draining || this.schedule(fe);
1524
+ this.draining || this.schedule(d);
1436
1525
  }
1437
1526
  stop() {
1438
1527
  this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
@@ -1443,20 +1532,20 @@ var bn = class {
1443
1532
  let t = setTimeout(() => {
1444
1533
  this.drain();
1445
1534
  }, e);
1446
- this.timer = t, C(t);
1535
+ this.timer = t, E(t);
1447
1536
  }
1448
1537
  clearTimer() {
1449
1538
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1450
1539
  }
1451
1540
  backoffMs() {
1452
- let e = Math.min(fe * 2 ** this.attempt, ee);
1541
+ let e = Math.min(d * 2 ** this.attempt, re);
1453
1542
  return Math.random() * e;
1454
1543
  }
1455
1544
  async drain() {
1456
1545
  if (!this.draining) {
1457
1546
  this.draining = !0;
1458
1547
  try {
1459
- await nn("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(f);
1548
+ await rn("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(_);
1460
1549
  } finally {
1461
1550
  this.draining = !1;
1462
1551
  }
@@ -1464,29 +1553,29 @@ var bn = class {
1464
1553
  }
1465
1554
  async drainLocked() {
1466
1555
  try {
1467
- if (globalThis.navigator?.onLine === !1) return this.schedule(f), !0;
1556
+ if (globalThis.navigator?.onLine === !1) return this.schedule(_), !0;
1468
1557
  let e = await this.storage.take(this.batchesPerDrain);
1469
- if (e.length === 0) return this.schedule(f), !0;
1558
+ if (e.length === 0) return this.schedule(_), !0;
1470
1559
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
1471
- return this.schedule(e.length === this.batchesPerDrain ? 0 : f), !0;
1560
+ return this.schedule(e.length === this.batchesPerDrain ? 0 : _), !0;
1472
1561
  } catch (e) {
1473
1562
  return this.diagnostics.report("storage.degraded", "the drain loop threw", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
1474
1563
  }
1475
1564
  }
1476
1565
  async deliver(e) {
1477
- if (e.attempts >= m.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1566
+ if (e.attempts >= ne.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `giving up on a batch after ${e.attempts.toString()} attempts`, {
1478
1567
  batchId: e.id,
1479
1568
  records: e.records.length
1480
1569
  }), await this.storage.remove(e.id), !0;
1481
1570
  try {
1482
1571
  return await this.transport.send(e), await this.storage.remove(e.id), this.attempt = 0, !0;
1483
1572
  } catch (t) {
1484
- let n = t instanceof V ? t : void 0;
1485
- 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);
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);
1486
1575
  }
1487
1576
  }
1488
1577
  async splitStored(e, t) {
1489
- let n = tn(e);
1578
+ let n = nn(e);
1490
1579
  if (await this.storage.remove(e.id), !n) {
1491
1580
  this.diagnostics.report("transport.dropped_permanent", "a single record exceeds the server limit and was dropped", {
1492
1581
  batchId: e.id,
@@ -1501,71 +1590,34 @@ var bn = class {
1501
1590
  });
1502
1591
  for (let e of n) await this.storage.save(e);
1503
1592
  }
1504
- }, Sn = {
1593
+ }, wn = {
1505
1594
  TRACE: "debug",
1506
1595
  DEBUG: "debug",
1507
1596
  INFO: "info",
1508
1597
  WARN: "warn",
1509
1598
  ERROR: "error",
1510
1599
  FATAL: "error"
1511
- }, Cn = class {
1600
+ }, Tn = class {
1512
1601
  minLevel;
1513
- constructor(e) {
1514
- this.minLevel = e;
1602
+ diagnostics;
1603
+ constructor(e, t) {
1604
+ this.minLevel = e, this.diagnostics = t;
1515
1605
  }
1516
1606
  update(e) {
1517
1607
  this.minLevel = e;
1518
1608
  }
1519
1609
  write(e, t, n) {
1520
- if (this.minLevel === null || b[e] < b[this.minLevel] || typeof console > "u") return;
1521
- let r = `%c${Ke}%c ${e}`;
1522
- if (n === void 0) {
1523
- console[Sn[e]](r, s, "", t);
1524
- return;
1525
- }
1526
- console[Sn[e]](r, s, "", t, n);
1527
- }
1528
- }, H = null;
1529
- function U(e, t) {
1530
- let n = e[t];
1531
- return n !== void 0 && e instanceof n;
1532
- }
1533
- function wn(e) {
1534
- if (H) return H;
1535
- let t = globalThis, n = t.navigator?.userAgent ?? "", r = "browser", i, a, o = !1, s = t.fin?.me;
1536
- 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 || Tn(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Ue.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
1537
- let e = s.identity;
1538
- i = e?.uuid, a = e?.name;
1539
- })), H = {
1540
- platform: r,
1541
- openfinUuid: i,
1542
- openfinName: a,
1543
- userAgent: n,
1544
- isWorker: o,
1545
- isTopLevelDocument: En()
1546
- }, H;
1547
- }
1548
- function Tn(t) {
1549
- return ft.test(t) ? !0 : (e.test(t) || dt.test(t) && ht.test(t)) && t.includes("AppleWebKit") && !t.includes("Safari/");
1550
- }
1551
- function En() {
1552
- if (typeof window > "u") return !1;
1553
- try {
1554
- return window.self === window.top;
1555
- } catch {
1556
- return !1;
1557
- }
1558
- }
1559
- function Dn() {
1560
- try {
1561
- return typeof location < "u" ? location.href : "";
1562
- } catch {
1563
- return "";
1610
+ if (this.minLevel === null || x[e] < x[this.minLevel] || typeof console > "u") return;
1611
+ let r = `%c${Ee}%c ${e}`, i = wn[e];
1612
+ this.diagnostics.guard("handler.threw", `mirroring to console.${i}`, () => {
1613
+ if (n === void 0) {
1614
+ console[i](r, o, "", t);
1615
+ return;
1616
+ }
1617
+ console[i](r, o, "", t, n);
1618
+ });
1564
1619
  }
1565
- }
1566
- //#endregion
1567
- //#region src/utils/sequence.ts
1568
- var On = class {
1620
+ }, En = class {
1569
1621
  value = 0;
1570
1622
  next() {
1571
1623
  return ++this.value;
@@ -1573,64 +1625,84 @@ var On = class {
1573
1625
  reset() {
1574
1626
  this.value = 0;
1575
1627
  }
1576
- };
1577
- //#endregion
1578
- //#region src/utils/tracing.ts
1579
- function kn() {
1580
- return A(16);
1581
- }
1628
+ }, Dn = /^[0-9a-f]{32}$/, On = /^[0-9a-f]{16}$/, kn = /[1-9a-f]/;
1582
1629
  function An() {
1583
- return A(8);
1630
+ return import(
1631
+ /* @vite-ignore */
1632
+ "@opentelemetry/api"
1633
+ );
1634
+ }
1635
+ function jn(e) {
1636
+ return Dn.test(e.traceId) && kn.test(e.traceId) && On.test(e.spanId) && kn.test(e.spanId);
1584
1637
  }
1585
- function jn() {
1638
+ function Mn() {
1639
+ return P(16);
1640
+ }
1641
+ function Nn() {
1642
+ return P(8);
1643
+ }
1644
+ function Pn() {
1586
1645
  return {
1587
- traceId: kn(),
1588
- spanId: An(),
1646
+ traceId: Mn(),
1647
+ spanId: Nn(),
1589
1648
  traceFlags: 1,
1590
1649
  startedAt: Date.now()
1591
1650
  };
1592
1651
  }
1593
- function Mn(e) {
1652
+ function Fn(e) {
1594
1653
  return {
1595
1654
  traceId: e.traceId,
1596
1655
  spanId: e.spanId,
1597
1656
  traceFlags: e.traceFlags
1598
1657
  };
1599
1658
  }
1600
- var Nn = class {
1659
+ var In = class {
1601
1660
  diagnostics;
1602
1661
  maxAgeMs;
1603
- ambient = jn();
1604
- constructor(e, t = lt) {
1605
- this.diagnostics = e, this.maxAgeMs = t;
1662
+ load;
1663
+ ambient = Pn();
1664
+ otel;
1665
+ constructor(e, t = He, n = An) {
1666
+ this.diagnostics = e, this.maxAgeMs = t, this.load = n;
1667
+ }
1668
+ async loadOtel() {
1669
+ try {
1670
+ this.otel = await this.load();
1671
+ } catch (e) {
1672
+ this.diagnostics.report("trace.otel_failed", "@opentelemetry/api is not available, so records carry this library's own trace ids", void 0, e);
1673
+ }
1606
1674
  }
1607
1675
  resolve() {
1608
- let e = this.diagnostics.guard("trace.otel_failed", "reading the active OpenTelemetry span", () => {
1609
- let e = Tt.getActiveSpan();
1610
- if (e === void 0) return;
1611
- let t = e.spanContext();
1612
- if (Ct(t)) return {
1613
- traceId: t.traceId,
1614
- spanId: t.spanId,
1615
- traceFlags: t.traceFlags
1676
+ let e = this.activeSpanContext();
1677
+ return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), Fn(this.ambient)) : e;
1678
+ }
1679
+ activeSpanContext() {
1680
+ let e = this.otel;
1681
+ if (e) return this.diagnostics.guard("trace.otel_failed", "reading the active OpenTelemetry span", () => {
1682
+ let t = e.trace.getActiveSpan();
1683
+ if (t === void 0) return;
1684
+ let n = t.spanContext();
1685
+ if (jn(n)) return {
1686
+ traceId: n.traceId,
1687
+ spanId: n.spanId,
1688
+ traceFlags: n.traceFlags
1616
1689
  };
1617
1690
  });
1618
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), Mn(this.ambient)) : e;
1619
1691
  }
1620
1692
  rotate(e) {
1621
- return this.ambient = jn(), Mn(this.ambient);
1693
+ return this.ambient = Pn(), Fn(this.ambient);
1622
1694
  }
1623
1695
  headers() {
1624
- let e = {};
1625
- if (this.diagnostics.guard("trace.otel_failed", "injecting OpenTelemetry headers", () => {
1626
- wt.inject(St.active(), e);
1696
+ let e = {}, t = this.otel;
1697
+ if (t && this.diagnostics.guard("trace.otel_failed", "injecting OpenTelemetry headers", () => {
1698
+ t.propagation.inject(t.context.active(), e);
1627
1699
  }), !e.traceparent) {
1628
1700
  let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
1629
- e[et] = `00-${t.traceId}-${t.spanId}-${n}`;
1701
+ e[at] = `00-${t.traceId}-${t.spanId}-${n}`;
1630
1702
  }
1631
1703
  return e;
1632
1704
  }
1633
- }, Pn = class {
1705
+ }, Ln = class {
1634
1706
  buffer;
1635
1707
  pointer = 0;
1636
1708
  filled = !1;
@@ -1650,47 +1722,79 @@ var Nn = class {
1650
1722
  };
1651
1723
  //#endregion
1652
1724
  //#region src/transport/serializers/ecs.ts
1653
- function Fn(e) {
1654
- return Ie.test(e) ? Number(BigInt(e) / ze) : Date.now();
1725
+ function Rn(e) {
1726
+ return Ie.test(e) ? Number(BigInt(e) / tt) : Date.now();
1727
+ }
1728
+ function zn(e) {
1729
+ return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
1730
+ }
1731
+ function Bn(e, t, n) {
1732
+ let r = e[t];
1733
+ if (r === void 0) {
1734
+ e[t] = n;
1735
+ return;
1736
+ }
1737
+ if (Array.isArray(r)) {
1738
+ r.push(n);
1739
+ return;
1740
+ }
1741
+ e[t] = [r, n];
1742
+ }
1743
+ function G(e, t, n, r) {
1744
+ let i = zn(n);
1745
+ if (i !== null) {
1746
+ Bn(e, t, i);
1747
+ return;
1748
+ }
1749
+ 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);
1752
+ r.delete(n);
1753
+ }
1754
+ }
1755
+ function Vn(e) {
1756
+ let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
1757
+ for (let [r, i] of Object.entries(e)) G(t, r, i, n);
1758
+ return t;
1655
1759
  }
1656
- var In = {
1760
+ var Hn = {
1657
1761
  name: "ecs",
1658
1762
  serialize(e) {
1659
1763
  return {
1660
1764
  body: `${e.map((e) => {
1661
- let t = Fn(e.timeUnixNano);
1765
+ let t = Rn(e.timeUnixNano);
1662
1766
  return JSON.stringify({
1663
1767
  "@timestamp": new Date(t).toISOString(),
1664
1768
  message: e.body,
1665
- log: { level: e.severityText.toLowerCase() },
1769
+ log: { level: g[e.severityText] ?? e.severityText.toLowerCase() },
1666
1770
  trace: { id: e.traceId },
1667
1771
  span: { id: e.spanId },
1668
1772
  service: {
1669
- name: e.resource[c],
1670
- version: e.resource[de],
1671
- environment: e.resource[o]
1773
+ name: e.resource[le],
1774
+ version: e.resource[Ke],
1775
+ environment: e.resource[_t]
1672
1776
  },
1673
- user_agent: { original: e.resource[yt] },
1777
+ user_agent: { original: e.resource[me] },
1674
1778
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
1675
1779
  labels: {
1676
- ...e.resource,
1677
- ...e.attributes
1780
+ ...Vn(e.resource),
1781
+ ...Vn(e.attributes)
1678
1782
  }
1679
1783
  });
1680
1784
  }).join("\n")}\n`,
1681
- contentType: Ye
1785
+ contentType: Ge
1682
1786
  };
1683
1787
  }
1684
1788
  };
1685
1789
  //#endregion
1686
1790
  //#region src/transport/serializers/otlp.ts
1687
- function Ln(e) {
1688
- 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(Ln).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: W(e) } } : null;
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;
1689
1793
  }
1690
- function W(e) {
1794
+ function K(e) {
1691
1795
  let t = [];
1692
1796
  for (let [n, r] of Object.entries(e)) {
1693
- let e = Ln(r);
1797
+ let e = Un(r);
1694
1798
  e && t.push({
1695
1799
  key: n,
1696
1800
  value: e
@@ -1698,19 +1802,19 @@ function W(e) {
1698
1802
  }
1699
1803
  return t;
1700
1804
  }
1701
- var Rn = /* @__PURE__ */ new WeakMap();
1702
- function zn(e) {
1703
- let t = Rn.get(e);
1805
+ var Wn = /* @__PURE__ */ new WeakMap();
1806
+ function Gn(e) {
1807
+ let t = Wn.get(e);
1704
1808
  if (t !== void 0) return t;
1705
1809
  let n = JSON.stringify(e);
1706
- return Rn.set(e, n), n;
1810
+ return Wn.set(e, n), n;
1707
1811
  }
1708
- var G = {
1709
- name: xt,
1812
+ var q = {
1813
+ name: r,
1710
1814
  serialize(e) {
1711
1815
  let t = /* @__PURE__ */ new Map();
1712
1816
  for (let n of e) {
1713
- let e = zn(n.resource), r = t.get(e);
1817
+ let e = Gn(n.resource), r = t.get(e);
1714
1818
  if (r) {
1715
1819
  r.records.push(n);
1716
1820
  continue;
@@ -1721,11 +1825,11 @@ var G = {
1721
1825
  });
1722
1826
  }
1723
1827
  let n = [...t.values()].map((e) => ({
1724
- resource: { attributes: W(e.resource) },
1828
+ resource: { attributes: K(e.resource) },
1725
1829
  scopeLogs: [{
1726
1830
  scope: {
1727
- name: Le,
1728
- version: pt
1831
+ name: dt,
1832
+ version: Xe
1729
1833
  },
1730
1834
  logRecords: e.records.map((e) => ({
1731
1835
  timeUnixNano: e.timeUnixNano,
@@ -1736,33 +1840,33 @@ var G = {
1736
1840
  traceId: e.traceId,
1737
1841
  spanId: e.spanId,
1738
1842
  flags: e.traceFlags,
1739
- attributes: W(e.attributes)
1843
+ attributes: K(e.attributes)
1740
1844
  }))
1741
1845
  }]
1742
1846
  }));
1743
1847
  return {
1744
1848
  body: JSON.stringify({ resourceLogs: n }),
1745
- contentType: ue
1849
+ contentType: ce
1746
1850
  };
1747
1851
  }
1748
1852
  };
1749
1853
  //#endregion
1750
1854
  //#region src/core/config.ts
1751
- function Bn(e) {
1855
+ function Kn(e) {
1752
1856
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
1753
1857
  }
1754
- function Vn(e, t, n) {
1755
- return e === void 0 ? t ?? G : e === "otlp" ? G : e === "ecs" ? In : Bn(e) ? e : (n.report("config.invalid", `serializer must be "${xt}", "ecs" or an implementation`), G);
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);
1756
1860
  }
1757
- function Hn(e, t) {
1758
- return e === void 0 ? t : e === !1 ? null : e === !0 ? l : e;
1861
+ function Jn(e, t) {
1862
+ return e === void 0 ? t : e === !1 ? null : e === !0 ? c : e;
1759
1863
  }
1760
- function Un(e, t, n) {
1761
- let r = n ?? qe, i = {
1864
+ function Yn(e, t, n) {
1865
+ let r = n ?? Ue, i = {
1762
1866
  ...r,
1763
1867
  ...e,
1764
- serializer: Vn(e.serializer, n?.serializer, t),
1765
- console: Hn(e.console, r.console),
1868
+ serializer: qn(e.serializer, n?.serializer, t),
1869
+ console: Jn(e.console, r.console),
1766
1870
  sampling: {
1767
1871
  ...r.sampling,
1768
1872
  ...e.sampling,
@@ -1786,23 +1890,30 @@ function Un(e, t, n) {
1786
1890
  } catch (e) {
1787
1891
  t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}`, void 0, e);
1788
1892
  }
1789
- i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${rt}'.`), rt);
1893
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record will report service.name as '${Ae}'.`), Ae);
1790
1894
  let a = i.sampling.defaultRate;
1791
1895
  (typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1, got ${String(a)}`), i.sampling.defaultRate = 1);
1792
1896
  let o = Object.entries(i.sampling.rates);
1793
1897
  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);
1794
- 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]);
1795
- let s = /* @__PURE__ */ new Set([...Object.keys(qe), ...ke]);
1796
- for (let n of Object.keys(e)) s.has(n) || t.report("config.invalid", `unknown config key "${n}", ignored. Typo?`);
1797
- return i;
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;
1798
1899
  }
1799
- function Wn(e, t) {
1800
- for (let n of Object.keys(t)) _e.includes(n) || Object.assign(e, { [n]: t[n] });
1801
- for (let n of _e) Object.assign(e[n], t[n]);
1900
+ function Xn(e, t) {
1901
+ let n = /* @__PURE__ */ new Set([...Object.keys(Ue), ...Qe]);
1902
+ 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) {
1904
+ let r = e[n];
1905
+ if (typeof r != "object" || !r) continue;
1906
+ let i = /* @__PURE__ */ new Set([...Object.keys(Ue[n]), ...ct[n]]);
1907
+ for (let e of Object.keys(r)) i.has(e) || t.report("config.invalid", `unknown config key "${n}.${e}", ignored. Typo?`);
1908
+ }
1909
+ }
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]);
1802
1913
  }
1803
1914
  //#endregion
1804
1915
  //#region src/core/context.ts
1805
- var Gn = class {
1916
+ var Qn = class {
1806
1917
  map = /* @__PURE__ */ new Map();
1807
1918
  set(e, t) {
1808
1919
  this.map.set(e, t);
@@ -1822,12 +1933,12 @@ var Gn = class {
1822
1933
  getAll() {
1823
1934
  return Object.fromEntries(this.map);
1824
1935
  }
1825
- }, Kn = class {
1936
+ }, $n = class {
1826
1937
  handler;
1827
1938
  throttleMs;
1828
1939
  counters = /* @__PURE__ */ new Map();
1829
1940
  lastEmitted = /* @__PURE__ */ new Map();
1830
- constructor(e, t = ce) {
1941
+ constructor(e, t = oe) {
1831
1942
  this.handler = e, this.throttleMs = t;
1832
1943
  }
1833
1944
  setHandler(e) {
@@ -1852,7 +1963,7 @@ var Gn = class {
1852
1963
  if (this.handler) try {
1853
1964
  this.handler(o);
1854
1965
  } catch (e) {
1855
- this.count("handler.threw"), typeof console < "u" && console.warn(`${Ke} onDiagnostic handler threw`, e);
1966
+ this.count("handler.threw"), typeof console < "u" && console.warn(`${Ee} onDiagnostic handler threw`, e);
1856
1967
  }
1857
1968
  }
1858
1969
  guard(e, t, n) {
@@ -1877,59 +1988,59 @@ var Gn = class {
1877
1988
  reset() {
1878
1989
  this.counters.clear(), this.lastEmitted.clear();
1879
1990
  }
1880
- }, qn = {
1881
- maxAgeMs: Re,
1991
+ }, er = {
1992
+ maxAgeMs: ft,
1882
1993
  endOnOwnerClose: !1,
1883
- urlParam: tt
1994
+ urlParam: ot
1884
1995
  };
1885
- function K(e, t) {
1996
+ function J(e, t) {
1886
1997
  let n = Reflect.get(e, t);
1887
1998
  return typeof n == "string" && n !== "" ? n : void 0;
1888
1999
  }
1889
- function Jn(e, t) {
2000
+ function tr(e, t) {
1890
2001
  let n = Reflect.get(e, t);
1891
2002
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
1892
2003
  }
1893
- function Yn(e) {
2004
+ function nr(e) {
1894
2005
  if (typeof e != "object" || !e) return null;
1895
- let t = K(e, "id"), n = K(e, "name"), r = Jn(e, "startedAt");
2006
+ let t = J(e, "id"), n = J(e, "name"), r = tr(e, "startedAt");
1896
2007
  return t === void 0 || n === void 0 || r === void 0 ? null : {
1897
2008
  id: t,
1898
2009
  name: n,
1899
2010
  startedAt: r,
1900
- parentId: K(e, "parentId"),
1901
- ownerContextId: K(e, "ownerContextId") ?? ""
2011
+ parentId: J(e, "parentId"),
2012
+ ownerContextId: J(e, "ownerContextId") ?? ""
1902
2013
  };
1903
2014
  }
1904
- function Xn(e) {
2015
+ function rr(e) {
1905
2016
  if (typeof e != "object" || !e) return null;
1906
- let t = K(e, "i"), n = K(e, "n");
2017
+ let t = J(e, "i"), n = J(e, "n");
1907
2018
  return t === void 0 || n === void 0 ? null : {
1908
2019
  id: t,
1909
2020
  name: n,
1910
- startedAt: Jn(e, "s") ?? Date.now(),
2021
+ startedAt: tr(e, "s") ?? Date.now(),
1911
2022
  parentId: void 0,
1912
2023
  ownerContextId: ""
1913
2024
  };
1914
2025
  }
1915
- function Zn(e) {
2026
+ function ir(e) {
1916
2027
  let t = JSON.stringify({
1917
2028
  i: e.id,
1918
2029
  n: e.name.slice(0, 64),
1919
2030
  s: e.startedAt
1920
2031
  }), n = new TextEncoder().encode(t), r = "";
1921
2032
  for (let e of n) r += String.fromCharCode(e);
1922
- return btoa(r).replace(Be, "-").replace(Ee, "_").replace(He, "");
2033
+ return btoa(r).replace(Le, "-").replace(Ce, "_").replace(ze, "");
1923
2034
  }
1924
- function Qn(e, t) {
2035
+ function ar(e, t) {
1925
2036
  let n = new Promise((e, n) => {
1926
- C(setTimeout(() => {
2037
+ E(setTimeout(() => {
1927
2038
  n(/* @__PURE__ */ Error(`timed out after ${String(t)}ms`));
1928
2039
  }, t));
1929
2040
  });
1930
2041
  return Promise.race([e, n]);
1931
2042
  }
1932
- var $n = class {
2043
+ var or = class {
1933
2044
  options;
1934
2045
  diagnostics;
1935
2046
  contextId;
@@ -1945,14 +2056,14 @@ var $n = class {
1945
2056
  async bootstrap() {
1946
2057
  let e = this.readUrlToken();
1947
2058
  if (e && this.adopt(e, "url")) return;
1948
- let t = this.diagnostics.guard("storage.unavailable", "reading the persisted journey", () => sessionStorage.getItem(x));
2059
+ let t = this.diagnostics.guard("storage.unavailable", "reading the persisted journey", () => sessionStorage.getItem(w));
1949
2060
  if (t && this.restore(t)) return;
1950
2061
  let n = await this.readOpenFinToken();
1951
2062
  n !== null && this.adopt(n, "openfin.customData");
1952
2063
  }
1953
2064
  start(e, t = {}) {
1954
2065
  let n = {
1955
- id: t.id ?? j(),
2066
+ id: t.id ?? F(),
1956
2067
  name: e,
1957
2068
  startedAt: Date.now(),
1958
2069
  parentId: t.parent ? this.journey?.id : void 0,
@@ -1970,7 +2081,7 @@ var $n = class {
1970
2081
  getToken() {
1971
2082
  let e = this.journey;
1972
2083
  if (e === null) return;
1973
- let t = Zn(e);
2084
+ let t = ir(e);
1974
2085
  if (t.length > 256) {
1975
2086
  this.diagnostics.report("journey.token_too_large", "journey token exceeded the size cap and was not issued", { length: t.length });
1976
2087
  return;
@@ -1994,7 +2105,7 @@ var $n = class {
1994
2105
  this.clearTimer();
1995
2106
  }
1996
2107
  restore(e) {
1997
- let t = Yn(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
2108
+ let t = nr(this.diagnostics.guard("storage.degraded", "parsing the persisted journey", () => JSON.parse(e)));
1998
2109
  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}"`, {
1999
2110
  source: "sessionStorage",
2000
2111
  journeyId: t.id
@@ -2002,22 +2113,22 @@ var $n = class {
2002
2113
  }
2003
2114
  decodeToken(e) {
2004
2115
  return this.diagnostics.guard("config.invalid", "decoding a seeded journey token", () => {
2005
- let t = e.replace(at, "+").replace(Qe, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
2006
- return Xn(JSON.parse(new TextDecoder().decode(i)));
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)));
2007
2118
  }) ?? null;
2008
2119
  }
2009
2120
  setJourney(e) {
2010
2121
  if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "persisting the journey", () => {
2011
- e === null ? sessionStorage.removeItem(x) : sessionStorage.setItem(x, JSON.stringify(e));
2122
+ e === null ? sessionStorage.removeItem(w) : sessionStorage.setItem(w, JSON.stringify(e));
2012
2123
  }), e === null) return;
2013
2124
  let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
2014
2125
  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();
2015
2126
  }, t);
2016
- this.expiryTimer = n, C(n);
2127
+ this.expiryTimer = n, E(n);
2017
2128
  }
2018
2129
  clearStored() {
2019
2130
  this.diagnostics.guard("storage.unavailable", "clearing the persisted journey", () => {
2020
- sessionStorage.removeItem(x);
2131
+ sessionStorage.removeItem(w);
2021
2132
  });
2022
2133
  }
2023
2134
  clearTimer() {
@@ -2029,46 +2140,64 @@ var $n = class {
2029
2140
  async readOpenFinToken() {
2030
2141
  let e = globalThis.fin?.me, t = e?.getOptions;
2031
2142
  if (t === void 0) return null;
2032
- let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => Qn(t.call(e), $e)))?.customData?.[ot];
2143
+ let n = (await this.diagnostics.guardAsync("openfin.unavailable", "reading fin.me.getOptions()", () => ar(t.call(e), Be)))?.customData?.[Ye];
2033
2144
  return typeof n == "string" ? n : null;
2034
2145
  }
2035
2146
  };
2036
2147
  //#endregion
2037
2148
  //#region src/core/sampling.ts
2038
- function er(e) {
2039
- let t = be;
2040
- for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, h);
2149
+ function sr(e) {
2150
+ let t = m;
2151
+ for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, ge);
2041
2152
  return t >>> 0;
2042
2153
  }
2043
- function q(e, t) {
2154
+ function cr(e, t) {
2044
2155
  let n = e.attributes[t];
2045
2156
  return typeof n == "string" ? n : "";
2046
2157
  }
2047
- function tr(e, t) {
2158
+ function lr(e, t) {
2048
2159
  let { rates: n, defaultRate: r } = t.sampling, i, a = -1;
2049
2160
  for (let [t, r] of Object.entries(n)) (e === t || e.startsWith(`${t}.`)) && t.length > a && (i = r, a = t.length);
2050
2161
  return i ?? r;
2051
2162
  }
2052
- function nr(e, t) {
2053
- if (e.severityText === "ERROR" || e.severityText === "FATAL" || t.sampling.alwaysSampleTypes.includes(q(e, "log.type"))) return !0;
2054
- let n = tr(q(e, y), t);
2055
- return n >= 1 ? !0 : n <= 0 ? !1 : er(q(e, "journey.id") || e.traceId) / Ge < n;
2163
+ function ur(e, t) {
2164
+ 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;
2056
2167
  }
2168
+ function dr(e, t) {
2169
+ return ur({
2170
+ level: e.severityText,
2171
+ type: cr(e, S),
2172
+ namespace: cr(e, C),
2173
+ journeyId: cr(e, b),
2174
+ traceId: e.traceId
2175
+ }, t);
2176
+ }
2177
+ var fr = class {
2178
+ windowStart = 0;
2179
+ count = 0;
2180
+ allow(e) {
2181
+ if (e.severityText !== "ERROR" && e.severityText !== "FATAL") return !0;
2182
+ let t = Date.now();
2183
+ return t - this.windowStart > 1e4 && (this.windowStart = t, this.count = 0), this.count++, this.count <= 500;
2184
+ }
2185
+ };
2057
2186
  //#endregion
2058
2187
  //#region src/core/pipeline.ts
2059
- function rr(e) {
2060
- return e.attributes[v] === it;
2188
+ function pr(e) {
2189
+ return e.attributes[S] === lt;
2061
2190
  }
2062
- var ir = {
2191
+ var mr = {
2063
2192
  logs: {
2064
- flushIntervalMs: Ae,
2193
+ flushIntervalMs: $e,
2065
2194
  batchSize: 100
2066
2195
  },
2067
2196
  metrics: {
2068
- flushIntervalMs: Pe,
2197
+ flushIntervalMs: qe,
2069
2198
  batchSize: 500
2070
2199
  }
2071
- }, ar = class {
2200
+ }, hr = class {
2072
2201
  options;
2073
2202
  onFlush;
2074
2203
  pending = [];
@@ -2096,13 +2225,12 @@ var ir = {
2096
2225
  let e = setTimeout(() => {
2097
2226
  this.timer = null, this.onFlush(this);
2098
2227
  }, this.options.flushIntervalMs);
2099
- this.timer = e, C(e);
2228
+ this.timer = e, E(e);
2100
2229
  }
2101
2230
  clearTimer() {
2102
2231
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
2103
2232
  }
2104
- }, or = class {
2105
- config;
2233
+ }, gr = class {
2106
2234
  transport;
2107
2235
  storage;
2108
2236
  retry;
@@ -2110,43 +2238,50 @@ var ir = {
2110
2238
  streams;
2111
2239
  unconfirmed = /* @__PURE__ */ new Map();
2112
2240
  queue = [];
2241
+ ceiling = new fr();
2113
2242
  inFlight = 0;
2114
2243
  pumpScheduled = !1;
2115
2244
  stopped = !1;
2116
- constructor(e, t, n, r, i, a = ir) {
2117
- this.config = e, this.transport = t, this.storage = n, this.retry = r, this.diagnostics = i;
2118
- let o = (e) => {
2245
+ constructor(e, t, n, r, i = mr) {
2246
+ this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
2247
+ let a = (e) => {
2119
2248
  this.claim(e);
2120
2249
  };
2121
2250
  this.streams = {
2122
- logs: new ar(a.logs, o),
2123
- metrics: new ar(a.metrics, o)
2251
+ logs: new hr(i.logs, a),
2252
+ metrics: new hr(i.metrics, a)
2124
2253
  };
2125
2254
  }
2126
2255
  push(e) {
2127
- this.stopped || (e.observedTimeUnixNano = O(), this.route(e));
2256
+ this.stopped || (e.observedTimeUnixNano = Xt(), this.route(e));
2128
2257
  }
2129
2258
  drainPending() {
2130
- let e = [
2131
- ...[...this.unconfirmed.values()].flatMap((e) => e.records),
2259
+ return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
2260
+ }
2261
+ drainForExit() {
2262
+ let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
2263
+ return this.unconfirmed.clear(), this.toBatch([
2264
+ ...e,
2132
2265
  ...this.streams.metrics.take(),
2133
2266
  ...this.streams.logs.take()
2134
- ];
2135
- return this.unconfirmed.clear(), e.length === 0 ? null : {
2136
- id: j(),
2267
+ ]);
2268
+ }
2269
+ destroy() {
2270
+ this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
2271
+ }
2272
+ toBatch(e) {
2273
+ return e.length === 0 ? null : {
2274
+ id: F(),
2137
2275
  records: e,
2138
2276
  createdAt: Date.now(),
2139
2277
  attempts: 0
2140
2278
  };
2141
2279
  }
2142
- destroy() {
2143
- this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
2144
- }
2145
2280
  route(e) {
2146
2281
  try {
2147
- let t = rr(e) ? this.streams.metrics : this.streams.logs;
2148
- if (!nr(e, this.config)) {
2149
- this.diagnostics.count("record.dropped_by_sampling");
2282
+ let t = pr(e) ? this.streams.metrics : this.streams.logs;
2283
+ if (!this.ceiling.allow(e)) {
2284
+ this.diagnostics.count("record.dropped_by_ceiling");
2150
2285
  return;
2151
2286
  }
2152
2287
  t.add(e);
@@ -2156,7 +2291,7 @@ var ir = {
2156
2291
  }
2157
2292
  claim(e) {
2158
2293
  let t = e.take(), n = {
2159
- id: j(),
2294
+ id: F(),
2160
2295
  records: t,
2161
2296
  createdAt: Date.now(),
2162
2297
  attempts: 0
@@ -2218,10 +2353,10 @@ var ir = {
2218
2353
  };
2219
2354
  //#endregion
2220
2355
  //#region src/core/record.ts
2221
- function J(e) {
2356
+ function Y(e) {
2222
2357
  return e;
2223
2358
  }
2224
- var sr = class {
2359
+ var _r = class {
2225
2360
  deps;
2226
2361
  resourceCache = null;
2227
2362
  constructor(e) {
@@ -2232,99 +2367,118 @@ var sr = class {
2232
2367
  }
2233
2368
  isEnabled(e) {
2234
2369
  let { config: t } = this.deps;
2235
- return t.enabled ? b[e] >= b[t.minLevel] : !1;
2370
+ return t.enabled ? x[e] >= x[t.minLevel] : !1;
2236
2371
  }
2237
2372
  build(e) {
2238
2373
  let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o } = this.deps;
2239
- if (!this.isEnabled(e.level)) return n.count("record.dropped_by_level"), null;
2240
- let s = r.resolve(), c = i.current(), l = a.next(), u = Dn(), d, f = 0;
2374
+ if (!this.isEnabled(e.level)) return n.count("record.dropped_by_level"), {
2375
+ record: null,
2376
+ dropped: "level"
2377
+ };
2378
+ let s = r.resolve(), c = i.current();
2379
+ if (!ur({
2380
+ level: e.level,
2381
+ type: e.type,
2382
+ namespace: e.namespace,
2383
+ journeyId: c?.id ?? "",
2384
+ traceId: s.traceId
2385
+ }, t)) return n.count("record.dropped_by_sampling"), {
2386
+ record: null,
2387
+ dropped: "sampling"
2388
+ };
2389
+ let l = a.next(), u = Ht(), d = t.capture.fullUrls ? u : j(u), f, p = 0;
2241
2390
  try {
2242
- let t = L(this.deps.context.getAll(), o), n = L(e.scoped ?? {}, o), r = L(e.payload ?? {}, o);
2243
- f = t.bytes + n.bytes + r.bytes, d = {
2244
- ...J(t.value),
2245
- ...J(n.value),
2246
- ...J(r.value)
2391
+ let t = B(this.deps.context.getAll(), o), n = B(e.scoped ?? {}, o), r = B(e.payload ?? {}, o);
2392
+ p = t.bytes + n.bytes + r.bytes, f = {
2393
+ ...Y(t.value),
2394
+ ...Y(n.value),
2395
+ ...Y(r.value)
2247
2396
  };
2248
2397
  } catch (e) {
2249
- n.report("record.sanitize_failed", "attributes could not be sanitized", void 0, e), d = { [Fe]: !0 };
2398
+ n.report("record.sanitize_failed", "attributes could not be sanitized", void 0, e), f = { [Me]: !0 };
2250
2399
  }
2251
- d[v] = e.type, d[Ne] = l, d[y] = e.namespace, d[mt] = u, c && (d[Oe] = c.id, d[nt] = c.name, c.parentId !== void 0 && (d[ut] = c.parentId));
2252
- let p = I(e.body, o.maxBodyChars);
2253
- p !== e.body && n.count("record.truncated");
2254
- let m = {
2255
- timeUnixNano: O(),
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);
2402
+ m !== e.body && n.count("record.truncated");
2403
+ let h = {
2404
+ timeUnixNano: Xt(),
2256
2405
  traceId: s.traceId,
2257
2406
  spanId: s.spanId,
2258
2407
  traceFlags: s.traceFlags,
2259
- severityNumber: ye[e.level],
2408
+ severityNumber: ve[e.level],
2260
2409
  severityText: e.level,
2261
- body: p,
2262
- attributes: d,
2410
+ body: m,
2411
+ attributes: f,
2263
2412
  resource: this.resource()
2264
- }, h = t.redact;
2265
- if (h) {
2266
- let e = n.guard("record.sanitize_failed", "redact hook threw", () => h(m));
2267
- if (e === null) return n.count("record.dropped_by_redact"), null;
2268
- if (e !== void 0 && e !== m) {
2269
- if (k(e)) {
2270
- let t = L(e.attributes, o);
2271
- m = {
2413
+ }, g = t.redact;
2414
+ if (g) {
2415
+ let e = n.guard("record.sanitize_failed", "redact hook threw", () => g(h));
2416
+ if (e === null) return n.count("record.dropped_by_redact"), {
2417
+ record: null,
2418
+ dropped: "redact"
2419
+ };
2420
+ if (e !== void 0 && e !== h) {
2421
+ if (Zt(e)) {
2422
+ let t = B(e.attributes, o);
2423
+ h = {
2272
2424
  ...e,
2273
- attributes: J(t.value)
2274
- }, f = t.bytes;
2425
+ attributes: Y(t.value)
2426
+ }, p = t.bytes;
2275
2427
  } else n.report("record.sanitize_failed", "redact hook returned something that is not a record, keeping the original");
2276
2428
  }
2277
2429
  }
2278
- if (f > o.maxRecordBytes) {
2430
+ if (p > o.maxRecordBytes) {
2279
2431
  n.report("record.truncated", "attributes exceeded the size budget and were dropped", {
2280
- bytes: f,
2281
- body: m.body
2432
+ bytes: p,
2433
+ body: h.body
2282
2434
  });
2283
2435
  let t = {
2284
- [v]: e.type,
2285
- [Ne]: l,
2286
- [y]: e.namespace,
2287
- [mt]: u,
2288
- [We]: !0,
2289
- [ct]: f
2436
+ [S]: e.type,
2437
+ [ke]: l,
2438
+ [C]: e.namespace,
2439
+ [pt]: d,
2440
+ [Ve]: !0,
2441
+ [it]: p
2290
2442
  };
2291
- c && (t[Oe] = c.id, t[nt] = c.name), m.attributes = t;
2443
+ c && (t[b] = c.id, t[Ze] = c.name), h.attributes = t;
2292
2444
  }
2293
- return m;
2445
+ return { record: h };
2294
2446
  }
2295
2447
  resource() {
2296
2448
  if (this.resourceCache) return this.resourceCache;
2297
- let { config: e, identity: n, platform: i } = this.deps;
2449
+ let { config: e, identity: t, platform: r } = this.deps;
2298
2450
  return this.resourceCache = {
2299
- [c]: e.serviceName,
2300
- [de]: e.serviceVersion,
2301
- [o]: e.environment,
2302
- [se]: Le,
2303
- [le]: pt,
2304
- [Je]: t,
2305
- [_t]: i.platform,
2306
- [Xe]: n.sessionId,
2307
- [r]: n.tabId,
2308
- [ge]: n.contextId,
2309
- [yt]: i.userAgent,
2310
- ...i.openfinUuid === void 0 ? {} : { [u]: i.openfinUuid },
2311
- ...i.openfinName === void 0 ? {} : { [ve]: i.openfinName }
2451
+ [le]: e.serviceName,
2452
+ [Ke]: e.serviceVersion,
2453
+ [_t]: e.environment,
2454
+ [se]: dt,
2455
+ [ue]: Xe,
2456
+ [ae]: Pe,
2457
+ [he]: r.platform,
2458
+ [n]: t.sessionId,
2459
+ [We]: t.tabId,
2460
+ [a]: t.contextId,
2461
+ [me]: r.userAgent,
2462
+ ...r.openfinUuid === void 0 ? {} : { [s]: r.openfinUuid },
2463
+ ...r.openfinName === void 0 ? {} : { [l]: r.openfinName }
2312
2464
  }, this.resourceCache;
2313
2465
  }
2314
- }, Y = Symbol.for(ae), X = class e {
2466
+ }, vr = Symbol.for(fe), X = class t {
2315
2467
  diagnostics;
2316
2468
  config;
2317
2469
  platform;
2318
2470
  identity;
2319
- context = new Gn();
2471
+ sessionTouch;
2472
+ context = new Qn();
2320
2473
  breadcrumbs;
2321
2474
  tracing;
2322
- sequence = new On();
2475
+ sequence = new En();
2323
2476
  journey;
2324
2477
  builder;
2325
2478
  console;
2326
2479
  bus;
2327
2480
  storage;
2481
+ storageBuiltAs;
2328
2482
  transport;
2329
2483
  retry;
2330
2484
  pipeline;
@@ -2337,11 +2491,11 @@ var sr = class {
2337
2491
  destroyed = !1;
2338
2492
  lastGapAt = 0;
2339
2493
  constructor(e) {
2340
- this.diagnostics = new Kn(e.onDiagnostic), this.platform = wn(this.diagnostics), this.config = Un(e, this.diagnostics), this.identity = Zt(this.diagnostics), this.breadcrumbs = new Pn(50), this.tracing = new Nn(this.diagnostics), this.console = new Cn(this.config.console), this.journey = new $n(qn, this.diagnostics, this.identity.contextId, (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) => {
2341
2495
  this.bus.broadcastJourney(e);
2342
- }), this.builder = new sr({
2496
+ }), this.builder = new _r({
2343
2497
  config: this.config,
2344
- limits: bt,
2498
+ limits: Oe,
2345
2499
  diagnostics: this.diagnostics,
2346
2500
  context: this.context,
2347
2501
  journey: this.journey,
@@ -2349,7 +2503,7 @@ var sr = class {
2349
2503
  sequence: this.sequence,
2350
2504
  identity: this.identity,
2351
2505
  platform: this.platform
2352
- }), this.bus = new Ht(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
2506
+ }), this.bus = new Rt(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
2353
2507
  onRecords: (e) => {
2354
2508
  this.ingestForwarded(e);
2355
2509
  },
@@ -2368,16 +2522,20 @@ var sr = class {
2368
2522
  });
2369
2523
  };
2370
2524
  static current() {
2371
- return globalThis[Y] ?? null;
2525
+ return globalThis[vr] ?? null;
2372
2526
  }
2373
- static configure(t) {
2374
- let n = e.current();
2375
- if (n && !n.destroyed) return n.reconfigure(t), n;
2376
- let r = new e(t);
2377
- return globalThis[Y] = r, r.init(), r;
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;
2378
2532
  }
2379
2533
  reconfigure(e) {
2380
- Wn(this.config, Un(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");
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");
2535
+ }
2536
+ keepBuiltStorage() {
2537
+ let e = this.storageBuiltAs;
2538
+ e !== void 0 && this.config.storage !== e && (this.diagnostics.report("config.invalid", `storage cannot change after startup, still ${e}`, { requested: this.config.storage }), this.config.storage = e);
2381
2539
  }
2382
2540
  async init() {
2383
2541
  try {
@@ -2390,11 +2548,11 @@ var sr = class {
2390
2548
  }
2391
2549
  }
2392
2550
  async becomeSender() {
2393
- this.storage = await mn(this.config.storage, Se, m, this.diagnostics, this.reportGap), this.transport = new bn(this.config, this.diagnostics), this.retry = new xn(this.storage, this.transport, this.diagnostics, this.config), this.pipeline = new or(this.config, this.transport, this.storage, this.retry, this.diagnostics), this.exitFlush = new _n({
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({
2394
2552
  config: this.config,
2395
2553
  diagnostics: this.diagnostics,
2396
- drainPending: () => this.pipeline?.drainPending() ?? null
2397
- }), await cn(this.storage, this.diagnostics), this.retry.start(), this.exitFlush.install();
2554
+ drainForExit: () => this.pipeline?.drainForExit() ?? null
2555
+ }), await ln(this.storage, this.diagnostics), this.retry.start(), this.exitFlush.install();
2398
2556
  }
2399
2557
  installCaptures() {
2400
2558
  let e = {
@@ -2402,7 +2560,7 @@ var sr = class {
2402
2560
  diagnostics: this.diagnostics,
2403
2561
  breadcrumbs: this.breadcrumbs,
2404
2562
  tracing: this.tracing,
2405
- logger: new S(this, a)
2563
+ logger: new T(this, i)
2406
2564
  }, t = this.config.capture;
2407
2565
  (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));
2408
2566
  for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `installing ${e.name}`, () => {
@@ -2424,12 +2582,12 @@ var sr = class {
2424
2582
  if (!this.destroyed) {
2425
2583
  this.destroyed = !0;
2426
2584
  for (let e of this.captures) e.uninstall();
2427
- 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, Y);
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);
2428
2586
  }
2429
2587
  }
2430
2588
  emit(e) {
2431
2589
  if (!(!e || this.destroyed)) {
2432
- if ($t(this.identity.sessionId, this.diagnostics), !this.ready) {
2590
+ if (this.sessionTouch.touch(this.identity.sessionId), !this.ready) {
2433
2591
  this.bootBuffer.length >= 500 && (this.bootBuffer.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), this.bootBuffer.push(e);
2434
2592
  return;
2435
2593
  }
@@ -2456,10 +2614,14 @@ var sr = class {
2456
2614
  return;
2457
2615
  }
2458
2616
  for (let t of e) {
2459
- if (!k(t)) {
2617
+ if (!Zt(t)) {
2460
2618
  this.diagnostics.count("record.dropped_malformed");
2461
2619
  continue;
2462
2620
  }
2621
+ if (!dr(t, this.config)) {
2622
+ this.diagnostics.count("record.dropped_by_sampling");
2623
+ continue;
2624
+ }
2463
2625
  this.pipeline?.push(t);
2464
2626
  }
2465
2627
  }
@@ -2471,19 +2633,19 @@ var sr = class {
2471
2633
  }
2472
2634
  reportGap = (e) => {
2473
2635
  let t = Date.now();
2474
- t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new S(this, ie).warn("stored records were dropped before delivery", {
2636
+ t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new T(this, rt).warn("stored records were dropped before delivery", {
2475
2637
  "gap.batches": e.batches,
2476
2638
  "gap.records": e.records,
2477
2639
  "gap.reason": e.reason
2478
2640
  }));
2479
2641
  };
2480
2642
  regenerateTabId() {
2481
- let e = j();
2643
+ let t = F();
2482
2644
  this.diagnostics.report("bus.role_resolved", "another context claimed this tab id, most likely a duplicated tab. Regenerating.", {
2483
2645
  was: this.identity.tabId,
2484
- now: e
2485
- }), this.identity.tabId = e, this.diagnostics.guard("storage.unavailable", "persisting the new tab id", () => {
2486
- sessionStorage.setItem(pe, e);
2646
+ now: t
2647
+ }), this.identity.tabId = t, this.diagnostics.guard("storage.unavailable", "persisting the new tab id", () => {
2648
+ sessionStorage.setItem(e, t);
2487
2649
  }), this.builder.invalidateResource();
2488
2650
  }
2489
2651
  async queueDepth() {
@@ -2514,93 +2676,94 @@ var sr = class {
2514
2676
  function Q() {
2515
2677
  return X.current() || X.configure({});
2516
2678
  }
2517
- function cr(e) {
2679
+ function yr(e) {
2518
2680
  X.configure(e), Z.clear();
2519
2681
  }
2520
- function lr(e, t) {
2521
- let n = t ? `${e}::${JSON.stringify(t)}` : e, r = Z.get(n);
2522
- return r || (r = new S(Q(), e, t), Z.set(n, r)), r;
2682
+ function br(e, t) {
2683
+ if (t) return new T(Q(), e, t);
2684
+ let n = Z.get(e);
2685
+ return n || (n = new T(Q(), e), Z.set(e, n)), n;
2523
2686
  }
2524
2687
  function $() {
2525
- return lr("app");
2688
+ return br("app");
2526
2689
  }
2527
- function ur(e, t) {
2690
+ function xr(e, t) {
2528
2691
  $().trace(e, t);
2529
2692
  }
2530
- function dr(e, t) {
2693
+ function Sr(e, t) {
2531
2694
  $().debug(e, t);
2532
2695
  }
2533
- function fr(e, t) {
2696
+ function Cr(e, t) {
2534
2697
  $().info(e, t);
2535
2698
  }
2536
- function pr(e, t) {
2699
+ function wr(e, t) {
2537
2700
  $().warn(e, t);
2538
2701
  }
2539
- function mr(e, t, n) {
2702
+ function Tr(e, t, n) {
2540
2703
  $().error(e, t, n);
2541
2704
  }
2542
- function hr(e, t) {
2705
+ function Er(e, t) {
2543
2706
  $().logAction(e, t);
2544
2707
  }
2545
- function gr(e, t) {
2708
+ function Dr(e, t) {
2546
2709
  $().logEvent(e, t);
2547
2710
  }
2548
- function _r(e, t, n, r, i) {
2711
+ function Or(e, t, n, r, i) {
2549
2712
  $().logMetric(e, t, n, r, i);
2550
2713
  }
2551
- function vr(e, t, n) {
2714
+ function kr(e, t, n) {
2552
2715
  return $().timeSync(e, t, n);
2553
2716
  }
2554
- function yr(e, t, n) {
2717
+ function Ar(e, t, n) {
2555
2718
  return $().timeAsync(e, t, n);
2556
2719
  }
2557
- function br(e, t) {
2720
+ function jr(e, t) {
2558
2721
  Q().context.set(e, t);
2559
2722
  }
2560
- function xr(e) {
2723
+ function Mr(e) {
2561
2724
  Q().context.setMany(e);
2562
2725
  }
2563
- function Sr(e) {
2726
+ function Nr(e) {
2564
2727
  Q().context.remove(e);
2565
2728
  }
2566
- function Cr(e, t) {
2729
+ function Pr(e, t) {
2567
2730
  return Q().journey.start(e, t);
2568
2731
  }
2569
- function wr() {
2732
+ function Fr() {
2570
2733
  Q().journey.end();
2571
2734
  }
2572
- function Tr() {
2735
+ function Ir() {
2573
2736
  return Q().journey.current();
2574
2737
  }
2575
- function Er() {
2738
+ function Lr() {
2576
2739
  return Q().journey.getToken();
2577
2740
  }
2578
- function Dr(e) {
2741
+ function Rr(e) {
2579
2742
  return Q().journey.adopt(e, "manual", !0);
2580
2743
  }
2581
- function Or(e) {
2744
+ function zr(e) {
2582
2745
  Q().registerWorker(e);
2583
2746
  }
2584
- function kr() {
2747
+ function Br() {
2585
2748
  Q().tracing.rotate("explicit");
2586
2749
  }
2587
- function Ar() {
2750
+ function Vr() {
2588
2751
  return Q().tracing.headers();
2589
2752
  }
2590
- function jr() {
2753
+ function Hr() {
2591
2754
  return Q().flush();
2592
2755
  }
2593
- function Mr() {
2756
+ function Ur() {
2594
2757
  return Q().queueDepth();
2595
2758
  }
2596
- function Nr() {
2759
+ function Wr() {
2597
2760
  return Q().diagnostics.snapshot();
2598
2761
  }
2599
- async function Pr() {
2762
+ async function Gr() {
2600
2763
  let e = X.current();
2601
2764
  Z.clear(), await e?.destroy();
2602
2765
  }
2603
2766
  //#endregion
2604
- export { S as OneLogger, Dr as adoptJourney, cr as configure, Tr as currentJourney, dr as debug, wr as endJourney, mr as error, jr as flush, Nr as getDiagnosticCounters, Er as getJourneyToken, lr as getLogger, Mr as getQueueDepth, Ar as getTraceHeaders, fr as info, hr as logAction, gr as logEvent, _r as logMetric, Or as registerWorker, Sr as removeContext, br as setContext, xr as setContextMap, Pr as shutdown, Cr as startJourney, kr as startTrace, yr as timeAsync, vr as timeSync, ur as trace, pr as warn };
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 };
2605
2768
 
2606
2769
  //# sourceMappingURL=index.js.map