@utk09/ui-observability 0.9.2 → 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 (191) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +108 -33
  3. package/dist/batch-C4oF6XZT.cjs +2 -0
  4. package/dist/batch-C4oF6XZT.cjs.map +1 -0
  5. package/dist/{batch-4xKzzSCj.js → batch-D-4xl7op.js} +8 -5
  6. package/dist/batch-D-4xl7op.js.map +1 -0
  7. package/dist/bus/bus.d.ts +0 -4
  8. package/dist/{bus-DrixwdiX.js → bus-Cyvq-Ngx.js} +59 -62
  9. package/dist/bus-Cyvq-Ngx.js.map +1 -0
  10. package/dist/bus-rOhVuRee.cjs +2 -0
  11. package/dist/bus-rOhVuRee.cjs.map +1 -0
  12. package/dist/capture/network.d.ts +1 -0
  13. package/dist/capture/storm.d.ts +2 -7
  14. package/dist/capture/types.d.ts +3 -0
  15. package/dist/capture/web-socket.d.ts +40 -0
  16. package/dist/{console-B3vGRW5p.js → console-BT7mcgU6.js} +3 -3
  17. package/dist/{console-B3vGRW5p.js.map → console-BT7mcgU6.js.map} +1 -1
  18. package/dist/{console-ChfuJlf9.cjs → console-Boqa7new.cjs} +2 -2
  19. package/dist/{console-ChfuJlf9.cjs.map → console-Boqa7new.cjs.map} +1 -1
  20. package/dist/constants-BgRS6MB0.cjs +2 -0
  21. package/dist/constants-BgRS6MB0.cjs.map +1 -0
  22. package/dist/constants-L_d5YvvQ.js +160 -0
  23. package/dist/constants-L_d5YvvQ.js.map +1 -0
  24. package/dist/constants.d.ts +36 -5
  25. package/dist/core/breadcrumbs.d.ts +4 -4
  26. package/dist/core/context.d.ts +0 -8
  27. package/dist/core/diagnostics.d.ts +1 -3
  28. package/dist/core/journey.d.ts +7 -0
  29. package/dist/core/meter.d.ts +19 -1
  30. package/dist/core/pipeline.d.ts +12 -4
  31. package/dist/core/record.d.ts +40 -8
  32. package/dist/core/remote-sampling.d.ts +7 -3
  33. package/dist/core/runtime.d.ts +62 -3
  34. package/dist/core/sampling.d.ts +33 -4
  35. package/dist/core/sender.d.ts +8 -0
  36. package/dist/core/spans.d.ts +34 -0
  37. package/dist/{errors-BGs5NOrw.js → errors-BDI96zKc.js} +6 -6
  38. package/dist/errors-BDI96zKc.js.map +1 -0
  39. package/dist/errors-_xEsCVXn.cjs +3 -0
  40. package/dist/errors-_xEsCVXn.cjs.map +1 -0
  41. package/dist/fixed-window-BR0bu32Y.cjs +2 -0
  42. package/dist/fixed-window-BR0bu32Y.cjs.map +1 -0
  43. package/dist/fixed-window-Re7jIRJH.js +9 -0
  44. package/dist/fixed-window-Re7jIRJH.js.map +1 -0
  45. package/dist/identity-Bwku7zzN.cjs +2 -0
  46. package/dist/identity-Bwku7zzN.cjs.map +1 -0
  47. package/dist/{identity-rpEyjvVg.js → identity-Dtv917nz.js} +33 -23
  48. package/dist/identity-Dtv917nz.js.map +1 -0
  49. package/dist/index.cjs +1 -1
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.ts +23 -1
  52. package/dist/index.js +804 -537
  53. package/dist/index.js.map +1 -1
  54. package/dist/indexeddb-storage-Cvavrf-y.cjs +2 -0
  55. package/dist/indexeddb-storage-Cvavrf-y.cjs.map +1 -0
  56. package/dist/{indexeddb-storage-Q9fDYlyn.js → indexeddb-storage-HgkQUTyS.js} +57 -68
  57. package/dist/indexeddb-storage-HgkQUTyS.js.map +1 -0
  58. package/dist/{interactions-BAGRmtrv.cjs → interactions-Bhe1ft8P.cjs} +2 -2
  59. package/dist/interactions-Bhe1ft8P.cjs.map +1 -0
  60. package/dist/{interactions-B8zjCjga.js → interactions-Ck01cEij.js} +3 -3
  61. package/dist/interactions-Ck01cEij.js.map +1 -0
  62. package/dist/journey-Co9OlzrW.cjs +2 -0
  63. package/dist/journey-Co9OlzrW.cjs.map +1 -0
  64. package/dist/{journey-_dQQ1eMP.js → journey-DRK0A8u_.js} +37 -33
  65. package/dist/journey-DRK0A8u_.js.map +1 -0
  66. package/dist/{library-request-DX6ev9oG.js → library-request-ChCar5F8.js} +3 -3
  67. package/dist/{library-request-DX6ev9oG.js.map → library-request-ChCar5F8.js.map} +1 -1
  68. package/dist/{library-request-BIG3Xpx3.cjs → library-request-gMFOCNcn.cjs} +2 -2
  69. package/dist/{library-request-BIG3Xpx3.cjs.map → library-request-gMFOCNcn.cjs.map} +1 -1
  70. package/dist/log-record-cwFiLyPY.js +17 -0
  71. package/dist/log-record-cwFiLyPY.js.map +1 -0
  72. package/dist/log-record-jX9eWUP8.cjs +2 -0
  73. package/dist/log-record-jX9eWUP8.cjs.map +1 -0
  74. package/dist/{long-frames-Cq2LgNnp.cjs → long-frames-Bky6nZDF.cjs} +2 -2
  75. package/dist/long-frames-Bky6nZDF.cjs.map +1 -0
  76. package/dist/{long-frames-B0tKuChx.js → long-frames-DDumopji.js} +4 -4
  77. package/dist/long-frames-DDumopji.js.map +1 -0
  78. package/dist/models/batch.d.ts +6 -0
  79. package/dist/models/config.d.ts +56 -5
  80. package/dist/models/log-record.d.ts +1 -1
  81. package/dist/models/plugin.d.ts +47 -0
  82. package/dist/models/stats.d.ts +11 -0
  83. package/dist/{network-CMnEvGJB.js → network-BsBZ6_-Q.js} +43 -29
  84. package/dist/network-BsBZ6_-Q.js.map +1 -0
  85. package/dist/network-_4csBGBM.cjs +2 -0
  86. package/dist/network-_4csBGBM.cjs.map +1 -0
  87. package/dist/openfin-BwEN0uj4.js +8 -0
  88. package/dist/openfin-BwEN0uj4.js.map +1 -0
  89. package/dist/openfin-DtH2f7zX.cjs +2 -0
  90. package/dist/openfin-DtH2f7zX.cjs.map +1 -0
  91. package/dist/platform-4yYjMD-B.js +57 -0
  92. package/dist/platform-4yYjMD-B.js.map +1 -0
  93. package/dist/platform-o7r1ocOu.cjs +2 -0
  94. package/dist/platform-o7r1ocOu.cjs.map +1 -0
  95. package/dist/remote-rules-1KqfVBIu.js +91 -0
  96. package/dist/remote-rules-1KqfVBIu.js.map +1 -0
  97. package/dist/remote-rules-BHgEGlYi.cjs +2 -0
  98. package/dist/remote-rules-BHgEGlYi.cjs.map +1 -0
  99. package/dist/sampling-C4my-ma0.cjs +2 -0
  100. package/dist/sampling-C4my-ma0.cjs.map +1 -0
  101. package/dist/sampling-nYIWP_vP.js +86 -0
  102. package/dist/sampling-nYIWP_vP.js.map +1 -0
  103. package/dist/{sanitize-BNwgPj_B.js → sanitize-BiUKCUG6.js} +2 -2
  104. package/dist/{sanitize-BNwgPj_B.js.map → sanitize-BiUKCUG6.js.map} +1 -1
  105. package/dist/{sanitize-BqzPc4Jg.cjs → sanitize-BxuPSXOk.cjs} +2 -2
  106. package/dist/{sanitize-BqzPc4Jg.cjs.map → sanitize-BxuPSXOk.cjs.map} +1 -1
  107. package/dist/sender-6vrT9fFL.cjs +3 -0
  108. package/dist/sender-6vrT9fFL.cjs.map +1 -0
  109. package/dist/{sender--0_VzPbN.js → sender-DFQMF39P.js} +380 -278
  110. package/dist/sender-DFQMF39P.js.map +1 -0
  111. package/dist/storage/gap.d.ts +20 -0
  112. package/dist/storage/indexeddb-storage.d.ts +1 -7
  113. package/dist/storage/keys.d.ts +9 -0
  114. package/dist/storage/local-storage.d.ts +0 -6
  115. package/dist/storage/memory-storage.d.ts +1 -1
  116. package/dist/storm-6YYbXzT_.cjs +2 -0
  117. package/dist/storm-6YYbXzT_.cjs.map +1 -0
  118. package/dist/storm-CfO0Sam2.js +10 -0
  119. package/dist/storm-CfO0Sam2.js.map +1 -0
  120. package/dist/transport/exit-flush.d.ts +6 -0
  121. package/dist/transport/http-transport.d.ts +2 -1
  122. package/dist/transport/serializers/otlp-traces.d.ts +3 -0
  123. package/dist/transport/serializers/select.d.ts +8 -5
  124. package/dist/transport/status-transport.d.ts +7 -0
  125. package/dist/types-BR9t_w28.js +8 -0
  126. package/dist/types-BR9t_w28.js.map +1 -0
  127. package/dist/types-C7WNpnG1.cjs +2 -0
  128. package/dist/types-C7WNpnG1.cjs.map +1 -0
  129. package/dist/utils/fixed-window.d.ts +15 -0
  130. package/dist/utils/guards.d.ts +6 -0
  131. package/dist/utils/identity.d.ts +11 -0
  132. package/dist/utils/openfin.d.ts +48 -0
  133. package/dist/utils/platform.d.ts +13 -0
  134. package/dist/utils/tracing.d.ts +82 -4
  135. package/dist/web-socket-Ar4cZxmd.js +102 -0
  136. package/dist/web-socket-Ar4cZxmd.js.map +1 -0
  137. package/dist/web-socket-BwJdwSHl.cjs +2 -0
  138. package/dist/web-socket-BwJdwSHl.cjs.map +1 -0
  139. package/package.json +2 -3
  140. package/dist/batch-4xKzzSCj.js.map +0 -1
  141. package/dist/batch-cys7e53Q.cjs +0 -2
  142. package/dist/batch-cys7e53Q.cjs.map +0 -1
  143. package/dist/bus-B6vzPmQM.cjs +0 -2
  144. package/dist/bus-B6vzPmQM.cjs.map +0 -1
  145. package/dist/bus-DrixwdiX.js.map +0 -1
  146. package/dist/constants-Be83LICb.cjs +0 -2
  147. package/dist/constants-Be83LICb.cjs.map +0 -1
  148. package/dist/constants-CQ_D7jIW.js +0 -144
  149. package/dist/constants-CQ_D7jIW.js.map +0 -1
  150. package/dist/deadline-5_PecIl5.js +0 -26
  151. package/dist/deadline-5_PecIl5.js.map +0 -1
  152. package/dist/deadline-XSnm95pg.cjs +0 -2
  153. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  154. package/dist/errors-BGs5NOrw.js.map +0 -1
  155. package/dist/errors-BMJm7KZZ.cjs +0 -3
  156. package/dist/errors-BMJm7KZZ.cjs.map +0 -1
  157. package/dist/identity-DXyV86o-.cjs +0 -2
  158. package/dist/identity-DXyV86o-.cjs.map +0 -1
  159. package/dist/identity-rpEyjvVg.js.map +0 -1
  160. package/dist/indexeddb-storage-BXaPVPyG.cjs +0 -2
  161. package/dist/indexeddb-storage-BXaPVPyG.cjs.map +0 -1
  162. package/dist/indexeddb-storage-Q9fDYlyn.js.map +0 -1
  163. package/dist/interactions-B8zjCjga.js.map +0 -1
  164. package/dist/interactions-BAGRmtrv.cjs.map +0 -1
  165. package/dist/journey-BGSyy8Es.cjs +0 -2
  166. package/dist/journey-BGSyy8Es.cjs.map +0 -1
  167. package/dist/journey-_dQQ1eMP.js.map +0 -1
  168. package/dist/long-frames-B0tKuChx.js.map +0 -1
  169. package/dist/long-frames-Cq2LgNnp.cjs.map +0 -1
  170. package/dist/network-C6kJbW6K.cjs +0 -2
  171. package/dist/network-C6kJbW6K.cjs.map +0 -1
  172. package/dist/network-CMnEvGJB.js.map +0 -1
  173. package/dist/platform-DNOJjpOm.cjs +0 -2
  174. package/dist/platform-DNOJjpOm.cjs.map +0 -1
  175. package/dist/platform-j0uMPwHi.js +0 -48
  176. package/dist/platform-j0uMPwHi.js.map +0 -1
  177. package/dist/remote-rules-DgoBJxZL.cjs +0 -2
  178. package/dist/remote-rules-DgoBJxZL.cjs.map +0 -1
  179. package/dist/remote-rules-UggoZqfP.js +0 -86
  180. package/dist/remote-rules-UggoZqfP.js.map +0 -1
  181. package/dist/sampling-BLMD8EGM.js +0 -64
  182. package/dist/sampling-BLMD8EGM.js.map +0 -1
  183. package/dist/sampling-MthcVXXU.cjs +0 -2
  184. package/dist/sampling-MthcVXXU.cjs.map +0 -1
  185. package/dist/sender--0_VzPbN.js.map +0 -1
  186. package/dist/sender-SPGMqZjD.cjs +0 -3
  187. package/dist/sender-SPGMqZjD.cjs.map +0 -1
  188. package/dist/storm-CTy1dfvs.cjs +0 -2
  189. package/dist/storm-CTy1dfvs.cjs.map +0 -1
  190. package/dist/storm-knaj4GUH.js +0 -10
  191. package/dist/storm-knaj4GUH.js.map +0 -1
@@ -1,13 +1,15 @@
1
- import { $ as e, B as t, Ct as n, Dt as r, Ft as i, H as a, Ht as o, Jt as s, Lt as c, M as l, N as u, Ot as d, P as f, Pt as p, Q as m, St as ee, U as h, Vt as te, X as g, Xt as _, Y as ne, Yt as v, Z as re, an as ie, bt as ae, d as oe, dn as se, en as y, et as ce, fn as b, gn as x, hn as S, ht as le, ln as ue, on as C, un as de, vt as w, x as T } from "./constants-CQ_D7jIW.js";
2
- import { o as fe, t as pe } from "./sampling-BLMD8EGM.js";
3
- import { o as me, t as E } from "./sanitize-BNwgPj_B.js";
4
- import { i as he } from "./identity-rpEyjvVg.js";
5
- import { i as ge, n as _e, r as D, t as ve } from "./batch-4xKzzSCj.js";
6
- import { i as ye, r as O } from "./library-request-DX6ev9oG.js";
7
- import { n as k, r as A, t as be } from "./deadline-5_PecIl5.js";
8
- import { n as xe, t as Se } from "./remote-rules-UggoZqfP.js";
1
+ import { $ as e, $t as t, B as n, Dt as r, Et as i, Gt as a, Kt as o, M as s, Mt as c, N as l, P as u, Q as d, Qt as f, Rt as p, St as m, U as h, V as ee, Vt as te, W as g, X as ne, Z as re, _n as _, bn as v, d as ie, dn as y, en as b, et as ae, gn as oe, hn as se, in as x, jt as ce, ln as S, mn as le, n as C, tt as ue, un as de, wt as fe, x as w, xn as T, zt as pe } from "./constants-L_d5YvvQ.js";
2
+ import { c as E, l as D, s as me, t as he } from "./sampling-nYIWP_vP.js";
3
+ import { r as ge } from "./log-record-cwFiLyPY.js";
4
+ import { o as _e, t as O } from "./sanitize-BiUKCUG6.js";
5
+ import { i as ve } from "./identity-Dtv917nz.js";
6
+ import { i as ye, r as k } from "./library-request-ChCar5F8.js";
7
+ import { t as A } from "./openfin-BwEN0uj4.js";
8
+ import { r as j } from "./platform-4yYjMD-B.js";
9
+ import { a as be, i as M, n as xe, r as Se, t as Ce } from "./batch-D-4xl7op.js";
10
+ import { n as we, t as Te } from "./remote-rules-1KqfVBIu.js";
9
11
  //#region src/models/storage.ts
10
- function j(e) {
12
+ function Ee(e) {
11
13
  let { maxBatches: t } = e;
12
14
  return e.mode === "until-delivered" ? {
13
15
  maxBatches: t,
@@ -21,12 +23,15 @@ function j(e) {
21
23
  }
22
24
  //#endregion
23
25
  //#region src/utils/lock.ts
24
- function M(e, t, n, { skipIfBusy: r = !0 } = {}) {
26
+ function De(e, t, n, { skipIfBusy: r = !0 } = {}) {
25
27
  let i = globalThis.navigator?.locks;
26
28
  return i?.request ? t.guardAsync("storage.degraded", `The library could not get the lock ${e}.`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
27
29
  }
28
30
  //#endregion
29
31
  //#region src/storage/keys.ts
32
+ function Oe(e, t) {
33
+ return `${e}${String(t.createdAt).padStart(14, "0")}.${t.id}`;
34
+ }
30
35
  function N(e, t) {
31
36
  let n = [];
32
37
  return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
@@ -38,57 +43,53 @@ function N(e, t) {
38
43
  }
39
44
  //#endregion
40
45
  //#region src/storage/emergency-queue.ts
41
- function Ce(e) {
42
- let t = String(e.createdAt).padStart(14, "0");
43
- return `${a}${t}.${e.id}`;
44
- }
45
- function P(e, t) {
46
+ function ke(e, t) {
46
47
  let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
47
- return n === void 0 ? null : D(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
48
+ return n === void 0 ? null : M(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
48
49
  }
49
- async function we(e, t) {
50
+ async function Ae(e, t) {
50
51
  let n = 0;
51
- for (let r of N(a, t)) {
52
+ for (let r of N(h, t)) {
52
53
  let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
53
54
  let e = localStorage.getItem(r);
54
55
  return localStorage.removeItem(r), e;
55
56
  });
56
57
  if (!i) continue;
57
- let a = P(i, t);
58
+ let a = ke(i, t);
58
59
  if (a !== null) try {
59
- await k(e.save(a), C), n++;
60
+ await E(e.save(a), y), n++;
60
61
  } catch (e) {
61
62
  t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
62
63
  }
63
64
  }
64
65
  return n;
65
66
  }
66
- function F(e, t, n) {
67
- let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], o = t.guard("storage.quota_exceeded", r, () => {
68
- let n = N(a, t);
67
+ function je(e, t, n) {
68
+ let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], a = t.guard("storage.quota_exceeded", r, () => {
69
+ let n = N(h, t);
69
70
  for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
70
- let n = P(String(localStorage.getItem(e)), t);
71
+ let n = ke(String(localStorage.getItem(e)), t);
71
72
  n !== null && i.push(n), localStorage.removeItem(e);
72
73
  }
73
- return localStorage.setItem(Ce(e), JSON.stringify(e)), !0;
74
+ return localStorage.setItem(Oe(h, e), JSON.stringify(e)), !0;
74
75
  });
75
76
  t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
76
77
  if (i.length > 0) {
77
78
  let e = i.flatMap((e) => e.records);
78
79
  n?.("exit_queue_full", e, i.map((e) => e.id));
79
80
  }
80
- o !== !0 && n?.("quota", e.records, [e.id]);
81
+ a !== !0 && n?.("quota", e.records, [e.id]);
81
82
  });
82
83
  }
83
- async function Te(e, t) {
84
- return await M("ui-observability.emergency", t, () => we(e, t), { skipIfBusy: !1 }) ?? 0;
84
+ async function Me(e, t) {
85
+ return await De("ui-observability.emergency", t, () => Ae(e, t), { skipIfBusy: !1 }) ?? 0;
85
86
  }
86
87
  //#endregion
87
88
  //#region src/storage/eviction.ts
88
- function I(e) {
89
- return Array.isArray(e.records) && e.records.some(_e);
89
+ function P(e) {
90
+ return Array.isArray(e.records) && e.records.some(Se);
90
91
  }
91
- var L = class {
92
+ var Ne = class {
92
93
  howMany;
93
94
  isAudit;
94
95
  plain = [];
@@ -103,35 +104,47 @@ var L = class {
103
104
  return [...this.plain, ...this.audit].slice(0, this.howMany);
104
105
  }
105
106
  };
106
- function R(e, t, n) {
107
- let r = new L(t, n);
107
+ function F(e, t, n) {
108
+ let r = new Ne(t, n);
108
109
  for (let t of e) if (!r.add(t)) break;
109
110
  return r.picked();
110
111
  }
111
112
  //#endregion
112
- //#region src/storage/local-storage.ts
113
- function Ee(e) {
114
- let t = String(e.createdAt).padStart(14, "0");
115
- return `${T}${t}.${e.id}`;
113
+ //#region src/storage/gap.ts
114
+ function I(e, t, n, r) {
115
+ return e.batches += n, e.records += r, e.reason = t, {
116
+ batches: n,
117
+ records: r,
118
+ reason: t
119
+ };
116
120
  }
117
- function De(e) {
118
- let t = T.length, n = Number(e.slice(t, t + 14));
121
+ function L(e, t, n, r) {
122
+ n.batches !== 0 && (e.report("storage.evicted", `The library dropped ${String(n.batches)} stored batches (${String(n.records)} records).`, { ...n }), t?.(n, r));
123
+ }
124
+ //#endregion
125
+ //#region src/storage/local-storage.ts
126
+ function Pe(e) {
127
+ let t = w.length, n = Number(e.slice(t, t + 14));
119
128
  return Number.isFinite(n) ? n : null;
120
129
  }
121
- var Oe = class {
130
+ var Fe = class {
122
131
  limits;
123
132
  diagnostics;
124
133
  onGap;
125
- name = ue;
134
+ name = le;
126
135
  constructor(e, t, n) {
127
136
  this.limits = e, this.diagnostics = t, this.onGap = n;
128
137
  }
129
138
  async save(e) {
130
- this.write(e, "localStorage refused a batch, evicting the oldest") ? await this.prune() : (this.evictForQuota(), this.write(e, "localStorage refused a batch even after evicting") || this.reportGap({
131
- batches: 1,
132
- records: e.records.length,
133
- reason: "quota"
134
- }, [e]));
139
+ if (this.write(e, "localStorage refused a batch, evicting the oldest")) await this.prune();
140
+ else if (this.evictForQuota(), !this.write(e, "localStorage refused a batch even after evicting")) {
141
+ let t = {
142
+ batches: 1,
143
+ records: e.records.length,
144
+ reason: "quota"
145
+ };
146
+ L(this.diagnostics, this.onGap, t, [e]);
147
+ }
135
148
  }
136
149
  take(e) {
137
150
  let t = [];
@@ -160,7 +173,7 @@ var Oe = class {
160
173
  reason: "expired"
161
174
  }, n = [], r = [];
162
175
  for (let t of this.keys()) {
163
- let i = De(t);
176
+ let i = Pe(t);
164
177
  i === null || i < e ? n.push(t) : r.push(t);
165
178
  }
166
179
  this.drop(t, "expired", [...this.entries(n)]);
@@ -177,7 +190,7 @@ var Oe = class {
177
190
  return Promise.resolve();
178
191
  }
179
192
  write(e, t) {
180
- return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(Ee(e), JSON.stringify(e)), !0)) === !0;
193
+ return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(Oe(w, e), JSON.stringify(e)), !0)) === !0;
181
194
  }
182
195
  evictForQuota() {
183
196
  let e = this.keys(), t = {
@@ -188,7 +201,7 @@ var Oe = class {
188
201
  this.drop(t, "quota", this.evictable(e, n));
189
202
  }
190
203
  evictable(e, t) {
191
- return R(this.entries(e), t, (e) => e.batch !== null && I(e.batch));
204
+ return F(this.entries(e), t, (e) => e.batch !== null && P(e.batch));
192
205
  }
193
206
  *entries(e) {
194
207
  for (let t of e) yield {
@@ -198,22 +211,16 @@ var Oe = class {
198
211
  }
199
212
  drop(e, t, n) {
200
213
  if (n.length === 0) return;
201
- let r = [], i = 0;
202
- for (let { key: e, batch: t } of n) this.removeKey(e), i += t?.records.length ?? 0, t && r.push(t);
203
- e.batches += n.length, e.records += i, e.reason = t, this.reportGap({
204
- batches: n.length,
205
- records: i,
206
- reason: t
207
- }, r);
208
- }
209
- reportGap(e, t) {
210
- this.diagnostics.report("storage.evicted", `The library dropped ${String(e.batches)} stored batches (${String(e.records)} records).`, { ...e }), this.onGap?.(e, t);
214
+ let r = [];
215
+ for (let { key: e, batch: t } of n) this.removeKey(e), t && r.push(t);
216
+ let i = I(e, t, n.length, xe(r));
217
+ L(this.diagnostics, this.onGap, i, r);
211
218
  }
212
219
  read(e) {
213
220
  let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
214
221
  if (!t) return null;
215
222
  let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
216
- return n === void 0 ? null : D(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
223
+ return n === void 0 ? null : M(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
217
224
  }
218
225
  keyOf(e) {
219
226
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -227,18 +234,12 @@ var Oe = class {
227
234
  });
228
235
  }
229
236
  keys() {
230
- return N(T, this.diagnostics);
237
+ return N(w, this.diagnostics);
231
238
  }
232
- };
233
- //#endregion
234
- //#region src/storage/memory-storage.ts
235
- function ke(e) {
236
- return e.reduce((e, t) => e + t.records.length, 0);
237
- }
238
- var z = class {
239
+ }, R = class {
239
240
  limits;
240
241
  onGap;
241
- name = de;
242
+ name = se;
242
243
  batches = [];
243
244
  constructor(e, t) {
244
245
  this.limits = e, this.onGap = t;
@@ -265,19 +266,15 @@ var z = class {
265
266
  this.batches = this.batches.filter((t) => t.createdAt >= e), this.report(t, "expired", n);
266
267
  let r = this.batches.length - this.limits.maxBatches;
267
268
  if (r > 0) {
268
- let e = R(this.batches, r, I);
269
+ let e = F(this.batches, r, P);
269
270
  this.batches = this.batches.filter((t) => !e.includes(t)), this.report(t, "over_capacity", e);
270
271
  }
271
272
  return Promise.resolve(t);
272
273
  }
273
274
  report(e, t, n) {
274
275
  if (n.length === 0) return;
275
- let r = ke(n);
276
- e.batches += n.length, e.records += r, e.reason = t, this.onGap?.({
277
- batches: n.length,
278
- records: r,
279
- reason: t
280
- }, n);
276
+ let r = I(e, t, n.length, xe(n));
277
+ this.onGap?.(r, n);
281
278
  }
282
279
  count() {
283
280
  return Promise.resolve(this.batches.length);
@@ -288,8 +285,8 @@ var z = class {
288
285
  close() {
289
286
  return this.batches = [], Promise.resolve();
290
287
  }
291
- }, Ae = (e) => ({
292
- name: se,
288
+ }, Ie = (e) => ({
289
+ name: oe,
293
290
  save: (t) => (e?.({
294
291
  batches: 1,
295
292
  records: t.records.length,
@@ -307,30 +304,30 @@ var z = class {
307
304
  clear: () => Promise.resolve(),
308
305
  close: () => Promise.resolve()
309
306
  });
310
- function je(e) {
307
+ function Le(e) {
311
308
  return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
312
309
  }
313
- function Me(e) {
314
- return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(b, "1"), localStorage.removeItem(b), !0)) === !0;
310
+ function Re(e) {
311
+ return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(_, "1"), localStorage.removeItem(_), !0)) === !0;
315
312
  }
316
- async function Ne(e, t, n, r, i) {
317
- if (e === "none") return Ae(i);
318
- if (e === "memory") return new z(n, i);
313
+ async function ze(e, t, n, r, i) {
314
+ if (e === "none") return Ie(i);
315
+ if (e === "memory") return new R(n, i);
319
316
  if (e === "indexeddb" || e === "auto") {
320
- if (je(r)) {
317
+ if (Le(r)) {
321
318
  let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
322
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-Q9fDYlyn.js"), a = new e(t, n, r, i);
319
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-HgkQUTyS.js"), a = new e(t, n, r, i);
323
320
  return await a.open(), a;
324
321
  });
325
322
  if (e) return e;
326
323
  }
327
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new z(n, i);
324
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new R(n, i);
328
325
  }
329
- return Me(r) ? new Oe(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new z(n, i));
326
+ return Re(r) ? new Fe(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new R(n, i));
330
327
  }
331
328
  //#endregion
332
329
  //#region src/transport/errors.ts
333
- var B = class extends Error {
330
+ var z = class extends Error {
334
331
  kind;
335
332
  status;
336
333
  retryAfterMs;
@@ -339,28 +336,33 @@ var B = class extends Error {
339
336
  super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
340
337
  }
341
338
  };
342
- function Pe(e) {
339
+ function Be(e) {
343
340
  if (!e) return;
344
341
  let t = Number(e);
345
- if (Number.isFinite(t)) return Math.max(0, t * ae);
342
+ if (Number.isFinite(t)) return Math.max(0, t * fe);
346
343
  let n = Date.parse(e);
347
344
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
348
345
  }
349
346
  //#endregion
350
347
  //#region src/transport/serializers/ecs.ts
351
- function Fe(e) {
352
- return ee.test(e) ? Number(BigInt(e) / n) : Date.now();
348
+ var B = {
349
+ "error.type": "type",
350
+ "error.message": "message",
351
+ "error.stack_trace": "stack_trace"
352
+ }, Ve = /* @__PURE__ */ new Set([C, ...Object.keys(B)]);
353
+ function He(e) {
354
+ return i.test(e) ? Number(BigInt(e) / r) : Date.now();
353
355
  }
354
- function Ie(e) {
356
+ function Ue(e) {
355
357
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
356
358
  }
357
- function Le(e, t, n) {
359
+ function We(e, t, n) {
358
360
  let r = e[t];
359
361
  r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
360
362
  }
361
363
  function V(e, t, n, r) {
362
- let i = Ie(n);
363
- if (i !== null) Le(e, t, i);
364
+ let i = Ue(n);
365
+ if (i !== null) We(e, t, i);
364
366
  else if (typeof n == "object" && n && !r.has(n)) {
365
367
  if (r.add(n), Array.isArray(n)) for (let i of n) V(e, t, i, r);
366
368
  else for (let [i, a] of Object.entries(n)) V(e, `${t}.${i}`, a, r);
@@ -372,32 +374,49 @@ function H(e) {
372
374
  for (let [r, i] of Object.entries(e)) V(t, r, i, n);
373
375
  return t;
374
376
  }
375
- var Re = {
377
+ function Ge(e) {
378
+ let t = [];
379
+ for (let [n, r] of Object.entries(B)) {
380
+ let i = e[n];
381
+ typeof i == "string" && t.push([r, i]);
382
+ }
383
+ return t.length > 0 ? Object.fromEntries(t) : void 0;
384
+ }
385
+ function Ke(e) {
386
+ return Object.fromEntries(Object.entries(e).filter(([e, t]) => !(Ve.has(e) && typeof t == "string")));
387
+ }
388
+ var qe = {
376
389
  name: "ecs",
377
390
  serialize(e) {
378
391
  return {
379
392
  body: `${e.map((e) => {
380
- let n = Fe(e.timeUnixNano);
393
+ let t = He(e.timeUnixNano), { attributes: r } = e, i = r[C];
381
394
  return JSON.stringify({
382
- "@timestamp": new Date(n).toISOString(),
395
+ "@timestamp": new Date(t).toISOString(),
383
396
  message: e.body,
384
- log: { level: t[e.severityText] ?? e.severityText.toLowerCase() },
397
+ ecs: { version: ee },
398
+ log: {
399
+ level: n[e.severityText] ?? e.severityText.toLowerCase(),
400
+ logger: typeof i == "string" ? i : void 0
401
+ },
402
+ event: { kind: r["log.type"] === "metric" ? "metric" : "event" },
403
+ error: Ge(r),
385
404
  trace: { id: e.traceId },
386
405
  span: { id: e.spanId },
387
406
  service: {
388
- name: e.resource[te],
407
+ name: e.resource[a],
389
408
  version: e.resource[o],
390
- environment: e.resource[c]
409
+ environment: e.resource[te]
391
410
  },
392
- user_agent: { original: e.resource[i] },
393
- url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
411
+ user_agent: { original: e.resource[pe] },
412
+ url: { full: r["url.full"] ?? r["page.url"] },
394
413
  labels: {
395
414
  ...H(e.resource),
396
- ...H(e.attributes)
415
+ ...H(Ke(r))
397
416
  }
398
417
  });
399
418
  }).join("\n")}\n`,
400
- contentType: u
419
+ contentType: l
401
420
  };
402
421
  }
403
422
  };
@@ -418,7 +437,7 @@ function W(e) {
418
437
  return t;
419
438
  }
420
439
  var G = /* @__PURE__ */ new WeakMap();
421
- function ze(e) {
440
+ function Je(e) {
422
441
  let t = G.get(e);
423
442
  if (t !== void 0) return t;
424
443
  let n = JSON.stringify(e);
@@ -427,7 +446,7 @@ function ze(e) {
427
446
  function K(e) {
428
447
  let t = /* @__PURE__ */ new Map();
429
448
  for (let n of e) {
430
- let e = ze(n.resource), r = t.get(e);
449
+ let e = Je(n.resource), r = t.get(e);
431
450
  r ? r.records.push(n) : t.set(e, {
432
451
  resource: n.resource,
433
452
  records: [n]
@@ -435,15 +454,15 @@ function K(e) {
435
454
  }
436
455
  return [...t.values()];
437
456
  }
438
- var Be = {
439
- name: y,
457
+ var Ye = {
458
+ name: x,
440
459
  serialize(e) {
441
460
  let t = K(e).map((e) => ({
442
461
  resource: { attributes: W(e.resource) },
443
462
  scopeLogs: [{
444
463
  scope: {
445
- name: S,
446
- version: x
464
+ name: v,
465
+ version: T
447
466
  },
448
467
  logRecords: e.records.map((e) => ({
449
468
  timeUnixNano: e.timeUnixNano,
@@ -460,19 +479,19 @@ var Be = {
460
479
  }));
461
480
  return {
462
481
  body: JSON.stringify({ resourceLogs: t }),
463
- contentType: l
482
+ contentType: s
464
483
  };
465
484
  }
466
- }, Ve = 1;
485
+ }, Xe = 1;
467
486
  function q(e, t) {
468
487
  let n = e.attributes[t];
469
488
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
470
489
  }
471
- function J(e) {
490
+ function Ze(e) {
472
491
  return Array.isArray(e) && e.every((e) => typeof e == "number" && Number.isFinite(e));
473
492
  }
474
- function He(e) {
475
- let t = e.attributes[w.attributeKeys], n = {};
493
+ function Qe(e) {
494
+ let t = e.attributes[m.attributeKeys], n = {};
476
495
  if (!Array.isArray(t)) return n;
477
496
  for (let r of t) {
478
497
  let t = typeof r == "string" && !r.startsWith("metric.") ? e.attributes[r] : void 0;
@@ -480,8 +499,8 @@ function He(e) {
480
499
  }
481
500
  return n;
482
501
  }
483
- function Ue(e) {
484
- let t = q(e, w.count);
502
+ function $e(e) {
503
+ let t = q(e, m.count);
485
504
  if (t === void 0) {
486
505
  let t = q(e, "metric.value");
487
506
  return t === void 0 ? null : {
@@ -493,39 +512,39 @@ function Ue(e) {
493
512
  explicitBounds: []
494
513
  };
495
514
  }
496
- let n = e.attributes[w.bounds], r = e.attributes[w.buckets];
497
- if (!J(n) || !J(r) || r.length !== n.length + 1) return null;
498
- let i = q(e, w.min);
515
+ let n = e.attributes[m.bounds], r = e.attributes[m.buckets];
516
+ if (!Ze(n) || !Ze(r) || r.length !== n.length + 1) return null;
517
+ let i = q(e, m.min);
499
518
  return {
500
519
  count: String(t),
501
- sum: i !== void 0 && i < 0 ? void 0 : q(e, w.sum),
520
+ sum: i !== void 0 && i < 0 ? void 0 : q(e, m.sum),
502
521
  min: i,
503
- max: q(e, w.max),
522
+ max: q(e, m.max),
504
523
  bucketCounts: r.map(String),
505
524
  explicitBounds: n
506
525
  };
507
526
  }
508
- function We(e) {
527
+ function et(e) {
509
528
  let t = q(e, "metric.value");
510
529
  return t === void 0 ? null : { asDouble: t };
511
530
  }
512
- function Ge(e, t) {
513
- let n = e.attributes[w.start], r = t === "histogram" ? Ue(e) : We(e);
531
+ function tt(e, t) {
532
+ let n = e.attributes[m.start], r = t === "histogram" ? $e(e) : et(e);
514
533
  return r === null ? null : {
515
- attributes: W(He(e)),
534
+ attributes: W(Qe(e)),
516
535
  startTimeUnixNano: typeof n == "string" ? n : e.timeUnixNano,
517
536
  timeUnixNano: e.timeUnixNano,
518
537
  ...r
519
538
  };
520
539
  }
521
- function Ke({ name: e, unit: t, field: n, points: r }) {
540
+ function nt({ name: e, unit: t, field: n, points: r }) {
522
541
  if (n === "gauge") return {
523
542
  name: e,
524
543
  unit: t,
525
544
  gauge: { dataPoints: r }
526
545
  };
527
546
  let i = {
528
- aggregationTemporality: Ve,
547
+ aggregationTemporality: Xe,
529
548
  dataPoints: r
530
549
  };
531
550
  return n === "sum" && (i.isMonotonic = r.every((e) => e.asDouble >= 0)), {
@@ -534,13 +553,13 @@ function Ke({ name: e, unit: t, field: n, points: r }) {
534
553
  [n]: i
535
554
  };
536
555
  }
537
- var qe = {
538
- name: y,
556
+ var rt = {
557
+ name: x,
539
558
  serialize(e) {
540
559
  let t = K(e).map((e) => {
541
560
  let t = /* @__PURE__ */ new Map();
542
561
  for (let n of e.records) {
543
- let e = n.attributes["metric.type"], r = e === "counter" ? "sum" : e === "histogram" ? "histogram" : "gauge", i = Ge(n, r);
562
+ let e = n.attributes["metric.type"], r = e === "counter" ? "sum" : e === "histogram" ? "histogram" : "gauge", i = tt(n, r);
544
563
  if (i === null) continue;
545
564
  let a = n.attributes["metric.name"], o = n.attributes["metric.unit"], s = {
546
565
  name: typeof a == "string" ? a : n.body,
@@ -558,33 +577,78 @@ var qe = {
558
577
  resource: { attributes: W(e.resource) },
559
578
  scopeMetrics: [{
560
579
  scope: {
561
- name: S,
562
- version: x
580
+ name: v,
581
+ version: T
563
582
  },
564
- metrics: [...t.values()].map(Ke)
583
+ metrics: [...t.values()].map(nt)
565
584
  }]
566
585
  };
567
586
  });
568
587
  return {
569
588
  body: JSON.stringify({ resourceMetrics: t }),
570
- contentType: l
589
+ contentType: s
590
+ };
591
+ }
592
+ }, it = {
593
+ internal: 1,
594
+ client: 3
595
+ }, at = 2, ot = 0, st = /* @__PURE__ */ new Set([ie, ...Object.values(S)]);
596
+ function J(e, t) {
597
+ let n = e.attributes[t];
598
+ return typeof n == "string" ? n : void 0;
599
+ }
600
+ function ct(e) {
601
+ let t = Object.fromEntries(Object.entries(e.attributes).filter(([e]) => !st.has(e))), n = J(e, S.parentId);
602
+ return {
603
+ traceId: e.traceId,
604
+ spanId: e.spanId,
605
+ ...n ? { parentSpanId: n } : {},
606
+ name: e.body,
607
+ kind: J(e, S.kind) === "client" ? it.client : it.internal,
608
+ startTimeUnixNano: J(e, S.start) ?? e.timeUnixNano,
609
+ endTimeUnixNano: J(e, S.end) ?? e.timeUnixNano,
610
+ attributes: W(t),
611
+ status: { code: J(e, S.status) === "error" ? at : ot }
612
+ };
613
+ }
614
+ var lt = {
615
+ name: x,
616
+ serialize(e) {
617
+ let t = K(e).map((e) => ({
618
+ resource: { attributes: W(e.resource) },
619
+ scopeSpans: [{
620
+ scope: {
621
+ name: v,
622
+ version: T
623
+ },
624
+ spans: e.records.map(ct)
625
+ }]
626
+ }));
627
+ return {
628
+ body: JSON.stringify({ resourceSpans: t }),
629
+ contentType: s
571
630
  };
572
631
  }
573
632
  };
574
633
  //#endregion
575
634
  //#region src/transport/serializers/select.ts
576
- function Je(e) {
577
- return e === "otlp" ? Be : e === "ecs" ? Re : e;
635
+ function ut(e) {
636
+ return e === "otlp" ? Ye : e === "ecs" ? qe : e;
578
637
  }
579
638
  function Y(e, t) {
580
- return t.metricsEndpoint !== "" && e.records.length > 0 && e.records.every((e) => ve(e, "log.type") === "metric") ? "metrics" : "logs";
639
+ let n = (t) => e.records.length > 0 && e.records.every((e) => Ce(e, "log.type") === t);
640
+ return t.metricsEndpoint !== "" && n("metric") ? "metrics" : n("span") ? "traces" : "logs";
581
641
  }
582
642
  function X(e, t) {
583
- return e === "metrics" ? t.metricsEndpoint : t.endpoint;
643
+ return e === "metrics" ? t.metricsEndpoint : e === "traces" ? t.tracesEndpoint : t.endpoint;
584
644
  }
645
+ var dt = {
646
+ metrics: rt,
647
+ traces: lt
648
+ };
585
649
  function Z(e, t, n, r) {
586
650
  try {
587
- return (Y(t, e) === "metrics" ? qe : Je(e.serializer)).serialize(t.records);
651
+ return (dt[Y(t, e)] ?? ut(e.serializer)).serialize(t.records);
588
652
  } catch (e) {
589
653
  n.report("transport.serialize_failed", r, { batchId: t.id }, e);
590
654
  return;
@@ -592,27 +656,32 @@ function Z(e, t, n, r) {
592
656
  }
593
657
  //#endregion
594
658
  //#region src/transport/status-transport.ts
595
- var Ye = class {
659
+ var ft = class {
596
660
  config;
597
661
  diagnostics;
598
662
  onSampling;
599
663
  onLoss;
600
664
  throttledUntil = {
601
665
  logs: 0,
602
- metrics: 0
666
+ metrics: 0,
667
+ traces: 0
603
668
  };
669
+ acceptedAt = null;
604
670
  constructor(e, t, n = () => void 0, r = () => void 0) {
605
671
  this.config = e, this.diagnostics = t, this.onSampling = n, this.onLoss = r;
606
672
  }
607
673
  throttledForMs(e) {
608
674
  return Math.max(0, this.throttledUntil[Y(e, this.config)] - Date.now());
609
675
  }
676
+ lastSendAt() {
677
+ return this.acceptedAt;
678
+ }
610
679
  serialize(e) {
611
680
  let t = Z(this.config, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
612
681
  return t || this.onLoss("unserializable", e.records, [e.id]), t;
613
682
  }
614
683
  accept(e, t) {
615
- this.throttledUntil[e] = 0, this.config.sampling.remote && t != null && this.onSampling(t);
684
+ this.throttledUntil[e] = 0, this.acceptedAt = Date.now(), this.config.sampling.remote && t != null && this.onSampling(t);
616
685
  }
617
686
  reject(e, t, n, r) {
618
687
  let i = String(e);
@@ -621,22 +690,22 @@ var Ye = class {
621
690
  return this.diagnostics.report("transport.rejected_credentials", `The server returned ${i}.${t}`, {
622
691
  status: e,
623
692
  endpoint: X(n, this.config)
624
- }), new B("permanent", `The server rejected the batch with ${i}.`, e);
693
+ }), new z("permanent", `The server rejected the batch with ${i}.`, e);
625
694
  }
626
- if (e === 413) return new B("too_large", "The payload is too large.", e, void 0, r.maxBytes);
695
+ if (e === 413) return new z("too_large", "The payload is too large.", e, void 0, r.maxBytes);
627
696
  if (e === 429 || e === 503) {
628
- let t = e === 429, i = r.retryAfterMs === void 0 ? void 0 : Math.min(r.retryAfterMs, _);
629
- return this.throttledUntil[n] = Date.now() + (i ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: i }), new B("throttled", t ? "The server throttles the requests." : "The service is not available.", e, i);
697
+ let t = e === 429, i = r.retryAfterMs === void 0 ? void 0 : Math.min(r.retryAfterMs, b);
698
+ return this.throttledUntil[n] = Date.now() + (i ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: i }), new z("throttled", t ? "The server throttles the requests." : "The service is not available.", e, i);
630
699
  }
631
- return e === 408 || e >= 500 ? new B("transient", `The server returned the error ${i}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${i}. The library dropped it.`, {
700
+ return e === 408 || e >= 500 ? new z("transient", `The server returned the error ${i}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${i}. The library dropped it.`, {
632
701
  batchId: t,
633
702
  status: e
634
- }), new B("permanent", `The server rejected the batch with ${i}.`, e));
703
+ }), new z("permanent", `The server rejected the batch with ${i}.`, e));
635
704
  }
636
705
  };
637
706
  //#endregion
638
707
  //#region src/transport/custom-transport.ts
639
- function Xe(e, t, n) {
708
+ function pt(e, t, n) {
640
709
  return {
641
710
  kind: n,
642
711
  body: t.body,
@@ -646,36 +715,36 @@ function Xe(e, t, n) {
646
715
  records: e.records
647
716
  };
648
717
  }
649
- function Ze(e) {
718
+ function mt(e) {
650
719
  if (typeof e != "object" || !e) return !1;
651
720
  let t = Reflect.get(e, "status");
652
721
  return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
653
722
  }
654
- function Qe(e) {
723
+ function ht(e) {
655
724
  return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
656
725
  }
657
- var $e = class extends Ye {
726
+ var gt = class extends ft {
658
727
  async send(e) {
659
728
  let { transport: t } = this.config;
660
729
  if (!t || e.records.length === 0) return;
661
730
  let n = this.serialize(e);
662
731
  if (!n) return;
663
- let r = Y(e, this.config), i = Xe(e, n, r), a;
732
+ let r = Y(e, this.config), i = pt(e, n, r), a;
664
733
  try {
665
- a = await k(ye(() => O(() => me(() => t(i)))), p);
734
+ a = await E(ye(() => k(() => _e(() => t(i)))), p);
666
735
  } catch (e) {
667
- let t = e instanceof be ? e : void 0;
668
- throw new B(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
736
+ let t = e instanceof me ? e : void 0;
737
+ throw new z(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
669
738
  }
670
- if (!Ze(a)) throw this.diagnostics.report("transport.http_error", "The custom transport returned no valid status. The library sends the batch again later.", { batchId: e.id }), new B("transient", "The custom transport returned no valid status.");
739
+ if (!mt(a)) throw this.diagnostics.report("transport.http_error", "The custom transport returned no valid status. The library sends the batch again later.", { batchId: e.id }), new z("transient", "The custom transport returned no valid status.");
671
740
  let { status: o } = a;
672
741
  if (o >= 200 && o < 300) this.accept(r, a.sampling);
673
742
  else throw this.reject(o, e.id, r, {
674
- retryAfterMs: Qe(a.retryAfterMs),
675
- maxBytes: Qe(a.maxBytes)
743
+ retryAfterMs: ht(a.retryAfterMs),
744
+ maxBytes: ht(a.maxBytes)
676
745
  });
677
746
  }
678
- }, et = class {
747
+ }, _t = class {
679
748
  deps;
680
749
  installed = !1;
681
750
  keepaliveBytes = 0;
@@ -697,7 +766,7 @@ var $e = class extends Ye {
697
766
  install() {
698
767
  if (this.installed || typeof addEventListener > "u") return;
699
768
  this.installed = !0, typeof document < "u" && (document.addEventListener("visibilitychange", this.onVisibility), document.addEventListener("freeze", this.onFreeze)), addEventListener("pagehide", this.onPageHide);
700
- let e = globalThis.fin?.me;
769
+ let e = A()?.me;
701
770
  this.deps.diagnostics.guard("openfin.unavailable", "The library could not subscribe to close-requested.", () => {
702
771
  e?.on?.("close-requested", this.onOpenFinClose);
703
772
  });
@@ -705,7 +774,7 @@ var $e = class extends Ye {
705
774
  uninstall() {
706
775
  if (!this.installed) return;
707
776
  this.installed = !1, typeof document < "u" && (document.removeEventListener("visibilitychange", this.onVisibility), document.removeEventListener("freeze", this.onFreeze)), removeEventListener("pagehide", this.onPageHide);
708
- let e = globalThis.fin?.me;
777
+ let e = A()?.me;
709
778
  this.deps.diagnostics.guard("openfin.unavailable", "The library could not unsubscribe from close-requested.", () => {
710
779
  e?.removeListener?.("close-requested", this.onOpenFinClose);
711
780
  });
@@ -725,36 +794,36 @@ var $e = class extends Ye {
725
794
  let r = this.endpointUrl();
726
795
  if (r !== null) {
727
796
  this.keepaliveBytes = 0;
728
- for (let n of this.deps.drainForExit()) {
729
- let i = Y(n, t) === "metrics" ? t.metricsEndpoint : r.href;
730
- this.flushBatch(n, e, new URL(i));
797
+ for (let i of this.deps.drainForExit()) {
798
+ let a = Y(i, t), o = a === "logs" ? r.href : X(a, t);
799
+ o ? this.flushBatch(i, e, new URL(o)) : n.count("record.dropped_no_destination");
731
800
  }
732
801
  }
733
802
  }
734
- flushBatch(e, t, n) {
735
- let { config: i, diagnostics: a } = this.deps;
736
- if (e.records.length === 0) return;
737
- let o = this.serialize(e, t);
738
- if (!o) return;
739
- if (E(o.body) > 6e4) {
740
- F(e, a, this.deps.onLoss);
803
+ flushBatch(t, n, r) {
804
+ let { config: i } = this.deps;
805
+ if (t.records.length === 0) return;
806
+ let a = this.serialize(t, n);
807
+ if (!a) return;
808
+ if (O(a.body) > 6e4) {
809
+ this.park(t);
741
810
  return;
742
811
  }
743
- n.searchParams.set(r, e.id), n.searchParams.set(d, t);
744
- let s = n.toString(), c = this.deps.exitHeaders();
745
- if (c) {
746
- this.keepaliveFetch(s, e, o.body, t, () => {
747
- let t = new Headers(c);
748
- return t.set(m, o.contentType), t.set(g, e.id), t;
812
+ r.searchParams.set(ce, t.id), r.searchParams.set(c, n);
813
+ let o = r.toString(), s = this.deps.exitHeaders();
814
+ if (s) {
815
+ this.keepaliveFetch(o, t, a.body, n, () => {
816
+ let n = new Headers(s);
817
+ return n.set(e, a.contentType), n.set(re, t.id), n;
749
818
  });
750
819
  return;
751
820
  }
752
821
  if (i.headers) {
753
- F(e, a, this.deps.onLoss);
822
+ this.park(t);
754
823
  return;
755
824
  }
756
- let l = this.beacon(s, o.body);
757
- l !== "sent" && (l === "refused" ? F(e, a, this.deps.onLoss) : this.keepaliveFetch(s, e, o.body, t, () => new Headers({ [m]: f })));
825
+ let l = this.beacon(o, a.body);
826
+ l !== "sent" && (l === "refused" ? this.park(t) : this.keepaliveFetch(o, t, a.body, n, () => new Headers({ [e]: u })));
758
827
  }
759
828
  flushAlive() {
760
829
  let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
@@ -769,10 +838,14 @@ var $e = class extends Ye {
769
838
  for (let i of this.deps.drainForExit()) {
770
839
  let a = this.serialize(i, e);
771
840
  if (!a) continue;
772
- let o = Xe(i, a, Y(i, n));
773
- (t === void 0 || r.guard("transport.http_error", "The transportOnExit hook threw an error.", () => O(() => t(o))) !== !0) && F(i, r, this.deps.onLoss);
841
+ let o = pt(i, a, Y(i, n));
842
+ (t === void 0 || r.guard("transport.http_error", "The transportOnExit hook threw an error.", () => k(() => t(o))) !== !0) && this.park(i);
774
843
  }
775
844
  }
845
+ park(e) {
846
+ let { config: t, diagnostics: n, onLoss: r } = this.deps;
847
+ t.storage === "memory" || t.storage === "none" ? r?.("not_stored", e.records, [e.id]) : je(e, n, r);
848
+ }
776
849
  serialize(e, t) {
777
850
  let n = Z(this.deps.config, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
778
851
  return n || this.deps.onLoss?.("unserializable", e.records, [e.id]), n;
@@ -789,8 +862,8 @@ var $e = class extends Ye {
789
862
  }
790
863
  keepaliveFetch(e, t, n, r, i) {
791
864
  let { config: a, diagnostics: o } = this.deps, s = () => {
792
- F(t, o, this.deps.onLoss);
793
- }, c = E(n);
865
+ this.park(t);
866
+ }, c = O(n);
794
867
  this.keepaliveBytes + c > 6e4 ? s() : (this.keepaliveBytes += c, o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
795
868
  method: "POST",
796
869
  body: n,
@@ -804,75 +877,75 @@ var $e = class extends Ye {
804
877
  };
805
878
  //#endregion
806
879
  //#region src/transport/compression.ts
807
- async function tt(e) {
880
+ async function vt(e) {
808
881
  let t = globalThis.CompressionStream;
809
882
  if (t === void 0) return null;
810
- let n = new Blob([e]).stream().pipeThrough(new t(h)), r = await new Response(n).arrayBuffer();
883
+ let n = new Blob([e]).stream().pipeThrough(new t(g)), r = await new Response(n).arrayBuffer();
811
884
  return new Uint8Array(r);
812
885
  }
813
886
  //#endregion
814
887
  //#region src/transport/http-transport.ts
815
- var nt = "In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.", rt = class extends Ye {
888
+ var yt = "In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.", bt = class extends ft {
816
889
  cachedHeaders;
817
890
  async send(e, t) {
818
891
  let { config: n } = this, r = Y(e, n), i = X(r, n);
819
- i && e.records.length !== 0 && await this.post(e, r, i, t);
892
+ i ? e.records.length !== 0 && await this.post(e, r, i, t) : this.diagnostics.count("record.dropped_no_destination");
820
893
  }
821
894
  lastHeaders() {
822
895
  let { headers: e } = this.config;
823
896
  if (!e) return;
824
897
  if (typeof e != "function") return e;
825
898
  let t = this.cachedHeaders;
826
- return t?.source === e && t.endpoint === this.config.endpoint && t.metricsEndpoint === this.config.metricsEndpoint ? t.headers : void 0;
827
- }
828
- async post(t, n, r, i) {
829
- let a = this.serialize(t);
830
- if (!a) return;
831
- let o = await this.attempt(t, r, a, i);
832
- if (this.rejectsCredentials(o.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, o = await this.attempt(t, r, a, i)), o.ok) {
833
- this.accept(n, o.headers.get(ce));
899
+ return t?.source === e && t.endpoint === this.config.endpoint && t.metricsEndpoint === this.config.metricsEndpoint && t.tracesEndpoint === this.config.tracesEndpoint ? t.headers : void 0;
900
+ }
901
+ async post(e, t, n, r) {
902
+ let i = this.serialize(e);
903
+ if (!i) return;
904
+ let a = await this.attempt(e, n, i, r);
905
+ if (this.rejectsCredentials(a.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, a = await this.attempt(e, n, i, r)), a.ok) {
906
+ this.accept(t, a.headers.get(ue));
834
907
  return;
835
908
  }
836
- let s = o.status, c = Pe(o.headers.get(e)), l = s === 413 ? await this.readMaxBytes(o) : void 0;
837
- throw this.reject(s, t.id, n, {
838
- retryAfterMs: c,
839
- maxBytes: l,
840
- advice: nt
909
+ let o = a.status, s = Be(a.headers.get(ae)), c = o === 413 ? await this.readMaxBytes(a) : void 0;
910
+ throw this.reject(o, e.id, t, {
911
+ retryAfterMs: s,
912
+ maxBytes: c,
913
+ advice: yt
841
914
  });
842
915
  }
843
916
  rejectsCredentials(e) {
844
917
  return e === 401 || e === 403;
845
918
  }
846
- async attempt(e, t, n, r) {
847
- let i = Date.now() + p, a = new Headers(await this.before(this.resolveHeaders(), i, t));
848
- a.set(m, n.contentType), a.set(g, e.id), a.set(ne, String(e.attempts));
849
- let o = await this.before(this.encodeBody(n.body), i, t);
850
- typeof o != "string" && a.set(re, h);
851
- let s = this.keepalive(o);
852
- return s && r?.(), this.dispatch(t, a, o, i, s);
919
+ async attempt(t, n, r, i) {
920
+ let a = Date.now() + p, o = new Headers(await this.before(this.resolveHeaders(), a, n));
921
+ o.set(e, r.contentType), o.set(re, t.id), o.set(ne, String(t.attempts));
922
+ let s = await this.before(this.encodeBody(r.body), a, n);
923
+ typeof s != "string" && o.set(d, g);
924
+ let c = this.keepalive(s);
925
+ return c && i?.(), this.dispatch(n, o, s, a, c);
853
926
  }
854
927
  async before(e, t, n) {
855
928
  try {
856
- return await k(e, Math.max(0, t - Date.now()));
929
+ return await E(e, Math.max(0, t - Date.now()));
857
930
  } catch {
858
931
  throw this.timeout(n);
859
932
  }
860
933
  }
861
934
  timeout(e) {
862
935
  let t = `The request took longer than ${String(p)} ms.`;
863
- return this.diagnostics.report("transport.timeout", t, { endpoint: e }), new B("timeout", t);
936
+ return this.diagnostics.report("transport.timeout", t, { endpoint: e }), new z("timeout", t);
864
937
  }
865
938
  async encodeBody(e) {
866
939
  let { config: t } = this;
867
- return t.compression !== "gzip" || E(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => tt(e)) ?? e;
940
+ return t.compression !== "gzip" || O(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => vt(e)) ?? e;
868
941
  }
869
942
  async dispatch(e, t, n, r, i) {
870
943
  let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
871
944
  o.abort();
872
945
  }, Math.max(0, r - Date.now()));
873
- A(s);
946
+ D(s);
874
947
  try {
875
- return await O(() => fetch(e, {
948
+ return await k(() => fetch(e, {
876
949
  method: "POST",
877
950
  headers: t,
878
951
  body: n,
@@ -882,15 +955,13 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
882
955
  keepalive: i
883
956
  }));
884
957
  } catch {
885
- if (o.signal.aborted) throw this.timeout(e);
886
- let t = globalThis.navigator?.onLine;
887
- throw new B(t === !1 ? "offline" : "transient", "A network error occurred.");
958
+ throw o.signal.aborted ? this.timeout(e) : new z(j() ? "transient" : "offline", "A network error occurred.");
888
959
  } finally {
889
960
  clearTimeout(s);
890
961
  }
891
962
  }
892
963
  keepalive(e) {
893
- let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? E(e) : e.byteLength;
964
+ let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? O(e) : e.byteLength;
894
965
  return t && n <= 6e4;
895
966
  }
896
967
  async readMaxBytes(e) {
@@ -903,15 +974,16 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
903
974
  let { headers: e } = this.config;
904
975
  if (!e) return {};
905
976
  if (typeof e != "function") return e;
906
- let { endpoint: t, metricsEndpoint: n } = this.config, r = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e()));
907
- return r && (this.cachedHeaders = {
977
+ let { endpoint: t, metricsEndpoint: n, tracesEndpoint: r } = this.config, i = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e()));
978
+ return i && (this.cachedHeaders = {
908
979
  source: e,
909
980
  endpoint: t,
910
981
  metricsEndpoint: n,
911
- headers: r
912
- }), r ?? {};
982
+ tracesEndpoint: r,
983
+ headers: i
984
+ }), i ?? {};
913
985
  }
914
- }, it = class {
986
+ }, xt = class {
915
987
  storage;
916
988
  transport;
917
989
  diagnostics;
@@ -927,13 +999,13 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
927
999
  this.attempt = 0, this.schedule(0);
928
1000
  };
929
1001
  constructor(e, t, n, r, i = 20, a = () => void 0) {
930
- this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = j(r.retention).maxAttempts;
1002
+ this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = Ee(r.retention).maxAttempts;
931
1003
  }
932
1004
  start() {
933
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(v);
1005
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(t);
934
1006
  }
935
1007
  nudge() {
936
- this.draining || this.schedule(s);
1008
+ this.draining || this.schedule(f);
937
1009
  }
938
1010
  async storeFailed(e, t) {
939
1011
  let n = this.toStorable(e, t);
@@ -949,23 +1021,23 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
949
1021
  let t = setTimeout(() => {
950
1022
  this.drain();
951
1023
  }, e);
952
- this.timer = t, A(t);
1024
+ this.timer = t, D(t);
953
1025
  }
954
1026
  bounded(e) {
955
- return k(e, C);
1027
+ return E(e, y);
956
1028
  }
957
1029
  clearTimer() {
958
1030
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
959
1031
  }
960
1032
  backoffMs() {
961
- let e = Math.min(s * 2 ** this.attempt, _);
1033
+ let e = Math.min(f * 2 ** this.attempt, b);
962
1034
  return Math.random() * e;
963
1035
  }
964
1036
  async drain() {
965
1037
  if (!this.draining) {
966
1038
  this.draining = !0;
967
1039
  try {
968
- await M("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(v);
1040
+ await De("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(t);
969
1041
  } finally {
970
1042
  this.draining = !1;
971
1043
  }
@@ -973,19 +1045,19 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
973
1045
  }
974
1046
  async drainLocked() {
975
1047
  try {
976
- if (globalThis.navigator?.onLine === !1) return this.schedule(v), !0;
1048
+ if (!j()) return this.schedule(t), !0;
977
1049
  let e = await this.bounded(this.storage.take(this.batchesPerDrain));
978
- if (e.length === 0) return this.schedule(v), !0;
979
- let t = /* @__PURE__ */ new Set(), n = 0;
980
- for (let r of e) {
1050
+ if (e.length === 0) return this.schedule(t), !0;
1051
+ let n = /* @__PURE__ */ new Set(), r = 0;
1052
+ for (let t of e) {
981
1053
  if (this.stopped) return !0;
982
- let e = Y(r, this.config);
983
- if (t.has(e)) continue;
984
- let i = await this.deliver(r);
1054
+ let e = Y(t, this.config);
1055
+ if (n.has(e)) continue;
1056
+ let i = await this.deliver(t);
985
1057
  if (i === "stop") return !0;
986
- i !== "next" && (t.add(e), n = Math.max(n, i));
1058
+ i !== "next" && (n.add(e), r = Math.max(r, i));
987
1059
  }
988
- return t.size > 0 ? this.schedule(n) : this.schedule(e.length === this.batchesPerDrain ? 0 : v), !0;
1060
+ return n.size > 0 ? this.schedule(r) : this.schedule(e.length === this.batchesPerDrain ? 0 : t), !0;
989
1061
  } catch (e) {
990
1062
  return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
991
1063
  }
@@ -997,9 +1069,9 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
997
1069
  }), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), "next";
998
1070
  try {
999
1071
  return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, "next";
1000
- } catch (t) {
1001
- let n = t instanceof B ? t : void 0;
1002
- return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), "next") : n?.kind === "offline" ? (this.schedule(v), "stop") : n?.kind === "throttled" ? (this.attempt++, n.retryAfterMs ?? this.backoffMs()) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, n?.retryAfterMs ?? this.backoffMs());
1072
+ } catch (n) {
1073
+ let r = n instanceof z ? n : void 0;
1074
+ return r?.kind === "permanent" || r?.kind === "too_large" ? (await this.replaceStored(e, n), "next") : r?.kind === "offline" ? (this.schedule(t), "stop") : r?.kind === "throttled" ? (this.attempt++, r.retryAfterMs ?? this.backoffMs()) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, r?.retryAfterMs ?? this.backoffMs());
1003
1075
  }
1004
1076
  }
1005
1077
  async replaceStored(e, t) {
@@ -1008,10 +1080,10 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
1008
1080
  for (let e of n) await this.bounded(this.storage.save(e));
1009
1081
  }
1010
1082
  toStorable(e, t) {
1011
- let n = t instanceof B ? t : void 0;
1083
+ let n = t instanceof z ? t : void 0;
1012
1084
  if (n?.kind === "permanent") return this.onLoss("rejected", e.records, [e.id]), [];
1013
1085
  if (n?.kind !== "too_large") return [e];
1014
- let r = ge(e, this.diagnostics);
1086
+ let r = be(e, this.diagnostics);
1015
1087
  return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
1016
1088
  from: e.records.length,
1017
1089
  to: r[0].records.length,
@@ -1021,11 +1093,14 @@ var nt = "In a cross-origin iframe, the session cookie is a third-party cookie.
1021
1093
  bodies: e.records.map((e) => e.body)
1022
1094
  }), this.onLoss("rejected", e.records, [e.id]), []);
1023
1095
  }
1024
- };
1025
- //#endregion
1026
- //#region src/core/pipeline.ts
1027
- function Q(e) {
1028
- return e.attributes[oe] === le;
1096
+ }, Q = [
1097
+ "metrics",
1098
+ "logs",
1099
+ "traces"
1100
+ ];
1101
+ function St(e) {
1102
+ let t = e.attributes[ie];
1103
+ return t === "metric" ? "metrics" : t === "span" ? "traces" : "logs";
1029
1104
  }
1030
1105
  var $ = class {
1031
1106
  options;
@@ -1043,6 +1118,9 @@ var $ = class {
1043
1118
  let e = this.pending;
1044
1119
  return this.pending = [], e;
1045
1120
  }
1121
+ get size() {
1122
+ return this.pending.length;
1123
+ }
1046
1124
  stop() {
1047
1125
  this.clearTimer();
1048
1126
  }
@@ -1051,12 +1129,12 @@ var $ = class {
1051
1129
  let e = setTimeout(() => {
1052
1130
  this.timer = null, this.onFlush(this);
1053
1131
  }, this.options.flushIntervalMs);
1054
- this.timer = e, A(e);
1132
+ this.timer = e, D(e);
1055
1133
  }
1056
1134
  clearTimer() {
1057
1135
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
1058
1136
  }
1059
- }, at = class {
1137
+ }, Ct = class {
1060
1138
  transport;
1061
1139
  storage;
1062
1140
  retry;
@@ -1065,7 +1143,7 @@ var $ = class {
1065
1143
  unconfirmed = /* @__PURE__ */ new Map();
1066
1144
  queue = [];
1067
1145
  open = /* @__PURE__ */ new Set();
1068
- ceiling = new pe();
1146
+ ceiling = new he();
1069
1147
  inFlight = 0;
1070
1148
  pumpScheduled = !1;
1071
1149
  stopped = !1;
@@ -1076,29 +1154,42 @@ var $ = class {
1076
1154
  };
1077
1155
  this.streams = {
1078
1156
  logs: new $(i.logs, a),
1079
- metrics: new $(i.metrics, a)
1157
+ metrics: new $(i.metrics, a),
1158
+ traces: new $(i.traces, a)
1080
1159
  };
1081
1160
  }
1082
1161
  push(e) {
1083
- this.stopped || (e.observedTimeUnixNano = fe(), this.route(e));
1162
+ this.stopped || (e.observedTimeUnixNano = ge(), this.route(e));
1084
1163
  }
1085
1164
  drainForExit() {
1086
1165
  let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
1087
- this.unconfirmed.clear();
1088
- let t = [...e.filter(Q), ...this.streams.metrics.take()], n = [...e.filter((e) => !Q(e)), ...this.streams.logs.take()];
1089
- return [this.toBatch(t), this.toBatch(n)].filter((e) => e !== null);
1166
+ return this.unconfirmed.clear(), Q.map((t) => this.toBatch([...e.filter((e) => St(e) === t), ...this.streams[t].take()])).filter((e) => e !== null);
1090
1167
  }
1091
1168
  async flushPending() {
1092
- this.stopped || (this.claim(this.streams.metrics), this.claim(this.streams.logs)), await Promise.all([...this.open].map((e) => e.done));
1169
+ if (!this.stopped) for (let e of Q) this.claim(this.streams[e]);
1170
+ await Promise.all([...this.open].map((e) => e.done));
1171
+ }
1172
+ counts() {
1173
+ let e = (e) => {
1174
+ let t = 0;
1175
+ for (let n of e) t += n.batch.records.length;
1176
+ return t;
1177
+ }, t = e(this.queue);
1178
+ return {
1179
+ pending: Q.reduce((e, t) => e + this.streams[t].size, 0) + t,
1180
+ inFlight: e(this.open) - t
1181
+ };
1093
1182
  }
1094
1183
  destroy() {
1095
- this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
1184
+ this.stopped = !0;
1185
+ for (let e of Q) this.streams[e].stop();
1186
+ this.queue.length = 0;
1096
1187
  for (let e of this.open) e.resolve();
1097
1188
  this.open.clear();
1098
1189
  }
1099
1190
  toBatch(e) {
1100
1191
  return e.length === 0 ? null : {
1101
- id: he(this.diagnostics),
1192
+ id: ve(this.diagnostics),
1102
1193
  records: e,
1103
1194
  createdAt: Date.now(),
1104
1195
  attempts: 0
@@ -1106,7 +1197,7 @@ var $ = class {
1106
1197
  }
1107
1198
  route(e) {
1108
1199
  try {
1109
- let t = Q(e) ? this.streams.metrics : this.streams.logs;
1200
+ let t = this.streams[St(e)];
1110
1201
  if (!this.ceiling.allow(e)) {
1111
1202
  this.diagnostics.count("record.dropped_by_ceiling");
1112
1203
  return;
@@ -1184,23 +1275,24 @@ var $ = class {
1184
1275
  }
1185
1276
  async store(e) {
1186
1277
  await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
1187
- await k(this.storage.save(e), C), this.retry.nudge();
1278
+ await E(this.storage.save(e), y), this.retry.nudge();
1188
1279
  });
1189
1280
  }
1190
- }, ot = class e {
1281
+ }, wt = class e {
1191
1282
  storage;
1192
1283
  retry;
1193
1284
  pipeline;
1194
1285
  exitFlush;
1195
1286
  diagnostics;
1196
- constructor(e, t, n, r, i) {
1197
- this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
1287
+ transport;
1288
+ constructor(e, t, n, r, i, a) {
1289
+ this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i, this.transport = a;
1198
1290
  }
1199
1291
  static async create(t) {
1200
- let { config: n, diagnostics: r } = t, i = await Ne(n.storage, ie, j(n.retention), r, t.onGap), a = (e) => {
1201
- let i = xe(e, r);
1202
- i && Se(t.remote, n, i);
1203
- }, { onLoss: o } = t, s = n.transport ? void 0 : new rt(n, r, a, o), c = s ?? new $e(n, r, a, o), l = new it(i, c, r, n, 20, o), { batching: u } = n, d = new at(c, i, l, r, {
1292
+ let { config: n, diagnostics: r } = t, i = await ze(n.storage, de, Ee(n.retention), r, t.onGap), a = (e) => {
1293
+ let i = we(e, r);
1294
+ i && Te(t.remote, n, i);
1295
+ }, { onLoss: o } = t, s = n.transport ? void 0 : new bt(n, r, a, o), c = s ?? new gt(n, r, a, o), l = new xt(i, c, r, n, 20, o), { batching: u } = n, d = new Ct(c, i, l, r, {
1204
1296
  logs: {
1205
1297
  flushIntervalMs: u.logFlushIntervalMs,
1206
1298
  batchSize: u.logBatchSize
@@ -1208,8 +1300,12 @@ var $ = class {
1208
1300
  metrics: {
1209
1301
  flushIntervalMs: u.metricFlushIntervalMs,
1210
1302
  batchSize: u.metricBatchSize
1303
+ },
1304
+ traces: {
1305
+ flushIntervalMs: u.logFlushIntervalMs,
1306
+ batchSize: u.logBatchSize
1211
1307
  }
1212
- }), f = new et({
1308
+ }), f = new _t({
1213
1309
  config: n,
1214
1310
  diagnostics: r,
1215
1311
  drainForExit: () => d.drainForExit(),
@@ -1223,7 +1319,7 @@ var $ = class {
1223
1319
  } finally {
1224
1320
  p || (f.uninstall(), l.stop());
1225
1321
  }
1226
- let m = new e(i, l, d, f, r);
1322
+ let m = new e(i, l, d, f, r, c);
1227
1323
  return m.importEmergency(), m;
1228
1324
  }
1229
1325
  push(e) {
@@ -1235,15 +1331,21 @@ var $ = class {
1235
1331
  async queueDepth() {
1236
1332
  return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
1237
1333
  }
1334
+ stats() {
1335
+ return {
1336
+ ...this.pipeline.counts(),
1337
+ lastSendAt: this.transport.lastSendAt()
1338
+ };
1339
+ }
1238
1340
  async destroy() {
1239
1341
  await this.diagnostics.guardAsync("pipeline.crashed", "The flush before shutdown failed.", () => this.flush()), this.exitFlush.flush("shutdown"), this.exitFlush.uninstall(), this.retry.stop(), this.pipeline.destroy(), await this.storage.close();
1240
1342
  }
1241
1343
  async importEmergency() {
1242
- let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => Te(this.storage, this.diagnostics));
1344
+ let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => Me(this.storage, this.diagnostics));
1243
1345
  e !== void 0 && e > 0 && this.retry.nudge();
1244
1346
  }
1245
1347
  };
1246
1348
  //#endregion
1247
- export { ot as Sender, I as n, L as t };
1349
+ export { wt as Sender, P as i, L as n, Ne as r, I as t };
1248
1350
 
1249
- //# sourceMappingURL=sender--0_VzPbN.js.map
1351
+ //# sourceMappingURL=sender-DFQMF39P.js.map