@utk09/ui-observability 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -0
- package/README.md +83 -52
- package/dist/batch-4xKzzSCj.js +31 -0
- package/dist/batch-4xKzzSCj.js.map +1 -0
- package/dist/batch-cys7e53Q.cjs +2 -0
- package/dist/batch-cys7e53Q.cjs.map +1 -0
- package/dist/{bus-CtJWf9QN.cjs → bus-B6vzPmQM.cjs} +2 -2
- package/dist/{bus-CtJWf9QN.cjs.map → bus-B6vzPmQM.cjs.map} +1 -1
- package/dist/{bus-D8kH58tb.js → bus-DrixwdiX.js} +10 -10
- package/dist/{bus-D8kH58tb.js.map → bus-DrixwdiX.js.map} +1 -1
- package/dist/capture/network.d.ts +2 -0
- package/dist/capture/types.d.ts +3 -0
- package/dist/{console-DjLbryED.js → console-B3vGRW5p.js} +3 -3
- package/dist/{console-DjLbryED.js.map → console-B3vGRW5p.js.map} +1 -1
- package/dist/{console-BpHfWstv.cjs → console-ChfuJlf9.cjs} +2 -2
- package/dist/{console-BpHfWstv.cjs.map → console-ChfuJlf9.cjs.map} +1 -1
- package/dist/constants-Be83LICb.cjs +2 -0
- package/dist/constants-Be83LICb.cjs.map +1 -0
- package/dist/constants-CQ_D7jIW.js +144 -0
- package/dist/constants-CQ_D7jIW.js.map +1 -0
- package/dist/constants.d.ts +44 -11
- package/dist/core/diagnostics.d.ts +1 -1
- package/dist/core/drops.d.ts +29 -0
- package/dist/core/hold-buffer.d.ts +27 -0
- package/dist/core/meter.d.ts +45 -0
- package/dist/core/pipeline.d.ts +7 -19
- package/dist/core/record.d.ts +7 -0
- package/dist/core/runtime.d.ts +61 -8
- package/dist/core/sampling.d.ts +2 -0
- package/dist/core/sender.d.ts +6 -1
- 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/{errors-DH4QJS0u.js → errors-BGs5NOrw.js} +4 -4
- package/dist/{errors-DH4QJS0u.js.map → errors-BGs5NOrw.js.map} +1 -1
- package/dist/{errors-CpGRhhIf.cjs → errors-BMJm7KZZ.cjs} +2 -2
- package/dist/{errors-CpGRhhIf.cjs.map → errors-BMJm7KZZ.cjs.map} +1 -1
- package/dist/identity-DXyV86o-.cjs +2 -0
- package/dist/identity-DXyV86o-.cjs.map +1 -0
- package/dist/{deadline-B5DINjD5.js → identity-rpEyjvVg.js} +3 -26
- package/dist/identity-rpEyjvVg.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.js +683 -369
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-BXaPVPyG.cjs +2 -0
- package/dist/indexeddb-storage-BXaPVPyG.cjs.map +1 -0
- package/dist/{indexeddb-storage-n1qkFBGA.js → indexeddb-storage-Q9fDYlyn.js} +76 -47
- package/dist/indexeddb-storage-Q9fDYlyn.js.map +1 -0
- package/dist/{interactions-OU94MPXs.js → interactions-B8zjCjga.js} +2 -2
- package/dist/{interactions-OU94MPXs.js.map → interactions-B8zjCjga.js.map} +1 -1
- package/dist/{interactions-31eHGwEQ.cjs → interactions-BAGRmtrv.cjs} +2 -2
- package/dist/{interactions-31eHGwEQ.cjs.map → interactions-BAGRmtrv.cjs.map} +1 -1
- package/dist/journey-BGSyy8Es.cjs +2 -0
- package/dist/journey-BGSyy8Es.cjs.map +1 -0
- package/dist/{journey-CeJ1QoT2.js → journey-_dQQ1eMP.js} +27 -26
- package/dist/{journey-CeJ1QoT2.js.map → journey-_dQQ1eMP.js.map} +1 -1
- package/dist/library-request-BIG3Xpx3.cjs +2 -0
- package/dist/library-request-BIG3Xpx3.cjs.map +1 -0
- package/dist/library-request-DX6ev9oG.js +25 -0
- package/dist/library-request-DX6ev9oG.js.map +1 -0
- package/dist/{long-frames-C_7OutLs.js → long-frames-B0tKuChx.js} +3 -3
- package/dist/{long-frames-C_7OutLs.js.map → long-frames-B0tKuChx.js.map} +1 -1
- package/dist/{long-frames-B8VdA_ny.cjs → long-frames-Cq2LgNnp.cjs} +2 -2
- package/dist/{long-frames-B8VdA_ny.cjs.map → long-frames-Cq2LgNnp.cjs.map} +1 -1
- package/dist/models/batch.d.ts +14 -0
- package/dist/models/config.d.ts +169 -0
- package/dist/models/drop.d.ts +39 -0
- package/dist/models/metric.d.ts +50 -0
- package/dist/models/storage.d.ts +15 -3
- package/dist/network-C6kJbW6K.cjs +2 -0
- package/dist/network-C6kJbW6K.cjs.map +1 -0
- package/dist/network-CMnEvGJB.js +211 -0
- package/dist/network-CMnEvGJB.js.map +1 -0
- package/dist/{platform-D4wu1eIF.cjs → platform-DNOJjpOm.cjs} +2 -2
- package/dist/{platform-D4wu1eIF.cjs.map → platform-DNOJjpOm.cjs.map} +1 -1
- package/dist/{platform-IHBZGqUe.js → platform-j0uMPwHi.js} +3 -3
- package/dist/{platform-IHBZGqUe.js.map → platform-j0uMPwHi.js.map} +1 -1
- package/dist/{remote-rules-kuDf5gbe.cjs → remote-rules-DgoBJxZL.cjs} +2 -2
- package/dist/{remote-rules-kuDf5gbe.cjs.map → remote-rules-DgoBJxZL.cjs.map} +1 -1
- package/dist/{remote-rules-Bt1XsdEQ.js → remote-rules-UggoZqfP.js} +11 -11
- package/dist/{remote-rules-Bt1XsdEQ.js.map → remote-rules-UggoZqfP.js.map} +1 -1
- package/dist/{sampling-o0VY1mqQ.js → sampling-BLMD8EGM.js} +28 -27
- package/dist/sampling-BLMD8EGM.js.map +1 -0
- package/dist/sampling-MthcVXXU.cjs +2 -0
- package/dist/sampling-MthcVXXU.cjs.map +1 -0
- package/dist/{sanitize-B9UheVKc.js → sanitize-BNwgPj_B.js} +2 -2
- package/dist/{sanitize-B9UheVKc.js.map → sanitize-BNwgPj_B.js.map} +1 -1
- package/dist/{sanitize-DSIP7amZ.cjs → sanitize-BqzPc4Jg.cjs} +2 -2
- package/dist/{sanitize-DSIP7amZ.cjs.map → sanitize-BqzPc4Jg.cjs.map} +1 -1
- package/dist/sender--0_VzPbN.js +1249 -0
- package/dist/sender--0_VzPbN.js.map +1 -0
- package/dist/sender-SPGMqZjD.cjs +3 -0
- package/dist/sender-SPGMqZjD.cjs.map +1 -0
- package/dist/storage/emergency-queue.d.ts +4 -1
- package/dist/storage/eviction.d.ts +40 -0
- package/dist/storage/idb-driver.d.ts +6 -0
- package/dist/storage/indexeddb-storage.d.ts +13 -5
- package/dist/storage/local-storage.d.ts +24 -1
- package/dist/storage/memory-storage.d.ts +7 -0
- package/dist/{storm-Y-yuBhvv.cjs → storm-CTy1dfvs.cjs} +2 -2
- package/dist/{storm-Y-yuBhvv.cjs.map → storm-CTy1dfvs.cjs.map} +1 -1
- package/dist/{storm-BTw0J6eE.js → storm-knaj4GUH.js} +2 -2
- package/dist/{storm-BTw0J6eE.js.map → storm-knaj4GUH.js.map} +1 -1
- package/dist/transport/custom-transport.d.ts +3 -2
- package/dist/transport/exit-flush.d.ts +19 -2
- package/dist/transport/http-transport.d.ts +6 -4
- package/dist/transport/retry-engine.d.ts +9 -3
- package/dist/transport/serializers/otlp-metrics.d.ts +3 -0
- package/dist/transport/serializers/otlp.d.ts +30 -0
- package/dist/transport/serializers/select.d.ts +20 -4
- package/dist/transport/status-transport.d.ts +23 -12
- package/dist/utils/console.d.ts +4 -1
- package/dist/utils/library-request.d.ts +12 -0
- package/package.json +1 -1
- package/dist/constants-Br3b89Wg.cjs +0 -2
- package/dist/constants-Br3b89Wg.cjs.map +0 -1
- package/dist/constants-DM94FjVX.js +0 -96
- package/dist/constants-DM94FjVX.js.map +0 -1
- package/dist/deadline-B5DINjD5.js.map +0 -1
- package/dist/deadline-Cbg2cbUw.cjs +0 -2
- package/dist/deadline-Cbg2cbUw.cjs.map +0 -1
- package/dist/indexeddb-storage-DNdf1fmL.cjs +0 -2
- package/dist/indexeddb-storage-DNdf1fmL.cjs.map +0 -1
- package/dist/indexeddb-storage-n1qkFBGA.js.map +0 -1
- package/dist/journey-CE2EcwHW.cjs +0 -2
- package/dist/journey-CE2EcwHW.cjs.map +0 -1
- package/dist/library-request-C9uJFlbq.cjs +0 -2
- package/dist/library-request-C9uJFlbq.cjs.map +0 -1
- package/dist/library-request-DvhuplAB.js +0 -14
- package/dist/library-request-DvhuplAB.js.map +0 -1
- package/dist/network-BAV7ipyn.cjs +0 -2
- package/dist/network-BAV7ipyn.cjs.map +0 -1
- package/dist/network-D_lloS5t.js +0 -174
- package/dist/network-D_lloS5t.js.map +0 -1
- package/dist/sampling-BI15ds9D.cjs +0 -2
- package/dist/sampling-BI15ds9D.cjs.map +0 -1
- package/dist/sampling-o0VY1mqQ.js.map +0 -1
- package/dist/sender-BnNj9bOX.js +0 -1050
- package/dist/sender-BnNj9bOX.js.map +0 -1
- package/dist/sender-D0OsyB1c.cjs +0 -3
- package/dist/sender-D0OsyB1c.cjs.map +0 -1
package/dist/sender-BnNj9bOX.js
DELETED
|
@@ -1,1050 +0,0 @@
|
|
|
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
|
-
//#region src/models/batch.ts
|
|
8
|
-
function F(e) {
|
|
9
|
-
if (typeof e != "object" || !e) return !1;
|
|
10
|
-
let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
|
|
11
|
-
return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
|
|
12
|
-
}
|
|
13
|
-
function I(e, t) {
|
|
14
|
-
if (e.records.length < 2) return null;
|
|
15
|
-
let n = Math.floor(e.records.length / 2), r = (n) => ({
|
|
16
|
-
id: A(t),
|
|
17
|
-
records: n,
|
|
18
|
-
createdAt: e.createdAt,
|
|
19
|
-
attempts: e.attempts
|
|
20
|
-
});
|
|
21
|
-
return [r(e.records.slice(0, n)), r(e.records.slice(n))];
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/utils/lock.ts
|
|
25
|
-
function L(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
26
|
-
let i = globalThis.navigator?.locks;
|
|
27
|
-
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();
|
|
28
|
-
}
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/storage/keys.ts
|
|
31
|
-
function R(e, t) {
|
|
32
|
-
let n = [];
|
|
33
|
-
return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
|
|
34
|
-
for (let t = 0; t < localStorage.length; t++) {
|
|
35
|
-
let r = String(localStorage.key(t));
|
|
36
|
-
r.startsWith(e) && n.push(r);
|
|
37
|
-
}
|
|
38
|
-
}), n.sort();
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/storage/emergency-queue.ts
|
|
42
|
-
function ge(e) {
|
|
43
|
-
let t = String(e.createdAt).padStart(14, "0");
|
|
44
|
-
return `${n}${t}.${e.id}`;
|
|
45
|
-
}
|
|
46
|
-
function _e(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 : F(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
|
|
49
|
-
}
|
|
50
|
-
async function ve(e, t) {
|
|
51
|
-
let r = 0;
|
|
52
|
-
for (let i of R(n, t)) {
|
|
53
|
-
let n = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
|
|
54
|
-
let e = localStorage.getItem(i);
|
|
55
|
-
return localStorage.removeItem(i), e;
|
|
56
|
-
});
|
|
57
|
-
if (!n) continue;
|
|
58
|
-
let a = _e(n, t);
|
|
59
|
-
if (a !== null) try {
|
|
60
|
-
await O(e.save(a), T), r++;
|
|
61
|
-
} catch (e) {
|
|
62
|
-
t.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return r;
|
|
66
|
-
}
|
|
67
|
-
function z(e, t) {
|
|
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
|
-
localStorage.setItem(ge(e), JSON.stringify(e));
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function ye(e, t) {
|
|
76
|
-
return await L("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
|
|
77
|
-
}
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/storage/local-storage.ts
|
|
80
|
-
function be(e) {
|
|
81
|
-
let t = String(e.createdAt).padStart(14, "0");
|
|
82
|
-
return `${g}${t}.${e.id}`;
|
|
83
|
-
}
|
|
84
|
-
function xe(e) {
|
|
85
|
-
let t = g.length, n = Number(e.slice(t, t + 14));
|
|
86
|
-
return Number.isFinite(n) ? n : null;
|
|
87
|
-
}
|
|
88
|
-
var Se = class {
|
|
89
|
-
limits;
|
|
90
|
-
diagnostics;
|
|
91
|
-
onGap;
|
|
92
|
-
name = ie;
|
|
93
|
-
constructor(e, t, n) {
|
|
94
|
-
this.limits = e, this.diagnostics = t, this.onGap = n;
|
|
95
|
-
}
|
|
96
|
-
async save(e) {
|
|
97
|
-
this.write(e, "localStorage refused a batch, evicting the oldest") ? await this.prune() : (this.evictForQuota(), this.write(e, "localStorage refused a batch even after evicting") || this.reportGap({
|
|
98
|
-
batches: 1,
|
|
99
|
-
records: e.records.length,
|
|
100
|
-
reason: "quota"
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
take(e) {
|
|
104
|
-
let t = [];
|
|
105
|
-
for (let n of this.keys().slice(0, e)) {
|
|
106
|
-
let e = this.read(n);
|
|
107
|
-
e === null ? this.removeKey(n) : t.push(e);
|
|
108
|
-
}
|
|
109
|
-
return Promise.resolve(t);
|
|
110
|
-
}
|
|
111
|
-
remove(e) {
|
|
112
|
-
let t = this.keyOf(e);
|
|
113
|
-
return t !== null && this.removeKey(t), Promise.resolve();
|
|
114
|
-
}
|
|
115
|
-
bumpAttempts(e, t) {
|
|
116
|
-
let n = this.keyOf(e);
|
|
117
|
-
if (n === null) return Promise.resolve();
|
|
118
|
-
let r = this.read(n);
|
|
119
|
-
return r === null || (r.attempts = t, this.diagnostics.guard("storage.degraded", "The library could not update the attempt count.", () => {
|
|
120
|
-
localStorage.setItem(n, JSON.stringify(r));
|
|
121
|
-
})), Promise.resolve();
|
|
122
|
-
}
|
|
123
|
-
prune() {
|
|
124
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
125
|
-
batches: 0,
|
|
126
|
-
records: 0,
|
|
127
|
-
reason: "expired"
|
|
128
|
-
}, n = (e) => {
|
|
129
|
-
let n = this.read(e);
|
|
130
|
-
this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
|
|
131
|
-
}, r = [];
|
|
132
|
-
for (let t of this.keys()) {
|
|
133
|
-
let i = xe(t);
|
|
134
|
-
i === null || i < e ? n(t) : r.push(t);
|
|
135
|
-
}
|
|
136
|
-
let i = r.length - this.limits.maxBatches;
|
|
137
|
-
if (i > 0) {
|
|
138
|
-
t.reason = "over_capacity";
|
|
139
|
-
for (let e of r.slice(0, i)) n(e);
|
|
140
|
-
}
|
|
141
|
-
return this.reportGap(t), Promise.resolve(t);
|
|
142
|
-
}
|
|
143
|
-
count() {
|
|
144
|
-
return Promise.resolve(this.keys().length);
|
|
145
|
-
}
|
|
146
|
-
clear() {
|
|
147
|
-
return this.evict(this.keys()), Promise.resolve();
|
|
148
|
-
}
|
|
149
|
-
close() {
|
|
150
|
-
return Promise.resolve();
|
|
151
|
-
}
|
|
152
|
-
write(e, t) {
|
|
153
|
-
return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(be(e), JSON.stringify(e)), !0)) === !0;
|
|
154
|
-
}
|
|
155
|
-
evictForQuota() {
|
|
156
|
-
let e = this.keys(), t = {
|
|
157
|
-
batches: 0,
|
|
158
|
-
records: 0,
|
|
159
|
-
reason: "quota"
|
|
160
|
-
};
|
|
161
|
-
for (let n of e.slice(0, Math.ceil(e.length / 4))) {
|
|
162
|
-
let e = this.read(n);
|
|
163
|
-
this.removeKey(n), t.batches++, t.records += e?.records.length ?? 0;
|
|
164
|
-
}
|
|
165
|
-
this.reportGap(t);
|
|
166
|
-
}
|
|
167
|
-
reportGap(e) {
|
|
168
|
-
e.batches !== 0 && (this.diagnostics.report("storage.evicted", `The library dropped ${String(e.batches)} stored batches (${String(e.records)} records).`, { ...e }), this.onGap?.(e));
|
|
169
|
-
}
|
|
170
|
-
read(e) {
|
|
171
|
-
let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
|
|
172
|
-
if (!t) return null;
|
|
173
|
-
let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
|
|
174
|
-
return n === void 0 ? null : F(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
|
|
175
|
-
}
|
|
176
|
-
keyOf(e) {
|
|
177
|
-
return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
|
|
178
|
-
}
|
|
179
|
-
evict(e) {
|
|
180
|
-
for (let t of e) this.removeKey(t);
|
|
181
|
-
}
|
|
182
|
-
removeKey(e) {
|
|
183
|
-
this.diagnostics.guard("storage.degraded", "The library could not remove a stored batch.", () => {
|
|
184
|
-
localStorage.removeItem(e);
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
keys() {
|
|
188
|
-
return R(g, this.diagnostics);
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/storage/memory-storage.ts
|
|
193
|
-
function B(e) {
|
|
194
|
-
return e.reduce((e, t) => e + t.records.length, 0);
|
|
195
|
-
}
|
|
196
|
-
var V = class {
|
|
197
|
-
limits;
|
|
198
|
-
onGap;
|
|
199
|
-
name = ce;
|
|
200
|
-
batches = [];
|
|
201
|
-
constructor(e, t) {
|
|
202
|
-
this.limits = e, this.onGap = t;
|
|
203
|
-
}
|
|
204
|
-
async save(e) {
|
|
205
|
-
this.batches.push(e), await this.prune();
|
|
206
|
-
}
|
|
207
|
-
take(e) {
|
|
208
|
-
return Promise.resolve(this.batches.slice(0, e));
|
|
209
|
-
}
|
|
210
|
-
remove(e) {
|
|
211
|
-
return this.batches = this.batches.filter((t) => t.id !== e), Promise.resolve();
|
|
212
|
-
}
|
|
213
|
-
bumpAttempts(e, t) {
|
|
214
|
-
let n = this.batches.find((t) => t.id === e);
|
|
215
|
-
return n && (n.attempts = t), Promise.resolve();
|
|
216
|
-
}
|
|
217
|
-
prune() {
|
|
218
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
219
|
-
batches: 0,
|
|
220
|
-
records: 0,
|
|
221
|
-
reason: "expired"
|
|
222
|
-
}, n = this.batches.filter((t) => t.createdAt < e);
|
|
223
|
-
this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += B(n);
|
|
224
|
-
let r = this.batches.length - this.limits.maxBatches;
|
|
225
|
-
if (r > 0) {
|
|
226
|
-
t.reason = "over_capacity";
|
|
227
|
-
let e = this.batches.slice(0, r);
|
|
228
|
-
this.batches = this.batches.slice(r), t.batches += e.length, t.records += B(e);
|
|
229
|
-
}
|
|
230
|
-
return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
|
|
231
|
-
}
|
|
232
|
-
count() {
|
|
233
|
-
return Promise.resolve(this.batches.length);
|
|
234
|
-
}
|
|
235
|
-
clear() {
|
|
236
|
-
return this.batches = [], Promise.resolve();
|
|
237
|
-
}
|
|
238
|
-
close() {
|
|
239
|
-
return this.batches = [], Promise.resolve();
|
|
240
|
-
}
|
|
241
|
-
}, Ce = {
|
|
242
|
-
name: re,
|
|
243
|
-
save: () => Promise.resolve(),
|
|
244
|
-
take: () => Promise.resolve([]),
|
|
245
|
-
remove: () => Promise.resolve(),
|
|
246
|
-
bumpAttempts: () => Promise.resolve(),
|
|
247
|
-
prune: () => Promise.resolve({
|
|
248
|
-
batches: 0,
|
|
249
|
-
records: 0,
|
|
250
|
-
reason: "expired"
|
|
251
|
-
}),
|
|
252
|
-
count: () => Promise.resolve(0),
|
|
253
|
-
clear: () => Promise.resolve(),
|
|
254
|
-
close: () => Promise.resolve()
|
|
255
|
-
};
|
|
256
|
-
function we(e) {
|
|
257
|
-
return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
|
|
258
|
-
}
|
|
259
|
-
function Te(e) {
|
|
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
|
-
}
|
|
262
|
-
async function Ee(e, t, n, r, i) {
|
|
263
|
-
if (e === "none") return Ce;
|
|
264
|
-
if (e === "memory") return new V(n, i);
|
|
265
|
-
if (e === "indexeddb" || e === "auto") {
|
|
266
|
-
if (we(r)) {
|
|
267
|
-
let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
|
|
268
|
-
let { IndexedDbStorage: e } = await import("./indexeddb-storage-n1qkFBGA.js"), a = new e(t, n, r, i);
|
|
269
|
-
return await a.open(), a;
|
|
270
|
-
});
|
|
271
|
-
if (e) return e;
|
|
272
|
-
}
|
|
273
|
-
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new V(n, i);
|
|
274
|
-
}
|
|
275
|
-
return Te(r) ? new Se(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new V(n, i));
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/transport/errors.ts
|
|
279
|
-
var H = class extends Error {
|
|
280
|
-
kind;
|
|
281
|
-
status;
|
|
282
|
-
retryAfterMs;
|
|
283
|
-
maxBytes;
|
|
284
|
-
constructor(e, t, n, r, i, a) {
|
|
285
|
-
super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
function De(e) {
|
|
289
|
-
if (!e) return;
|
|
290
|
-
let t = Number(e);
|
|
291
|
-
if (Number.isFinite(t)) return Math.max(0, t * b);
|
|
292
|
-
let n = Date.parse(e);
|
|
293
|
-
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
294
|
-
}
|
|
295
|
-
//#endregion
|
|
296
|
-
//#region src/transport/serializers/ecs.ts
|
|
297
|
-
function Oe(e) {
|
|
298
|
-
return ue.test(e) ? Number(BigInt(e) / fe) : Date.now();
|
|
299
|
-
}
|
|
300
|
-
function ke(e) {
|
|
301
|
-
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
|
|
302
|
-
}
|
|
303
|
-
function Ae(e, t, n) {
|
|
304
|
-
let r = e[t];
|
|
305
|
-
r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
|
|
306
|
-
}
|
|
307
|
-
function U(e, t, n, r) {
|
|
308
|
-
let i = ke(n);
|
|
309
|
-
if (i !== null) Ae(e, t, i);
|
|
310
|
-
else if (typeof n == "object" && n && !r.has(n)) {
|
|
311
|
-
if (r.add(n), Array.isArray(n)) for (let i of n) U(e, t, i, r);
|
|
312
|
-
else for (let [i, a] of Object.entries(n)) U(e, `${t}.${i}`, a, r);
|
|
313
|
-
r.delete(n);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
function W(e) {
|
|
317
|
-
let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
|
|
318
|
-
for (let [r, i] of Object.entries(e)) U(t, r, i, n);
|
|
319
|
-
return t;
|
|
320
|
-
}
|
|
321
|
-
var je = {
|
|
322
|
-
name: "ecs",
|
|
323
|
-
serialize(e) {
|
|
324
|
-
return {
|
|
325
|
-
body: `${e.map((e) => {
|
|
326
|
-
let t = Oe(e.timeUnixNano);
|
|
327
|
-
return JSON.stringify({
|
|
328
|
-
"@timestamp": new Date(t).toISOString(),
|
|
329
|
-
message: e.body,
|
|
330
|
-
log: { level: d[e.severityText] ?? e.severityText.toLowerCase() },
|
|
331
|
-
trace: { id: e.traceId },
|
|
332
|
-
span: { id: e.spanId },
|
|
333
|
-
service: {
|
|
334
|
-
name: e.resource[s],
|
|
335
|
-
version: e.resource[f],
|
|
336
|
-
environment: e.resource[l]
|
|
337
|
-
},
|
|
338
|
-
user_agent: { original: e.resource[C] },
|
|
339
|
-
url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
|
|
340
|
-
labels: {
|
|
341
|
-
...W(e.resource),
|
|
342
|
-
...W(e.attributes)
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
}).join("\n")}\n`,
|
|
346
|
-
contentType: S
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region src/transport/serializers/otlp.ts
|
|
352
|
-
function G(e) {
|
|
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
|
-
}
|
|
355
|
-
function K(e) {
|
|
356
|
-
let t = [];
|
|
357
|
-
for (let [n, r] of Object.entries(e)) {
|
|
358
|
-
let e = G(r);
|
|
359
|
-
e && t.push({
|
|
360
|
-
key: n,
|
|
361
|
-
value: e
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
return t;
|
|
365
|
-
}
|
|
366
|
-
var q = /* @__PURE__ */ new WeakMap();
|
|
367
|
-
function Me(e) {
|
|
368
|
-
let t = q.get(e);
|
|
369
|
-
if (t !== void 0) return t;
|
|
370
|
-
let n = JSON.stringify(e);
|
|
371
|
-
return q.set(e, n), n;
|
|
372
|
-
}
|
|
373
|
-
var Ne = {
|
|
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
|
-
});
|
|
383
|
-
}
|
|
384
|
-
let r = [...n.values()].map((e) => ({
|
|
385
|
-
resource: { attributes: K(e.resource) },
|
|
386
|
-
scopeLogs: [{
|
|
387
|
-
scope: {
|
|
388
|
-
name: v,
|
|
389
|
-
version: ae
|
|
390
|
-
},
|
|
391
|
-
logRecords: e.records.map((e) => ({
|
|
392
|
-
timeUnixNano: e.timeUnixNano,
|
|
393
|
-
observedTimeUnixNano: e.observedTimeUnixNano ?? e.timeUnixNano,
|
|
394
|
-
severityNumber: e.severityNumber,
|
|
395
|
-
severityText: e.severityText,
|
|
396
|
-
body: { stringValue: e.body },
|
|
397
|
-
traceId: e.traceId,
|
|
398
|
-
spanId: e.spanId,
|
|
399
|
-
flags: e.traceFlags,
|
|
400
|
-
attributes: K(e.attributes)
|
|
401
|
-
}))
|
|
402
|
-
}]
|
|
403
|
-
}));
|
|
404
|
-
return {
|
|
405
|
-
body: JSON.stringify({ resourceLogs: r }),
|
|
406
|
-
contentType: e
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
//#endregion
|
|
411
|
-
//#region src/transport/serializers/select.ts
|
|
412
|
-
function Pe(e) {
|
|
413
|
-
return e === "otlp" ? Ne : e === "ecs" ? je : e;
|
|
414
|
-
}
|
|
415
|
-
function J(e, t, n, r) {
|
|
416
|
-
try {
|
|
417
|
-
return Pe(e).serialize(t.records);
|
|
418
|
-
} catch (e) {
|
|
419
|
-
n.report("transport.serialize_failed", r, { batchId: t.id }, e);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region src/transport/status-transport.ts
|
|
425
|
-
var Y = class {
|
|
426
|
-
config;
|
|
427
|
-
diagnostics;
|
|
428
|
-
onSampling;
|
|
429
|
-
throttledUntil = 0;
|
|
430
|
-
constructor(e, t, n = () => void 0) {
|
|
431
|
-
this.config = e, this.diagnostics = t, this.onSampling = n;
|
|
432
|
-
}
|
|
433
|
-
throttledForMs() {
|
|
434
|
-
return Math.max(0, this.throttledUntil - Date.now());
|
|
435
|
-
}
|
|
436
|
-
serialize(e) {
|
|
437
|
-
return J(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
|
|
438
|
-
}
|
|
439
|
-
accept(e) {
|
|
440
|
-
this.throttledUntil = 0, this.config.sampling.remote && e != null && this.onSampling(e);
|
|
441
|
-
}
|
|
442
|
-
reject(e, t, n) {
|
|
443
|
-
let r = String(e);
|
|
444
|
-
if (e === 401 || e === 403) {
|
|
445
|
-
let t = n.advice === void 0 ? "" : ` ${n.advice}`;
|
|
446
|
-
return this.diagnostics.report("transport.rejected_credentials", `The server returned ${r}.${t}`, {
|
|
447
|
-
status: e,
|
|
448
|
-
endpoint: this.config.endpoint
|
|
449
|
-
}), new H("permanent", `The server rejected the batch with ${r}.`, e);
|
|
450
|
-
}
|
|
451
|
-
if (e === 413) return new H("too_large", "The payload is too large.", e, void 0, n.maxBytes);
|
|
452
|
-
if (e === 429 || e === 503) {
|
|
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
|
-
}
|
|
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
|
-
batchId: t,
|
|
458
|
-
status: e
|
|
459
|
-
}), new H("permanent", `The server rejected the batch with ${r}.`, e));
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
//#endregion
|
|
463
|
-
//#region src/transport/custom-transport.ts
|
|
464
|
-
function X(e, t) {
|
|
465
|
-
return {
|
|
466
|
-
body: t.body,
|
|
467
|
-
contentType: t.contentType,
|
|
468
|
-
batchId: e.id,
|
|
469
|
-
attempt: e.attempts,
|
|
470
|
-
records: e.records
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
function Fe(e) {
|
|
474
|
-
if (typeof e != "object" || !e) return !1;
|
|
475
|
-
let t = Reflect.get(e, "status");
|
|
476
|
-
return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
|
|
477
|
-
}
|
|
478
|
-
function Z(e) {
|
|
479
|
-
return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
|
|
480
|
-
}
|
|
481
|
-
var Ie = class extends Y {
|
|
482
|
-
async send(e) {
|
|
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
|
-
try {
|
|
489
|
-
a = await O(P(() => he(() => n(i))), t);
|
|
490
|
-
} catch (e) {
|
|
491
|
-
let t = e instanceof j ? e : void 0;
|
|
492
|
-
throw new H(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
|
|
493
|
-
}
|
|
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.");
|
|
495
|
-
let { status: o } = a;
|
|
496
|
-
if (o >= 200 && o < 300) this.accept(a.sampling);
|
|
497
|
-
else throw this.reject(o, e.id, {
|
|
498
|
-
retryAfterMs: Z(a.retryAfterMs),
|
|
499
|
-
maxBytes: Z(a.maxBytes)
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
}, Le = class {
|
|
503
|
-
deps;
|
|
504
|
-
installed = !1;
|
|
505
|
-
onVisibility = () => {
|
|
506
|
-
document.visibilityState === "hidden" && this.flush("hidden");
|
|
507
|
-
};
|
|
508
|
-
onPageHide = () => {
|
|
509
|
-
this.flush("pagehide");
|
|
510
|
-
};
|
|
511
|
-
onFreeze = () => {
|
|
512
|
-
this.flush("freeze");
|
|
513
|
-
};
|
|
514
|
-
onOpenFinClose = () => {
|
|
515
|
-
this.flush("openfin-close");
|
|
516
|
-
};
|
|
517
|
-
constructor(e) {
|
|
518
|
-
this.deps = e;
|
|
519
|
-
}
|
|
520
|
-
install() {
|
|
521
|
-
if (this.installed || typeof addEventListener > "u") return;
|
|
522
|
-
this.installed = !0, typeof document < "u" && (document.addEventListener("visibilitychange", this.onVisibility), document.addEventListener("freeze", this.onFreeze)), addEventListener("pagehide", this.onPageHide);
|
|
523
|
-
let e = globalThis.fin?.me;
|
|
524
|
-
this.deps.diagnostics.guard("openfin.unavailable", "The library could not subscribe to close-requested.", () => {
|
|
525
|
-
e?.on?.("close-requested", this.onOpenFinClose);
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
uninstall() {
|
|
529
|
-
if (!this.installed) return;
|
|
530
|
-
this.installed = !1, typeof document < "u" && (document.removeEventListener("visibilitychange", this.onVisibility), document.removeEventListener("freeze", this.onFreeze)), removeEventListener("pagehide", this.onPageHide);
|
|
531
|
-
let e = globalThis.fin?.me;
|
|
532
|
-
this.deps.diagnostics.guard("openfin.unavailable", "The library could not unsubscribe from close-requested.", () => {
|
|
533
|
-
e?.removeListener?.("close-requested", this.onOpenFinClose);
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
flush(e) {
|
|
537
|
-
let { config: t, diagnostics: n } = this.deps;
|
|
538
|
-
if (e === "hidden") {
|
|
539
|
-
this.flushAlive();
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
if (t.transport) {
|
|
543
|
-
this.flushCustom(e, t.transportOnExit);
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
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
|
-
});
|
|
563
|
-
return;
|
|
564
|
-
}
|
|
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
|
-
});
|
|
579
|
-
}
|
|
580
|
-
flushCustom(e, t) {
|
|
581
|
-
let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
|
|
582
|
-
if (!r || r.records.length === 0) return;
|
|
583
|
-
let i = this.serialize(r, e);
|
|
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);
|
|
585
|
-
}
|
|
586
|
-
serialize(e, t) {
|
|
587
|
-
return J(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
|
|
588
|
-
}
|
|
589
|
-
endpointUrl() {
|
|
590
|
-
let { endpoint: e } = this.deps.config;
|
|
591
|
-
return e ? this.deps.diagnostics.guard("config.invalid", `The exit flush cannot use the endpoint ${e}.`, () => new URL(e)) ?? null : null;
|
|
592
|
-
}
|
|
593
|
-
beacon(e, t) {
|
|
594
|
-
return this.deps.diagnostics.guard("transport.http_error", "The sendBeacon call failed.", () => {
|
|
595
|
-
let n = globalThis.navigator;
|
|
596
|
-
return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
|
|
597
|
-
}) ?? "unavailable";
|
|
598
|
-
}
|
|
599
|
-
keepaliveFetch(e, t, n, r) {
|
|
600
|
-
let { config: i, diagnostics: a } = this.deps;
|
|
601
|
-
a.guard("transport.http_error", "The keepalive fetch failed.", () => {
|
|
602
|
-
fetch(e, {
|
|
603
|
-
method: "POST",
|
|
604
|
-
body: t,
|
|
605
|
-
headers: r(),
|
|
606
|
-
credentials: i.credentials,
|
|
607
|
-
keepalive: !0
|
|
608
|
-
}).catch((e) => {
|
|
609
|
-
a.report("transport.http_error", "The exit flush failed.", { reason: n }, e);
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
};
|
|
614
|
-
//#endregion
|
|
615
|
-
//#region src/transport/compression.ts
|
|
616
|
-
async function Re(e) {
|
|
617
|
-
let t = globalThis.CompressionStream;
|
|
618
|
-
if (t === void 0) return null;
|
|
619
|
-
let n = new Blob([e]).stream().pipeThrough(new t(p)), r = await new Response(n).arrayBuffer();
|
|
620
|
-
return new Uint8Array(r);
|
|
621
|
-
}
|
|
622
|
-
//#endregion
|
|
623
|
-
//#region src/transport/http-transport.ts
|
|
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 {
|
|
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));
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
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,
|
|
649
|
-
advice: Q
|
|
650
|
-
});
|
|
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
|
-
}
|
|
674
|
-
async encodeBody(e) {
|
|
675
|
-
let { config: t } = this;
|
|
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;
|
|
677
|
-
}
|
|
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);
|
|
683
|
-
try {
|
|
684
|
-
return await P(() => fetch(e, {
|
|
685
|
-
method: "POST",
|
|
686
|
-
headers: t,
|
|
687
|
-
body: n,
|
|
688
|
-
credentials: a.credentials,
|
|
689
|
-
signal: o.signal,
|
|
690
|
-
cache: "no-store",
|
|
691
|
-
keepalive: i
|
|
692
|
-
}));
|
|
693
|
-
} catch {
|
|
694
|
-
if (o.signal.aborted) throw this.timeout();
|
|
695
|
-
let e = globalThis.navigator?.onLine;
|
|
696
|
-
throw new H(e === !1 ? "offline" : "transient", "A network error occurred.");
|
|
697
|
-
} finally {
|
|
698
|
-
clearTimeout(s);
|
|
699
|
-
}
|
|
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
|
-
}
|
|
705
|
-
async readMaxBytes(e) {
|
|
706
|
-
return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
|
|
707
|
-
let t = JSON.parse(await e.text());
|
|
708
|
-
return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
|
|
709
|
-
});
|
|
710
|
-
}
|
|
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 ?? {};
|
|
721
|
-
}
|
|
722
|
-
}, Be = class {
|
|
723
|
-
storage;
|
|
724
|
-
transport;
|
|
725
|
-
diagnostics;
|
|
726
|
-
config;
|
|
727
|
-
batchesPerDrain;
|
|
728
|
-
timer = null;
|
|
729
|
-
attempt = 0;
|
|
730
|
-
draining = !1;
|
|
731
|
-
stopped = !1;
|
|
732
|
-
onOnline = () => {
|
|
733
|
-
this.attempt = 0, this.schedule(0);
|
|
734
|
-
};
|
|
735
|
-
constructor(e, t, n, r, i = 20) {
|
|
736
|
-
this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
|
|
737
|
-
}
|
|
738
|
-
start() {
|
|
739
|
-
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(i);
|
|
740
|
-
}
|
|
741
|
-
nudge() {
|
|
742
|
-
this.draining || this.schedule(m);
|
|
743
|
-
}
|
|
744
|
-
async storeFailed(e, t) {
|
|
745
|
-
let n = this.toStorable(e, t);
|
|
746
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
747
|
-
n.length > 0 && this.nudge();
|
|
748
|
-
}
|
|
749
|
-
stop() {
|
|
750
|
-
this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
|
|
751
|
-
}
|
|
752
|
-
schedule(e) {
|
|
753
|
-
if (this.stopped) return;
|
|
754
|
-
this.clearTimer();
|
|
755
|
-
let t = setTimeout(() => {
|
|
756
|
-
this.drain();
|
|
757
|
-
}, e);
|
|
758
|
-
this.timer = t, k(t);
|
|
759
|
-
}
|
|
760
|
-
bounded(e) {
|
|
761
|
-
return O(e, T);
|
|
762
|
-
}
|
|
763
|
-
clearTimer() {
|
|
764
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
765
|
-
}
|
|
766
|
-
backoffMs() {
|
|
767
|
-
let e = Math.min(m * 2 ** this.attempt, o);
|
|
768
|
-
return Math.random() * e;
|
|
769
|
-
}
|
|
770
|
-
async drain() {
|
|
771
|
-
if (!this.draining) {
|
|
772
|
-
this.draining = !0;
|
|
773
|
-
try {
|
|
774
|
-
await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(i);
|
|
775
|
-
} finally {
|
|
776
|
-
this.draining = !1;
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
async drainLocked() {
|
|
781
|
-
try {
|
|
782
|
-
if (globalThis.navigator?.onLine === !1) return this.schedule(i), !0;
|
|
783
|
-
let e = await this.bounded(this.storage.take(this.batchesPerDrain));
|
|
784
|
-
if (e.length === 0) return this.schedule(i), !0;
|
|
785
|
-
for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
|
|
786
|
-
return this.schedule(e.length === this.batchesPerDrain ? 0 : i), !0;
|
|
787
|
-
} catch (e) {
|
|
788
|
-
return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
async deliver(e) {
|
|
792
|
-
if (e.attempts >= E.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
|
|
793
|
-
batchId: e.id,
|
|
794
|
-
records: e.records.length
|
|
795
|
-
}), await this.bounded(this.storage.remove(e.id)), !0;
|
|
796
|
-
try {
|
|
797
|
-
return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
|
|
798
|
-
} catch (t) {
|
|
799
|
-
let n = t instanceof H ? t : void 0;
|
|
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);
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
async replaceStored(e, t) {
|
|
804
|
-
let n = this.toStorable(e, t);
|
|
805
|
-
await this.bounded(this.storage.remove(e.id));
|
|
806
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
807
|
-
}
|
|
808
|
-
toStorable(e, t) {
|
|
809
|
-
let n = t instanceof H ? t : void 0;
|
|
810
|
-
if (n?.kind === "permanent") return [];
|
|
811
|
-
if (n?.kind !== "too_large") return [e];
|
|
812
|
-
let r = I(e, this.diagnostics);
|
|
813
|
-
return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
|
|
814
|
-
from: e.records.length,
|
|
815
|
-
to: r[0].records.length,
|
|
816
|
-
serverMaxBytes: n.maxBytes
|
|
817
|
-
}), r) : (this.diagnostics.report("transport.dropped_permanent", "One record is larger than the server limit. The library dropped it.", {
|
|
818
|
-
batchId: e.id,
|
|
819
|
-
bodies: e.records.map((e) => e.body)
|
|
820
|
-
}), []);
|
|
821
|
-
}
|
|
822
|
-
};
|
|
823
|
-
//#endregion
|
|
824
|
-
//#region src/core/pipeline.ts
|
|
825
|
-
function Ve(e) {
|
|
826
|
-
return e.attributes[_] === oe;
|
|
827
|
-
}
|
|
828
|
-
var He = {
|
|
829
|
-
logs: {
|
|
830
|
-
flushIntervalMs: y,
|
|
831
|
-
batchSize: 100
|
|
832
|
-
},
|
|
833
|
-
metrics: {
|
|
834
|
-
flushIntervalMs: x,
|
|
835
|
-
batchSize: 500
|
|
836
|
-
}
|
|
837
|
-
}, $ = class {
|
|
838
|
-
options;
|
|
839
|
-
onFlush;
|
|
840
|
-
pending = [];
|
|
841
|
-
timer = null;
|
|
842
|
-
constructor(e, t) {
|
|
843
|
-
this.options = e, this.onFlush = t;
|
|
844
|
-
}
|
|
845
|
-
add(e) {
|
|
846
|
-
this.pending.push(e), this.pending.length >= this.options.batchSize ? this.onFlush(this) : this.arm();
|
|
847
|
-
}
|
|
848
|
-
take() {
|
|
849
|
-
this.clearTimer();
|
|
850
|
-
let e = this.pending;
|
|
851
|
-
return this.pending = [], e;
|
|
852
|
-
}
|
|
853
|
-
stop() {
|
|
854
|
-
this.clearTimer();
|
|
855
|
-
}
|
|
856
|
-
arm() {
|
|
857
|
-
if (this.timer !== null) return;
|
|
858
|
-
let e = setTimeout(() => {
|
|
859
|
-
this.timer = null, this.onFlush(this);
|
|
860
|
-
}, this.options.flushIntervalMs);
|
|
861
|
-
this.timer = e, k(e);
|
|
862
|
-
}
|
|
863
|
-
clearTimer() {
|
|
864
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
865
|
-
}
|
|
866
|
-
}, Ue = class {
|
|
867
|
-
transport;
|
|
868
|
-
storage;
|
|
869
|
-
retry;
|
|
870
|
-
diagnostics;
|
|
871
|
-
streams;
|
|
872
|
-
unconfirmed = /* @__PURE__ */ new Map();
|
|
873
|
-
queue = [];
|
|
874
|
-
open = /* @__PURE__ */ new Set();
|
|
875
|
-
ceiling = new me();
|
|
876
|
-
inFlight = 0;
|
|
877
|
-
pumpScheduled = !1;
|
|
878
|
-
stopped = !1;
|
|
879
|
-
constructor(e, t, n, r, i = He) {
|
|
880
|
-
this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
|
|
881
|
-
let a = (e) => {
|
|
882
|
-
this.claim(e);
|
|
883
|
-
};
|
|
884
|
-
this.streams = {
|
|
885
|
-
logs: new $(i.logs, a),
|
|
886
|
-
metrics: new $(i.metrics, a)
|
|
887
|
-
};
|
|
888
|
-
}
|
|
889
|
-
push(e) {
|
|
890
|
-
this.stopped || (e.observedTimeUnixNano = pe(), this.route(e));
|
|
891
|
-
}
|
|
892
|
-
drainPending() {
|
|
893
|
-
return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
|
|
894
|
-
}
|
|
895
|
-
drainForExit() {
|
|
896
|
-
let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
|
|
897
|
-
return this.unconfirmed.clear(), this.toBatch([
|
|
898
|
-
...e,
|
|
899
|
-
...this.streams.metrics.take(),
|
|
900
|
-
...this.streams.logs.take()
|
|
901
|
-
]);
|
|
902
|
-
}
|
|
903
|
-
async flushPending() {
|
|
904
|
-
this.enqueue(this.stopped ? null : this.drainPending()), await Promise.all([...this.open].map((e) => e.done));
|
|
905
|
-
}
|
|
906
|
-
destroy() {
|
|
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();
|
|
910
|
-
}
|
|
911
|
-
toBatch(e) {
|
|
912
|
-
return e.length === 0 ? null : {
|
|
913
|
-
id: A(this.diagnostics),
|
|
914
|
-
records: e,
|
|
915
|
-
createdAt: Date.now(),
|
|
916
|
-
attempts: 0
|
|
917
|
-
};
|
|
918
|
-
}
|
|
919
|
-
route(e) {
|
|
920
|
-
try {
|
|
921
|
-
let t = Ve(e) ? this.streams.metrics : this.streams.logs;
|
|
922
|
-
if (!this.ceiling.allow(e)) {
|
|
923
|
-
this.diagnostics.count("record.dropped_by_ceiling");
|
|
924
|
-
return;
|
|
925
|
-
}
|
|
926
|
-
t.add(e);
|
|
927
|
-
} catch (e) {
|
|
928
|
-
this.diagnostics.report("pipeline.crashed", "The pipeline dropped a record before it reached a stream.", void 0, e);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
claim(e) {
|
|
932
|
-
this.enqueue(this.toBatch(e.take()));
|
|
933
|
-
}
|
|
934
|
-
enqueue(e) {
|
|
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(() => {
|
|
944
|
-
this.pumpScheduled = !1, this.pump();
|
|
945
|
-
}));
|
|
946
|
-
}
|
|
947
|
-
pump() {
|
|
948
|
-
for (; this.inFlight < 2;) {
|
|
949
|
-
let e = this.queue.shift();
|
|
950
|
-
if (!e) return;
|
|
951
|
-
this.inFlight++, this.run(e);
|
|
952
|
-
}
|
|
953
|
-
}
|
|
954
|
-
async run(e) {
|
|
955
|
-
let { batch: t } = e;
|
|
956
|
-
try {
|
|
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);
|
|
960
|
-
} finally {
|
|
961
|
-
this.inFlight--, this.open.delete(e), e.resolve(), this.pump();
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
async dispatch(e) {
|
|
965
|
-
try {
|
|
966
|
-
let t = this.transport.throttledForMs();
|
|
967
|
-
if (t > 0) {
|
|
968
|
-
await this.store(e), this.diagnostics.report("transport.throttled", "The server throttles requests. The pipeline stored the batch and did not send it.", {
|
|
969
|
-
batchId: e.id,
|
|
970
|
-
records: e.records.length,
|
|
971
|
-
throttledMs: t
|
|
972
|
-
});
|
|
973
|
-
return;
|
|
974
|
-
}
|
|
975
|
-
try {
|
|
976
|
-
await this.transport.send(e, () => {
|
|
977
|
-
this.unconfirmed.delete(e.id);
|
|
978
|
-
});
|
|
979
|
-
} catch (t) {
|
|
980
|
-
await this.storeFailed({
|
|
981
|
-
...e,
|
|
982
|
-
attempts: e.attempts + 1
|
|
983
|
-
}, t), this.diagnostics.report("transport.http_error", "The send failed. The pipeline stored the batch for a retry.", {
|
|
984
|
-
batchId: e.id,
|
|
985
|
-
records: e.records.length
|
|
986
|
-
}, t);
|
|
987
|
-
}
|
|
988
|
-
} finally {
|
|
989
|
-
this.unconfirmed.delete(e.id);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
async storeFailed(e, t) {
|
|
993
|
-
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
994
|
-
await this.retry.storeFailed(e, t);
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
async store(e) {
|
|
998
|
-
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
999
|
-
await O(this.storage.save(e), T), this.retry.nudge();
|
|
1000
|
-
});
|
|
1001
|
-
}
|
|
1002
|
-
}, We = class e {
|
|
1003
|
-
storage;
|
|
1004
|
-
retry;
|
|
1005
|
-
pipeline;
|
|
1006
|
-
exitFlush;
|
|
1007
|
-
diagnostics;
|
|
1008
|
-
constructor(e, t, n, r, i) {
|
|
1009
|
-
this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
|
|
1010
|
-
}
|
|
1011
|
-
static async create(t) {
|
|
1012
|
-
let { config: n, diagnostics: r } = t, i = await Ee(n.storage, le, E, r, t.onGap), a = (e) => {
|
|
1013
|
-
let i = M(e, r);
|
|
1014
|
-
i && N(t.remote, n, i);
|
|
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({
|
|
1016
|
-
config: n,
|
|
1017
|
-
diagnostics: r,
|
|
1018
|
-
drainForExit: () => l.drainForExit(),
|
|
1019
|
-
flushAlive: () => l.flushPending(),
|
|
1020
|
-
exitHeaders: () => o?.lastHeaders()
|
|
1021
|
-
}), d = !1;
|
|
1022
|
-
try {
|
|
1023
|
-
u.install(), c.start(), d = !0;
|
|
1024
|
-
} finally {
|
|
1025
|
-
d || (u.uninstall(), c.stop());
|
|
1026
|
-
}
|
|
1027
|
-
let f = new e(i, c, l, u, r);
|
|
1028
|
-
return f.importEmergency(), f;
|
|
1029
|
-
}
|
|
1030
|
-
push(e) {
|
|
1031
|
-
this.pipeline.push(e);
|
|
1032
|
-
}
|
|
1033
|
-
async flush() {
|
|
1034
|
-
await this.pipeline.flushPending();
|
|
1035
|
-
}
|
|
1036
|
-
async queueDepth() {
|
|
1037
|
-
return await this.diagnostics.guardAsync("storage.degraded", "The library could not count the batches in storage.", () => this.storage.count()) ?? 0;
|
|
1038
|
-
}
|
|
1039
|
-
async destroy() {
|
|
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();
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
//#endregion
|
|
1048
|
-
export { We as Sender };
|
|
1049
|
-
|
|
1050
|
-
//# sourceMappingURL=sender-BnNj9bOX.js.map
|