@utk09/ui-observability 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -1
- package/README.md +122 -0
- package/dist/bus/bus.d.ts +30 -0
- package/dist/bus-CUXRY0JR.cjs +2 -0
- package/dist/bus-CUXRY0JR.cjs.map +1 -0
- package/dist/{bus-DfAbg_pg.js → bus-DPDrlUBY.js} +96 -50
- package/dist/bus-DPDrlUBY.js.map +1 -0
- package/dist/capture/console.d.ts +37 -0
- package/dist/capture/errors.d.ts +2 -4
- package/dist/capture/long-frames.d.ts +31 -0
- package/dist/capture/storm.d.ts +17 -0
- package/dist/capture/types.d.ts +2 -0
- package/dist/console-CNljJict.js +81 -0
- package/dist/console-CNljJict.js.map +1 -0
- package/dist/console-PKzc-FmR.cjs +2 -0
- package/dist/console-PKzc-FmR.cjs.map +1 -0
- package/dist/constants-B28fDv2F.cjs +2 -0
- package/dist/constants-B28fDv2F.cjs.map +1 -0
- package/dist/constants-Bu49bm39.js +93 -0
- package/dist/constants-Bu49bm39.js.map +1 -0
- package/dist/constants.d.ts +32 -2
- package/dist/core/breadcrumbs.d.ts +1 -1
- package/dist/core/pipeline.d.ts +2 -2
- package/dist/core/record.d.ts +3 -0
- package/dist/core/remote-rules.d.ts +17 -0
- package/dist/core/remote-sampling.d.ts +65 -0
- package/dist/core/runtime.d.ts +10 -4
- package/dist/core/sampling.d.ts +5 -2
- package/dist/core/sender.d.ts +3 -0
- package/dist/errors-C78ZTjet.cjs +3 -0
- package/dist/errors-C78ZTjet.cjs.map +1 -0
- package/dist/{errors-4MQyjZVj.js → errors-Dnc-X4Ec.js} +19 -20
- package/dist/errors-Dnc-X4Ec.js.map +1 -0
- package/dist/global-scope-BN-Io_yv.cjs +2 -0
- package/dist/global-scope-BN-Io_yv.cjs.map +1 -0
- package/dist/global-scope-dp2jADRl.js +19 -0
- package/dist/global-scope-dp2jADRl.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +287 -242
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-D0p3iMD0.cjs +2 -0
- package/dist/{indexeddb-storage-CcEJlq2l.cjs.map → indexeddb-storage-D0p3iMD0.cjs.map} +1 -1
- package/dist/{indexeddb-storage-0LtUALBg.js → indexeddb-storage-uD4oaRMc.js} +10 -10
- package/dist/{indexeddb-storage-0LtUALBg.js.map → indexeddb-storage-uD4oaRMc.js.map} +1 -1
- package/dist/{interactions-BMNPQ3WH.cjs → interactions-CsE2y_fQ.cjs} +2 -2
- package/dist/{interactions-BMNPQ3WH.cjs.map → interactions-CsE2y_fQ.cjs.map} +1 -1
- package/dist/{interactions-BaCmoGLB.js → interactions-igKTAJvj.js} +2 -2
- package/dist/{interactions-BaCmoGLB.js.map → interactions-igKTAJvj.js.map} +1 -1
- package/dist/library-request-Br_T09Bn.cjs +2 -0
- package/dist/library-request-Br_T09Bn.cjs.map +1 -0
- package/dist/library-request-Dt0fXhcn.js +14 -0
- package/dist/library-request-Dt0fXhcn.js.map +1 -0
- package/dist/long-frames-6pnjWSSR.js +65 -0
- package/dist/long-frames-6pnjWSSR.js.map +1 -0
- package/dist/long-frames-DahhqM6u.cjs +2 -0
- package/dist/long-frames-DahhqM6u.cjs.map +1 -0
- package/dist/models/bus.d.ts +16 -0
- package/dist/models/config.d.ts +90 -0
- package/dist/network-CZ0aFUsy.cjs +2 -0
- package/dist/network-CZ0aFUsy.cjs.map +1 -0
- package/dist/{network-jQ2t8rU4.js → network-aSNbwpue.js} +16 -15
- package/dist/network-aSNbwpue.js.map +1 -0
- package/dist/{platform-YuByH8A5.js → platform-BwbMRwHm.js} +7 -7
- package/dist/{platform-YuByH8A5.js.map → platform-BwbMRwHm.js.map} +1 -1
- package/dist/{platform-ByQllE_W.cjs → platform-D_XkVIF6.cjs} +2 -2
- package/dist/{platform-ByQllE_W.cjs.map → platform-D_XkVIF6.cjs.map} +1 -1
- package/dist/remote-rules-5UA23alm.js +86 -0
- package/dist/remote-rules-5UA23alm.js.map +1 -0
- package/dist/remote-rules-rJJZKVG8.cjs +2 -0
- package/dist/remote-rules-rJJZKVG8.cjs.map +1 -0
- package/dist/sampling-E4x92Nn2.cjs +2 -0
- package/dist/sampling-E4x92Nn2.cjs.map +1 -0
- package/dist/sampling-J1eahbfT.js +160 -0
- package/dist/sampling-J1eahbfT.js.map +1 -0
- package/dist/sanitize-BMhh8ghJ.cjs +2 -0
- package/dist/sanitize-BMhh8ghJ.cjs.map +1 -0
- package/dist/sanitize-UJ-4Lb0n.js +114 -0
- package/dist/sanitize-UJ-4Lb0n.js.map +1 -0
- package/dist/sender-B6ufz26f.cjs +3 -0
- package/dist/sender-B6ufz26f.cjs.map +1 -0
- package/dist/{sender-BIob8eZz.js → sender-G6v4Uqi4.js} +304 -219
- package/dist/sender-G6v4Uqi4.js.map +1 -0
- package/dist/storm-BtzgLOCX.cjs +2 -0
- package/dist/storm-BtzgLOCX.cjs.map +1 -0
- package/dist/storm-DJkEZP_8.js +10 -0
- package/dist/storm-DJkEZP_8.js.map +1 -0
- package/dist/transport/custom-transport.d.ts +20 -0
- package/dist/transport/errors.d.ts +2 -1
- package/dist/transport/exit-flush.d.ts +15 -0
- package/dist/transport/http-transport.d.ts +2 -24
- package/dist/transport/memory-transport.d.ts +30 -0
- package/dist/transport/retry-engine.d.ts +2 -2
- package/dist/transport/serializers/select.d.ts +12 -1
- package/dist/transport/status-transport.d.ts +72 -0
- package/dist/utils/deadline.d.ts +7 -0
- package/dist/utils/global-scope.d.ts +20 -0
- package/dist/utils/library-console.d.ts +11 -0
- package/dist/utils/library-request.d.ts +12 -0
- package/package.json +1 -1
- package/dist/bus-DeZzr2bx.cjs +0 -2
- package/dist/bus-DeZzr2bx.cjs.map +0 -1
- package/dist/bus-DfAbg_pg.js.map +0 -1
- package/dist/constants-C8nZQBmQ.js +0 -86
- package/dist/constants-C8nZQBmQ.js.map +0 -1
- package/dist/constants-IBL_jd5R.cjs +0 -2
- package/dist/constants-IBL_jd5R.cjs.map +0 -1
- package/dist/errors-4MQyjZVj.js.map +0 -1
- package/dist/errors-CUdShXe7.cjs +0 -3
- package/dist/errors-CUdShXe7.cjs.map +0 -1
- package/dist/indexeddb-storage-CcEJlq2l.cjs +0 -2
- package/dist/network-DBNvxCE3.cjs +0 -2
- package/dist/network-DBNvxCE3.cjs.map +0 -1
- package/dist/network-jQ2t8rU4.js.map +0 -1
- package/dist/sampling-CbYySsZ1.js +0 -251
- package/dist/sampling-CbYySsZ1.js.map +0 -1
- package/dist/sampling-Cs50xsZl.cjs +0 -2
- package/dist/sampling-Cs50xsZl.cjs.map +0 -1
- package/dist/sender-BIob8eZz.js.map +0 -1
- package/dist/sender-iOjzcueM.cjs +0 -3
- package/dist/sender-iOjzcueM.cjs.map +0 -1
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { $t as e, A as t,
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { $t as e, A as t, At as n, Dt as r, Ft as i, G as a, Ht as o, I as s, J as c, K as l, O as u, Ot as d, Pt as f, Qt as ee, R as p, Ut as te, Vt as m, X as ne, Y as re, an as h, bt as g, en as _, ft as v, gt as y, ht as b, in as x, k as ie, l as ae, ln as oe, lt as se, on as S, pt as ce, q as le, qt as ue, rn as de, un as fe, ut as pe, v as C, xt as me, z as w } from "./constants-Bu49bm39.js";
|
|
2
|
+
import { a as T, i as he, l as E, m as D, t as O } from "./sampling-J1eahbfT.js";
|
|
3
|
+
import { o as k, t as A } from "./sanitize-UJ-4Lb0n.js";
|
|
4
|
+
import { t as j } from "./unref-16maCyKA.js";
|
|
5
|
+
import { n as M, t as N } from "./remote-rules-5UA23alm.js";
|
|
6
|
+
import { n as P } from "./library-request-Dt0fXhcn.js";
|
|
4
7
|
//#region src/models/batch.ts
|
|
5
|
-
function
|
|
8
|
+
function F(e) {
|
|
6
9
|
if (typeof e != "object" || !e) return !1;
|
|
7
10
|
let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
|
|
8
11
|
return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
|
|
9
12
|
}
|
|
10
|
-
function
|
|
13
|
+
function I(e, t) {
|
|
11
14
|
if (e.records.length < 2) return null;
|
|
12
15
|
let n = Math.floor(e.records.length / 2), r = (n) => ({
|
|
13
|
-
id:
|
|
16
|
+
id: E(t),
|
|
14
17
|
records: n,
|
|
15
18
|
createdAt: e.createdAt,
|
|
16
19
|
attempts: e.attempts
|
|
@@ -19,13 +22,13 @@ function P(e, t) {
|
|
|
19
22
|
}
|
|
20
23
|
//#endregion
|
|
21
24
|
//#region src/utils/lock.ts
|
|
22
|
-
function
|
|
25
|
+
function L(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
23
26
|
let i = globalThis.navigator?.locks;
|
|
24
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();
|
|
25
28
|
}
|
|
26
29
|
//#endregion
|
|
27
30
|
//#region src/storage/keys.ts
|
|
28
|
-
function
|
|
31
|
+
function R(e, t) {
|
|
29
32
|
let n = [];
|
|
30
33
|
return t.guard("storage.unavailable", "The library could not list the localStorage keys.", () => {
|
|
31
34
|
for (let t = 0; t < localStorage.length; t++) {
|
|
@@ -36,57 +39,57 @@ function I(e, t) {
|
|
|
36
39
|
}
|
|
37
40
|
//#endregion
|
|
38
41
|
//#region src/storage/emergency-queue.ts
|
|
39
|
-
function
|
|
42
|
+
function ge(e) {
|
|
40
43
|
let t = String(e.createdAt).padStart(14, "0");
|
|
41
|
-
return `${
|
|
44
|
+
return `${p}${t}.${e.id}`;
|
|
42
45
|
}
|
|
43
|
-
function
|
|
46
|
+
function _e(e, t) {
|
|
44
47
|
let n = t.guard("storage.degraded", "An emergency entry is not valid JSON. The library dropped it.", () => JSON.parse(e));
|
|
45
|
-
return n === void 0 ? null :
|
|
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);
|
|
46
49
|
}
|
|
47
|
-
async function
|
|
48
|
-
let
|
|
49
|
-
for (let
|
|
50
|
-
let
|
|
51
|
-
let e = localStorage.getItem(
|
|
52
|
-
return localStorage.removeItem(
|
|
50
|
+
async function ve(t, n) {
|
|
51
|
+
let r = 0;
|
|
52
|
+
for (let i of R(p, n)) {
|
|
53
|
+
let a = n.guard("storage.unavailable", "The library could not read the emergency queue.", () => {
|
|
54
|
+
let e = localStorage.getItem(i);
|
|
55
|
+
return localStorage.removeItem(i), e;
|
|
53
56
|
});
|
|
54
|
-
if (!
|
|
55
|
-
let
|
|
56
|
-
if (
|
|
57
|
-
await
|
|
57
|
+
if (!a) continue;
|
|
58
|
+
let o = _e(a, n);
|
|
59
|
+
if (o !== null) try {
|
|
60
|
+
await T(t.save(o), e), r++;
|
|
58
61
|
} catch (e) {
|
|
59
|
-
|
|
62
|
+
n.report("storage.degraded", "The library could not recover an emergency batch.", { key: i }, e);
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
return
|
|
65
|
+
return r;
|
|
63
66
|
}
|
|
64
|
-
function
|
|
67
|
+
function z(e, t) {
|
|
65
68
|
let n = `writing the emergency queue, ${String(e.records.length)} records`;
|
|
66
69
|
t.guard("storage.quota_exceeded", n, () => {
|
|
67
|
-
let n =
|
|
70
|
+
let n = R(p, t);
|
|
68
71
|
for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
|
|
69
|
-
localStorage.setItem(
|
|
72
|
+
localStorage.setItem(ge(e), JSON.stringify(e));
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
|
-
async function
|
|
73
|
-
return await
|
|
75
|
+
async function ye(e, t) {
|
|
76
|
+
return await L("ui-observability.emergency", t, () => ve(e, t), { skipIfBusy: !1 }) ?? 0;
|
|
74
77
|
}
|
|
75
78
|
//#endregion
|
|
76
79
|
//#region src/storage/local-storage.ts
|
|
77
|
-
function
|
|
80
|
+
function be(e) {
|
|
78
81
|
let t = String(e.createdAt).padStart(14, "0");
|
|
79
|
-
return `${
|
|
82
|
+
return `${C}${t}.${e.id}`;
|
|
80
83
|
}
|
|
81
|
-
function
|
|
82
|
-
let t =
|
|
84
|
+
function xe(e) {
|
|
85
|
+
let t = C.length, n = Number(e.slice(t, t + 14));
|
|
83
86
|
return Number.isFinite(n) ? n : null;
|
|
84
87
|
}
|
|
85
|
-
var
|
|
88
|
+
var Se = class {
|
|
86
89
|
limits;
|
|
87
90
|
diagnostics;
|
|
88
91
|
onGap;
|
|
89
|
-
name =
|
|
92
|
+
name = de;
|
|
90
93
|
constructor(e, t, n) {
|
|
91
94
|
this.limits = e, this.diagnostics = t, this.onGap = n;
|
|
92
95
|
}
|
|
@@ -127,7 +130,7 @@ var pe = class {
|
|
|
127
130
|
this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
|
|
128
131
|
}, r = [];
|
|
129
132
|
for (let t of this.keys()) {
|
|
130
|
-
let i =
|
|
133
|
+
let i = xe(t);
|
|
131
134
|
i === null || i < e ? n(t) : r.push(t);
|
|
132
135
|
}
|
|
133
136
|
let i = r.length - this.limits.maxBatches;
|
|
@@ -147,7 +150,7 @@ var pe = class {
|
|
|
147
150
|
return Promise.resolve();
|
|
148
151
|
}
|
|
149
152
|
write(e, t) {
|
|
150
|
-
return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(
|
|
153
|
+
return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(be(e), JSON.stringify(e)), !0)) === !0;
|
|
151
154
|
}
|
|
152
155
|
evictForQuota() {
|
|
153
156
|
let e = this.keys(), t = {
|
|
@@ -168,7 +171,7 @@ var pe = class {
|
|
|
168
171
|
let t = this.diagnostics.guard("storage.unavailable", "The library could not read a stored batch.", () => localStorage.getItem(e));
|
|
169
172
|
if (!t) return null;
|
|
170
173
|
let n = this.diagnostics.guard("storage.degraded", "A stored batch is corrupt. The library removed it.", () => JSON.parse(t));
|
|
171
|
-
return n === void 0 ? null :
|
|
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);
|
|
172
175
|
}
|
|
173
176
|
keyOf(e) {
|
|
174
177
|
return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
|
|
@@ -182,18 +185,18 @@ var pe = class {
|
|
|
182
185
|
});
|
|
183
186
|
}
|
|
184
187
|
keys() {
|
|
185
|
-
return
|
|
188
|
+
return R(C, this.diagnostics);
|
|
186
189
|
}
|
|
187
190
|
};
|
|
188
191
|
//#endregion
|
|
189
192
|
//#region src/storage/memory-storage.ts
|
|
190
|
-
function
|
|
193
|
+
function B(e) {
|
|
191
194
|
return e.reduce((e, t) => e + t.records.length, 0);
|
|
192
195
|
}
|
|
193
|
-
var
|
|
196
|
+
var V = class {
|
|
194
197
|
limits;
|
|
195
198
|
onGap;
|
|
196
|
-
name =
|
|
199
|
+
name = x;
|
|
197
200
|
batches = [];
|
|
198
201
|
constructor(e, t) {
|
|
199
202
|
this.limits = e, this.onGap = t;
|
|
@@ -217,12 +220,12 @@ var W = class {
|
|
|
217
220
|
records: 0,
|
|
218
221
|
reason: "expired"
|
|
219
222
|
}, n = this.batches.filter((t) => t.createdAt < e);
|
|
220
|
-
this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records +=
|
|
223
|
+
this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += B(n);
|
|
221
224
|
let r = this.batches.length - this.limits.maxBatches;
|
|
222
225
|
if (r > 0) {
|
|
223
226
|
t.reason = "over_capacity";
|
|
224
227
|
let e = this.batches.slice(0, r);
|
|
225
|
-
this.batches = this.batches.slice(r), t.batches += e.length, t.records +=
|
|
228
|
+
this.batches = this.batches.slice(r), t.batches += e.length, t.records += B(e);
|
|
226
229
|
}
|
|
227
230
|
return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
|
|
228
231
|
}
|
|
@@ -235,8 +238,8 @@ var W = class {
|
|
|
235
238
|
close() {
|
|
236
239
|
return this.batches = [], Promise.resolve();
|
|
237
240
|
}
|
|
238
|
-
},
|
|
239
|
-
name:
|
|
241
|
+
}, Ce = {
|
|
242
|
+
name: h,
|
|
240
243
|
save: () => Promise.resolve(),
|
|
241
244
|
take: () => Promise.resolve([]),
|
|
242
245
|
remove: () => Promise.resolve(),
|
|
@@ -250,91 +253,109 @@ var W = class {
|
|
|
250
253
|
clear: () => Promise.resolve(),
|
|
251
254
|
close: () => Promise.resolve()
|
|
252
255
|
};
|
|
253
|
-
function
|
|
256
|
+
function we(e) {
|
|
254
257
|
return e.guard("storage.unavailable", "The library could not read indexedDB.", () => globalThis.indexedDB != null) === !0;
|
|
255
258
|
}
|
|
256
|
-
function
|
|
257
|
-
return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(
|
|
259
|
+
function Te(e) {
|
|
260
|
+
return e.guard("storage.unavailable", "The library could not write a test key to localStorage.", () => (localStorage.setItem(S, "1"), localStorage.removeItem(S), !0)) === !0;
|
|
258
261
|
}
|
|
259
|
-
async function
|
|
260
|
-
if (e === "none") return
|
|
261
|
-
if (e === "memory") return new
|
|
262
|
+
async function Ee(e, t, n, r, i) {
|
|
263
|
+
if (e === "none") return Ce;
|
|
264
|
+
if (e === "memory") return new V(n, i);
|
|
262
265
|
if (e === "indexeddb" || e === "auto") {
|
|
263
|
-
if (
|
|
266
|
+
if (we(r)) {
|
|
264
267
|
let e = await r.guardAsync("storage.unavailable", "The library could not open IndexedDB.", async () => {
|
|
265
|
-
let { IndexedDbStorage: e } = await import("./indexeddb-storage-
|
|
268
|
+
let { IndexedDbStorage: e } = await import("./indexeddb-storage-uD4oaRMc.js"), a = new e(t, n, r, i);
|
|
266
269
|
return await a.open(), a;
|
|
267
270
|
});
|
|
268
271
|
if (e) return e;
|
|
269
272
|
}
|
|
270
|
-
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB is not available. The library uses memory storage instead."), new
|
|
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";
|
|
271
286
|
}
|
|
272
|
-
|
|
287
|
+
};
|
|
288
|
+
function De(e) {
|
|
289
|
+
if (!e) return;
|
|
290
|
+
let t = Number(e);
|
|
291
|
+
if (Number.isFinite(t)) return Math.max(0, t * ce);
|
|
292
|
+
let n = Date.parse(e);
|
|
293
|
+
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
273
294
|
}
|
|
274
295
|
//#endregion
|
|
275
296
|
//#region src/transport/serializers/ecs.ts
|
|
276
|
-
function
|
|
277
|
-
return
|
|
297
|
+
function Oe(e) {
|
|
298
|
+
return b.test(e) ? Number(BigInt(e) / y) : Date.now();
|
|
278
299
|
}
|
|
279
|
-
function
|
|
300
|
+
function ke(e) {
|
|
280
301
|
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
|
|
281
302
|
}
|
|
282
|
-
function
|
|
303
|
+
function Ae(e, t, n) {
|
|
283
304
|
let r = e[t];
|
|
284
305
|
r === void 0 ? e[t] = n : Array.isArray(r) ? r.push(n) : e[t] = [r, n];
|
|
285
306
|
}
|
|
286
|
-
function
|
|
287
|
-
let i =
|
|
288
|
-
if (i !== null)
|
|
307
|
+
function U(e, t, n, r) {
|
|
308
|
+
let i = ke(n);
|
|
309
|
+
if (i !== null) Ae(e, t, i);
|
|
289
310
|
else if (typeof n == "object" && n && !r.has(n)) {
|
|
290
|
-
if (r.add(n), Array.isArray(n)) for (let i of n)
|
|
291
|
-
else for (let [i, a] of Object.entries(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);
|
|
292
313
|
r.delete(n);
|
|
293
314
|
}
|
|
294
315
|
}
|
|
295
|
-
function
|
|
316
|
+
function W(e) {
|
|
296
317
|
let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
|
|
297
|
-
for (let [r, i] of Object.entries(e))
|
|
318
|
+
for (let [r, i] of Object.entries(e)) U(t, r, i, n);
|
|
298
319
|
return t;
|
|
299
320
|
}
|
|
300
|
-
var
|
|
321
|
+
var je = {
|
|
301
322
|
name: "ecs",
|
|
302
323
|
serialize(e) {
|
|
303
324
|
return {
|
|
304
325
|
body: `${e.map((e) => {
|
|
305
|
-
let t =
|
|
326
|
+
let t = Oe(e.timeUnixNano);
|
|
306
327
|
return JSON.stringify({
|
|
307
328
|
"@timestamp": new Date(t).toISOString(),
|
|
308
329
|
message: e.body,
|
|
309
|
-
log: { level:
|
|
330
|
+
log: { level: s[e.severityText] ?? e.severityText.toLowerCase() },
|
|
310
331
|
trace: { id: e.traceId },
|
|
311
332
|
span: { id: e.spanId },
|
|
312
333
|
service: {
|
|
313
|
-
name: e.resource[
|
|
314
|
-
version: e.resource[
|
|
315
|
-
environment: e.resource[
|
|
334
|
+
name: e.resource[f],
|
|
335
|
+
version: e.resource[i],
|
|
336
|
+
environment: e.resource[n]
|
|
316
337
|
},
|
|
317
|
-
user_agent: { original: e.resource[
|
|
338
|
+
user_agent: { original: e.resource[d] },
|
|
318
339
|
url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
|
|
319
340
|
labels: {
|
|
320
|
-
...
|
|
321
|
-
...
|
|
341
|
+
...W(e.resource),
|
|
342
|
+
...W(e.attributes)
|
|
322
343
|
}
|
|
323
344
|
});
|
|
324
345
|
}).join("\n")}\n`,
|
|
325
|
-
contentType:
|
|
346
|
+
contentType: ie
|
|
326
347
|
};
|
|
327
348
|
}
|
|
328
349
|
};
|
|
329
350
|
//#endregion
|
|
330
351
|
//#region src/transport/serializers/otlp.ts
|
|
331
|
-
function
|
|
332
|
-
return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(
|
|
352
|
+
function G(e) {
|
|
353
|
+
return e == null ? null : typeof e == "string" ? { stringValue: e } : typeof e == "boolean" ? { boolValue: e } : typeof e == "number" ? Number.isInteger(e) ? { intValue: String(e) } : { doubleValue: e } : typeof e == "bigint" ? { intValue: e.toString() } : Array.isArray(e) ? { arrayValue: { values: e.map(G).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: K(e) } } : null;
|
|
333
354
|
}
|
|
334
|
-
function
|
|
355
|
+
function K(e) {
|
|
335
356
|
let t = [];
|
|
336
357
|
for (let [n, r] of Object.entries(e)) {
|
|
337
|
-
let e =
|
|
358
|
+
let e = G(r);
|
|
338
359
|
e && t.push({
|
|
339
360
|
key: n,
|
|
340
361
|
value: e
|
|
@@ -342,30 +363,30 @@ function J(e) {
|
|
|
342
363
|
}
|
|
343
364
|
return t;
|
|
344
365
|
}
|
|
345
|
-
var
|
|
346
|
-
function
|
|
347
|
-
let t =
|
|
366
|
+
var q = /* @__PURE__ */ new WeakMap();
|
|
367
|
+
function Me(e) {
|
|
368
|
+
let t = q.get(e);
|
|
348
369
|
if (t !== void 0) return t;
|
|
349
370
|
let n = JSON.stringify(e);
|
|
350
|
-
return
|
|
371
|
+
return q.set(e, n), n;
|
|
351
372
|
}
|
|
352
|
-
var
|
|
353
|
-
name:
|
|
373
|
+
var Ne = {
|
|
374
|
+
name: ue,
|
|
354
375
|
serialize(e) {
|
|
355
376
|
let t = /* @__PURE__ */ new Map();
|
|
356
377
|
for (let n of e) {
|
|
357
|
-
let e =
|
|
378
|
+
let e = Me(n.resource), r = t.get(e);
|
|
358
379
|
r ? r.records.push(n) : t.set(e, {
|
|
359
380
|
resource: n.resource,
|
|
360
381
|
records: [n]
|
|
361
382
|
});
|
|
362
383
|
}
|
|
363
384
|
let n = [...t.values()].map((e) => ({
|
|
364
|
-
resource: { attributes:
|
|
385
|
+
resource: { attributes: K(e.resource) },
|
|
365
386
|
scopeLogs: [{
|
|
366
387
|
scope: {
|
|
367
|
-
name:
|
|
368
|
-
version:
|
|
388
|
+
name: oe,
|
|
389
|
+
version: fe
|
|
369
390
|
},
|
|
370
391
|
logRecords: e.records.map((e) => ({
|
|
371
392
|
timeUnixNano: e.timeUnixNano,
|
|
@@ -376,24 +397,109 @@ var Ce = {
|
|
|
376
397
|
traceId: e.traceId,
|
|
377
398
|
spanId: e.spanId,
|
|
378
399
|
flags: e.traceFlags,
|
|
379
|
-
attributes:
|
|
400
|
+
attributes: K(e.attributes)
|
|
380
401
|
}))
|
|
381
402
|
}]
|
|
382
403
|
}));
|
|
383
404
|
return {
|
|
384
405
|
body: JSON.stringify({ resourceLogs: n }),
|
|
385
|
-
contentType:
|
|
406
|
+
contentType: u
|
|
386
407
|
};
|
|
387
408
|
}
|
|
388
409
|
};
|
|
389
410
|
//#endregion
|
|
390
411
|
//#region src/transport/serializers/select.ts
|
|
391
|
-
function
|
|
392
|
-
return e === "otlp" ?
|
|
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
|
+
}
|
|
393
422
|
}
|
|
394
423
|
//#endregion
|
|
395
|
-
//#region src/transport/
|
|
396
|
-
var
|
|
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;
|
|
454
|
+
return this.throttledUntil = Date.now() + (n.retryAfterMs ?? 2e3), t && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: n.retryAfterMs }), new H("throttled", t ? "The server throttles the requests." : "The service is not available.", e, n.retryAfterMs);
|
|
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: t } = this.config;
|
|
484
|
+
if (!t || e.records.length === 0) return;
|
|
485
|
+
let n = this.serialize(e);
|
|
486
|
+
if (!n) return;
|
|
487
|
+
let i = X(e, n), a;
|
|
488
|
+
try {
|
|
489
|
+
a = await T(P(() => k(() => t(i))), r);
|
|
490
|
+
} catch (e) {
|
|
491
|
+
let t = e instanceof he ? 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 {
|
|
397
503
|
deps;
|
|
398
504
|
installed = !1;
|
|
399
505
|
onVisibility = () => {
|
|
@@ -428,19 +534,35 @@ var we = class {
|
|
|
428
534
|
});
|
|
429
535
|
}
|
|
430
536
|
flush(e) {
|
|
431
|
-
let {
|
|
432
|
-
if (
|
|
433
|
-
|
|
434
|
-
if (!r || r.records.length === 0) return;
|
|
435
|
-
let i = t.guard("transport.serialize_failed", `The ${e} exit flush could not serialize its batch.`, () => X(this.deps.config.serializer).serialize(r.records));
|
|
436
|
-
if (!i) return;
|
|
437
|
-
if (k(i.body) > 6e4) {
|
|
438
|
-
B(r, t);
|
|
537
|
+
let { config: t, diagnostics: n } = this.deps;
|
|
538
|
+
if (t.transport) {
|
|
539
|
+
this.flushCustom(e, t.transportOnExit);
|
|
439
540
|
return;
|
|
440
541
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
542
|
+
let r = this.endpointUrl();
|
|
543
|
+
if (r === null) return;
|
|
544
|
+
let i = this.drain(e);
|
|
545
|
+
if (!i || i.records.length === 0) return;
|
|
546
|
+
let a = this.serialize(i, e);
|
|
547
|
+
if (!a) return;
|
|
548
|
+
if (A(a.body) > 6e4) {
|
|
549
|
+
z(i, n);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
r.searchParams.set(g, i.id), r.searchParams.set(me, e);
|
|
553
|
+
let o = r.toString(), s = this.beacon(o, a.body);
|
|
554
|
+
s !== "sent" && (s === "refused" ? z(i, n) : this.keepaliveFetch(o, a.body, e));
|
|
555
|
+
}
|
|
556
|
+
flushCustom(e, t) {
|
|
557
|
+
let { diagnostics: n } = this.deps;
|
|
558
|
+
if (e === "hidden" && !t) return;
|
|
559
|
+
let r = this.drain(e);
|
|
560
|
+
if (!r || r.records.length === 0) return;
|
|
561
|
+
let i = this.serialize(r, e);
|
|
562
|
+
i && (t === void 0 || n.guard("transport.http_error", "The transportOnExit hook threw an error.", () => P(() => t(X(r, i)))) !== !0) && z(r, n);
|
|
563
|
+
}
|
|
564
|
+
serialize(e, t) {
|
|
565
|
+
return J(this.deps.config.serializer, e, this.deps.diagnostics, `The ${t} exit flush could not serialize its batch.`);
|
|
444
566
|
}
|
|
445
567
|
drain(e) {
|
|
446
568
|
return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
|
|
@@ -450,7 +572,7 @@ var we = class {
|
|
|
450
572
|
return e ? this.deps.diagnostics.guard("config.invalid", `The exit flush cannot use the endpoint ${e}.`, () => new URL(e)) ?? null : null;
|
|
451
573
|
}
|
|
452
574
|
beacon(e, t) {
|
|
453
|
-
return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
|
|
575
|
+
return this.deps.diagnostics.guard("transport.http_error", "The sendBeacon call failed.", () => {
|
|
454
576
|
let n = globalThis.navigator;
|
|
455
577
|
return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
|
|
456
578
|
}) ?? "unavailable";
|
|
@@ -461,7 +583,7 @@ var we = class {
|
|
|
461
583
|
fetch(e, {
|
|
462
584
|
method: "POST",
|
|
463
585
|
body: n,
|
|
464
|
-
headers: { [
|
|
586
|
+
headers: { [c]: t },
|
|
465
587
|
credentials: i.credentials,
|
|
466
588
|
keepalive: !0
|
|
467
589
|
}).catch((e) => {
|
|
@@ -472,104 +594,64 @@ var we = class {
|
|
|
472
594
|
};
|
|
473
595
|
//#endregion
|
|
474
596
|
//#region src/transport/compression.ts
|
|
475
|
-
async function
|
|
597
|
+
async function Re(e) {
|
|
476
598
|
let t = globalThis.CompressionStream;
|
|
477
599
|
if (t === void 0) return null;
|
|
478
|
-
let n = new Blob([e]).stream().pipeThrough(new t(
|
|
600
|
+
let n = new Blob([e]).stream().pipeThrough(new t(w)), r = await new Response(n).arrayBuffer();
|
|
479
601
|
return new Uint8Array(r);
|
|
480
602
|
}
|
|
481
603
|
//#endregion
|
|
482
|
-
//#region src/transport/errors.ts
|
|
483
|
-
var Z = class extends Error {
|
|
484
|
-
kind;
|
|
485
|
-
status;
|
|
486
|
-
retryAfterMs;
|
|
487
|
-
maxBytes;
|
|
488
|
-
constructor(e, t, n, r, i) {
|
|
489
|
-
super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
|
|
490
|
-
}
|
|
491
|
-
};
|
|
492
|
-
function Ee(e) {
|
|
493
|
-
if (!e) return;
|
|
494
|
-
let t = Number(e);
|
|
495
|
-
if (Number.isFinite(t)) return Math.max(0, t * le);
|
|
496
|
-
let n = Date.parse(e);
|
|
497
|
-
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
498
|
-
}
|
|
499
|
-
//#endregion
|
|
500
604
|
//#region src/transport/http-transport.ts
|
|
501
|
-
var Q = class {
|
|
502
|
-
config;
|
|
503
|
-
diagnostics;
|
|
504
|
-
throttledUntil = 0;
|
|
505
|
-
constructor(e, t) {
|
|
506
|
-
this.config = e, this.diagnostics = t;
|
|
507
|
-
}
|
|
605
|
+
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 {
|
|
508
606
|
async send(e) {
|
|
509
607
|
let { endpoint: t } = this.config;
|
|
510
608
|
t && e.records.length !== 0 && await this.post(e, t);
|
|
511
609
|
}
|
|
512
|
-
throttledForMs() {
|
|
513
|
-
return Math.max(0, this.throttledUntil - Date.now());
|
|
514
|
-
}
|
|
515
610
|
async post(e, t) {
|
|
516
|
-
let
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
611
|
+
let n = this.serialize(e);
|
|
612
|
+
if (!n) return;
|
|
613
|
+
let r = new Headers(await this.resolveHeaders());
|
|
614
|
+
r.set(c, n.contentType), r.set(l, e.id), r.set(a, String(e.attempts));
|
|
615
|
+
let i = await this.encodeBody(n.body);
|
|
616
|
+
typeof i != "string" && r.set(le, w);
|
|
617
|
+
let o = await this.dispatch(t, r, i);
|
|
618
|
+
if (o.ok) {
|
|
619
|
+
this.accept(o.headers.get(ne));
|
|
521
620
|
return;
|
|
522
621
|
}
|
|
523
|
-
let
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
else throw await this.classify(l, e.id);
|
|
622
|
+
let s = o.status, u = De(o.headers.get(re)), d = s === 413 ? await this.readMaxBytes(o) : void 0;
|
|
623
|
+
throw this.reject(s, e.id, {
|
|
624
|
+
retryAfterMs: u,
|
|
625
|
+
maxBytes: d,
|
|
626
|
+
advice: Q
|
|
627
|
+
});
|
|
530
628
|
}
|
|
531
629
|
async encodeBody(e) {
|
|
532
630
|
let { config: t } = this;
|
|
533
|
-
return t.compression !== "gzip" ||
|
|
631
|
+
return t.compression !== "gzip" || A(e) < 1024 ? e : await this.diagnostics.guardAsync("transport.http_error", "The library could not compress the payload.", () => Re(e)) ?? e;
|
|
534
632
|
}
|
|
535
633
|
async dispatch(e, t, n) {
|
|
536
|
-
let { config:
|
|
537
|
-
|
|
538
|
-
},
|
|
539
|
-
|
|
634
|
+
let { config: i } = this, a = new AbortController(), o = setTimeout(() => {
|
|
635
|
+
a.abort();
|
|
636
|
+
}, r);
|
|
637
|
+
j(o);
|
|
540
638
|
try {
|
|
541
|
-
return await fetch(e, {
|
|
639
|
+
return await P(() => fetch(e, {
|
|
542
640
|
method: "POST",
|
|
543
641
|
headers: t,
|
|
544
642
|
body: n,
|
|
545
|
-
credentials:
|
|
546
|
-
signal:
|
|
643
|
+
credentials: i.credentials,
|
|
644
|
+
signal: a.signal,
|
|
547
645
|
cache: "no-store"
|
|
548
|
-
});
|
|
646
|
+
}));
|
|
549
647
|
} catch {
|
|
550
|
-
if (
|
|
648
|
+
if (a.signal.aborted) throw new H("timeout", `The request took longer than ${String(r)} ms.`);
|
|
551
649
|
let e = globalThis.navigator?.onLine;
|
|
552
|
-
throw new
|
|
650
|
+
throw new H(e === !1 ? "offline" : "transient", "A network error occurred.");
|
|
553
651
|
} finally {
|
|
554
|
-
clearTimeout(
|
|
652
|
+
clearTimeout(o);
|
|
555
653
|
}
|
|
556
654
|
}
|
|
557
|
-
async classify(e, t) {
|
|
558
|
-
let n = e.status, r = Ee(e.headers.get(re));
|
|
559
|
-
if (n === 401 || n === 403) return this.diagnostics.report("transport.rejected_credentials", `The server returned ${String(n)}. 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.`, {
|
|
560
|
-
status: n,
|
|
561
|
-
endpoint: this.config.endpoint
|
|
562
|
-
}), new Z("permanent", `The server rejected the batch with ${String(n)}.`, n);
|
|
563
|
-
if (n === 413) return new Z("too_large", "The payload is too large.", n, void 0, await this.readMaxBytes(e));
|
|
564
|
-
if (n === 429 || n === 503) {
|
|
565
|
-
let e = n === 429;
|
|
566
|
-
return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "The server throttles the requests.", { retryAfterMs: r }), new Z("throttled", e ? "The server throttles the requests." : "The service is not available.", n, r);
|
|
567
|
-
}
|
|
568
|
-
return n === 408 || n >= 500 ? new Z("transient", `The server returned the error ${String(n)}.`, n) : (this.diagnostics.report("transport.dropped_permanent", `The server rejected the batch with ${String(n)}. The library dropped it.`, {
|
|
569
|
-
batchId: t,
|
|
570
|
-
status: n
|
|
571
|
-
}), new Z("permanent", `The server rejected the batch with ${String(n)}.`, n));
|
|
572
|
-
}
|
|
573
655
|
async readMaxBytes(e) {
|
|
574
656
|
return this.diagnostics.guardAsync("transport.http_error", "The library could not read the body of the 413 response.", async () => {
|
|
575
657
|
let t = JSON.parse(await e.text());
|
|
@@ -580,7 +662,7 @@ var Q = class {
|
|
|
580
662
|
let { headers: e } = this.config;
|
|
581
663
|
return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "The headers() function threw an error.", () => Promise.resolve(e())) ?? {} : e : {};
|
|
582
664
|
}
|
|
583
|
-
},
|
|
665
|
+
}, Be = class {
|
|
584
666
|
storage;
|
|
585
667
|
transport;
|
|
586
668
|
diagnostics;
|
|
@@ -597,10 +679,10 @@ var Q = class {
|
|
|
597
679
|
this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
|
|
598
680
|
}
|
|
599
681
|
start() {
|
|
600
|
-
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(
|
|
682
|
+
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(o);
|
|
601
683
|
}
|
|
602
684
|
nudge() {
|
|
603
|
-
this.draining || this.schedule(
|
|
685
|
+
this.draining || this.schedule(m);
|
|
604
686
|
}
|
|
605
687
|
async storeFailed(e, t) {
|
|
606
688
|
let n = this.toStorable(e, t);
|
|
@@ -616,23 +698,23 @@ var Q = class {
|
|
|
616
698
|
let t = setTimeout(() => {
|
|
617
699
|
this.drain();
|
|
618
700
|
}, e);
|
|
619
|
-
this.timer = t,
|
|
701
|
+
this.timer = t, j(t);
|
|
620
702
|
}
|
|
621
|
-
bounded(
|
|
622
|
-
return
|
|
703
|
+
bounded(t) {
|
|
704
|
+
return T(t, e);
|
|
623
705
|
}
|
|
624
706
|
clearTimer() {
|
|
625
707
|
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
626
708
|
}
|
|
627
709
|
backoffMs() {
|
|
628
|
-
let e = Math.min(
|
|
710
|
+
let e = Math.min(m * 2 ** this.attempt, te);
|
|
629
711
|
return Math.random() * e;
|
|
630
712
|
}
|
|
631
713
|
async drain() {
|
|
632
714
|
if (!this.draining) {
|
|
633
715
|
this.draining = !0;
|
|
634
716
|
try {
|
|
635
|
-
await
|
|
717
|
+
await L("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(o);
|
|
636
718
|
} finally {
|
|
637
719
|
this.draining = !1;
|
|
638
720
|
}
|
|
@@ -640,25 +722,25 @@ var Q = class {
|
|
|
640
722
|
}
|
|
641
723
|
async drainLocked() {
|
|
642
724
|
try {
|
|
643
|
-
if (globalThis.navigator?.onLine === !1) return this.schedule(
|
|
725
|
+
if (globalThis.navigator?.onLine === !1) return this.schedule(o), !0;
|
|
644
726
|
let e = await this.bounded(this.storage.take(this.batchesPerDrain));
|
|
645
|
-
if (e.length === 0) return this.schedule(
|
|
727
|
+
if (e.length === 0) return this.schedule(o), !0;
|
|
646
728
|
for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
|
|
647
|
-
return this.schedule(e.length === this.batchesPerDrain ? 0 :
|
|
729
|
+
return this.schedule(e.length === this.batchesPerDrain ? 0 : o), !0;
|
|
648
730
|
} catch (e) {
|
|
649
731
|
return this.diagnostics.report("storage.degraded", "The drain loop threw an error.", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
|
|
650
732
|
}
|
|
651
733
|
}
|
|
652
734
|
async deliver(e) {
|
|
653
|
-
if (e.attempts >=
|
|
735
|
+
if (e.attempts >= _.maxAttempts) return this.diagnostics.report("storage.dead_lettered", `The library dropped a batch after ${e.attempts.toString()} attempts.`, {
|
|
654
736
|
batchId: e.id,
|
|
655
737
|
records: e.records.length
|
|
656
738
|
}), await this.bounded(this.storage.remove(e.id)), !0;
|
|
657
739
|
try {
|
|
658
740
|
return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
|
|
659
741
|
} catch (t) {
|
|
660
|
-
let n = t instanceof
|
|
661
|
-
return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(
|
|
742
|
+
let n = t instanceof H ? t : void 0;
|
|
743
|
+
return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(o), !1) : n?.kind === "throttled" ? (this.attempt++, this.schedule(n.retryAfterMs ?? this.backoffMs()), !1) : (await this.bounded(this.storage.bumpAttempts(e.id, e.attempts + 1)), this.attempt++, this.schedule(n?.retryAfterMs ?? this.backoffMs()), !1);
|
|
662
744
|
}
|
|
663
745
|
}
|
|
664
746
|
async replaceStored(e, t) {
|
|
@@ -667,10 +749,10 @@ var Q = class {
|
|
|
667
749
|
for (let e of n) await this.bounded(this.storage.save(e));
|
|
668
750
|
}
|
|
669
751
|
toStorable(e, t) {
|
|
670
|
-
let n = t instanceof
|
|
752
|
+
let n = t instanceof H ? t : void 0;
|
|
671
753
|
if (n?.kind === "permanent") return [];
|
|
672
754
|
if (n?.kind !== "too_large") return [e];
|
|
673
|
-
let r =
|
|
755
|
+
let r = I(e, this.diagnostics);
|
|
674
756
|
return r ? (this.diagnostics.report("transport.batch_split", "The server refused the batch because it is too large.", {
|
|
675
757
|
from: e.records.length,
|
|
676
758
|
to: r[0].records.length,
|
|
@@ -683,16 +765,16 @@ var Q = class {
|
|
|
683
765
|
};
|
|
684
766
|
//#endregion
|
|
685
767
|
//#region src/core/pipeline.ts
|
|
686
|
-
function
|
|
687
|
-
return e.attributes[
|
|
768
|
+
function Ve(e) {
|
|
769
|
+
return e.attributes[ae] === pe;
|
|
688
770
|
}
|
|
689
|
-
var
|
|
771
|
+
var He = {
|
|
690
772
|
logs: {
|
|
691
|
-
flushIntervalMs:
|
|
773
|
+
flushIntervalMs: se,
|
|
692
774
|
batchSize: 100
|
|
693
775
|
},
|
|
694
776
|
metrics: {
|
|
695
|
-
flushIntervalMs:
|
|
777
|
+
flushIntervalMs: v,
|
|
696
778
|
batchSize: 500
|
|
697
779
|
}
|
|
698
780
|
}, $ = class {
|
|
@@ -719,12 +801,12 @@ var ke = {
|
|
|
719
801
|
let e = setTimeout(() => {
|
|
720
802
|
this.timer = null, this.onFlush(this);
|
|
721
803
|
}, this.options.flushIntervalMs);
|
|
722
|
-
this.timer = e,
|
|
804
|
+
this.timer = e, j(e);
|
|
723
805
|
}
|
|
724
806
|
clearTimer() {
|
|
725
807
|
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
726
808
|
}
|
|
727
|
-
},
|
|
809
|
+
}, Ue = class {
|
|
728
810
|
transport;
|
|
729
811
|
storage;
|
|
730
812
|
retry;
|
|
@@ -732,11 +814,11 @@ var ke = {
|
|
|
732
814
|
streams;
|
|
733
815
|
unconfirmed = /* @__PURE__ */ new Map();
|
|
734
816
|
queue = [];
|
|
735
|
-
ceiling = new
|
|
817
|
+
ceiling = new O();
|
|
736
818
|
inFlight = 0;
|
|
737
819
|
pumpScheduled = !1;
|
|
738
820
|
stopped = !1;
|
|
739
|
-
constructor(e, t, n, r, i =
|
|
821
|
+
constructor(e, t, n, r, i = He) {
|
|
740
822
|
this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
|
|
741
823
|
let a = (e) => {
|
|
742
824
|
this.claim(e);
|
|
@@ -765,7 +847,7 @@ var ke = {
|
|
|
765
847
|
}
|
|
766
848
|
toBatch(e) {
|
|
767
849
|
return e.length === 0 ? null : {
|
|
768
|
-
id:
|
|
850
|
+
id: E(this.diagnostics),
|
|
769
851
|
records: e,
|
|
770
852
|
createdAt: Date.now(),
|
|
771
853
|
attempts: 0
|
|
@@ -773,7 +855,7 @@ var ke = {
|
|
|
773
855
|
}
|
|
774
856
|
route(e) {
|
|
775
857
|
try {
|
|
776
|
-
let t =
|
|
858
|
+
let t = Ve(e) ? this.streams.metrics : this.streams.logs;
|
|
777
859
|
if (!this.ceiling.allow(e)) {
|
|
778
860
|
this.diagnostics.count("record.dropped_by_ceiling");
|
|
779
861
|
return;
|
|
@@ -785,7 +867,7 @@ var ke = {
|
|
|
785
867
|
}
|
|
786
868
|
claim(e) {
|
|
787
869
|
let t = e.take(), n = {
|
|
788
|
-
id:
|
|
870
|
+
id: E(this.diagnostics),
|
|
789
871
|
records: t,
|
|
790
872
|
createdAt: Date.now(),
|
|
791
873
|
attempts: 0
|
|
@@ -844,12 +926,12 @@ var ke = {
|
|
|
844
926
|
await this.retry.storeFailed(e, t);
|
|
845
927
|
});
|
|
846
928
|
}
|
|
847
|
-
async store(
|
|
929
|
+
async store(t) {
|
|
848
930
|
await this.diagnostics.guardAsync("storage.degraded", "The library could not store an undelivered batch.", async () => {
|
|
849
|
-
await
|
|
931
|
+
await T(this.storage.save(t), e), this.retry.nudge();
|
|
850
932
|
});
|
|
851
933
|
}
|
|
852
|
-
},
|
|
934
|
+
}, We = class e {
|
|
853
935
|
storage;
|
|
854
936
|
transport;
|
|
855
937
|
retry;
|
|
@@ -860,20 +942,23 @@ var ke = {
|
|
|
860
942
|
this.storage = e, this.transport = t, this.retry = n, this.pipeline = r, this.exitFlush = i, this.diagnostics = a;
|
|
861
943
|
}
|
|
862
944
|
static async create(t) {
|
|
863
|
-
let { config: n, diagnostics: r } = t, i = await
|
|
945
|
+
let { config: n, diagnostics: r } = t, i = await Ee(n.storage, ee, _, r, t.onGap), a = (e) => {
|
|
946
|
+
let i = M(e, r);
|
|
947
|
+
i && N(t.remote, n, i);
|
|
948
|
+
}, o = n.transport ? new Ie(n, r, a) : new ze(n, r, a), s = new Be(i, o, r, n), c = new Ue(o, i, s, r), l = new Le({
|
|
864
949
|
config: n,
|
|
865
950
|
diagnostics: r,
|
|
866
951
|
drainForExit: () => c.drainForExit(),
|
|
867
952
|
drainPending: () => c.drainPending()
|
|
868
953
|
});
|
|
869
|
-
await
|
|
870
|
-
let
|
|
954
|
+
await ye(i, r);
|
|
955
|
+
let u = !1;
|
|
871
956
|
try {
|
|
872
|
-
|
|
957
|
+
l.install(), s.start(), u = !0;
|
|
873
958
|
} finally {
|
|
874
|
-
|
|
959
|
+
u || (l.uninstall(), s.stop());
|
|
875
960
|
}
|
|
876
|
-
return new e(i,
|
|
961
|
+
return new e(i, o, s, c, l, r);
|
|
877
962
|
}
|
|
878
963
|
push(e) {
|
|
879
964
|
this.pipeline.push(e);
|
|
@@ -902,6 +987,6 @@ var ke = {
|
|
|
902
987
|
}
|
|
903
988
|
};
|
|
904
989
|
//#endregion
|
|
905
|
-
export {
|
|
990
|
+
export { We as Sender };
|
|
906
991
|
|
|
907
|
-
//# sourceMappingURL=sender-
|
|
992
|
+
//# sourceMappingURL=sender-G6v4Uqi4.js.map
|