@utk09/ui-observability 0.9.1 → 0.9.2

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 (118) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +75 -64
  3. package/dist/{batch-DEK4bv9N.js → batch-4xKzzSCj.js} +3 -3
  4. package/dist/{batch-DEK4bv9N.js.map → batch-4xKzzSCj.js.map} +1 -1
  5. package/dist/{batch-DEVFs28i.cjs → batch-cys7e53Q.cjs} +2 -2
  6. package/dist/{batch-DEVFs28i.cjs.map → batch-cys7e53Q.cjs.map} +1 -1
  7. package/dist/{bus-DNFvTkif.cjs → bus-B6vzPmQM.cjs} +2 -2
  8. package/dist/{bus-DNFvTkif.cjs.map → bus-B6vzPmQM.cjs.map} +1 -1
  9. package/dist/{bus-HVQ8E72V.js → bus-DrixwdiX.js} +11 -11
  10. package/dist/{bus-HVQ8E72V.js.map → bus-DrixwdiX.js.map} +1 -1
  11. package/dist/capture/network.d.ts +2 -0
  12. package/dist/capture/types.d.ts +3 -0
  13. package/dist/{console-C9Y639mn.js → console-B3vGRW5p.js} +3 -3
  14. package/dist/{console-C9Y639mn.js.map → console-B3vGRW5p.js.map} +1 -1
  15. package/dist/{console-DssDxq1B.cjs → console-ChfuJlf9.cjs} +2 -2
  16. package/dist/{console-DssDxq1B.cjs.map → console-ChfuJlf9.cjs.map} +1 -1
  17. package/dist/constants-Be83LICb.cjs +2 -0
  18. package/dist/constants-Be83LICb.cjs.map +1 -0
  19. package/dist/{constants-N99w84xy.js → constants-CQ_D7jIW.js} +39 -12
  20. package/dist/constants-CQ_D7jIW.js.map +1 -0
  21. package/dist/constants.d.ts +27 -1
  22. package/dist/core/diagnostics.d.ts +1 -1
  23. package/dist/core/meter.d.ts +45 -0
  24. package/dist/core/pipeline.d.ts +5 -12
  25. package/dist/core/record.d.ts +7 -0
  26. package/dist/core/runtime.d.ts +17 -0
  27. package/dist/core/sampling.d.ts +2 -0
  28. package/dist/core/sender.d.ts +2 -0
  29. package/dist/{errors-CQusIGWJ.js → errors-BGs5NOrw.js} +4 -4
  30. package/dist/{errors-CQusIGWJ.js.map → errors-BGs5NOrw.js.map} +1 -1
  31. package/dist/{errors-BTWuVnHZ.cjs → errors-BMJm7KZZ.cjs} +2 -2
  32. package/dist/{errors-BTWuVnHZ.cjs.map → errors-BMJm7KZZ.cjs.map} +1 -1
  33. package/dist/{identity-B1GDS1Tb.cjs → identity-DXyV86o-.cjs} +2 -2
  34. package/dist/{identity-B1GDS1Tb.cjs.map → identity-DXyV86o-.cjs.map} +1 -1
  35. package/dist/{identity-D4DPjTM9.js → identity-rpEyjvVg.js} +2 -2
  36. package/dist/{identity-D4DPjTM9.js.map → identity-rpEyjvVg.js.map} +1 -1
  37. package/dist/index.cjs +1 -1
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.ts +18 -0
  40. package/dist/index.js +520 -355
  41. package/dist/index.js.map +1 -1
  42. package/dist/{indexeddb-storage-ukzC82dm.cjs → indexeddb-storage-BXaPVPyG.cjs} +2 -2
  43. package/dist/{indexeddb-storage-ukzC82dm.cjs.map → indexeddb-storage-BXaPVPyG.cjs.map} +1 -1
  44. package/dist/{indexeddb-storage-B8SGUzSV.js → indexeddb-storage-Q9fDYlyn.js} +15 -15
  45. package/dist/{indexeddb-storage-B8SGUzSV.js.map → indexeddb-storage-Q9fDYlyn.js.map} +1 -1
  46. package/dist/{interactions-CnjfQgw3.js → interactions-B8zjCjga.js} +2 -2
  47. package/dist/{interactions-CnjfQgw3.js.map → interactions-B8zjCjga.js.map} +1 -1
  48. package/dist/{interactions-CcxrVzpg.cjs → interactions-BAGRmtrv.cjs} +2 -2
  49. package/dist/{interactions-CcxrVzpg.cjs.map → interactions-BAGRmtrv.cjs.map} +1 -1
  50. package/dist/{journey-DxlfdFJV.cjs → journey-BGSyy8Es.cjs} +2 -2
  51. package/dist/{journey-DxlfdFJV.cjs.map → journey-BGSyy8Es.cjs.map} +1 -1
  52. package/dist/{journey-DjvDzHyp.js → journey-_dQQ1eMP.js} +19 -19
  53. package/dist/{journey-DjvDzHyp.js.map → journey-_dQQ1eMP.js.map} +1 -1
  54. package/dist/library-request-BIG3Xpx3.cjs +2 -0
  55. package/dist/library-request-BIG3Xpx3.cjs.map +1 -0
  56. package/dist/library-request-DX6ev9oG.js +25 -0
  57. package/dist/library-request-DX6ev9oG.js.map +1 -0
  58. package/dist/{long-frames-CZk3XOkH.js → long-frames-B0tKuChx.js} +3 -3
  59. package/dist/{long-frames-CZk3XOkH.js.map → long-frames-B0tKuChx.js.map} +1 -1
  60. package/dist/{long-frames-BGik_Yhy.cjs → long-frames-Cq2LgNnp.cjs} +2 -2
  61. package/dist/{long-frames-BGik_Yhy.cjs.map → long-frames-Cq2LgNnp.cjs.map} +1 -1
  62. package/dist/models/config.d.ts +23 -0
  63. package/dist/models/metric.d.ts +50 -0
  64. package/dist/network-C6kJbW6K.cjs +2 -0
  65. package/dist/network-C6kJbW6K.cjs.map +1 -0
  66. package/dist/network-CMnEvGJB.js +211 -0
  67. package/dist/network-CMnEvGJB.js.map +1 -0
  68. package/dist/{platform-DW3GFIUE.cjs → platform-DNOJjpOm.cjs} +2 -2
  69. package/dist/{platform-DW3GFIUE.cjs.map → platform-DNOJjpOm.cjs.map} +1 -1
  70. package/dist/{platform-Cjts-8k8.js → platform-j0uMPwHi.js} +3 -3
  71. package/dist/{platform-Cjts-8k8.js.map → platform-j0uMPwHi.js.map} +1 -1
  72. package/dist/{remote-rules-ByS34k4e.cjs → remote-rules-DgoBJxZL.cjs} +2 -2
  73. package/dist/{remote-rules-ByS34k4e.cjs.map → remote-rules-DgoBJxZL.cjs.map} +1 -1
  74. package/dist/{remote-rules-M-XZ1xbe.js → remote-rules-UggoZqfP.js} +11 -11
  75. package/dist/{remote-rules-M-XZ1xbe.js.map → remote-rules-UggoZqfP.js.map} +1 -1
  76. package/dist/{sampling-BN3Oi6SV.js → sampling-BLMD8EGM.js} +28 -27
  77. package/dist/sampling-BLMD8EGM.js.map +1 -0
  78. package/dist/sampling-MthcVXXU.cjs +2 -0
  79. package/dist/sampling-MthcVXXU.cjs.map +1 -0
  80. package/dist/{sanitize-Dwj9JCkI.js → sanitize-BNwgPj_B.js} +2 -2
  81. package/dist/{sanitize-Dwj9JCkI.js.map → sanitize-BNwgPj_B.js.map} +1 -1
  82. package/dist/{sanitize-DKp5MRsa.cjs → sanitize-BqzPc4Jg.cjs} +2 -2
  83. package/dist/{sanitize-DKp5MRsa.cjs.map → sanitize-BqzPc4Jg.cjs.map} +1 -1
  84. package/dist/{sender-BBY0IcUo.js → sender--0_VzPbN.js} +408 -268
  85. package/dist/sender--0_VzPbN.js.map +1 -0
  86. package/dist/sender-SPGMqZjD.cjs +3 -0
  87. package/dist/sender-SPGMqZjD.cjs.map +1 -0
  88. package/dist/{storm-CKuaBp7i.cjs → storm-CTy1dfvs.cjs} +2 -2
  89. package/dist/{storm-CKuaBp7i.cjs.map → storm-CTy1dfvs.cjs.map} +1 -1
  90. package/dist/{storm-DhtL2eVr.js → storm-knaj4GUH.js} +2 -2
  91. package/dist/{storm-DhtL2eVr.js.map → storm-knaj4GUH.js.map} +1 -1
  92. package/dist/transport/custom-transport.d.ts +3 -2
  93. package/dist/transport/exit-flush.d.ts +13 -2
  94. package/dist/transport/http-transport.d.ts +6 -4
  95. package/dist/transport/retry-engine.d.ts +3 -1
  96. package/dist/transport/serializers/otlp-metrics.d.ts +3 -0
  97. package/dist/transport/serializers/otlp.d.ts +30 -0
  98. package/dist/transport/serializers/select.d.ts +20 -4
  99. package/dist/transport/status-transport.d.ts +19 -11
  100. package/dist/utils/library-request.d.ts +12 -0
  101. package/package.json +1 -1
  102. package/dist/constants-N99w84xy.js.map +0 -1
  103. package/dist/constants-X86IDwkC.cjs +0 -2
  104. package/dist/constants-X86IDwkC.cjs.map +0 -1
  105. package/dist/library-request-BZ1ekVtl.cjs +0 -2
  106. package/dist/library-request-BZ1ekVtl.cjs.map +0 -1
  107. package/dist/library-request-C8kc5YWv.js +0 -14
  108. package/dist/library-request-C8kc5YWv.js.map +0 -1
  109. package/dist/network-51iicpLl.js +0 -174
  110. package/dist/network-51iicpLl.js.map +0 -1
  111. package/dist/network-jBbjyAJP.cjs +0 -2
  112. package/dist/network-jBbjyAJP.cjs.map +0 -1
  113. package/dist/sampling-BN3Oi6SV.js.map +0 -1
  114. package/dist/sampling-b2ck5X98.cjs +0 -2
  115. package/dist/sampling-b2ck5X98.cjs.map +0 -1
  116. package/dist/sender-BBY0IcUo.js.map +0 -1
  117. package/dist/sender-BXoAZKum.cjs +0 -3
  118. package/dist/sender-BXoAZKum.cjs.map +0 -1
@@ -1,13 +1,13 @@
1
- import { $ as e, At as t, Ct as n, Gt as r, H as i, J as a, Kt as o, Lt as s, M as c, N as l, Nt as u, Q as d, Rt as f, V as p, Wt as m, X as ee, Xt as te, Y as h, Z as g, an as ne, b as _, cn as v, d as y, dn as b, fn as re, gt as ie, j as x, jt as ae, mt as oe, nn as S, on as se, sn as ce, tn as le, vt as C, wt as w, yt as ue, z as de } from "./constants-N99w84xy.js";
2
- import { o as fe, t as pe } from "./sampling-BN3Oi6SV.js";
3
- import { o as me, t as T } from "./sanitize-Dwj9JCkI.js";
4
- import { i as he } from "./identity-D4DPjTM9.js";
5
- import { i as ge, n as _e, r as E } from "./batch-DEK4bv9N.js";
6
- import { n as D } from "./library-request-C8kc5YWv.js";
7
- import { n as O, r as k, t as A } from "./deadline-5_PecIl5.js";
8
- import { n as j, t as M } from "./remote-rules-M-XZ1xbe.js";
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";
9
9
  //#region src/models/storage.ts
10
- function N(e) {
10
+ function j(e) {
11
11
  let { maxBatches: t } = e;
12
12
  return e.mode === "until-delivered" ? {
13
13
  maxBatches: t,
@@ -21,13 +21,13 @@ function N(e) {
21
21
  }
22
22
  //#endregion
23
23
  //#region src/utils/lock.ts
24
- function P(e, t, n, { skipIfBusy: r = !0 } = {}) {
24
+ function M(e, t, n, { skipIfBusy: r = !0 } = {}) {
25
25
  let i = globalThis.navigator?.locks;
26
26
  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
27
  }
28
28
  //#endregion
29
29
  //#region src/storage/keys.ts
30
- function F(e, t) {
30
+ function N(e, t) {
31
31
  let n = [];
32
32
  return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
33
33
  for (let t = 0; t < localStorage.length; t++) {
@@ -38,57 +38,57 @@ function F(e, t) {
38
38
  }
39
39
  //#endregion
40
40
  //#region src/storage/emergency-queue.ts
41
- function I(e) {
41
+ function Ce(e) {
42
42
  let t = String(e.createdAt).padStart(14, "0");
43
- return `${p}${t}.${e.id}`;
43
+ return `${a}${t}.${e.id}`;
44
44
  }
45
- function L(e, t) {
45
+ function P(e, t) {
46
46
  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 : E(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
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
48
  }
49
- async function ve(e, t) {
49
+ async function we(e, t) {
50
50
  let n = 0;
51
- for (let r of F(p, t)) {
51
+ for (let r of N(a, t)) {
52
52
  let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
53
53
  let e = localStorage.getItem(r);
54
54
  return localStorage.removeItem(r), e;
55
55
  });
56
56
  if (!i) continue;
57
- let a = L(i, t);
57
+ let a = P(i, t);
58
58
  if (a !== null) try {
59
- await O(e.save(a), S), n++;
59
+ await k(e.save(a), C), n++;
60
60
  } catch (e) {
61
61
  t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
62
62
  }
63
63
  }
64
64
  return n;
65
65
  }
66
- function R(e, t, n) {
67
- let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], a = t.guard("storage.quota_exceeded", r, () => {
68
- let n = F(p, t);
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);
69
69
  for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
70
- let n = L(String(localStorage.getItem(e)), t);
70
+ let n = P(String(localStorage.getItem(e)), t);
71
71
  n !== null && i.push(n), localStorage.removeItem(e);
72
72
  }
73
- return localStorage.setItem(I(e), JSON.stringify(e)), !0;
73
+ return localStorage.setItem(Ce(e), JSON.stringify(e)), !0;
74
74
  });
75
75
  t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
76
76
  if (i.length > 0) {
77
77
  let e = i.flatMap((e) => e.records);
78
78
  n?.("exit_queue_full", e, i.map((e) => e.id));
79
79
  }
80
- a !== !0 && n?.("quota", e.records, [e.id]);
80
+ o !== !0 && n?.("quota", e.records, [e.id]);
81
81
  });
82
82
  }
83
- async function ye(e, t) {
84
- return await P("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
83
+ async function Te(e, t) {
84
+ return await M("ui-observability.emergency", t, () => we(e, t), { skipIfBusy: !1 }) ?? 0;
85
85
  }
86
86
  //#endregion
87
87
  //#region src/storage/eviction.ts
88
- function z(e) {
88
+ function I(e) {
89
89
  return Array.isArray(e.records) && e.records.some(_e);
90
90
  }
91
- var B = class {
91
+ var L = class {
92
92
  howMany;
93
93
  isAudit;
94
94
  plain = [];
@@ -103,26 +103,26 @@ var B = class {
103
103
  return [...this.plain, ...this.audit].slice(0, this.howMany);
104
104
  }
105
105
  };
106
- function V(e, t, n) {
107
- let r = new B(t, n);
106
+ function R(e, t, n) {
107
+ let r = new L(t, n);
108
108
  for (let t of e) if (!r.add(t)) break;
109
109
  return r.picked();
110
110
  }
111
111
  //#endregion
112
112
  //#region src/storage/local-storage.ts
113
- function be(e) {
113
+ function Ee(e) {
114
114
  let t = String(e.createdAt).padStart(14, "0");
115
- return `${_}${t}.${e.id}`;
115
+ return `${T}${t}.${e.id}`;
116
116
  }
117
- function xe(e) {
118
- let t = _.length, n = Number(e.slice(t, t + 14));
117
+ function De(e) {
118
+ let t = T.length, n = Number(e.slice(t, t + 14));
119
119
  return Number.isFinite(n) ? n : null;
120
120
  }
121
- var Se = class {
121
+ var Oe = class {
122
122
  limits;
123
123
  diagnostics;
124
124
  onGap;
125
- name = ne;
125
+ name = ue;
126
126
  constructor(e, t, n) {
127
127
  this.limits = e, this.diagnostics = t, this.onGap = n;
128
128
  }
@@ -160,7 +160,7 @@ var Se = class {
160
160
  reason: "expired"
161
161
  }, n = [], r = [];
162
162
  for (let t of this.keys()) {
163
- let i = xe(t);
163
+ let i = De(t);
164
164
  i === null || i < e ? n.push(t) : r.push(t);
165
165
  }
166
166
  this.drop(t, "expired", [...this.entries(n)]);
@@ -177,7 +177,7 @@ var Se = class {
177
177
  return Promise.resolve();
178
178
  }
179
179
  write(e, t) {
180
- return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(be(e), JSON.stringify(e)), !0)) === !0;
180
+ return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(Ee(e), JSON.stringify(e)), !0)) === !0;
181
181
  }
182
182
  evictForQuota() {
183
183
  let e = this.keys(), t = {
@@ -188,7 +188,7 @@ var Se = class {
188
188
  this.drop(t, "quota", this.evictable(e, n));
189
189
  }
190
190
  evictable(e, t) {
191
- return V(this.entries(e), t, (e) => e.batch !== null && z(e.batch));
191
+ return R(this.entries(e), t, (e) => e.batch !== null && I(e.batch));
192
192
  }
193
193
  *entries(e) {
194
194
  for (let t of e) yield {
@@ -213,7 +213,7 @@ var Se = class {
213
213
  let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
214
214
  if (!t) return null;
215
215
  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 : E(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
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);
217
217
  }
218
218
  keyOf(e) {
219
219
  return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
@@ -227,18 +227,18 @@ var Se = class {
227
227
  });
228
228
  }
229
229
  keys() {
230
- return F(_, this.diagnostics);
230
+ return N(T, this.diagnostics);
231
231
  }
232
232
  };
233
233
  //#endregion
234
234
  //#region src/storage/memory-storage.ts
235
- function Ce(e) {
235
+ function ke(e) {
236
236
  return e.reduce((e, t) => e + t.records.length, 0);
237
237
  }
238
- var H = class {
238
+ var z = class {
239
239
  limits;
240
240
  onGap;
241
- name = se;
241
+ name = de;
242
242
  batches = [];
243
243
  constructor(e, t) {
244
244
  this.limits = e, this.onGap = t;
@@ -265,14 +265,14 @@ var H = class {
265
265
  this.batches = this.batches.filter((t) => t.createdAt >= e), this.report(t, "expired", n);
266
266
  let r = this.batches.length - this.limits.maxBatches;
267
267
  if (r > 0) {
268
- let e = V(this.batches, r, z);
268
+ let e = R(this.batches, r, I);
269
269
  this.batches = this.batches.filter((t) => !e.includes(t)), this.report(t, "over_capacity", e);
270
270
  }
271
271
  return Promise.resolve(t);
272
272
  }
273
273
  report(e, t, n) {
274
274
  if (n.length === 0) return;
275
- let r = Ce(n);
275
+ let r = ke(n);
276
276
  e.batches += n.length, e.records += r, e.reason = t, this.onGap?.({
277
277
  batches: n.length,
278
278
  records: r,
@@ -288,8 +288,8 @@ var H = class {
288
288
  close() {
289
289
  return this.batches = [], Promise.resolve();
290
290
  }
291
- }, we = (e) => ({
292
- name: ce,
291
+ }, Ae = (e) => ({
292
+ name: se,
293
293
  save: (t) => (e?.({
294
294
  batches: 1,
295
295
  records: t.records.length,
@@ -307,30 +307,30 @@ var H = class {
307
307
  clear: () => Promise.resolve(),
308
308
  close: () => Promise.resolve()
309
309
  });
310
- function Te(e) {
310
+ function je(e) {
311
311
  return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
312
312
  }
313
- function Ee(e) {
314
- return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(v, "1"), localStorage.removeItem(v), !0)) === !0;
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;
315
315
  }
316
- async function De(e, t, n, r, i) {
317
- if (e === "none") return we(i);
318
- if (e === "memory") return new H(n, i);
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);
319
319
  if (e === "indexeddb" || e === "auto") {
320
- if (Te(r)) {
320
+ if (je(r)) {
321
321
  let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
322
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-B8SGUzSV.js"), a = new e(t, n, r, i);
322
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-Q9fDYlyn.js"), a = new e(t, n, r, i);
323
323
  return await a.open(), a;
324
324
  });
325
325
  if (e) return e;
326
326
  }
327
- if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new H(n, i);
327
+ if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new z(n, i);
328
328
  }
329
- return Ee(r) ? new Se(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new H(n, i));
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));
330
330
  }
331
331
  //#endregion
332
332
  //#region src/transport/errors.ts
333
- var U = class extends Error {
333
+ var B = class extends Error {
334
334
  kind;
335
335
  status;
336
336
  retryAfterMs;
@@ -339,77 +339,77 @@ var U = class extends Error {
339
339
  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
340
  }
341
341
  };
342
- function Oe(e) {
342
+ function Pe(e) {
343
343
  if (!e) return;
344
344
  let t = Number(e);
345
- if (Number.isFinite(t)) return Math.max(0, t * ie);
345
+ if (Number.isFinite(t)) return Math.max(0, t * ae);
346
346
  let n = Date.parse(e);
347
347
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
348
348
  }
349
349
  //#endregion
350
350
  //#region src/transport/serializers/ecs.ts
351
- function ke(e) {
352
- return C.test(e) ? Number(BigInt(e) / ue) : Date.now();
351
+ function Fe(e) {
352
+ return ee.test(e) ? Number(BigInt(e) / n) : Date.now();
353
353
  }
354
- function Ae(e) {
354
+ function Ie(e) {
355
355
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
356
356
  }
357
- function je(e, t, n) {
357
+ function Le(e, t, n) {
358
358
  let r = e[t];
359
359
  r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
360
360
  }
361
- function W(e, t, n, r) {
362
- let i = Ae(n);
363
- if (i !== null) je(e, t, i);
361
+ function V(e, t, n, r) {
362
+ let i = Ie(n);
363
+ if (i !== null) Le(e, t, i);
364
364
  else if (typeof n == "object" && n && !r.has(n)) {
365
- if (r.add(n), Array.isArray(n)) for (let i of n) W(e, t, i, r);
366
- else for (let [i, a] of Object.entries(n)) W(e, `${t}.${i}`, a, r);
365
+ if (r.add(n), Array.isArray(n)) for (let i of n) V(e, t, i, r);
366
+ else for (let [i, a] of Object.entries(n)) V(e, `${t}.${i}`, a, r);
367
367
  r.delete(n);
368
368
  }
369
369
  }
370
- function G(e) {
370
+ function H(e) {
371
371
  let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
372
- for (let [r, i] of Object.entries(e)) W(t, r, i, n);
372
+ for (let [r, i] of Object.entries(e)) V(t, r, i, n);
373
373
  return t;
374
374
  }
375
- var Me = {
375
+ var Re = {
376
376
  name: "ecs",
377
377
  serialize(e) {
378
378
  return {
379
379
  body: `${e.map((e) => {
380
- let t = ke(e.timeUnixNano);
380
+ let n = Fe(e.timeUnixNano);
381
381
  return JSON.stringify({
382
- "@timestamp": new Date(t).toISOString(),
382
+ "@timestamp": new Date(n).toISOString(),
383
383
  message: e.body,
384
- log: { level: de[e.severityText] ?? e.severityText.toLowerCase() },
384
+ log: { level: t[e.severityText] ?? e.severityText.toLowerCase() },
385
385
  trace: { id: e.traceId },
386
386
  span: { id: e.spanId },
387
387
  service: {
388
- name: e.resource[s],
389
- version: e.resource[f],
390
- environment: e.resource[u]
388
+ name: e.resource[te],
389
+ version: e.resource[o],
390
+ environment: e.resource[c]
391
391
  },
392
- user_agent: { original: e.resource[ae] },
392
+ user_agent: { original: e.resource[i] },
393
393
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
394
394
  labels: {
395
- ...G(e.resource),
396
- ...G(e.attributes)
395
+ ...H(e.resource),
396
+ ...H(e.attributes)
397
397
  }
398
398
  });
399
399
  }).join("\n")}\n`,
400
- contentType: c
400
+ contentType: u
401
401
  };
402
402
  }
403
403
  };
404
404
  //#endregion
405
405
  //#region src/transport/serializers/otlp.ts
406
- function K(e) {
407
- return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isSafeInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(K).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: q(e) } } : null;
406
+ function U(e) {
407
+ return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isSafeInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(U).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: W(e) } } : null;
408
408
  }
409
- function q(e) {
409
+ function W(e) {
410
410
  let t = [];
411
411
  for (let [n, r] of Object.entries(e)) {
412
- let e = K(r);
412
+ let e = U(r);
413
413
  e && t.push({
414
414
  key: n,
415
415
  value: e
@@ -417,30 +417,33 @@ function q(e) {
417
417
  }
418
418
  return t;
419
419
  }
420
- var J = /* @__PURE__ */ new WeakMap();
421
- function Ne(e) {
422
- let t = J.get(e);
420
+ var G = /* @__PURE__ */ new WeakMap();
421
+ function ze(e) {
422
+ let t = G.get(e);
423
423
  if (t !== void 0) return t;
424
424
  let n = JSON.stringify(e);
425
- return J.set(e, n), n;
425
+ return G.set(e, n), n;
426
426
  }
427
- var Pe = {
428
- name: te,
427
+ function K(e) {
428
+ let t = /* @__PURE__ */ new Map();
429
+ for (let n of e) {
430
+ let e = ze(n.resource), r = t.get(e);
431
+ r ? r.records.push(n) : t.set(e, {
432
+ resource: n.resource,
433
+ records: [n]
434
+ });
435
+ }
436
+ return [...t.values()];
437
+ }
438
+ var Be = {
439
+ name: y,
429
440
  serialize(e) {
430
- let t = /* @__PURE__ */ new Map();
431
- for (let n of e) {
432
- let e = Ne(n.resource), r = t.get(e);
433
- r ? r.records.push(n) : t.set(e, {
434
- resource: n.resource,
435
- records: [n]
436
- });
437
- }
438
- let n = [...t.values()].map((e) => ({
439
- resource: { attributes: q(e.resource) },
441
+ let t = K(e).map((e) => ({
442
+ resource: { attributes: W(e.resource) },
440
443
  scopeLogs: [{
441
444
  scope: {
442
- name: b,
443
- version: re
445
+ name: S,
446
+ version: x
444
447
  },
445
448
  logRecords: e.records.map((e) => ({
446
449
  timeUnixNano: e.timeUnixNano,
@@ -451,24 +454,137 @@ var Pe = {
451
454
  traceId: e.traceId,
452
455
  spanId: e.spanId,
453
456
  flags: e.traceFlags,
454
- attributes: q(e.attributes)
457
+ attributes: W(e.attributes)
455
458
  }))
456
459
  }]
457
460
  }));
458
461
  return {
459
- body: JSON.stringify({ resourceLogs: n }),
460
- contentType: x
462
+ body: JSON.stringify({ resourceLogs: t }),
463
+ contentType: l
464
+ };
465
+ }
466
+ }, Ve = 1;
467
+ function q(e, t) {
468
+ let n = e.attributes[t];
469
+ return typeof n == "number" && Number.isFinite(n) ? n : void 0;
470
+ }
471
+ function J(e) {
472
+ return Array.isArray(e) && e.every((e) => typeof e == "number" && Number.isFinite(e));
473
+ }
474
+ function He(e) {
475
+ let t = e.attributes[w.attributeKeys], n = {};
476
+ if (!Array.isArray(t)) return n;
477
+ for (let r of t) {
478
+ let t = typeof r == "string" && !r.startsWith("metric.") ? e.attributes[r] : void 0;
479
+ (typeof t == "string" || typeof t == "number" || typeof t == "boolean") && (n[r] = t);
480
+ }
481
+ return n;
482
+ }
483
+ function Ue(e) {
484
+ let t = q(e, w.count);
485
+ if (t === void 0) {
486
+ let t = q(e, "metric.value");
487
+ return t === void 0 ? null : {
488
+ count: "1",
489
+ sum: t < 0 ? void 0 : t,
490
+ min: t,
491
+ max: t,
492
+ bucketCounts: ["1"],
493
+ explicitBounds: []
494
+ };
495
+ }
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);
499
+ return {
500
+ count: String(t),
501
+ sum: i !== void 0 && i < 0 ? void 0 : q(e, w.sum),
502
+ min: i,
503
+ max: q(e, w.max),
504
+ bucketCounts: r.map(String),
505
+ explicitBounds: n
506
+ };
507
+ }
508
+ function We(e) {
509
+ let t = q(e, "metric.value");
510
+ return t === void 0 ? null : { asDouble: t };
511
+ }
512
+ function Ge(e, t) {
513
+ let n = e.attributes[w.start], r = t === "histogram" ? Ue(e) : We(e);
514
+ return r === null ? null : {
515
+ attributes: W(He(e)),
516
+ startTimeUnixNano: typeof n == "string" ? n : e.timeUnixNano,
517
+ timeUnixNano: e.timeUnixNano,
518
+ ...r
519
+ };
520
+ }
521
+ function Ke({ name: e, unit: t, field: n, points: r }) {
522
+ if (n === "gauge") return {
523
+ name: e,
524
+ unit: t,
525
+ gauge: { dataPoints: r }
526
+ };
527
+ let i = {
528
+ aggregationTemporality: Ve,
529
+ dataPoints: r
530
+ };
531
+ return n === "sum" && (i.isMonotonic = r.every((e) => e.asDouble >= 0)), {
532
+ name: e,
533
+ unit: t,
534
+ [n]: i
535
+ };
536
+ }
537
+ var qe = {
538
+ name: y,
539
+ serialize(e) {
540
+ let t = K(e).map((e) => {
541
+ let t = /* @__PURE__ */ new Map();
542
+ 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);
544
+ if (i === null) continue;
545
+ let a = n.attributes["metric.name"], o = n.attributes["metric.unit"], s = {
546
+ name: typeof a == "string" ? a : n.body,
547
+ unit: typeof o == "string" ? o : "",
548
+ field: r,
549
+ points: []
550
+ }, c = JSON.stringify([
551
+ s.field,
552
+ s.name,
553
+ s.unit
554
+ ]), l = t.get(c) ?? s;
555
+ l.points.push(i), t.set(c, l);
556
+ }
557
+ return {
558
+ resource: { attributes: W(e.resource) },
559
+ scopeMetrics: [{
560
+ scope: {
561
+ name: S,
562
+ version: x
563
+ },
564
+ metrics: [...t.values()].map(Ke)
565
+ }]
566
+ };
567
+ });
568
+ return {
569
+ body: JSON.stringify({ resourceMetrics: t }),
570
+ contentType: l
461
571
  };
462
572
  }
463
573
  };
464
574
  //#endregion
465
575
  //#region src/transport/serializers/select.ts
466
- function Fe(e) {
467
- return e === "otlp" ? Pe : e === "ecs" ? Me : e;
576
+ function Je(e) {
577
+ return e === "otlp" ? Be : e === "ecs" ? Re : e;
578
+ }
579
+ function Y(e, t) {
580
+ return t.metricsEndpoint !== "" && e.records.length > 0 && e.records.every((e) => ve(e, "log.type") === "metric") ? "metrics" : "logs";
581
+ }
582
+ function X(e, t) {
583
+ return e === "metrics" ? t.metricsEndpoint : t.endpoint;
468
584
  }
469
- function Y(e, t, n, r) {
585
+ function Z(e, t, n, r) {
470
586
  try {
471
- return Fe(e).serialize(t.records);
587
+ return (Y(t, e) === "metrics" ? qe : Je(e.serializer)).serialize(t.records);
472
588
  } catch (e) {
473
589
  n.report("transport.serialize_failed", r, { batchId: t.id }, e);
474
590
  return;
@@ -476,49 +592,53 @@ function Y(e, t, n, r) {
476
592
  }
477
593
  //#endregion
478
594
  //#region src/transport/status-transport.ts
479
- var X = class {
595
+ var Ye = class {
480
596
  config;
481
597
  diagnostics;
482
598
  onSampling;
483
599
  onLoss;
484
- throttledUntil = 0;
600
+ throttledUntil = {
601
+ logs: 0,
602
+ metrics: 0
603
+ };
485
604
  constructor(e, t, n = () => void 0, r = () => void 0) {
486
605
  this.config = e, this.diagnostics = t, this.onSampling = n, this.onLoss = r;
487
606
  }
488
- throttledForMs() {
489
- return Math.max(0, this.throttledUntil - Date.now());
607
+ throttledForMs(e) {
608
+ return Math.max(0, this.throttledUntil[Y(e, this.config)] - Date.now());
490
609
  }
491
610
  serialize(e) {
492
- let t = Y(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
611
+ let t = Z(this.config, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
493
612
  return t || this.onLoss("unserializable", e.records, [e.id]), t;
494
613
  }
495
- accept(e) {
496
- this.throttledUntil = 0, this.config.sampling.remote && e != null && this.onSampling(e);
614
+ accept(e, t) {
615
+ this.throttledUntil[e] = 0, this.config.sampling.remote && t != null && this.onSampling(t);
497
616
  }
498
- reject(e, t, n) {
499
- let r = String(e);
617
+ reject(e, t, n, r) {
618
+ let i = String(e);
500
619
  if (e === 401 || e === 403) {
501
- let t = n.advice === void 0 ? "" : ` ${n.advice}`;
502
- return this.diagnostics.report("transport.rejected_credentials", `The server returned ${r}.${t}`, {
620
+ let t = r.advice === void 0 ? "" : ` ${r.advice}`;
621
+ return this.diagnostics.report("transport.rejected_credentials", `The server returned ${i}.${t}`, {
503
622
  status: e,
504
- endpoint: this.config.endpoint
505
- }), new U("permanent", `The server rejected the batch with ${r}.`, e);
623
+ endpoint: X(n, this.config)
624
+ }), new B("permanent", `The server rejected the batch with ${i}.`, e);
506
625
  }
507
- if (e === 413) return new U("too_large", "The payload is too large.", e, void 0, n.maxBytes);
626
+ if (e === 413) return new B("too_large", "The payload is too large.", e, void 0, r.maxBytes);
508
627
  if (e === 429 || e === 503) {
509
- let t = e === 429, r = n.retryAfterMs === void 0 ? void 0 : Math.min(n.retryAfterMs, o);
510
- return this.throttledUntil = Date.now() + (r ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new U("throttled", t ? "The server throttles the requests." : "The service is not available.", e, r);
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);
511
630
  }
512
- return e === 408 || e >= 500 ? new U("transient", `The server returned the error ${r}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${r}. The library dropped it.`, {
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.`, {
513
632
  batchId: t,
514
633
  status: e
515
- }), new U("permanent", `The server rejected the batch with ${r}.`, e));
634
+ }), new B("permanent", `The server rejected the batch with ${i}.`, e));
516
635
  }
517
636
  };
518
637
  //#endregion
519
638
  //#region src/transport/custom-transport.ts
520
- function Z(e, t) {
639
+ function Xe(e, t, n) {
521
640
  return {
641
+ kind: n,
522
642
  body: t.body,
523
643
  contentType: t.contentType,
524
644
  batchId: e.id,
@@ -526,38 +646,39 @@ function Z(e, t) {
526
646
  records: e.records
527
647
  };
528
648
  }
529
- function Ie(e) {
649
+ function Ze(e) {
530
650
  if (typeof e != "object" || !e) return !1;
531
651
  let t = Reflect.get(e, "status");
532
652
  return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
533
653
  }
534
- function Q(e) {
654
+ function Qe(e) {
535
655
  return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
536
656
  }
537
- var Le = class extends X {
657
+ var $e = class extends Ye {
538
658
  async send(e) {
539
- let { transport: n } = this.config;
540
- if (!n || e.records.length === 0) return;
541
- let r = this.serialize(e);
542
- if (!r) return;
543
- let i = Z(e, r), a;
659
+ let { transport: t } = this.config;
660
+ if (!t || e.records.length === 0) return;
661
+ let n = this.serialize(e);
662
+ if (!n) return;
663
+ let r = Y(e, this.config), i = Xe(e, n, r), a;
544
664
  try {
545
- a = await O(D(() => me(() => n(i))), t);
665
+ a = await k(ye(() => O(() => me(() => t(i)))), p);
546
666
  } catch (e) {
547
- let t = e instanceof A ? e : void 0;
548
- throw new U(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, 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);
549
669
  }
550
- if (!Ie(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 U("transient", "The custom transport returned no valid status.");
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.");
551
671
  let { status: o } = a;
552
- if (o >= 200 && o < 300) this.accept(a.sampling);
553
- else throw this.reject(o, e.id, {
554
- retryAfterMs: Q(a.retryAfterMs),
555
- maxBytes: Q(a.maxBytes)
672
+ if (o >= 200 && o < 300) this.accept(r, a.sampling);
673
+ else throw this.reject(o, e.id, r, {
674
+ retryAfterMs: Qe(a.retryAfterMs),
675
+ maxBytes: Qe(a.maxBytes)
556
676
  });
557
677
  }
558
- }, Re = class {
678
+ }, et = class {
559
679
  deps;
560
680
  installed = !1;
681
+ keepaliveBytes = 0;
561
682
  onVisibility = () => {
562
683
  document.visibilityState === "hidden" && this.flush("hidden");
563
684
  };
@@ -590,8 +711,10 @@ var Le = class extends X {
590
711
  });
591
712
  }
592
713
  flush(e) {
593
- let { config: t, diagnostics: r } = this.deps;
594
- if (e === "hidden") {
714
+ let { config: t, diagnostics: n } = this.deps;
715
+ if (n.guard("pipeline.crashed", "The metric points before the exit flush failed.", () => {
716
+ this.deps.beforeExit?.();
717
+ }), e === "hidden") {
595
718
  this.flushAlive();
596
719
  return;
597
720
  }
@@ -599,31 +722,39 @@ var Le = class extends X {
599
722
  this.flushCustom(e, t.transportOnExit);
600
723
  return;
601
724
  }
602
- let i = this.endpointUrl();
603
- if (i === null) return;
604
- let a = this.deps.drainForExit();
605
- if (!a || a.records.length === 0) return;
606
- let o = this.serialize(a, e);
725
+ let r = this.endpointUrl();
726
+ if (r !== null) {
727
+ 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));
731
+ }
732
+ }
733
+ }
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);
607
738
  if (!o) return;
608
- if (T(o.body) > 6e4) {
609
- R(a, r, this.deps.onLoss);
739
+ if (E(o.body) > 6e4) {
740
+ F(e, a, this.deps.onLoss);
610
741
  return;
611
742
  }
612
- i.searchParams.set(n, a.id), i.searchParams.set(w, e);
613
- let s = i.toString(), c = this.deps.exitHeaders();
743
+ n.searchParams.set(r, e.id), n.searchParams.set(d, t);
744
+ let s = n.toString(), c = this.deps.exitHeaders();
614
745
  if (c) {
615
- this.keepaliveFetch(s, a, o.body, e, () => {
616
- let e = new Headers(c);
617
- return e.set(g, o.contentType), e.set(h, a.id), e;
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;
618
749
  });
619
750
  return;
620
751
  }
621
- if (t.headers) {
622
- R(a, r, this.deps.onLoss);
752
+ if (i.headers) {
753
+ F(e, a, this.deps.onLoss);
623
754
  return;
624
755
  }
625
- let u = this.beacon(s, o.body);
626
- u !== "sent" && (u === "refused" ? R(a, r, this.deps.onLoss) : this.keepaliveFetch(s, a, o.body, e, () => new Headers({ [g]: l })));
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 })));
627
758
  }
628
759
  flushAlive() {
629
760
  let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
@@ -634,13 +765,16 @@ var Le = class extends X {
634
765
  });
635
766
  }
636
767
  flushCustom(e, t) {
637
- let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
638
- if (!r || r.records.length === 0) return;
639
- let i = this.serialize(r, e);
640
- i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => D(() => t(Z(r, i)))) !== !0) && R(r, n, this.deps.onLoss);
768
+ let { config: n, diagnostics: r } = this.deps;
769
+ for (let i of this.deps.drainForExit()) {
770
+ let a = this.serialize(i, e);
771
+ 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);
774
+ }
641
775
  }
642
776
  serialize(e, t) {
643
- let n = Y(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
777
+ let n = Z(this.deps.config, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
644
778
  return n || this.deps.onLoss?.("unserializable", e.records, [e.id]), n;
645
779
  }
646
780
  endpointUrl() {
@@ -655,9 +789,9 @@ var Le = class extends X {
655
789
  }
656
790
  keepaliveFetch(e, t, n, r, i) {
657
791
  let { config: a, diagnostics: o } = this.deps, s = () => {
658
- R(t, o, this.deps.onLoss);
659
- };
660
- o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
792
+ F(t, o, this.deps.onLoss);
793
+ }, c = E(n);
794
+ this.keepaliveBytes + c > 6e4 ? s() : (this.keepaliveBytes += c, o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
661
795
  method: "POST",
662
796
  body: n,
663
797
  headers: i(),
@@ -665,80 +799,80 @@ var Le = class extends X {
665
799
  keepalive: !0
666
800
  }).catch((e) => {
667
801
  o.report("transport.http_error", "The exit flush failed.", { reason: r }, e), s();
668
- }), !0)) !== !0 && s();
802
+ }), !0)) !== !0 && s());
669
803
  }
670
804
  };
671
805
  //#endregion
672
806
  //#region src/transport/compression.ts
673
- async function ze(e) {
807
+ async function tt(e) {
674
808
  let t = globalThis.CompressionStream;
675
809
  if (t === void 0) return null;
676
- let n = new Blob([e]).stream().pipeThrough(new t(i)), r = await new Response(n).arrayBuffer();
810
+ let n = new Blob([e]).stream().pipeThrough(new t(h)), r = await new Response(n).arrayBuffer();
677
811
  return new Uint8Array(r);
678
812
  }
679
813
  //#endregion
680
814
  //#region src/transport/http-transport.ts
681
- var Be = "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.", Ve = class extends X {
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 {
682
816
  cachedHeaders;
683
817
  async send(e, t) {
684
- let { endpoint: n } = this.config;
685
- n && e.records.length !== 0 && await this.post(e, n, t);
818
+ 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);
686
820
  }
687
821
  lastHeaders() {
688
822
  let { headers: e } = this.config;
689
823
  if (!e) return;
690
824
  if (typeof e != "function") return e;
691
825
  let t = this.cachedHeaders;
692
- return t?.source === e && t.endpoint === this.config.endpoint ? t.headers : void 0;
693
- }
694
- async post(t, n, r) {
695
- let i = this.serialize(t);
696
- if (!i) return;
697
- let a = await this.attempt(t, n, i, r);
698
- if (this.rejectsCredentials(a.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, a = await this.attempt(t, n, i, r)), a.ok) {
699
- this.accept(a.headers.get(e));
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));
700
834
  return;
701
835
  }
702
- let o = a.status, s = Oe(a.headers.get(d)), c = o === 413 ? await this.readMaxBytes(a) : void 0;
703
- throw this.reject(o, t.id, {
704
- retryAfterMs: s,
705
- maxBytes: c,
706
- advice: Be
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
707
841
  });
708
842
  }
709
843
  rejectsCredentials(e) {
710
844
  return e === 401 || e === 403;
711
845
  }
712
- async attempt(e, n, r, o) {
713
- let s = Date.now() + t, c = new Headers(await this.before(this.resolveHeaders(n), s));
714
- c.set(g, r.contentType), c.set(h, e.id), c.set(a, String(e.attempts));
715
- let l = await this.before(this.encodeBody(r.body), s);
716
- typeof l != "string" && c.set(ee, i);
717
- let u = this.keepalive(l);
718
- return u && o?.(), this.dispatch(n, c, l, s, u);
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);
719
853
  }
720
- async before(e, t) {
854
+ async before(e, t, n) {
721
855
  try {
722
- return await O(e, Math.max(0, t - Date.now()));
856
+ return await k(e, Math.max(0, t - Date.now()));
723
857
  } catch {
724
- throw this.timeout();
858
+ throw this.timeout(n);
725
859
  }
726
860
  }
727
- timeout() {
728
- let e = `The request took longer than ${String(t)} ms.`;
729
- return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new U("timeout", e);
861
+ timeout(e) {
862
+ let t = `The request took longer than ${String(p)} ms.`;
863
+ return this.diagnostics.report("transport.timeout", t, { endpoint: e }), new B("timeout", t);
730
864
  }
731
865
  async encodeBody(e) {
732
866
  let { config: t } = this;
733
- return t.compression !== "gzip" || T(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => ze(e)) ?? e;
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;
734
868
  }
735
869
  async dispatch(e, t, n, r, i) {
736
870
  let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
737
871
  o.abort();
738
872
  }, Math.max(0, r - Date.now()));
739
- k(s);
873
+ A(s);
740
874
  try {
741
- return await D(() => fetch(e, {
875
+ return await O(() => fetch(e, {
742
876
  method: "POST",
743
877
  headers: t,
744
878
  body: n,
@@ -748,15 +882,15 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
748
882
  keepalive: i
749
883
  }));
750
884
  } catch {
751
- if (o.signal.aborted) throw this.timeout();
752
- let e = globalThis.navigator?.onLine;
753
- throw new U(e === !1 ? "offline" : "transient", "A network error occurred.");
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.");
754
888
  } finally {
755
889
  clearTimeout(s);
756
890
  }
757
891
  }
758
892
  keepalive(e) {
759
- let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? T(e) : e.byteLength;
893
+ let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? E(e) : e.byteLength;
760
894
  return t && n <= 6e4;
761
895
  }
762
896
  async readMaxBytes(e) {
@@ -765,21 +899,23 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
765
899
  return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
766
900
  });
767
901
  }
768
- async resolveHeaders(e) {
769
- let { headers: t } = this.config;
770
- if (!t) return {};
771
- if (typeof t != "function") return t;
772
- let n = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(t()));
773
- return n && (this.cachedHeaders = {
774
- source: t,
775
- endpoint: e,
776
- headers: n
777
- }), n ?? {};
778
- }
779
- }, He = class {
902
+ async resolveHeaders() {
903
+ let { headers: e } = this.config;
904
+ if (!e) return {};
905
+ 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 = {
908
+ source: e,
909
+ endpoint: t,
910
+ metricsEndpoint: n,
911
+ headers: r
912
+ }), r ?? {};
913
+ }
914
+ }, it = class {
780
915
  storage;
781
916
  transport;
782
917
  diagnostics;
918
+ config;
783
919
  batchesPerDrain;
784
920
  onLoss;
785
921
  timer = null;
@@ -791,13 +927,13 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
791
927
  this.attempt = 0, this.schedule(0);
792
928
  };
793
929
  constructor(e, t, n, r, i = 20, a = () => void 0) {
794
- this.storage = e, this.transport = t, this.diagnostics = n, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = N(r.retention).maxAttempts;
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;
795
931
  }
796
932
  start() {
797
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(r);
933
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(v);
798
934
  }
799
935
  nudge() {
800
- this.draining || this.schedule(m);
936
+ this.draining || this.schedule(s);
801
937
  }
802
938
  async storeFailed(e, t) {
803
939
  let n = this.toStorable(e, t);
@@ -813,23 +949,23 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
813
949
  let t = setTimeout(() => {
814
950
  this.drain();
815
951
  }, e);
816
- this.timer = t, k(t);
952
+ this.timer = t, A(t);
817
953
  }
818
954
  bounded(e) {
819
- return O(e, S);
955
+ return k(e, C);
820
956
  }
821
957
  clearTimer() {
822
958
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
823
959
  }
824
960
  backoffMs() {
825
- let e = Math.min(m * 2 ** this.attempt, o);
961
+ let e = Math.min(s * 2 ** this.attempt, _);
826
962
  return Math.random() * e;
827
963
  }
828
964
  async drain() {
829
965
  if (!this.draining) {
830
966
  this.draining = !0;
831
967
  try {
832
- await P("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(r);
968
+ await M("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(v);
833
969
  } finally {
834
970
  this.draining = !1;
835
971
  }
@@ -837,11 +973,19 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
837
973
  }
838
974
  async drainLocked() {
839
975
  try {
840
- if (globalThis.navigator?.onLine === !1) return this.schedule(r), !0;
976
+ if (globalThis.navigator?.onLine === !1) return this.schedule(v), !0;
841
977
  let e = await this.bounded(this.storage.take(this.batchesPerDrain));
842
- if (e.length === 0) return this.schedule(r), !0;
843
- for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
844
- return this.schedule(e.length === this.batchesPerDrain ? 0 : r), !0;
978
+ if (e.length === 0) return this.schedule(v), !0;
979
+ let t = /* @__PURE__ */ new Set(), n = 0;
980
+ for (let r of e) {
981
+ 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);
985
+ if (i === "stop") return !0;
986
+ i !== "next" && (t.add(e), n = Math.max(n, i));
987
+ }
988
+ return t.size > 0 ? this.schedule(n) : this.schedule(e.length === this.batchesPerDrain ? 0 : v), !0;
845
989
  } catch (e) {
846
990
  return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
847
991
  }
@@ -850,12 +994,12 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
850
994
  if (e.attempts >= this.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
851
995
  batchId: e.id,
852
996
  records: e.records.length
853
- }), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), !0;
997
+ }), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), "next";
854
998
  try {
855
- return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
999
+ return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, "next";
856
1000
  } catch (t) {
857
- let n = t instanceof U ? t : void 0;
858
- return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(r), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
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());
859
1003
  }
860
1004
  }
861
1005
  async replaceStored(e, t) {
@@ -864,7 +1008,7 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
864
1008
  for (let e of n) await this.bounded(this.storage.save(e));
865
1009
  }
866
1010
  toStorable(e, t) {
867
- let n = t instanceof U ? t : void 0;
1011
+ let n = t instanceof B ? t : void 0;
868
1012
  if (n?.kind === "permanent") return this.onLoss("rejected", e.records, [e.id]), [];
869
1013
  if (n?.kind !== "too_large") return [e];
870
1014
  let r = ge(e, this.diagnostics);
@@ -880,8 +1024,8 @@ var Be = "In a cross-origin iframe, the session cookie is a third-party cookie.
880
1024
  };
881
1025
  //#endregion
882
1026
  //#region src/core/pipeline.ts
883
- function Ue(e) {
884
- return e.attributes[y] === oe;
1027
+ function Q(e) {
1028
+ return e.attributes[oe] === le;
885
1029
  }
886
1030
  var $ = class {
887
1031
  options;
@@ -907,12 +1051,12 @@ var $ = class {
907
1051
  let e = setTimeout(() => {
908
1052
  this.timer = null, this.onFlush(this);
909
1053
  }, this.options.flushIntervalMs);
910
- this.timer = e, k(e);
1054
+ this.timer = e, A(e);
911
1055
  }
912
1056
  clearTimer() {
913
1057
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
914
1058
  }
915
- }, We = class {
1059
+ }, at = class {
916
1060
  transport;
917
1061
  storage;
918
1062
  retry;
@@ -938,19 +1082,14 @@ var $ = class {
938
1082
  push(e) {
939
1083
  this.stopped || (e.observedTimeUnixNano = fe(), this.route(e));
940
1084
  }
941
- drainPending() {
942
- return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
943
- }
944
1085
  drainForExit() {
945
1086
  let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
946
- return this.unconfirmed.clear(), this.toBatch([
947
- ...e,
948
- ...this.streams.metrics.take(),
949
- ...this.streams.logs.take()
950
- ]);
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);
951
1090
  }
952
1091
  async flushPending() {
953
- this.enqueue(this.stopped ? null : this.drainPending()), await Promise.all([...this.open].map((e) => e.done));
1092
+ this.stopped || (this.claim(this.streams.metrics), this.claim(this.streams.logs)), await Promise.all([...this.open].map((e) => e.done));
954
1093
  }
955
1094
  destroy() {
956
1095
  this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
@@ -967,7 +1106,7 @@ var $ = class {
967
1106
  }
968
1107
  route(e) {
969
1108
  try {
970
- let t = Ue(e) ? this.streams.metrics : this.streams.logs;
1109
+ let t = Q(e) ? this.streams.metrics : this.streams.logs;
971
1110
  if (!this.ceiling.allow(e)) {
972
1111
  this.diagnostics.count("record.dropped_by_ceiling");
973
1112
  return;
@@ -1012,7 +1151,7 @@ var $ = class {
1012
1151
  }
1013
1152
  async dispatch(e) {
1014
1153
  try {
1015
- let t = this.transport.throttledForMs();
1154
+ let t = this.transport.throttledForMs(e);
1016
1155
  if (t > 0) {
1017
1156
  await this.store(e), this.diagnostics.report("transport.throttled", "The server throttles requests. The pipeline stored the batch and did not send it.", {
1018
1157
  batchId: e.id,
@@ -1045,10 +1184,10 @@ var $ = class {
1045
1184
  }
1046
1185
  async store(e) {
1047
1186
  await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
1048
- await O(this.storage.save(e), S), this.retry.nudge();
1187
+ await k(this.storage.save(e), C), this.retry.nudge();
1049
1188
  });
1050
1189
  }
1051
- }, Ge = class e {
1190
+ }, ot = class e {
1052
1191
  storage;
1053
1192
  retry;
1054
1193
  pipeline;
@@ -1058,10 +1197,10 @@ var $ = class {
1058
1197
  this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
1059
1198
  }
1060
1199
  static async create(t) {
1061
- let { config: n, diagnostics: r } = t, i = await De(n.storage, le, N(n.retention), r, t.onGap), a = (e) => {
1062
- let i = j(e, r);
1063
- i && M(t.remote, n, i);
1064
- }, { onLoss: o } = t, s = n.transport ? void 0 : new Ve(n, r, a, o), c = s ?? new Le(n, r, a, o), l = new He(i, c, r, n, 20, o), { batching: u } = n, d = new We(c, i, l, r, {
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, {
1065
1204
  logs: {
1066
1205
  flushIntervalMs: u.logFlushIntervalMs,
1067
1206
  batchSize: u.logBatchSize
@@ -1070,13 +1209,14 @@ var $ = class {
1070
1209
  flushIntervalMs: u.metricFlushIntervalMs,
1071
1210
  batchSize: u.metricBatchSize
1072
1211
  }
1073
- }), f = new Re({
1212
+ }), f = new et({
1074
1213
  config: n,
1075
1214
  diagnostics: r,
1076
1215
  drainForExit: () => d.drainForExit(),
1077
1216
  flushAlive: () => d.flushPending(),
1078
1217
  exitHeaders: () => s?.lastHeaders(),
1079
- onLoss: o
1218
+ onLoss: o,
1219
+ beforeExit: t.beforeExit
1080
1220
  }), p = !1;
1081
1221
  try {
1082
1222
  f.install(), l.start(), p = !0;
@@ -1099,11 +1239,11 @@ var $ = class {
1099
1239
  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();
1100
1240
  }
1101
1241
  async importEmergency() {
1102
- let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => ye(this.storage, this.diagnostics));
1242
+ let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => Te(this.storage, this.diagnostics));
1103
1243
  e !== void 0 && e > 0 && this.retry.nudge();
1104
1244
  }
1105
1245
  };
1106
1246
  //#endregion
1107
- export { Ge as Sender, z as n, B as t };
1247
+ export { ot as Sender, I as n, L as t };
1108
1248
 
1109
- //# sourceMappingURL=sender-BBY0IcUo.js.map
1249
+ //# sourceMappingURL=sender--0_VzPbN.js.map