@utk09/ui-observability 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +52 -45
  3. package/dist/bus/bus.d.ts +46 -12
  4. package/dist/bus/links.d.ts +6 -3
  5. package/dist/bus-CtJWf9QN.cjs +2 -0
  6. package/dist/bus-CtJWf9QN.cjs.map +1 -0
  7. package/dist/{bus-DPDrlUBY.js → bus-D8kH58tb.js} +128 -71
  8. package/dist/bus-D8kH58tb.js.map +1 -0
  9. package/dist/capture/interactions.d.ts +7 -6
  10. package/dist/capture/network.d.ts +23 -9
  11. package/dist/capture/types.d.ts +3 -3
  12. package/dist/console-BpHfWstv.cjs +2 -0
  13. package/dist/console-BpHfWstv.cjs.map +1 -0
  14. package/dist/console-DjLbryED.js +82 -0
  15. package/dist/console-DjLbryED.js.map +1 -0
  16. package/dist/constants-Br3b89Wg.cjs +2 -0
  17. package/dist/constants-Br3b89Wg.cjs.map +1 -0
  18. package/dist/constants-DM94FjVX.js +96 -0
  19. package/dist/constants-DM94FjVX.js.map +1 -0
  20. package/dist/constants.d.ts +20 -9
  21. package/dist/core/diagnostics.d.ts +2 -2
  22. package/dist/core/journey.d.ts +16 -4
  23. package/dist/core/logger.d.ts +6 -2
  24. package/dist/core/pipeline.d.ts +18 -9
  25. package/dist/core/record.d.ts +11 -6
  26. package/dist/core/remote-sampling.d.ts +1 -1
  27. package/dist/core/runtime.d.ts +43 -15
  28. package/dist/core/sender.d.ts +15 -10
  29. package/dist/deadline-B5DINjD5.js +111 -0
  30. package/dist/deadline-B5DINjD5.js.map +1 -0
  31. package/dist/deadline-Cbg2cbUw.cjs +2 -0
  32. package/dist/deadline-Cbg2cbUw.cjs.map +1 -0
  33. package/dist/error-like-Ywo5uRHo.js +19 -0
  34. package/dist/error-like-Ywo5uRHo.js.map +1 -0
  35. package/dist/error-like-gGRx2s36.cjs +2 -0
  36. package/dist/error-like-gGRx2s36.cjs.map +1 -0
  37. package/dist/errors-CpGRhhIf.cjs +3 -0
  38. package/dist/errors-CpGRhhIf.cjs.map +1 -0
  39. package/dist/{errors-Dnc-X4Ec.js → errors-DH4QJS0u.js} +39 -20
  40. package/dist/errors-DH4QJS0u.js.map +1 -0
  41. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  42. package/dist/global-scope-dp2jADRl.js.map +1 -1
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.d.ts +11 -4
  46. package/dist/index.js +561 -436
  47. package/dist/index.js.map +1 -1
  48. package/dist/indexeddb-storage-DNdf1fmL.cjs +2 -0
  49. package/dist/indexeddb-storage-DNdf1fmL.cjs.map +1 -0
  50. package/dist/{indexeddb-storage-uD4oaRMc.js → indexeddb-storage-n1qkFBGA.js} +17 -17
  51. package/dist/indexeddb-storage-n1qkFBGA.js.map +1 -0
  52. package/dist/interactions-31eHGwEQ.cjs +2 -0
  53. package/dist/interactions-31eHGwEQ.cjs.map +1 -0
  54. package/dist/{interactions-igKTAJvj.js → interactions-OU94MPXs.js} +22 -19
  55. package/dist/interactions-OU94MPXs.js.map +1 -0
  56. package/dist/journey-CE2EcwHW.cjs +2 -0
  57. package/dist/journey-CE2EcwHW.cjs.map +1 -0
  58. package/dist/journey-CeJ1QoT2.js +162 -0
  59. package/dist/journey-CeJ1QoT2.js.map +1 -0
  60. package/dist/{library-request-Br_T09Bn.cjs → library-request-C9uJFlbq.cjs} +2 -2
  61. package/dist/{library-request-Br_T09Bn.cjs.map → library-request-C9uJFlbq.cjs.map} +1 -1
  62. package/dist/{library-request-Dt0fXhcn.js → library-request-DvhuplAB.js} +2 -2
  63. package/dist/{library-request-Dt0fXhcn.js.map → library-request-DvhuplAB.js.map} +1 -1
  64. package/dist/{long-frames-DahhqM6u.cjs → long-frames-B8VdA_ny.cjs} +2 -2
  65. package/dist/{long-frames-DahhqM6u.cjs.map → long-frames-B8VdA_ny.cjs.map} +1 -1
  66. package/dist/{long-frames-6pnjWSSR.js → long-frames-C_7OutLs.js} +3 -3
  67. package/dist/{long-frames-6pnjWSSR.js.map → long-frames-C_7OutLs.js.map} +1 -1
  68. package/dist/models/batch.d.ts +1 -1
  69. package/dist/models/bus.d.ts +7 -4
  70. package/dist/models/config.d.ts +43 -12
  71. package/dist/models/log-record.d.ts +12 -6
  72. package/dist/network-BAV7ipyn.cjs +2 -0
  73. package/dist/network-BAV7ipyn.cjs.map +1 -0
  74. package/dist/network-D_lloS5t.js +174 -0
  75. package/dist/network-D_lloS5t.js.map +1 -0
  76. package/dist/patch-BX8KrPCT.cjs +2 -0
  77. package/dist/patch-BX8KrPCT.cjs.map +1 -0
  78. package/dist/patch-CCWfuEY7.js +9 -0
  79. package/dist/patch-CCWfuEY7.js.map +1 -0
  80. package/dist/{platform-D_XkVIF6.cjs → platform-D4wu1eIF.cjs} +2 -2
  81. package/dist/platform-D4wu1eIF.cjs.map +1 -0
  82. package/dist/platform-IHBZGqUe.js +48 -0
  83. package/dist/platform-IHBZGqUe.js.map +1 -0
  84. package/dist/{remote-rules-5UA23alm.js → remote-rules-Bt1XsdEQ.js} +14 -14
  85. package/dist/remote-rules-Bt1XsdEQ.js.map +1 -0
  86. package/dist/{remote-rules-rJJZKVG8.cjs → remote-rules-kuDf5gbe.cjs} +2 -2
  87. package/dist/remote-rules-kuDf5gbe.cjs.map +1 -0
  88. package/dist/sampling-BI15ds9D.cjs +2 -0
  89. package/dist/sampling-BI15ds9D.cjs.map +1 -0
  90. package/dist/sampling-o0VY1mqQ.js +63 -0
  91. package/dist/sampling-o0VY1mqQ.js.map +1 -0
  92. package/dist/sanitize-B9UheVKc.js +123 -0
  93. package/dist/sanitize-B9UheVKc.js.map +1 -0
  94. package/dist/sanitize-DSIP7amZ.cjs +2 -0
  95. package/dist/sanitize-DSIP7amZ.cjs.map +1 -0
  96. package/dist/{sender-G6v4Uqi4.js → sender-BnNj9bOX.js} +234 -176
  97. package/dist/sender-BnNj9bOX.js.map +1 -0
  98. package/dist/sender-D0OsyB1c.cjs +3 -0
  99. package/dist/sender-D0OsyB1c.cjs.map +1 -0
  100. package/dist/storage/emergency-queue.d.ts +1 -1
  101. package/dist/storage/factory.d.ts +1 -1
  102. package/dist/storage/idb-driver.d.ts +1 -1
  103. package/dist/storage/local-storage.d.ts +3 -3
  104. package/dist/storage/memory-storage.d.ts +3 -3
  105. package/dist/{storm-DJkEZP_8.js → storm-BTw0J6eE.js} +2 -2
  106. package/dist/{storm-DJkEZP_8.js.map → storm-BTw0J6eE.js.map} +1 -1
  107. package/dist/{storm-BtzgLOCX.cjs → storm-Y-yuBhvv.cjs} +2 -2
  108. package/dist/{storm-BtzgLOCX.cjs.map → storm-Y-yuBhvv.cjs.map} +1 -1
  109. package/dist/transport/compression.d.ts +1 -1
  110. package/dist/transport/exit-flush.d.ts +21 -17
  111. package/dist/transport/http-transport.d.ts +61 -7
  112. package/dist/transport/retry-engine.d.ts +5 -5
  113. package/dist/transport/status-transport.d.ts +4 -2
  114. package/dist/utils/console.d.ts +1 -1
  115. package/dist/utils/error-like.d.ts +25 -0
  116. package/dist/utils/global-scope.d.ts +1 -1
  117. package/dist/utils/identity.d.ts +1 -1
  118. package/dist/utils/library-console.d.ts +1 -1
  119. package/dist/utils/library-request.d.ts +1 -1
  120. package/dist/utils/patch.d.ts +9 -0
  121. package/dist/utils/platform.d.ts +3 -3
  122. package/dist/utils/sequence.d.ts +0 -5
  123. package/dist/utils/timer.d.ts +1 -1
  124. package/dist/utils/tracing.d.ts +3 -3
  125. package/dist/utils/unref.d.ts +2 -2
  126. package/dist/{web-vitals-DHZ0yA_H.js → web-vitals-Bflr5jSA.js} +4 -2
  127. package/dist/web-vitals-Bflr5jSA.js.map +1 -0
  128. package/dist/web-vitals-DFuoTQbZ.cjs +2 -0
  129. package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -0
  130. package/package.json +2 -2
  131. package/dist/bus-CUXRY0JR.cjs +0 -2
  132. package/dist/bus-CUXRY0JR.cjs.map +0 -1
  133. package/dist/bus-DPDrlUBY.js.map +0 -1
  134. package/dist/console-CNljJict.js +0 -81
  135. package/dist/console-CNljJict.js.map +0 -1
  136. package/dist/console-PKzc-FmR.cjs +0 -2
  137. package/dist/console-PKzc-FmR.cjs.map +0 -1
  138. package/dist/constants-B28fDv2F.cjs +0 -2
  139. package/dist/constants-B28fDv2F.cjs.map +0 -1
  140. package/dist/constants-Bu49bm39.js +0 -93
  141. package/dist/constants-Bu49bm39.js.map +0 -1
  142. package/dist/errors-C78ZTjet.cjs +0 -3
  143. package/dist/errors-C78ZTjet.cjs.map +0 -1
  144. package/dist/errors-Dnc-X4Ec.js.map +0 -1
  145. package/dist/indexeddb-storage-D0p3iMD0.cjs +0 -2
  146. package/dist/indexeddb-storage-D0p3iMD0.cjs.map +0 -1
  147. package/dist/indexeddb-storage-uD4oaRMc.js.map +0 -1
  148. package/dist/interactions-CsE2y_fQ.cjs +0 -2
  149. package/dist/interactions-CsE2y_fQ.cjs.map +0 -1
  150. package/dist/interactions-igKTAJvj.js.map +0 -1
  151. package/dist/network-CZ0aFUsy.cjs +0 -2
  152. package/dist/network-CZ0aFUsy.cjs.map +0 -1
  153. package/dist/network-aSNbwpue.js +0 -112
  154. package/dist/network-aSNbwpue.js.map +0 -1
  155. package/dist/platform-BwbMRwHm.js +0 -48
  156. package/dist/platform-BwbMRwHm.js.map +0 -1
  157. package/dist/platform-D_XkVIF6.cjs.map +0 -1
  158. package/dist/remote-rules-5UA23alm.js.map +0 -1
  159. package/dist/remote-rules-rJJZKVG8.cjs.map +0 -1
  160. package/dist/sampling-E4x92Nn2.cjs +0 -2
  161. package/dist/sampling-E4x92Nn2.cjs.map +0 -1
  162. package/dist/sampling-J1eahbfT.js +0 -160
  163. package/dist/sampling-J1eahbfT.js.map +0 -1
  164. package/dist/sanitize-BMhh8ghJ.cjs +0 -2
  165. package/dist/sanitize-BMhh8ghJ.cjs.map +0 -1
  166. package/dist/sanitize-UJ-4Lb0n.js +0 -114
  167. package/dist/sanitize-UJ-4Lb0n.js.map +0 -1
  168. package/dist/sender-B6ufz26f.cjs +0 -3
  169. package/dist/sender-B6ufz26f.cjs.map +0 -1
  170. package/dist/sender-G6v4Uqi4.js.map +0 -1
  171. package/dist/unref-16maCyKA.js +0 -8
  172. package/dist/unref-16maCyKA.js.map +0 -1
  173. package/dist/unref-CU9Nyz_9.cjs +0 -2
  174. package/dist/unref-CU9Nyz_9.cjs.map +0 -1
  175. package/dist/web-vitals-B2FYsEAU.cjs +0 -2
  176. package/dist/web-vitals-B2FYsEAU.cjs.map +0 -1
  177. package/dist/web-vitals-DHZ0yA_H.js.map +0 -1
@@ -1,9 +1,9 @@
1
- import { $t as e, A as t, At as n, Dt as r, Ft as i, G as a, Ht as o, I as s, J as c, K as l, O as u, Ot as d, Pt as f, Qt as ee, R as p, Ut as te, Vt as m, X as ne, Y as re, an as h, bt as g, en as _, ft as v, gt as y, ht as b, in as x, k as ie, l as ae, ln as oe, lt as se, on as S, pt as ce, q as le, qt as ue, rn as de, un as fe, ut as pe, v as C, xt as me, z as w } from "./constants-Bu49bm39.js";
2
- import { a as T, i as he, l as E, m as D, t as O } from "./sampling-J1eahbfT.js";
3
- import { o as k, t as A } from "./sanitize-UJ-4Lb0n.js";
4
- import { t as j } from "./unref-16maCyKA.js";
5
- import { n as M, t as N } from "./remote-rules-5UA23alm.js";
6
- import { n as P } from "./library-request-Dt0fXhcn.js";
1
+ import { A as e, At as t, B as n, Ct as r, Gt as i, J as a, Kt as o, Lt as s, M as c, Nt as l, Q as u, R as d, Rt as f, V as p, Wt as m, X as h, Xt as ee, Y as te, Z as ne, b as g, cn as re, d as _, fn as v, ft as y, gt as b, ht as x, j as S, jt as C, ln as w, nn as T, on as ie, pn as ae, pt as oe, q as se, rn as E, sn as ce, tn as le, vt as ue, wt as de, yt as fe } from "./constants-DM94FjVX.js";
2
+ import { o as pe, t as me } from "./sampling-o0VY1mqQ.js";
3
+ import { o as he, t as D } from "./sanitize-B9UheVKc.js";
4
+ import { n as O, r as k, s as A, t as j } from "./deadline-B5DINjD5.js";
5
+ import { n as M, t as N } from "./remote-rules-Bt1XsdEQ.js";
6
+ import { n as P } from "./library-request-DvhuplAB.js";
7
7
  //#region src/models/batch.ts
8
8
  function F(e) {
9
9
  if (typeof e != "object" || !e) return !1;
@@ -13,7 +13,7 @@ function F(e) {
13
13
  function I(e, t) {
14
14
  if (e.records.length < 2) return null;
15
15
  let n = Math.floor(e.records.length / 2), r = (n) => ({
16
- id: E(t),
16
+ id: A(t),
17
17
  records: n,
18
18
  createdAt: e.createdAt,
19
19
  attempts: e.attempts
@@ -41,34 +41,34 @@ function R(e, t) {
41
41
  //#region src/storage/emergency-queue.ts
42
42
  function ge(e) {
43
43
  let t = String(e.createdAt).padStart(14, "0");
44
- return `${p}${t}.${e.id}`;
44
+ return `${n}${t}.${e.id}`;
45
45
  }
46
46
  function _e(e, t) {
47
47
  let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
48
48
  return n === void 0 ? null : F(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
49
49
  }
50
- async function ve(t, n) {
50
+ async function ve(e, t) {
51
51
  let r = 0;
52
- for (let i of R(p, n)) {
53
- let a = n.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
52
+ for (let i of R(n, t)) {
53
+ let n = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
54
54
  let e = localStorage.getItem(i);
55
55
  return localStorage.removeItem(i), e;
56
56
  });
57
- if (!a) continue;
58
- let o = _e(a, n);
59
- if (o !== null) try {
60
- await T(t.save(o), e), r++;
57
+ if (!n) continue;
58
+ let a = _e(n, t);
59
+ if (a !== null) try {
60
+ await O(e.save(a), T), r++;
61
61
  } catch (e) {
62
- n.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
62
+ t.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
63
63
  }
64
64
  }
65
65
  return r;
66
66
  }
67
67
  function z(e, t) {
68
- let n = `writing the emergency queue, ${String(e.records.length)} records`;
69
- t.guard("storage.quota_exceeded", n, () => {
70
- let n = R(p, t);
71
- for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
68
+ let r = `writing the emergency queue, ${String(e.records.length)} records`;
69
+ t.guard("storage.quota_exceeded", r, () => {
70
+ let r = R(n, t);
71
+ for (let e of r.slice(0, Math.max(0, r.length - 20 + 1))) localStorage.removeItem(e);
72
72
  localStorage.setItem(ge(e), JSON.stringify(e));
73
73
  });
74
74
  }
@@ -79,17 +79,17 @@ async function ye(e, t) {
79
79
  //#region src/storage/local-storage.ts
80
80
  function be(e) {
81
81
  let t = String(e.createdAt).padStart(14, "0");
82
- return `${C}${t}.${e.id}`;
82
+ return `${g}${t}.${e.id}`;
83
83
  }
84
84
  function xe(e) {
85
- let t = C.length, n = Number(e.slice(t, t + 14));
85
+ let t = g.length, n = Number(e.slice(t, t + 14));
86
86
  return Number.isFinite(n) ? n : null;
87
87
  }
88
88
  var Se = class {
89
89
  limits;
90
90
  diagnostics;
91
91
  onGap;
92
- name = de;
92
+ name = ie;
93
93
  constructor(e, t, n) {
94
94
  this.limits = e, this.diagnostics = t, this.onGap = n;
95
95
  }
@@ -185,7 +185,7 @@ var Se = class {
185
185
  });
186
186
  }
187
187
  keys() {
188
- return R(C, this.diagnostics);
188
+ return R(g, this.diagnostics);
189
189
  }
190
190
  };
191
191
  //#endregion
@@ -196,7 +196,7 @@ function B(e) {
196
196
  var V = class {
197
197
  limits;
198
198
  onGap;
199
- name = x;
199
+ name = ce;
200
200
  batches = [];
201
201
  constructor(e, t) {
202
202
  this.limits = e, this.onGap = t;
@@ -239,7 +239,7 @@ var V = class {
239
239
  return this.batches = [], Promise.resolve();
240
240
  }
241
241
  }, Ce = {
242
- name: h,
242
+ name: re,
243
243
  save: () => Promise.resolve(),
244
244
  take: () => Promise.resolve([]),
245
245
  remove: () => Promise.resolve(),
@@ -257,7 +257,7 @@ function we(e) {
257
257
  return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
258
258
  }
259
259
  function Te(e) {
260
- return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(S, "1"), localStorage.removeItem(S), !0)) === !0;
260
+ return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(w, "1"), localStorage.removeItem(w), !0)) === !0;
261
261
  }
262
262
  async function Ee(e, t, n, r, i) {
263
263
  if (e === "none") return Ce;
@@ -265,7 +265,7 @@ async function Ee(e, t, n, r, i) {
265
265
  if (e === "indexeddb" || e === "auto") {
266
266
  if (we(r)) {
267
267
  let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
268
- let { IndexedDbStorage: e } = await import("./indexeddb-storage-uD4oaRMc.js"), a = new e(t, n, r, i);
268
+ let { IndexedDbStorage: e } = await import("./indexeddb-storage-n1qkFBGA.js"), a = new e(t, n, r, i);
269
269
  return await a.open(), a;
270
270
  });
271
271
  if (e) return e;
@@ -288,14 +288,14 @@ var H = class extends Error {
288
288
  function De(e) {
289
289
  if (!e) return;
290
290
  let t = Number(e);
291
- if (Number.isFinite(t)) return Math.max(0, t * ce);
291
+ if (Number.isFinite(t)) return Math.max(0, t * b);
292
292
  let n = Date.parse(e);
293
293
  return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
294
294
  }
295
295
  //#endregion
296
296
  //#region src/transport/serializers/ecs.ts
297
297
  function Oe(e) {
298
- return b.test(e) ? Number(BigInt(e) / y) : Date.now();
298
+ return ue.test(e) ? Number(BigInt(e) / fe) : Date.now();
299
299
  }
300
300
  function ke(e) {
301
301
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
@@ -327,15 +327,15 @@ var je = {
327
327
  return JSON.stringify({
328
328
  "@timestamp": new Date(t).toISOString(),
329
329
  message: e.body,
330
- log: { level: s[e.severityText] ?? e.severityText.toLowerCase() },
330
+ log: { level: d[e.severityText] ?? e.severityText.toLowerCase() },
331
331
  trace: { id: e.traceId },
332
332
  span: { id: e.spanId },
333
333
  service: {
334
- name: e.resource[f],
335
- version: e.resource[i],
336
- environment: e.resource[n]
334
+ name: e.resource[s],
335
+ version: e.resource[f],
336
+ environment: e.resource[l]
337
337
  },
338
- user_agent: { original: e.resource[d] },
338
+ user_agent: { original: e.resource[C] },
339
339
  url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
340
340
  labels: {
341
341
  ...W(e.resource),
@@ -343,14 +343,14 @@ var je = {
343
343
  }
344
344
  });
345
345
  }).join("\n")}\n`,
346
- contentType: ie
346
+ contentType: S
347
347
  };
348
348
  }
349
349
  };
350
350
  //#endregion
351
351
  //#region src/transport/serializers/otlp.ts
352
352
  function G(e) {
353
- return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(G).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
353
+ 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(G).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
354
354
  }
355
355
  function K(e) {
356
356
  let t = [];
@@ -371,22 +371,22 @@ function Me(e) {
371
371
  return q.set(e, n), n;
372
372
  }
373
373
  var Ne = {
374
- name: ue,
375
- serialize(e) {
376
- let t = /* @__PURE__ */ new Map();
377
- for (let n of e) {
378
- let e = Me(n.resource), r = t.get(e);
379
- r ? r.records.push(n) : t.set(e, {
380
- resource: n.resource,
381
- records: [n]
374
+ name: ee,
375
+ serialize(t) {
376
+ let n = /* @__PURE__ */ new Map();
377
+ for (let e of t) {
378
+ let t = Me(e.resource), r = n.get(t);
379
+ r ? r.records.push(e) : n.set(t, {
380
+ resource: e.resource,
381
+ records: [e]
382
382
  });
383
383
  }
384
- let n = [...t.values()].map((e) => ({
384
+ let r = [...n.values()].map((e) => ({
385
385
  resource: { attributes: K(e.resource) },
386
386
  scopeLogs: [{
387
387
  scope: {
388
- name: oe,
389
- version: fe
388
+ name: v,
389
+ version: ae
390
390
  },
391
391
  logRecords: e.records.map((e) => ({
392
392
  timeUnixNano: e.timeUnixNano,
@@ -402,8 +402,8 @@ var Ne = {
402
402
  }]
403
403
  }));
404
404
  return {
405
- body: JSON.stringify({ resourceLogs: n }),
406
- contentType: u
405
+ body: JSON.stringify({ resourceLogs: r }),
406
+ contentType: e
407
407
  };
408
408
  }
409
409
  };
@@ -450,8 +450,8 @@ var Y = class {
450
450
  }
451
451
  if (e === 413) return new H("too_large", "The payload is too large.", e, void 0, n.maxBytes);
452
452
  if (e === 429 || e === 503) {
453
- let t = e === 429;
454
- return this.throttledUntil = Date.now() + (n.retryAfterMs ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: n.retryAfterMs }), new H("throttled", t ? "The server throttles the requests." : "The service is not available.", e, n.retryAfterMs);
453
+ let t = e === 429, r = n.retryAfterMs === void 0 ? void 0 : Math.min(n.retryAfterMs, o);
454
+ return this.throttledUntil = Date.now() + (r ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new H("throttled", t ? "The server throttles the requests." : "The service is not available.", e, r);
455
455
  }
456
456
  return e === 408 || e >= 500 ? new H("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.`, {
457
457
  batchId: t,
@@ -480,15 +480,15 @@ function Z(e) {
480
480
  }
481
481
  var Ie = class extends Y {
482
482
  async send(e) {
483
- let { transport: t } = this.config;
484
- if (!t || e.records.length === 0) return;
485
- let n = this.serialize(e);
486
- if (!n) return;
487
- let i = X(e, n), a;
483
+ let { transport: n } = this.config;
484
+ if (!n || e.records.length === 0) return;
485
+ let r = this.serialize(e);
486
+ if (!r) return;
487
+ let i = X(e, r), a;
488
488
  try {
489
- a = await T(P(() => k(() => t(i))), r);
489
+ a = await O(P(() => he(() => n(i))), t);
490
490
  } catch (e) {
491
- let t = e instanceof he ? e : void 0;
491
+ let t = e instanceof j ? e : void 0;
492
492
  throw new H(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
493
493
  }
494
494
  if (!Fe(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 H("transient", "The custom transport returned no valid status.");
@@ -535,28 +535,50 @@ var Ie = class extends Y {
535
535
  }
536
536
  flush(e) {
537
537
  let { config: t, diagnostics: n } = this.deps;
538
+ if (e === "hidden") {
539
+ this.flushAlive();
540
+ return;
541
+ }
538
542
  if (t.transport) {
539
543
  this.flushCustom(e, t.transportOnExit);
540
544
  return;
541
545
  }
542
- let r = this.endpointUrl();
543
- if (r === null) return;
544
- let i = this.drain(e);
545
- if (!i || i.records.length === 0) return;
546
- let a = this.serialize(i, e);
547
- if (!a) return;
548
- if (A(a.body) > 6e4) {
549
- z(i, n);
546
+ let i = this.endpointUrl();
547
+ if (i === null) return;
548
+ let o = this.deps.drainForExit();
549
+ if (!o || o.records.length === 0) return;
550
+ let s = this.serialize(o, e);
551
+ if (!s) return;
552
+ if (D(s.body) > 6e4) {
553
+ z(o, n);
554
+ return;
555
+ }
556
+ i.searchParams.set(r, o.id), i.searchParams.set(de, e);
557
+ let l = i.toString(), u = this.deps.exitHeaders();
558
+ if (u) {
559
+ this.keepaliveFetch(l, s.body, e, () => {
560
+ let e = new Headers(u);
561
+ return e.set(h, s.contentType), e.set(a, o.id), e;
562
+ });
550
563
  return;
551
564
  }
552
- r.searchParams.set(g, i.id), r.searchParams.set(me, e);
553
- let o = r.toString(), s = this.beacon(o, a.body);
554
- s !== "sent" && (s === "refused" ? z(i, n) : this.keepaliveFetch(o, a.body, e));
565
+ if (t.headers) {
566
+ z(o, n);
567
+ return;
568
+ }
569
+ let d = this.beacon(l, s.body);
570
+ d !== "sent" && (d === "refused" ? z(o, n) : this.keepaliveFetch(l, s.body, e, () => new Headers({ [h]: c })));
571
+ }
572
+ flushAlive() {
573
+ let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
574
+ e.guard("pipeline.crashed", t, () => {
575
+ Promise.resolve(this.deps.flushAlive()).catch((n) => {
576
+ e.report("pipeline.crashed", t, void 0, n);
577
+ });
578
+ });
555
579
  }
556
580
  flushCustom(e, t) {
557
- let { diagnostics: n } = this.deps;
558
- if (e === "hidden" && !t) return;
559
- let r = this.drain(e);
581
+ let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
560
582
  if (!r || r.records.length === 0) return;
561
583
  let i = this.serialize(r, e);
562
584
  i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => P(() => t(X(r, i)))) !== !0) && z(r, n);
@@ -564,9 +586,6 @@ var Ie = class extends Y {
564
586
  serialize(e, t) {
565
587
  return J(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
566
588
  }
567
- drain(e) {
568
- return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
569
- }
570
589
  endpointUrl() {
571
590
  let { endpoint: e } = this.deps.config;
572
591
  return e ? this.deps.diagnostics.guard("config.invalid", `The exit flush cannot use the endpoint ${e}.`, () => new URL(e)) ?? null : null;
@@ -577,17 +596,17 @@ var Ie = class extends Y {
577
596
  return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
578
597
  }) ?? "unavailable";
579
598
  }
580
- keepaliveFetch(e, n, r) {
599
+ keepaliveFetch(e, t, n, r) {
581
600
  let { config: i, diagnostics: a } = this.deps;
582
- a.guard("transport.http_error", "The keepalive fetch fallback failed.", () => {
601
+ a.guard("transport.http_error", "The keepalive fetch failed.", () => {
583
602
  fetch(e, {
584
603
  method: "POST",
585
- body: n,
586
- headers: { [c]: t },
604
+ body: t,
605
+ headers: r(),
587
606
  credentials: i.credentials,
588
607
  keepalive: !0
589
608
  }).catch((e) => {
590
- a.report("transport.http_error", "The exit flush failed.", { reason: r }, e);
609
+ a.report("transport.http_error", "The exit flush failed.", { reason: n }, e);
591
610
  });
592
611
  });
593
612
  }
@@ -597,70 +616,108 @@ var Ie = class extends Y {
597
616
  async function Re(e) {
598
617
  let t = globalThis.CompressionStream;
599
618
  if (t === void 0) return null;
600
- let n = new Blob([e]).stream().pipeThrough(new t(w)), r = await new Response(n).arrayBuffer();
619
+ let n = new Blob([e]).stream().pipeThrough(new t(p)), r = await new Response(n).arrayBuffer();
601
620
  return new Uint8Array(r);
602
621
  }
603
622
  //#endregion
604
623
  //#region src/transport/http-transport.ts
605
624
  var Q = "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.", ze = class extends Y {
606
- async send(e) {
607
- let { endpoint: t } = this.config;
608
- t && e.records.length !== 0 && await this.post(e, t);
609
- }
610
- async post(e, t) {
611
- let n = this.serialize(e);
612
- if (!n) return;
613
- let r = new Headers(await this.resolveHeaders());
614
- r.set(c, n.contentType), r.set(l, e.id), r.set(a, String(e.attempts));
615
- let i = await this.encodeBody(n.body);
616
- typeof i != "string" && r.set(le, w);
617
- let o = await this.dispatch(t, r, i);
618
- if (o.ok) {
619
- this.accept(o.headers.get(ne));
625
+ cachedHeaders;
626
+ async send(e, t) {
627
+ let { endpoint: n } = this.config;
628
+ n && e.records.length !== 0 && await this.post(e, n, t);
629
+ }
630
+ lastHeaders() {
631
+ let { headers: e } = this.config;
632
+ if (!e) return;
633
+ if (typeof e != "function") return e;
634
+ let t = this.cachedHeaders;
635
+ return t?.source === e && t.endpoint === this.config.endpoint ? t.headers : void 0;
636
+ }
637
+ async post(e, t, n) {
638
+ let r = this.serialize(e);
639
+ if (!r) return;
640
+ let i = await this.attempt(e, t, r, n);
641
+ if (this.rejectsCredentials(i.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, i = await this.attempt(e, t, r, n)), i.ok) {
642
+ this.accept(i.headers.get(u));
620
643
  return;
621
644
  }
622
- let s = o.status, u = De(o.headers.get(re)), d = s === 413 ? await this.readMaxBytes(o) : void 0;
623
- throw this.reject(s, e.id, {
624
- retryAfterMs: u,
625
- maxBytes: d,
645
+ let a = i.status, o = De(i.headers.get(ne)), s = a === 413 ? await this.readMaxBytes(i) : void 0;
646
+ throw this.reject(a, e.id, {
647
+ retryAfterMs: o,
648
+ maxBytes: s,
626
649
  advice: Q
627
650
  });
628
651
  }
652
+ rejectsCredentials(e) {
653
+ return e === 401 || e === 403;
654
+ }
655
+ async attempt(e, n, r, i) {
656
+ let o = Date.now() + t, s = new Headers(await this.before(this.resolveHeaders(n), o));
657
+ s.set(h, r.contentType), s.set(a, e.id), s.set(se, String(e.attempts));
658
+ let c = await this.before(this.encodeBody(r.body), o);
659
+ typeof c != "string" && s.set(te, p);
660
+ let l = this.keepalive(c);
661
+ return l && i?.(), this.dispatch(n, s, c, o, l);
662
+ }
663
+ async before(e, t) {
664
+ try {
665
+ return await O(e, Math.max(0, t - Date.now()));
666
+ } catch {
667
+ throw this.timeout();
668
+ }
669
+ }
670
+ timeout() {
671
+ let e = `The request took longer than ${String(t)} ms.`;
672
+ return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new H("timeout", e);
673
+ }
629
674
  async encodeBody(e) {
630
675
  let { config: t } = this;
631
- return t.compression !== "gzip" || A(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Re(e)) ?? e;
676
+ return t.compression !== "gzip" || D(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Re(e)) ?? e;
632
677
  }
633
- async dispatch(e, t, n) {
634
- let { config: i } = this, a = new AbortController(), o = setTimeout(() => {
635
- a.abort();
636
- }, r);
637
- j(o);
678
+ async dispatch(e, t, n, r, i) {
679
+ let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
680
+ o.abort();
681
+ }, Math.max(0, r - Date.now()));
682
+ k(s);
638
683
  try {
639
684
  return await P(() => fetch(e, {
640
685
  method: "POST",
641
686
  headers: t,
642
687
  body: n,
643
- credentials: i.credentials,
644
- signal: a.signal,
645
- cache: "no-store"
688
+ credentials: a.credentials,
689
+ signal: o.signal,
690
+ cache: "no-store",
691
+ keepalive: i
646
692
  }));
647
693
  } catch {
648
- if (a.signal.aborted) throw new H("timeout", `The request took longer than ${String(r)} ms.`);
694
+ if (o.signal.aborted) throw this.timeout();
649
695
  let e = globalThis.navigator?.onLine;
650
696
  throw new H(e === !1 ? "offline" : "transient", "A network error occurred.");
651
697
  } finally {
652
- clearTimeout(o);
698
+ clearTimeout(s);
653
699
  }
654
700
  }
701
+ keepalive(e) {
702
+ let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? D(e) : e.byteLength;
703
+ return t && n <= 6e4;
704
+ }
655
705
  async readMaxBytes(e) {
656
706
  return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
657
707
  let t = JSON.parse(await e.text());
658
708
  return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
659
709
  });
660
710
  }
661
- async resolveHeaders() {
662
- let { headers: e } = this.config;
663
- return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e())) ?? {} : e : {};
711
+ async resolveHeaders(e) {
712
+ let { headers: t } = this.config;
713
+ if (!t) return {};
714
+ if (typeof t != "function") return t;
715
+ let n = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(t()));
716
+ return n && (this.cachedHeaders = {
717
+ source: t,
718
+ endpoint: e,
719
+ headers: n
720
+ }), n ?? {};
664
721
  }
665
722
  }, Be = class {
666
723
  storage;
@@ -679,7 +736,7 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
679
736
  this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
680
737
  }
681
738
  start() {
682
- this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(o);
739
+ this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(i);
683
740
  }
684
741
  nudge() {
685
742
  this.draining || this.schedule(m);
@@ -698,23 +755,23 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
698
755
  let t = setTimeout(() => {
699
756
  this.drain();
700
757
  }, e);
701
- this.timer = t, j(t);
758
+ this.timer = t, k(t);
702
759
  }
703
- bounded(t) {
704
- return T(t, e);
760
+ bounded(e) {
761
+ return O(e, T);
705
762
  }
706
763
  clearTimer() {
707
764
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
708
765
  }
709
766
  backoffMs() {
710
- let e = Math.min(m * 2 ** this.attempt, te);
767
+ let e = Math.min(m * 2 ** this.attempt, o);
711
768
  return Math.random() * e;
712
769
  }
713
770
  async drain() {
714
771
  if (!this.draining) {
715
772
  this.draining = !0;
716
773
  try {
717
- await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(o);
774
+ await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(i);
718
775
  } finally {
719
776
  this.draining = !1;
720
777
  }
@@ -722,17 +779,17 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
722
779
  }
723
780
  async drainLocked() {
724
781
  try {
725
- if (globalThis.navigator?.onLine === !1) return this.schedule(o), !0;
782
+ if (globalThis.navigator?.onLine === !1) return this.schedule(i), !0;
726
783
  let e = await this.bounded(this.storage.take(this.batchesPerDrain));
727
- if (e.length === 0) return this.schedule(o), !0;
784
+ if (e.length === 0) return this.schedule(i), !0;
728
785
  for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
729
- return this.schedule(e.length === this.batchesPerDrain ? 0 : o), !0;
786
+ return this.schedule(e.length === this.batchesPerDrain ? 0 : i), !0;
730
787
  } catch (e) {
731
788
  return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
732
789
  }
733
790
  }
734
791
  async deliver(e) {
735
- if (e.attempts >= _.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
792
+ if (e.attempts >= E.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
736
793
  batchId: e.id,
737
794
  records: e.records.length
738
795
  }), await this.bounded(this.storage.remove(e.id)), !0;
@@ -740,7 +797,7 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
740
797
  return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
741
798
  } catch (t) {
742
799
  let n = t instanceof H ? t : void 0;
743
- return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(o), !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);
800
+ return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(i), !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);
744
801
  }
745
802
  }
746
803
  async replaceStored(e, t) {
@@ -766,15 +823,15 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
766
823
  //#endregion
767
824
  //#region src/core/pipeline.ts
768
825
  function Ve(e) {
769
- return e.attributes[ae] === pe;
826
+ return e.attributes[_] === oe;
770
827
  }
771
828
  var He = {
772
829
  logs: {
773
- flushIntervalMs: se,
830
+ flushIntervalMs: y,
774
831
  batchSize: 100
775
832
  },
776
833
  metrics: {
777
- flushIntervalMs: v,
834
+ flushIntervalMs: x,
778
835
  batchSize: 500
779
836
  }
780
837
  }, $ = class {
@@ -801,7 +858,7 @@ var He = {
801
858
  let e = setTimeout(() => {
802
859
  this.timer = null, this.onFlush(this);
803
860
  }, this.options.flushIntervalMs);
804
- this.timer = e, j(e);
861
+ this.timer = e, k(e);
805
862
  }
806
863
  clearTimer() {
807
864
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
@@ -814,7 +871,8 @@ var He = {
814
871
  streams;
815
872
  unconfirmed = /* @__PURE__ */ new Map();
816
873
  queue = [];
817
- ceiling = new O();
874
+ open = /* @__PURE__ */ new Set();
875
+ ceiling = new me();
818
876
  inFlight = 0;
819
877
  pumpScheduled = !1;
820
878
  stopped = !1;
@@ -829,7 +887,7 @@ var He = {
829
887
  };
830
888
  }
831
889
  push(e) {
832
- this.stopped || (e.observedTimeUnixNano = D(), this.route(e));
890
+ this.stopped || (e.observedTimeUnixNano = pe(), this.route(e));
833
891
  }
834
892
  drainPending() {
835
893
  return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
@@ -842,12 +900,17 @@ var He = {
842
900
  ...this.streams.logs.take()
843
901
  ]);
844
902
  }
903
+ async flushPending() {
904
+ this.enqueue(this.stopped ? null : this.drainPending()), await Promise.all([...this.open].map((e) => e.done));
905
+ }
845
906
  destroy() {
846
907
  this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
908
+ for (let e of this.open) e.resolve();
909
+ this.open.clear();
847
910
  }
848
911
  toBatch(e) {
849
912
  return e.length === 0 ? null : {
850
- id: E(this.diagnostics),
913
+ id: A(this.diagnostics),
851
914
  records: e,
852
915
  createdAt: Date.now(),
853
916
  attempts: 0
@@ -866,16 +929,18 @@ var He = {
866
929
  }
867
930
  }
868
931
  claim(e) {
869
- let t = e.take(), n = {
870
- id: E(this.diagnostics),
871
- records: t,
872
- createdAt: Date.now(),
873
- attempts: 0
874
- };
875
- this.unconfirmed.set(n.id, n), this.enqueue(n);
932
+ this.enqueue(this.toBatch(e.take()));
876
933
  }
877
934
  enqueue(e) {
878
- this.queue.push(e), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
935
+ if (!e) return;
936
+ let t, n = {
937
+ batch: e,
938
+ done: new Promise((e) => {
939
+ t = e;
940
+ }),
941
+ resolve: t
942
+ };
943
+ this.unconfirmed.set(e.id, e), this.open.add(n), this.queue.push(n), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
879
944
  this.pumpScheduled = !1, this.pump();
880
945
  }));
881
946
  }
@@ -887,12 +952,13 @@ var He = {
887
952
  }
888
953
  }
889
954
  async run(e) {
955
+ let { batch: t } = e;
890
956
  try {
891
- await this.dispatch(e);
892
- } catch (t) {
893
- this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: e.id }, t);
957
+ await this.dispatch(t);
958
+ } catch (e) {
959
+ this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: t.id }, e);
894
960
  } finally {
895
- this.inFlight--, this.pump();
961
+ this.inFlight--, this.open.delete(e), e.resolve(), this.pump();
896
962
  }
897
963
  }
898
964
  async dispatch(e) {
@@ -907,7 +973,9 @@ var He = {
907
973
  return;
908
974
  }
909
975
  try {
910
- await this.transport.send(e);
976
+ await this.transport.send(e, () => {
977
+ this.unconfirmed.delete(e.id);
978
+ });
911
979
  } catch (t) {
912
980
  await this.storeFailed({
913
981
  ...e,
@@ -926,67 +994,57 @@ var He = {
926
994
  await this.retry.storeFailed(e, t);
927
995
  });
928
996
  }
929
- async store(t) {
997
+ async store(e) {
930
998
  await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
931
- await T(this.storage.save(t), e), this.retry.nudge();
999
+ await O(this.storage.save(e), T), this.retry.nudge();
932
1000
  });
933
1001
  }
934
1002
  }, We = class e {
935
1003
  storage;
936
- transport;
937
1004
  retry;
938
1005
  pipeline;
939
1006
  exitFlush;
940
1007
  diagnostics;
941
- constructor(e, t, n, r, i, a) {
942
- this.storage = e, this.transport = t, this.retry = n, this.pipeline = r, this.exitFlush = i, this.diagnostics = a;
1008
+ constructor(e, t, n, r, i) {
1009
+ this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
943
1010
  }
944
1011
  static async create(t) {
945
- let { config: n, diagnostics: r } = t, i = await Ee(n.storage, ee, _, r, t.onGap), a = (e) => {
1012
+ let { config: n, diagnostics: r } = t, i = await Ee(n.storage, le, E, r, t.onGap), a = (e) => {
946
1013
  let i = M(e, r);
947
1014
  i && N(t.remote, n, i);
948
- }, o = n.transport ? new Ie(n, r, a) : new ze(n, r, a), s = new Be(i, o, r, n), c = new Ue(o, i, s, r), l = new Le({
1015
+ }, o = n.transport ? void 0 : new ze(n, r, a), s = o ?? new Ie(n, r, a), c = new Be(i, s, r, n), l = new Ue(s, i, c, r), u = new Le({
949
1016
  config: n,
950
1017
  diagnostics: r,
951
- drainForExit: () => c.drainForExit(),
952
- drainPending: () => c.drainPending()
953
- });
954
- await ye(i, r);
955
- let u = !1;
1018
+ drainForExit: () => l.drainForExit(),
1019
+ flushAlive: () => l.flushPending(),
1020
+ exitHeaders: () => o?.lastHeaders()
1021
+ }), d = !1;
956
1022
  try {
957
- l.install(), s.start(), u = !0;
1023
+ u.install(), c.start(), d = !0;
958
1024
  } finally {
959
- u || (l.uninstall(), s.stop());
1025
+ d || (u.uninstall(), c.stop());
960
1026
  }
961
- return new e(i, o, s, c, l, r);
1027
+ let f = new e(i, c, l, u, r);
1028
+ return f.importEmergency(), f;
962
1029
  }
963
1030
  push(e) {
964
1031
  this.pipeline.push(e);
965
1032
  }
966
1033
  async flush() {
967
- let e = this.pipeline.drainPending();
968
- if (e) try {
969
- await this.transport.send(e);
970
- } catch (t) {
971
- await this.diagnostics.guardAsync("storage.degraded", "The library could not store the batch that flush() drained.", async () => {
972
- await this.retry.storeFailed({
973
- ...e,
974
- attempts: e.attempts + 1
975
- }, t);
976
- }), this.diagnostics.report("transport.http_error", "The send from flush() failed. The library stored the batch for a retry.", {
977
- batchId: e.id,
978
- records: e.records.length
979
- }, t);
980
- }
1034
+ await this.pipeline.flushPending();
981
1035
  }
982
1036
  async queueDepth() {
983
1037
  return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
984
1038
  }
985
1039
  async destroy() {
986
- this.exitFlush.flush("shutdown"), this.exitFlush.uninstall(), this.retry.stop(), this.pipeline.destroy(), await this.storage.close();
1040
+ 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();
1041
+ }
1042
+ async importEmergency() {
1043
+ let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => ye(this.storage, this.diagnostics));
1044
+ e !== void 0 && e > 0 && this.retry.nudge();
987
1045
  }
988
1046
  };
989
1047
  //#endregion
990
1048
  export { We as Sender };
991
1049
 
992
- //# sourceMappingURL=sender-G6v4Uqi4.js.map
1050
+ //# sourceMappingURL=sender-BnNj9bOX.js.map