@utk09/ui-observability 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +75 -48
  3. package/dist/batch-DEK4bv9N.js +31 -0
  4. package/dist/batch-DEK4bv9N.js.map +1 -0
  5. package/dist/batch-DEVFs28i.cjs +2 -0
  6. package/dist/batch-DEVFs28i.cjs.map +1 -0
  7. package/dist/bus/bus.d.ts +46 -12
  8. package/dist/bus/links.d.ts +6 -3
  9. package/dist/bus-DNFvTkif.cjs +2 -0
  10. package/dist/bus-DNFvTkif.cjs.map +1 -0
  11. package/dist/{bus-DPDrlUBY.js → bus-HVQ8E72V.js} +128 -71
  12. package/dist/bus-HVQ8E72V.js.map +1 -0
  13. package/dist/capture/interactions.d.ts +7 -6
  14. package/dist/capture/network.d.ts +23 -9
  15. package/dist/capture/types.d.ts +3 -3
  16. package/dist/console-C9Y639mn.js +82 -0
  17. package/dist/console-C9Y639mn.js.map +1 -0
  18. package/dist/console-DssDxq1B.cjs +2 -0
  19. package/dist/console-DssDxq1B.cjs.map +1 -0
  20. package/dist/constants-N99w84xy.js +117 -0
  21. package/dist/constants-N99w84xy.js.map +1 -0
  22. package/dist/constants-X86IDwkC.cjs +2 -0
  23. package/dist/constants-X86IDwkC.cjs.map +1 -0
  24. package/dist/constants.d.ts +36 -18
  25. package/dist/core/diagnostics.d.ts +2 -2
  26. package/dist/core/drops.d.ts +29 -0
  27. package/dist/core/hold-buffer.d.ts +27 -0
  28. package/dist/core/journey.d.ts +16 -4
  29. package/dist/core/logger.d.ts +6 -2
  30. package/dist/core/pipeline.d.ts +20 -16
  31. package/dist/core/record.d.ts +11 -6
  32. package/dist/core/remote-sampling.d.ts +1 -1
  33. package/dist/core/runtime.d.ts +87 -23
  34. package/dist/core/sender.d.ts +19 -11
  35. package/dist/deadline-5_PecIl5.js +26 -0
  36. package/dist/deadline-5_PecIl5.js.map +1 -0
  37. package/dist/deadline-XSnm95pg.cjs +2 -0
  38. package/dist/deadline-XSnm95pg.cjs.map +1 -0
  39. package/dist/error-like-Ywo5uRHo.js +19 -0
  40. package/dist/error-like-Ywo5uRHo.js.map +1 -0
  41. package/dist/error-like-gGRx2s36.cjs +2 -0
  42. package/dist/error-like-gGRx2s36.cjs.map +1 -0
  43. package/dist/errors-BTWuVnHZ.cjs +3 -0
  44. package/dist/errors-BTWuVnHZ.cjs.map +1 -0
  45. package/dist/{errors-Dnc-X4Ec.js → errors-CQusIGWJ.js} +39 -20
  46. package/dist/errors-CQusIGWJ.js.map +1 -0
  47. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  48. package/dist/global-scope-dp2jADRl.js.map +1 -1
  49. package/dist/identity-B1GDS1Tb.cjs +2 -0
  50. package/dist/identity-B1GDS1Tb.cjs.map +1 -0
  51. package/dist/identity-D4DPjTM9.js +88 -0
  52. package/dist/identity-D4DPjTM9.js.map +1 -0
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.ts +12 -4
  56. package/dist/index.js +720 -446
  57. package/dist/index.js.map +1 -1
  58. package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-B8SGUzSV.js} +88 -59
  59. package/dist/indexeddb-storage-B8SGUzSV.js.map +1 -0
  60. package/dist/indexeddb-storage-ukzC82dm.cjs +2 -0
  61. package/dist/indexeddb-storage-ukzC82dm.cjs.map +1 -0
  62. package/dist/interactions-CcxrVzpg.cjs +2 -0
  63. package/dist/interactions-CcxrVzpg.cjs.map +1 -0
  64. package/dist/{interactions-igKTAJvj.js → interactions-CnjfQgw3.js} +22 -19
  65. package/dist/interactions-CnjfQgw3.js.map +1 -0
  66. package/dist/journey-DjvDzHyp.js +163 -0
  67. package/dist/journey-DjvDzHyp.js.map +1 -0
  68. package/dist/journey-DxlfdFJV.cjs +2 -0
  69. package/dist/journey-DxlfdFJV.cjs.map +1 -0
  70. package/dist/{library-request-Br_T09Bn.cjs → library-request-BZ1ekVtl.cjs} +2 -2
  71. package/dist/{library-request-Br_T09Bn.cjs.map → library-request-BZ1ekVtl.cjs.map} +1 -1
  72. package/dist/{library-request-Dt0fXhcn.js → library-request-C8kc5YWv.js} +2 -2
  73. package/dist/{library-request-Dt0fXhcn.js.map → library-request-C8kc5YWv.js.map} +1 -1
  74. package/dist/{long-frames-DahhqM6u.cjs → long-frames-BGik_Yhy.cjs} +2 -2
  75. package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-BGik_Yhy.cjs.map} +1 -1
  76. package/dist/{long-frames-6pnjWSSR.js → long-frames-CZk3XOkH.js} +3 -3
  77. package/dist/{long-frames-6pnjWSSR.js.map → long-frames-CZk3XOkH.js.map} +1 -1
  78. package/dist/models/batch.d.ts +15 -1
  79. package/dist/models/bus.d.ts +7 -4
  80. package/dist/models/config.d.ts +189 -12
  81. package/dist/models/drop.d.ts +39 -0
  82. package/dist/models/log-record.d.ts +12 -6
  83. package/dist/models/storage.d.ts +15 -3
  84. package/dist/network-51iicpLl.js +174 -0
  85. package/dist/network-51iicpLl.js.map +1 -0
  86. package/dist/network-jBbjyAJP.cjs +2 -0
  87. package/dist/network-jBbjyAJP.cjs.map +1 -0
  88. package/dist/patch-BX8KrPCT.cjs +2 -0
  89. package/dist/patch-BX8KrPCT.cjs.map +1 -0
  90. package/dist/patch-CCWfuEY7.js +9 -0
  91. package/dist/patch-CCWfuEY7.js.map +1 -0
  92. package/dist/platform-Cjts-8k8.js +48 -0
  93. package/dist/platform-Cjts-8k8.js.map +1 -0
  94. package/dist/{platform-D_XkVIF6.cjs → platform-DW3GFIUE.cjs} +2 -2
  95. package/dist/platform-DW3GFIUE.cjs.map +1 -0
  96. package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-ByS34k4e.cjs} +2 -2
  97. package/dist/remote-rules-ByS34k4e.cjs.map +1 -0
  98. package/dist/{remote-rules-5UA23alm.js → remote-rules-M-XZ1xbe.js} +14 -14
  99. package/dist/remote-rules-M-XZ1xbe.js.map +1 -0
  100. package/dist/sampling-BN3Oi6SV.js +63 -0
  101. package/dist/sampling-BN3Oi6SV.js.map +1 -0
  102. package/dist/sampling-b2ck5X98.cjs +2 -0
  103. package/dist/sampling-b2ck5X98.cjs.map +1 -0
  104. package/dist/sanitize-DKp5MRsa.cjs +2 -0
  105. package/dist/sanitize-DKp5MRsa.cjs.map +1 -0
  106. package/dist/sanitize-Dwj9JCkI.js +123 -0
  107. package/dist/sanitize-Dwj9JCkI.js.map +1 -0
  108. package/dist/{sender-G6v4Uqi4.js → sender-BBY0IcUo.js} +439 -322
  109. package/dist/sender-BBY0IcUo.js.map +1 -0
  110. package/dist/sender-BXoAZKum.cjs +3 -0
  111. package/dist/sender-BXoAZKum.cjs.map +1 -0
  112. package/dist/storage/emergency-queue.d.ts +5 -2
  113. package/dist/storage/eviction.d.ts +40 -0
  114. package/dist/storage/factory.d.ts +1 -1
  115. package/dist/storage/idb-driver.d.ts +7 -1
  116. package/dist/storage/indexeddb-storage.d.ts +13 -5
  117. package/dist/storage/local-storage.d.ts +27 -4
  118. package/dist/storage/memory-storage.d.ts +10 -3
  119. package/dist/{storm-BtzgLOCX.cjs → storm-CKuaBp7i.cjs} +2 -2
  120. package/dist/{storm-BtzgLOCX.cjs.map → storm-CKuaBp7i.cjs.map} +1 -1
  121. package/dist/{storm-DJkEZP_8.js → storm-DhtL2eVr.js} +2 -2
  122. package/dist/{storm-DJkEZP_8.js.map → storm-DhtL2eVr.js.map} +1 -1
  123. package/dist/transport/compression.d.ts +1 -1
  124. package/dist/transport/exit-flush.d.ts +27 -17
  125. package/dist/transport/http-transport.d.ts +61 -7
  126. package/dist/transport/retry-engine.d.ts +12 -8
  127. package/dist/transport/status-transport.d.ts +8 -3
  128. package/dist/utils/console.d.ts +5 -2
  129. package/dist/utils/error-like.d.ts +25 -0
  130. package/dist/utils/global-scope.d.ts +1 -1
  131. package/dist/utils/identity.d.ts +1 -1
  132. package/dist/utils/library-console.d.ts +1 -1
  133. package/dist/utils/library-request.d.ts +1 -1
  134. package/dist/utils/patch.d.ts +9 -0
  135. package/dist/utils/platform.d.ts +3 -3
  136. package/dist/utils/sequence.d.ts +0 -5
  137. package/dist/utils/timer.d.ts +1 -1
  138. package/dist/utils/tracing.d.ts +3 -3
  139. package/dist/utils/unref.d.ts +2 -2
  140. package/dist/{web-vitals-DHZ0yA_H.js → web-vitals-Bflr5jSA.js} +4 -2
  141. package/dist/web-vitals-Bflr5jSA.js.map +1 -0
  142. package/dist/web-vitals-DFuoTQbZ.cjs +2 -0
  143. package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -0
  144. package/package.json +2 -2
  145. package/dist/bus-CUXRY0JR.cjs +0 -2
  146. package/dist/bus-CUXRY0JR.cjs.map +0 -1
  147. package/dist/bus-DPDrlUBY.js.map +0 -1
  148. package/dist/console-CNljJict.js +0 -81
  149. package/dist/console-CNljJict.js.map +0 -1
  150. package/dist/console-PKzc-FmR.cjs +0 -2
  151. package/dist/console-PKzc-FmR.cjs.map +0 -1
  152. package/dist/constants-B28fDv2F.cjs +0 -2
  153. package/dist/constants-B28fDv2F.cjs.map +0 -1
  154. package/dist/constants-Bu49bm39.js +0 -93
  155. package/dist/constants-Bu49bm39.js.map +0 -1
  156. package/dist/errors-C78ZTjet.cjs +0 -3
  157. package/dist/errors-C78ZTjet.cjs.map +0 -1
  158. package/dist/errors-Dnc-X4Ec.js.map +0 -1
  159. package/dist/indexeddb-storage-D0p3iMD0.cjs +0 -2
  160. package/dist/indexeddb-storage-D0p3iMD0.cjs.map +0 -1
  161. package/dist/indexeddb-storage-uD4oaRMc.js.map +0 -1
  162. package/dist/interactions-CsE2y_fQ.cjs +0 -2
  163. package/dist/interactions-CsE2y_fQ.cjs.map +0 -1
  164. package/dist/interactions-igKTAJvj.js.map +0 -1
  165. package/dist/network-CZ0aFUsy.cjs +0 -2
  166. package/dist/network-CZ0aFUsy.cjs.map +0 -1
  167. package/dist/network-aSNbwpue.js +0 -112
  168. package/dist/network-aSNbwpue.js.map +0 -1
  169. package/dist/platform-BwbMRwHm.js +0 -48
  170. package/dist/platform-BwbMRwHm.js.map +0 -1
  171. package/dist/platform-D_XkVIF6.cjs.map +0 -1
  172. package/dist/remote-rules-5UA23alm.js.map +0 -1
  173. package/dist/remote-rules-rJJZKVG8.cjs.map +0 -1
  174. package/dist/sampling-E4x92Nn2.cjs +0 -2
  175. package/dist/sampling-E4x92Nn2.cjs.map +0 -1
  176. package/dist/sampling-J1eahbfT.js +0 -160
  177. package/dist/sampling-J1eahbfT.js.map +0 -1
  178. package/dist/sanitize-BMhh8ghJ.cjs +0 -2
  179. package/dist/sanitize-BMhh8ghJ.cjs.map +0 -1
  180. package/dist/sanitize-UJ-4Lb0n.js +0 -114
  181. package/dist/sanitize-UJ-4Lb0n.js.map +0 -1
  182. package/dist/sender-B6ufz26f.cjs +0 -3
  183. package/dist/sender-B6ufz26f.cjs.map +0 -1
  184. package/dist/sender-G6v4Uqi4.js.map +0 -1
  185. package/dist/unref-16maCyKA.js +0 -8
  186. package/dist/unref-16maCyKA.js.map +0 -1
  187. package/dist/unref-CU9Nyz_9.cjs +0 -2
  188. package/dist/unref-CU9Nyz_9.cjs.map +0 -1
  189. package/dist/web-vitals-B2FYsEAU.cjs +0 -2
  190. package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
  191. package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,61 +1,93 @@
1
- import { At as e, Bt as t, C as n, Ct as r, D as i, E as a, F as o, Ft as s, Gt as c, It as l, Lt as u, M as d, Mt as f, N as p, Nt as m, Ot as h, Pt as g, Rt as _, T as v, Wt as ee, Zt as te, _ as ne, _t as re, a as y, at as b, c as x, cn as ie, d as ae, dn as oe, fn as se, g as ce, gn as S, h as le, hn as ue, i as de, it as fe, j as C, jt as pe, kt as me, l as w, ln as he, m as ge, mn as _e, n as T, nt as ve, o as E, p as ye, qt as D, r as be, rt as O, s as xe, st as Se, tn as Ce, u as k, un as we, vt as Te, zt as Ee } from "./constants-Bu49bm39.js";
2
- import { a as De, c as Oe, d as A, f as ke, l as j, m as Ae, n as je, o as M, p as N, r as Me, s as Ne, u as Pe } from "./sampling-J1eahbfT.js";
3
- import { a as Fe, i as Ie, n as Le, o as P, r as F } from "./sanitize-UJ-4Lb0n.js";
4
- import { n as Re, r as ze, t as Be } from "./platform-BwbMRwHm.js";
5
- import { t as Ve } from "./unref-16maCyKA.js";
1
+ import { A as e, Bt as t, E as n, Et as r, F as i, Ft as a, Ht as o, I as s, It as c, Jt as l, Lt as u, Mt as d, Nt as f, O as p, P as m, Pt as h, R as g, Rt as _, Ut as ee, Vt as te, Xt as v, _n as ne, a as y, c as re, ct as ie, d as b, dn as ae, dt as oe, en as x, f as se, fn as S, gn as ce, i as le, jt as ue, k as de, l as fe, lt as C, mn as pe, n as me, o as he, p as ge, pn as _e, qt as ve, r as ye, rn as be, s as w, u as T, un as xe, vn as E, x as Se, zt as Ce } from "./constants-N99w84xy.js";
2
+ import { n as we, r as Te, t as Ee } from "./error-like-Ywo5uRHo.js";
3
+ import { a as D, i as De, n as Oe, o as ke, r as Ae } from "./sampling-BN3Oi6SV.js";
4
+ import { a as je, i as Me, n as Ne, o as O, r as k } from "./sanitize-Dwj9JCkI.js";
5
+ import { a as Pe, i as Fe, n as Ie, o as A, r as Le, s as Re, t as ze } from "./identity-D4DPjTM9.js";
6
+ import { n as Be, r as Ve, t as He } from "./platform-Cjts-8k8.js";
7
+ import { n as j, t as Ue } from "./batch-DEK4bv9N.js";
8
+ import { n as We } from "./library-request-C8kc5YWv.js";
9
+ import { n as Ge, t as Ke } from "./journey-DjvDzHyp.js";
6
10
  //#region src/utils/timer.ts
7
- function I(e) {
8
- return Math.round((performance.now() - e) * o) / o;
11
+ function M(e) {
12
+ return Math.round((performance.now() - e) * g) / g;
9
13
  }
10
- function L(e, t, n, r, i) {
11
- e.logMetric(`${t}.duration`, I(n), "ms", "histogram", {
14
+ function N(e, t, n, r, i) {
15
+ e.logMetric(`${t}.duration`, n, "ms", "histogram", {
12
16
  status: r,
13
17
  ...i
14
18
  });
15
19
  }
16
- function R(e, t, n, r, i) {
20
+ function qe(e, t, n, r, i) {
21
+ let a = M(n);
17
22
  e.error(`${t} failed`, r, {
18
- "action.duration_ms": I(n),
23
+ "action.duration_ms": a,
19
24
  status: "FAILURE",
20
25
  ...i
21
- });
26
+ }), N(e, t, a, "FAILURE", i);
22
27
  }
23
- function He(e, t, n, r) {
28
+ function Je(e, t, n, r) {
24
29
  let i = performance.now();
25
30
  try {
26
31
  let a = n();
27
- return L(e, t, i, "SUCCESS", r), a;
32
+ return N(e, t, M(i), "SUCCESS", r), a;
28
33
  } catch (n) {
29
- throw R(e, t, i, n, r), n;
34
+ throw qe(e, t, i, n, r), n;
30
35
  }
31
36
  }
32
- async function Ue(e, t, n, r) {
37
+ async function Ye(e, t, n, r) {
33
38
  let i = performance.now();
34
39
  try {
35
40
  let a = await n();
36
- return L(e, t, i, "SUCCESS", r), a;
41
+ return N(e, t, M(i), "SUCCESS", r), a;
37
42
  } catch (n) {
38
- throw R(e, t, i, n, r), n;
43
+ throw qe(e, t, i, n, r), n;
39
44
  }
40
45
  }
41
46
  //#endregion
42
47
  //#region src/core/logger.ts
43
- function We(e, t) {
44
- if (e instanceof Error) return e;
45
- let n = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
46
- return Error(n ?? typeof e);
48
+ var Xe = [n, be];
49
+ function Ze(e, t) {
50
+ let n = t.guard("record.sanitize_failed", "The library could not read the error reason.", () => {
51
+ if (!(e instanceof Error) && !Te(e)) return;
52
+ let t = Error(e.message);
53
+ return t.name = e.name, t.stack = e.stack, t;
54
+ });
55
+ if (n) return n;
56
+ let r = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
57
+ return Error(r ?? typeof e);
58
+ }
59
+ function Qe(e, t, n) {
60
+ return n.guard("record.sanitize_failed", "The library could not read the error reason.", () => e instanceof Error ? e : t) ?? t;
47
61
  }
48
- function Ge(e) {
62
+ function $e(e, t) {
63
+ if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint" || typeof e == "symbol") return e;
64
+ if (typeof e == "object" && e) return t.guard("record.sanitize_failed", "The library could not read the properties of the error reason.", () => {
65
+ let t = e, n = Te(e), r = {}, i = 0;
66
+ for (let e of Object.keys(t)) {
67
+ let a = t[e];
68
+ (!n || !Ee.has(e)) && we(a) && (r[e] = a, i++);
69
+ }
70
+ return i === 0 ? void 0 : r;
71
+ });
72
+ }
73
+ function et(e) {
49
74
  if (typeof e != "object" || !e || Array.isArray(e) || e instanceof Error) return !1;
50
75
  let t = Object.getPrototypeOf(e);
51
76
  return t === null || Object.getPrototypeOf(t) === null;
52
77
  }
53
- var z = class e {
78
+ function tt(e) {
79
+ return Xe.some((t) => e === t || e.startsWith(`${t}.`)) ? "system" : "log";
80
+ }
81
+ function P(e, t) {
82
+ return e === void 0 ? {} : t.guard("record.sanitize_failed", "The library could not read the payload.", () => ({ ...e })) ?? { "uiobs.sanitize_failed": !0 };
83
+ }
84
+ var F = class e {
54
85
  bind;
55
86
  namespace;
56
87
  options;
88
+ levelType;
57
89
  constructor(e, t, n = {}) {
58
- this.bind = e, this.namespace = t, this.options = n;
90
+ this.bind = e, this.namespace = t, this.options = n, this.levelType = tt(t);
59
91
  }
60
92
  child(t, n = {}) {
61
93
  return new e(this.bind, `${this.namespace}.${t}`, { scopedContext: {
@@ -64,16 +96,16 @@ var z = class e {
64
96
  } });
65
97
  }
66
98
  trace = (e, t) => {
67
- this.write("TRACE", "system", e, t);
99
+ this.write("TRACE", this.levelType, e, t);
68
100
  };
69
101
  debug = (e, t) => {
70
- this.write("DEBUG", "system", e, t);
102
+ this.write("DEBUG", this.levelType, e, t);
71
103
  };
72
104
  info = (e, t) => {
73
- this.write("INFO", "system", e, t);
105
+ this.write("INFO", this.levelType, e, t);
74
106
  };
75
107
  warn = (e, t) => {
76
- this.write("WARN", "system", e, t);
108
+ this.write("WARN", this.levelType, e, t);
77
109
  };
78
110
  error = (e, t, n) => {
79
111
  this.writeError("ERROR", e, t, n);
@@ -87,141 +119,145 @@ var z = class e {
87
119
  logEvent = (e, t) => {
88
120
  this.write("INFO", "event", e, t);
89
121
  };
90
- logMetric = (e, t, n = d, r = "gauge", i) => {
91
- this.write("INFO", "metric", e, {
122
+ logMetric = (e, t, n = i, r = "gauge", a) => {
123
+ if (!Number.isFinite(t)) {
124
+ this.bind().diagnostics.report("record.dropped_malformed", "The metric value is not a finite number. The library dropped the metric.", { "metric.name": e });
125
+ return;
126
+ }
127
+ let o = {
128
+ ...P(a, this.bind().diagnostics),
92
129
  "metric.name": e,
93
130
  "metric.value": t,
94
131
  "metric.unit": n,
95
- "metric.type": r,
96
- ...i
97
- });
132
+ "metric.type": r
133
+ };
134
+ this.write("INFO", "metric", e, o, !0);
98
135
  };
99
- timeSync = (e, t, n) => He(this, e, t, n);
100
- timeAsync = (e, t, n) => Ue(this, e, t, n);
101
- write(e, t, n, r) {
102
- let i = this.bind();
103
- if (i.isDestroyed()) return;
104
- if (!i.builder.isEnabled(e)) {
105
- this.mirrors(i, e) && this.print(i, e, n, r, void 0, null);
136
+ timeSync = (e, t, n) => Je(this, e, t, n);
137
+ timeAsync = (e, t, n) => Ye(this, e, t, n);
138
+ write(e, t, n, r, i = !1) {
139
+ let a = this.bind();
140
+ if (a.isDestroyed()) return;
141
+ if (!a.builder.isEnabled(e, t)) {
142
+ this.mirrors(a, e) && this.print(a, e, n, r, void 0, null);
106
143
  return;
107
144
  }
108
- let { record: a, dropped: o } = i.builder.build({
145
+ let { record: o, dropped: s } = a.builder.build({
109
146
  level: e,
110
147
  type: t,
111
148
  body: n,
112
149
  namespace: this.namespace,
113
150
  scoped: this.options.scopedContext,
114
- payload: r
115
- });
116
- t !== "metric" && o !== "redact" && i.breadcrumbs.push({
151
+ payload: i ? r : P(r, a.diagnostics)
152
+ }), c = o ? o.body : s === "sampling" ? n : void 0;
153
+ t !== "metric" && c !== void 0 && a.breadcrumbs.push({
117
154
  t: Date.now(),
118
155
  category: t === "action" ? "action" : t === "event" ? "event" : "log",
119
- message: n
120
- }), this.print(i, e, n, r, void 0, a), i.emit(a);
156
+ message: c
157
+ }), this.print(a, e, n, r, void 0, o, s), a.emit(o);
121
158
  }
122
159
  writeError(e, t, n, r) {
123
160
  let i = this.bind();
124
161
  if (i.isDestroyed()) return;
125
162
  let a = i.builder.isEnabled(e);
126
163
  if (!a && !this.mirrors(i, e)) return;
127
- let o = r === void 0 && Ge(n), s = o ? n : r, c = o || n === void 0 ? void 0 : We(n, i.diagnostics);
164
+ let o = r === void 0 && (i.diagnostics.guard("record.sanitize_failed", "The library could not read the error slot.", () => et(n)) ?? !1), s = o ? n : r, c = o ? void 0 : n, l = c === void 0 ? void 0 : Ze(c, i.diagnostics), u = l === void 0 ? void 0 : Qe(c, l, i.diagnostics);
128
165
  if (!a) {
129
- this.print(i, e, t, s, c, null);
166
+ this.print(i, e, t, s, u, null);
130
167
  return;
131
168
  }
132
- let { record: l } = i.builder.build({
169
+ let d = l ? $e(c, i.diagnostics) : void 0, { record: f, dropped: p } = i.builder.build({
133
170
  level: e,
134
- type: "system",
171
+ type: this.levelType,
135
172
  body: t,
136
173
  namespace: this.namespace,
137
174
  scoped: this.options.scopedContext,
138
175
  payload: {
139
- ...s,
140
- ...c ? {
141
- "error.type": c.name,
142
- "error.message": c.message,
143
- "error.stack_trace": c.stack
176
+ ...P(s, i.diagnostics),
177
+ ...l ? {
178
+ "error.type": l.name,
179
+ "error.message": l.message,
180
+ "error.stack_trace": l.stack
144
181
  } : {},
145
- breadcrumbs: i.breadcrumbs.snapshot()
182
+ ...d === void 0 ? {} : { [he]: d },
183
+ [y]: i.breadcrumbs.snapshot()
146
184
  }
147
185
  });
148
- this.print(i, e, t, s, c, l), i.emit(l);
186
+ this.print(i, e, t, s, u, f, p), i.emit(f);
149
187
  }
150
- print(e, t, n, r, i, a) {
151
- e.config.redact ? a ? e.console.write(this.namespace, t, a.body, a.attributes) : e.console.write(this.namespace, t, n, void 0, i) : e.console.write(this.namespace, t, n, r, i);
188
+ print(e, t, n, r, i, a, o) {
189
+ e.config.redact ? a ? e.console.write(this.namespace, t, a.body, a.attributes) : o !== "redact" && o !== "malformed" && e.console.write(this.namespace, t, n, void 0, i) : e.console.write(this.namespace, t, n, r, i);
152
190
  }
153
191
  mirrors(e, t) {
154
192
  return e.config.enabled && e.console.accepts(t);
155
193
  }
156
- }, Ke = {
194
+ }, nt = {
157
195
  TRACE: "debug",
158
196
  DEBUG: "debug",
159
197
  INFO: "info",
160
198
  WARN: "warn",
161
199
  ERROR: "error",
162
200
  FATAL: "error"
163
- }, qe = class {
201
+ }, rt = class {
164
202
  settings;
165
203
  diagnostics;
166
- constructor(e, t) {
167
- this.settings = e, this.diagnostics = t;
204
+ limits;
205
+ constructor(e, t, n = r) {
206
+ this.settings = e, this.diagnostics = t, this.limits = n;
168
207
  }
169
208
  update(e) {
170
209
  this.settings = e;
171
210
  }
172
211
  accepts(e) {
173
- return this.settings.level !== null && b[e] >= b[this.settings.level];
174
- }
175
- write(e, t, n, i, a) {
176
- if (!this.accepts(t) || typeof console > "u" || Fe()) return;
177
- let o = `%c[%s]%c[${t}]%c`, { styles: s } = this.settings, c = Ke[t];
178
- this.diagnostics.guard("handler.threw", `The library could not print to console.${c}.`, () => {
179
- let l = [];
180
- a !== void 0 && l.push(a), i !== void 0 && l.push(Le(i, r, this.diagnostics)), P(() => {
181
- console[c](o, s.namespace, e, s[t], "", n, ...l);
212
+ return this.settings.level === null || !Object.hasOwn(C, this.settings.level) ? !1 : C[e] >= C[this.settings.level];
213
+ }
214
+ write(e, t, n, r, i) {
215
+ if (!this.accepts(t) || typeof console > "u" || je()) return;
216
+ let a = `%c[%s]%c[${t}]%c`, { styles: o } = this.settings, s = nt[t];
217
+ this.diagnostics.guard("handler.threw", `The library could not print to console.${s}.`, () => {
218
+ let c = [];
219
+ i !== void 0 && c.push(i), r !== void 0 && c.push(Ne(r, this.limits, this.diagnostics)), O(() => {
220
+ console[s](a, o.namespace, e, o[t], "", n, ...c);
182
221
  });
183
222
  });
184
223
  }
185
- }, Je = class {
224
+ }, it = class {
186
225
  value = 0;
187
226
  next() {
188
227
  return ++this.value;
189
228
  }
190
- reset() {
191
- this.value = 0;
192
- }
193
- }, Ye = /^[0-9a-f]{32}$/, Xe = /^[0-9a-f]{16}$/, B = /[1-9a-f]/;
194
- function Ze(e) {
195
- return Ye.test(e.traceId) && B.test(e.traceId) && Xe.test(e.spanId) && B.test(e.spanId);
229
+ }, at = /^[0-9a-f]{32}$/, ot = /^[0-9a-f]{16}$/, st = /[1-9a-f]/;
230
+ function ct(e) {
231
+ return at.test(e.traceId) && st.test(e.traceId) && ot.test(e.spanId) && st.test(e.spanId);
196
232
  }
197
- function Qe() {
233
+ function lt() {
198
234
  return A(16);
199
235
  }
200
- function $e() {
236
+ function ut() {
201
237
  return A(8);
202
238
  }
203
- function V() {
239
+ function dt() {
204
240
  return {
205
- traceId: Qe(),
206
- spanId: $e(),
241
+ traceId: lt(),
242
+ spanId: ut(),
207
243
  traceFlags: 1,
208
244
  startedAt: Date.now()
209
245
  };
210
246
  }
211
- function H(e) {
247
+ function ft(e) {
212
248
  return {
213
249
  traceId: e.traceId,
214
250
  spanId: e.spanId,
215
251
  traceFlags: e.traceFlags
216
252
  };
217
253
  }
218
- var et = class {
254
+ var pt = class {
219
255
  diagnostics;
220
256
  maxAgeMs;
221
257
  load;
222
- ambient = V();
258
+ ambient = dt();
223
259
  otel;
224
- constructor(e, t = se, n) {
260
+ constructor(e, t = pe, n) {
225
261
  this.diagnostics = e, this.maxAgeMs = t, this.load = n;
226
262
  }
227
263
  async loadOtel() {
@@ -233,7 +269,7 @@ var et = class {
233
269
  }
234
270
  resolve() {
235
271
  let e = this.activeSpanContext();
236
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), H(this.ambient)) : e;
272
+ return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), ft(this.ambient)) : e;
237
273
  }
238
274
  activeSpanContext() {
239
275
  let e = this.otel;
@@ -241,7 +277,7 @@ var et = class {
241
277
  let t = e.trace.getActiveSpan();
242
278
  if (t === void 0) return;
243
279
  let n = t.spanContext();
244
- if (Ze(n)) return {
280
+ if (ct(n)) return {
245
281
  traceId: n.traceId,
246
282
  spanId: n.spanId,
247
283
  traceFlags: n.traceFlags
@@ -249,7 +285,7 @@ var et = class {
249
285
  });
250
286
  }
251
287
  rotate(e) {
252
- return this.ambient = V(), H(this.ambient);
288
+ return this.ambient = dt(), ft(this.ambient);
253
289
  }
254
290
  headers() {
255
291
  let e = {}, t = this.otel;
@@ -257,11 +293,11 @@ var et = class {
257
293
  t.propagation.inject(t.context.active(), e);
258
294
  }), !e.traceparent) {
259
295
  let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
260
- e[oe] = `00-${t.traceId}-${t.spanId}-${n}`;
296
+ e[_e] = `00-${t.traceId}-${t.spanId}-${n}`;
261
297
  }
262
298
  return e;
263
299
  }
264
- }, tt = class {
300
+ }, mt = class {
265
301
  buffer;
266
302
  pointer = 0;
267
303
  filled = !1;
@@ -278,95 +314,287 @@ var et = class {
278
314
  clear() {
279
315
  this.buffer = Array(this.capacity), this.pointer = 0, this.filled = !1;
280
316
  }
281
- };
282
- //#endregion
283
- //#region src/core/config.ts
284
- function nt(e) {
317
+ }, ht = Object.keys(C), gt = ["gzip", "none"], _t = [
318
+ "omit",
319
+ "same-origin",
320
+ "include"
321
+ ], vt = [
322
+ "auto",
323
+ "indexeddb",
324
+ "localstorage",
325
+ "memory",
326
+ "none"
327
+ ], yt = ["storage", "memory"], bt = [
328
+ "auto",
329
+ "sender",
330
+ "forwarder",
331
+ "off"
332
+ ], xt = [
333
+ "auto",
334
+ "provider",
335
+ "client"
336
+ ], St = [
337
+ "auto",
338
+ "context",
339
+ "tab",
340
+ "origin"
341
+ ], Ct = [
342
+ "error",
343
+ "warn",
344
+ "info",
345
+ "log"
346
+ ], wt = ["limited", "until-delivered"], Tt = {
347
+ logFlushIntervalMs: [100, 6e4],
348
+ logBatchSize: [1, 1e3],
349
+ metricFlushIntervalMs: [100, 6e4],
350
+ metricBatchSize: [1, 1e3]
351
+ }, Et = {
352
+ maxBatches: [1, 5e3],
353
+ maxAgeMs: [6e4, 6048e5],
354
+ maxAttempts: [1, 20]
355
+ }, Dt = {
356
+ maxBodyChars: [256, 65536],
357
+ maxAttributeChars: [256, 65536],
358
+ maxAttributeCount: [1, 1024],
359
+ maxStackChars: [256, 65536],
360
+ maxDepth: [1, 16],
361
+ maxArrayLength: [1, 1e4],
362
+ maxNodes: [100, 1e5],
363
+ maxRecordBytes: [1024, Se]
364
+ }, Ot = [6e4, 864e5], kt = [
365
+ "errors",
366
+ "rejections",
367
+ "resourceErrors",
368
+ "fetch",
369
+ "xhr",
370
+ "interactions",
371
+ "navigation",
372
+ "webVitals",
373
+ "longFrames",
374
+ "fullUrls"
375
+ ], At = "null", I = `a level name: ${R(ht)}`, L = `true, false or a list of ${R(Ct)}`, jt = "a list of strings and RegExp patterns", Mt = "a list of origin URLs such as \"https://api.example\" and RegExp patterns", Nt = "a list of origin URLs such as \"https://app.example\". For a sandboxed frame, set bus.mode: \"sender\" in the frame", Pt = "a list of strings";
376
+ function R(e) {
377
+ let t = e.map((e) => `"${e}"`);
378
+ return `${t.slice(0, -1).join(", ")} or ${t[t.length - 1]}`;
379
+ }
380
+ function z(e) {
381
+ return typeof e == "string" ? `"${e}"` : typeof e == "function" ? "a function" : typeof e == "object" && e ? "an object" : String(e);
382
+ }
383
+ function B(e, t, n, r, i) {
384
+ e.report("config.invalid", `${t} must be ${n}. The value is ${z(r)}. The library keeps ${i}.`);
385
+ }
386
+ function V(e, t, n, r, i) {
387
+ if (t === void 0) return r;
388
+ let a = n.find((e) => e === t);
389
+ return a === void 0 ? (B(i, e, R(n), t, `"${r}"`), r) : a;
390
+ }
391
+ function H(e, t, n, r) {
392
+ return t === void 0 ? n : typeof t == "boolean" ? t : (B(r, e, "true or false", t, String(n)), n);
393
+ }
394
+ function Ft(e, t, n, r) {
395
+ return t === void 0 ? n : typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : (B(r, e, "a finite number of 0 or more", t, String(n)), n);
396
+ }
397
+ function It(e, t, n, r, i) {
398
+ if (t === void 0) return r;
399
+ let [a, o] = n;
400
+ return typeof t == "number" && Number.isInteger(t) && t >= a && t <= o ? t : (B(i, e, `an integer from ${String(a)} to ${String(o)}`, t, String(r)), r);
401
+ }
402
+ function U(e, t, n, r, i) {
403
+ let a = t ?? {}, o = Object.keys(r);
404
+ return Object.fromEntries(o.map((t) => [t, It(`${e}.${t}`, a[t], r[t], n[t], i)]));
405
+ }
406
+ function W(e) {
407
+ if (typeof e != "string") return;
408
+ let t = e.toUpperCase();
409
+ return ht.find((e) => e === t);
410
+ }
411
+ function Lt(e, t, n, r) {
412
+ if (t === void 0) return n;
413
+ let i = W(t);
414
+ return i === void 0 ? (B(r, e, I, t, `"${n}"`), n) : i;
415
+ }
416
+ function G(e, t, n, r, i, a) {
417
+ if (t === void 0) return n;
418
+ if (!Array.isArray(t)) return B(a, e, r, t, "the list in force"), n;
419
+ let o = [], s = t;
420
+ for (let t of s) {
421
+ let n = i(t);
422
+ n === void 0 ? a.report("config.invalid", `The library ignores the ${e} entry ${z(t)}. ${e} must be ${r}.`) : o.push(n);
423
+ }
424
+ return o;
425
+ }
426
+ function Rt(e) {
427
+ return typeof e == "string" ? e : void 0;
428
+ }
429
+ function zt(e) {
430
+ return typeof e == "string" || e instanceof RegExp ? e : void 0;
431
+ }
432
+ function Bt(e) {
433
+ return Ct.find((t) => t === e);
434
+ }
435
+ function Vt(e) {
436
+ if (typeof e == "string") try {
437
+ let { origin: t } = new URL(e);
438
+ return t === At ? void 0 : t;
439
+ } catch {
440
+ return;
441
+ }
442
+ }
443
+ function Ht(e) {
444
+ return e instanceof RegExp ? e : Vt(e);
445
+ }
446
+ function Ut(e) {
447
+ return typeof e != "object" || !e || Array.isArray(e) ? !1 : Object.values(e).every((e) => typeof e == "string");
448
+ }
449
+ function Wt(e, t, n) {
450
+ if (e !== void 0) return typeof e == "function" || Ut(e) ? e : (B(n, "headers", "an object of strings or a function", e, "the headers in force"), t);
451
+ }
452
+ function Gt(e) {
285
453
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
286
454
  }
287
- function rt(e, t, n) {
288
- return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || nt(e) ? e : (n.report("config.invalid", `serializer must be "${D}", "ecs" or an implementation. The library uses "${D}".`), D);
455
+ function Kt(e, t, n) {
456
+ return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || Gt(e) ? e : (n.report("config.invalid", `serializer must be "${v}", "ecs" or an implementation. The library uses "${v}".`), v);
289
457
  }
290
- var it = new Set(Object.keys(i));
291
- function at(e, t) {
458
+ var qt = new Set(Object.keys(e));
459
+ function Jt(e, t) {
292
460
  let n = {}, r = Object.entries(e ?? {});
293
- for (let [e, i] of r) it.has(e) ? typeof i == "string" ? n[e] = i : t.report("config.invalid", `console.styles.${e} must be a string. The library keeps the style in force.`) : t.report("config.invalid", `The library ignores the unknown console.styles key "${e}". Check the spelling.`);
461
+ for (let [e, i] of r) qt.has(e) ? typeof i == "string" ? n[e] = i : t.report("config.invalid", `console.styles.${e} must be a string. The library keeps the style in force.`) : t.report("config.invalid", `The library ignores the unknown console.styles key "${e}". Check the spelling.`);
294
462
  return n;
295
463
  }
296
- function ot(e, t, n) {
297
- return e === void 0 ? t : e === !1 ? {
464
+ function Yt(e, t, n) {
465
+ if (e === void 0) return t ?? "DEBUG";
466
+ let r = W(e);
467
+ return r === void 0 ? (B(n, "console.level", I, e, "the console level in force"), t) : r;
468
+ }
469
+ function Xt(e, t, n) {
470
+ if (e === void 0) return t;
471
+ if (e === !1) return {
298
472
  level: null,
299
473
  styles: t.styles
300
- } : e === !0 ? {
301
- level: a,
302
- styles: t.styles
303
- } : typeof e == "string" ? {
304
- level: e,
474
+ };
475
+ if (e === !0) return {
476
+ level: de,
305
477
  styles: t.styles
306
- } : typeof e != "object" || !e ? (n.report("config.invalid", "console must be a boolean, a level or an object. The console settings in force stay."), t) : {
307
- level: e.level ?? t.level ?? "DEBUG",
478
+ };
479
+ if (typeof e == "string") {
480
+ let r = W(e);
481
+ return r === void 0 ? (B(n, "console", I, e, "the console level in force"), t) : {
482
+ level: r,
483
+ styles: t.styles
484
+ };
485
+ }
486
+ return typeof e != "object" || !e ? (n.report("config.invalid", "console must be a boolean, a level or an object. The console settings in force stay."), t) : {
487
+ level: Yt(e.level, t.level, n),
308
488
  styles: {
309
489
  ...t.styles,
310
- ...at(e.styles, n)
490
+ ...Jt(e.styles, n)
311
491
  }
312
492
  };
313
493
  }
314
- function U(e, t, n) {
315
- let r = n ?? C, i = {
494
+ function Zt(e, t, n) {
495
+ let r = e ?? {};
496
+ return {
497
+ ...t,
498
+ ...r,
499
+ rates: {
500
+ ...t.rates,
501
+ ...r.rates
502
+ },
503
+ alwaysSampleTypes: G("sampling.alwaysSampleTypes", r.alwaysSampleTypes, t.alwaysSampleTypes, Pt, Rt, n),
504
+ remote: H("sampling.remote", r.remote, t.remote, n)
505
+ };
506
+ }
507
+ function Qt(e, t, n) {
508
+ let r = e ?? {};
509
+ return {
510
+ mode: V("bus.mode", r.mode, bt, t.mode, n),
511
+ trustedOrigins: G("bus.trustedOrigins", r.trustedOrigins, t.trustedOrigins, Nt, Vt, n),
512
+ openFinRole: V("bus.openFinRole", r.openFinRole, xt, t.openFinRole, n)
513
+ };
514
+ }
515
+ function $t(e, t, n) {
516
+ let r = e ?? {};
517
+ return {
518
+ scope: V("journey.scope", r.scope, St, t.scope, n),
519
+ maxAgeMs: It("journey.maxAgeMs", r.maxAgeMs, Ot, t.maxAgeMs, n)
520
+ };
521
+ }
522
+ function en(e, t, n) {
523
+ let r = e ?? {};
524
+ return {
525
+ mode: V("retention.mode", r.mode, wt, t.mode, n),
526
+ ...U("retention", r, t, Et, n)
527
+ };
528
+ }
529
+ function tn(e, t, n) {
530
+ return e === void 0 ? t : typeof e == "boolean" ? e : Array.isArray(e) ? G("capture.console", e, [], L, Bt, n) : (B(n, "capture.console", L, e, "the value in force"), t);
531
+ }
532
+ function nn(e, t, n) {
533
+ let r = e ?? {}, i = {
534
+ ...t,
535
+ ...r,
536
+ console: tn(r.console, t.console, n),
537
+ longFrameThresholdMs: Ft("capture.longFrameThresholdMs", r.longFrameThresholdMs, t.longFrameThresholdMs, n),
538
+ ignoreUrls: G("capture.ignoreUrls", r.ignoreUrls, t.ignoreUrls, jt, zt, n),
539
+ propagateTraceHeaderTo: G("capture.propagateTraceHeaderTo", r.propagateTraceHeaderTo, t.propagateTraceHeaderTo, Mt, Ht, n)
540
+ };
541
+ for (let e of kt) i[e] = H(`capture.${e}`, r[e], t[e], n);
542
+ return i;
543
+ }
544
+ function rn(e, t, n) {
545
+ let r = n ?? m, i = {
316
546
  ...r,
317
547
  ...e,
318
548
  endpoint: e.endpoint === void 0 ? r.endpoint : e.endpoint,
319
- serializer: rt(e.serializer, n?.serializer, t),
320
- console: ot(e.console, r.console, t),
321
- sampling: {
322
- ...r.sampling,
323
- ...e.sampling,
324
- rates: {
325
- ...r.sampling.rates,
326
- ...e.sampling?.rates
327
- }
328
- },
329
- bus: {
330
- ...r.bus,
331
- ...e.bus
332
- },
333
- capture: {
334
- ...r.capture,
335
- ...e.capture
336
- }
549
+ enabled: H("enabled", e.enabled, r.enabled, t),
550
+ minLevel: Lt("minLevel", e.minLevel, r.minLevel, t),
551
+ compression: V("compression", e.compression, gt, r.compression, t),
552
+ credentials: V("credentials", e.credentials, _t, r.credentials, t),
553
+ headers: "headers" in e ? Wt(e.headers, r.headers, t) : r.headers,
554
+ storage: V("storage", e.storage, vt, r.storage, t),
555
+ identity: V("identity", e.identity, yt, r.identity, t),
556
+ serializer: Kt(e.serializer, n?.serializer, t),
557
+ console: Xt(e.console, r.console, t),
558
+ sampling: Zt(e.sampling, r.sampling, t),
559
+ bus: Qt(e.bus, r.bus, t),
560
+ batching: U("batching", e.batching, r.batching, Tt, t),
561
+ retention: en(e.retention, r.retention, t),
562
+ limits: U("limits", e.limits, r.limits, Dt, t),
563
+ journey: $t(e.journey, r.journey, t),
564
+ capture: nn(e.capture, r.capture, t)
337
565
  };
338
- if (i.transport !== void 0 && typeof i.transport != "function" && (t.report("config.invalid", "transport must be a function. The library ignores the value."), i.transport = r.transport), i.transportOnExit !== void 0 && typeof i.transportOnExit != "function" && (t.report("config.invalid", "transportOnExit must be a function. The library ignores the value."), i.transportOnExit = r.transportOnExit), i.endpoint === "") i.transport === void 0 && t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
566
+ if (i.transport !== void 0 && typeof i.transport != "function" && (t.report("config.invalid", "transport must be a function. The library ignores the value."), i.transport = r.transport), i.onDrop !== void 0 && typeof i.onDrop != "function" && (t.report("config.invalid", "onDrop must be a function. The library ignores the value."), i.onDrop = r.onDrop), i.transportOnExit !== void 0 && typeof i.transportOnExit != "function" && (t.report("config.invalid", "transportOnExit must be a function. The library ignores the value."), i.transportOnExit = r.transportOnExit), i.endpoint === "") i.transport === void 0 && t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
339
567
  else if (i.endpoint !== null) try {
340
568
  new URL(i.endpoint);
341
569
  } catch (e) {
342
570
  t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}.`, void 0, e);
343
571
  }
344
- i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${S}'.`), S);
572
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${E}'.`), E);
345
573
  let a = i.sampling.defaultRate;
346
574
  (typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1. The value is ${String(a)}. The library uses 1.`), i.sampling.defaultRate = 1);
347
575
  let o = i.sampling.remoteMaxRate;
348
576
  (typeof o != "number" || !(o >= 0 && o <= 1)) && (t.report("config.invalid", `sampling.remoteMaxRate must be 0..1. The value is ${String(o)}. The library uses 1.`), i.sampling.remoteMaxRate = 1);
349
577
  let s = Object.entries(i.sampling.rates);
350
578
  for (let [e, n] of s) (typeof n != "number" || n < 0 || n > 1) && (t.report("config.invalid", `sampling.rates["${e}"] must be 0..1. The value is ${String(n)}. The library uses 1.`), i.sampling.rates[e] = 1);
351
- 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]), st(e, t), i;
579
+ 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]), an(e, t), i;
352
580
  }
353
- function st(e, t) {
354
- let n = /* @__PURE__ */ new Set([...Object.keys(C), ..._e]);
581
+ function an(e, t) {
582
+ let n = /* @__PURE__ */ new Set([...Object.keys(m), ...ce]);
355
583
  for (let r of Object.keys(e)) n.has(r) || t.report("config.invalid", `The library ignores the unknown config key "${r}". Check the spelling.`);
356
- for (let n of v) {
584
+ for (let n of p) {
357
585
  let r = e[n];
358
586
  if (typeof r != "object" || !r) continue;
359
- let i = /* @__PURE__ */ new Set([...Object.keys(C[n]), ...ue[n]]);
587
+ let i = /* @__PURE__ */ new Set([...Object.keys(m[n]), ...ne[n]]);
360
588
  for (let e of Object.keys(r)) i.has(e) || t.report("config.invalid", `The library ignores the unknown config key "${n}.${e}". Check the spelling.`);
361
589
  }
362
590
  }
363
- function ct(e, t) {
364
- for (let n of Object.keys(t)) v.includes(n) || Object.assign(e, { [n]: t[n] });
365
- for (let n of v) Object.assign(e[n], t[n]);
591
+ function on(e, t) {
592
+ for (let n of Object.keys(t)) p.includes(n) || Object.assign(e, { [n]: t[n] });
593
+ for (let n of p) Object.assign(e[n], t[n]);
366
594
  }
367
595
  //#endregion
368
596
  //#region src/core/context.ts
369
- var lt = class {
597
+ var sn = class {
370
598
  map = /* @__PURE__ */ new Map();
371
599
  set(e, t) {
372
600
  this.map.set(e, t);
@@ -386,12 +614,12 @@ var lt = class {
386
614
  getAll() {
387
615
  return Object.fromEntries(this.map);
388
616
  }
389
- }, ut = class {
617
+ }, cn = class {
390
618
  handler;
391
619
  throttleMs;
392
620
  counters = /* @__PURE__ */ new Map();
393
621
  lastEmitted = /* @__PURE__ */ new Map();
394
- constructor(e, t = p) {
622
+ constructor(e, t = s) {
395
623
  this.handler = e, this.throttleMs = t;
396
624
  }
397
625
  setHandler(e) {
@@ -414,12 +642,12 @@ var lt = class {
414
642
  count: i
415
643
  }, { handler: s } = this;
416
644
  if (s) try {
417
- P(() => {
645
+ O(() => {
418
646
  s(o);
419
647
  });
420
648
  } catch (e) {
421
- this.count("handler.threw"), typeof console < "u" && P(() => {
422
- console.warn(`${Se} The onDiagnostic handler threw an error.`, e);
649
+ this.count("handler.threw"), typeof console < "u" && O(() => {
650
+ console.warn(`${oe} The onDiagnostic handler threw an error.`, e);
423
651
  });
424
652
  }
425
653
  }
@@ -445,158 +673,94 @@ var lt = class {
445
673
  reset() {
446
674
  this.counters.clear(), this.lastEmitted.clear();
447
675
  }
448
- }, dt = {
449
- maxAgeMs: ve,
450
- endOnOwnerClose: !1,
451
- urlParam: fe
452
676
  };
453
- function W(e, t) {
454
- let n = Reflect.get(e, t);
455
- return typeof n == "string" && n !== "" ? n : void 0;
456
- }
457
- function G(e, t) {
458
- let n = Reflect.get(e, t);
459
- return typeof n == "number" && Number.isFinite(n) ? n : void 0;
460
- }
461
- function ft(e) {
462
- if (typeof e != "object" || !e) return null;
463
- let t = W(e, "id"), n = W(e, "name"), r = G(e, "startedAt");
464
- return t === void 0 || n === void 0 || r === void 0 ? null : {
465
- id: t,
466
- name: n,
467
- startedAt: r,
468
- parentId: W(e, "parentId"),
469
- ownerContextId: W(e, "ownerContextId") ?? ""
470
- };
471
- }
472
- function pt(e) {
473
- if (typeof e != "object" || !e) return null;
474
- let t = W(e, "i"), n = W(e, "n");
475
- return t === void 0 || n === void 0 ? null : {
476
- id: t,
477
- name: n,
478
- startedAt: G(e, "s") ?? Date.now(),
479
- parentId: void 0,
480
- ownerContextId: ""
481
- };
482
- }
483
- function mt(e) {
484
- let t = JSON.stringify({
485
- i: e.id,
486
- n: e.name.slice(0, 64),
487
- s: e.startedAt
488
- }), n = new TextEncoder().encode(t), r = "";
489
- for (let e of n) r += String.fromCharCode(e);
490
- return btoa(r).replace(ce, "-").replace(ne, "_").replace(le, "");
677
+ //#endregion
678
+ //#region src/core/drops.ts
679
+ function K(e, t) {
680
+ e.length < 20 && !e.includes(t) && e.push(t);
491
681
  }
492
- var ht = class {
493
- options;
682
+ var ln = class {
683
+ config;
494
684
  diagnostics;
495
- contextId;
496
- onLocalChange;
497
- stores;
498
- journey = null;
499
- expiryTimer = null;
500
- constructor(e, t, n, r, i = M) {
501
- this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r, this.stores = i;
502
- }
503
- current() {
504
- return this.journey;
505
- }
506
- async bootstrap() {
507
- let e = this.readUrlToken();
508
- if (e && this.adopt(e, "url")) return;
509
- let t = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(O));
510
- if (t && this.restore(t)) return;
511
- let n = await this.readOpenFinToken();
512
- n !== null && this.adopt(n, "openfin.customData");
513
- }
514
- start(e, t = {}) {
515
- let n = {
516
- id: t.id ?? j(this.diagnostics),
517
- name: e,
518
- startedAt: Date.now(),
519
- parentId: t.parent ? this.journey?.id : void 0,
520
- ownerContextId: this.contextId
521
- };
522
- return this.setJourney(n), this.onLocalChange(n), n;
523
- }
524
- end() {
525
- this.journey !== null && (this.setJourney(null), this.onLocalChange(null));
526
- }
527
- applyRemote(e) {
528
- let t = this.journey;
529
- (e === null || t === null || e.id !== t.id) && this.setJourney(e);
530
- }
531
- getToken() {
532
- let e = this.journey;
533
- if (e === null) return;
534
- let t = mt(e);
535
- if (t.length > 256) this.diagnostics.report("journey.token_too_large", "The journey token is larger than the size limit. The library does not issue it.", { length: t.length });
536
- else return t;
537
- }
538
- adopt(e, t, n = !1) {
539
- let r = this.decodeToken(e);
540
- return r === null ? !1 : Date.now() - r.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "The library discarded a seeded journey older than maxAgeMs.", {
541
- source: t,
542
- name: r.name
543
- }), !1) : (this.setJourney(r), this.diagnostics.report("journey.adopted", `The library adopted the journey "${r.name}".`, {
544
- source: t,
545
- journeyId: r.id
546
- }), n && this.onLocalChange(r), !0);
547
- }
548
- ownerClosed(e) {
549
- this.options.endOnOwnerClose && this.journey?.ownerContextId === e && this.end();
550
- }
551
- destroy() {
552
- this.clearTimer();
553
- }
554
- restore(e) {
555
- let t = ft(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
556
- return t === null ? !1 : Date.now() - t.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "The library discarded a persisted journey older than maxAgeMs.", { name: t.name }), this.clearStored(), !1) : (this.setJourney(t), this.diagnostics.report("journey.adopted", `The library resumed the journey "${t.name}".`, {
557
- source: "sessionStorage",
558
- journeyId: t.id
559
- }), !0);
560
- }
561
- decodeToken(e) {
562
- return this.diagnostics.guard("config.invalid", "The library could not decode a seeded journey token.", () => {
563
- let t = e.replace(ye, "+").replace(ge, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
564
- return pt(JSON.parse(new TextDecoder().decode(i)));
565
- }) ?? null;
566
- }
567
- setJourney(e) {
568
- if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "The library could not save the journey.", () => {
569
- e === null ? this.stores.session().removeItem(O) : this.stores.session().setItem(O, JSON.stringify(e));
570
- }), e === null) return;
571
- let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
572
- this.diagnostics.report("journey.expired", `The journey "${e.name}" reached maxAgeMs. The library ended it.`, { journeyId: e.id }), this.journey = null, this.expiryTimer = null, this.clearStored();
573
- }, t);
574
- this.expiryTimer = n, Ve(n);
575
- }
576
- clearStored() {
577
- this.diagnostics.guard("storage.unavailable", "The library could not clear the persisted journey.", () => {
578
- this.stores.session().removeItem(O);
579
- });
685
+ pending = /* @__PURE__ */ new Map();
686
+ scheduled = !1;
687
+ reporting = !1;
688
+ constructor(e, t) {
689
+ this.config = e, this.diagnostics = t;
690
+ }
691
+ add(e, t, n = []) {
692
+ if (!this.config.onDrop || this.reporting || t.length === 0 && n.length === 0) return;
693
+ let r = this.pending.get(e);
694
+ r || (r = {
695
+ reason: e,
696
+ records: 0,
697
+ batchIds: [],
698
+ journeyIds: [],
699
+ actions: []
700
+ }, this.pending.set(e, r)), r.records += t.length;
701
+ for (let e of n) K(r.batchIds, e);
702
+ for (let e of t) {
703
+ let t = Ue(e, w);
704
+ typeof t == "string" && K(r.journeyIds, t);
705
+ let n = j(e) ? e.body : void 0;
706
+ typeof n == "string" && K(r.actions, n);
707
+ }
708
+ this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
709
+ this.flush();
710
+ }));
711
+ }
712
+ flush() {
713
+ this.scheduled = !1;
714
+ let e = [...this.pending.values()];
715
+ this.pending.clear();
716
+ let t = this.config.onDrop;
717
+ if (t) {
718
+ this.reporting = !0;
719
+ for (let n of e) this.diagnostics.guard("handler.threw", "The onDrop hook threw an error.", () => {
720
+ We(() => {
721
+ O(() => {
722
+ t(n);
723
+ });
724
+ });
725
+ });
726
+ this.reporting = !1;
727
+ }
580
728
  }
581
- clearTimer() {
582
- this.expiryTimer !== null && (clearTimeout(this.expiryTimer), this.expiryTimer = null);
729
+ }, un = class {
730
+ onDrop;
731
+ held = [];
732
+ actions = 0;
733
+ constructor(e) {
734
+ this.onDrop = e;
583
735
  }
584
- readUrlToken() {
585
- return this.diagnostics.guard("config.invalid", "The library could not read the journey token from the URL.", () => typeof location > "u" ? null : new URL(location.href).searchParams.get(this.options.urlParam)) ?? null;
736
+ get records() {
737
+ return this.held;
586
738
  }
587
- async readOpenFinToken() {
588
- let e = globalThis.fin?.me, t = e?.getOptions;
589
- if (t === void 0) return null;
590
- let n = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => De(t.call(e), Te)))?.customData?.[re];
591
- return typeof n == "string" ? n : null;
739
+ get length() {
740
+ return this.held.length;
592
741
  }
593
- };
594
- //#endregion
595
- //#region src/core/record.ts
596
- function K(e) {
742
+ push(e) {
743
+ let t = j(e);
744
+ if ((t ? this.actions : this.held.length - this.actions) < (t ? 2e3 : 500)) this.actions += +!!t;
745
+ else {
746
+ let e = this.held.findIndex((e) => j(e) === t), [n] = this.held.splice(e, 1);
747
+ this.onDrop(n);
748
+ }
749
+ this.held.push(e);
750
+ }
751
+ take() {
752
+ let e = this.held;
753
+ return this.held = [], this.actions = 0, e;
754
+ }
755
+ }, dn = "error.", fn = [
756
+ se,
757
+ w,
758
+ re
759
+ ];
760
+ function q(e) {
597
761
  return e;
598
762
  }
599
- var gt = class {
763
+ var pn = class {
600
764
  deps;
601
765
  resourceCache = null;
602
766
  constructor(e) {
@@ -605,20 +769,21 @@ var gt = class {
605
769
  invalidateResource() {
606
770
  this.resourceCache = null;
607
771
  }
608
- isEnabled(e) {
609
- let { config: t } = this.deps;
610
- if (!t.enabled) return !1;
611
- let n = this.deps.remote.sampling?.minLevel() ?? t.minLevel;
612
- return b[e] >= b[n];
772
+ isEnabled(e, t) {
773
+ let { config: n } = this.deps;
774
+ if (!n.enabled) return !1;
775
+ if (t !== void 0 && ie.includes(t)) return !0;
776
+ let r = this.deps.remote.sampling?.minLevel() ?? n.minLevel;
777
+ return C[e] >= C[r];
613
778
  }
614
779
  build(e) {
615
780
  let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o, remote: s } = this.deps;
616
- if (!this.isEnabled(e.level)) return n.count("record.dropped_by_level"), {
781
+ if (!this.isEnabled(e.level, e.type)) return n.count("record.dropped_by_level"), {
617
782
  record: null,
618
783
  dropped: "level"
619
784
  };
620
785
  let c = r.resolve(), l = i.current();
621
- if (!Me({
786
+ if (!Ae({
622
787
  level: e.level,
623
788
  type: e.type,
624
789
  namespace: e.namespace,
@@ -628,91 +793,146 @@ var gt = class {
628
793
  record: null,
629
794
  dropped: "sampling"
630
795
  };
631
- let u = a.next(), d = Be(n), f = t.capture.fullUrls ? d : ze(d), p, m = 0;
796
+ let u = a.next(), d = He(n), f = t.capture.fullUrls ? d : Ve(d), p, m = 0;
632
797
  try {
633
- let t = F(this.deps.context.getAll(), o, n), r = F(e.scoped ?? {}, o, n), i = F(e.payload ?? {}, o, n);
798
+ let t = k(this.deps.context.getAll(), o, n), r = k(e.scoped ?? {}, o, n), i = k(e.payload ?? {}, o, n);
634
799
  m = t.bytes + r.bytes + i.bytes, p = {
635
- ...K(t.value),
636
- ...K(r.value),
637
- ...K(i.value)
800
+ ...q(t.value),
801
+ ...q(r.value),
802
+ ...q(i.value)
638
803
  };
639
804
  } catch (e) {
640
- n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [ae]: !0 };
805
+ n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [ge]: !0 };
641
806
  }
642
- p[w] = e.type, p[x] = u, p[T] = e.namespace, p[k] = f, l && (p[y] = l.id, p[E] = l.name, l.parentId !== void 0 && (p[xe] = l.parentId));
643
- let h = Ie(e.body, o.maxBodyChars);
807
+ p[b] = e.type, p[T] = u, p[me] = e.namespace, p[se] = f, l && (p[w] = l.id, p[re] = l.name, l.parentId !== void 0 && (p[fe] = l.parentId));
808
+ let h = Me(e.body, o.maxBodyChars);
644
809
  h !== e.body && n.count("record.truncated");
645
810
  let g = {
646
- timeUnixNano: Ae(),
811
+ timeUnixNano: ke(),
647
812
  traceId: c.traceId,
648
813
  spanId: c.spanId,
649
814
  traceFlags: c.traceFlags,
650
- severityNumber: te[e.level],
815
+ severityNumber: x[e.level],
651
816
  severityText: e.level,
652
817
  body: h,
653
818
  attributes: p,
654
819
  resource: this.resource()
655
820
  }, _ = t.redact;
656
821
  if (_) {
657
- let e = n.guard("record.sanitize_failed", "The redact hook threw an error.", () => _(g));
822
+ let e;
823
+ try {
824
+ e = _(g);
825
+ } catch (e) {
826
+ return n.report("record.dropped_by_redact", "The redact hook threw an error. The library dropped the record.", void 0, e), {
827
+ record: null,
828
+ dropped: "redact"
829
+ };
830
+ }
658
831
  if (e === null) return n.count("record.dropped_by_redact"), {
659
832
  record: null,
660
833
  dropped: "redact"
661
834
  };
662
- if (e !== void 0 && e !== g) {
663
- if (N(e)) {
664
- let t = F(e.attributes, o, n);
835
+ let t = e ?? g;
836
+ if (!D(t)) return t === g ? (n.report("record.dropped_malformed", "The redact hook changed the record to a shape that is not a record. The library dropped it."), {
837
+ record: null,
838
+ dropped: "malformed"
839
+ }) : (n.report("record.dropped_by_redact", "The redact hook returned a value that is not a record. The library dropped the record."), {
840
+ record: null,
841
+ dropped: "redact"
842
+ });
843
+ if (De(t.severityText)) {
844
+ if (t !== g) {
845
+ let e = k(t.attributes, o, n);
665
846
  g = {
666
- ...e,
667
- attributes: K(t.value)
668
- }, m = t.bytes;
669
- } else n.report("record.sanitize_failed", "The redact hook returned a value that is not a record. The library keeps the original record.");
670
- }
847
+ ...t,
848
+ attributes: q(e.value)
849
+ }, m = e.bytes;
850
+ }
851
+ g.severityNumber = x[g.severityText];
852
+ } else return n.report("record.dropped_malformed", "The redact hook set a severityText that is not a log level. The library dropped the record."), {
853
+ record: null,
854
+ dropped: "malformed"
855
+ };
671
856
  }
672
857
  if (m > o.maxRecordBytes) {
673
- n.report("record.truncated", "The attributes are larger than the size limit. The library dropped them.", {
858
+ n.report("record.truncated", "The attributes are larger than the size limit. The library dropped the caller attributes.", {
674
859
  bytes: m,
675
860
  body: g.body
676
861
  });
677
862
  let t = {
678
- [w]: e.type,
679
- [x]: u,
680
- [T]: e.namespace,
681
- [k]: f,
682
- [de]: !0,
683
- [be]: m
863
+ [b]: e.type,
864
+ [T]: u,
865
+ [me]: e.namespace,
866
+ [le]: !0,
867
+ [ye]: m
684
868
  };
685
- l && (t[y] = l.id, t[E] = l.name), g.attributes = t;
869
+ for (let e of fn) e in g.attributes && (t[e] = g.attributes[e]);
870
+ for (let [e, n] of Object.entries(g.attributes)) e.startsWith(dn) && (t[e] = n);
871
+ let r = k(t, o, n).bytes;
872
+ r > o.maxRecordBytes && "error.data" in t && (Reflect.deleteProperty(t, he), r = k(t, o, n).bytes);
873
+ let i = g.attributes[y];
874
+ if (i !== void 0) {
875
+ let e = k(i, o, n).bytes;
876
+ r + e <= o.maxRecordBytes && (t[y] = i);
877
+ }
878
+ g.attributes = t;
686
879
  }
687
880
  return { record: g };
688
881
  }
689
882
  resource() {
690
883
  if (this.resourceCache) return this.resourceCache;
691
- let { config: n, identity: r, platform: i } = this.deps;
884
+ let { config: e, identity: n, platform: r } = this.deps;
692
885
  return this.resourceCache = {
693
- [g]: n.serviceName,
694
- [s]: n.serviceVersion,
695
- [e]: n.environment,
696
- [Ee]: he,
697
- [t]: we,
698
- [_]: ie,
699
- [pe]: i.platform,
700
- [l]: r.sessionId,
701
- [u]: r.tabId,
702
- [me]: r.contextId,
703
- [h]: i.userAgent,
704
- ...i.openfinUuid === void 0 ? {} : { [m]: i.openfinUuid },
705
- ...i.openfinName === void 0 ? {} : { [f]: i.openfinName }
886
+ [u]: e.serviceName,
887
+ [_]: e.serviceVersion,
888
+ [f]: e.environment,
889
+ [o]: ae,
890
+ [ee]: S,
891
+ [te]: xe,
892
+ [h]: r.platform,
893
+ [Ce]: n.sessionId,
894
+ [t]: n.tabId,
895
+ [d]: n.contextId,
896
+ [ue]: r.userAgent,
897
+ ...r.openfinUuid === void 0 ? {} : { [c]: r.openfinUuid },
898
+ ...r.openfinName === void 0 ? {} : { [a]: r.openfinName }
706
899
  }, this.resourceCache;
707
900
  }
708
- }, _t = {
709
- errors: async () => (await import("./errors-Dnc-X4Ec.js")).ErrorCapture,
710
- network: async () => (await import("./network-aSNbwpue.js")).NetworkCapture,
711
- interactions: async () => (await import("./interactions-igKTAJvj.js")).InteractionCapture,
712
- webVitals: async () => (await import("./web-vitals-DHZ0yA_H.js")).WebVitalsCapture,
713
- longFrames: async () => (await import("./long-frames-6pnjWSSR.js")).LongFrameCapture,
714
- console: async () => (await import("./console-CNljJict.js")).ConsoleCapture
715
- }, q = Symbol.for(ee), J = Symbol.for(c), Y = class e {
901
+ }, mn = {
902
+ errors: async () => (await import("./errors-CQusIGWJ.js")).ErrorCapture,
903
+ network: async () => (await import("./network-51iicpLl.js")).NetworkCapture,
904
+ interactions: async () => (await import("./interactions-CnjfQgw3.js")).InteractionCapture,
905
+ webVitals: async () => (await import("./web-vitals-Bflr5jSA.js")).WebVitalsCapture,
906
+ longFrames: async () => (await import("./long-frames-CZk3XOkH.js")).LongFrameCapture,
907
+ console: async () => (await import("./console-C9Y639mn.js")).ConsoleCapture
908
+ }, J = Symbol.for(ve), Y = Symbol.for(l), hn = ["batching", "retention"];
909
+ function gn(e) {
910
+ return JSON.stringify({
911
+ ...e,
912
+ webVitalsLoader: e.webVitalsLoader !== void 0,
913
+ ignoreUrls: e.ignoreUrls.map(String),
914
+ propagateTraceHeaderTo: e.propagateTraceHeaderTo.map(String)
915
+ });
916
+ }
917
+ function _n(e) {
918
+ return {
919
+ ...e,
920
+ endpoint: null,
921
+ transport: void 0,
922
+ transportOnExit: void 0,
923
+ bus: {
924
+ ...e.bus,
925
+ mode: "off"
926
+ }
927
+ };
928
+ }
929
+ function X(e) {
930
+ return e.sdkVersion === S;
931
+ }
932
+ var Z = class e {
933
+ degraded;
934
+ static local = null;
935
+ sdkVersion = S;
716
936
  diagnostics;
717
937
  config;
718
938
  platform;
@@ -720,21 +940,24 @@ var gt = class {
720
940
  stores;
721
941
  identityBuiltAs;
722
942
  sessionTouch;
723
- context = new lt();
943
+ context = new sn();
724
944
  breadcrumbs;
725
945
  tracing;
726
- sequence = new Je();
946
+ sequence = new it();
727
947
  journey;
728
948
  builder;
729
949
  remote = { sampling: null };
730
950
  console;
951
+ drops;
731
952
  bus = null;
732
953
  busBuilt;
733
954
  busLoad;
734
955
  storageBuiltAs;
735
956
  sender;
736
957
  senderLoad;
737
- pendingRecords = [];
958
+ pendingRecords = new un((e) => {
959
+ this.dropHeld(e);
960
+ });
738
961
  captures = [];
739
962
  captureGeneration = 0;
740
963
  captureOnce = {
@@ -742,7 +965,9 @@ var gt = class {
742
965
  navigationTiming: !1,
743
966
  longFrames: !1
744
967
  };
745
- bootBuffer = [];
968
+ bootBuffer = new un((e) => {
969
+ this.dropHeld(e);
970
+ });
746
971
  forwardBuffer = [];
747
972
  forwardScheduled = !1;
748
973
  roleResolved = !1;
@@ -750,13 +975,19 @@ var gt = class {
750
975
  ready = !1;
751
976
  destroyed = !1;
752
977
  lastGapAt = 0;
753
- constructor(e) {
754
- this.diagnostics = new ut(e.onDiagnostic), this.platform = Re(this.diagnostics), this.config = U(e, this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" ? Oe() : M, this.identity = ke(this.diagnostics, this.stores), this.sessionTouch = new Ne(this.diagnostics, this.stores), this.breadcrumbs = new tt(50), this.tracing = new et(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new qe(this.config.console, this.diagnostics), this.journey = new ht(dt, this.diagnostics, this.identity.contextId, (e) => {
978
+ limits;
979
+ journeyOptions;
980
+ tunablesLocked = !0;
981
+ constructor(e, t = !1) {
982
+ this.degraded = t, this.diagnostics = new cn(e.onDiagnostic), this.platform = Be(this.diagnostics), this.config = rn(e, this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" ? Le() : ze, this.identity = Re(this.diagnostics, this.stores), this.sessionTouch = new Ie(this.diagnostics, this.stores), this.breadcrumbs = new mt(50), this.tracing = new pt(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.limits = { ...this.config.limits }, this.console = new rt(this.config.console, this.diagnostics, this.limits), this.drops = new ln(this.config, this.diagnostics), this.journeyOptions = {
983
+ ...Ke,
984
+ maxAgeMs: this.config.journey.maxAgeMs
985
+ }, this.journey = new Ge(this.journeyOptions, this.diagnostics, this.identity.contextId, (e) => {
755
986
  this.bus?.broadcastJourney(e);
756
- }, this.stores), this.builder = new gt({
987
+ }, this.stores), this.builder = new pn({
757
988
  remote: this.remote,
758
989
  config: this.config,
759
- limits: r,
990
+ limits: this.limits,
760
991
  diagnostics: this.diagnostics,
761
992
  context: this.context,
762
993
  journey: this.journey,
@@ -773,24 +1004,60 @@ var gt = class {
773
1004
  });
774
1005
  });
775
1006
  };
1007
+ static pinned() {
1008
+ return globalThis[J] ?? null;
1009
+ }
776
1010
  static current() {
777
- return globalThis[q] ?? null;
1011
+ let t = e.local;
1012
+ if (t) return t.destroyed ? null : t;
1013
+ let n = e.pinned();
1014
+ return n && X(n) ? n : null;
778
1015
  }
779
1016
  static stopped() {
780
- return globalThis[J] ?? null;
1017
+ let t = e.local;
1018
+ if (t?.destroyed) return t;
1019
+ let n = globalThis[Y];
1020
+ return n && X(n) ? n : null;
781
1021
  }
782
1022
  isDestroyed() {
783
1023
  return this.destroyed;
784
1024
  }
785
- static configure(t) {
786
- let n = e.current();
787
- if (n && !n.destroyed) return n.reconfigure(t), n;
788
- let r = new e(t);
789
- return globalThis[q] = r, Reflect.deleteProperty(globalThis, J), r.init(), r;
1025
+ static configure(t, n = !1) {
1026
+ let r = e.local;
1027
+ if (r && !r.destroyed) return r.reconfigure(_n(t)), r;
1028
+ e.local = null;
1029
+ let i = e.pinned();
1030
+ if (i) {
1031
+ if (!X(i)) return e.startDegraded(t, i.sdkVersion);
1032
+ if (!i.destroyed) return i.reconfigure(t), i;
1033
+ }
1034
+ let a = new e(t);
1035
+ return a.tunablesLocked = !n, globalThis[J] = a, Reflect.deleteProperty(globalThis, Y), a.init(), a;
1036
+ }
1037
+ static startDegraded(t, n) {
1038
+ let r = new e(_n(t), !0);
1039
+ e.local = r;
1040
+ let i = typeof n == "string" ? n : "before 0.9.0";
1041
+ return r.diagnostics.report("runtime.version_mismatch", `Another copy of the library, version ${i}, owns the page runtime. This copy, version ${S}, runs in console-only mode and installs no capture. Load one version of the library on the page.`, {
1042
+ found: i,
1043
+ own: S
1044
+ }), r.init(), r;
790
1045
  }
791
1046
  reconfigure(e) {
792
- let t = this.keepDestination(e);
793
- ct(this.config, U(t, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), this.installCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1047
+ let t = this.keepDestination(e), n = gn(this.config.capture), r = rn(t, this.diagnostics, this.config);
1048
+ this.keepStartupTunables(r), on(this.config, r), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), gn(this.config.capture) !== n && this.installCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1049
+ }
1050
+ keepStartupTunables(e) {
1051
+ if (this.senderLoad !== void 0 && this.keepSections(e, hn), !this.tunablesLocked) {
1052
+ this.tunablesLocked = !0, Object.assign(this.limits, e.limits), this.journeyOptions.maxAgeMs = e.journey.maxAgeMs;
1053
+ return;
1054
+ }
1055
+ this.keepSections(e, ["limits"]);
1056
+ let { maxAgeMs: t } = this.config.journey;
1057
+ e.journey.maxAgeMs !== t && (this.diagnostics.report("config.invalid", `journey.maxAgeMs cannot change after startup. It stays ${String(t)}.`, { requested: e.journey.maxAgeMs }), e.journey.maxAgeMs = t);
1058
+ }
1059
+ keepSections(e, t) {
1060
+ for (let n of t) JSON.stringify(e[n]) !== JSON.stringify(this.config[n]) && (this.diagnostics.report("config.invalid", `${n} cannot change after startup. The values in force stay.`, { requested: e[n] }), Object.assign(e, { [n]: this.config[n] }));
794
1061
  }
795
1062
  keepBuiltStorage() {
796
1063
  let e = this.storageBuiltAs;
@@ -839,7 +1106,7 @@ var gt = class {
839
1106
  }
840
1107
  async buildBus() {
841
1108
  try {
842
- let { Bus: e } = await import("./bus-DPDrlUBY.js");
1109
+ let { Bus: e } = await import("./bus-HVQ8E72V.js");
843
1110
  if (this.destroyed) return null;
844
1111
  let t = new e(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
845
1112
  onRecords: (e) => {
@@ -863,7 +1130,10 @@ var gt = class {
863
1130
  return this.bus?.getRole() ?? "sender";
864
1131
  }
865
1132
  syncSender() {
866
- return !(this.config.endpoint || this.config.transport !== void 0) || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
1133
+ return !this.hasDestination() || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
1134
+ }
1135
+ hasDestination() {
1136
+ return !!this.config.endpoint || this.config.transport !== void 0;
867
1137
  }
868
1138
  loadSender() {
869
1139
  return this.senderLoad ??= this.buildSender(), this.senderLoad;
@@ -871,10 +1141,11 @@ var gt = class {
871
1141
  async buildSender() {
872
1142
  this.storageBuiltAs = this.config.storage;
873
1143
  try {
874
- let { Sender: e } = await import("./sender-G6v4Uqi4.js"), t = this.destroyed ? null : await e.create({
1144
+ let { Sender: e } = await import("./sender-BBY0IcUo.js"), t = this.destroyed ? null : await e.create({
875
1145
  config: this.config,
876
1146
  diagnostics: this.diagnostics,
877
1147
  onGap: this.reportGap,
1148
+ onLoss: this.reportLoss,
878
1149
  remote: this.remote
879
1150
  });
880
1151
  if (!t || this.destroyed) {
@@ -883,13 +1154,12 @@ var gt = class {
883
1154
  }
884
1155
  this.sender = t;
885
1156
  } catch (e) {
886
- this.senderLoad = void 0, this.diagnostics.report("pipeline.crashed", "The delivery stack did not load. The library does not send records.", { held: this.pendingRecords.length }, e);
1157
+ this.senderLoad = void 0, this.diagnostics.report("pipeline.crashed", "The delivery stack did not load. The library does not send records.", { held: this.pendingRecords.length }, e), this.drops.add("load_failed", this.pendingRecords.records);
887
1158
  }
888
- let e = this.pendingRecords;
889
- this.pendingRecords = [];
890
- for (let t of e) this.sender?.push(t);
1159
+ for (let e of this.pendingRecords.take()) this.sender?.push(e);
891
1160
  }
892
1161
  async installCaptures() {
1162
+ if (this.degraded) return;
893
1163
  let e = ++this.captureGeneration, t = this.config.capture, r = [];
894
1164
  (t.errors || t.rejections || t.resourceErrors) && r.push("errors"), (t.fetch || t.xhr) && r.push("network"), (t.interactions || t.navigation) && r.push("interactions"), t.webVitals && r.push("webVitals"), t.longFrames && r.push("longFrames"), (Array.isArray(t.console) ? t.console.length > 0 : t.console) && r.push("console");
895
1165
  let i = await Promise.all(r.map((e) => this.loadCapture(e)));
@@ -900,7 +1170,7 @@ var gt = class {
900
1170
  diagnostics: this.diagnostics,
901
1171
  breadcrumbs: this.breadcrumbs,
902
1172
  tracing: this.tracing,
903
- logger: new z(() => this, n),
1173
+ logger: new F(() => this, n),
904
1174
  once: this.captureOnce
905
1175
  };
906
1176
  for (let e of i) e && this.captures.push(new e(a));
@@ -915,7 +1185,7 @@ var gt = class {
915
1185
  this.captures.length = 0;
916
1186
  }
917
1187
  loadCapture(e) {
918
- return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, _t[e]);
1188
+ return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, mn[e]);
919
1189
  }
920
1190
  registerWorker(e) {
921
1191
  this.destroyed || this.constructBus().then((t) => {
@@ -928,47 +1198,51 @@ var gt = class {
928
1198
  if (this.destroyed) return;
929
1199
  this.destroyed = !0, this.uninstallCaptures();
930
1200
  let t = this.sender?.destroy();
931
- this.journey.destroy(), this.bus?.destroy(), this.forwardBuffer = [], this.pendingRecords = [], await t, await this.senderLoad, e.current() === this && (Reflect.deleteProperty(globalThis, q), globalThis[J] = this);
1201
+ this.journey.destroy(), this.sendForwarded(), this.bus?.destroy(), this.drops.add("load_failed", this.pendingRecords.take()), await t, await this.senderLoad, e.pinned() === this && (Reflect.deleteProperty(globalThis, J), globalThis[Y] = this);
932
1202
  }
933
1203
  emit(e) {
934
- e && !this.destroyed && (this.sessionTouch.touch(this.identity.sessionId), this.ready ? this.route(e) : this.pushCapped(this.bootBuffer, e));
1204
+ e && !this.destroyed && (this.sessionTouch.touch(this.identity.sessionId), this.ready ? this.route(e) : this.bootBuffer.push(e));
935
1205
  }
936
1206
  route(e) {
937
1207
  this.role() === "forwarder" ? this.forward(e) : this.deliver(e);
938
1208
  }
939
1209
  deliver(e) {
940
- this.sender ? this.sender.push(e) : this.senderLoad && this.pushCapped(this.pendingRecords, e);
1210
+ this.sender ? this.sender.push(e) : this.senderLoad ? this.pendingRecords.push(e) : (this.diagnostics.count("record.dropped_no_destination"), this.hasDestination() && this.drops.add("load_failed", [e]));
941
1211
  }
942
- pushCapped(e, t) {
943
- e.length >= 500 && (e.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), e.push(t);
1212
+ dropHeld(e) {
1213
+ this.diagnostics.count("record.dropped_boot_buffer_full"), this.drops.add("buffer_full", [e]);
944
1214
  }
945
1215
  forward(e) {
946
1216
  this.forwardBuffer.push(e), !this.forwardScheduled && (this.forwardScheduled = !0, queueMicrotask(() => {
947
- this.forwardScheduled = !1;
948
- let e = this.forwardBuffer;
949
- this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
1217
+ this.forwardScheduled = !1, this.sendForwarded();
950
1218
  }));
951
1219
  }
1220
+ sendForwarded() {
1221
+ let e = this.forwardBuffer;
1222
+ this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
1223
+ }
952
1224
  ingestForwarded(e) {
953
1225
  if (!Array.isArray(e)) this.diagnostics.count("record.dropped_malformed");
954
- else for (let t of e) N(t) ? je(t, this.config, this.remote.sampling?.current() ?? null) ? this.deliver(t) : this.diagnostics.count("record.dropped_by_sampling") : this.diagnostics.count("record.dropped_malformed");
1226
+ else for (let t of e) D(t) ? Oe(t, this.config, this.remote.sampling?.current() ?? null) ? this.deliver(t) : this.diagnostics.count("record.dropped_by_sampling") : this.diagnostics.count("record.dropped_malformed");
955
1227
  }
956
1228
  releaseBootBuffer() {
957
- let e = this.bootBuffer;
958
- this.bootBuffer = [];
959
- let t = this.journey.current();
1229
+ let e = this.bootBuffer.take(), t = this.journey.current();
960
1230
  for (let n of e) t && !n.attributes["journey.id"] && (n.attributes["journey.id"] = t.id, n.attributes["journey.name"] = t.name), this.route(n);
961
1231
  }
962
- reportGap = (e) => {
963
- let t = Date.now();
964
- t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new z(() => this, Ce).warn("stored records were dropped before delivery", {
1232
+ reportLoss = (e, t, n) => {
1233
+ this.drops.add(e, t, n);
1234
+ };
1235
+ reportGap = (e, t) => {
1236
+ this.drops.add(e.reason, t.flatMap((e) => e.records), t.map((e) => e.id));
1237
+ let n = Date.now();
1238
+ n - this.lastGapAt < 6e4 || (this.lastGapAt = n, new F(() => this, be).warn("stored records were dropped before delivery", {
965
1239
  "gap.batches": e.batches,
966
1240
  "gap.records": e.records,
967
1241
  "gap.reason": e.reason
968
1242
  }));
969
1243
  };
970
1244
  regenerateTabId() {
971
- let e = j(this.diagnostics);
1245
+ let e = Fe(this.diagnostics);
972
1246
  this.diagnostics.report("bus.role_resolved", "Another context uses this tab id. A duplicated tab is the usual cause. The library makes a new tab id.", {
973
1247
  was: this.identity.tabId,
974
1248
  now: e
@@ -978,15 +1252,12 @@ var gt = class {
978
1252
  return await this.senderLoad, await this.sender?.queueDepth() ?? 0;
979
1253
  }
980
1254
  async flush() {
981
- if (this.ready || await this.started, this.role() === "forwarder") {
982
- let e = this.forwardBuffer;
983
- this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
984
- } else await this.senderLoad, await this.sender?.flush();
1255
+ this.ready || await this.started, this.role() === "forwarder" ? this.sendForwarded() : (await this.senderLoad, await this.sender?.flush());
985
1256
  }
986
1257
  };
987
1258
  //#endregion
988
1259
  //#region src/transport/memory-transport.ts
989
- function vt() {
1260
+ function vn() {
990
1261
  let e = [], t = [], n = { status: 200 };
991
1262
  return {
992
1263
  transport: (r) => (e.push(r), n.status >= 200 && n.status < 300 && t.push(r), Promise.resolve({ ...n })),
@@ -1005,97 +1276,100 @@ function vt() {
1005
1276
  }
1006
1277
  //#endregion
1007
1278
  //#region src/index.ts
1008
- var X = /* @__PURE__ */ new Map();
1009
- function Z() {
1010
- return (Y.current() ?? Y.stopped()) || Y.configure({});
1279
+ var yn = /* @__PURE__ */ new Map();
1280
+ function Q() {
1281
+ return (Z.current() ?? Z.stopped()) || Z.configure({}, !0);
1011
1282
  }
1012
- function yt(e) {
1013
- Y.configure(e);
1283
+ function bn(e) {
1284
+ Z.configure(e);
1014
1285
  }
1015
- function Q(e, t) {
1016
- if (t) return new z(Z, e, t);
1017
- let n = X.get(e);
1018
- return n || (n = new z(Z, e), X.set(e, n)), n;
1286
+ function xn(e, t) {
1287
+ if (t) return new F(Q, e, t);
1288
+ let n = yn.get(e);
1289
+ return n || (n = new F(Q, e), yn.set(e, n)), n;
1019
1290
  }
1020
1291
  function $() {
1021
- return Q("app");
1292
+ return xn("app");
1022
1293
  }
1023
- function bt(e, t) {
1294
+ function Sn(e, t) {
1024
1295
  $().trace(e, t);
1025
1296
  }
1026
- function xt(e, t) {
1297
+ function Cn(e, t) {
1027
1298
  $().debug(e, t);
1028
1299
  }
1029
- function St(e, t) {
1300
+ function wn(e, t) {
1030
1301
  $().info(e, t);
1031
1302
  }
1032
- function Ct(e, t) {
1303
+ function Tn(e, t) {
1033
1304
  $().warn(e, t);
1034
1305
  }
1035
- function wt(e, t, n) {
1306
+ function En(e, t, n) {
1036
1307
  $().error(e, t, n);
1037
1308
  }
1038
- function Tt(e, t) {
1309
+ function Dn(e, t, n) {
1310
+ $().fatal(e, t, n);
1311
+ }
1312
+ function On(e, t) {
1039
1313
  $().logAction(e, t);
1040
1314
  }
1041
- function Et(e, t) {
1315
+ function kn(e, t) {
1042
1316
  $().logEvent(e, t);
1043
1317
  }
1044
- function Dt(e, t, n, r, i) {
1318
+ function An(e, t, n, r, i) {
1045
1319
  $().logMetric(e, t, n, r, i);
1046
1320
  }
1047
- function Ot(e, t, n) {
1321
+ function jn(e, t, n) {
1048
1322
  return $().timeSync(e, t, n);
1049
1323
  }
1050
- function kt(e, t, n) {
1324
+ function Mn(e, t, n) {
1051
1325
  return $().timeAsync(e, t, n);
1052
1326
  }
1053
- function At(e, t) {
1054
- Z().context.set(e, t);
1327
+ function Nn(e, t) {
1328
+ Q().context.set(e, t);
1055
1329
  }
1056
- function jt(e) {
1057
- Z().context.setMany(e);
1330
+ function Pn(e) {
1331
+ Q().context.setMany(e);
1058
1332
  }
1059
- function Mt(e) {
1060
- Z().context.remove(e);
1333
+ function Fn(e) {
1334
+ Q().context.remove(e);
1061
1335
  }
1062
- function Nt(e, t) {
1063
- return Z().journey.start(e, t);
1336
+ function In(e, t) {
1337
+ return Q().journey.start(e, t);
1064
1338
  }
1065
- function Pt() {
1066
- Z().journey.end();
1339
+ function Ln() {
1340
+ Q().journey.end();
1067
1341
  }
1068
- function Ft() {
1069
- return Z().journey.current();
1342
+ function Rn() {
1343
+ return Q().journey.current();
1070
1344
  }
1071
- function It() {
1072
- return Z().journey.getToken();
1345
+ function zn() {
1346
+ return Q().journey.getToken();
1073
1347
  }
1074
- function Lt(e) {
1075
- return Z().journey.adopt(e, "manual", !0);
1348
+ function Bn(e) {
1349
+ return Q().journey.adopt(e, "manual", !0);
1076
1350
  }
1077
- function Rt(e) {
1078
- Z().registerWorker(e);
1351
+ function Vn(e) {
1352
+ Q().registerWorker(e);
1079
1353
  }
1080
- function zt() {
1081
- Z().tracing.rotate("explicit");
1354
+ function Hn() {
1355
+ Q().tracing.rotate("explicit");
1082
1356
  }
1083
- function Bt() {
1084
- return Z().tracing.headers();
1357
+ function Un() {
1358
+ return Q().tracing.headers();
1085
1359
  }
1086
- function Vt() {
1087
- return Z().flush();
1360
+ function Wn() {
1361
+ return Q().flush();
1088
1362
  }
1089
- function Ht() {
1090
- return Z().queueDepth();
1363
+ function Gn() {
1364
+ return Q().queueDepth();
1091
1365
  }
1092
- function Ut() {
1093
- return Z().diagnostics.snapshot();
1366
+ function Kn() {
1367
+ return Q().diagnostics.snapshot();
1094
1368
  }
1095
- async function Wt() {
1096
- await Y.current()?.destroy();
1369
+ async function qn() {
1370
+ await Z.current()?.destroy();
1097
1371
  }
1098
1372
  //#endregion
1099
- export { z as OneLogger, Lt as adoptJourney, yt as configure, vt as createMemoryTransport, Ft as currentJourney, xt as debug, Pt as endJourney, wt as error, Vt as flush, Ut as getDiagnosticCounters, It as getJourneyToken, Q as getLogger, Ht as getQueueDepth, Bt as getTraceHeaders, St as info, Tt as logAction, Et as logEvent, Dt as logMetric, Rt as registerWorker, Mt as removeContext, At as setContext, jt as setContextMap, Wt as shutdown, Nt as startJourney, zt as startTrace, kt as timeAsync, Ot as timeSync, bt as trace, Ct as warn };
1373
+ export { F as OneLogger, Bn as adoptJourney, bn as configure, vn as createMemoryTransport, Rn as currentJourney, Cn as debug, Ln as endJourney, En as error, Dn as fatal, Wn as flush, Kn as getDiagnosticCounters, zn as getJourneyToken, xn as getLogger, Gn as getQueueDepth, Un as getTraceHeaders, wn as info, On as logAction, kn as logEvent, An as logMetric, Vn as registerWorker, Fn as removeContext, Nn as setContext, Pn as setContextMap, qn as shutdown, In as startJourney, Hn as startTrace, Mn as timeAsync, jn as timeSync, Sn as trace, Tn as warn };
1100
1374
 
1101
1375
  //# sourceMappingURL=index.js.map