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