@utk09/ui-observability 0.9.0 → 0.9.1
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 +36 -0
- package/README.md +56 -36
- package/dist/batch-DEK4bv9N.js +31 -0
- package/dist/batch-DEK4bv9N.js.map +1 -0
- package/dist/batch-DEVFs28i.cjs +2 -0
- package/dist/batch-DEVFs28i.cjs.map +1 -0
- package/dist/{bus-CtJWf9QN.cjs → bus-DNFvTkif.cjs} +2 -2
- package/dist/{bus-CtJWf9QN.cjs.map → bus-DNFvTkif.cjs.map} +1 -1
- package/dist/{bus-D8kH58tb.js → bus-HVQ8E72V.js} +8 -8
- package/dist/{bus-D8kH58tb.js.map → bus-HVQ8E72V.js.map} +1 -1
- package/dist/{console-DjLbryED.js → console-C9Y639mn.js} +3 -3
- package/dist/{console-DjLbryED.js.map → console-C9Y639mn.js.map} +1 -1
- package/dist/{console-BpHfWstv.cjs → console-DssDxq1B.cjs} +2 -2
- package/dist/{console-BpHfWstv.cjs.map → console-DssDxq1B.cjs.map} +1 -1
- package/dist/constants-N99w84xy.js +117 -0
- package/dist/constants-N99w84xy.js.map +1 -0
- package/dist/constants-X86IDwkC.cjs +2 -0
- package/dist/constants-X86IDwkC.cjs.map +1 -0
- package/dist/constants.d.ts +18 -11
- package/dist/core/drops.d.ts +29 -0
- package/dist/core/hold-buffer.d.ts +27 -0
- package/dist/core/pipeline.d.ts +2 -7
- package/dist/core/runtime.d.ts +44 -8
- package/dist/core/sender.d.ts +4 -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-CpGRhhIf.cjs → errors-BTWuVnHZ.cjs} +2 -2
- package/dist/{errors-CpGRhhIf.cjs.map → errors-BTWuVnHZ.cjs.map} +1 -1
- package/dist/{errors-DH4QJS0u.js → errors-CQusIGWJ.js} +4 -4
- package/dist/{errors-DH4QJS0u.js.map → errors-CQusIGWJ.js.map} +1 -1
- package/dist/{deadline-Cbg2cbUw.cjs → identity-B1GDS1Tb.cjs} +2 -2
- package/dist/identity-B1GDS1Tb.cjs.map +1 -0
- package/dist/{deadline-B5DINjD5.js → identity-D4DPjTM9.js} +3 -26
- package/dist/identity-D4DPjTM9.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +467 -318
- package/dist/index.js.map +1 -1
- package/dist/{indexeddb-storage-n1qkFBGA.js → indexeddb-storage-B8SGUzSV.js} +79 -50
- package/dist/indexeddb-storage-B8SGUzSV.js.map +1 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs +2 -0
- package/dist/indexeddb-storage-ukzC82dm.cjs.map +1 -0
- package/dist/{interactions-31eHGwEQ.cjs → interactions-CcxrVzpg.cjs} +2 -2
- package/dist/{interactions-31eHGwEQ.cjs.map → interactions-CcxrVzpg.cjs.map} +1 -1
- package/dist/{interactions-OU94MPXs.js → interactions-CnjfQgw3.js} +2 -2
- package/dist/{interactions-OU94MPXs.js.map → interactions-CnjfQgw3.js.map} +1 -1
- package/dist/{journey-CeJ1QoT2.js → journey-DjvDzHyp.js} +17 -16
- package/dist/{journey-CeJ1QoT2.js.map → journey-DjvDzHyp.js.map} +1 -1
- package/dist/journey-DxlfdFJV.cjs +2 -0
- package/dist/journey-DxlfdFJV.cjs.map +1 -0
- package/dist/{library-request-C9uJFlbq.cjs → library-request-BZ1ekVtl.cjs} +2 -2
- package/dist/{library-request-C9uJFlbq.cjs.map → library-request-BZ1ekVtl.cjs.map} +1 -1
- package/dist/{library-request-DvhuplAB.js → library-request-C8kc5YWv.js} +2 -2
- package/dist/{library-request-DvhuplAB.js.map → library-request-C8kc5YWv.js.map} +1 -1
- package/dist/{long-frames-B8VdA_ny.cjs → long-frames-BGik_Yhy.cjs} +2 -2
- package/dist/{long-frames-B8VdA_ny.cjs.map → long-frames-BGik_Yhy.cjs.map} +1 -1
- package/dist/{long-frames-C_7OutLs.js → long-frames-CZk3XOkH.js} +3 -3
- package/dist/{long-frames-C_7OutLs.js.map → long-frames-CZk3XOkH.js.map} +1 -1
- package/dist/models/batch.d.ts +14 -0
- package/dist/models/config.d.ts +146 -0
- package/dist/models/drop.d.ts +39 -0
- package/dist/models/storage.d.ts +15 -3
- package/dist/{network-D_lloS5t.js → network-51iicpLl.js} +19 -19
- package/dist/{network-D_lloS5t.js.map → network-51iicpLl.js.map} +1 -1
- package/dist/{network-BAV7ipyn.cjs → network-jBbjyAJP.cjs} +2 -2
- package/dist/{network-BAV7ipyn.cjs.map → network-jBbjyAJP.cjs.map} +1 -1
- package/dist/{platform-IHBZGqUe.js → platform-Cjts-8k8.js} +2 -2
- package/dist/{platform-IHBZGqUe.js.map → platform-Cjts-8k8.js.map} +1 -1
- package/dist/{platform-D4wu1eIF.cjs → platform-DW3GFIUE.cjs} +2 -2
- package/dist/{platform-D4wu1eIF.cjs.map → platform-DW3GFIUE.cjs.map} +1 -1
- package/dist/{remote-rules-kuDf5gbe.cjs → remote-rules-ByS34k4e.cjs} +2 -2
- package/dist/{remote-rules-kuDf5gbe.cjs.map → remote-rules-ByS34k4e.cjs.map} +1 -1
- package/dist/{remote-rules-Bt1XsdEQ.js → remote-rules-M-XZ1xbe.js} +2 -2
- package/dist/{remote-rules-Bt1XsdEQ.js.map → remote-rules-M-XZ1xbe.js.map} +1 -1
- package/dist/{sampling-o0VY1mqQ.js → sampling-BN3Oi6SV.js} +9 -9
- package/dist/{sampling-o0VY1mqQ.js.map → sampling-BN3Oi6SV.js.map} +1 -1
- package/dist/{sampling-BI15ds9D.cjs → sampling-b2ck5X98.cjs} +2 -2
- package/dist/{sampling-BI15ds9D.cjs.map → sampling-b2ck5X98.cjs.map} +1 -1
- package/dist/{sanitize-DSIP7amZ.cjs → sanitize-DKp5MRsa.cjs} +2 -2
- package/dist/{sanitize-DSIP7amZ.cjs.map → sanitize-DKp5MRsa.cjs.map} +1 -1
- package/dist/{sanitize-B9UheVKc.js → sanitize-Dwj9JCkI.js} +2 -2
- package/dist/{sanitize-B9UheVKc.js.map → sanitize-Dwj9JCkI.js.map} +1 -1
- package/dist/{sender-BnNj9bOX.js → sender-BBY0IcUo.js} +328 -269
- package/dist/sender-BBY0IcUo.js.map +1 -0
- package/dist/sender-BXoAZKum.cjs +3 -0
- package/dist/sender-BXoAZKum.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-CKuaBp7i.cjs} +2 -2
- package/dist/{storm-Y-yuBhvv.cjs.map → storm-CKuaBp7i.cjs.map} +1 -1
- package/dist/{storm-BTw0J6eE.js → storm-DhtL2eVr.js} +2 -2
- package/dist/{storm-BTw0J6eE.js.map → storm-DhtL2eVr.js.map} +1 -1
- package/dist/transport/exit-flush.d.ts +6 -0
- package/dist/transport/retry-engine.d.ts +7 -3
- package/dist/transport/status-transport.d.ts +4 -1
- package/dist/utils/console.d.ts +4 -1
- 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.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/sender-BnNj9bOX.js.map +0 -1
- package/dist/sender-D0OsyB1c.cjs +0 -3
- package/dist/sender-D0OsyB1c.cjs.map +0 -1
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as
|
|
3
|
-
import { o as
|
|
4
|
-
import {
|
|
5
|
-
import { n as
|
|
6
|
-
import { n as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
return [r(e.records.slice(0, n)), r(e.records.slice(n))];
|
|
1
|
+
import { $ as e, At as t, Ct as n, Gt as r, H as i, J as a, Kt as o, Lt as s, M as c, N as l, Nt as u, Q as d, Rt as f, V as p, Wt as m, X as ee, Xt as te, Y as h, Z as g, an as ne, b as _, cn as v, d as y, dn as b, fn as re, gt as ie, j as x, jt as ae, mt as oe, nn as S, on as se, sn as ce, tn as le, vt as C, wt as w, yt as ue, z as de } from "./constants-N99w84xy.js";
|
|
2
|
+
import { o as fe, t as pe } from "./sampling-BN3Oi6SV.js";
|
|
3
|
+
import { o as me, t as T } from "./sanitize-Dwj9JCkI.js";
|
|
4
|
+
import { i as he } from "./identity-D4DPjTM9.js";
|
|
5
|
+
import { i as ge, n as _e, r as E } from "./batch-DEK4bv9N.js";
|
|
6
|
+
import { n as D } from "./library-request-C8kc5YWv.js";
|
|
7
|
+
import { n as O, r as k, t as A } from "./deadline-5_PecIl5.js";
|
|
8
|
+
import { n as j, t as M } from "./remote-rules-M-XZ1xbe.js";
|
|
9
|
+
//#region src/models/storage.ts
|
|
10
|
+
function N(e) {
|
|
11
|
+
let { maxBatches: t } = e;
|
|
12
|
+
return e.mode === "until-delivered" ? {
|
|
13
|
+
maxBatches: t,
|
|
14
|
+
maxAgeMs: Infinity,
|
|
15
|
+
maxAttempts: Infinity
|
|
16
|
+
} : {
|
|
17
|
+
maxBatches: t,
|
|
18
|
+
maxAgeMs: e.maxAgeMs,
|
|
19
|
+
maxAttempts: e.maxAttempts
|
|
20
|
+
};
|
|
22
21
|
}
|
|
23
22
|
//#endregion
|
|
24
23
|
//#region src/utils/lock.ts
|
|
25
|
-
function
|
|
24
|
+
function P(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
26
25
|
let i = globalThis.navigator?.locks;
|
|
27
26
|
return i?.request ? t.guardAsync("storage.degraded", `The library could not get the lock ${e}.`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
|
|
28
27
|
}
|
|
29
28
|
//#endregion
|
|
30
29
|
//#region src/storage/keys.ts
|
|
31
|
-
function
|
|
30
|
+
function F(e, t) {
|
|
32
31
|
let n = [];
|
|
33
32
|
return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
|
|
34
33
|
for (let t = 0; t < localStorage.length; t++) {
|
|
@@ -39,57 +38,91 @@ function R(e, t) {
|
|
|
39
38
|
}
|
|
40
39
|
//#endregion
|
|
41
40
|
//#region src/storage/emergency-queue.ts
|
|
42
|
-
function
|
|
41
|
+
function I(e) {
|
|
43
42
|
let t = String(e.createdAt).padStart(14, "0");
|
|
44
|
-
return `${
|
|
43
|
+
return `${p}${t}.${e.id}`;
|
|
45
44
|
}
|
|
46
|
-
function
|
|
45
|
+
function L(e, t) {
|
|
47
46
|
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 :
|
|
47
|
+
return n === void 0 ? null : E(n) ? n : (t.report("storage.degraded", "An emergency entry is not a batch. The library dropped it."), null);
|
|
49
48
|
}
|
|
50
49
|
async function ve(e, t) {
|
|
51
|
-
let
|
|
52
|
-
for (let
|
|
53
|
-
let
|
|
54
|
-
let e = localStorage.getItem(
|
|
55
|
-
return localStorage.removeItem(
|
|
50
|
+
let n = 0;
|
|
51
|
+
for (let r of F(p, t)) {
|
|
52
|
+
let i = t.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
|
|
53
|
+
let e = localStorage.getItem(r);
|
|
54
|
+
return localStorage.removeItem(r), e;
|
|
56
55
|
});
|
|
57
|
-
if (!
|
|
58
|
-
let a =
|
|
56
|
+
if (!i) continue;
|
|
57
|
+
let a = L(i, t);
|
|
59
58
|
if (a !== null) try {
|
|
60
|
-
await O(e.save(a),
|
|
59
|
+
await O(e.save(a), S), n++;
|
|
61
60
|
} catch (e) {
|
|
62
|
-
t.report("storage.degraded", "The library could not recover an emergency batch.", { key:
|
|
61
|
+
t.report("storage.degraded", "The library could not recover an emergency batch.", { key: r }, e);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
return
|
|
64
|
+
return n;
|
|
66
65
|
}
|
|
67
|
-
function
|
|
68
|
-
let r = `writing the emergency queue, ${String(e.records.length)} records
|
|
69
|
-
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
function R(e, t, n) {
|
|
67
|
+
let r = `writing the emergency queue, ${String(e.records.length)} records`, i = [], a = t.guard("storage.quota_exceeded", r, () => {
|
|
68
|
+
let n = F(p, t);
|
|
69
|
+
for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) {
|
|
70
|
+
let n = L(String(localStorage.getItem(e)), t);
|
|
71
|
+
n !== null && i.push(n), localStorage.removeItem(e);
|
|
72
|
+
}
|
|
73
|
+
return localStorage.setItem(I(e), JSON.stringify(e)), !0;
|
|
74
|
+
});
|
|
75
|
+
t.guard("pipeline.crashed", "The loss report of the emergency queue failed.", () => {
|
|
76
|
+
if (i.length > 0) {
|
|
77
|
+
let e = i.flatMap((e) => e.records);
|
|
78
|
+
n?.("exit_queue_full", e, i.map((e) => e.id));
|
|
79
|
+
}
|
|
80
|
+
a !== !0 && n?.("quota", e.records, [e.id]);
|
|
73
81
|
});
|
|
74
82
|
}
|
|
75
83
|
async function ye(e, t) {
|
|
76
|
-
return await
|
|
84
|
+
return await P("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/storage/eviction.ts
|
|
88
|
+
function z(e) {
|
|
89
|
+
return Array.isArray(e.records) && e.records.some(_e);
|
|
90
|
+
}
|
|
91
|
+
var B = class {
|
|
92
|
+
howMany;
|
|
93
|
+
isAudit;
|
|
94
|
+
plain = [];
|
|
95
|
+
audit = [];
|
|
96
|
+
constructor(e, t) {
|
|
97
|
+
this.howMany = e, this.isAudit = t;
|
|
98
|
+
}
|
|
99
|
+
add(e) {
|
|
100
|
+
return this.isAudit(e) ? this.audit.length < this.howMany && this.audit.push(e) : this.plain.push(e), this.plain.length < this.howMany;
|
|
101
|
+
}
|
|
102
|
+
picked() {
|
|
103
|
+
return [...this.plain, ...this.audit].slice(0, this.howMany);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
function V(e, t, n) {
|
|
107
|
+
let r = new B(t, n);
|
|
108
|
+
for (let t of e) if (!r.add(t)) break;
|
|
109
|
+
return r.picked();
|
|
77
110
|
}
|
|
78
111
|
//#endregion
|
|
79
112
|
//#region src/storage/local-storage.ts
|
|
80
113
|
function be(e) {
|
|
81
114
|
let t = String(e.createdAt).padStart(14, "0");
|
|
82
|
-
return `${
|
|
115
|
+
return `${_}${t}.${e.id}`;
|
|
83
116
|
}
|
|
84
117
|
function xe(e) {
|
|
85
|
-
let t =
|
|
118
|
+
let t = _.length, n = Number(e.slice(t, t + 14));
|
|
86
119
|
return Number.isFinite(n) ? n : null;
|
|
87
120
|
}
|
|
88
121
|
var Se = class {
|
|
89
122
|
limits;
|
|
90
123
|
diagnostics;
|
|
91
124
|
onGap;
|
|
92
|
-
name =
|
|
125
|
+
name = ne;
|
|
93
126
|
constructor(e, t, n) {
|
|
94
127
|
this.limits = e, this.diagnostics = t, this.onGap = n;
|
|
95
128
|
}
|
|
@@ -98,7 +131,7 @@ var Se = class {
|
|
|
98
131
|
batches: 1,
|
|
99
132
|
records: e.records.length,
|
|
100
133
|
reason: "quota"
|
|
101
|
-
}));
|
|
134
|
+
}, [e]));
|
|
102
135
|
}
|
|
103
136
|
take(e) {
|
|
104
137
|
let t = [];
|
|
@@ -125,20 +158,14 @@ var Se = class {
|
|
|
125
158
|
batches: 0,
|
|
126
159
|
records: 0,
|
|
127
160
|
reason: "expired"
|
|
128
|
-
}, n =
|
|
129
|
-
let n = this.read(e);
|
|
130
|
-
this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
|
|
131
|
-
}, r = [];
|
|
161
|
+
}, n = [], r = [];
|
|
132
162
|
for (let t of this.keys()) {
|
|
133
163
|
let i = xe(t);
|
|
134
|
-
i === null || i < e ? n(t) : r.push(t);
|
|
164
|
+
i === null || i < e ? n.push(t) : r.push(t);
|
|
135
165
|
}
|
|
166
|
+
this.drop(t, "expired", [...this.entries(n)]);
|
|
136
167
|
let i = r.length - this.limits.maxBatches;
|
|
137
|
-
|
|
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);
|
|
168
|
+
return i > 0 && this.drop(t, "over_capacity", this.evictable(r, i)), Promise.resolve(t);
|
|
142
169
|
}
|
|
143
170
|
count() {
|
|
144
171
|
return Promise.resolve(this.keys().length);
|
|
@@ -157,21 +184,36 @@ var Se = class {
|
|
|
157
184
|
batches: 0,
|
|
158
185
|
records: 0,
|
|
159
186
|
reason: "quota"
|
|
187
|
+
}, n = Math.ceil(e.length / 4);
|
|
188
|
+
this.drop(t, "quota", this.evictable(e, n));
|
|
189
|
+
}
|
|
190
|
+
evictable(e, t) {
|
|
191
|
+
return V(this.entries(e), t, (e) => e.batch !== null && z(e.batch));
|
|
192
|
+
}
|
|
193
|
+
*entries(e) {
|
|
194
|
+
for (let t of e) yield {
|
|
195
|
+
key: t,
|
|
196
|
+
batch: this.read(t)
|
|
160
197
|
};
|
|
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
198
|
}
|
|
167
|
-
|
|
168
|
-
|
|
199
|
+
drop(e, t, n) {
|
|
200
|
+
if (n.length === 0) return;
|
|
201
|
+
let r = [], i = 0;
|
|
202
|
+
for (let { key: e, batch: t } of n) this.removeKey(e), i += t?.records.length ?? 0, t && r.push(t);
|
|
203
|
+
e.batches += n.length, e.records += i, e.reason = t, this.reportGap({
|
|
204
|
+
batches: n.length,
|
|
205
|
+
records: i,
|
|
206
|
+
reason: t
|
|
207
|
+
}, r);
|
|
208
|
+
}
|
|
209
|
+
reportGap(e, t) {
|
|
210
|
+
this.diagnostics.report("storage.evicted", `The library dropped ${String(e.batches)} stored batches (${String(e.records)} records).`, { ...e }), this.onGap?.(e, t);
|
|
169
211
|
}
|
|
170
212
|
read(e) {
|
|
171
213
|
let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
|
|
172
214
|
if (!t) return null;
|
|
173
215
|
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 :
|
|
216
|
+
return n === void 0 ? null : E(n) ? n : (this.diagnostics.report("storage.degraded", "A stored entry is not a batch. The library dropped it."), null);
|
|
175
217
|
}
|
|
176
218
|
keyOf(e) {
|
|
177
219
|
return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
|
|
@@ -185,18 +227,18 @@ var Se = class {
|
|
|
185
227
|
});
|
|
186
228
|
}
|
|
187
229
|
keys() {
|
|
188
|
-
return
|
|
230
|
+
return F(_, this.diagnostics);
|
|
189
231
|
}
|
|
190
232
|
};
|
|
191
233
|
//#endregion
|
|
192
234
|
//#region src/storage/memory-storage.ts
|
|
193
|
-
function
|
|
235
|
+
function Ce(e) {
|
|
194
236
|
return e.reduce((e, t) => e + t.records.length, 0);
|
|
195
237
|
}
|
|
196
|
-
var
|
|
238
|
+
var H = class {
|
|
197
239
|
limits;
|
|
198
240
|
onGap;
|
|
199
|
-
name =
|
|
241
|
+
name = se;
|
|
200
242
|
batches = [];
|
|
201
243
|
constructor(e, t) {
|
|
202
244
|
this.limits = e, this.onGap = t;
|
|
@@ -220,14 +262,22 @@ var V = class {
|
|
|
220
262
|
records: 0,
|
|
221
263
|
reason: "expired"
|
|
222
264
|
}, n = this.batches.filter((t) => t.createdAt < e);
|
|
223
|
-
this.batches = this.batches.filter((t) => t.createdAt >= e), t
|
|
265
|
+
this.batches = this.batches.filter((t) => t.createdAt >= e), this.report(t, "expired", n);
|
|
224
266
|
let r = this.batches.length - this.limits.maxBatches;
|
|
225
267
|
if (r > 0) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.batches = this.batches.slice(r), t.batches += e.length, t.records += B(e);
|
|
268
|
+
let e = V(this.batches, r, z);
|
|
269
|
+
this.batches = this.batches.filter((t) => !e.includes(t)), this.report(t, "over_capacity", e);
|
|
229
270
|
}
|
|
230
|
-
return
|
|
271
|
+
return Promise.resolve(t);
|
|
272
|
+
}
|
|
273
|
+
report(e, t, n) {
|
|
274
|
+
if (n.length === 0) return;
|
|
275
|
+
let r = Ce(n);
|
|
276
|
+
e.batches += n.length, e.records += r, e.reason = t, this.onGap?.({
|
|
277
|
+
batches: n.length,
|
|
278
|
+
records: r,
|
|
279
|
+
reason: t
|
|
280
|
+
}, n);
|
|
231
281
|
}
|
|
232
282
|
count() {
|
|
233
283
|
return Promise.resolve(this.batches.length);
|
|
@@ -238,9 +288,13 @@ var V = class {
|
|
|
238
288
|
close() {
|
|
239
289
|
return this.batches = [], Promise.resolve();
|
|
240
290
|
}
|
|
241
|
-
},
|
|
242
|
-
name:
|
|
243
|
-
save: () =>
|
|
291
|
+
}, we = (e) => ({
|
|
292
|
+
name: ce,
|
|
293
|
+
save: (t) => (e?.({
|
|
294
|
+
batches: 1,
|
|
295
|
+
records: t.records.length,
|
|
296
|
+
reason: "not_stored"
|
|
297
|
+
}, [t]), Promise.resolve()),
|
|
244
298
|
take: () => Promise.resolve([]),
|
|
245
299
|
remove: () => Promise.resolve(),
|
|
246
300
|
bumpAttempts: () => Promise.resolve(),
|
|
@@ -252,31 +306,31 @@ var V = class {
|
|
|
252
306
|
count: () => Promise.resolve(0),
|
|
253
307
|
clear: () => Promise.resolve(),
|
|
254
308
|
close: () => Promise.resolve()
|
|
255
|
-
};
|
|
256
|
-
function
|
|
309
|
+
});
|
|
310
|
+
function Te(e) {
|
|
257
311
|
return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
|
|
258
312
|
}
|
|
259
|
-
function
|
|
260
|
-
return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(
|
|
313
|
+
function Ee(e) {
|
|
314
|
+
return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(v, "1"), localStorage.removeItem(v), !0)) === !0;
|
|
261
315
|
}
|
|
262
|
-
async function
|
|
263
|
-
if (e === "none") return
|
|
264
|
-
if (e === "memory") return new
|
|
316
|
+
async function De(e, t, n, r, i) {
|
|
317
|
+
if (e === "none") return we(i);
|
|
318
|
+
if (e === "memory") return new H(n, i);
|
|
265
319
|
if (e === "indexeddb" || e === "auto") {
|
|
266
|
-
if (
|
|
320
|
+
if (Te(r)) {
|
|
267
321
|
let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
|
|
268
|
-
let { IndexedDbStorage: e } = await import("./indexeddb-storage-
|
|
322
|
+
let { IndexedDbStorage: e } = await import("./indexeddb-storage-B8SGUzSV.js"), a = new e(t, n, r, i);
|
|
269
323
|
return await a.open(), a;
|
|
270
324
|
});
|
|
271
325
|
if (e) return e;
|
|
272
326
|
}
|
|
273
|
-
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new
|
|
327
|
+
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new H(n, i);
|
|
274
328
|
}
|
|
275
|
-
return
|
|
329
|
+
return Ee(r) ? new Se(n, r, i) : (r.report("storage.degraded", "No persistent storage is available. The library keeps undelivered records in memory only."), new H(n, i));
|
|
276
330
|
}
|
|
277
331
|
//#endregion
|
|
278
332
|
//#region src/transport/errors.ts
|
|
279
|
-
var
|
|
333
|
+
var U = class extends Error {
|
|
280
334
|
kind;
|
|
281
335
|
status;
|
|
282
336
|
retryAfterMs;
|
|
@@ -285,77 +339,77 @@ var H = class extends Error {
|
|
|
285
339
|
super(t, a === void 0 ? void 0 : { cause: a }), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
|
|
286
340
|
}
|
|
287
341
|
};
|
|
288
|
-
function
|
|
342
|
+
function Oe(e) {
|
|
289
343
|
if (!e) return;
|
|
290
344
|
let t = Number(e);
|
|
291
|
-
if (Number.isFinite(t)) return Math.max(0, t *
|
|
345
|
+
if (Number.isFinite(t)) return Math.max(0, t * ie);
|
|
292
346
|
let n = Date.parse(e);
|
|
293
347
|
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
294
348
|
}
|
|
295
349
|
//#endregion
|
|
296
350
|
//#region src/transport/serializers/ecs.ts
|
|
297
|
-
function Oe(e) {
|
|
298
|
-
return ue.test(e) ? Number(BigInt(e) / fe) : Date.now();
|
|
299
|
-
}
|
|
300
351
|
function ke(e) {
|
|
352
|
+
return C.test(e) ? Number(BigInt(e) / ue) : Date.now();
|
|
353
|
+
}
|
|
354
|
+
function Ae(e) {
|
|
301
355
|
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
|
|
302
356
|
}
|
|
303
|
-
function
|
|
357
|
+
function je(e, t, n) {
|
|
304
358
|
let r = e[t];
|
|
305
359
|
r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
|
|
306
360
|
}
|
|
307
|
-
function
|
|
308
|
-
let i =
|
|
309
|
-
if (i !== null)
|
|
361
|
+
function W(e, t, n, r) {
|
|
362
|
+
let i = Ae(n);
|
|
363
|
+
if (i !== null) je(e, t, i);
|
|
310
364
|
else if (typeof n == "object" && n && !r.has(n)) {
|
|
311
|
-
if (r.add(n), Array.isArray(n)) for (let i of n)
|
|
312
|
-
else for (let [i, a] of Object.entries(n))
|
|
365
|
+
if (r.add(n), Array.isArray(n)) for (let i of n) W(e, t, i, r);
|
|
366
|
+
else for (let [i, a] of Object.entries(n)) W(e, `${t}.${i}`, a, r);
|
|
313
367
|
r.delete(n);
|
|
314
368
|
}
|
|
315
369
|
}
|
|
316
|
-
function
|
|
370
|
+
function G(e) {
|
|
317
371
|
let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
|
|
318
|
-
for (let [r, i] of Object.entries(e))
|
|
372
|
+
for (let [r, i] of Object.entries(e)) W(t, r, i, n);
|
|
319
373
|
return t;
|
|
320
374
|
}
|
|
321
|
-
var
|
|
375
|
+
var Me = {
|
|
322
376
|
name: "ecs",
|
|
323
377
|
serialize(e) {
|
|
324
378
|
return {
|
|
325
379
|
body: `${e.map((e) => {
|
|
326
|
-
let t =
|
|
380
|
+
let t = ke(e.timeUnixNano);
|
|
327
381
|
return JSON.stringify({
|
|
328
382
|
"@timestamp": new Date(t).toISOString(),
|
|
329
383
|
message: e.body,
|
|
330
|
-
log: { level:
|
|
384
|
+
log: { level: de[e.severityText] ?? e.severityText.toLowerCase() },
|
|
331
385
|
trace: { id: e.traceId },
|
|
332
386
|
span: { id: e.spanId },
|
|
333
387
|
service: {
|
|
334
388
|
name: e.resource[s],
|
|
335
389
|
version: e.resource[f],
|
|
336
|
-
environment: e.resource[
|
|
390
|
+
environment: e.resource[u]
|
|
337
391
|
},
|
|
338
|
-
user_agent: { original: e.resource[
|
|
392
|
+
user_agent: { original: e.resource[ae] },
|
|
339
393
|
url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
|
|
340
394
|
labels: {
|
|
341
|
-
...
|
|
342
|
-
...
|
|
395
|
+
...G(e.resource),
|
|
396
|
+
...G(e.attributes)
|
|
343
397
|
}
|
|
344
398
|
});
|
|
345
399
|
}).join("\n")}\n`,
|
|
346
|
-
contentType:
|
|
400
|
+
contentType: c
|
|
347
401
|
};
|
|
348
402
|
}
|
|
349
403
|
};
|
|
350
404
|
//#endregion
|
|
351
405
|
//#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
406
|
function K(e) {
|
|
407
|
+
return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isSafeInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(K).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: q(e) } } : null;
|
|
408
|
+
}
|
|
409
|
+
function q(e) {
|
|
356
410
|
let t = [];
|
|
357
411
|
for (let [n, r] of Object.entries(e)) {
|
|
358
|
-
let e =
|
|
412
|
+
let e = K(r);
|
|
359
413
|
e && t.push({
|
|
360
414
|
key: n,
|
|
361
415
|
value: e
|
|
@@ -363,30 +417,30 @@ function K(e) {
|
|
|
363
417
|
}
|
|
364
418
|
return t;
|
|
365
419
|
}
|
|
366
|
-
var
|
|
367
|
-
function
|
|
368
|
-
let t =
|
|
420
|
+
var J = /* @__PURE__ */ new WeakMap();
|
|
421
|
+
function Ne(e) {
|
|
422
|
+
let t = J.get(e);
|
|
369
423
|
if (t !== void 0) return t;
|
|
370
424
|
let n = JSON.stringify(e);
|
|
371
|
-
return
|
|
425
|
+
return J.set(e, n), n;
|
|
372
426
|
}
|
|
373
|
-
var
|
|
374
|
-
name:
|
|
375
|
-
serialize(
|
|
376
|
-
let
|
|
377
|
-
for (let
|
|
378
|
-
let
|
|
379
|
-
r ? r.records.push(
|
|
380
|
-
resource:
|
|
381
|
-
records: [
|
|
427
|
+
var Pe = {
|
|
428
|
+
name: te,
|
|
429
|
+
serialize(e) {
|
|
430
|
+
let t = /* @__PURE__ */ new Map();
|
|
431
|
+
for (let n of e) {
|
|
432
|
+
let e = Ne(n.resource), r = t.get(e);
|
|
433
|
+
r ? r.records.push(n) : t.set(e, {
|
|
434
|
+
resource: n.resource,
|
|
435
|
+
records: [n]
|
|
382
436
|
});
|
|
383
437
|
}
|
|
384
|
-
let
|
|
385
|
-
resource: { attributes:
|
|
438
|
+
let n = [...t.values()].map((e) => ({
|
|
439
|
+
resource: { attributes: q(e.resource) },
|
|
386
440
|
scopeLogs: [{
|
|
387
441
|
scope: {
|
|
388
|
-
name:
|
|
389
|
-
version:
|
|
442
|
+
name: b,
|
|
443
|
+
version: re
|
|
390
444
|
},
|
|
391
445
|
logRecords: e.records.map((e) => ({
|
|
392
446
|
timeUnixNano: e.timeUnixNano,
|
|
@@ -397,24 +451,24 @@ var Ne = {
|
|
|
397
451
|
traceId: e.traceId,
|
|
398
452
|
spanId: e.spanId,
|
|
399
453
|
flags: e.traceFlags,
|
|
400
|
-
attributes:
|
|
454
|
+
attributes: q(e.attributes)
|
|
401
455
|
}))
|
|
402
456
|
}]
|
|
403
457
|
}));
|
|
404
458
|
return {
|
|
405
|
-
body: JSON.stringify({ resourceLogs:
|
|
406
|
-
contentType:
|
|
459
|
+
body: JSON.stringify({ resourceLogs: n }),
|
|
460
|
+
contentType: x
|
|
407
461
|
};
|
|
408
462
|
}
|
|
409
463
|
};
|
|
410
464
|
//#endregion
|
|
411
465
|
//#region src/transport/serializers/select.ts
|
|
412
|
-
function
|
|
413
|
-
return e === "otlp" ?
|
|
466
|
+
function Fe(e) {
|
|
467
|
+
return e === "otlp" ? Pe : e === "ecs" ? Me : e;
|
|
414
468
|
}
|
|
415
|
-
function
|
|
469
|
+
function Y(e, t, n, r) {
|
|
416
470
|
try {
|
|
417
|
-
return
|
|
471
|
+
return Fe(e).serialize(t.records);
|
|
418
472
|
} catch (e) {
|
|
419
473
|
n.report("transport.serialize_failed", r, { batchId: t.id }, e);
|
|
420
474
|
return;
|
|
@@ -422,19 +476,21 @@ function J(e, t, n, r) {
|
|
|
422
476
|
}
|
|
423
477
|
//#endregion
|
|
424
478
|
//#region src/transport/status-transport.ts
|
|
425
|
-
var
|
|
479
|
+
var X = class {
|
|
426
480
|
config;
|
|
427
481
|
diagnostics;
|
|
428
482
|
onSampling;
|
|
483
|
+
onLoss;
|
|
429
484
|
throttledUntil = 0;
|
|
430
|
-
constructor(e, t, n = () => void 0) {
|
|
431
|
-
this.config = e, this.diagnostics = t, this.onSampling = n;
|
|
485
|
+
constructor(e, t, n = () => void 0, r = () => void 0) {
|
|
486
|
+
this.config = e, this.diagnostics = t, this.onSampling = n, this.onLoss = r;
|
|
432
487
|
}
|
|
433
488
|
throttledForMs() {
|
|
434
489
|
return Math.max(0, this.throttledUntil - Date.now());
|
|
435
490
|
}
|
|
436
491
|
serialize(e) {
|
|
437
|
-
|
|
492
|
+
let t = Y(this.config.serializer, e, this.diagnostics, "The serializer threw an error. The library dropped the batch.");
|
|
493
|
+
return t || this.onLoss("unserializable", e.records, [e.id]), t;
|
|
438
494
|
}
|
|
439
495
|
accept(e) {
|
|
440
496
|
this.throttledUntil = 0, this.config.sampling.remote && e != null && this.onSampling(e);
|
|
@@ -446,22 +502,22 @@ var Y = class {
|
|
|
446
502
|
return this.diagnostics.report("transport.rejected_credentials", `The server returned ${r}.${t}`, {
|
|
447
503
|
status: e,
|
|
448
504
|
endpoint: this.config.endpoint
|
|
449
|
-
}), new
|
|
505
|
+
}), new U("permanent", `The server rejected the batch with ${r}.`, e);
|
|
450
506
|
}
|
|
451
|
-
if (e === 413) return new
|
|
507
|
+
if (e === 413) return new U("too_large", "The payload is too large.", e, void 0, n.maxBytes);
|
|
452
508
|
if (e === 429 || e === 503) {
|
|
453
509
|
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
|
|
510
|
+
return this.throttledUntil = Date.now() + (r ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new U("throttled", t ? "The server throttles the requests." : "The service is not available.", e, r);
|
|
455
511
|
}
|
|
456
|
-
return e === 408 || e >= 500 ? new
|
|
512
|
+
return e === 408 || e >= 500 ? new U("transient", `The server returned the error ${r}.`, e) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${r}. The library dropped it.`, {
|
|
457
513
|
batchId: t,
|
|
458
514
|
status: e
|
|
459
|
-
}), new
|
|
515
|
+
}), new U("permanent", `The server rejected the batch with ${r}.`, e));
|
|
460
516
|
}
|
|
461
517
|
};
|
|
462
518
|
//#endregion
|
|
463
519
|
//#region src/transport/custom-transport.ts
|
|
464
|
-
function
|
|
520
|
+
function Z(e, t) {
|
|
465
521
|
return {
|
|
466
522
|
body: t.body,
|
|
467
523
|
contentType: t.contentType,
|
|
@@ -470,36 +526,36 @@ function X(e, t) {
|
|
|
470
526
|
records: e.records
|
|
471
527
|
};
|
|
472
528
|
}
|
|
473
|
-
function
|
|
529
|
+
function Ie(e) {
|
|
474
530
|
if (typeof e != "object" || !e) return !1;
|
|
475
531
|
let t = Reflect.get(e, "status");
|
|
476
532
|
return typeof t == "number" && Number.isInteger(t) && t >= 100 && t <= 599;
|
|
477
533
|
}
|
|
478
|
-
function
|
|
534
|
+
function Q(e) {
|
|
479
535
|
return typeof e == "number" && Number.isFinite(e) ? Math.max(0, e) : void 0;
|
|
480
536
|
}
|
|
481
|
-
var
|
|
537
|
+
var Le = class extends X {
|
|
482
538
|
async send(e) {
|
|
483
539
|
let { transport: n } = this.config;
|
|
484
540
|
if (!n || e.records.length === 0) return;
|
|
485
541
|
let r = this.serialize(e);
|
|
486
542
|
if (!r) return;
|
|
487
|
-
let i =
|
|
543
|
+
let i = Z(e, r), a;
|
|
488
544
|
try {
|
|
489
|
-
a = await O(
|
|
545
|
+
a = await O(D(() => me(() => n(i))), t);
|
|
490
546
|
} catch (e) {
|
|
491
|
-
let t = e instanceof
|
|
492
|
-
throw new
|
|
547
|
+
let t = e instanceof A ? e : void 0;
|
|
548
|
+
throw new U(t ? "timeout" : "transient", t?.message ?? "The custom transport failed.", void 0, void 0, void 0, e);
|
|
493
549
|
}
|
|
494
|
-
if (!
|
|
550
|
+
if (!Ie(a)) throw this.diagnostics.report("transport.http_error", "The custom transport returned no valid status. The library sends the batch again later.", { batchId: e.id }), new U("transient", "The custom transport returned no valid status.");
|
|
495
551
|
let { status: o } = a;
|
|
496
552
|
if (o >= 200 && o < 300) this.accept(a.sampling);
|
|
497
553
|
else throw this.reject(o, e.id, {
|
|
498
|
-
retryAfterMs:
|
|
499
|
-
maxBytes:
|
|
554
|
+
retryAfterMs: Q(a.retryAfterMs),
|
|
555
|
+
maxBytes: Q(a.maxBytes)
|
|
500
556
|
});
|
|
501
557
|
}
|
|
502
|
-
},
|
|
558
|
+
}, Re = class {
|
|
503
559
|
deps;
|
|
504
560
|
installed = !1;
|
|
505
561
|
onVisibility = () => {
|
|
@@ -534,7 +590,7 @@ var Ie = class extends Y {
|
|
|
534
590
|
});
|
|
535
591
|
}
|
|
536
592
|
flush(e) {
|
|
537
|
-
let { config: t, diagnostics:
|
|
593
|
+
let { config: t, diagnostics: r } = this.deps;
|
|
538
594
|
if (e === "hidden") {
|
|
539
595
|
this.flushAlive();
|
|
540
596
|
return;
|
|
@@ -545,29 +601,29 @@ var Ie = class extends Y {
|
|
|
545
601
|
}
|
|
546
602
|
let i = this.endpointUrl();
|
|
547
603
|
if (i === null) return;
|
|
548
|
-
let
|
|
549
|
-
if (!
|
|
550
|
-
let
|
|
551
|
-
if (!
|
|
552
|
-
if (
|
|
553
|
-
|
|
604
|
+
let a = this.deps.drainForExit();
|
|
605
|
+
if (!a || a.records.length === 0) return;
|
|
606
|
+
let o = this.serialize(a, e);
|
|
607
|
+
if (!o) return;
|
|
608
|
+
if (T(o.body) > 6e4) {
|
|
609
|
+
R(a, r, this.deps.onLoss);
|
|
554
610
|
return;
|
|
555
611
|
}
|
|
556
|
-
i.searchParams.set(
|
|
557
|
-
let
|
|
558
|
-
if (
|
|
559
|
-
this.keepaliveFetch(
|
|
560
|
-
let e = new Headers(
|
|
561
|
-
return e.set(
|
|
612
|
+
i.searchParams.set(n, a.id), i.searchParams.set(w, e);
|
|
613
|
+
let s = i.toString(), c = this.deps.exitHeaders();
|
|
614
|
+
if (c) {
|
|
615
|
+
this.keepaliveFetch(s, a, o.body, e, () => {
|
|
616
|
+
let e = new Headers(c);
|
|
617
|
+
return e.set(g, o.contentType), e.set(h, a.id), e;
|
|
562
618
|
});
|
|
563
619
|
return;
|
|
564
620
|
}
|
|
565
621
|
if (t.headers) {
|
|
566
|
-
|
|
622
|
+
R(a, r, this.deps.onLoss);
|
|
567
623
|
return;
|
|
568
624
|
}
|
|
569
|
-
let
|
|
570
|
-
|
|
625
|
+
let u = this.beacon(s, o.body);
|
|
626
|
+
u !== "sent" && (u === "refused" ? R(a, r, this.deps.onLoss) : this.keepaliveFetch(s, a, o.body, e, () => new Headers({ [g]: l })));
|
|
571
627
|
}
|
|
572
628
|
flushAlive() {
|
|
573
629
|
let { diagnostics: e } = this.deps, t = "The flush of the hidden document failed.";
|
|
@@ -581,10 +637,11 @@ var Ie = class extends Y {
|
|
|
581
637
|
let { diagnostics: n } = this.deps, r = this.deps.drainForExit();
|
|
582
638
|
if (!r || r.records.length === 0) return;
|
|
583
639
|
let i = this.serialize(r, e);
|
|
584
|
-
i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () =>
|
|
640
|
+
i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => D(() => t(Z(r, i)))) !== !0) && R(r, n, this.deps.onLoss);
|
|
585
641
|
}
|
|
586
642
|
serialize(e, t) {
|
|
587
|
-
|
|
643
|
+
let n = Y(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
|
|
644
|
+
return n || this.deps.onLoss?.("unserializable", e.records, [e.id]), n;
|
|
588
645
|
}
|
|
589
646
|
endpointUrl() {
|
|
590
647
|
let { endpoint: e } = this.deps.config;
|
|
@@ -596,32 +653,32 @@ var Ie = class extends Y {
|
|
|
596
653
|
return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
|
|
597
654
|
}) ?? "unavailable";
|
|
598
655
|
}
|
|
599
|
-
keepaliveFetch(e, t, n, r) {
|
|
600
|
-
let { config:
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
});
|
|
611
|
-
});
|
|
656
|
+
keepaliveFetch(e, t, n, r, i) {
|
|
657
|
+
let { config: a, diagnostics: o } = this.deps, s = () => {
|
|
658
|
+
R(t, o, this.deps.onLoss);
|
|
659
|
+
};
|
|
660
|
+
o.guard("transport.http_error", "The keepalive fetch failed.", () => (fetch(e, {
|
|
661
|
+
method: "POST",
|
|
662
|
+
body: n,
|
|
663
|
+
headers: i(),
|
|
664
|
+
credentials: a.credentials,
|
|
665
|
+
keepalive: !0
|
|
666
|
+
}).catch((e) => {
|
|
667
|
+
o.report("transport.http_error", "The exit flush failed.", { reason: r }, e), s();
|
|
668
|
+
}), !0)) !== !0 && s();
|
|
612
669
|
}
|
|
613
670
|
};
|
|
614
671
|
//#endregion
|
|
615
672
|
//#region src/transport/compression.ts
|
|
616
|
-
async function
|
|
673
|
+
async function ze(e) {
|
|
617
674
|
let t = globalThis.CompressionStream;
|
|
618
675
|
if (t === void 0) return null;
|
|
619
|
-
let n = new Blob([e]).stream().pipeThrough(new t(
|
|
676
|
+
let n = new Blob([e]).stream().pipeThrough(new t(i)), r = await new Response(n).arrayBuffer();
|
|
620
677
|
return new Uint8Array(r);
|
|
621
678
|
}
|
|
622
679
|
//#endregion
|
|
623
680
|
//#region src/transport/http-transport.ts
|
|
624
|
-
var
|
|
681
|
+
var Be = "In a cross-origin iframe, the session cookie is a third-party cookie. The browser often blocks it. Forward the records to the platform document. As an alternative, issue the cookie with the Partitioned attribute.", Ve = class extends X {
|
|
625
682
|
cachedHeaders;
|
|
626
683
|
async send(e, t) {
|
|
627
684
|
let { endpoint: n } = this.config;
|
|
@@ -634,31 +691,31 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
634
691
|
let t = this.cachedHeaders;
|
|
635
692
|
return t?.source === e && t.endpoint === this.config.endpoint ? t.headers : void 0;
|
|
636
693
|
}
|
|
637
|
-
async post(
|
|
638
|
-
let
|
|
639
|
-
if (!
|
|
640
|
-
let
|
|
641
|
-
if (this.rejectsCredentials(
|
|
642
|
-
this.accept(
|
|
694
|
+
async post(t, n, r) {
|
|
695
|
+
let i = this.serialize(t);
|
|
696
|
+
if (!i) return;
|
|
697
|
+
let a = await this.attempt(t, n, i, r);
|
|
698
|
+
if (this.rejectsCredentials(a.status) && typeof this.config.headers == "function" && (this.cachedHeaders = void 0, a = await this.attempt(t, n, i, r)), a.ok) {
|
|
699
|
+
this.accept(a.headers.get(e));
|
|
643
700
|
return;
|
|
644
701
|
}
|
|
645
|
-
let
|
|
646
|
-
throw this.reject(
|
|
647
|
-
retryAfterMs:
|
|
648
|
-
maxBytes:
|
|
649
|
-
advice:
|
|
702
|
+
let o = a.status, s = Oe(a.headers.get(d)), c = o === 413 ? await this.readMaxBytes(a) : void 0;
|
|
703
|
+
throw this.reject(o, t.id, {
|
|
704
|
+
retryAfterMs: s,
|
|
705
|
+
maxBytes: c,
|
|
706
|
+
advice: Be
|
|
650
707
|
});
|
|
651
708
|
}
|
|
652
709
|
rejectsCredentials(e) {
|
|
653
710
|
return e === 401 || e === 403;
|
|
654
711
|
}
|
|
655
|
-
async attempt(e, n, r,
|
|
656
|
-
let
|
|
657
|
-
|
|
658
|
-
let
|
|
659
|
-
typeof
|
|
660
|
-
let
|
|
661
|
-
return
|
|
712
|
+
async attempt(e, n, r, o) {
|
|
713
|
+
let s = Date.now() + t, c = new Headers(await this.before(this.resolveHeaders(n), s));
|
|
714
|
+
c.set(g, r.contentType), c.set(h, e.id), c.set(a, String(e.attempts));
|
|
715
|
+
let l = await this.before(this.encodeBody(r.body), s);
|
|
716
|
+
typeof l != "string" && c.set(ee, i);
|
|
717
|
+
let u = this.keepalive(l);
|
|
718
|
+
return u && o?.(), this.dispatch(n, c, l, s, u);
|
|
662
719
|
}
|
|
663
720
|
async before(e, t) {
|
|
664
721
|
try {
|
|
@@ -669,11 +726,11 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
669
726
|
}
|
|
670
727
|
timeout() {
|
|
671
728
|
let e = `The request took longer than ${String(t)} ms.`;
|
|
672
|
-
return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new
|
|
729
|
+
return this.diagnostics.report("transport.timeout", e, { endpoint: this.config.endpoint }), new U("timeout", e);
|
|
673
730
|
}
|
|
674
731
|
async encodeBody(e) {
|
|
675
732
|
let { config: t } = this;
|
|
676
|
-
return t.compression !== "gzip" ||
|
|
733
|
+
return t.compression !== "gzip" || T(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => ze(e)) ?? e;
|
|
677
734
|
}
|
|
678
735
|
async dispatch(e, t, n, r, i) {
|
|
679
736
|
let { config: a } = this, o = new AbortController(), s = setTimeout(() => {
|
|
@@ -681,7 +738,7 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
681
738
|
}, Math.max(0, r - Date.now()));
|
|
682
739
|
k(s);
|
|
683
740
|
try {
|
|
684
|
-
return await
|
|
741
|
+
return await D(() => fetch(e, {
|
|
685
742
|
method: "POST",
|
|
686
743
|
headers: t,
|
|
687
744
|
body: n,
|
|
@@ -693,13 +750,13 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
693
750
|
} catch {
|
|
694
751
|
if (o.signal.aborted) throw this.timeout();
|
|
695
752
|
let e = globalThis.navigator?.onLine;
|
|
696
|
-
throw new
|
|
753
|
+
throw new U(e === !1 ? "offline" : "transient", "A network error occurred.");
|
|
697
754
|
} finally {
|
|
698
755
|
clearTimeout(s);
|
|
699
756
|
}
|
|
700
757
|
}
|
|
701
758
|
keepalive(e) {
|
|
702
|
-
let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ?
|
|
759
|
+
let t = globalThis.document?.visibilityState === "hidden", n = typeof e == "string" ? T(e) : e.byteLength;
|
|
703
760
|
return t && n <= 6e4;
|
|
704
761
|
}
|
|
705
762
|
async readMaxBytes(e) {
|
|
@@ -719,24 +776,25 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
719
776
|
headers: n
|
|
720
777
|
}), n ?? {};
|
|
721
778
|
}
|
|
722
|
-
},
|
|
779
|
+
}, He = class {
|
|
723
780
|
storage;
|
|
724
781
|
transport;
|
|
725
782
|
diagnostics;
|
|
726
|
-
config;
|
|
727
783
|
batchesPerDrain;
|
|
784
|
+
onLoss;
|
|
728
785
|
timer = null;
|
|
729
786
|
attempt = 0;
|
|
730
787
|
draining = !1;
|
|
731
788
|
stopped = !1;
|
|
789
|
+
maxAttempts;
|
|
732
790
|
onOnline = () => {
|
|
733
791
|
this.attempt = 0, this.schedule(0);
|
|
734
792
|
};
|
|
735
|
-
constructor(e, t, n, r, i = 20) {
|
|
736
|
-
this.storage = e, this.transport = t, this.diagnostics = n, this.
|
|
793
|
+
constructor(e, t, n, r, i = 20, a = () => void 0) {
|
|
794
|
+
this.storage = e, this.transport = t, this.diagnostics = n, this.batchesPerDrain = i, this.onLoss = a, this.maxAttempts = N(r.retention).maxAttempts;
|
|
737
795
|
}
|
|
738
796
|
start() {
|
|
739
|
-
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(
|
|
797
|
+
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(r);
|
|
740
798
|
}
|
|
741
799
|
nudge() {
|
|
742
800
|
this.draining || this.schedule(m);
|
|
@@ -758,7 +816,7 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
758
816
|
this.timer = t, k(t);
|
|
759
817
|
}
|
|
760
818
|
bounded(e) {
|
|
761
|
-
return O(e,
|
|
819
|
+
return O(e, S);
|
|
762
820
|
}
|
|
763
821
|
clearTimer() {
|
|
764
822
|
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
@@ -771,7 +829,7 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
771
829
|
if (!this.draining) {
|
|
772
830
|
this.draining = !0;
|
|
773
831
|
try {
|
|
774
|
-
await
|
|
832
|
+
await P("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(r);
|
|
775
833
|
} finally {
|
|
776
834
|
this.draining = !1;
|
|
777
835
|
}
|
|
@@ -779,25 +837,25 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
779
837
|
}
|
|
780
838
|
async drainLocked() {
|
|
781
839
|
try {
|
|
782
|
-
if (globalThis.navigator?.onLine === !1) return this.schedule(
|
|
840
|
+
if (globalThis.navigator?.onLine === !1) return this.schedule(r), !0;
|
|
783
841
|
let e = await this.bounded(this.storage.take(this.batchesPerDrain));
|
|
784
|
-
if (e.length === 0) return this.schedule(
|
|
842
|
+
if (e.length === 0) return this.schedule(r), !0;
|
|
785
843
|
for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
|
|
786
|
-
return this.schedule(e.length === this.batchesPerDrain ? 0 :
|
|
844
|
+
return this.schedule(e.length === this.batchesPerDrain ? 0 : r), !0;
|
|
787
845
|
} catch (e) {
|
|
788
846
|
return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
|
|
789
847
|
}
|
|
790
848
|
}
|
|
791
849
|
async deliver(e) {
|
|
792
|
-
if (e.attempts >=
|
|
850
|
+
if (e.attempts >= this.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
|
|
793
851
|
batchId: e.id,
|
|
794
852
|
records: e.records.length
|
|
795
|
-
}), await this.bounded(this.storage.remove(e.id)), !0;
|
|
853
|
+
}), this.onLoss("max_attempts", e.records, [e.id]), await this.bounded(this.storage.remove(e.id)), !0;
|
|
796
854
|
try {
|
|
797
855
|
return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
|
|
798
856
|
} catch (t) {
|
|
799
|
-
let n = t instanceof
|
|
800
|
-
return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(
|
|
857
|
+
let n = t instanceof U ? t : void 0;
|
|
858
|
+
return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(r), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
|
|
801
859
|
}
|
|
802
860
|
}
|
|
803
861
|
async replaceStored(e, t) {
|
|
@@ -806,10 +864,10 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
806
864
|
for (let e of n) await this.bounded(this.storage.save(e));
|
|
807
865
|
}
|
|
808
866
|
toStorable(e, t) {
|
|
809
|
-
let n = t instanceof
|
|
810
|
-
if (n?.kind === "permanent") return [];
|
|
867
|
+
let n = t instanceof U ? t : void 0;
|
|
868
|
+
if (n?.kind === "permanent") return this.onLoss("rejected", e.records, [e.id]), [];
|
|
811
869
|
if (n?.kind !== "too_large") return [e];
|
|
812
|
-
let r =
|
|
870
|
+
let r = ge(e, this.diagnostics);
|
|
813
871
|
return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
|
|
814
872
|
from: e.records.length,
|
|
815
873
|
to: r[0].records.length,
|
|
@@ -817,24 +875,15 @@ var Q = "In a cross-origin iframe, the session cookie is a third-party cookie. T
|
|
|
817
875
|
}), r) : (this.diagnostics.report("transport.dropped_permanent", "One record is larger than the server limit. The library dropped it.", {
|
|
818
876
|
batchId: e.id,
|
|
819
877
|
bodies: e.records.map((e) => e.body)
|
|
820
|
-
}), []);
|
|
878
|
+
}), this.onLoss("rejected", e.records, [e.id]), []);
|
|
821
879
|
}
|
|
822
880
|
};
|
|
823
881
|
//#endregion
|
|
824
882
|
//#region src/core/pipeline.ts
|
|
825
|
-
function
|
|
826
|
-
return e.attributes[
|
|
883
|
+
function Ue(e) {
|
|
884
|
+
return e.attributes[y] === oe;
|
|
827
885
|
}
|
|
828
|
-
var
|
|
829
|
-
logs: {
|
|
830
|
-
flushIntervalMs: y,
|
|
831
|
-
batchSize: 100
|
|
832
|
-
},
|
|
833
|
-
metrics: {
|
|
834
|
-
flushIntervalMs: x,
|
|
835
|
-
batchSize: 500
|
|
836
|
-
}
|
|
837
|
-
}, $ = class {
|
|
886
|
+
var $ = class {
|
|
838
887
|
options;
|
|
839
888
|
onFlush;
|
|
840
889
|
pending = [];
|
|
@@ -863,7 +912,7 @@ var He = {
|
|
|
863
912
|
clearTimer() {
|
|
864
913
|
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
865
914
|
}
|
|
866
|
-
},
|
|
915
|
+
}, We = class {
|
|
867
916
|
transport;
|
|
868
917
|
storage;
|
|
869
918
|
retry;
|
|
@@ -872,11 +921,11 @@ var He = {
|
|
|
872
921
|
unconfirmed = /* @__PURE__ */ new Map();
|
|
873
922
|
queue = [];
|
|
874
923
|
open = /* @__PURE__ */ new Set();
|
|
875
|
-
ceiling = new
|
|
924
|
+
ceiling = new pe();
|
|
876
925
|
inFlight = 0;
|
|
877
926
|
pumpScheduled = !1;
|
|
878
927
|
stopped = !1;
|
|
879
|
-
constructor(e, t, n, r, i
|
|
928
|
+
constructor(e, t, n, r, i) {
|
|
880
929
|
this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
|
|
881
930
|
let a = (e) => {
|
|
882
931
|
this.claim(e);
|
|
@@ -887,7 +936,7 @@ var He = {
|
|
|
887
936
|
};
|
|
888
937
|
}
|
|
889
938
|
push(e) {
|
|
890
|
-
this.stopped || (e.observedTimeUnixNano =
|
|
939
|
+
this.stopped || (e.observedTimeUnixNano = fe(), this.route(e));
|
|
891
940
|
}
|
|
892
941
|
drainPending() {
|
|
893
942
|
return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
|
|
@@ -910,7 +959,7 @@ var He = {
|
|
|
910
959
|
}
|
|
911
960
|
toBatch(e) {
|
|
912
961
|
return e.length === 0 ? null : {
|
|
913
|
-
id:
|
|
962
|
+
id: he(this.diagnostics),
|
|
914
963
|
records: e,
|
|
915
964
|
createdAt: Date.now(),
|
|
916
965
|
attempts: 0
|
|
@@ -918,7 +967,7 @@ var He = {
|
|
|
918
967
|
}
|
|
919
968
|
route(e) {
|
|
920
969
|
try {
|
|
921
|
-
let t =
|
|
970
|
+
let t = Ue(e) ? this.streams.metrics : this.streams.logs;
|
|
922
971
|
if (!this.ceiling.allow(e)) {
|
|
923
972
|
this.diagnostics.count("record.dropped_by_ceiling");
|
|
924
973
|
return;
|
|
@@ -996,10 +1045,10 @@ var He = {
|
|
|
996
1045
|
}
|
|
997
1046
|
async store(e) {
|
|
998
1047
|
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
999
|
-
await O(this.storage.save(e),
|
|
1048
|
+
await O(this.storage.save(e), S), this.retry.nudge();
|
|
1000
1049
|
});
|
|
1001
1050
|
}
|
|
1002
|
-
},
|
|
1051
|
+
}, Ge = class e {
|
|
1003
1052
|
storage;
|
|
1004
1053
|
retry;
|
|
1005
1054
|
pipeline;
|
|
@@ -1009,23 +1058,33 @@ var He = {
|
|
|
1009
1058
|
this.storage = e, this.retry = t, this.pipeline = n, this.exitFlush = r, this.diagnostics = i;
|
|
1010
1059
|
}
|
|
1011
1060
|
static async create(t) {
|
|
1012
|
-
let { config: n, diagnostics: r } = t, i = await
|
|
1013
|
-
let i =
|
|
1014
|
-
i &&
|
|
1015
|
-
}, o = n.transport ? void 0 : new
|
|
1061
|
+
let { config: n, diagnostics: r } = t, i = await De(n.storage, le, N(n.retention), r, t.onGap), a = (e) => {
|
|
1062
|
+
let i = j(e, r);
|
|
1063
|
+
i && M(t.remote, n, i);
|
|
1064
|
+
}, { onLoss: o } = t, s = n.transport ? void 0 : new Ve(n, r, a, o), c = s ?? new Le(n, r, a, o), l = new He(i, c, r, n, 20, o), { batching: u } = n, d = new We(c, i, l, r, {
|
|
1065
|
+
logs: {
|
|
1066
|
+
flushIntervalMs: u.logFlushIntervalMs,
|
|
1067
|
+
batchSize: u.logBatchSize
|
|
1068
|
+
},
|
|
1069
|
+
metrics: {
|
|
1070
|
+
flushIntervalMs: u.metricFlushIntervalMs,
|
|
1071
|
+
batchSize: u.metricBatchSize
|
|
1072
|
+
}
|
|
1073
|
+
}), f = new Re({
|
|
1016
1074
|
config: n,
|
|
1017
1075
|
diagnostics: r,
|
|
1018
|
-
drainForExit: () =>
|
|
1019
|
-
flushAlive: () =>
|
|
1020
|
-
exitHeaders: () =>
|
|
1021
|
-
|
|
1076
|
+
drainForExit: () => d.drainForExit(),
|
|
1077
|
+
flushAlive: () => d.flushPending(),
|
|
1078
|
+
exitHeaders: () => s?.lastHeaders(),
|
|
1079
|
+
onLoss: o
|
|
1080
|
+
}), p = !1;
|
|
1022
1081
|
try {
|
|
1023
|
-
|
|
1082
|
+
f.install(), l.start(), p = !0;
|
|
1024
1083
|
} finally {
|
|
1025
|
-
|
|
1084
|
+
p || (f.uninstall(), l.stop());
|
|
1026
1085
|
}
|
|
1027
|
-
let
|
|
1028
|
-
return
|
|
1086
|
+
let m = new e(i, l, d, f, r);
|
|
1087
|
+
return m.importEmergency(), m;
|
|
1029
1088
|
}
|
|
1030
1089
|
push(e) {
|
|
1031
1090
|
this.pipeline.push(e);
|
|
@@ -1045,6 +1104,6 @@ var He = {
|
|
|
1045
1104
|
}
|
|
1046
1105
|
};
|
|
1047
1106
|
//#endregion
|
|
1048
|
-
export {
|
|
1107
|
+
export { Ge as Sender, z as n, B as t };
|
|
1049
1108
|
|
|
1050
|
-
//# sourceMappingURL=sender-
|
|
1109
|
+
//# sourceMappingURL=sender-BBY0IcUo.js.map
|