@utk09/ui-observability 0.9.3 → 0.9.5
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.
- package/CHANGELOG.md +90 -0
- package/README.md +199 -96
- package/dist/batch-BQFtb3i5.cjs +2 -0
- package/dist/batch-BQFtb3i5.cjs.map +1 -0
- package/dist/{batch-DDgxg16_.js → batch-BUJh-1jZ.js} +6 -4
- package/dist/batch-BUJh-1jZ.js.map +1 -0
- package/dist/bus/bus.d.ts +76 -2
- package/dist/bus/links.d.ts +9 -2
- package/dist/bus/validation.d.ts +7 -0
- package/dist/bus-BW6N-pY8.cjs +2 -0
- package/dist/bus-BW6N-pY8.cjs.map +1 -0
- package/dist/bus-DeOPHWaD.js +647 -0
- package/dist/bus-DeOPHWaD.js.map +1 -0
- package/dist/capture/network.d.ts +1 -0
- package/dist/capture/storm.d.ts +2 -1
- package/dist/capture/types.d.ts +5 -0
- package/dist/capture/web-socket.d.ts +40 -0
- package/dist/{console-BSusX_M-.cjs → console-Ce6heqZZ.cjs} +2 -2
- package/dist/console-Ce6heqZZ.cjs.map +1 -0
- package/dist/{console-Dv5GfaNn.js → console-DbAZYJuy.js} +4 -4
- package/dist/console-DbAZYJuy.js.map +1 -0
- package/dist/constants-CN7GE1Lt.js +246 -0
- package/dist/constants-CN7GE1Lt.js.map +1 -0
- package/dist/constants-CW-MlHdY.cjs +2 -0
- package/dist/constants-CW-MlHdY.cjs.map +1 -0
- package/dist/constants.d.ts +63 -11
- package/dist/context-storage-BjzeBSxH.cjs +2 -0
- package/dist/context-storage-BjzeBSxH.cjs.map +1 -0
- package/dist/context-storage-DxZf4Gfh.js +52 -0
- package/dist/context-storage-DxZf4Gfh.js.map +1 -0
- package/dist/core/breadcrumbs.d.ts +10 -3
- package/dist/core/context.d.ts +2 -0
- package/dist/core/diagnostics.d.ts +11 -3
- package/dist/core/journey.d.ts +7 -0
- package/dist/core/meter.d.ts +25 -2
- package/dist/core/pipeline.d.ts +41 -6
- package/dist/core/record.d.ts +42 -9
- package/dist/core/remote-sampling.d.ts +7 -3
- package/dist/core/runtime.d.ts +153 -6
- package/dist/core/sampling.d.ts +35 -2
- package/dist/core/sender.d.ts +43 -1
- package/dist/core/spans.d.ts +34 -0
- package/dist/deadline-5_PecIl5.js +26 -0
- package/dist/deadline-5_PecIl5.js.map +1 -0
- package/dist/deadline-XSnm95pg.cjs +2 -0
- package/dist/deadline-XSnm95pg.cjs.map +1 -0
- package/dist/emergency-queue-BYUyDHGD.js +69 -0
- package/dist/emergency-queue-BYUyDHGD.js.map +1 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs +2 -0
- package/dist/emergency-queue-Cs1hrjsC.cjs.map +1 -0
- package/dist/{errors-DCZWcHkd.js → errors-BhC7HTSt.js} +8 -9
- package/dist/errors-BhC7HTSt.js.map +1 -0
- package/dist/errors-CgY633cG.cjs +3 -0
- package/dist/errors-CgY633cG.cjs.map +1 -0
- package/dist/factory-C5TujXlU.js +280 -0
- package/dist/factory-C5TujXlU.js.map +1 -0
- package/dist/factory-CNj4DH3n.cjs +2 -0
- package/dist/factory-CNj4DH3n.cjs.map +1 -0
- package/dist/fixed-window-CtaFHanJ.js +12 -0
- package/dist/fixed-window-CtaFHanJ.js.map +1 -0
- package/dist/fixed-window-CvESpFYV.cjs +2 -0
- package/dist/fixed-window-CvESpFYV.cjs.map +1 -0
- package/dist/identity-8vKkyAWm.js +103 -0
- package/dist/identity-8vKkyAWm.js.map +1 -0
- package/dist/identity-Da9TkuKd.cjs +2 -0
- package/dist/identity-Da9TkuKd.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -6
- package/dist/index.js +1253 -595
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-BTfIFRHF.cjs +2 -0
- package/dist/indexeddb-storage-BTfIFRHF.cjs.map +1 -0
- package/dist/{indexeddb-storage-T9YIYVYC.js → indexeddb-storage-CCA1LvtO.js} +45 -30
- package/dist/indexeddb-storage-CCA1LvtO.js.map +1 -0
- package/dist/{interactions-BLH_tX87.js → interactions-BUDLxbv1.js} +16 -12
- package/dist/interactions-BUDLxbv1.js.map +1 -0
- package/dist/interactions-NHbLKrqe.cjs +2 -0
- package/dist/interactions-NHbLKrqe.cjs.map +1 -0
- package/dist/{journey-yALMEWF7.js → journey-BUJ4WJxP.js} +37 -34
- package/dist/journey-BUJ4WJxP.js.map +1 -0
- package/dist/journey-B_tTnvac.cjs +2 -0
- package/dist/journey-B_tTnvac.cjs.map +1 -0
- package/dist/keys-BHhw_0Wh.cjs +2 -0
- package/dist/keys-BHhw_0Wh.cjs.map +1 -0
- package/dist/keys-D5r_GH9q.js +17 -0
- package/dist/keys-D5r_GH9q.js.map +1 -0
- package/dist/{library-request-CQD4HUiP.js → library-request-BKOcaKtQ.js} +3 -3
- package/dist/{library-request-CQD4HUiP.js.map → library-request-BKOcaKtQ.js.map} +1 -1
- package/dist/{library-request-BcAxuwsf.cjs → library-request-BaZOi4eg.cjs} +2 -2
- package/dist/{library-request-BcAxuwsf.cjs.map → library-request-BaZOi4eg.cjs.map} +1 -1
- package/dist/{long-frames-D4Bm3Zkz.cjs → long-frames-CF3qiSAX.cjs} +2 -2
- package/dist/long-frames-CF3qiSAX.cjs.map +1 -0
- package/dist/{long-frames-DD_Um9_4.js → long-frames-DI5ypfAF.js} +5 -5
- package/dist/long-frames-DI5ypfAF.js.map +1 -0
- package/dist/models/batch.d.ts +4 -0
- package/dist/models/bus.d.ts +32 -9
- package/dist/models/config.d.ts +401 -12
- package/dist/models/drop.d.ts +1 -1
- package/dist/models/health.d.ts +27 -0
- package/dist/models/log-record.d.ts +1 -1
- package/dist/models/plugin.d.ts +47 -0
- package/dist/models/stats.d.ts +11 -0
- package/dist/models/storage.d.ts +13 -0
- package/dist/network-CF8UO5PK.cjs +2 -0
- package/dist/network-CF8UO5PK.cjs.map +1 -0
- package/dist/{network--GoE7_Or.js → network-DdzXDI3J.js} +47 -31
- package/dist/network-DdzXDI3J.js.map +1 -0
- package/dist/openfin-BwEN0uj4.js.map +1 -1
- package/dist/openfin-DtH2f7zX.cjs.map +1 -1
- package/dist/{platform-GaM6h7XM.js → platform-Bw1btWCT.js} +21 -10
- package/dist/platform-Bw1btWCT.js.map +1 -0
- package/dist/platform-DBSKTvFn.cjs +2 -0
- package/dist/platform-DBSKTvFn.cjs.map +1 -0
- package/dist/remote-rules-DIcC5vVC.js +91 -0
- package/dist/remote-rules-DIcC5vVC.js.map +1 -0
- package/dist/remote-rules-DpFmOef2.cjs +2 -0
- package/dist/remote-rules-DpFmOef2.cjs.map +1 -0
- package/dist/sampling-BVjspJWu.cjs +2 -0
- package/dist/sampling-BVjspJWu.cjs.map +1 -0
- package/dist/sampling-Cm3WhI0a.js +76 -0
- package/dist/sampling-Cm3WhI0a.js.map +1 -0
- package/dist/{sanitize-DP0xDPrt.js → sanitize-C-ahCFsG.js} +2 -2
- package/dist/{sanitize-DP0xDPrt.js.map → sanitize-C-ahCFsG.js.map} +1 -1
- package/dist/{sanitize--_e4oOPX.cjs → sanitize-DHucKGdi.cjs} +2 -2
- package/dist/{sanitize--_e4oOPX.cjs.map → sanitize-DHucKGdi.cjs.map} +1 -1
- package/dist/sender-D3fRCR8d.cjs +3 -0
- package/dist/sender-D3fRCR8d.cjs.map +1 -0
- package/dist/sender-DUUmSglb.js +1163 -0
- package/dist/sender-DUUmSglb.js.map +1 -0
- package/dist/storage/context-storage.d.ts +89 -0
- package/dist/storage/emergency-queue.d.ts +9 -1
- package/dist/storage/factory.d.ts +7 -1
- package/dist/storage/idb-driver.d.ts +13 -0
- package/dist/storage/indexeddb-storage.d.ts +13 -0
- package/dist/storage/local-storage.d.ts +21 -1
- package/dist/storage/memory-storage.d.ts +13 -0
- package/dist/storage-BA9RqRO-.cjs +2 -0
- package/dist/storage-BA9RqRO-.cjs.map +1 -0
- package/dist/storage-w7Tslvlq.js +17 -0
- package/dist/storage-w7Tslvlq.js.map +1 -0
- package/dist/storm-CNZjsw4T.cjs +2 -0
- package/dist/storm-CNZjsw4T.cjs.map +1 -0
- package/dist/storm-Daq2jGHU.js +10 -0
- package/dist/storm-Daq2jGHU.js.map +1 -0
- package/dist/transport/exit-flush.d.ts +6 -0
- package/dist/transport/http-transport.d.ts +2 -1
- package/dist/transport/retry-engine.d.ts +7 -2
- package/dist/transport/serializers/otlp-traces.d.ts +3 -0
- package/dist/transport/serializers/select.d.ts +8 -5
- package/dist/transport/status-transport.d.ts +24 -0
- package/dist/types-BR9t_w28.js +8 -0
- package/dist/types-BR9t_w28.js.map +1 -0
- package/dist/types-C7WNpnG1.cjs +2 -0
- package/dist/types-C7WNpnG1.cjs.map +1 -0
- package/dist/utils/fixed-window.d.ts +9 -0
- package/dist/utils/identity.d.ts +20 -2
- package/dist/utils/lock.d.ts +8 -0
- package/dist/utils/openfin.d.ts +1 -1
- package/dist/utils/platform.d.ts +10 -0
- package/dist/utils/tracing.d.ts +82 -4
- package/dist/web-socket-BacvKOvD.cjs +2 -0
- package/dist/web-socket-BacvKOvD.cjs.map +1 -0
- package/dist/web-socket-CpsD8WAa.js +105 -0
- package/dist/web-socket-CpsD8WAa.js.map +1 -0
- package/package.json +1 -1
- package/dist/batch-D5qvsMQ_.cjs +0 -2
- package/dist/batch-D5qvsMQ_.cjs.map +0 -1
- package/dist/batch-DDgxg16_.js.map +0 -1
- package/dist/bus-C6RwKzPW.js +0 -478
- package/dist/bus-C6RwKzPW.js.map +0 -1
- package/dist/bus-WPVDFw2y.cjs +0 -2
- package/dist/bus-WPVDFw2y.cjs.map +0 -1
- package/dist/console-BSusX_M-.cjs.map +0 -1
- package/dist/console-Dv5GfaNn.js.map +0 -1
- package/dist/constants-Cb92egPS.cjs +0 -2
- package/dist/constants-Cb92egPS.cjs.map +0 -1
- package/dist/constants-DhH6VI5a.js +0 -144
- package/dist/constants-DhH6VI5a.js.map +0 -1
- package/dist/deadline-CUrH0Hd8.cjs +0 -2
- package/dist/deadline-CUrH0Hd8.cjs.map +0 -1
- package/dist/deadline-DeqXEliN.js +0 -31
- package/dist/deadline-DeqXEliN.js.map +0 -1
- package/dist/errors-DCZWcHkd.js.map +0 -1
- package/dist/errors-ERu-su8m.cjs +0 -3
- package/dist/errors-ERu-su8m.cjs.map +0 -1
- package/dist/fixed-window-BR0bu32Y.cjs +0 -2
- package/dist/fixed-window-BR0bu32Y.cjs.map +0 -1
- package/dist/fixed-window-Re7jIRJH.js +0 -9
- package/dist/fixed-window-Re7jIRJH.js.map +0 -1
- package/dist/identity-C1WLItSl.cjs +0 -2
- package/dist/identity-C1WLItSl.cjs.map +0 -1
- package/dist/identity-Di-QXGCC.js +0 -88
- package/dist/identity-Di-QXGCC.js.map +0 -1
- package/dist/indexeddb-storage-DX18p39D.cjs +0 -2
- package/dist/indexeddb-storage-DX18p39D.cjs.map +0 -1
- package/dist/indexeddb-storage-T9YIYVYC.js.map +0 -1
- package/dist/interactions-BLH_tX87.js.map +0 -1
- package/dist/interactions-_hfOerfC.cjs +0 -2
- package/dist/interactions-_hfOerfC.cjs.map +0 -1
- package/dist/journey-BRUj0hqD.cjs +0 -2
- package/dist/journey-BRUj0hqD.cjs.map +0 -1
- package/dist/journey-yALMEWF7.js.map +0 -1
- package/dist/long-frames-D4Bm3Zkz.cjs.map +0 -1
- package/dist/long-frames-DD_Um9_4.js.map +0 -1
- package/dist/network--GoE7_Or.js.map +0 -1
- package/dist/network-DcuS2H1P.cjs +0 -2
- package/dist/network-DcuS2H1P.cjs.map +0 -1
- package/dist/platform-GaM6h7XM.js.map +0 -1
- package/dist/platform-kIL5AZB7.cjs +0 -2
- package/dist/platform-kIL5AZB7.cjs.map +0 -1
- package/dist/remote-rules-6ePq8CrI.js +0 -84
- package/dist/remote-rules-6ePq8CrI.js.map +0 -1
- package/dist/remote-rules-CI3gbRCL.cjs +0 -2
- package/dist/remote-rules-CI3gbRCL.cjs.map +0 -1
- package/dist/sampling-C-M8p3FK.cjs +0 -2
- package/dist/sampling-C-M8p3FK.cjs.map +0 -1
- package/dist/sampling-Ud_WiuU9.js +0 -65
- package/dist/sampling-Ud_WiuU9.js.map +0 -1
- package/dist/sender-BESHz6my.cjs +0 -3
- package/dist/sender-BESHz6my.cjs.map +0 -1
- package/dist/sender-BUBWLn5i.js +0 -1244
- package/dist/sender-BUBWLn5i.js.map +0 -1
- package/dist/storm-DhHGHhOc.cjs +0 -2
- package/dist/storm-DhHGHhOc.cjs.map +0 -1
- package/dist/storm-OD5J6Ylm.js +0 -10
- package/dist/storm-OD5J6Ylm.js.map +0 -1
package/dist/sender-BUBWLn5i.js
DELETED
|
@@ -1,1244 +0,0 @@
|
|
|
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-DhH6VI5a.js";
|
|
2
|
-
import { n as E, r as D, t as fe } from "./deadline-DeqXEliN.js";
|
|
3
|
-
import { o as pe, t as me } from "./sampling-Ud_WiuU9.js";
|
|
4
|
-
import { o as he, t as O } from "./sanitize-DP0xDPrt.js";
|
|
5
|
-
import { i as ge } from "./identity-Di-QXGCC.js";
|
|
6
|
-
import { t as k } from "./openfin-BwEN0uj4.js";
|
|
7
|
-
import { r as _e } from "./platform-GaM6h7XM.js";
|
|
8
|
-
import { a as ve, i as A, n as j, r as ye, t as be } from "./batch-DDgxg16_.js";
|
|
9
|
-
import { i as xe, r as M } from "./library-request-CQD4HUiP.js";
|
|
10
|
-
import { n as Se, t as Ce } from "./remote-rules-6ePq8CrI.js";
|
|
11
|
-
//#region src/models/storage.ts
|
|
12
|
-
function N(e) {
|
|
13
|
-
let { maxBatches: t } = e;
|
|
14
|
-
return e.mode === "until-delivered" ? {
|
|
15
|
-
maxBatches: t,
|
|
16
|
-
maxAgeMs: Infinity,
|
|
17
|
-
maxAttempts: Infinity
|
|
18
|
-
} : {
|
|
19
|
-
maxBatches: t,
|
|
20
|
-
maxAgeMs: e.maxAgeMs,
|
|
21
|
-
maxAttempts: e.maxAttempts
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/utils/lock.ts
|
|
26
|
-
function P(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
27
|
-
let i = globalThis.navigator?.locks;
|
|
28
|
-
return i?.request ? t.guardAsync("storage.degraded", `The library could not get the lock ${e}.`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/storage/keys.ts
|
|
32
|
-
function F(e, t) {
|
|
33
|
-
return `${e}${String(t.createdAt).padStart(14, "0")}.${t.id}`;
|
|
34
|
-
}
|
|
35
|
-
function I(e, t) {
|
|
36
|
-
let n = [];
|
|
37
|
-
return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
|
|
38
|
-
for (let t = 0; t < localStorage.length; t++) {
|
|
39
|
-
let r = String(localStorage.key(t));
|
|
40
|
-
r.startsWith(e) && n.push(r);
|
|
41
|
-
}
|
|
42
|
-
}), n.sort();
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/storage/emergency-queue.ts
|
|
46
|
-
function L(e, t) {
|
|
47
|
-
let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
|
|
48
|
-
return n === void 0 ? null : A(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
|
|
49
|
-
}
|
|
50
|
-
async function we(e, t) {
|
|
51
|
-
let n = 0;
|
|
52
|
-
for (let r of I(a, t)) {
|
|
53
|
-
let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
|
|
54
|
-
let e = localStorage.getItem(r);
|
|
55
|
-
return localStorage.removeItem(r), e;
|
|
56
|
-
});
|
|
57
|
-
if (!i) continue;
|
|
58
|
-
let a = L(i, t);
|
|
59
|
-
if (a !== null) try {
|
|
60
|
-
await E(e.save(a), C), n++;
|
|
61
|
-
} catch (e) {
|
|
62
|
-
t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return n;
|
|
66
|
-
}
|
|
67
|
-
function R(e, t, n) {
|
|
68
|
-
let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], o = t.guard("storage.quota_exceeded", r, () => {
|
|
69
|
-
let n = I(a, t);
|
|
70
|
-
for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
|
|
71
|
-
let n = L(String(localStorage.getItem(e)), t);
|
|
72
|
-
n !== null && i.push(n), localStorage.removeItem(e);
|
|
73
|
-
}
|
|
74
|
-
return localStorage.setItem(F(a, e), JSON.stringify(e)), !0;
|
|
75
|
-
});
|
|
76
|
-
t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
|
|
77
|
-
if (i.length > 0) {
|
|
78
|
-
let e = i.flatMap((e) => e.records);
|
|
79
|
-
n?.("exit_queue_full", e, i.map((e) => e.id));
|
|
80
|
-
}
|
|
81
|
-
o !== !0 && n?.("quota", e.records, [e.id]);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
async function Te(e, t) {
|
|
85
|
-
return await P("ui-observability.emergency", t, () => we(e, t), { skipIfBusy: !1 }) ?? 0;
|
|
86
|
-
}
|
|
87
|
-
//#endregion
|
|
88
|
-
//#region src/storage/eviction.ts
|
|
89
|
-
function z(e) {
|
|
90
|
-
return Array.isArray(e.records) && e.records.some(ye);
|
|
91
|
-
}
|
|
92
|
-
var B = class {
|
|
93
|
-
howMany;
|
|
94
|
-
isAudit;
|
|
95
|
-
plain = [];
|
|
96
|
-
audit = [];
|
|
97
|
-
constructor(e, t) {
|
|
98
|
-
this.howMany = e, this.isAudit = t;
|
|
99
|
-
}
|
|
100
|
-
add(e) {
|
|
101
|
-
return this.isAudit(e) ? this.audit.length < this.howMany && this.audit.push(e) : this.plain.push(e), this.plain.length < this.howMany;
|
|
102
|
-
}
|
|
103
|
-
picked() {
|
|
104
|
-
return [...this.plain, ...this.audit].slice(0, this.howMany);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
function V(e, t, n) {
|
|
108
|
-
let r = new B(t, n);
|
|
109
|
-
for (let t of e) if (!r.add(t)) break;
|
|
110
|
-
return r.picked();
|
|
111
|
-
}
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/storage/gap.ts
|
|
114
|
-
function H(e, t, n, r) {
|
|
115
|
-
return e.batches += n, e.records += r, e.reason = t, {
|
|
116
|
-
batches: n,
|
|
117
|
-
records: r,
|
|
118
|
-
reason: t
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function U(e, t, n, r) {
|
|
122
|
-
n.batches !== 0 && (e.report("storage.evicted", `The library dropped ${String(n.batches)} stored batches (${String(n.records)} records).`, { ...n }), t?.(n, r));
|
|
123
|
-
}
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/storage/local-storage.ts
|
|
126
|
-
function Ee(e) {
|
|
127
|
-
let t = T.length, n = Number(e.slice(t, t + 14));
|
|
128
|
-
return Number.isFinite(n) ? n : null;
|
|
129
|
-
}
|
|
130
|
-
var De = class {
|
|
131
|
-
limits;
|
|
132
|
-
diagnostics;
|
|
133
|
-
onGap;
|
|
134
|
-
name = ue;
|
|
135
|
-
constructor(e, t, n) {
|
|
136
|
-
this.limits = e, this.diagnostics = t, this.onGap = n;
|
|
137
|
-
}
|
|
138
|
-
async save(e) {
|
|
139
|
-
if (this.write(e, "localStorage refused a batch, evicting the oldest")) await this.prune();
|
|
140
|
-
else if (this.evictForQuota(), !this.write(e, "localStorage refused a batch even after evicting")) {
|
|
141
|
-
let t = {
|
|
142
|
-
batches: 1,
|
|
143
|
-
records: e.records.length,
|
|
144
|
-
reason: "quota"
|
|
145
|
-
};
|
|
146
|
-
U(this.diagnostics, this.onGap, t, [e]);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
take(e) {
|
|
150
|
-
let t = [];
|
|
151
|
-
for (let n of this.keys().slice(0, e)) {
|
|
152
|
-
let e = this.read(n);
|
|
153
|
-
e === null ? this.removeKey(n) : t.push(e);
|
|
154
|
-
}
|
|
155
|
-
return Promise.resolve(t);
|
|
156
|
-
}
|
|
157
|
-
remove(e) {
|
|
158
|
-
let t = this.keyOf(e);
|
|
159
|
-
return t !== null && this.removeKey(t), Promise.resolve();
|
|
160
|
-
}
|
|
161
|
-
bumpAttempts(e, t) {
|
|
162
|
-
let n = this.keyOf(e);
|
|
163
|
-
if (n === null) return Promise.resolve();
|
|
164
|
-
let r = this.read(n);
|
|
165
|
-
return r === null || (r.attempts = t, this.diagnostics.guard("storage.degraded", "The library could not update the attempt count.", () => {
|
|
166
|
-
localStorage.setItem(n, JSON.stringify(r));
|
|
167
|
-
})), Promise.resolve();
|
|
168
|
-
}
|
|
169
|
-
prune() {
|
|
170
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
171
|
-
batches: 0,
|
|
172
|
-
records: 0,
|
|
173
|
-
reason: "expired"
|
|
174
|
-
}, n = [], r = [];
|
|
175
|
-
for (let t of this.keys()) {
|
|
176
|
-
let i = Ee(t);
|
|
177
|
-
i === null || i < e ? n.push(t) : r.push(t);
|
|
178
|
-
}
|
|
179
|
-
this.drop(t, "expired", [...this.entries(n)]);
|
|
180
|
-
let i = r.length - this.limits.maxBatches;
|
|
181
|
-
return i > 0 && this.drop(t, "over_capacity", this.evictable(r, i)), Promise.resolve(t);
|
|
182
|
-
}
|
|
183
|
-
count() {
|
|
184
|
-
return Promise.resolve(this.keys().length);
|
|
185
|
-
}
|
|
186
|
-
clear() {
|
|
187
|
-
return this.evict(this.keys()), Promise.resolve();
|
|
188
|
-
}
|
|
189
|
-
close() {
|
|
190
|
-
return Promise.resolve();
|
|
191
|
-
}
|
|
192
|
-
write(e, t) {
|
|
193
|
-
return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(F(T, e), JSON.stringify(e)), !0)) === !0;
|
|
194
|
-
}
|
|
195
|
-
evictForQuota() {
|
|
196
|
-
let e = this.keys(), t = {
|
|
197
|
-
batches: 0,
|
|
198
|
-
records: 0,
|
|
199
|
-
reason: "quota"
|
|
200
|
-
}, n = Math.ceil(e.length / 4);
|
|
201
|
-
this.drop(t, "quota", this.evictable(e, n));
|
|
202
|
-
}
|
|
203
|
-
evictable(e, t) {
|
|
204
|
-
return V(this.entries(e), t, (e) => e.batch !== null && z(e.batch));
|
|
205
|
-
}
|
|
206
|
-
*entries(e) {
|
|
207
|
-
for (let t of e) yield {
|
|
208
|
-
key: t,
|
|
209
|
-
batch: this.read(t)
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
drop(e, t, n) {
|
|
213
|
-
if (n.length === 0) return;
|
|
214
|
-
let r = [];
|
|
215
|
-
for (let { key: e, batch: t } of n) this.removeKey(e), t && r.push(t);
|
|
216
|
-
let i = H(e, t, n.length, j(r));
|
|
217
|
-
U(this.diagnostics, this.onGap, i, r);
|
|
218
|
-
}
|
|
219
|
-
read(e) {
|
|
220
|
-
let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
|
|
221
|
-
if (!t) return null;
|
|
222
|
-
let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
|
|
223
|
-
return n === void 0 ? null : A(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
|
|
224
|
-
}
|
|
225
|
-
keyOf(e) {
|
|
226
|
-
return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
|
|
227
|
-
}
|
|
228
|
-
evict(e) {
|
|
229
|
-
for (let t of e) this.removeKey(t);
|
|
230
|
-
}
|
|
231
|
-
removeKey(e) {
|
|
232
|
-
this.diagnostics.guard("storage.degraded", "The library could not remove a stored batch.", () => {
|
|
233
|
-
localStorage.removeItem(e);
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
keys() {
|
|
237
|
-
return I(T, this.diagnostics);
|
|
238
|
-
}
|
|
239
|
-
}, W = class {
|
|
240
|
-
limits;
|
|
241
|
-
onGap;
|
|
242
|
-
name = de;
|
|
243
|
-
batches = [];
|
|
244
|
-
constructor(e, t) {
|
|
245
|
-
this.limits = e, this.onGap = t;
|
|
246
|
-
}
|
|
247
|
-
async save(e) {
|
|
248
|
-
this.batches.push(e), await this.prune();
|
|
249
|
-
}
|
|
250
|
-
take(e) {
|
|
251
|
-
return Promise.resolve(this.batches.slice(0, e));
|
|
252
|
-
}
|
|
253
|
-
remove(e) {
|
|
254
|
-
return this.batches = this.batches.filter((t) => t.id !== e), Promise.resolve();
|
|
255
|
-
}
|
|
256
|
-
bumpAttempts(e, t) {
|
|
257
|
-
let n = this.batches.find((t) => t.id === e);
|
|
258
|
-
return n && (n.attempts = t), Promise.resolve();
|
|
259
|
-
}
|
|
260
|
-
prune() {
|
|
261
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
262
|
-
batches: 0,
|
|
263
|
-
records: 0,
|
|
264
|
-
reason: "expired"
|
|
265
|
-
}, n = this.batches.filter((t) => t.createdAt < e);
|
|
266
|
-
this.batches = this.batches.filter((t) => t.createdAt >= e), this.report(t, "expired", n);
|
|
267
|
-
let r = this.batches.length - this.limits.maxBatches;
|
|
268
|
-
if (r > 0) {
|
|
269
|
-
let e = V(this.batches, r, z);
|
|
270
|
-
this.batches = this.batches.filter((t) => !e.includes(t)), this.report(t, "over_capacity", e);
|
|
271
|
-
}
|
|
272
|
-
return Promise.resolve(t);
|
|
273
|
-
}
|
|
274
|
-
report(e, t, n) {
|
|
275
|
-
if (n.length === 0) return;
|
|
276
|
-
let r = H(e, t, n.length, j(n));
|
|
277
|
-
this.onGap?.(r, n);
|
|
278
|
-
}
|
|
279
|
-
count() {
|
|
280
|
-
return Promise.resolve(this.batches.length);
|
|
281
|
-
}
|
|
282
|
-
clear() {
|
|
283
|
-
return this.batches = [], Promise.resolve();
|
|
284
|
-
}
|
|
285
|
-
close() {
|
|
286
|
-
return this.batches = [], Promise.resolve();
|
|
287
|
-
}
|
|
288
|
-
}, Oe = (e) => ({
|
|
289
|
-
name: se,
|
|
290
|
-
save: (t) => (e?.({
|
|
291
|
-
batches: 1,
|
|
292
|
-
records: t.records.length,
|
|
293
|
-
reason: "not_stored"
|
|
294
|
-
}, [t]), Promise.resolve()),
|
|
295
|
-
take: () => Promise.resolve([]),
|
|
296
|
-
remove: () => Promise.resolve(),
|
|
297
|
-
bumpAttempts: () => Promise.resolve(),
|
|
298
|
-
prune: () => Promise.resolve({
|
|
299
|
-
batches: 0,
|
|
300
|
-
records: 0,
|
|
301
|
-
reason: "expired"
|
|
302
|
-
}),
|
|
303
|
-
count: () => Promise.resolve(0),
|
|
304
|
-
clear: () => Promise.resolve(),
|
|
305
|
-
close: () => Promise.resolve()
|
|
306
|
-
});
|
|
307
|
-
function ke(e) {
|
|
308
|
-
return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
|
|
309
|
-
}
|
|
310
|
-
function Ae(e) {
|
|
311
|
-
return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(b, "1"), localStorage.removeItem(b), !0)) === !0;
|
|
312
|
-
}
|
|
313
|
-
async function je(e, t, n, r, i) {
|
|
314
|
-
if (e === "none") return Oe(i);
|
|
315
|
-
if (e === "memory") return new W(n, i);
|
|
316
|
-
if (e === "indexeddb" || e === "auto") {
|
|
317
|
-
if (ke(r)) {
|
|
318
|
-
let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
|
|
319
|
-
let { IndexedDbStorage: e } = await import("./indexeddb-storage-T9YIYVYC.js"), a = new e(t, n, r, i);
|
|
320
|
-
return await a.open(), a;
|
|
321
|
-
});
|
|
322
|
-
if (e) return e;
|
|
323
|
-
}
|
|
324
|
-
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new W(n, i);
|
|
325
|
-
}
|
|
326
|
-
return Ae(r) ? new De(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new W(n, i));
|
|
327
|
-
}
|
|
328
|
-
//#endregion
|
|
329
|
-
//#region src/transport/errors.ts
|
|
330
|
-
var G = class extends Error {
|
|
331
|
-
kind;
|
|
332
|
-
status;
|
|
333
|
-
retryAfterMs;
|
|
334
|
-
maxBytes;
|
|
335
|
-
constructor(e, t, n, r, i, a) {
|
|
336
|
-
super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
function Me(e) {
|
|
340
|
-
if (!e) return;
|
|
341
|
-
let t = Number(e);
|
|
342
|
-
if (Number.isFinite(t)) return Math.max(0, t * ae);
|
|
343
|
-
let n = Date.parse(e);
|
|
344
|
-
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
345
|
-
}
|
|
346
|
-
//#endregion
|
|
347
|
-
//#region src/transport/serializers/ecs.ts
|
|
348
|
-
function Ne(e) {
|
|
349
|
-
return ee.test(e) ? Number(BigInt(e) / n) : Date.now();
|
|
350
|
-
}
|
|
351
|
-
function Pe(e) {
|
|
352
|
-
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
|
|
353
|
-
}
|
|
354
|
-
function Fe(e, t, n) {
|
|
355
|
-
let r = e[t];
|
|
356
|
-
r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
|
|
357
|
-
}
|
|
358
|
-
function K(e, t, n, r) {
|
|
359
|
-
let i = Pe(n);
|
|
360
|
-
if (i !== null) Fe(e, t, i);
|
|
361
|
-
else if (typeof n == "object" && n && !r.has(n)) {
|
|
362
|
-
if (r.add(n), Array.isArray(n)) for (let i of n) K(e, t, i, r);
|
|
363
|
-
else for (let [i, a] of Object.entries(n)) K(e, `${t}.${i}`, a, r);
|
|
364
|
-
r.delete(n);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function q(e) {
|
|
368
|
-
let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
|
|
369
|
-
for (let [r, i] of Object.entries(e)) K(t, r, i, n);
|
|
370
|
-
return t;
|
|
371
|
-
}
|
|
372
|
-
var Ie = {
|
|
373
|
-
name: "ecs",
|
|
374
|
-
serialize(e) {
|
|
375
|
-
return {
|
|
376
|
-
body: `${e.map((e) => {
|
|
377
|
-
let n = Ne(e.timeUnixNano);
|
|
378
|
-
return JSON.stringify({
|
|
379
|
-
"@timestamp": new Date(n).toISOString(),
|
|
380
|
-
message: e.body,
|
|
381
|
-
log: { level: t[e.severityText] ?? e.severityText.toLowerCase() },
|
|
382
|
-
trace: { id: e.traceId },
|
|
383
|
-
span: { id: e.spanId },
|
|
384
|
-
service: {
|
|
385
|
-
name: e.resource[te],
|
|
386
|
-
version: e.resource[o],
|
|
387
|
-
environment: e.resource[c]
|
|
388
|
-
},
|
|
389
|
-
user_agent: { original: e.resource[i] },
|
|
390
|
-
url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
|
|
391
|
-
labels: {
|
|
392
|
-
...q(e.resource),
|
|
393
|
-
...q(e.attributes)
|
|
394
|
-
}
|
|
395
|
-
});
|
|
396
|
-
}).join("\n")}\n`,
|
|
397
|
-
contentType: u
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
//#endregion
|
|
402
|
-
//#region src/transport/serializers/otlp.ts
|
|
403
|
-
function J(e) {
|
|
404
|
-
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(J).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: Y(e) } } : null;
|
|
405
|
-
}
|
|
406
|
-
function Y(e) {
|
|
407
|
-
let t = [];
|
|
408
|
-
for (let [n, r] of Object.entries(e)) {
|
|
409
|
-
let e = J(r);
|
|
410
|
-
e && t.push({
|
|
411
|
-
key: n,
|
|
412
|
-
value: e
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
return t;
|
|
416
|
-
}
|
|
417
|
-
var Le = /* @__PURE__ */ new WeakMap();
|
|
418
|
-
function Re(e) {
|
|
419
|
-
let t = Le.get(e);
|
|
420
|
-
if (t !== void 0) return t;
|
|
421
|
-
let n = JSON.stringify(e);
|
|
422
|
-
return Le.set(e, n), n;
|
|
423
|
-
}
|
|
424
|
-
function ze(e) {
|
|
425
|
-
let t = /* @__PURE__ */ new Map();
|
|
426
|
-
for (let n of e) {
|
|
427
|
-
let e = Re(n.resource), r = t.get(e);
|
|
428
|
-
r ? r.records.push(n) : t.set(e, {
|
|
429
|
-
resource: n.resource,
|
|
430
|
-
records: [n]
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
return [...t.values()];
|
|
434
|
-
}
|
|
435
|
-
var Be = {
|
|
436
|
-
name: y,
|
|
437
|
-
serialize(e) {
|
|
438
|
-
let t = ze(e).map((e) => ({
|
|
439
|
-
resource: { attributes: Y(e.resource) },
|
|
440
|
-
scopeLogs: [{
|
|
441
|
-
scope: {
|
|
442
|
-
name: S,
|
|
443
|
-
version: x
|
|
444
|
-
},
|
|
445
|
-
logRecords: e.records.map((e) => ({
|
|
446
|
-
timeUnixNano: e.timeUnixNano,
|
|
447
|
-
observedTimeUnixNano: e.observedTimeUnixNano ?? e.timeUnixNano,
|
|
448
|
-
severityNumber: e.severityNumber,
|
|
449
|
-
severityText: e.severityText,
|
|
450
|
-
body: { stringValue: e.body },
|
|
451
|
-
traceId: e.traceId,
|
|
452
|
-
spanId: e.spanId,
|
|
453
|
-
flags: e.traceFlags,
|
|
454
|
-
attributes: Y(e.attributes)
|
|
455
|
-
}))
|
|
456
|
-
}]
|
|
457
|
-
}));
|
|
458
|
-
return {
|
|
459
|
-
body: JSON.stringify({ resourceLogs: t }),
|
|
460
|
-
contentType: l
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
}, Ve = 1;
|
|
464
|
-
function X(e, t) {
|
|
465
|
-
let n = e.attributes[t];
|
|
466
|
-
return typeof n == "number" && Number.isFinite(n) ? n : void 0;
|
|
467
|
-
}
|
|
468
|
-
function He(e) {
|
|
469
|
-
return Array.isArray(e) && e.every((e) => typeof e == "number" && Number.isFinite(e));
|
|
470
|
-
}
|
|
471
|
-
function Ue(e) {
|
|
472
|
-
let t = e.attributes[w.attributeKeys], n = {};
|
|
473
|
-
if (!Array.isArray(t)) return n;
|
|
474
|
-
for (let r of t) {
|
|
475
|
-
let t = typeof r == "string" && !r.startsWith("metric.") ? e.attributes[r] : void 0;
|
|
476
|
-
(typeof t == "string" || typeof t == "number" || typeof t == "boolean") && (n[r] = t);
|
|
477
|
-
}
|
|
478
|
-
return n;
|
|
479
|
-
}
|
|
480
|
-
function We(e) {
|
|
481
|
-
let t = X(e, w.count);
|
|
482
|
-
if (t === void 0) {
|
|
483
|
-
let t = X(e, "metric.value");
|
|
484
|
-
return t === void 0 ? null : {
|
|
485
|
-
count: "1",
|
|
486
|
-
sum: t < 0 ? void 0 : t,
|
|
487
|
-
min: t,
|
|
488
|
-
max: t,
|
|
489
|
-
bucketCounts: ["1"],
|
|
490
|
-
explicitBounds: []
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
let n = e.attributes[w.bounds], r = e.attributes[w.buckets];
|
|
494
|
-
if (!He(n) || !He(r) || r.length !== n.length + 1) return null;
|
|
495
|
-
let i = X(e, w.min);
|
|
496
|
-
return {
|
|
497
|
-
count: String(t),
|
|
498
|
-
sum: i !== void 0 && i < 0 ? void 0 : X(e, w.sum),
|
|
499
|
-
min: i,
|
|
500
|
-
max: X(e, w.max),
|
|
501
|
-
bucketCounts: r.map(String),
|
|
502
|
-
explicitBounds: n
|
|
503
|
-
};
|
|
504
|
-
}
|
|
505
|
-
function Ge(e) {
|
|
506
|
-
let t = X(e, "metric.value");
|
|
507
|
-
return t === void 0 ? null : { asDouble: t };
|
|
508
|
-
}
|
|
509
|
-
function Ke(e, t) {
|
|
510
|
-
let n = e.attributes[w.start], r = t === "histogram" ? We(e) : Ge(e);
|
|
511
|
-
return r === null ? null : {
|
|
512
|
-
attributes: Y(Ue(e)),
|
|
513
|
-
startTimeUnixNano: typeof n == "string" ? n : e.timeUnixNano,
|
|
514
|
-
timeUnixNano: e.timeUnixNano,
|
|
515
|
-
...r
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
function qe({ name: e, unit: t, field: n, points: r }) {
|
|
519
|
-
if (n === "gauge") return {
|
|
520
|
-
name: e,
|
|
521
|
-
unit: t,
|
|
522
|
-
gauge: { dataPoints: r }
|
|
523
|
-
};
|
|
524
|
-
let i = {
|
|
525
|
-
aggregationTemporality: Ve,
|
|
526
|
-
dataPoints: r
|
|
527
|
-
};
|
|
528
|
-
return n === "sum" && (i.isMonotonic = r.every((e) => e.asDouble >= 0)), {
|
|
529
|
-
name: e,
|
|
530
|
-
unit: t,
|
|
531
|
-
[n]: i
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
var Je = {
|
|
535
|
-
name: y,
|
|
536
|
-
serialize(e) {
|
|
537
|
-
let t = ze(e).map((e) => {
|
|
538
|
-
let t = /* @__PURE__ */ new Map();
|
|
539
|
-
for (let n of e.records) {
|
|
540
|
-
let e = n.attributes["metric.type"], r = e === "counter" ? "sum" : e === "histogram" ? "histogram" : "gauge", i = Ke(n, r);
|
|
541
|
-
if (i === null) continue;
|
|
542
|
-
let a = n.attributes["metric.name"], o = n.attributes["metric.unit"], s = {
|
|
543
|
-
name: typeof a == "string" ? a : n.body,
|
|
544
|
-
unit: typeof o == "string" ? o : "",
|
|
545
|
-
field: r,
|
|
546
|
-
points: []
|
|
547
|
-
}, c = JSON.stringify([
|
|
548
|
-
s.field,
|
|
549
|
-
s.name,
|
|
550
|
-
s.unit
|
|
551
|
-
]), l = t.get(c) ?? s;
|
|
552
|
-
l.points.push(i), t.set(c, l);
|
|
553
|
-
}
|
|
554
|
-
return {
|
|
555
|
-
resource: { attributes: Y(e.resource) },
|
|
556
|
-
scopeMetrics: [{
|
|
557
|
-
scope: {
|
|
558
|
-
name: S,
|
|
559
|
-
version: x
|
|
560
|
-
},
|
|
561
|
-
metrics: [...t.values()].map(qe)
|
|
562
|
-
}]
|
|
563
|
-
};
|
|
564
|
-
});
|
|
565
|
-
return {
|
|
566
|
-
body: JSON.stringify({ resourceMetrics: t }),
|
|
567
|
-
contentType: l
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
//#endregion
|
|
572
|
-
//#region src/transport/serializers/select.ts
|
|
573
|
-
function Ye(e) {
|
|
574
|
-
return e === "otlp" ? Be : e === "ecs" ? Ie : e;
|
|
575
|
-
}
|
|
576
|
-
function Z(e, t) {
|
|
577
|
-
return t.metricsEndpoint !== "" && e.records.length > 0 && e.records.every((e) => be(e, "log.type") === "metric") ? "metrics" : "logs";
|
|
578
|
-
}
|
|
579
|
-
function Xe(e, t) {
|
|
580
|
-
return e === "metrics" ? t.metricsEndpoint : t.endpoint;
|
|
581
|
-
}
|
|
582
|
-
function Ze(e, t, n, r) {
|
|
583
|
-
try {
|
|
584
|
-
return (Z(t, e) === "metrics" ? Je : Ye(e.serializer)).serialize(t.records);
|
|
585
|
-
} catch (e) {
|
|
586
|
-
n.report("transport.serialize_failed", r, { batchId: t.id }, e);
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
//#endregion
|
|
591
|
-
//#region src/transport/status-transport.ts
|
|
592
|
-
var Qe = class {
|
|
593
|
-
config;
|
|
594
|
-
diagnostics;
|
|
595
|
-
onSampling;
|
|
596
|
-
onLoss;
|
|
597
|
-
throttledUntil = {
|
|
598
|
-
logs: 0,
|
|
599
|
-
metrics: 0
|
|
600
|
-
};
|
|
601
|
-
constructor(e, t, n = () => void 0, r = () => void 0) {
|
|
602
|
-
this.config = e, this.diagnostics = t, this.onSampling = n, this.onLoss = r;
|
|
603
|
-
}
|
|
604
|
-
throttledForMs(e) {
|
|
605
|
-
return Math.max(0, this.throttledUntil[Z(e, this.config)] - Date.now());
|
|
606
|
-
}
|
|
607
|
-
serialize(e) {
|
|
608
|
-
let t = Ze(this.config, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
|
|
609
|
-
return t || this.onLoss("unserializable", e.records, [e.id]), t;
|
|
610
|
-
}
|
|
611
|
-
accept(e, t) {
|
|
612
|
-
this.throttledUntil[e] = 0, this.config.sampling.remote && t != null && this.onSampling(t);
|
|
613
|
-
}
|
|
614
|
-
reject(e, t, n, r) {
|
|
615
|
-
let i = String(e);
|
|
616
|
-
if (e === 401 || e === 403) {
|
|
617
|
-
let t = r.advice === void 0 ? "" : ` ${r.advice}`;
|
|
618
|
-
return this.diagnostics.report("transport.rejected_credentials", `The server returned ${i}.${t}`, {
|
|
619
|
-
status: e,
|
|
620
|
-
endpoint: Xe(n, this.config)
|
|
621
|
-
}), new G("permanent", `The server rejected the batch with ${i}.`, e);
|
|
622
|
-
}
|
|
623
|
-
if (e === 413) return new G("too_large", "The payload is too large.", e, void 0, r.maxBytes);
|
|
624
|
-
if (e === 429 || e === 503) {
|
|
625
|
-
let t = e === 429, i = r.retryAfterMs === void 0 ? void 0 : Math.min(r.retryAfterMs, _);
|
|
626
|
-
return this.throttledUntil[n] = Date.now() + (i ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: i }), new G("throttled", t ? "The server throttles the requests." : "The service is not available.", e, i);
|
|
627
|
-
}
|
|
628
|
-
return e === 408 || e >= 500 ? new G("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.`, {
|
|
629
|
-
batchId: t,
|
|
630
|
-
status: e
|
|
631
|
-
}), new G("permanent", `The server rejected the batch with ${i}.`, e));
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
//#endregion
|
|
635
|
-
//#region src/transport/custom-transport.ts
|
|
636
|
-
function $e(e, t, n) {
|
|
637
|
-
return {
|
|
638
|
-
kind: n,
|
|
639
|
-
body: t.body,
|
|
640
|
-
contentType: t.contentType,
|
|
641
|
-
batchId: e.id,
|
|
642
|
-
attempt: e.attempts,
|
|
643
|
-
records: e.records
|
|
644
|
-
};
|
|
645
|
-
}
|
|
646
|
-
function et(e) {
|
|
647
|
-
if (typeof e != "object" || !e) return !1;
|
|
648
|
-
let t = Reflect.get(e, "status");
|
|
649
|
-
return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
|
|
650
|
-
}
|
|
651
|
-
function tt(e) {
|
|
652
|
-
return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
|
|
653
|
-
}
|
|
654
|
-
var nt = class extends Qe {
|
|
655
|
-
async send(e) {
|
|
656
|
-
let { transport: t } = this.config;
|
|
657
|
-
if (!t || e.records.length === 0) return;
|
|
658
|
-
let n = this.serialize(e);
|
|
659
|
-
if (!n) return;
|
|
660
|
-
let r = Z(e, this.config), i = $e(e, n, r), a;
|
|
661
|
-
try {
|
|
662
|
-
a = await E(xe(() => M(() => he(() => t(i)))), p);
|
|
663
|
-
} catch (e) {
|
|
664
|
-
let t = e instanceof fe ? e : void 0;
|
|
665
|
-
throw new G(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
|
|
666
|
-
}
|
|
667
|
-
if (!et(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 G("transient", "The custom transport returned no valid status.");
|
|
668
|
-
let { status: o } = a;
|
|
669
|
-
if (o >= 200 && o < 300) this.accept(r, a.sampling);
|
|
670
|
-
else throw this.reject(o, e.id, r, {
|
|
671
|
-
retryAfterMs: tt(a.retryAfterMs),
|
|
672
|
-
maxBytes: tt(a.maxBytes)
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}, rt = class {
|
|
676
|
-
deps;
|
|
677
|
-
installed = !1;
|
|
678
|
-
keepaliveBytes = 0;
|
|
679
|
-
onVisibility = () => {
|
|
680
|
-
document.visibilityState === "hidden" && this.flush("hidden");
|
|
681
|
-
};
|
|
682
|
-
onPageHide = () => {
|
|
683
|
-
this.flush("pagehide");
|
|
684
|
-
};
|
|
685
|
-
onFreeze = () => {
|
|
686
|
-
this.flush("freeze");
|
|
687
|
-
};
|
|
688
|
-
onOpenFinClose = () => {
|
|
689
|
-
this.flush("openfin-close");
|
|
690
|
-
};
|
|
691
|
-
constructor(e) {
|
|
692
|
-
this.deps = e;
|
|
693
|
-
}
|
|
694
|
-
install() {
|
|
695
|
-
if (this.installed || typeof addEventListener > "u") return;
|
|
696
|
-
this.installed = !0, typeof document < "u" && (document.addEventListener("visibilitychange", this.onVisibility), document.addEventListener("freeze", this.onFreeze)), addEventListener("pagehide", this.onPageHide);
|
|
697
|
-
let e = k()?.me;
|
|
698
|
-
this.deps.diagnostics.guard("openfin.unavailable", "The library could not subscribe to close-requested.", () => {
|
|
699
|
-
e?.on?.("close-requested", this.onOpenFinClose);
|
|
700
|
-
});
|
|
701
|
-
}
|
|
702
|
-
uninstall() {
|
|
703
|
-
if (!this.installed) return;
|
|
704
|
-
this.installed = !1, typeof document < "u" && (document.removeEventListener("visibilitychange", this.onVisibility), document.removeEventListener("freeze", this.onFreeze)), removeEventListener("pagehide", this.onPageHide);
|
|
705
|
-
let e = k()?.me;
|
|
706
|
-
this.deps.diagnostics.guard("openfin.unavailable", "The library could not unsubscribe from close-requested.", () => {
|
|
707
|
-
e?.removeListener?.("close-requested", this.onOpenFinClose);
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
flush(e) {
|
|
711
|
-
let { config: t, diagnostics: n } = this.deps;
|
|
712
|
-
if (n.guard("pipeline.crashed", "The metric points before the exit flush failed.", () => {
|
|
713
|
-
this.deps.beforeExit?.();
|
|
714
|
-
}), e === "hidden") {
|
|
715
|
-
this.flushAlive();
|
|
716
|
-
return;
|
|
717
|
-
}
|
|
718
|
-
if (t.transport) {
|
|
719
|
-
this.flushCustom(e, t.transportOnExit);
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
let r = this.endpointUrl();
|
|
723
|
-
if (r !== null) {
|
|
724
|
-
this.keepaliveBytes = 0;
|
|
725
|
-
for (let n of this.deps.drainForExit()) {
|
|
726
|
-
let i = Z(n, t) === "metrics" ? t.metricsEndpoint : r.href;
|
|
727
|
-
this.flushBatch(n, e, new URL(i));
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
flushBatch(e, t, n) {
|
|
732
|
-
let { config: i, diagnostics: a } = this.deps;
|
|
733
|
-
if (e.records.length === 0) return;
|
|
734
|
-
let o = this.serialize(e, t);
|
|
735
|
-
if (!o) return;
|
|
736
|
-
if (O(o.body) > 6e4) {
|
|
737
|
-
R(e, a, this.deps.onLoss);
|
|
738
|
-
return;
|
|
739
|
-
}
|
|
740
|
-
n.searchParams.set(r, e.id), n.searchParams.set(d, t);
|
|
741
|
-
let s = n.toString(), c = this.deps.exitHeaders();
|
|
742
|
-
if (c) {
|
|
743
|
-
this.keepaliveFetch(s, e, o.body, t, () => {
|
|
744
|
-
let t = new Headers(c);
|
|
745
|
-
return t.set(m, o.contentType), t.set(g, e.id), t;
|
|
746
|
-
});
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
if (i.headers) {
|
|
750
|
-
R(e, a, this.deps.onLoss);
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
let l = this.beacon(s, o.body);
|
|
754
|
-
l !== "sent" && (l === "refused" ? R(e, a, this.deps.onLoss) : this.keepaliveFetch(s, e, o.body, t, () => new Headers({ [m]: f })));
|
|
755
|
-
}
|
|
756
|
-
flushAlive() {
|
|
757
|
-
let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
|
|
758
|
-
e.guard("pipeline.crashed", t, () => {
|
|
759
|
-
Promise.resolve(this.deps.flushAlive()).catch((n) => {
|
|
760
|
-
e.report("pipeline.crashed", t, void 0, n);
|
|
761
|
-
});
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
flushCustom(e, t) {
|
|
765
|
-
let { config: n, diagnostics: r } = this.deps;
|
|
766
|
-
for (let i of this.deps.drainForExit()) {
|
|
767
|
-
let a = this.serialize(i, e);
|
|
768
|
-
if (!a) continue;
|
|
769
|
-
let o = $e(i, a, Z(i, n));
|
|
770
|
-
(t === void 0 || r.guard("transport.http_error", "The transportOnExit hook threw an error.", () => M(() => t(o))) !== !0) && R(i, r, this.deps.onLoss);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
serialize(e, t) {
|
|
774
|
-
let n = Ze(this.deps.config, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
|
|
775
|
-
return n || this.deps.onLoss?.("unserializable", e.records, [e.id]), n;
|
|
776
|
-
}
|
|
777
|
-
endpointUrl() {
|
|
778
|
-
let { endpoint: e } = this.deps.config;
|
|
779
|
-
return e ? this.deps.diagnostics.guard("config.invalid", `The exit flush cannot use the endpoint ${e}.`, () => new URL(e)) ?? null : null;
|
|
780
|
-
}
|
|
781
|
-
beacon(e, t) {
|
|
782
|
-
return this.deps.diagnostics.guard("transport.http_error", "The sendBeacon call failed.", () => {
|
|
783
|
-
let n = globalThis.navigator;
|
|
784
|
-
return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
|
|
785
|
-
}) ?? "unavailable";
|
|
786
|
-
}
|
|
787
|
-
keepaliveFetch(e, t, n, r, i) {
|
|
788
|
-
let { config: a, diagnostics: o } = this.deps, s = () => {
|
|
789
|
-
R(t, o, this.deps.onLoss);
|
|
790
|
-
}, c = O(n);
|
|
791
|
-
this.keepaliveBytes + c > 6e4 ? s() : (this.keepaliveBytes += c, o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
|
|
792
|
-
method: "POST",
|
|
793
|
-
body: n,
|
|
794
|
-
headers: i(),
|
|
795
|
-
credentials: a.credentials,
|
|
796
|
-
keepalive: !0
|
|
797
|
-
}).catch((e) => {
|
|
798
|
-
o.report("transport.http_error", "The exit flush failed.", { reason: r }, e), s();
|
|
799
|
-
}), !0)) !== !0 && s());
|
|
800
|
-
}
|
|
801
|
-
};
|
|
802
|
-
//#endregion
|
|
803
|
-
//#region src/transport/compression.ts
|
|
804
|
-
async function it(e) {
|
|
805
|
-
let t = globalThis.CompressionStream;
|
|
806
|
-
if (t === void 0) return null;
|
|
807
|
-
let n = new Blob([e]).stream().pipeThrough(new t(h)), r = await new Response(n).arrayBuffer();
|
|
808
|
-
return new Uint8Array(r);
|
|
809
|
-
}
|
|
810
|
-
//#endregion
|
|
811
|
-
//#region src/transport/http-transport.ts
|
|
812
|
-
var at = "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.", ot = class extends Qe {
|
|
813
|
-
cachedHeaders;
|
|
814
|
-
async send(e, t) {
|
|
815
|
-
let { config: n } = this, r = Z(e, n), i = Xe(r, n);
|
|
816
|
-
i && e.records.length !== 0 && await this.post(e, r, i, t);
|
|
817
|
-
}
|
|
818
|
-
lastHeaders() {
|
|
819
|
-
let { headers: e } = this.config;
|
|
820
|
-
if (!e) return;
|
|
821
|
-
if (typeof e != "function") return e;
|
|
822
|
-
let t = this.cachedHeaders;
|
|
823
|
-
return t?.source === e && t.endpoint === this.config.endpoint && t.metricsEndpoint === this.config.metricsEndpoint ? t.headers : void 0;
|
|
824
|
-
}
|
|
825
|
-
async post(t, n, r, i) {
|
|
826
|
-
let a = this.serialize(t);
|
|
827
|
-
if (!a) return;
|
|
828
|
-
let o = await this.attempt(t, r, a, i);
|
|
829
|
-
if (this.rejectsCredentials(o.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, o = await this.attempt(t, r, a, i)), o.ok) {
|
|
830
|
-
this.accept(n, o.headers.get(ce));
|
|
831
|
-
return;
|
|
832
|
-
}
|
|
833
|
-
let s = o.status, c = Me(o.headers.get(e)), l = s === 413 ? await this.readMaxBytes(o) : void 0;
|
|
834
|
-
throw this.reject(s, t.id, n, {
|
|
835
|
-
retryAfterMs: c,
|
|
836
|
-
maxBytes: l,
|
|
837
|
-
advice: at
|
|
838
|
-
});
|
|
839
|
-
}
|
|
840
|
-
rejectsCredentials(e) {
|
|
841
|
-
return e === 401 || e === 403;
|
|
842
|
-
}
|
|
843
|
-
async attempt(e, t, n, r) {
|
|
844
|
-
let i = Date.now() + p, a = new Headers(await this.before(this.resolveHeaders(), i, t));
|
|
845
|
-
a.set(m, n.contentType), a.set(g, e.id), a.set(ne, String(e.attempts));
|
|
846
|
-
let o = await this.before(this.encodeBody(n.body), i, t);
|
|
847
|
-
typeof o != "string" && a.set(re, h);
|
|
848
|
-
let s = this.keepalive(o);
|
|
849
|
-
return s && r?.(), this.dispatch(t, a, o, i, s);
|
|
850
|
-
}
|
|
851
|
-
async before(e, t, n) {
|
|
852
|
-
try {
|
|
853
|
-
return await E(e, Math.max(0, t - Date.now()));
|
|
854
|
-
} catch {
|
|
855
|
-
throw this.timeout(n);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
timeout(e) {
|
|
859
|
-
let t = `The request took longer than ${String(p)} ms.`;
|
|
860
|
-
return this.diagnostics.report("transport.timeout", t, { endpoint: e }), new G("timeout", t);
|
|
861
|
-
}
|
|
862
|
-
async encodeBody(e) {
|
|
863
|
-
let { config: t } = this;
|
|
864
|
-
return t.compression !== "gzip" || O(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => it(e)) ?? e;
|
|
865
|
-
}
|
|
866
|
-
async dispatch(e, t, n, r, i) {
|
|
867
|
-
let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
|
|
868
|
-
o.abort();
|
|
869
|
-
}, Math.max(0, r - Date.now()));
|
|
870
|
-
D(s);
|
|
871
|
-
try {
|
|
872
|
-
return await M(() => fetch(e, {
|
|
873
|
-
method: "POST",
|
|
874
|
-
headers: t,
|
|
875
|
-
body: n,
|
|
876
|
-
credentials: a.credentials,
|
|
877
|
-
signal: o.signal,
|
|
878
|
-
cache: "no-store",
|
|
879
|
-
keepalive: i
|
|
880
|
-
}));
|
|
881
|
-
} catch {
|
|
882
|
-
throw o.signal.aborted ? this.timeout(e) : new G(_e() ? "transient" : "offline", "A network error occurred.");
|
|
883
|
-
} finally {
|
|
884
|
-
clearTimeout(s);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
keepalive(e) {
|
|
888
|
-
let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? O(e) : e.byteLength;
|
|
889
|
-
return t && n <= 6e4;
|
|
890
|
-
}
|
|
891
|
-
async readMaxBytes(e) {
|
|
892
|
-
return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
|
|
893
|
-
let t = JSON.parse(await e.text());
|
|
894
|
-
return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
|
|
895
|
-
});
|
|
896
|
-
}
|
|
897
|
-
async resolveHeaders() {
|
|
898
|
-
let { headers: e } = this.config;
|
|
899
|
-
if (!e) return {};
|
|
900
|
-
if (typeof e != "function") return e;
|
|
901
|
-
let { endpoint: t, metricsEndpoint: n } = this.config, r = await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e()));
|
|
902
|
-
return r && (this.cachedHeaders = {
|
|
903
|
-
source: e,
|
|
904
|
-
endpoint: t,
|
|
905
|
-
metricsEndpoint: n,
|
|
906
|
-
headers: r
|
|
907
|
-
}), r ?? {};
|
|
908
|
-
}
|
|
909
|
-
}, st = class {
|
|
910
|
-
storage;
|
|
911
|
-
transport;
|
|
912
|
-
diagnostics;
|
|
913
|
-
config;
|
|
914
|
-
batchesPerDrain;
|
|
915
|
-
onLoss;
|
|
916
|
-
timer = null;
|
|
917
|
-
attempt = 0;
|
|
918
|
-
draining = !1;
|
|
919
|
-
stopped = !1;
|
|
920
|
-
maxAttempts;
|
|
921
|
-
onOnline = () => {
|
|
922
|
-
this.attempt = 0, this.schedule(0);
|
|
923
|
-
};
|
|
924
|
-
constructor(e, t, n, r, i = 20, a = () => void 0) {
|
|
925
|
-
this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = N(r.retention).maxAttempts;
|
|
926
|
-
}
|
|
927
|
-
start() {
|
|
928
|
-
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(v);
|
|
929
|
-
}
|
|
930
|
-
nudge() {
|
|
931
|
-
this.draining || this.schedule(s);
|
|
932
|
-
}
|
|
933
|
-
async storeFailed(e, t) {
|
|
934
|
-
let n = this.toStorable(e, t);
|
|
935
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
936
|
-
n.length > 0 && this.nudge();
|
|
937
|
-
}
|
|
938
|
-
stop() {
|
|
939
|
-
this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
|
|
940
|
-
}
|
|
941
|
-
schedule(e) {
|
|
942
|
-
if (this.stopped) return;
|
|
943
|
-
this.clearTimer();
|
|
944
|
-
let t = setTimeout(() => {
|
|
945
|
-
this.drain();
|
|
946
|
-
}, e);
|
|
947
|
-
this.timer = t, D(t);
|
|
948
|
-
}
|
|
949
|
-
bounded(e) {
|
|
950
|
-
return E(e, C);
|
|
951
|
-
}
|
|
952
|
-
clearTimer() {
|
|
953
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
954
|
-
}
|
|
955
|
-
backoffMs() {
|
|
956
|
-
let e = Math.min(s * 2 ** this.attempt, _);
|
|
957
|
-
return Math.random() * e;
|
|
958
|
-
}
|
|
959
|
-
async drain() {
|
|
960
|
-
if (!this.draining) {
|
|
961
|
-
this.draining = !0;
|
|
962
|
-
try {
|
|
963
|
-
await P("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(v);
|
|
964
|
-
} finally {
|
|
965
|
-
this.draining = !1;
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
async drainLocked() {
|
|
970
|
-
try {
|
|
971
|
-
if (!_e()) return this.schedule(v), !0;
|
|
972
|
-
let e = await this.bounded(this.storage.take(this.batchesPerDrain));
|
|
973
|
-
if (e.length === 0) return this.schedule(v), !0;
|
|
974
|
-
let t = /* @__PURE__ */ new Set(), n = 0;
|
|
975
|
-
for (let r of e) {
|
|
976
|
-
if (this.stopped) return !0;
|
|
977
|
-
let e = Z(r, this.config);
|
|
978
|
-
if (t.has(e)) continue;
|
|
979
|
-
let i = await this.deliver(r);
|
|
980
|
-
if (i === "stop") return !0;
|
|
981
|
-
i !== "next" && (t.add(e), n = Math.max(n, i));
|
|
982
|
-
}
|
|
983
|
-
return t.size > 0 ? this.schedule(n) : this.schedule(e.length === this.batchesPerDrain ? 0 : v), !0;
|
|
984
|
-
} catch (e) {
|
|
985
|
-
return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
async deliver(e) {
|
|
989
|
-
if (e.attempts >= this.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
|
|
990
|
-
batchId: e.id,
|
|
991
|
-
records: e.records.length
|
|
992
|
-
}), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), "next";
|
|
993
|
-
try {
|
|
994
|
-
return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, "next";
|
|
995
|
-
} catch (t) {
|
|
996
|
-
let n = t instanceof G ? t : void 0;
|
|
997
|
-
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());
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
async replaceStored(e, t) {
|
|
1001
|
-
let n = this.toStorable(e, t);
|
|
1002
|
-
await this.bounded(this.storage.remove(e.id));
|
|
1003
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
1004
|
-
}
|
|
1005
|
-
toStorable(e, t) {
|
|
1006
|
-
let n = t instanceof G ? t : void 0;
|
|
1007
|
-
if (n?.kind === "permanent") return this.onLoss("rejected", e.records, [e.id]), [];
|
|
1008
|
-
if (n?.kind !== "too_large") return [e];
|
|
1009
|
-
let r = ve(e, this.diagnostics);
|
|
1010
|
-
return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
|
|
1011
|
-
from: e.records.length,
|
|
1012
|
-
to: r[0].records.length,
|
|
1013
|
-
serverMaxBytes: n.maxBytes
|
|
1014
|
-
}), r) : (this.diagnostics.report("transport.dropped_permanent", "One record is larger than the server limit. The library dropped it.", {
|
|
1015
|
-
batchId: e.id,
|
|
1016
|
-
bodies: e.records.map((e) => e.body)
|
|
1017
|
-
}), this.onLoss("rejected", e.records, [e.id]), []);
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
//#endregion
|
|
1021
|
-
//#region src/core/pipeline.ts
|
|
1022
|
-
function Q(e) {
|
|
1023
|
-
return e.attributes[oe] === le;
|
|
1024
|
-
}
|
|
1025
|
-
var $ = class {
|
|
1026
|
-
options;
|
|
1027
|
-
onFlush;
|
|
1028
|
-
pending = [];
|
|
1029
|
-
timer = null;
|
|
1030
|
-
constructor(e, t) {
|
|
1031
|
-
this.options = e, this.onFlush = t;
|
|
1032
|
-
}
|
|
1033
|
-
add(e) {
|
|
1034
|
-
this.pending.push(e), this.pending.length >= this.options.batchSize ? this.onFlush(this) : this.arm();
|
|
1035
|
-
}
|
|
1036
|
-
take() {
|
|
1037
|
-
this.clearTimer();
|
|
1038
|
-
let e = this.pending;
|
|
1039
|
-
return this.pending = [], e;
|
|
1040
|
-
}
|
|
1041
|
-
stop() {
|
|
1042
|
-
this.clearTimer();
|
|
1043
|
-
}
|
|
1044
|
-
arm() {
|
|
1045
|
-
if (this.timer !== null) return;
|
|
1046
|
-
let e = setTimeout(() => {
|
|
1047
|
-
this.timer = null, this.onFlush(this);
|
|
1048
|
-
}, this.options.flushIntervalMs);
|
|
1049
|
-
this.timer = e, D(e);
|
|
1050
|
-
}
|
|
1051
|
-
clearTimer() {
|
|
1052
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
1053
|
-
}
|
|
1054
|
-
}, ct = class {
|
|
1055
|
-
transport;
|
|
1056
|
-
storage;
|
|
1057
|
-
retry;
|
|
1058
|
-
diagnostics;
|
|
1059
|
-
streams;
|
|
1060
|
-
unconfirmed = /* @__PURE__ */ new Map();
|
|
1061
|
-
queue = [];
|
|
1062
|
-
open = /* @__PURE__ */ new Set();
|
|
1063
|
-
ceiling = new me();
|
|
1064
|
-
inFlight = 0;
|
|
1065
|
-
pumpScheduled = !1;
|
|
1066
|
-
stopped = !1;
|
|
1067
|
-
constructor(e, t, n, r, i) {
|
|
1068
|
-
this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
|
|
1069
|
-
let a = (e) => {
|
|
1070
|
-
this.claim(e);
|
|
1071
|
-
};
|
|
1072
|
-
this.streams = {
|
|
1073
|
-
logs: new $(i.logs, a),
|
|
1074
|
-
metrics: new $(i.metrics, a)
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
push(e) {
|
|
1078
|
-
this.stopped || (e.observedTimeUnixNano = pe(), this.route(e));
|
|
1079
|
-
}
|
|
1080
|
-
drainForExit() {
|
|
1081
|
-
let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
|
|
1082
|
-
this.unconfirmed.clear();
|
|
1083
|
-
let t = [...e.filter(Q), ...this.streams.metrics.take()], n = [...e.filter((e) => !Q(e)), ...this.streams.logs.take()];
|
|
1084
|
-
return [this.toBatch(t), this.toBatch(n)].filter((e) => e !== null);
|
|
1085
|
-
}
|
|
1086
|
-
async flushPending() {
|
|
1087
|
-
this.stopped || (this.claim(this.streams.metrics), this.claim(this.streams.logs)), await Promise.all([...this.open].map((e) => e.done));
|
|
1088
|
-
}
|
|
1089
|
-
destroy() {
|
|
1090
|
-
this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
|
|
1091
|
-
for (let e of this.open) e.resolve();
|
|
1092
|
-
this.open.clear();
|
|
1093
|
-
}
|
|
1094
|
-
toBatch(e) {
|
|
1095
|
-
return e.length === 0 ? null : {
|
|
1096
|
-
id: ge(this.diagnostics),
|
|
1097
|
-
records: e,
|
|
1098
|
-
createdAt: Date.now(),
|
|
1099
|
-
attempts: 0
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
route(e) {
|
|
1103
|
-
try {
|
|
1104
|
-
let t = Q(e) ? this.streams.metrics : this.streams.logs;
|
|
1105
|
-
if (!this.ceiling.allow(e)) {
|
|
1106
|
-
this.diagnostics.count("record.dropped_by_ceiling");
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
t.add(e);
|
|
1110
|
-
} catch (e) {
|
|
1111
|
-
this.diagnostics.report("pipeline.crashed", "The pipeline dropped a record before it reached a stream.", void 0, e);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
claim(e) {
|
|
1115
|
-
this.enqueue(this.toBatch(e.take()));
|
|
1116
|
-
}
|
|
1117
|
-
enqueue(e) {
|
|
1118
|
-
if (!e) return;
|
|
1119
|
-
let t, n = {
|
|
1120
|
-
batch: e,
|
|
1121
|
-
done: new Promise((e) => {
|
|
1122
|
-
t = e;
|
|
1123
|
-
}),
|
|
1124
|
-
resolve: t
|
|
1125
|
-
};
|
|
1126
|
-
this.unconfirmed.set(e.id, e), this.open.add(n), this.queue.push(n), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
|
|
1127
|
-
this.pumpScheduled = !1, this.pump();
|
|
1128
|
-
}));
|
|
1129
|
-
}
|
|
1130
|
-
pump() {
|
|
1131
|
-
for (; this.inFlight < 2;) {
|
|
1132
|
-
let e = this.queue.shift();
|
|
1133
|
-
if (!e) return;
|
|
1134
|
-
this.inFlight++, this.run(e);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
async run(e) {
|
|
1138
|
-
let { batch: t } = e;
|
|
1139
|
-
try {
|
|
1140
|
-
await this.dispatch(t);
|
|
1141
|
-
} catch (e) {
|
|
1142
|
-
this.diagnostics.report("pipeline.crashed", "A dispatch rejected its promise. This must not occur.", { batchId: t.id }, e);
|
|
1143
|
-
} finally {
|
|
1144
|
-
this.inFlight--, this.open.delete(e), e.resolve(), this.pump();
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
async dispatch(e) {
|
|
1148
|
-
try {
|
|
1149
|
-
let t = this.transport.throttledForMs(e);
|
|
1150
|
-
if (t > 0) {
|
|
1151
|
-
await this.store(e), this.diagnostics.report("transport.throttled", "The server throttles requests. The pipeline stored the batch and did not send it.", {
|
|
1152
|
-
batchId: e.id,
|
|
1153
|
-
records: e.records.length,
|
|
1154
|
-
throttledMs: t
|
|
1155
|
-
});
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
try {
|
|
1159
|
-
await this.transport.send(e, () => {
|
|
1160
|
-
this.unconfirmed.delete(e.id);
|
|
1161
|
-
});
|
|
1162
|
-
} catch (t) {
|
|
1163
|
-
await this.storeFailed({
|
|
1164
|
-
...e,
|
|
1165
|
-
attempts: e.attempts + 1
|
|
1166
|
-
}, t), this.diagnostics.report("transport.http_error", "The send failed. The pipeline stored the batch for a retry.", {
|
|
1167
|
-
batchId: e.id,
|
|
1168
|
-
records: e.records.length
|
|
1169
|
-
}, t);
|
|
1170
|
-
}
|
|
1171
|
-
} finally {
|
|
1172
|
-
this.unconfirmed.delete(e.id);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
async storeFailed(e, t) {
|
|
1176
|
-
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
1177
|
-
await this.retry.storeFailed(e, t);
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
async store(e) {
|
|
1181
|
-
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
1182
|
-
await E(this.storage.save(e), C), this.retry.nudge();
|
|
1183
|
-
});
|
|
1184
|
-
}
|
|
1185
|
-
}, lt = class e {
|
|
1186
|
-
storage;
|
|
1187
|
-
retry;
|
|
1188
|
-
pipeline;
|
|
1189
|
-
exitFlush;
|
|
1190
|
-
diagnostics;
|
|
1191
|
-
constructor(e, t, n, r, i) {
|
|
1192
|
-
this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
|
|
1193
|
-
}
|
|
1194
|
-
static async create(t) {
|
|
1195
|
-
let { config: n, diagnostics: r } = t, i = await je(n.storage, ie, N(n.retention), r, t.onGap), a = (e) => {
|
|
1196
|
-
let i = Se(e, r);
|
|
1197
|
-
i && Ce(t.remote, n, i);
|
|
1198
|
-
}, { onLoss: o } = t, s = n.transport ? void 0 : new ot(n, r, a, o), c = s ?? new nt(n, r, a, o), l = new st(i, c, r, n, 20, o), { batching: u } = n, d = new ct(c, i, l, r, {
|
|
1199
|
-
logs: {
|
|
1200
|
-
flushIntervalMs: u.logFlushIntervalMs,
|
|
1201
|
-
batchSize: u.logBatchSize
|
|
1202
|
-
},
|
|
1203
|
-
metrics: {
|
|
1204
|
-
flushIntervalMs: u.metricFlushIntervalMs,
|
|
1205
|
-
batchSize: u.metricBatchSize
|
|
1206
|
-
}
|
|
1207
|
-
}), f = new rt({
|
|
1208
|
-
config: n,
|
|
1209
|
-
diagnostics: r,
|
|
1210
|
-
drainForExit: () => d.drainForExit(),
|
|
1211
|
-
flushAlive: () => d.flushPending(),
|
|
1212
|
-
exitHeaders: () => s?.lastHeaders(),
|
|
1213
|
-
onLoss: o,
|
|
1214
|
-
beforeExit: t.beforeExit
|
|
1215
|
-
}), p = !1;
|
|
1216
|
-
try {
|
|
1217
|
-
f.install(), l.start(), p = !0;
|
|
1218
|
-
} finally {
|
|
1219
|
-
p || (f.uninstall(), l.stop());
|
|
1220
|
-
}
|
|
1221
|
-
let m = new e(i, l, d, f, r);
|
|
1222
|
-
return m.importEmergency(), m;
|
|
1223
|
-
}
|
|
1224
|
-
push(e) {
|
|
1225
|
-
this.pipeline.push(e);
|
|
1226
|
-
}
|
|
1227
|
-
async flush() {
|
|
1228
|
-
await this.pipeline.flushPending();
|
|
1229
|
-
}
|
|
1230
|
-
async queueDepth() {
|
|
1231
|
-
return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
|
|
1232
|
-
}
|
|
1233
|
-
async destroy() {
|
|
1234
|
-
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();
|
|
1235
|
-
}
|
|
1236
|
-
async importEmergency() {
|
|
1237
|
-
let e = await this.diagnostics.guardAsync("storage.degraded", "The emergency import failed.", () => Te(this.storage, this.diagnostics));
|
|
1238
|
-
e !== void 0 && e > 0 && this.retry.nudge();
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
//#endregion
|
|
1242
|
-
export { lt as Sender, z as i, U as n, B as r, H as t };
|
|
1243
|
-
|
|
1244
|
-
//# sourceMappingURL=sender-BUBWLn5i.js.map
|