@utk09/ui-observability 0.9.3 → 0.9.4

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 (156) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +108 -33
  3. package/dist/{batch-D5qvsMQ_.cjs → batch-C4oF6XZT.cjs} +2 -2
  4. package/dist/{batch-D5qvsMQ_.cjs.map → batch-C4oF6XZT.cjs.map} +1 -1
  5. package/dist/{batch-DDgxg16_.js → batch-D-4xl7op.js} +4 -4
  6. package/dist/{batch-DDgxg16_.js.map → batch-D-4xl7op.js.map} +1 -1
  7. package/dist/{bus-C6RwKzPW.js → bus-Cyvq-Ngx.js} +5 -5
  8. package/dist/{bus-C6RwKzPW.js.map → bus-Cyvq-Ngx.js.map} +1 -1
  9. package/dist/{bus-WPVDFw2y.cjs → bus-rOhVuRee.cjs} +2 -2
  10. package/dist/{bus-WPVDFw2y.cjs.map → bus-rOhVuRee.cjs.map} +1 -1
  11. package/dist/capture/network.d.ts +1 -0
  12. package/dist/capture/types.d.ts +3 -0
  13. package/dist/capture/web-socket.d.ts +40 -0
  14. package/dist/{console-Dv5GfaNn.js → console-BT7mcgU6.js} +3 -3
  15. package/dist/{console-Dv5GfaNn.js.map → console-BT7mcgU6.js.map} +1 -1
  16. package/dist/{console-BSusX_M-.cjs → console-Boqa7new.cjs} +2 -2
  17. package/dist/{console-BSusX_M-.cjs.map → console-Boqa7new.cjs.map} +1 -1
  18. package/dist/constants-BgRS6MB0.cjs +2 -0
  19. package/dist/constants-BgRS6MB0.cjs.map +1 -0
  20. package/dist/constants-L_d5YvvQ.js +160 -0
  21. package/dist/constants-L_d5YvvQ.js.map +1 -0
  22. package/dist/constants.d.ts +34 -2
  23. package/dist/core/breadcrumbs.d.ts +3 -1
  24. package/dist/core/diagnostics.d.ts +1 -1
  25. package/dist/core/journey.d.ts +7 -0
  26. package/dist/core/meter.d.ts +19 -1
  27. package/dist/core/pipeline.d.ts +12 -4
  28. package/dist/core/record.d.ts +40 -8
  29. package/dist/core/remote-sampling.d.ts +7 -3
  30. package/dist/core/runtime.d.ts +62 -3
  31. package/dist/core/sampling.d.ts +32 -1
  32. package/dist/core/sender.d.ts +8 -0
  33. package/dist/core/spans.d.ts +34 -0
  34. package/dist/{errors-DCZWcHkd.js → errors-BDI96zKc.js} +6 -6
  35. package/dist/errors-BDI96zKc.js.map +1 -0
  36. package/dist/errors-_xEsCVXn.cjs +3 -0
  37. package/dist/errors-_xEsCVXn.cjs.map +1 -0
  38. package/dist/identity-Bwku7zzN.cjs +2 -0
  39. package/dist/identity-Bwku7zzN.cjs.map +1 -0
  40. package/dist/{identity-Di-QXGCC.js → identity-Dtv917nz.js} +33 -23
  41. package/dist/identity-Dtv917nz.js.map +1 -0
  42. package/dist/index.cjs +1 -1
  43. package/dist/index.cjs.map +1 -1
  44. package/dist/index.d.ts +23 -1
  45. package/dist/index.js +803 -524
  46. package/dist/index.js.map +1 -1
  47. package/dist/{indexeddb-storage-DX18p39D.cjs → indexeddb-storage-Cvavrf-y.cjs} +2 -2
  48. package/dist/{indexeddb-storage-DX18p39D.cjs.map → indexeddb-storage-Cvavrf-y.cjs.map} +1 -1
  49. package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-HgkQUTyS.js} +26 -26
  50. package/dist/{indexeddb-storage-T9YIYVYC.js.map → indexeddb-storage-HgkQUTyS.js.map} +1 -1
  51. package/dist/{interactions-_hfOerfC.cjs → interactions-Bhe1ft8P.cjs} +2 -2
  52. package/dist/interactions-Bhe1ft8P.cjs.map +1 -0
  53. package/dist/{interactions-BLH_tX87.js → interactions-Ck01cEij.js} +3 -3
  54. package/dist/interactions-Ck01cEij.js.map +1 -0
  55. package/dist/journey-Co9OlzrW.cjs +2 -0
  56. package/dist/journey-Co9OlzrW.cjs.map +1 -0
  57. package/dist/{journey-yALMEWF7.js → journey-DRK0A8u_.js} +37 -34
  58. package/dist/journey-DRK0A8u_.js.map +1 -0
  59. package/dist/{library-request-CQD4HUiP.js → library-request-ChCar5F8.js} +3 -3
  60. package/dist/{library-request-CQD4HUiP.js.map → library-request-ChCar5F8.js.map} +1 -1
  61. package/dist/{library-request-BcAxuwsf.cjs → library-request-gMFOCNcn.cjs} +2 -2
  62. package/dist/{library-request-BcAxuwsf.cjs.map → library-request-gMFOCNcn.cjs.map} +1 -1
  63. package/dist/log-record-cwFiLyPY.js +17 -0
  64. package/dist/log-record-cwFiLyPY.js.map +1 -0
  65. package/dist/log-record-jX9eWUP8.cjs +2 -0
  66. package/dist/log-record-jX9eWUP8.cjs.map +1 -0
  67. package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-Bky6nZDF.cjs} +2 -2
  68. package/dist/long-frames-Bky6nZDF.cjs.map +1 -0
  69. package/dist/{long-frames-DD_Um9_4.js → long-frames-DDumopji.js} +4 -4
  70. package/dist/long-frames-DDumopji.js.map +1 -0
  71. package/dist/models/config.d.ts +56 -5
  72. package/dist/models/log-record.d.ts +1 -1
  73. package/dist/models/plugin.d.ts +47 -0
  74. package/dist/models/stats.d.ts +11 -0
  75. package/dist/{network--GoE7_Or.js → network-BsBZ6_-Q.js} +43 -29
  76. package/dist/network-BsBZ6_-Q.js.map +1 -0
  77. package/dist/network-_4csBGBM.cjs +2 -0
  78. package/dist/network-_4csBGBM.cjs.map +1 -0
  79. package/dist/{platform-GaM6h7XM.js → platform-4yYjMD-B.js} +11 -6
  80. package/dist/platform-4yYjMD-B.js.map +1 -0
  81. package/dist/{platform-kIL5AZB7.cjs → platform-o7r1ocOu.cjs} +2 -2
  82. package/dist/platform-o7r1ocOu.cjs.map +1 -0
  83. package/dist/remote-rules-1KqfVBIu.js +91 -0
  84. package/dist/remote-rules-1KqfVBIu.js.map +1 -0
  85. package/dist/remote-rules-BHgEGlYi.cjs +2 -0
  86. package/dist/remote-rules-BHgEGlYi.cjs.map +1 -0
  87. package/dist/sampling-C4my-ma0.cjs +2 -0
  88. package/dist/sampling-C4my-ma0.cjs.map +1 -0
  89. package/dist/sampling-nYIWP_vP.js +86 -0
  90. package/dist/sampling-nYIWP_vP.js.map +1 -0
  91. package/dist/{sanitize-DP0xDPrt.js → sanitize-BiUKCUG6.js} +2 -2
  92. package/dist/{sanitize-DP0xDPrt.js.map → sanitize-BiUKCUG6.js.map} +1 -1
  93. package/dist/{sanitize--_e4oOPX.cjs → sanitize-BxuPSXOk.cjs} +2 -2
  94. package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-BxuPSXOk.cjs.map} +1 -1
  95. package/dist/sender-6vrT9fFL.cjs +3 -0
  96. package/dist/sender-6vrT9fFL.cjs.map +1 -0
  97. package/dist/{sender-BUBWLn5i.js → sender-DFQMF39P.js} +382 -275
  98. package/dist/sender-DFQMF39P.js.map +1 -0
  99. package/dist/{storm-DhHGHhOc.cjs → storm-6YYbXzT_.cjs} +2 -2
  100. package/dist/{storm-DhHGHhOc.cjs.map → storm-6YYbXzT_.cjs.map} +1 -1
  101. package/dist/{storm-OD5J6Ylm.js → storm-CfO0Sam2.js} +2 -2
  102. package/dist/{storm-OD5J6Ylm.js.map → storm-CfO0Sam2.js.map} +1 -1
  103. package/dist/transport/exit-flush.d.ts +6 -0
  104. package/dist/transport/http-transport.d.ts +2 -1
  105. package/dist/transport/serializers/otlp-traces.d.ts +3 -0
  106. package/dist/transport/serializers/select.d.ts +8 -5
  107. package/dist/transport/status-transport.d.ts +7 -0
  108. package/dist/types-BR9t_w28.js +8 -0
  109. package/dist/types-BR9t_w28.js.map +1 -0
  110. package/dist/types-C7WNpnG1.cjs +2 -0
  111. package/dist/types-C7WNpnG1.cjs.map +1 -0
  112. package/dist/utils/identity.d.ts +11 -0
  113. package/dist/utils/platform.d.ts +8 -0
  114. package/dist/utils/tracing.d.ts +82 -4
  115. package/dist/web-socket-Ar4cZxmd.js +102 -0
  116. package/dist/web-socket-Ar4cZxmd.js.map +1 -0
  117. package/dist/web-socket-BwJdwSHl.cjs +2 -0
  118. package/dist/web-socket-BwJdwSHl.cjs.map +1 -0
  119. package/package.json +1 -1
  120. package/dist/constants-Cb92egPS.cjs +0 -2
  121. package/dist/constants-Cb92egPS.cjs.map +0 -1
  122. package/dist/constants-DhH6VI5a.js +0 -144
  123. package/dist/constants-DhH6VI5a.js.map +0 -1
  124. package/dist/deadline-CUrH0Hd8.cjs +0 -2
  125. package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
  126. package/dist/deadline-DeqXEliN.js +0 -31
  127. package/dist/deadline-DeqXEliN.js.map +0 -1
  128. package/dist/errors-DCZWcHkd.js.map +0 -1
  129. package/dist/errors-ERu-su8m.cjs +0 -3
  130. package/dist/errors-ERu-su8m.cjs.map +0 -1
  131. package/dist/identity-C1WLItSl.cjs +0 -2
  132. package/dist/identity-C1WLItSl.cjs.map +0 -1
  133. package/dist/identity-Di-QXGCC.js.map +0 -1
  134. package/dist/interactions-BLH_tX87.js.map +0 -1
  135. package/dist/interactions-_hfOerfC.cjs.map +0 -1
  136. package/dist/journey-BRUj0hqD.cjs +0 -2
  137. package/dist/journey-BRUj0hqD.cjs.map +0 -1
  138. package/dist/journey-yALMEWF7.js.map +0 -1
  139. package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
  140. package/dist/long-frames-DD_Um9_4.js.map +0 -1
  141. package/dist/network--GoE7_Or.js.map +0 -1
  142. package/dist/network-DcuS2H1P.cjs +0 -2
  143. package/dist/network-DcuS2H1P.cjs.map +0 -1
  144. package/dist/platform-GaM6h7XM.js.map +0 -1
  145. package/dist/platform-kIL5AZB7.cjs.map +0 -1
  146. package/dist/remote-rules-6ePq8CrI.js +0 -84
  147. package/dist/remote-rules-6ePq8CrI.js.map +0 -1
  148. package/dist/remote-rules-CI3gbRCL.cjs +0 -2
  149. package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
  150. package/dist/sampling-C-M8p3FK.cjs +0 -2
  151. package/dist/sampling-C-M8p3FK.cjs.map +0 -1
  152. package/dist/sampling-Ud_WiuU9.js +0 -65
  153. package/dist/sampling-Ud_WiuU9.js.map +0 -1
  154. package/dist/sender-BESHz6my.cjs +0 -3
  155. package/dist/sender-BESHz6my.cjs.map +0 -1
  156. package/dist/sender-BUBWLn5i.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,55 +1,55 @@
1
- import { A as e, At as t, Bt as n, Cn as r, D as i, F as a, Ft as o, Gt as s, Ht as c, I as l, It as u, Kt as d, L as f, Lt as p, Qt as m, Rt as h, S as g, Sn as _, Ut as ee, Vt as te, Wt as ne, Zt as re, _n as ie, _t as ae, a as v, c as y, d as b, en as x, f as oe, ft as se, gn as S, hn as ce, i as le, in as ue, j as de, k as C, l as fe, lt as pe, m as me, mn as he, n as w, o as ge, p as T, qt as _e, r as ve, s as E, sn as ye, u as D, ut as O, vn as be, vt as k, xn as xe, yt as Se, z as Ce, zt as we } from "./constants-DhH6VI5a.js";
2
- import { n as Te, r as Ee, t as De } from "./error-like-Ywo5uRHo.js";
3
- import { i as Oe, r as ke } from "./deadline-DeqXEliN.js";
4
- import { a as Ae, i as je, n as Me, o as Ne, r as Pe } from "./sampling-Ud_WiuU9.js";
5
- import { a as Fe, i as Ie, n as Le, o as A, r as j } from "./sanitize-DP0xDPrt.js";
6
- import { a as Re, i as ze, n as Be, o as Ve, r as He, s as Ue, t as We } from "./identity-Di-QXGCC.js";
7
- import { i as Ge, n as Ke, t as qe } from "./platform-GaM6h7XM.js";
8
- import { r as M, t as Je } from "./batch-DDgxg16_.js";
9
- import { r as Ye } from "./library-request-CQD4HUiP.js";
10
- import { n as Xe, t as Ze } from "./journey-yALMEWF7.js";
1
+ import { A as e, Bt as t, Cn as n, Ct as r, D as i, Dn as a, F as o, Gt as s, Ht as c, I as l, Jt as u, Kt as d, L as f, On as p, Pt as m, S as h, Sn as g, St as _, Ut as ee, Vt as te, Wt as ne, Xt as re, Yt as ie, Zt as ae, a as v, bn as oe, c as y, cn as se, d as b, f as ce, fn as le, ft as ue, ht as de, i as fe, in as x, j as pe, k as S, kn as me, l as he, ln as C, m as ge, n as w, nn as _e, o as ve, p as T, pt as E, qt as ye, r as be, s as D, tn as xe, u as O, wn as Se, xn as k, xt as Ce, yn as we, z as Te, zt as Ee } from "./constants-L_d5YvvQ.js";
2
+ import { n as De, r as Oe, t as ke } from "./error-like-Ywo5uRHo.js";
3
+ import { a as Ae, i as je, l as Me, n as Ne, o as Pe, u as A } from "./sampling-nYIWP_vP.js";
4
+ import { n as Fe, r as Ie, t as Le } from "./log-record-cwFiLyPY.js";
5
+ import { a as Re, i as ze, n as Be, o as j, r as M } from "./sanitize-BiUKCUG6.js";
6
+ import { a as Ve, i as He, n as Ue, o as We, r as Ge, s as Ke, t as qe } from "./identity-Dtv917nz.js";
7
+ import { r as Je } from "./library-request-ChCar5F8.js";
8
+ import { i as Ye, n as Xe, t as Ze } from "./platform-4yYjMD-B.js";
9
+ import { r as N, t as Qe } from "./batch-D-4xl7op.js";
10
+ import { n as $e, t as et } from "./journey-DRK0A8u_.js";
11
11
  //#region src/utils/timer.ts
12
- function N(e) {
13
- return Math.round((performance.now() - e) * Ce) / Ce;
12
+ function P(e) {
13
+ return Math.round((performance.now() - e) * Te) / Te;
14
14
  }
15
- function P(e, t, n, r, i) {
15
+ function F(e, t, n, r, i) {
16
16
  e.logMetric(`${t}.duration`, n, "ms", "histogram", {
17
17
  status: r,
18
18
  ...i
19
19
  });
20
20
  }
21
- function Qe(e, t, n, r, i) {
22
- let a = N(n);
21
+ function tt(e, t, n, r, i) {
22
+ let a = P(n);
23
23
  e.error(`${t} failed`, r, {
24
24
  "action.duration_ms": a,
25
25
  status: "FAILURE",
26
26
  ...i
27
- }), P(e, t, a, "FAILURE", i);
27
+ }), F(e, t, a, "FAILURE", i);
28
28
  }
29
- function $e(e, t, n, r) {
29
+ function nt(e, t, n, r) {
30
30
  let i = performance.now();
31
31
  try {
32
32
  let a = n();
33
- return P(e, t, N(i), "SUCCESS", r), a;
33
+ return F(e, t, P(i), "SUCCESS", r), a;
34
34
  } catch (n) {
35
- throw Qe(e, t, i, n, r), n;
35
+ throw tt(e, t, i, n, r), n;
36
36
  }
37
37
  }
38
- async function et(e, t, n, r) {
38
+ async function rt(e, t, n, r) {
39
39
  let i = performance.now();
40
40
  try {
41
41
  let a = await n();
42
- return P(e, t, N(i), "SUCCESS", r), a;
42
+ return F(e, t, P(i), "SUCCESS", r), a;
43
43
  } catch (n) {
44
- throw Qe(e, t, i, n, r), n;
44
+ throw tt(e, t, i, n, r), n;
45
45
  }
46
46
  }
47
47
  //#endregion
48
48
  //#region src/core/logger.ts
49
- var tt = [i, ye];
50
- function nt(e, t) {
49
+ var it = [i, le];
50
+ function at(e, t) {
51
51
  let n = t.guard("record.sanitize_failed", "The library could not read the error reason.", () => {
52
- if (!(e instanceof Error) && !Ee(e)) return;
52
+ if (!(e instanceof Error) && !Oe(e)) return;
53
53
  let t = Error(e.message);
54
54
  return t.name = e.name, t.stack = e.stack, t;
55
55
  });
@@ -57,38 +57,38 @@ function nt(e, t) {
57
57
  let r = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
58
58
  return Error(r ?? typeof e);
59
59
  }
60
- function rt(e, t, n) {
60
+ function ot(e, t, n) {
61
61
  return n.guard("record.sanitize_failed", "The library could not read the error reason.", () => e instanceof Error ? e : t) ?? t;
62
62
  }
63
- function it(e, t) {
63
+ function st(e, t) {
64
64
  if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint" || typeof e == "symbol") return e;
65
65
  if (typeof e == "object" && e) return t.guard("record.sanitize_failed", "The library could not read the properties of the error reason.", () => {
66
- let t = e, n = Ee(e), r = {}, i = 0;
66
+ let t = e, n = Oe(e), r = {}, i = 0;
67
67
  for (let e of Object.keys(t)) {
68
68
  let a = t[e];
69
- (!n || !De.has(e)) && Te(a) && (r[e] = a, i++);
69
+ (!n || !ke.has(e)) && De(a) && (r[e] = a, i++);
70
70
  }
71
71
  return i === 0 ? void 0 : r;
72
72
  });
73
73
  }
74
- function at(e) {
75
- if (!Oe(e) || e instanceof Error) return !1;
74
+ function ct(e) {
75
+ if (!A(e) || e instanceof Error) return !1;
76
76
  let t = Object.getPrototypeOf(e);
77
77
  return t === null || Object.getPrototypeOf(t) === null;
78
78
  }
79
- function ot(e) {
80
- return tt.some((t) => e === t || e.startsWith(`${t}.`)) ? "system" : "log";
79
+ function lt(e) {
80
+ return it.some((t) => e === t || e.startsWith(`${t}.`)) ? "system" : "log";
81
81
  }
82
- function F(e, t) {
82
+ function I(e, t) {
83
83
  return e === void 0 ? {} : t.guard("record.sanitize_failed", "The library could not read the payload.", () => ({ ...e })) ?? { "uiobs.sanitize_failed": !0 };
84
84
  }
85
- var I = class e {
85
+ var L = class e {
86
86
  bind;
87
87
  namespace;
88
88
  options;
89
89
  levelType;
90
90
  constructor(e, t, n = {}) {
91
- this.bind = e, this.namespace = t, this.options = n, this.levelType = ot(t);
91
+ this.bind = e, this.namespace = t, this.options = n, this.levelType = lt(t);
92
92
  }
93
93
  child(t, n = {}) {
94
94
  return new e(this.bind, `${this.namespace}.${t}`, { scopedContext: {
@@ -125,22 +125,22 @@ var I = class e {
125
125
  this.bind().diagnostics.report("record.dropped_malformed", "The metric value is not a finite number. The library dropped the metric.", { "metric.name": e });
126
126
  return;
127
127
  }
128
- let a = F(i, this.bind().diagnostics), o = {
128
+ let a = I(i, this.bind().diagnostics), o = {
129
129
  ...a,
130
130
  "metric.name": e,
131
131
  "metric.value": t,
132
132
  "metric.unit": n,
133
133
  "metric.type": r,
134
- [k.attributeKeys]: Object.keys(a)
134
+ [_.attributeKeys]: Object.keys(a)
135
135
  };
136
136
  this.write("INFO", "metric", e, o, !0);
137
137
  };
138
- timeSync = (e, t, n) => $e(this, e, t, n);
139
- timeAsync = (e, t, n) => et(this, e, t, n);
138
+ timeSync = (e, t, n) => nt(this, e, t, n);
139
+ timeAsync = (e, t, n) => rt(this, e, t, n);
140
140
  write(e, t, n, r, i = !1) {
141
141
  let a = this.bind();
142
142
  if (a.isDestroyed()) return;
143
- if (!a.builder.isEnabled(e, t)) {
143
+ if (!a.builder.isEnabled(e, this.namespace, t)) {
144
144
  this.mirrors(a, e) && this.print(a, e, n, r, void 0, null);
145
145
  return;
146
146
  }
@@ -150,7 +150,7 @@ var I = class e {
150
150
  body: n,
151
151
  namespace: this.namespace,
152
152
  scoped: this.options.scopedContext,
153
- payload: i ? r : F(r, a.diagnostics)
153
+ payload: i ? r : I(r, a.diagnostics)
154
154
  }), c = o ? o.body : s === "sampling" ? n : void 0;
155
155
  t !== "metric" && c !== void 0 && a.breadcrumbs.push({
156
156
  t: Date.now(),
@@ -161,106 +161,237 @@ var I = class e {
161
161
  writeError(e, t, n, r) {
162
162
  let i = this.bind();
163
163
  if (i.isDestroyed()) return;
164
- let a = i.builder.isEnabled(e);
164
+ let a = i.builder.isEnabled(e, this.namespace);
165
165
  if (!a && !this.mirrors(i, e)) return;
166
- let o = r === void 0 && (i.diagnostics.guard("record.sanitize_failed", "The library could not read the error slot.", () => at(n)) ?? !1), s = o ? n : r, c = o ? void 0 : n, l = c === void 0 ? void 0 : nt(c, i.diagnostics), u = l === void 0 ? void 0 : rt(c, l, i.diagnostics);
166
+ let o = r === void 0 && (i.diagnostics.guard("record.sanitize_failed", "The library could not read the error slot.", () => ct(n)) ?? !1), s = o ? n : r, c = o ? void 0 : n, l = c === void 0 ? void 0 : at(c, i.diagnostics), u = l === void 0 ? void 0 : ot(c, l, i.diagnostics);
167
167
  if (!a) {
168
168
  this.print(i, e, t, s, u, null);
169
169
  return;
170
170
  }
171
- let d = l ? it(c, i.diagnostics) : void 0, { record: f, dropped: p } = i.builder.build({
171
+ let d = l ? st(c, i.diagnostics) : void 0, { record: f, dropped: p } = i.builder.build({
172
172
  level: e,
173
173
  type: this.levelType,
174
174
  body: t,
175
175
  namespace: this.namespace,
176
176
  scoped: this.options.scopedContext,
177
177
  payload: {
178
- ...F(s, i.diagnostics),
178
+ ...I(s, i.diagnostics),
179
179
  ...l ? {
180
180
  "error.type": l.name,
181
181
  "error.message": l.message,
182
182
  "error.stack_trace": l.stack
183
183
  } : {},
184
- ...d === void 0 ? {} : { [ge]: d },
184
+ ...d === void 0 ? {} : { [ve]: d },
185
185
  [v]: i.breadcrumbs.snapshot()
186
186
  }
187
187
  });
188
188
  this.print(i, e, t, s, u, f, p), i.emit(f);
189
189
  }
190
190
  print(e, t, n, r, i, a, o) {
191
- 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);
191
+ e.config.redact ? a ? e.console.write(this.namespace, t, a.body, a.attributes) : o !== "processor" && o !== "redact" && o !== "malformed" && e.console.write(this.namespace, t, n, void 0, i) : e.console.write(this.namespace, t, n, r, i);
192
192
  }
193
193
  mirrors(e, t) {
194
194
  return e.config.enabled && e.console.accepts(t);
195
195
  }
196
- }, st = {
196
+ }, ut = "overflow", dt = /* @__PURE__ */ new Set([
197
+ b,
198
+ O,
199
+ w,
200
+ T,
201
+ D,
202
+ y,
203
+ he
204
+ ]);
205
+ function ft(e = {}) {
206
+ let t = {};
207
+ for (let n of Object.keys(e).sort()) {
208
+ if (n.startsWith("metric.") || dt.has(n)) continue;
209
+ let r = e[n];
210
+ (typeof r == "string" || typeof r == "boolean" || typeof r == "number" && Number.isFinite(r)) && (t[n] = r);
211
+ }
212
+ return t;
213
+ }
214
+ function pt(e) {
215
+ if (!Array.isArray(e)) return null;
216
+ let t = Math.min(e.length, 51);
217
+ return Array.from({ length: t }, (t, n) => e[n]);
218
+ }
219
+ function mt(e) {
220
+ return Array.isArray(e) && e.length <= 50 && e.every((t, n) => typeof t == "number" && Number.isFinite(t) && (n === 0 || t > e[n - 1]));
221
+ }
222
+ function ht(e, t, n) {
223
+ let r = {
224
+ "metric.name": e.name,
225
+ "metric.unit": e.unit,
226
+ "metric.type": e.kind,
227
+ [_.start]: n,
228
+ [_.attributeKeys]: Object.keys(t.attributes)
229
+ };
230
+ return e.kind === "counter" ? (r["metric.value"] = t.sum, r) : {
231
+ ...r,
232
+ [_.count]: t.count,
233
+ [_.sum]: t.sum,
234
+ [_.min]: t.min,
235
+ [_.max]: t.max,
236
+ [_.bounds]: e.boundaries,
237
+ [_.buckets]: t.buckets
238
+ };
239
+ }
240
+ function gt(e, t, n) {
241
+ let r = {
242
+ name: e,
243
+ kind: "counter",
244
+ unit: t.unit ?? "count",
245
+ boundaries: []
246
+ };
247
+ return { add: (e, t) => {
248
+ n(r, e, t);
249
+ } };
250
+ }
251
+ function _t(e, t, n) {
252
+ let r = {
253
+ name: e,
254
+ kind: "histogram",
255
+ unit: t.unit ?? "count",
256
+ boundaries: t.boundaries ?? Ce
257
+ };
258
+ return { record: (e, t) => {
259
+ n(r, e, t);
260
+ } };
261
+ }
262
+ var vt = class {
263
+ intervalMs;
264
+ emit;
265
+ diagnostics;
266
+ instruments = /* @__PURE__ */ new Map();
267
+ timer = null;
268
+ startedAt = 0;
269
+ constructor(e, t, n) {
270
+ this.intervalMs = e, this.emit = t, this.diagnostics = n;
271
+ }
272
+ record(e, t, n) {
273
+ !Number.isFinite(t) || e.kind === "counter" && t < 0 ? this.diagnostics.report("record.dropped_malformed", `The value of the metric ${e.name} is not valid. The library dropped it.`, { "metric.name": e.name }) : this.diagnostics.guard("record.sanitize_failed", `The library could not read the attributes of the metric ${e.name}.`, () => {
274
+ let r = this.instrumentOf(e);
275
+ r && (this.add(r, t, ft(n)), this.arm());
276
+ });
277
+ }
278
+ collect() {
279
+ this.timer !== null && (clearTimeout(this.timer), this.timer = null);
280
+ let e = `${String(this.startedAt)}000000`, t = [...this.instruments.values()];
281
+ this.instruments.clear();
282
+ for (let { def: n, series: r } of t) for (let t of r.values()) this.emit(n.name, t.attributes, ht(n, t, e));
283
+ }
284
+ instrumentOf(e) {
285
+ let t = this.instruments.get(e.name);
286
+ if (t) return t.def.kind === e.kind ? t : (this.diagnostics.report("record.dropped_malformed", `The metric ${e.name} is a counter and a histogram. The library dropped the value.`, { "metric.name": e.name }), null);
287
+ let n = pt(e.boundaries), r = mt(n);
288
+ e.kind === "histogram" && !r && this.diagnostics.report("config.invalid", `The boundaries of the metric ${e.name} must be at most 50 finite numbers in ascending order. The library uses the default boundaries.`);
289
+ let i = {
290
+ def: {
291
+ ...e,
292
+ boundaries: r ? n : [...Ce]
293
+ },
294
+ series: /* @__PURE__ */ new Map()
295
+ };
296
+ return this.instruments.set(e.name, i), i;
297
+ }
298
+ add(e, t, n) {
299
+ let r = JSON.stringify(n), i = e.series.get(r), a = n;
300
+ if (!i && e.series.size >= 100 && (r = ut, i = e.series.get(r), a = { [ce]: !0 }), !i) {
301
+ let n = e.def.kind === "histogram" ? e.def.boundaries.length + 1 : 0, o = Array(n).fill(0);
302
+ i = {
303
+ attributes: a,
304
+ count: 0,
305
+ sum: 0,
306
+ min: t,
307
+ max: t,
308
+ buckets: o
309
+ }, e.series.set(r, i);
310
+ }
311
+ if (i.count += 1, i.sum += t, i.min = Math.min(i.min, t), i.max = Math.max(i.max, t), i.buckets.length > 0) {
312
+ let n = e.def.boundaries.findIndex((e) => t <= e);
313
+ i.buckets[n === -1 ? i.buckets.length - 1 : n] += 1;
314
+ }
315
+ }
316
+ arm() {
317
+ this.timer === null && (this.startedAt = Date.now(), this.timer = setTimeout(() => {
318
+ this.collect();
319
+ }, this.intervalMs()), Me(this.timer));
320
+ }
321
+ }, yt = {
197
322
  TRACE: "debug",
198
323
  DEBUG: "debug",
199
324
  INFO: "info",
200
325
  WARN: "warn",
201
326
  ERROR: "error",
202
327
  FATAL: "error"
203
- }, ct = class {
328
+ }, bt = class {
204
329
  settings;
205
330
  diagnostics;
206
331
  limits;
207
- constructor(e, n, r = t) {
208
- this.settings = e, this.diagnostics = n, this.limits = r;
332
+ constructor(e, t, n = m) {
333
+ this.settings = e, this.diagnostics = t, this.limits = n;
209
334
  }
210
335
  update(e) {
211
336
  this.settings = e;
212
337
  }
213
338
  accepts(e) {
214
- return this.settings.level === null || !Object.hasOwn(O, this.settings.level) ? !1 : O[e] >= O[this.settings.level];
339
+ return this.settings.level === null || !Object.hasOwn(E, this.settings.level) ? !1 : E[e] >= E[this.settings.level];
215
340
  }
216
341
  write(e, t, n, r, i) {
217
- if (!this.accepts(t) || typeof console > "u" || Fe()) return;
218
- let a = `%c[%s]%c[${t}]%c`, { styles: o } = this.settings, s = st[t];
342
+ if (!this.accepts(t) || typeof console > "u" || Re()) return;
343
+ let a = `%c[%s]%c[${t}]%c`, { styles: o } = this.settings, s = yt[t];
219
344
  this.diagnostics.guard("handler.threw", `The library could not print to console.${s}.`, () => {
220
345
  let c = [];
221
- i !== void 0 && c.push(i), r !== void 0 && c.push(Le(r, this.limits, this.diagnostics)), A(() => {
346
+ i !== void 0 && c.push(i), r !== void 0 && c.push(Be(r, this.limits, this.diagnostics)), j(() => {
222
347
  console[s](a, o.namespace, e, o[t], "", n, ...c);
223
348
  });
224
349
  });
225
350
  }
226
- }, lt = class {
351
+ }, xt = class {
227
352
  value = 0;
228
353
  next() {
229
354
  return ++this.value;
230
355
  }
231
- }, ut = /^[0-9a-f]{32}$/, dt = /^[0-9a-f]{16}$/, ft = /[1-9a-f]/;
232
- function pt(e) {
233
- return ut.test(e.traceId) && ft.test(e.traceId) && dt.test(e.spanId) && ft.test(e.spanId);
356
+ }, St = /^[0-9a-f]{32}$/, Ct = /^[0-9a-f]{16}$/, wt = /[1-9a-f]/;
357
+ function Tt(e) {
358
+ return St.test(e.traceId) && wt.test(e.traceId) && Ct.test(e.spanId) && wt.test(e.spanId);
234
359
  }
235
- function mt() {
236
- return Ve(16);
360
+ function Et() {
361
+ return We(16);
237
362
  }
238
- function ht() {
239
- return Ve(8);
363
+ function Dt() {
364
+ return We(8);
240
365
  }
241
- function gt() {
366
+ function Ot(e) {
242
367
  return {
243
- traceId: mt(),
244
- spanId: ht(),
368
+ traceId: Et(),
369
+ spanId: Dt(),
245
370
  traceFlags: 1,
246
- startedAt: Date.now()
371
+ startedAt: Date.now(),
372
+ reason: e,
373
+ ended: !1
247
374
  };
248
375
  }
249
- function _t(e) {
376
+ function kt(e, t, n) {
377
+ return `00-${e}-${t}-${(n & 255).toString(16).padStart(2, "0")}`;
378
+ }
379
+ function At(e) {
250
380
  return {
251
381
  traceId: e.traceId,
252
382
  spanId: e.spanId,
253
383
  traceFlags: e.traceFlags
254
384
  };
255
385
  }
256
- var vt = class {
386
+ var jt = class {
257
387
  diagnostics;
258
388
  maxAgeMs;
259
389
  load;
260
- ambient = gt();
390
+ spans;
391
+ ambient = Ot("start");
261
392
  otel;
262
- constructor(e, t = be, n) {
263
- this.diagnostics = e, this.maxAgeMs = t, this.load = n;
393
+ constructor(e, t = n, r, i) {
394
+ this.diagnostics = e, this.maxAgeMs = t, this.load = r, this.spans = i;
264
395
  }
265
396
  async loadOtel() {
266
397
  if (this.load) try {
@@ -270,8 +401,10 @@ var vt = class {
270
401
  }
271
402
  }
272
403
  resolve() {
273
- let e = this.activeSpanContext();
274
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), _t(this.ambient)) : e;
404
+ return this.activeSpanContext() ?? this.ambientContext();
405
+ }
406
+ ambientContext() {
407
+ return Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), At(this.ambient);
275
408
  }
276
409
  activeSpanContext() {
277
410
  let e = this.otel;
@@ -279,7 +412,7 @@ var vt = class {
279
412
  let t = e.trace.getActiveSpan();
280
413
  if (t === void 0) return;
281
414
  let n = t.spanContext();
282
- if (pt(n)) return {
415
+ if (Tt(n)) return {
283
416
  traceId: n.traceId,
284
417
  spanId: n.spanId,
285
418
  traceFlags: n.traceFlags
@@ -287,19 +420,47 @@ var vt = class {
287
420
  });
288
421
  }
289
422
  rotate(e) {
290
- return this.ambient = gt(), _t(this.ambient);
423
+ let t = this.ambient;
424
+ this.ambient = Ot(e);
425
+ let n = At(this.ambient);
426
+ return this.finish(t), n;
427
+ }
428
+ end() {
429
+ this.finish(this.ambient);
430
+ }
431
+ finish(e) {
432
+ e.ended || (e.ended = !0, this.spans?.onEnd({
433
+ traceId: e.traceId,
434
+ spanId: e.spanId,
435
+ reason: e.reason,
436
+ startedAt: e.startedAt,
437
+ endedAt: Date.now()
438
+ }));
291
439
  }
292
440
  headers() {
293
- let e = {}, t = this.otel;
294
- if (t && this.diagnostics.guard("trace.otel_failed", "The library could not add the OpenTelemetry headers.", () => {
295
- t.propagation.inject(t.context.active(), e);
296
- }), !e.traceparent) {
297
- let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
298
- e[ie] = `00-${t.traceId}-${t.spanId}-${n}`;
299
- }
300
- return e;
441
+ return this.trace(!1).headers;
442
+ }
443
+ request() {
444
+ return this.trace(!0);
445
+ }
446
+ trace(e) {
447
+ let t = {}, n = this.otel;
448
+ if (n && this.diagnostics.guard("trace.otel_failed", "The library could not add the OpenTelemetry headers.", () => {
449
+ n.propagation.inject(n.context.active(), t);
450
+ }), t.traceparent) return { headers: t };
451
+ let r = this.activeSpanContext(), i = r ?? this.ambientContext(), a = r ? void 0 : this.spans;
452
+ if (!a?.enabled()) return t[g] = kt(i.traceId, i.spanId, i.traceFlags), { headers: t };
453
+ let o = a.keeps(i.traceId), s = o ? i.traceFlags : i.traceFlags & -2, c = e ? Dt() : i.spanId;
454
+ return t[g] = kt(i.traceId, c, s), !e || !o ? { headers: t } : {
455
+ headers: t,
456
+ span: {
457
+ traceId: i.traceId,
458
+ spanId: c,
459
+ parentSpanId: i.spanId
460
+ }
461
+ };
301
462
  }
302
- }, yt = class {
463
+ }, Mt = class {
303
464
  buffer;
304
465
  pointer = 0;
305
466
  filled = !1;
@@ -310,48 +471,51 @@ var vt = class {
310
471
  push(e) {
311
472
  this.buffer[this.pointer] = e, this.pointer = (this.pointer + 1) % this.capacity, this.pointer === 0 && (this.filled = !0);
312
473
  }
474
+ clear() {
475
+ this.buffer.fill(void 0), this.pointer = 0, this.filled = !1;
476
+ }
313
477
  snapshot() {
314
478
  return (this.filled ? [...this.buffer.slice(this.pointer), ...this.buffer.slice(0, this.pointer)] : this.buffer.slice(0, this.pointer)).filter((e) => e !== void 0);
315
479
  }
316
- }, bt = Object.keys(O), xt = ["gzip", "none"], St = [
480
+ }, Nt = Object.keys(E), Pt = ["gzip", "none"], Ft = [
317
481
  "omit",
318
482
  "same-origin",
319
483
  "include"
320
- ], Ct = [
484
+ ], It = [
321
485
  "auto",
322
486
  "indexeddb",
323
487
  "localstorage",
324
488
  "memory",
325
489
  "none"
326
- ], wt = ["storage", "memory"], Tt = [
490
+ ], Lt = ["storage", "memory"], Rt = [
327
491
  "auto",
328
492
  "sender",
329
493
  "forwarder",
330
494
  "off"
331
- ], Et = [
495
+ ], zt = [
332
496
  "auto",
333
497
  "provider",
334
498
  "client"
335
- ], Dt = [
499
+ ], Bt = [
336
500
  "auto",
337
501
  "context",
338
502
  "tab",
339
503
  "origin"
340
- ], Ot = [
504
+ ], Vt = [
341
505
  "error",
342
506
  "warn",
343
507
  "info",
344
508
  "log"
345
- ], kt = ["limited", "until-delivered"], At = {
509
+ ], Ht = ["limited", "until-delivered"], Ut = {
346
510
  logFlushIntervalMs: [100, 6e4],
347
511
  logBatchSize: [1, 1e3],
348
512
  metricFlushIntervalMs: [100, 6e4],
349
513
  metricBatchSize: [1, 1e3]
350
- }, jt = {
514
+ }, Wt = {
351
515
  maxBatches: [1, 5e3],
352
516
  maxAgeMs: [6e4, 6048e5],
353
517
  maxAttempts: [1, 20]
354
- }, Mt = {
518
+ }, Gt = {
355
519
  maxBodyChars: [256, 65536],
356
520
  maxAttributeChars: [256, 65536],
357
521
  maxAttributeCount: [1, 1024],
@@ -359,8 +523,8 @@ var vt = class {
359
523
  maxDepth: [1, 16],
360
524
  maxArrayLength: [1, 1e4],
361
525
  maxNodes: [100, 1e5],
362
- maxRecordBytes: [1024, g]
363
- }, Nt = [6e4, 864e5], Pt = [
526
+ maxRecordBytes: [1024, h]
527
+ }, Kt = [6e4, 864e5], qt = [
364
528
  "errors",
365
529
  "rejections",
366
530
  "resourceErrors",
@@ -371,102 +535,119 @@ var vt = class {
371
535
  "navigation",
372
536
  "webVitals",
373
537
  "longFrames",
374
- "fullUrls"
375
- ], Ft = "null", L = `a level name: ${R(bt)}`, It = `true, false or a list of ${R(Ot)}`, Lt = "a list of strings and RegExp patterns", Rt = "a list of origin URLs such as \"https://api.example\" and RegExp patterns", zt = "a list of origin URLs such as \"https://app.example\". For a sandboxed frame, set bus.mode: \"sender\" in the frame", Bt = "a list of strings";
376
- function R(e) {
538
+ "fullUrls",
539
+ "webSocket"
540
+ ], Jt = "null", R = `a level name: ${z(Nt)}`, Yt = `true, false or a list of ${z(Vt)}`, Xt = "a list of strings and RegExp patterns", Zt = "a list of origin URLs such as \"https://api.example\" and RegExp patterns", Qt = "a list of origin URLs such as \"https://app.example\". For a sandboxed frame, set bus.mode: \"sender\" in the frame", $t = "a list of strings";
541
+ function z(e) {
377
542
  let t = e.map((e) => `"${e}"`);
378
543
  return `${t.slice(0, -1).join(", ")} or ${t[t.length - 1]}`;
379
544
  }
380
- function Vt(e) {
545
+ function en(e) {
381
546
  return typeof e == "string" ? `"${e}"` : typeof e == "function" ? "a function" : typeof e == "object" && e ? "an object" : String(e);
382
547
  }
383
- function z(e, t, n, r, i) {
384
- e.report("config.invalid", `${t} must be ${n}. The value is ${Vt(r)}. The library keeps ${i}.`);
385
- }
386
548
  function B(e, t, n, r, i) {
549
+ e.report("config.invalid", `${t} must be ${n}. The value is ${en(r)}. The library keeps ${i}.`);
550
+ }
551
+ function V(e, t, n, r, i) {
387
552
  if (t === void 0) return r;
388
553
  let a = n.find((e) => e === t);
389
- return a === void 0 ? (z(i, e, R(n), t, `"${r}"`), r) : a;
554
+ return a === void 0 ? (B(i, e, z(n), t, `"${r}"`), r) : a;
390
555
  }
391
- function V(e, t, n, r) {
392
- return t === void 0 ? n : typeof t == "boolean" ? t : (z(r, e, "true or false", t, String(n)), n);
556
+ function H(e, t, n, r) {
557
+ return t === void 0 ? n : typeof t == "boolean" ? t : (B(r, e, "true or false", t, String(n)), n);
393
558
  }
394
- function Ht(e, t, n, r) {
395
- return t === void 0 ? n : typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : (z(r, e, "a finite number of 0 or more", t, String(n)), n);
559
+ function tn(e, t, n, r) {
560
+ 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
561
  }
397
- function Ut(e, t, n, r, i) {
562
+ function nn(e, t, n, r, i) {
398
563
  if (t === void 0) return r;
399
564
  let [a, o] = n;
400
- return typeof t == "number" && Number.isInteger(t) && t >= a && t <= o ? t : (z(i, e, `an integer from ${String(a)} to ${String(o)}`, t, String(r)), r);
565
+ 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
566
  }
402
- function H(e, t, n, r, i) {
567
+ function U(e, t, n, r, i) {
403
568
  let a = t ?? {}, o = Object.keys(r);
404
- return Object.fromEntries(o.map((t) => [t, Ut(`${e}.${t}`, a[t], r[t], n[t], i)]));
569
+ return Object.fromEntries(o.map((t) => [t, nn(`${e}.${t}`, a[t], r[t], n[t], i)]));
405
570
  }
406
- function U(e) {
571
+ function W(e) {
407
572
  if (typeof e != "string") return;
408
573
  let t = e.toUpperCase();
409
- return bt.find((e) => e === t);
574
+ return Nt.find((e) => e === t);
410
575
  }
411
- function Wt(e, t, n, r) {
576
+ function rn(e, t, n, r) {
412
577
  if (t === void 0) return n;
413
- let i = U(t);
414
- return i === void 0 ? (z(r, e, L, t, `"${n}"`), n) : i;
578
+ let i = W(t);
579
+ return i === void 0 ? (B(r, e, R, t, `"${n}"`), n) : i;
580
+ }
581
+ function an(e, t, n) {
582
+ if (e === void 0) return t;
583
+ if (!A(e)) return B(n, "minLevels", "an object of level names", e, "the value in force"), t;
584
+ let r = [];
585
+ for (let [t, i] of Object.entries(e)) {
586
+ let e = W(i);
587
+ t !== "" && e !== void 0 ? r.push([t, e]) : B(n, `minLevels["${t}"]`, R, i, "minLevel for it");
588
+ }
589
+ return Object.fromEntries(r);
415
590
  }
416
- function W(e, t, n, r, i, a) {
591
+ function G(e, t, n, r, i, a) {
417
592
  if (t === void 0) return n;
418
- if (!Array.isArray(t)) return z(a, e, r, t, "the list in force"), n;
593
+ if (!Array.isArray(t)) return B(a, e, r, t, "the list in force"), n;
419
594
  let o = [], s = t;
420
595
  for (let t of s) {
421
596
  let n = i(t);
422
- n === void 0 ? a.report("config.invalid", `The library ignores the ${e} entry ${Vt(t)}. ${e} must be ${r}.`) : o.push(n);
597
+ n === void 0 ? a.report("config.invalid", `The library ignores the ${e} entry ${en(t)}. ${e} must be ${r}.`) : o.push(n);
423
598
  }
424
599
  return o;
425
600
  }
426
- function Gt(e) {
601
+ function on(e) {
602
+ return typeof e == "function" ? e : void 0;
603
+ }
604
+ function sn(e) {
605
+ return A(e) && typeof e.name == "string" && e.name !== "" && typeof e.install == "function" && typeof e.uninstall == "function" ? e : void 0;
606
+ }
607
+ function cn(e) {
427
608
  return typeof e == "string" ? e : void 0;
428
609
  }
429
- function Kt(e) {
610
+ function ln(e) {
430
611
  return typeof e == "string" || e instanceof RegExp ? e : void 0;
431
612
  }
432
- function qt(e) {
433
- return Ot.find((t) => t === e);
613
+ function un(e) {
614
+ return Vt.find((t) => t === e);
434
615
  }
435
- function Jt(e) {
616
+ function dn(e) {
436
617
  if (typeof e == "string") try {
437
618
  let { origin: t } = new URL(e);
438
- return t === Ft ? void 0 : t;
619
+ return t === Jt ? void 0 : t;
439
620
  } catch {
440
621
  return;
441
622
  }
442
623
  }
443
- function Yt(e) {
444
- return e instanceof RegExp ? e : Jt(e);
624
+ function fn(e) {
625
+ return e instanceof RegExp ? e : dn(e);
445
626
  }
446
- function Xt(e) {
447
- return Oe(e) ? Object.values(e).every((e) => typeof e == "string") : !1;
627
+ function pn(e) {
628
+ return A(e) ? Object.values(e).every((e) => typeof e == "string") : !1;
448
629
  }
449
- function Zt(e, t, n) {
450
- if (e !== void 0) return typeof e == "function" || Xt(e) ? e : (z(n, "headers", "an object of strings or a function", e, "the headers in force"), t);
630
+ function mn(e, t, n) {
631
+ if (e !== void 0) return typeof e == "function" || pn(e) ? e : (B(n, "headers", "an object of strings or a function", e, "the headers in force"), t);
451
632
  }
452
- function Qt(e) {
633
+ function hn(e) {
453
634
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
454
635
  }
455
- function $t(e, t, n) {
456
- return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || Qt(e) ? e : (n.report("config.invalid", `serializer must be "${x}", "ecs" or an implementation. The library uses "${x}".`), x);
636
+ function gn(e, t, n) {
637
+ return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || hn(e) ? e : (n.report("config.invalid", `serializer must be "${x}", "ecs" or an implementation. The library uses "${x}".`), x);
457
638
  }
458
- var en = new Set(Object.keys(de));
459
- function tn(e, t) {
639
+ var _n = new Set(Object.keys(pe));
640
+ function vn(e, t) {
460
641
  let n = {}, r = Object.entries(e ?? {});
461
- for (let [e, i] of r) en.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.`);
642
+ for (let [e, i] of r) _n.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.`);
462
643
  return n;
463
644
  }
464
- function nn(e, t, n) {
645
+ function yn(e, t, n) {
465
646
  if (e === void 0) return t ?? "DEBUG";
466
- let r = U(e);
467
- return r === void 0 ? (z(n, "console.level", L, e, "the console level in force"), t) : r;
647
+ let r = W(e);
648
+ return r === void 0 ? (B(n, "console.level", R, e, "the console level in force"), t) : r;
468
649
  }
469
- function rn(t, n, r) {
650
+ function bn(t, n, r) {
470
651
  if (t === void 0) return n;
471
652
  if (t === !1) return {
472
653
  level: null,
@@ -477,21 +658,21 @@ function rn(t, n, r) {
477
658
  styles: n.styles
478
659
  };
479
660
  if (typeof t == "string") {
480
- let e = U(t);
481
- return e === void 0 ? (z(r, "console", L, t, "the console level in force"), n) : {
661
+ let e = W(t);
662
+ return e === void 0 ? (B(r, "console", R, t, "the console level in force"), n) : {
482
663
  level: e,
483
664
  styles: n.styles
484
665
  };
485
666
  }
486
667
  return typeof t != "object" || !t ? (r.report("config.invalid", "console must be a boolean, a level or an object. The console settings in force stay."), n) : {
487
- level: nn(t.level, n.level, r),
668
+ level: yn(t.level, n.level, r),
488
669
  styles: {
489
670
  ...n.styles,
490
- ...tn(t.styles, r)
671
+ ...vn(t.styles, r)
491
672
  }
492
673
  };
493
674
  }
494
- function an(e, t, n) {
675
+ function xn(e, t, n) {
495
676
  let r = e ?? {};
496
677
  return {
497
678
  ...t,
@@ -500,113 +681,126 @@ function an(e, t, n) {
500
681
  ...t.rates,
501
682
  ...r.rates
502
683
  },
503
- alwaysSampleTypes: W("sampling.alwaysSampleTypes", r.alwaysSampleTypes, t.alwaysSampleTypes, Bt, Gt, n),
504
- remote: V("sampling.remote", r.remote, t.remote, n)
684
+ alwaysSampleTypes: G("sampling.alwaysSampleTypes", r.alwaysSampleTypes, t.alwaysSampleTypes, $t, cn, n),
685
+ remote: H("sampling.remote", r.remote, t.remote, n)
505
686
  };
506
687
  }
507
- function on(e, t, n) {
688
+ function Sn(e, t, n) {
508
689
  let r = e ?? {};
509
690
  return {
510
- mode: B("bus.mode", r.mode, Tt, t.mode, n),
511
- trustedOrigins: W("bus.trustedOrigins", r.trustedOrigins, t.trustedOrigins, zt, Jt, n),
512
- openFinRole: B("bus.openFinRole", r.openFinRole, Et, t.openFinRole, n)
691
+ mode: V("bus.mode", r.mode, Rt, t.mode, n),
692
+ trustedOrigins: G("bus.trustedOrigins", r.trustedOrigins, t.trustedOrigins, Qt, dn, n),
693
+ openFinRole: V("bus.openFinRole", r.openFinRole, zt, t.openFinRole, n)
513
694
  };
514
695
  }
515
- function sn(e, t, n) {
696
+ function Cn(e, t, n) {
516
697
  let r = e ?? {};
517
698
  return {
518
- scope: B("journey.scope", r.scope, Dt, t.scope, n),
519
- maxAgeMs: Ut("journey.maxAgeMs", r.maxAgeMs, Nt, t.maxAgeMs, n)
699
+ scope: V("journey.scope", r.scope, Bt, t.scope, n),
700
+ maxAgeMs: nn("journey.maxAgeMs", r.maxAgeMs, Kt, t.maxAgeMs, n)
520
701
  };
521
702
  }
522
- function cn(e, t, n) {
703
+ function wn(e, t, n) {
523
704
  let r = e ?? {};
524
705
  return {
525
- mode: B("retention.mode", r.mode, kt, t.mode, n),
526
- ...H("retention", r, t, jt, n)
706
+ mode: V("retention.mode", r.mode, Ht, t.mode, n),
707
+ ...U("retention", r, t, Wt, n)
527
708
  };
528
709
  }
529
- function ln(e, t, n) {
530
- return e === void 0 ? t : typeof e == "boolean" ? e : Array.isArray(e) ? W("capture.console", e, [], It, qt, n) : (z(n, "capture.console", It, e, "the value in force"), t);
710
+ function Tn(e, t, n) {
711
+ return e === void 0 ? t : typeof e == "boolean" ? e : Array.isArray(e) ? G("capture.console", e, [], Yt, un, n) : (B(n, "capture.console", Yt, e, "the value in force"), t);
531
712
  }
532
- function un(e, t, n) {
713
+ function En(e, t, n) {
533
714
  let r = e ?? {}, i = {
534
715
  ...t,
535
716
  ...r,
536
- console: ln(r.console, t.console, n),
537
- longFrameThresholdMs: Ht("capture.longFrameThresholdMs", r.longFrameThresholdMs, t.longFrameThresholdMs, n),
538
- ignoreUrls: W("capture.ignoreUrls", r.ignoreUrls, t.ignoreUrls, Lt, Kt, n),
539
- propagateTraceHeaderTo: W("capture.propagateTraceHeaderTo", r.propagateTraceHeaderTo, t.propagateTraceHeaderTo, Rt, Yt, n)
717
+ console: Tn(r.console, t.console, n),
718
+ longFrameThresholdMs: tn("capture.longFrameThresholdMs", r.longFrameThresholdMs, t.longFrameThresholdMs, n),
719
+ ignoreUrls: G("capture.ignoreUrls", r.ignoreUrls, t.ignoreUrls, Xt, ln, n),
720
+ propagateTraceHeaderTo: G("capture.propagateTraceHeaderTo", r.propagateTraceHeaderTo, t.propagateTraceHeaderTo, Zt, fn, n),
721
+ plugins: G("capture.plugins", r.plugins, t.plugins, "a list of objects with a name, install() and uninstall()", sn, n)
540
722
  };
541
- for (let e of Pt) i[e] = V(`capture.${e}`, r[e], t[e], n);
723
+ for (let e of qt) i[e] = H(`capture.${e}`, r[e], t[e], n);
542
724
  return i;
543
725
  }
544
- function dn(e, t, n, r) {
545
- let i = t;
546
- if (typeof e == "string" && e !== "") try {
547
- new URL(e), i = e;
548
- } catch (t) {
549
- r.report("config.invalid", `metricsEndpoint is not a valid absolute URL: ${e}. The library keeps the value in force.`, void 0, t);
726
+ var Dn = {
727
+ metricsEndpoint: "The library sends metric records as log records.",
728
+ tracesEndpoint: "The library sends no span."
729
+ };
730
+ function On(e, t, n, r, i) {
731
+ let a = n;
732
+ if (typeof t == "string" && t !== "") try {
733
+ new URL(t), a = t;
734
+ } catch (n) {
735
+ i.report("config.invalid", `${e} is not a valid absolute URL: ${t}. The library keeps the value in force.`, void 0, n);
550
736
  }
551
- else e === "" ? i = "" : e !== void 0 && z(r, "metricsEndpoint", "a URL string", e, "the value in force");
552
- return i !== "" && n !== "otlp" ? (r.report("config.invalid", `metricsEndpoint needs serializer "${x}". The library sends metric records as log records.`), "") : i;
737
+ else t === "" ? a = "" : t !== void 0 && B(i, e, "a URL string", t, "the value in force");
738
+ return a !== "" && r !== "otlp" ? (i.report("config.invalid", `${e} needs serializer "${x}". ${Dn[e]}`), "") : a;
553
739
  }
554
- function fn(e, t, n) {
555
- let i = n ?? a, o = {
556
- ...i,
740
+ function kn(e, t, n) {
741
+ let r = n ?? o, i = {
742
+ ...r,
557
743
  ...e,
558
- endpoint: e.endpoint === void 0 ? i.endpoint : e.endpoint,
559
- enabled: V("enabled", e.enabled, i.enabled, t),
560
- minLevel: Wt("minLevel", e.minLevel, i.minLevel, t),
561
- compression: B("compression", e.compression, xt, i.compression, t),
562
- credentials: B("credentials", e.credentials, St, i.credentials, t),
563
- headers: "headers" in e ? Zt(e.headers, i.headers, t) : i.headers,
564
- storage: B("storage", e.storage, Ct, i.storage, t),
565
- identity: B("identity", e.identity, wt, i.identity, t),
566
- serializer: $t(e.serializer, n?.serializer, t),
567
- console: rn(e.console, i.console, t),
568
- sampling: an(e.sampling, i.sampling, t),
569
- bus: on(e.bus, i.bus, t),
570
- batching: H("batching", e.batching, i.batching, At, t),
571
- retention: cn(e.retention, i.retention, t),
572
- limits: H("limits", e.limits, i.limits, Mt, t),
573
- journey: sn(e.journey, i.journey, t),
574
- capture: un(e.capture, i.capture, t)
744
+ endpoint: e.endpoint === void 0 ? r.endpoint : e.endpoint,
745
+ enabled: H("enabled", e.enabled, r.enabled, t),
746
+ minLevel: rn("minLevel", e.minLevel, r.minLevel, t),
747
+ minLevels: an(e.minLevels, r.minLevels, t),
748
+ processors: G("processors", e.processors, r.processors, "a list of functions", on, t),
749
+ compression: V("compression", e.compression, Pt, r.compression, t),
750
+ credentials: V("credentials", e.credentials, Ft, r.credentials, t),
751
+ headers: "headers" in e ? mn(e.headers, r.headers, t) : r.headers,
752
+ storage: V("storage", e.storage, It, r.storage, t),
753
+ identity: V("identity", e.identity, Lt, r.identity, t),
754
+ serializer: gn(e.serializer, n?.serializer, t),
755
+ console: bn(e.console, r.console, t),
756
+ sampling: xn(e.sampling, r.sampling, t),
757
+ bus: Sn(e.bus, r.bus, t),
758
+ batching: U("batching", e.batching, r.batching, Ut, t),
759
+ retention: wn(e.retention, r.retention, t),
760
+ limits: U("limits", e.limits, r.limits, Gt, t),
761
+ journey: Cn(e.journey, r.journey, t),
762
+ capture: En(e.capture, r.capture, t)
575
763
  };
576
- if (o.metricsEndpoint = dn(e.metricsEndpoint, i.metricsEndpoint, o.serializer, t), o.transport !== void 0 && typeof o.transport != "function" && (t.report("config.invalid", "transport must be a function. The library ignores the value."), o.transport = i.transport), o.onDrop !== void 0 && typeof o.onDrop != "function" && (t.report("config.invalid", "onDrop must be a function. The library ignores the value."), o.onDrop = i.onDrop), o.transportOnExit !== void 0 && typeof o.transportOnExit != "function" && (t.report("config.invalid", "transportOnExit must be a function. The library ignores the value."), o.transportOnExit = i.transportOnExit), o.endpoint === "") o.transport === void 0 && t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
577
- else if (o.endpoint !== null) try {
578
- new URL(o.endpoint);
764
+ for (let n of ["metricsEndpoint", "tracesEndpoint"]) i[n] = On(n, e[n], r[n], i.serializer, t);
765
+ 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.contextProvider !== void 0 && typeof i.contextProvider != "function" && (t.report("config.invalid", "contextProvider must be a function. The library ignores the value."), i.contextProvider = r.contextProvider), 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.");
766
+ else if (i.endpoint !== null) try {
767
+ new URL(i.endpoint);
579
768
  } catch (e) {
580
- t.report("config.invalid", `endpoint is not a valid absolute URL: ${o.endpoint}.`, void 0, e);
581
- }
582
- o.metricsEndpoint !== "" && o.endpoint === null && !o.transport && t.report("config.invalid", "metricsEndpoint needs endpoint or transport. The library sends nothing to metricsEndpoint."), o.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${r}'.`), r);
583
- let s = o.sampling.defaultRate;
584
- (typeof s != "number" || s < 0 || s > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1. The value is ${String(s)}. The library uses 1.`), o.sampling.defaultRate = 1);
585
- let c = o.sampling.remoteMaxRate;
586
- (typeof c != "number" || !(c >= 0 && c <= 1)) && (t.report("config.invalid", `sampling.remoteMaxRate must be 0..1. The value is ${String(c)}. The library uses 1.`), o.sampling.remoteMaxRate = 1);
587
- let l = Object.entries(o.sampling.rates);
588
- for (let [e, n] of l) (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.`), o.sampling.rates[e] = 1);
589
- o.capture.ignoreUrls = o.capture.ignoreUrls.filter((e) => e !== n?.endpoint && e !== n?.metricsEndpoint);
590
- for (let e of [o.endpoint, o.metricsEndpoint]) e && !o.capture.ignoreUrls.includes(e) && (o.capture.ignoreUrls = [...o.capture.ignoreUrls, e]);
591
- return pn(e, t), o;
592
- }
593
- function pn(e, t) {
594
- let n = /* @__PURE__ */ new Set([...Object.keys(a), ...xe]);
769
+ t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}.`, void 0, e);
770
+ }
771
+ for (let e of ["metricsEndpoint", "tracesEndpoint"]) i[e] !== "" && i.endpoint === null && !i.transport && t.report("config.invalid", `${e} needs endpoint or transport. The library sends nothing to ${e}.`);
772
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${me}'.`), me);
773
+ let a = i.sampling.defaultRate;
774
+ (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);
775
+ let s = i.sampling.remoteMaxRate;
776
+ (typeof s != "number" || !(s >= 0 && s <= 1)) && (t.report("config.invalid", `sampling.remoteMaxRate must be 0..1. The value is ${String(s)}. The library uses 1.`), i.sampling.remoteMaxRate = 1);
777
+ let c = Object.entries(i.sampling.rates);
778
+ for (let [e, n] of c) (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);
779
+ i.capture.ignoreUrls = i.capture.ignoreUrls.filter((e) => e !== n?.endpoint && e !== n?.metricsEndpoint && e !== n?.tracesEndpoint);
780
+ for (let e of [
781
+ i.endpoint,
782
+ i.metricsEndpoint,
783
+ i.tracesEndpoint
784
+ ]) e && !i.capture.ignoreUrls.includes(e) && (i.capture.ignoreUrls = [...i.capture.ignoreUrls, e]);
785
+ return An(e, t), i;
786
+ }
787
+ function An(e, t) {
788
+ let n = /* @__PURE__ */ new Set([...Object.keys(o), ...a]);
595
789
  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.`);
596
- for (let n of C) {
790
+ for (let n of S) {
597
791
  let r = e[n];
598
792
  if (typeof r != "object" || !r) continue;
599
- let i = /* @__PURE__ */ new Set([...Object.keys(a[n]), ..._[n]]);
793
+ let i = /* @__PURE__ */ new Set([...Object.keys(o[n]), ...p[n]]);
600
794
  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.`);
601
795
  }
602
796
  }
603
- function mn(e, t) {
604
- for (let n of Object.keys(t)) C.includes(n) || Object.assign(e, { [n]: t[n] });
605
- for (let n of C) Object.assign(e[n], t[n]);
797
+ function jn(e, t) {
798
+ for (let n of Object.keys(t)) S.includes(n) || Object.assign(e, { [n]: t[n] });
799
+ for (let n of S) Object.assign(e[n], t[n]);
606
800
  }
607
801
  //#endregion
608
802
  //#region src/core/context.ts
609
- var hn = class {
803
+ var Mn = class {
610
804
  map = /* @__PURE__ */ new Map();
611
805
  set(e, t) {
612
806
  this.map.set(e, t);
@@ -620,7 +814,7 @@ var hn = class {
620
814
  getAll() {
621
815
  return Object.fromEntries(this.map);
622
816
  }
623
- }, gn = class {
817
+ }, Nn = class {
624
818
  handler;
625
819
  throttleMs;
626
820
  counters = /* @__PURE__ */ new Map();
@@ -648,12 +842,12 @@ var hn = class {
648
842
  count: i
649
843
  }, { handler: s } = this;
650
844
  if (s) try {
651
- A(() => {
845
+ j(() => {
652
846
  s(o);
653
847
  });
654
848
  } catch (e) {
655
- this.count("handler.threw"), typeof console < "u" && A(() => {
656
- console.warn(`${se} The onDiagnostic handler threw an error.`, e);
849
+ this.count("handler.threw"), typeof console < "u" && j(() => {
850
+ console.warn(`${de} The onDiagnostic handler threw an error.`, e);
657
851
  });
658
852
  }
659
853
  }
@@ -679,10 +873,10 @@ var hn = class {
679
873
  };
680
874
  //#endregion
681
875
  //#region src/core/drops.ts
682
- function G(e, t) {
876
+ function K(e, t) {
683
877
  e.length < 20 && !e.includes(t) && e.push(t);
684
878
  }
685
- var _n = class {
879
+ var Pn = class {
686
880
  config;
687
881
  diagnostics;
688
882
  pending = /* @__PURE__ */ new Map();
@@ -701,12 +895,12 @@ var _n = class {
701
895
  journeyIds: [],
702
896
  actions: []
703
897
  }, this.pending.set(e, r)), r.records += t.length;
704
- for (let e of n) G(r.batchIds, e);
898
+ for (let e of n) K(r.batchIds, e);
705
899
  for (let e of t) {
706
- let t = Je(e, E);
707
- typeof t == "string" && G(r.journeyIds, t);
708
- let n = M(e) ? e.body : void 0;
709
- typeof n == "string" && G(r.actions, n);
900
+ let t = Qe(e, D);
901
+ typeof t == "string" && K(r.journeyIds, t);
902
+ let n = N(e) ? e.body : void 0;
903
+ typeof n == "string" && K(r.actions, n);
710
904
  }
711
905
  this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
712
906
  this.flush();
@@ -720,8 +914,8 @@ var _n = class {
720
914
  if (t) {
721
915
  this.reporting = !0;
722
916
  for (let n of e) this.diagnostics.guard("handler.threw", "The onDrop hook threw an error.", () => {
723
- Ye(() => {
724
- A(() => {
917
+ Je(() => {
918
+ j(() => {
725
919
  t(n);
726
920
  });
727
921
  });
@@ -729,7 +923,7 @@ var _n = class {
729
923
  this.reporting = !1;
730
924
  }
731
925
  }
732
- }, vn = class {
926
+ }, Fn = class {
733
927
  onDrop;
734
928
  held = [];
735
929
  actions = 0;
@@ -743,10 +937,10 @@ var _n = class {
743
937
  return this.held.length;
744
938
  }
745
939
  push(e) {
746
- let t = M(e);
940
+ let t = N(e);
747
941
  if ((t ? this.actions : this.held.length - this.actions) < (t ? 2e3 : 500)) this.actions += +!!t;
748
942
  else {
749
- let e = this.held.findIndex((e) => M(e) === t), [n] = this.held.splice(e, 1);
943
+ let e = this.held.findIndex((e) => N(e) === t), [n] = this.held.splice(e, 1);
750
944
  this.onDrop(n);
751
945
  }
752
946
  this.held.push(e);
@@ -755,118 +949,34 @@ var _n = class {
755
949
  let e = this.held;
756
950
  return this.held = [], this.actions = 0, e;
757
951
  }
758
- }, yn = "overflow", bn = /* @__PURE__ */ new Set([
759
- b,
760
- D,
761
- w,
952
+ }, In = "error.", Ln = [
762
953
  T,
763
- E,
764
- y,
765
- fe
766
- ]);
767
- function xn(e = {}) {
768
- let t = {};
769
- for (let n of Object.keys(e).sort()) {
770
- if (n.startsWith("metric.") || bn.has(n)) continue;
771
- let r = e[n];
772
- (typeof r == "string" || typeof r == "boolean" || typeof r == "number" && Number.isFinite(r)) && (t[n] = r);
773
- }
774
- return t;
775
- }
776
- function Sn(e) {
777
- if (!Array.isArray(e)) return null;
778
- let t = Math.min(e.length, 51);
779
- return Array.from({ length: t }, (t, n) => e[n]);
780
- }
781
- function Cn(e) {
782
- return Array.isArray(e) && e.length <= 50 && e.every((t, n) => typeof t == "number" && Number.isFinite(t) && (n === 0 || t > e[n - 1]));
783
- }
784
- function wn(e, t, n) {
785
- let r = {
786
- "metric.name": e.name,
787
- "metric.unit": e.unit,
788
- "metric.type": e.kind,
789
- [k.start]: n,
790
- [k.attributeKeys]: Object.keys(t.attributes)
791
- };
792
- return e.kind === "counter" ? (r["metric.value"] = t.sum, r) : {
793
- ...r,
794
- [k.count]: t.count,
795
- [k.sum]: t.sum,
796
- [k.min]: t.min,
797
- [k.max]: t.max,
798
- [k.bounds]: e.boundaries,
799
- [k.buckets]: t.buckets
800
- };
801
- }
802
- var Tn = class {
803
- intervalMs;
804
- emit;
805
- diagnostics;
806
- instruments = /* @__PURE__ */ new Map();
807
- timer = null;
808
- startedAt = 0;
809
- constructor(e, t, n) {
810
- this.intervalMs = e, this.emit = t, this.diagnostics = n;
811
- }
812
- record(e, t, n) {
813
- !Number.isFinite(t) || e.kind === "counter" && t < 0 ? this.diagnostics.report("record.dropped_malformed", `The value of the metric ${e.name} is not valid. The library dropped it.`, { "metric.name": e.name }) : this.diagnostics.guard("record.sanitize_failed", `The library could not read the attributes of the metric ${e.name}.`, () => {
814
- let r = this.instrumentOf(e);
815
- r && (this.add(r, t, xn(n)), this.arm());
816
- });
817
- }
818
- collect() {
819
- this.timer !== null && (clearTimeout(this.timer), this.timer = null);
820
- let e = `${String(this.startedAt)}000000`, t = [...this.instruments.values()];
821
- this.instruments.clear();
822
- for (let { def: n, series: r } of t) for (let t of r.values()) this.emit(n.name, t.attributes, wn(n, t, e));
823
- }
824
- instrumentOf(e) {
825
- let t = this.instruments.get(e.name);
826
- if (t) return t.def.kind === e.kind ? t : (this.diagnostics.report("record.dropped_malformed", `The metric ${e.name} is a counter and a histogram. The library dropped the value.`, { "metric.name": e.name }), null);
827
- let n = Sn(e.boundaries), r = Cn(n);
828
- e.kind === "histogram" && !r && this.diagnostics.report("config.invalid", `The boundaries of the metric ${e.name} must be at most 50 finite numbers in ascending order. The library uses the default boundaries.`);
829
- let i = {
830
- def: {
831
- ...e,
832
- boundaries: r ? n : [...ae]
833
- },
834
- series: /* @__PURE__ */ new Map()
835
- };
836
- return this.instruments.set(e.name, i), i;
837
- }
838
- add(e, t, n) {
839
- let r = JSON.stringify(n), i = e.series.get(r), a = n;
840
- if (!i && e.series.size >= 100 && (r = yn, i = e.series.get(r), a = { [oe]: !0 }), !i) {
841
- let n = e.def.kind === "histogram" ? e.def.boundaries.length + 1 : 0, o = Array(n).fill(0);
842
- i = {
843
- attributes: a,
844
- count: 0,
845
- sum: 0,
846
- min: t,
847
- max: t,
848
- buckets: o
849
- }, e.series.set(r, i);
850
- }
851
- if (i.count += 1, i.sum += t, i.min = Math.min(i.min, t), i.max = Math.max(i.max, t), i.buckets.length > 0) {
852
- let n = e.def.boundaries.findIndex((e) => t <= e);
853
- i.buckets[n === -1 ? i.buckets.length - 1 : n] += 1;
854
- }
855
- }
856
- arm() {
857
- this.timer === null && (this.startedAt = Date.now(), this.timer = setTimeout(() => {
858
- this.collect();
859
- }, this.intervalMs()), ke(this.timer));
860
- }
861
- }, En = "error.", Dn = [
862
- T,
863
- E,
954
+ D,
864
955
  y
956
+ ], Rn = {
957
+ processor: {
958
+ label: "A processor",
959
+ code: "record.dropped_by_processor"
960
+ },
961
+ redact: {
962
+ label: "The redact hook",
963
+ code: "record.dropped_by_redact"
964
+ }
965
+ }, zn = [
966
+ "metric.name",
967
+ "metric.unit",
968
+ "metric.type",
969
+ "metric.value",
970
+ ...Object.values(_),
971
+ ...Object.values(C)
865
972
  ];
866
- function K(e) {
973
+ function Bn(e) {
974
+ return Object.fromEntries(zn.filter((t) => t in e).map((t) => [t, e[t]]));
975
+ }
976
+ function q(e) {
867
977
  return e;
868
978
  }
869
- var On = class {
979
+ var Vn = class {
870
980
  deps;
871
981
  resourceCache = null;
872
982
  constructor(e) {
@@ -875,20 +985,20 @@ var On = class {
875
985
  invalidateResource() {
876
986
  this.resourceCache = null;
877
987
  }
878
- isEnabled(e, t) {
879
- let { config: n } = this.deps;
880
- if (!n.enabled) return !1;
881
- if (t !== void 0 && pe.includes(t)) return !0;
882
- let r = this.deps.remote.sampling?.minLevel() ?? n.minLevel;
883
- return O[e] >= O[r];
988
+ isEnabled(e, t, n) {
989
+ let { config: r } = this.deps;
990
+ if (!r.enabled) return !1;
991
+ if (n !== void 0 && ue.includes(n)) return !0;
992
+ let i = this.deps.remote.sampling?.minLevelFor(t) ?? Ne(t, r);
993
+ return E[e] >= E[i];
884
994
  }
885
995
  build(e) {
886
996
  let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o, remote: s } = this.deps;
887
- if (!this.isEnabled(e.level, e.type)) return n.count("record.dropped_by_level"), {
997
+ if (!this.isEnabled(e.level, e.namespace, e.type)) return n.count("record.dropped_by_level"), {
888
998
  record: null,
889
999
  dropped: "level"
890
1000
  };
891
- let c = r.resolve(), l = i.current();
1001
+ let c = e.trace ?? r.resolve(), l = i.current();
892
1002
  if (!Pe({
893
1003
  level: e.level,
894
1004
  type: e.type,
@@ -900,66 +1010,39 @@ var On = class {
900
1010
  record: null,
901
1011
  dropped: "sampling"
902
1012
  };
903
- let u = a.next(), d = qe(n), f = t.capture.fullUrls ? d : Ge(d), p, m = 0;
1013
+ let u = a.next(), d = Ze(n), f = Ye(d, t.capture.fullUrls), p, m = 0;
904
1014
  try {
905
- let t = j(this.deps.context.getAll(), o, n), r = j(e.scoped ?? {}, o, n), i = j(e.payload ?? {}, o, n);
906
- m = t.bytes + r.bytes + i.bytes, p = {
907
- ...K(t.value),
908
- ...K(r.value),
909
- ...K(i.value)
1015
+ let t = M(this.deps.context.getAll(), o, n), r = M(this.provided(), o, n), i = M(e.scoped ?? {}, o, n), a = M(e.payload ?? {}, o, n);
1016
+ m = t.bytes + r.bytes + i.bytes + a.bytes, p = {
1017
+ ...q(t.value),
1018
+ ...q(r.value),
1019
+ ...q(i.value),
1020
+ ...q(a.value)
910
1021
  };
911
1022
  } catch (e) {
912
- n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [me]: !0 };
1023
+ n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [ge]: !0 };
913
1024
  }
914
- Object.assign(p, e.fixed), p[b] = e.type, p[D] = u, p[w] = e.namespace, p[T] = f, l && (p[E] = l.id, p[y] = l.name, l.parentId !== void 0 && (p[fe] = l.parentId));
915
- let h = Ie(e.body, o.maxBodyChars);
1025
+ Object.assign(p, e.fixed), p[b] = e.type, p[O] = u, p[w] = e.namespace, p[T] = f, l && (p[D] = l.id, p[y] = l.name, l.parentId !== void 0 && (p[he] = l.parentId));
1026
+ let h = ze(e.body, o.maxBodyChars);
916
1027
  h !== e.body && n.count("record.truncated");
917
1028
  let g = {
918
- timeUnixNano: Ne(),
1029
+ timeUnixNano: Ie(),
919
1030
  traceId: c.traceId,
920
1031
  spanId: c.spanId,
921
1032
  traceFlags: c.traceFlags,
922
- severityNumber: ue[e.level],
1033
+ severityNumber: se[e.level],
923
1034
  severityText: e.level,
924
1035
  body: h,
925
1036
  attributes: p,
926
1037
  resource: this.resource()
927
- }, _ = t.redact;
928
- if (_) {
929
- let t;
930
- try {
931
- t = _(g);
932
- } catch (e) {
933
- return n.report("record.dropped_by_redact", "The redact hook threw an error. The library dropped the record.", void 0, e), {
934
- record: null,
935
- dropped: "redact"
936
- };
937
- }
938
- if (t === null) return n.count("record.dropped_by_redact"), {
939
- record: null,
940
- dropped: "redact"
941
- };
942
- let r = t ?? g;
943
- if (!Ae(r)) return r === g ? (n.report("record.dropped_malformed", "The redact hook changed the record to a shape that is not a record. The library dropped it."), {
944
- record: null,
945
- dropped: "malformed"
946
- }) : (n.report("record.dropped_by_redact", "The redact hook returned a value that is not a record. The library dropped the record."), {
1038
+ }, _ = t.processors.map((e) => [e, "processor"]);
1039
+ if (t.redact && _.push([t.redact, "redact"]), _.length > 0) {
1040
+ let t = this.applyHooks(g, _, e.fixed);
1041
+ if (typeof t == "string") return {
947
1042
  record: null,
948
- dropped: "redact"
949
- });
950
- if (je(r.severityText)) {
951
- if (r !== g) {
952
- let t = j(r.attributes, o, n);
953
- g = {
954
- ...r,
955
- attributes: K(t.value)
956
- }, m = t.bytes, Object.assign(g.attributes, e.fixed);
957
- }
958
- g.severityNumber = ue[g.severityText];
959
- } else return n.report("record.dropped_malformed", "The redact hook set a severityText that is not a log level. The library dropped the record."), {
960
- record: null,
961
- dropped: "malformed"
1043
+ dropped: t
962
1044
  };
1045
+ ({record: g, bytes: m} = t);
963
1046
  }
964
1047
  if (m > o.maxRecordBytes) {
965
1048
  n.report("record.truncated", "The attributes are larger than the size limit. The library dropped the caller attributes.", {
@@ -968,63 +1051,150 @@ var On = class {
968
1051
  });
969
1052
  let t = {
970
1053
  [b]: e.type,
971
- [D]: u,
1054
+ [O]: u,
972
1055
  [w]: e.namespace,
973
- [le]: !0,
974
- [ve]: m
1056
+ [fe]: !0,
1057
+ [be]: m
975
1058
  };
976
- for (let e of Dn) e in g.attributes && (t[e] = g.attributes[e]);
977
- for (let [e, n] of Object.entries(g.attributes)) e.startsWith(En) && (t[e] = n);
978
- let r = j(t, o, n).bytes;
979
- r > o.maxRecordBytes && "error.data" in t && (Reflect.deleteProperty(t, ge), r = j(t, o, n).bytes);
1059
+ for (let e of Ln) e in g.attributes && (t[e] = g.attributes[e]);
1060
+ for (let [e, n] of Object.entries(g.attributes)) e.startsWith(In) && (t[e] = n);
1061
+ let r = M(t, o, n).bytes;
1062
+ r > o.maxRecordBytes && "error.data" in t && (Reflect.deleteProperty(t, ve), r = M(t, o, n).bytes);
980
1063
  let i = g.attributes[v];
981
1064
  if (i !== void 0) {
982
- let e = j(i, o, n).bytes;
1065
+ let e = M(i, o, n).bytes;
983
1066
  r + e <= o.maxRecordBytes && (t[v] = i);
984
1067
  }
985
1068
  Object.assign(t, e.fixed), g.attributes = t;
986
1069
  }
987
1070
  return { record: g };
988
1071
  }
1072
+ redactForwarded(e) {
1073
+ let { redact: t } = this.deps.config;
1074
+ if (!t) return e;
1075
+ let n = [[t, "redact"]], r = this.applyHooks(e, n, Bn(e.attributes));
1076
+ return typeof r == "string" ? null : r.record;
1077
+ }
1078
+ applyHooks(e, t, n) {
1079
+ let r = e;
1080
+ for (let [e, n] of t) {
1081
+ let t = this.runHook(e, n, r);
1082
+ if (typeof t == "string") return t;
1083
+ r = t;
1084
+ }
1085
+ let { diagnostics: i, limits: a } = this.deps, o = M(r.attributes, a, i), s = q(o.value);
1086
+ return Object.assign(s, n), {
1087
+ record: {
1088
+ ...r,
1089
+ attributes: s
1090
+ },
1091
+ bytes: o.bytes
1092
+ };
1093
+ }
1094
+ runHook(e, t, n) {
1095
+ let { diagnostics: r } = this.deps, { label: i, code: a } = Rn[t], o;
1096
+ try {
1097
+ o = e(n);
1098
+ } catch (e) {
1099
+ return r.report(a, `${i} threw an error. The library dropped the record.`, void 0, e), t;
1100
+ }
1101
+ if (o === null) return r.count(a), t;
1102
+ let s = o ?? n;
1103
+ return Fe(s) ? Le(s.severityText) ? {
1104
+ ...s,
1105
+ severityNumber: se[s.severityText]
1106
+ } : (r.report("record.dropped_malformed", `${i} set a severityText that is not a log level. The library dropped the record.`), "malformed") : s === n ? (r.report("record.dropped_malformed", `${i} changed the record to a shape that is not a record. The library dropped it.`), "malformed") : (r.report(a, `${i} returned a value that is not a record. The library dropped the record.`), t);
1107
+ }
1108
+ provided() {
1109
+ let e = this.deps.config.contextProvider;
1110
+ if (!e) return {};
1111
+ let { diagnostics: t } = this.deps, n = t.guard("handler.threw", "The contextProvider threw an error. The record has no attributes from it.", () => {
1112
+ let t = e();
1113
+ return t === void 0 ? {} : A(t) && typeof t.then != "function" ? t : null;
1114
+ });
1115
+ return n === null && t.report("config.invalid", "contextProvider must return an object of attributes. The library ignores the value."), n ?? {};
1116
+ }
989
1117
  resource() {
990
1118
  if (this.resourceCache) return this.resourceCache;
991
- let { config: e, identity: t, platform: r } = this.deps;
1119
+ let { config: e, identity: n, platform: r } = this.deps;
992
1120
  return this.resourceCache = {
993
- [te]: e.serviceName,
994
- [c]: e.serviceVersion,
995
- [p]: e.environment,
996
- [d]: ce,
997
- [_e]: S,
998
- [s]: he,
999
- [h]: r.platform,
1000
- [ee]: t.sessionId,
1001
- [ne]: t.tabId,
1002
- [u]: t.contextId,
1003
- [o]: r.userAgent,
1004
- ...r.openfinUuid === void 0 ? {} : { [n]: r.openfinUuid },
1005
- ...r.openfinName === void 0 ? {} : { [we]: r.openfinName }
1121
+ [s]: e.serviceName,
1122
+ [d]: e.serviceVersion,
1123
+ [te]: e.environment,
1124
+ [re]: oe,
1125
+ [ae]: k,
1126
+ [ie]: we,
1127
+ [c]: r.platform,
1128
+ [ye]: n.sessionId,
1129
+ [u]: n.tabId,
1130
+ [t]: n.contextId,
1131
+ [Ee]: r.userAgent,
1132
+ ...r.openfinUuid === void 0 ? {} : { [ne]: r.openfinUuid },
1133
+ ...r.openfinName === void 0 ? {} : { [ee]: r.openfinName }
1006
1134
  }, this.resourceCache;
1007
1135
  }
1008
- }, kn = {
1009
- errors: async () => (await import("./errors-DCZWcHkd.js")).ErrorCapture,
1010
- network: async () => (await import("./network--GoE7_Or.js")).NetworkCapture,
1011
- interactions: async () => (await import("./interactions-BLH_tX87.js")).InteractionCapture,
1136
+ }, Hn = 1e3, Un = {
1137
+ start: "ui.start",
1138
+ interaction: "ui.interaction",
1139
+ navigation: "ui.navigation",
1140
+ explicit: "ui.trace",
1141
+ maxAge: "ui.trace"
1142
+ };
1143
+ function Wn(e) {
1144
+ return `${String(Math.round(e * Hn))}000`;
1145
+ }
1146
+ function Gn(e) {
1147
+ return {
1148
+ name: Un[e.reason],
1149
+ kind: "internal",
1150
+ traceId: e.traceId,
1151
+ spanId: e.spanId,
1152
+ parentSpanId: "",
1153
+ startMs: e.startedAt,
1154
+ endMs: e.endedAt,
1155
+ error: !1,
1156
+ attributes: {}
1157
+ };
1158
+ }
1159
+ function Kn(e) {
1160
+ return {
1161
+ [C.kind]: e.kind,
1162
+ [C.parentId]: e.parentSpanId,
1163
+ [C.start]: Wn(e.startMs),
1164
+ [C.end]: Wn(e.endMs),
1165
+ [C.status]: e.error ? "error" : "unset"
1166
+ };
1167
+ }
1168
+ //#endregion
1169
+ //#region src/core/runtime.ts
1170
+ var qn = {
1171
+ errors: async () => (await import("./errors-BDI96zKc.js")).ErrorCapture,
1172
+ network: async () => (await import("./network-BsBZ6_-Q.js")).NetworkCapture,
1173
+ interactions: async () => (await import("./interactions-Ck01cEij.js")).InteractionCapture,
1012
1174
  webVitals: async () => (await import("./web-vitals-Bflr5jSA.js")).WebVitalsCapture,
1013
- longFrames: async () => (await import("./long-frames-DD_Um9_4.js")).LongFrameCapture,
1014
- console: async () => (await import("./console-Dv5GfaNn.js")).ConsoleCapture
1015
- }, q = Symbol.for(re), J = Symbol.for(m), An = ["batching", "retention"];
1016
- function Y(e) {
1175
+ longFrames: async () => (await import("./long-frames-DDumopji.js")).LongFrameCapture,
1176
+ console: async () => (await import("./console-BT7mcgU6.js")).ConsoleCapture
1177
+ }, Jn = /* @__PURE__ */ new WeakMap(), Yn = 0;
1178
+ function Xn(e) {
1179
+ let t = Jn.get(e);
1180
+ return t === void 0 && (t = ++Yn, Jn.set(e, t)), t;
1181
+ }
1182
+ var J = Symbol.for(xe), Y = Symbol.for(_e), Zn = ["batching", "retention"];
1183
+ function Qn(e) {
1017
1184
  return JSON.stringify({
1018
1185
  ...e,
1019
1186
  webVitalsLoader: e.webVitalsLoader !== void 0,
1020
1187
  ignoreUrls: e.ignoreUrls.map(String),
1021
- propagateTraceHeaderTo: e.propagateTraceHeaderTo.map(String)
1188
+ propagateTraceHeaderTo: e.propagateTraceHeaderTo.map(String),
1189
+ plugins: e.plugins.map(Xn)
1022
1190
  });
1023
1191
  }
1024
- function jn(e) {
1192
+ function $n(e) {
1025
1193
  return {
1026
1194
  ...e,
1027
1195
  endpoint: null,
1196
+ metricsEndpoint: "",
1197
+ tracesEndpoint: "",
1028
1198
  transport: void 0,
1029
1199
  transportOnExit: void 0,
1030
1200
  bus: {
@@ -1033,13 +1203,15 @@ function jn(e) {
1033
1203
  }
1034
1204
  };
1035
1205
  }
1206
+ function er(e) {
1207
+ return !!e.endpoint || !!e.metricsEndpoint || !!e.tracesEndpoint || e.transport !== void 0;
1208
+ }
1036
1209
  function X(e) {
1037
- return e.sdkVersion === S;
1210
+ return e.sdkVersion === k;
1038
1211
  }
1039
1212
  var Z = class e {
1040
- degraded;
1041
1213
  static local = null;
1042
- sdkVersion = S;
1214
+ sdkVersion = k;
1043
1215
  diagnostics;
1044
1216
  config;
1045
1217
  platform;
@@ -1047,10 +1219,10 @@ var Z = class e {
1047
1219
  stores;
1048
1220
  identityBuiltAs;
1049
1221
  sessionTouch;
1050
- context = new hn();
1222
+ context = new Mn();
1051
1223
  breadcrumbs;
1052
1224
  tracing;
1053
- sequence = new lt();
1225
+ sequence = new xt();
1054
1226
  journey;
1055
1227
  builder;
1056
1228
  remote = { sampling: null };
@@ -1063,7 +1235,7 @@ var Z = class e {
1063
1235
  storageBuiltAs;
1064
1236
  sender;
1065
1237
  senderLoad;
1066
- pendingRecords = new vn((e) => {
1238
+ pendingRecords = new Fn((e) => {
1067
1239
  this.dropHeld(e);
1068
1240
  });
1069
1241
  captures = [];
@@ -1073,7 +1245,7 @@ var Z = class e {
1073
1245
  navigationTiming: !1,
1074
1246
  longFrames: !1
1075
1247
  };
1076
- bootBuffer = new vn((e) => {
1248
+ bootBuffer = new Fn((e) => {
1077
1249
  this.dropHeld(e);
1078
1250
  });
1079
1251
  forwardBuffer = [];
@@ -1086,13 +1258,26 @@ var Z = class e {
1086
1258
  limits;
1087
1259
  journeyOptions;
1088
1260
  tunablesLocked = !0;
1261
+ degraded;
1262
+ serverReported = !1;
1263
+ onPageHide = () => {
1264
+ this.role() === "forwarder" && (this.tracing.end(), this.sendForwarded());
1265
+ };
1089
1266
  constructor(e, t = !1) {
1090
- this.degraded = t, this.diagnostics = new gn(e.onDiagnostic), this.platform = Ke(this.diagnostics), this.config = fn(e, this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" ? He() : We, this.identity = Ue(this.diagnostics, this.stores), this.sessionTouch = new Be(this.diagnostics, this.stores), this.breadcrumbs = new yt(50), this.tracing = new vt(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.limits = { ...this.config.limits }, this.console = new ct(this.config.console, this.diagnostics, this.limits), this.drops = new _n(this.config, this.diagnostics), this.journeyOptions = {
1091
- ...Ze,
1267
+ this.diagnostics = new Nn(e.onDiagnostic), this.platform = Xe(this.diagnostics), this.degraded = t || this.onServer(), this.config = kn(this.allowed(e), this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" || this.onServer() ? Ge() : qe, this.identity = Ke(this.diagnostics, this.stores), this.sessionTouch = new Ue(this.diagnostics, this.stores), this.breadcrumbs = new Mt(50);
1268
+ let n = (e) => je(e, this.config.sampling.defaultRate);
1269
+ this.tracing = new jt(this.diagnostics, void 0, this.config.otelLoader, {
1270
+ enabled: () => this.config.tracesEndpoint !== "",
1271
+ keeps: n,
1272
+ onEnd: (e) => {
1273
+ n(e.traceId) && this.recordSpan(Gn(e));
1274
+ }
1275
+ }), this.tracing.loadOtel(), this.limits = { ...this.config.limits }, this.console = new bt(this.config.console, this.diagnostics, this.limits), this.drops = new Pn(this.config, this.diagnostics), this.journeyOptions = {
1276
+ ...et,
1092
1277
  maxAgeMs: this.config.journey.maxAgeMs
1093
- }, this.journey = new Xe(this.journeyOptions, this.diagnostics, this.identity.contextId, (e) => {
1278
+ }, this.journey = new $e(this.journeyOptions, this.diagnostics, this.identity.contextId, (e) => {
1094
1279
  this.bus?.broadcastJourney(e);
1095
- }, this.stores), this.builder = new On({
1280
+ }, this.stores), this.builder = new Vn({
1096
1281
  remote: this.remote,
1097
1282
  config: this.config,
1098
1283
  limits: this.limits,
@@ -1103,24 +1288,55 @@ var Z = class e {
1103
1288
  sequence: this.sequence,
1104
1289
  identity: this.identity,
1105
1290
  platform: this.platform
1106
- }), this.meter = new Tn(() => this.config.batching.metricFlushIntervalMs, (e, t, n) => {
1291
+ }), this.meter = new vt(() => this.config.batching.metricFlushIntervalMs, (e, t, n) => {
1107
1292
  this.emitPoint(e, t, n);
1108
1293
  }, this.diagnostics);
1109
1294
  }
1295
+ addBreadcrumb(e, t) {
1296
+ this.diagnostics.guard("record.sanitize_failed", "The library could not add the breadcrumb.", () => {
1297
+ let n = {
1298
+ t: Date.now(),
1299
+ category: "custom",
1300
+ message: ze(String(e), this.limits.maxBodyChars)
1301
+ };
1302
+ if (t !== void 0) {
1303
+ let e = Be(t, this.limits, this.diagnostics);
1304
+ n.data = A(e) ? e : { value: e };
1305
+ }
1306
+ this.breadcrumbs.push(n);
1307
+ });
1308
+ }
1110
1309
  recordMetric(e, t, n) {
1111
1310
  this.destroyed || this.meter.record(e, t, n);
1112
1311
  }
1312
+ recordSpan(e) {
1313
+ if (this.config.tracesEndpoint === "") return;
1314
+ let { record: t } = this.builder.build({
1315
+ level: "INFO",
1316
+ type: "span",
1317
+ body: e.name,
1318
+ namespace: Se,
1319
+ payload: e.attributes,
1320
+ fixed: Kn(e),
1321
+ trace: {
1322
+ traceId: e.traceId,
1323
+ spanId: e.spanId,
1324
+ traceFlags: 1
1325
+ }
1326
+ });
1327
+ this.emit(t);
1328
+ }
1113
1329
  emitPoint(e, t, n) {
1114
- let { record: r } = this.builder.build({
1330
+ let { record: i } = this.builder.build({
1115
1331
  level: "INFO",
1116
1332
  type: "metric",
1117
1333
  body: e,
1118
- namespace: Se,
1334
+ namespace: r,
1119
1335
  payload: t,
1120
1336
  fixed: n,
1121
1337
  aggregated: !0
1122
1338
  });
1123
- this.emit(r);
1339
+ this.emit(i);
1124
1340
  }
1125
1341
  busAccept = (e, t) => {
1126
1342
  this.destroyed || this.ensureBus().then((n) => {
@@ -1130,7 +1346,7 @@ var Z = class e {
1130
1346
  });
1131
1347
  };
1132
1348
  static pinned() {
1133
- return globalThis[q] ?? null;
1349
+ return globalThis[J] ?? null;
1134
1350
  }
1135
1351
  static current() {
1136
1352
  let t = e.local;
@@ -1141,7 +1357,7 @@ var Z = class e {
1141
1357
  static stopped() {
1142
1358
  let t = e.local;
1143
1359
  if (t?.destroyed) return t;
1144
- let n = globalThis[J];
1360
+ let n = globalThis[Y];
1145
1361
  return n && X(n) ? n : null;
1146
1362
  }
1147
1363
  isDestroyed() {
@@ -1149,7 +1365,7 @@ var Z = class e {
1149
1365
  }
1150
1366
  static configure(t, n = !1) {
1151
1367
  let r = e.local;
1152
- if (r && !r.destroyed) return r.reconfigure(jn(t)), r;
1368
+ if (r && !r.destroyed) return r.reconfigure(t), r;
1153
1369
  e.local = null;
1154
1370
  let i = e.pinned();
1155
1371
  if (i) {
@@ -1157,23 +1373,29 @@ var Z = class e {
1157
1373
  if (!i.destroyed) return i.reconfigure(t), i;
1158
1374
  }
1159
1375
  let a = new e(t);
1160
- return a.tunablesLocked = !n, globalThis[q] = a, Reflect.deleteProperty(globalThis, J), a.init(), a;
1376
+ return a.tunablesLocked = !n, globalThis[J] = a, Reflect.deleteProperty(globalThis, Y), a.init(), a;
1161
1377
  }
1162
1378
  static startDegraded(t, n) {
1163
- let r = new e(jn(t), !0);
1379
+ let r = new e(t, !0);
1164
1380
  e.local = r;
1165
1381
  let i = typeof n == "string" ? n : "before 0.9.0";
1166
- 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.`, {
1382
+ return r.diagnostics.report("runtime.version_mismatch", `Another copy of the library, version ${i}, owns the page runtime. This copy, version ${k}, runs in console-only mode and installs no capture. Load one version of the library on the page.`, {
1167
1383
  found: i,
1168
- own: S
1384
+ own: k
1169
1385
  }), r.init(), r;
1170
1386
  }
1171
1387
  reconfigure(e) {
1172
- let t = this.keepDestination(e), n = Y(this.config.capture), r = fn(t, this.diagnostics, this.config);
1173
- this.keepStartupTunables(r), mn(this.config, r), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), Y(this.config.capture) !== n && this.installCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1388
+ let t = this.keepDestination(this.allowed(e)), n = Qn(this.config.capture), r = kn(t, this.diagnostics, this.config);
1389
+ this.keepStartupTunables(r), jn(this.config, r), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), Qn(this.config.capture) !== n && this.installCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1390
+ }
1391
+ onServer() {
1392
+ return this.platform.platform === "node";
1393
+ }
1394
+ allowed(e) {
1395
+ return this.degraded ? (this.onServer() && !this.serverReported && er(e) && (this.serverReported = !0, this.diagnostics.report("config.invalid", "The library runs console-only on Node. It sends no record and installs no capture. It ignores endpoint, metricsEndpoint, tracesEndpoint and transport.")), $n(e)) : e;
1174
1396
  }
1175
1397
  keepStartupTunables(e) {
1176
- if (this.senderLoad !== void 0 && this.keepSections(e, An), !this.tunablesLocked) {
1398
+ if (this.senderLoad !== void 0 && this.keepSections(e, Zn), !this.tunablesLocked) {
1177
1399
  this.tunablesLocked = !0, Object.assign(this.limits, e.limits), this.journeyOptions.maxAgeMs = e.journey.maxAgeMs;
1178
1400
  return;
1179
1401
  }
@@ -1201,6 +1423,7 @@ var Z = class e {
1201
1423
  this.config.identity !== e && (this.diagnostics.report("config.invalid", `identity cannot change after startup. It stays ${e}.`, { requested: this.config.identity }), this.config.identity = e);
1202
1424
  }
1203
1425
  async init() {
1426
+ this.degraded || addEventListener("pagehide", this.onPageHide);
1204
1427
  let e = this.installCaptures();
1205
1428
  this.started = this.boot(), await this.started, await e;
1206
1429
  }
@@ -1231,7 +1454,7 @@ var Z = class e {
1231
1454
  }
1232
1455
  async buildBus() {
1233
1456
  try {
1234
- let { Bus: e } = await import("./bus-C6RwKzPW.js");
1457
+ let { Bus: e } = await import("./bus-Cyvq-Ngx.js");
1235
1458
  if (this.destroyed) return null;
1236
1459
  let t = new e(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
1237
1460
  onRecords: (e) => {
@@ -1266,14 +1489,14 @@ var Z = class e {
1266
1489
  async buildSender() {
1267
1490
  this.storageBuiltAs = this.config.storage;
1268
1491
  try {
1269
- let { Sender: e } = await import("./sender-BUBWLn5i.js"), t = this.destroyed ? null : await e.create({
1492
+ let { Sender: e } = await import("./sender-DFQMF39P.js"), t = this.destroyed ? null : await e.create({
1270
1493
  config: this.config,
1271
1494
  diagnostics: this.diagnostics,
1272
1495
  onGap: this.reportGap,
1273
1496
  onLoss: this.reportLoss,
1274
1497
  remote: this.remote,
1275
1498
  beforeExit: () => {
1276
- this.meter.collect();
1499
+ this.meter.collect(), this.tracing.end();
1277
1500
  }
1278
1501
  });
1279
1502
  if (!t || this.destroyed) {
@@ -1290,21 +1513,26 @@ var Z = class e {
1290
1513
  if (this.degraded) return;
1291
1514
  let e = ++this.captureGeneration, t = this.config.capture, n = [];
1292
1515
  (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");
1293
- let r = await Promise.all(n.map((e) => this.loadCapture(e)));
1516
+ let [r, a] = await Promise.all([Promise.all(n.map((e) => this.loadCapture(e))), t.webSocket ? this.loadWebSocket() : void 0]);
1294
1517
  if (e !== this.captureGeneration || this.destroyed) return;
1295
1518
  this.uninstallCaptures();
1296
- let a = {
1519
+ let o = {
1297
1520
  config: this.config,
1298
1521
  diagnostics: this.diagnostics,
1299
1522
  breadcrumbs: this.breadcrumbs,
1300
1523
  tracing: this.tracing,
1301
- logger: new I(() => this, i),
1524
+ logger: new L(() => this, i),
1302
1525
  once: this.captureOnce,
1303
1526
  recordMetric: (e, t, n) => {
1304
1527
  this.recordMetric(e, t, n);
1528
+ },
1529
+ recordSpan: (e) => {
1530
+ this.recordSpan(e);
1305
1531
  }
1306
1532
  };
1307
- for (let e of r) e && this.captures.push(new e(a));
1533
+ for (let e of r) e && this.captures.push(new e(o));
1534
+ let s = a ? [...t.plugins, new a(this.diagnostics, this.config)] : t.plugins;
1535
+ for (let e of s) this.captures.push(this.pluginCapture(e));
1308
1536
  for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `The library could not install the ${e.name} capture.`, () => {
1309
1537
  e.install();
1310
1538
  });
@@ -1315,8 +1543,33 @@ var Z = class e {
1315
1543
  });
1316
1544
  this.captures.length = 0;
1317
1545
  }
1546
+ loadWebSocket() {
1547
+ return this.diagnostics.guardAsync("capture.install_failed", "The library could not load the webSocket capture.", async () => (await import("./web-socket-Ar4cZxmd.js")).WebSocketCapture);
1548
+ }
1549
+ pluginCapture(e) {
1550
+ let { name: t } = e, n = (e, t, n) => {
1551
+ this.recordMetric(e, t, n);
1552
+ }, r = {
1553
+ logger: new L(() => this, `${i}.${t}`),
1554
+ counter: (e, t = {}) => gt(e, t, n),
1555
+ histogram: (e, t = {}) => _t(e, t, n),
1556
+ addBreadcrumb: (e, t) => {
1557
+ this.addBreadcrumb(e, t);
1558
+ },
1559
+ ownRequest: Je
1560
+ };
1561
+ return {
1562
+ name: t,
1563
+ install: () => {
1564
+ e.install(r);
1565
+ },
1566
+ uninstall: () => {
1567
+ e.uninstall();
1568
+ }
1569
+ };
1570
+ }
1318
1571
  loadCapture(e) {
1319
- return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, kn[e]);
1572
+ return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, qn[e]);
1320
1573
  }
1321
1574
  registerWorker(e) {
1322
1575
  this.destroyed || this.constructBus().then((t) => {
@@ -1327,9 +1580,9 @@ var Z = class e {
1327
1580
  }
1328
1581
  async destroy() {
1329
1582
  if (this.destroyed) return;
1330
- this.meter.collect(), this.destroyed = !0, this.uninstallCaptures();
1583
+ this.meter.collect(), this.tracing.end(), this.destroyed = !0, this.degraded || removeEventListener("pagehide", this.onPageHide), this.uninstallCaptures();
1331
1584
  let t = this.sender?.destroy();
1332
- 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, q), globalThis[J] = this);
1585
+ 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);
1333
1586
  }
1334
1587
  emit(e) {
1335
1588
  e && !this.destroyed && (this.sessionTouch.touch(this.identity.sessionId), this.ready ? this.route(e) : this.bootBuffer.push(e));
@@ -1354,11 +1607,22 @@ var Z = class e {
1354
1607
  }
1355
1608
  ingestForwarded(e) {
1356
1609
  if (!Array.isArray(e)) this.diagnostics.count("record.dropped_malformed");
1357
- else for (let t of e) Ae(t) ? Me(t, this.config, this.remote.sampling?.current() ?? null) ? this.deliver(t) : this.diagnostics.count("record.dropped_by_sampling") : this.diagnostics.count("record.dropped_malformed");
1610
+ else for (let t of e) {
1611
+ if (!Fe(t)) {
1612
+ this.diagnostics.count("record.dropped_malformed");
1613
+ continue;
1614
+ }
1615
+ if (!Ae(t, this.config, this.remote.sampling?.current() ?? null)) {
1616
+ this.diagnostics.count("record.dropped_by_sampling");
1617
+ continue;
1618
+ }
1619
+ let e = this.builder.redactForwarded(t);
1620
+ e && this.deliver(e);
1621
+ }
1358
1622
  }
1359
1623
  releaseBootBuffer() {
1360
- let e = this.bootBuffer.take(), t = this.journey.current();
1361
- 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);
1624
+ let e = this.bootBuffer.take(), { processors: t, redact: n } = this.config, r = t.length === 0 && n === void 0 ? this.journey.current() : null;
1625
+ for (let t of e) r && !t.attributes["journey.id"] && (t.attributes["journey.id"] = r.id, t.attributes["journey.name"] = r.name), this.route(t);
1362
1626
  }
1363
1627
  reportLoss = (e, t, n) => {
1364
1628
  this.drops.add(e, t, n);
@@ -1366,18 +1630,36 @@ var Z = class e {
1366
1630
  reportGap = (e, t) => {
1367
1631
  this.drops.add(e.reason, t.flatMap((e) => e.records), t.map((e) => e.id));
1368
1632
  let n = Date.now();
1369
- n - this.lastGapAt < 6e4 || (this.lastGapAt = n, new I(() => this, ye).warn("stored records were dropped before delivery", {
1633
+ n - this.lastGapAt < 6e4 || (this.lastGapAt = n, new L(() => this, le).warn("stored records were dropped before delivery", {
1370
1634
  "gap.batches": e.batches,
1371
1635
  "gap.records": e.records,
1372
1636
  "gap.reason": e.reason
1373
1637
  }));
1374
1638
  };
1375
1639
  regenerateTabId() {
1376
- let e = ze(this.diagnostics);
1640
+ let e = He(this.diagnostics);
1377
1641
  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.", {
1378
1642
  was: this.identity.tabId,
1379
1643
  now: e
1380
- }), this.identity.tabId = e, Re(e, this.diagnostics, this.stores), this.builder.invalidateResource();
1644
+ }), this.identity.tabId = e, Ve(e, this.diagnostics, this.stores), this.builder.invalidateResource();
1645
+ }
1646
+ newSession() {
1647
+ if (this.destroyed) return;
1648
+ this.meter.collect(), this.tracing.rotate("explicit"), this.journey.end(), this.breadcrumbs.clear();
1649
+ let e = He(this.diagnostics);
1650
+ this.identity.sessionId = e, this.sessionTouch.restart(e), this.builder.invalidateResource();
1651
+ }
1652
+ async stats() {
1653
+ let e = await this.queueDepth(), t = this.sender?.stats() ?? {
1654
+ pending: 0,
1655
+ inFlight: 0,
1656
+ lastSendAt: null
1657
+ }, n = this.bootBuffer.length + this.pendingRecords.length + this.forwardBuffer.length;
1658
+ return {
1659
+ ...t,
1660
+ pending: t.pending + n,
1661
+ stored: e
1662
+ };
1381
1663
  }
1382
1664
  async queueDepth() {
1383
1665
  return await this.senderLoad, await this.sender?.queueDepth() ?? 0;
@@ -1388,7 +1670,7 @@ var Z = class e {
1388
1670
  };
1389
1671
  //#endregion
1390
1672
  //#region src/transport/memory-transport.ts
1391
- function Mn() {
1673
+ function tr() {
1392
1674
  let e = [], t = [], n = { status: 200 };
1393
1675
  return {
1394
1676
  transport: (r) => (e.push(r), n.status >= 200 && n.status < 300 && t.push(r), Promise.resolve({ ...n })),
@@ -1407,122 +1689,119 @@ function Mn() {
1407
1689
  }
1408
1690
  //#endregion
1409
1691
  //#region src/index.ts
1410
- var Nn = /* @__PURE__ */ new Map();
1692
+ var nr = /* @__PURE__ */ new Map();
1411
1693
  function Q() {
1412
1694
  return (Z.current() ?? Z.stopped()) || Z.configure({}, !0);
1413
1695
  }
1414
- function Pn(e) {
1696
+ function rr(e) {
1415
1697
  Z.configure(e);
1416
1698
  }
1417
- function Fn(e, t) {
1418
- if (t) return new I(Q, e, t);
1419
- let n = Nn.get(e);
1420
- return n || (n = new I(Q, e), Nn.set(e, n)), n;
1699
+ function ir(e, t) {
1700
+ if (t) return new L(Q, e, t);
1701
+ let n = nr.get(e);
1702
+ return n || (n = new L(Q, e), nr.set(e, n)), n;
1421
1703
  }
1422
1704
  function $() {
1423
- return Fn("app");
1705
+ return ir("app");
1424
1706
  }
1425
- function In(e, t) {
1707
+ function ar(e, t) {
1426
1708
  $().trace(e, t);
1427
1709
  }
1428
- function Ln(e, t) {
1710
+ function or(e, t) {
1429
1711
  $().debug(e, t);
1430
1712
  }
1431
- function Rn(e, t) {
1713
+ function sr(e, t) {
1432
1714
  $().info(e, t);
1433
1715
  }
1434
- function zn(e, t) {
1716
+ function cr(e, t) {
1435
1717
  $().warn(e, t);
1436
1718
  }
1437
- function Bn(e, t, n) {
1719
+ function lr(e, t, n) {
1438
1720
  $().error(e, t, n);
1439
1721
  }
1440
- function Vn(e, t, n) {
1722
+ function ur(e, t, n) {
1441
1723
  $().fatal(e, t, n);
1442
1724
  }
1443
- function Hn(e, t) {
1725
+ function dr(e, t) {
1444
1726
  $().logAction(e, t);
1445
1727
  }
1446
- function Un(e, t) {
1728
+ function fr(e, t) {
1447
1729
  $().logEvent(e, t);
1448
1730
  }
1449
- function Wn(e, t, n, r, i) {
1731
+ function pr(e, t, n, r, i) {
1450
1732
  $().logMetric(e, t, n, r, i);
1451
1733
  }
1452
- function Gn(e, t = {}) {
1453
- let n = {
1454
- name: e,
1455
- kind: "counter",
1456
- unit: t.unit ?? "count",
1457
- boundaries: []
1458
- };
1459
- return { add: (e, t) => {
1460
- Q().recordMetric(n, e, t);
1461
- } };
1734
+ function mr(e, t = {}) {
1735
+ return gt(e, t, (e, t, n) => {
1736
+ Q().recordMetric(e, t, n);
1737
+ });
1462
1738
  }
1463
- function Kn(e, t = {}) {
1464
- let n = {
1465
- name: e,
1466
- kind: "histogram",
1467
- unit: t.unit ?? "count",
1468
- boundaries: t.boundaries ?? ae
1469
- };
1470
- return { record: (e, t) => {
1471
- Q().recordMetric(n, e, t);
1472
- } };
1739
+ function hr(e, t = {}) {
1740
+ return _t(e, t, (e, t, n) => {
1741
+ Q().recordMetric(e, t, n);
1742
+ });
1473
1743
  }
1474
- function qn(e, t, n) {
1744
+ function gr(e, t, n) {
1475
1745
  return $().timeSync(e, t, n);
1476
1746
  }
1477
- function Jn(e, t, n) {
1747
+ function _r(e, t, n) {
1478
1748
  return $().timeAsync(e, t, n);
1479
1749
  }
1480
- function Yn(e, t) {
1750
+ function vr(e, t) {
1751
+ Q().addBreadcrumb(e, t);
1752
+ }
1753
+ function yr(e, t) {
1481
1754
  Q().context.set(e, t);
1482
1755
  }
1483
- function Xn(e) {
1756
+ function br(e) {
1484
1757
  Q().context.setMany(e);
1485
1758
  }
1486
- function Zn(e) {
1759
+ function xr(e) {
1487
1760
  Q().context.remove(e);
1488
1761
  }
1489
- function Qn(e, t) {
1762
+ function Sr(e, t) {
1490
1763
  return Q().journey.start(e, t);
1491
1764
  }
1492
- function $n() {
1765
+ function Cr() {
1493
1766
  Q().journey.end();
1494
1767
  }
1495
- function er() {
1768
+ function wr() {
1496
1769
  return Q().journey.current();
1497
1770
  }
1498
- function tr() {
1771
+ function Tr() {
1499
1772
  return Q().journey.getToken();
1500
1773
  }
1501
- function nr(e) {
1774
+ function Er(e) {
1502
1775
  return Q().journey.adopt(e, "manual", !0);
1503
1776
  }
1504
- function rr(e) {
1777
+ function Dr(e) {
1505
1778
  Q().registerWorker(e);
1506
1779
  }
1507
- function ir() {
1780
+ function Or() {
1508
1781
  Q().tracing.rotate("explicit");
1509
1782
  }
1510
- function ar() {
1783
+ function kr() {
1511
1784
  return Q().tracing.headers();
1512
1785
  }
1513
- function or() {
1786
+ function Ar() {
1514
1787
  return Q().flush();
1515
1788
  }
1516
- function sr() {
1789
+ function jr() {
1517
1790
  return Q().queueDepth();
1518
1791
  }
1519
- function cr() {
1792
+ function Mr() {
1793
+ return Q().stats();
1794
+ }
1795
+ function Nr() {
1796
+ Q().newSession();
1797
+ }
1798
+ function Pr() {
1520
1799
  return Q().diagnostics.snapshot();
1521
1800
  }
1522
- async function lr() {
1801
+ async function Fr() {
1523
1802
  await Z.current()?.destroy();
1524
1803
  }
1525
1804
  //#endregion
1526
- export { I as OneLogger, nr as adoptJourney, Pn as configure, Gn as counter, Mn as createMemoryTransport, er as currentJourney, Ln as debug, $n as endJourney, Bn as error, Vn as fatal, or as flush, cr as getDiagnosticCounters, tr as getJourneyToken, Fn as getLogger, sr as getQueueDepth, ar as getTraceHeaders, Kn as histogram, Rn as info, Hn as logAction, Un as logEvent, Wn as logMetric, rr as registerWorker, Zn as removeContext, Yn as setContext, Xn as setContextMap, lr as shutdown, Qn as startJourney, ir as startTrace, Jn as timeAsync, qn as timeSync, In as trace, zn as warn };
1805
+ export { L as OneLogger, vr as addBreadcrumb, Er as adoptJourney, rr as configure, mr as counter, tr as createMemoryTransport, wr as currentJourney, or as debug, Cr as endJourney, lr as error, ur as fatal, Ar as flush, Pr as getDiagnosticCounters, Tr as getJourneyToken, ir as getLogger, jr as getQueueDepth, Mr as getStats, kr as getTraceHeaders, hr as histogram, sr as info, dr as logAction, fr as logEvent, pr as logMetric, Nr as newSession, Dr as registerWorker, xr as removeContext, yr as setContext, br as setContextMap, Fr as shutdown, Sr as startJourney, Or as startTrace, _r as timeAsync, gr as timeSync, ar as trace, cr as warn };
1527
1806
 
1528
1807
  //# sourceMappingURL=index.js.map