@utk09/ui-observability 0.4.1 → 0.6.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 +63 -0
- package/README.md +114 -59
- package/dist/bus/bus.d.ts +10 -10
- package/dist/bus/links.d.ts +1 -1
- package/dist/bus-BTMuVkDk.js +378 -0
- package/dist/bus-BTMuVkDk.js.map +1 -0
- package/dist/bus-ChIXDAWD.cjs +2 -0
- package/dist/bus-ChIXDAWD.cjs.map +1 -0
- package/dist/capture/network.d.ts +2 -2
- package/dist/capture/types.d.ts +10 -10
- package/dist/capture/web-vitals.d.ts +7 -4
- package/dist/{constants-DVbpJ1tv.js → constants-0-YchbAL.js} +9 -8
- package/dist/constants-0-YchbAL.js.map +1 -0
- package/dist/constants-TUFcy95w.cjs +2 -0
- package/dist/constants-TUFcy95w.cjs.map +1 -0
- package/dist/constants.d.ts +55 -40
- package/dist/core/breadcrumbs.d.ts +14 -14
- package/dist/core/config.d.ts +5 -4
- package/dist/core/context.d.ts +2 -2
- package/dist/core/diagnostics.d.ts +10 -9
- package/dist/core/journey.d.ts +28 -22
- package/dist/core/logger.d.ts +29 -10
- package/dist/core/pipeline.d.ts +34 -29
- package/dist/core/record.d.ts +6 -6
- package/dist/core/runtime.d.ts +119 -35
- package/dist/core/sampling.d.ts +15 -16
- package/dist/core/sender.d.ts +58 -0
- package/dist/errors-DRXBRqvm.cjs +3 -0
- package/dist/errors-DRXBRqvm.cjs.map +1 -0
- package/dist/errors-Dwm2SzBa.js +76 -0
- package/dist/errors-Dwm2SzBa.js.map +1 -0
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +476 -2247
- package/dist/index.js.map +1 -1
- package/dist/indexeddb-storage-B5dwq4hW.cjs +2 -0
- package/dist/indexeddb-storage-B5dwq4hW.cjs.map +1 -0
- package/dist/{indexeddb-storage-B6uqejZb.js → indexeddb-storage-DjY4Ml6t.js} +18 -22
- package/dist/indexeddb-storage-DjY4Ml6t.js.map +1 -0
- package/dist/interactions-DVom6eYn.cjs +2 -0
- package/dist/interactions-DVom6eYn.cjs.map +1 -0
- package/dist/interactions-DZmLu7l2.js +67 -0
- package/dist/interactions-DZmLu7l2.js.map +1 -0
- package/dist/models/batch.d.ts +12 -9
- package/dist/models/bus.d.ts +12 -13
- package/dist/models/config.d.ts +84 -49
- package/dist/models/log-record.d.ts +12 -10
- package/dist/models/serializer.d.ts +3 -2
- package/dist/models/storage.d.ts +2 -2
- package/dist/network-C4d2uw2Z.js +111 -0
- package/dist/network-C4d2uw2Z.js.map +1 -0
- package/dist/network-CuqWadNn.cjs +2 -0
- package/dist/network-CuqWadNn.cjs.map +1 -0
- package/dist/platform-CXio0W2n.cjs +2 -0
- package/dist/platform-CXio0W2n.cjs.map +1 -0
- package/dist/platform-CY8S3hUs.js +48 -0
- package/dist/platform-CY8S3hUs.js.map +1 -0
- package/dist/sampling-CEthcmEX.cjs +2 -0
- package/dist/sampling-CEthcmEX.cjs.map +1 -0
- package/dist/sampling-CJsI_24L.js +251 -0
- package/dist/sampling-CJsI_24L.js.map +1 -0
- package/dist/sender-ByFAkXVd.cjs +3 -0
- package/dist/sender-ByFAkXVd.cjs.map +1 -0
- package/dist/sender-dpvR_bHM.js +907 -0
- package/dist/sender-dpvR_bHM.js.map +1 -0
- package/dist/storage/emergency-queue.d.ts +2 -2
- package/dist/storage/factory.d.ts +2 -1
- package/dist/storage/idb-driver.d.ts +19 -19
- package/dist/storage/indexeddb-storage.d.ts +18 -17
- package/dist/storage/keys.d.ts +1 -1
- package/dist/storage/local-storage.d.ts +19 -18
- package/dist/storage/memory-storage.d.ts +12 -11
- package/dist/transport/compression.d.ts +2 -2
- package/dist/transport/errors.d.ts +8 -7
- package/dist/transport/exit-flush.d.ts +27 -24
- package/dist/transport/http-transport.d.ts +19 -10
- package/dist/transport/retry-engine.d.ts +33 -28
- package/dist/transport/serializers/ecs.d.ts +1 -1
- package/dist/transport/serializers/otlp.d.ts +1 -1
- package/dist/transport/serializers/select.d.ts +8 -0
- package/dist/unref-16maCyKA.js +8 -0
- package/dist/unref-16maCyKA.js.map +1 -0
- package/dist/unref-CU9Nyz_9.cjs +2 -0
- package/dist/unref-CU9Nyz_9.cjs.map +1 -0
- package/dist/utils/console.d.ts +11 -3
- package/dist/utils/identity.d.ts +53 -8
- package/dist/utils/lock.d.ts +4 -4
- package/dist/utils/platform.d.ts +5 -3
- package/dist/utils/sanitize.d.ts +5 -2
- package/dist/utils/sequence.d.ts +2 -2
- package/dist/utils/tracing.d.ts +14 -12
- package/dist/web-vitals-B2FYsEAU.cjs +2 -0
- package/dist/web-vitals-B2FYsEAU.cjs.map +1 -0
- package/dist/web-vitals-DHZ0yA_H.js +51 -0
- package/dist/web-vitals-DHZ0yA_H.js.map +1 -0
- package/package.json +21 -11
- package/dist/constants-DVbpJ1tv.js.map +0 -1
- package/dist/constants-tQpoTzkY.cjs +0 -2
- package/dist/constants-tQpoTzkY.cjs.map +0 -1
- package/dist/indexeddb-storage-B6uqejZb.js.map +0 -1
- package/dist/indexeddb-storage-CgT1GLYj.cjs +0 -2
- package/dist/indexeddb-storage-CgT1GLYj.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,60 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as e, C as t, Ct as n, D as r, Dt as i, E as a, Et as o, F as s, Gt as c, M as l, Mt as u, N as d, Nt as f, Ot as p, Pt as m, Rt as h, St as g, T as _, Tt as ee, Vt as v, Yt as te, _ as ne, a as y, an as re, at as ie, bt as b, c as x, cn as ae, d as oe, g as se, h as ce, ht as le, i as ue, in as de, it as S, j as C, jt as fe, kt as pe, l as w, ln as me, m as he, mt as ge, n as T, nn as _e, nt as E, o as D, on as ve, p as ye, r as be, rn as xe, rt as Se, s as Ce, tt as we, u as O, un as k, wt as Te, zt as Ee } from "./constants-0-YchbAL.js";
|
|
2
|
+
import { _ as De, a as A, c as j, d as Oe, g as M, h as ke, i as Ae, l as je, m as N, n as Me, o as Ne, p as Pe, r as Fe, s as Ie, u as P } from "./sampling-CJsI_24L.js";
|
|
3
|
+
import { n as Le, r as Re, t as ze } from "./platform-CY8S3hUs.js";
|
|
4
|
+
import { t as Be } from "./unref-16maCyKA.js";
|
|
2
5
|
//#region src/utils/timer.ts
|
|
3
|
-
function
|
|
4
|
-
return Math.round((performance.now() - e) *
|
|
6
|
+
function F(e) {
|
|
7
|
+
return Math.round((performance.now() - e) * s) / s;
|
|
5
8
|
}
|
|
6
|
-
function
|
|
7
|
-
e.logMetric(`${t}.duration`,
|
|
9
|
+
function I(e, t, n, r, i) {
|
|
10
|
+
e.logMetric(`${t}.duration`, F(n), "ms", "histogram", {
|
|
8
11
|
status: r,
|
|
9
12
|
...i
|
|
10
13
|
});
|
|
11
14
|
}
|
|
12
|
-
function
|
|
15
|
+
function L(e, t, n, r, i) {
|
|
13
16
|
e.error(`${t} failed`, r, {
|
|
14
|
-
"action.duration_ms":
|
|
17
|
+
"action.duration_ms": F(n),
|
|
15
18
|
status: "FAILURE",
|
|
16
19
|
...i
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
|
-
function
|
|
22
|
+
function Ve(e, t, n, r) {
|
|
20
23
|
let i = performance.now();
|
|
21
24
|
try {
|
|
22
25
|
let a = n();
|
|
23
|
-
return
|
|
26
|
+
return I(e, t, i, "SUCCESS", r), a;
|
|
24
27
|
} catch (n) {
|
|
25
|
-
throw
|
|
28
|
+
throw L(e, t, i, n, r), n;
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
|
-
async function
|
|
31
|
+
async function He(e, t, n, r) {
|
|
29
32
|
let i = performance.now();
|
|
30
33
|
try {
|
|
31
34
|
let a = await n();
|
|
32
|
-
return
|
|
35
|
+
return I(e, t, i, "SUCCESS", r), a;
|
|
33
36
|
} catch (n) {
|
|
34
|
-
throw
|
|
37
|
+
throw L(e, t, i, n, r), n;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
//#endregion
|
|
38
41
|
//#region src/core/logger.ts
|
|
39
|
-
function
|
|
42
|
+
function Ue(e, t) {
|
|
40
43
|
if (e instanceof Error) return e;
|
|
41
|
-
let n = t.guard("record.sanitize_failed", "
|
|
44
|
+
let n = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
|
|
42
45
|
return Error(n ?? typeof e);
|
|
43
46
|
}
|
|
44
|
-
function
|
|
47
|
+
function We(e) {
|
|
45
48
|
if (typeof e != "object" || !e || Array.isArray(e) || e instanceof Error) return !1;
|
|
46
49
|
let t = Object.getPrototypeOf(e);
|
|
47
50
|
return t === null || Object.getPrototypeOf(t) === null;
|
|
48
51
|
}
|
|
49
|
-
var
|
|
50
|
-
|
|
52
|
+
var R = class e {
|
|
53
|
+
bind;
|
|
51
54
|
namespace;
|
|
52
55
|
options;
|
|
53
56
|
constructor(e, t, n = {}) {
|
|
54
|
-
this.
|
|
57
|
+
this.bind = e, this.namespace = t, this.options = n;
|
|
55
58
|
}
|
|
56
59
|
child(t, n = {}) {
|
|
57
|
-
return new e(this.
|
|
60
|
+
return new e(this.bind, `${this.namespace}.${t}`, { scopedContext: {
|
|
58
61
|
...this.options.scopedContext,
|
|
59
62
|
...n.scopedContext
|
|
60
63
|
} });
|
|
@@ -62,1576 +65,101 @@ var E = class e {
|
|
|
62
65
|
trace = (e, t) => {
|
|
63
66
|
this.write("TRACE", "system", e, t);
|
|
64
67
|
};
|
|
65
|
-
debug = (e, t) => {
|
|
66
|
-
this.write("DEBUG", "system", e, t);
|
|
67
|
-
};
|
|
68
|
-
info = (e, t) => {
|
|
69
|
-
this.write("INFO", "system", e, t);
|
|
70
|
-
};
|
|
71
|
-
warn = (e, t) => {
|
|
72
|
-
this.write("WARN", "system", e, t);
|
|
73
|
-
};
|
|
74
|
-
error = (e, t, n) => {
|
|
75
|
-
this.writeError("ERROR", e, t, n);
|
|
76
|
-
};
|
|
77
|
-
fatal = (e, t, n) => {
|
|
78
|
-
this.writeError("FATAL", e, t, n);
|
|
79
|
-
};
|
|
80
|
-
logAction = (e, t) => {
|
|
81
|
-
this.write("INFO", "action", e, t);
|
|
82
|
-
};
|
|
83
|
-
logEvent = (e, t) => {
|
|
84
|
-
this.write("INFO", "event", e, t);
|
|
85
|
-
};
|
|
86
|
-
logMetric = (e, t, n = ie, r = "gauge", i) => {
|
|
87
|
-
this.write("INFO", "metric", e, {
|
|
88
|
-
"metric.name": e,
|
|
89
|
-
"metric.value": t,
|
|
90
|
-
"metric.unit": n,
|
|
91
|
-
"metric.type": r,
|
|
92
|
-
...i
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
timeSync = (e, t, n) => wt(this, e, t, n);
|
|
96
|
-
timeAsync = (e, t, n) => Tt(this, e, t, n);
|
|
97
|
-
write(e, t, n, r) {
|
|
98
|
-
if (!this.runtime.builder.isEnabled(e)) return;
|
|
99
|
-
let { record: i, dropped: a } = this.runtime.builder.build({
|
|
100
|
-
level: e,
|
|
101
|
-
type: t,
|
|
102
|
-
body: n,
|
|
103
|
-
namespace: this.namespace,
|
|
104
|
-
scoped: this.options.scopedContext,
|
|
105
|
-
payload: r
|
|
106
|
-
});
|
|
107
|
-
t !== "metric" && a !== "redact" && this.runtime.breadcrumbs.push({
|
|
108
|
-
t: Date.now(),
|
|
109
|
-
category: t === "action" ? "action" : t === "event" ? "event" : "log",
|
|
110
|
-
message: n
|
|
111
|
-
}), this.runtime.console.write(e, n, i?.attributes), this.runtime.emit(i);
|
|
112
|
-
}
|
|
113
|
-
writeError(e, t, n, r) {
|
|
114
|
-
if (!this.runtime.builder.isEnabled(e)) return;
|
|
115
|
-
let i = r === void 0 && Dt(n), a = i ? n : r, o = i || n === void 0 ? void 0 : Et(n, this.runtime.diagnostics), { record: s } = this.runtime.builder.build({
|
|
116
|
-
level: e,
|
|
117
|
-
type: "system",
|
|
118
|
-
body: t,
|
|
119
|
-
namespace: this.namespace,
|
|
120
|
-
scoped: this.options.scopedContext,
|
|
121
|
-
payload: {
|
|
122
|
-
...a,
|
|
123
|
-
...o ? {
|
|
124
|
-
"error.type": o.name,
|
|
125
|
-
"error.message": o.message,
|
|
126
|
-
"error.stack_trace": o.stack
|
|
127
|
-
} : {},
|
|
128
|
-
breadcrumbs: this.runtime.breadcrumbs.snapshot()
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
this.runtime.console.write(e, t, o ?? s?.attributes), this.runtime.emit(s);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/utils/unref.ts
|
|
136
|
-
function D(e) {
|
|
137
|
-
typeof e != "number" && e.unref?.();
|
|
138
|
-
}
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/models/bus.ts
|
|
141
|
-
function O(e) {
|
|
142
|
-
return {
|
|
143
|
-
p: pe,
|
|
144
|
-
m: e
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function k(e) {
|
|
148
|
-
if (typeof e != "object" || !e) return null;
|
|
149
|
-
let t = e;
|
|
150
|
-
if (t.p !== "ui-observability/1" || typeof t.m != "object" || t.m === null) return null;
|
|
151
|
-
let n = t.m;
|
|
152
|
-
return typeof n.t == "string" ? n : null;
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/bus/links.ts
|
|
156
|
-
var Ot = Symbol.for(fe);
|
|
157
|
-
function kt(e, t) {
|
|
158
|
-
if (typeof window > "u" || window.parent === window) return null;
|
|
159
|
-
let n;
|
|
160
|
-
try {
|
|
161
|
-
n = window.parent[Ot];
|
|
162
|
-
} catch {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
if (typeof n?.busAccept != "function") return null;
|
|
166
|
-
let r = n, i = !0;
|
|
167
|
-
return {
|
|
168
|
-
kind: "direct",
|
|
169
|
-
post(n) {
|
|
170
|
-
i && t.guard("bus.send_failed", "direct call into the parent runtime", () => {
|
|
171
|
-
r.busAccept(n, e);
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
close() {
|
|
175
|
-
i = !1;
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
function At(e, t) {
|
|
180
|
-
if (typeof window > "u" || window.parent === window) return null;
|
|
181
|
-
let n = (t) => {
|
|
182
|
-
let n = k(t.data);
|
|
183
|
-
n && t.source === window.parent && e(n, {
|
|
184
|
-
link: "parent",
|
|
185
|
-
origin: t.origin
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
return addEventListener("message", n), {
|
|
189
|
-
kind: "parent",
|
|
190
|
-
post(e) {
|
|
191
|
-
t.guard("bus.send_failed", "postMessage to parent", () => {
|
|
192
|
-
window.parent.postMessage(O(e), "*");
|
|
193
|
-
});
|
|
194
|
-
},
|
|
195
|
-
close() {
|
|
196
|
-
removeEventListener("message", n);
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function jt(e, t, n) {
|
|
201
|
-
if (typeof window > "u") return null;
|
|
202
|
-
let r = /* @__PURE__ */ new Set([window.location.origin, ...t]), i = /* @__PURE__ */ new Map(), a = (t) => {
|
|
203
|
-
let a = k(t.data);
|
|
204
|
-
if (a) {
|
|
205
|
-
if (!r.has(t.origin)) {
|
|
206
|
-
n.report("bus.untrusted_origin", `ignored a bus message from ${t.origin}. Add it to bus.trustedOrigins if it is yours.`, {
|
|
207
|
-
origin: t.origin,
|
|
208
|
-
type: a.t
|
|
209
|
-
});
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
t.source && i.set(t.source, t.origin), e(a, {
|
|
213
|
-
link: "children",
|
|
214
|
-
origin: t.origin
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
return addEventListener("message", a), {
|
|
219
|
-
kind: "children",
|
|
220
|
-
post(e) {
|
|
221
|
-
for (let [t, r] of i) {
|
|
222
|
-
let a = t;
|
|
223
|
-
if (a.closed) {
|
|
224
|
-
i.delete(t);
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
n.guard("bus.send_failed", "postMessage to child", () => {
|
|
228
|
-
a.postMessage(O(e), r);
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
close() {
|
|
233
|
-
removeEventListener("message", a), i.clear();
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function Mt(e, t, n) {
|
|
238
|
-
let r = globalThis.BroadcastChannel;
|
|
239
|
-
if (r === void 0) return null;
|
|
240
|
-
let i = n.guard("bus.send_failed", "opening BroadcastChannel", () => new r(e));
|
|
241
|
-
return i ? (i.onmessage = (e) => {
|
|
242
|
-
let n = k(e.data);
|
|
243
|
-
n && t(n, {
|
|
244
|
-
link: "broadcast",
|
|
245
|
-
origin: "same-origin"
|
|
246
|
-
});
|
|
247
|
-
}, {
|
|
248
|
-
kind: "broadcast",
|
|
249
|
-
post(e) {
|
|
250
|
-
n.guard("bus.send_failed", "BroadcastChannel.postMessage", () => {
|
|
251
|
-
i.postMessage(O(e));
|
|
252
|
-
});
|
|
253
|
-
},
|
|
254
|
-
close() {
|
|
255
|
-
n.guard("bus.send_failed", "closing BroadcastChannel", () => {
|
|
256
|
-
i.close();
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}) : null;
|
|
260
|
-
}
|
|
261
|
-
function Nt(e, t, n, r) {
|
|
262
|
-
let i = globalThis.fin?.InterApplicationBus;
|
|
263
|
-
if (!i) return null;
|
|
264
|
-
if (!t) return r.report("openfin.unavailable", "no OpenFin application uuid, so the InterApplicationBus link stays closed"), null;
|
|
265
|
-
let a = `${e}.${t}`;
|
|
266
|
-
return r.guardAsync("bus.send_failed", "InterApplicationBus.subscribe", () => i.subscribe({ uuid: t }, a, (e) => {
|
|
267
|
-
let t = k(e);
|
|
268
|
-
t && n(t, {
|
|
269
|
-
link: "openfin",
|
|
270
|
-
origin: "openfin"
|
|
271
|
-
});
|
|
272
|
-
})), {
|
|
273
|
-
kind: "openfin",
|
|
274
|
-
post(e) {
|
|
275
|
-
r.guardAsync("bus.send_failed", "InterApplicationBus.publish", () => i.publish(a, O(e)));
|
|
276
|
-
},
|
|
277
|
-
close() {}
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
function Pt(e, t) {
|
|
281
|
-
let n = globalThis, r = n.postMessage;
|
|
282
|
-
return n.WorkerGlobalScope === void 0 || !r ? null : (n.addEventListener?.("message", (t) => {
|
|
283
|
-
let n = k(t.data);
|
|
284
|
-
n && e(n, {
|
|
285
|
-
link: "owner",
|
|
286
|
-
origin: "same-origin"
|
|
287
|
-
});
|
|
288
|
-
}), {
|
|
289
|
-
kind: "owner",
|
|
290
|
-
post(e) {
|
|
291
|
-
t.guard("bus.send_failed", "worker postMessage", () => {
|
|
292
|
-
r(O(e));
|
|
293
|
-
});
|
|
294
|
-
},
|
|
295
|
-
close() {}
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
function Ft(e, t, n) {
|
|
299
|
-
let r = (e) => {
|
|
300
|
-
let n = k(e.data);
|
|
301
|
-
n && t(n, {
|
|
302
|
-
link: "worker",
|
|
303
|
-
origin: "same-origin"
|
|
304
|
-
});
|
|
305
|
-
};
|
|
306
|
-
return e.addEventListener("message", r), e.start?.(), {
|
|
307
|
-
kind: "worker",
|
|
308
|
-
post(t) {
|
|
309
|
-
n.guard("bus.send_failed", "postMessage to a worker", () => {
|
|
310
|
-
e.postMessage(O(t));
|
|
311
|
-
});
|
|
312
|
-
},
|
|
313
|
-
close() {
|
|
314
|
-
e.removeEventListener("message", r);
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
//#endregion
|
|
319
|
-
//#region src/bus/bus.ts
|
|
320
|
-
var It = {
|
|
321
|
-
timeoutMs: vt,
|
|
322
|
-
maxAttempts: 3
|
|
323
|
-
}, Lt = [
|
|
324
|
-
"children",
|
|
325
|
-
"direct",
|
|
326
|
-
"worker"
|
|
327
|
-
], Rt = class {
|
|
328
|
-
config;
|
|
329
|
-
diagnostics;
|
|
330
|
-
platform;
|
|
331
|
-
contextId;
|
|
332
|
-
tabId;
|
|
333
|
-
handlers;
|
|
334
|
-
handshakeOptions;
|
|
335
|
-
role = "sender";
|
|
336
|
-
upstream = null;
|
|
337
|
-
links = [];
|
|
338
|
-
openFinLink = null;
|
|
339
|
-
isOpenFinProvider = !1;
|
|
340
|
-
resolved = !1;
|
|
341
|
-
awaitingWelcome = null;
|
|
342
|
-
constructor(e, t, n, r, i, a, o = It) {
|
|
343
|
-
this.config = e, this.diagnostics = t, this.platform = n, this.contextId = r, this.tabId = i, this.handlers = a, this.handshakeOptions = o;
|
|
344
|
-
}
|
|
345
|
-
getRole() {
|
|
346
|
-
return this.role;
|
|
347
|
-
}
|
|
348
|
-
isResolved() {
|
|
349
|
-
return this.resolved;
|
|
350
|
-
}
|
|
351
|
-
async start() {
|
|
352
|
-
let { bus: e } = this.config;
|
|
353
|
-
if (e.mode === "off") return this.role = "sender", this.resolved = !0, this.role;
|
|
354
|
-
if (this.isOpenFinProvider = this.resolveOpenFinProvider(), e.mode === "sender" || e.mode === "forwarder") return this.role = e.mode, this.openControlLinks(), this.role === "forwarder" && (this.upstream = this.candidateUpstream(), this.upstream || this.diagnostics.report("bus.no_owner", "bus.mode is \"forwarder\" but there is no owner to forward to. Records will be dropped.")), this.resolved = !0, this.announce(), this.role;
|
|
355
|
-
this.openControlLinks();
|
|
356
|
-
let t = kt(this.receive, this.diagnostics);
|
|
357
|
-
if (t) return this.role = "forwarder", this.upstream = t, this.resolved = !0, this.diagnostics.report("bus.role_resolved", "attached directly to the same-origin parent runtime", {
|
|
358
|
-
role: "forwarder",
|
|
359
|
-
via: "direct"
|
|
360
|
-
}), this.announce(), this.role;
|
|
361
|
-
let n = this.candidateUpstream();
|
|
362
|
-
if (!n) return this.role = "sender", this.resolved = !0, this.diagnostics.report("bus.role_resolved", "no owner to forward to, sending directly", { role: "sender" }), this.announce(), this.role;
|
|
363
|
-
let r = this.orphanPolicy() === "retry" ? this.handshakeOptions.maxAttempts : 1, i = !1;
|
|
364
|
-
for (let e = 0; e < r && !i; e++) i = await this.handshake(n);
|
|
365
|
-
return this.role = i ? "forwarder" : "sender", this.upstream = i ? n : null, i || (n !== this.openFinLink && n.close(), this.diagnostics.report("bus.handshake_timeout", `no owner answered after ${String(r)} attempt(s) of ${String(this.handshakeOptions.timeoutMs)}ms, promoting to sender`, {
|
|
366
|
-
via: n.kind,
|
|
367
|
-
crossOrigin: this.isCrossOriginFrame()
|
|
368
|
-
})), this.diagnostics.report("bus.role_resolved", `role is ${this.role}`, {
|
|
369
|
-
role: this.role,
|
|
370
|
-
via: i ? n.kind : "none"
|
|
371
|
-
}), this.resolved = !0, this.announce(), this.role;
|
|
372
|
-
}
|
|
373
|
-
sendRecords(e) {
|
|
374
|
-
this.upstream?.post({
|
|
375
|
-
t: "records",
|
|
376
|
-
from: this.contextId,
|
|
377
|
-
records: e
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
acceptDirect(e, t) {
|
|
381
|
-
if (e.from === this.contextId) return;
|
|
382
|
-
let n = {
|
|
383
|
-
link: "direct",
|
|
384
|
-
origin: "same-origin"
|
|
385
|
-
};
|
|
386
|
-
if (e.t === "hello") {
|
|
387
|
-
this.canOwn("direct") && t({
|
|
388
|
-
t: "welcome",
|
|
389
|
-
from: this.contextId,
|
|
390
|
-
to: e.from,
|
|
391
|
-
tabId: this.tabId
|
|
392
|
-
}, n);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (e.t === "journey?") {
|
|
396
|
-
let e = this.handlers.onJourneyRequest();
|
|
397
|
-
e && t({
|
|
398
|
-
t: "journey",
|
|
399
|
-
from: this.contextId,
|
|
400
|
-
journey: e
|
|
401
|
-
}, n);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
this.receive(e, n);
|
|
405
|
-
}
|
|
406
|
-
attachWorker(e) {
|
|
407
|
-
this.links.push(Ft(e, this.receive, this.diagnostics));
|
|
408
|
-
}
|
|
409
|
-
broadcastJourney(e) {
|
|
410
|
-
this.post({
|
|
411
|
-
t: "journey",
|
|
412
|
-
from: this.contextId,
|
|
413
|
-
journey: e
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
destroy() {
|
|
417
|
-
for (let e of this.allLinks()) e.close();
|
|
418
|
-
this.links.length = 0, this.upstream = null, this.openFinLink = null;
|
|
419
|
-
}
|
|
420
|
-
allLinks() {
|
|
421
|
-
return !this.upstream || this.links.includes(this.upstream) ? this.links : [...this.links, this.upstream];
|
|
422
|
-
}
|
|
423
|
-
post(e) {
|
|
424
|
-
for (let t of this.allLinks()) t.post(e);
|
|
425
|
-
}
|
|
426
|
-
postOver(e, t) {
|
|
427
|
-
for (let n of this.allLinks()) n.kind === e && n.post(t);
|
|
428
|
-
}
|
|
429
|
-
receive = (e, t) => {
|
|
430
|
-
if (e.from !== this.contextId) switch (e.t) {
|
|
431
|
-
case "hello":
|
|
432
|
-
this.canOwn(t.link) && this.postOver(t.link, {
|
|
433
|
-
t: "welcome",
|
|
434
|
-
from: this.contextId,
|
|
435
|
-
to: e.from,
|
|
436
|
-
tabId: this.tabId
|
|
437
|
-
});
|
|
438
|
-
break;
|
|
439
|
-
case "welcome":
|
|
440
|
-
if (e.to !== this.contextId) break;
|
|
441
|
-
this.awaitingWelcome?.link === t.link && this.awaitingWelcome.settle(!0);
|
|
442
|
-
break;
|
|
443
|
-
case "records":
|
|
444
|
-
this.role === "sender" ? this.handlers.onRecords(e.records) : this.upstream && this.canRelay(t.link) && this.upstream.post(e);
|
|
445
|
-
break;
|
|
446
|
-
case "journey":
|
|
447
|
-
this.handlers.onJourney(e.journey);
|
|
448
|
-
break;
|
|
449
|
-
case "journey?": {
|
|
450
|
-
let e = this.handlers.onJourneyRequest();
|
|
451
|
-
e && this.postOver(t.link, {
|
|
452
|
-
t: "journey",
|
|
453
|
-
from: this.contextId,
|
|
454
|
-
journey: e
|
|
455
|
-
});
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
case "tab": t.link === "broadcast" && e.tabId === this.tabId && this.contextId > e.from && this.handlers.onTabConflict();
|
|
459
|
-
}
|
|
460
|
-
};
|
|
461
|
-
canRelay(e) {
|
|
462
|
-
return e === "direct" || e !== this.upstream?.kind;
|
|
463
|
-
}
|
|
464
|
-
canOwn(e) {
|
|
465
|
-
return this.role === "sender" ? e === "openfin" ? this.isOpenFinProvider : Lt.includes(e) : !1;
|
|
466
|
-
}
|
|
467
|
-
resolveOpenFinProvider() {
|
|
468
|
-
let e = this.config.bus.openFinRole;
|
|
469
|
-
if (e !== "auto") return e === "provider";
|
|
470
|
-
if (this.platform.platform !== "openfin" && this.platform.platform !== "openfin_web") return !1;
|
|
471
|
-
let t = globalThis.fin?.me;
|
|
472
|
-
return !t?.identity || t.isView ? !1 : !!(t.identity.name && t.identity.name === t.identity.uuid);
|
|
473
|
-
}
|
|
474
|
-
orphanPolicy() {
|
|
475
|
-
return this.isCrossOriginFrame() ? "retry" : "promote";
|
|
476
|
-
}
|
|
477
|
-
isCrossOriginFrame() {
|
|
478
|
-
if (typeof window > "u" || window.parent === window) return !1;
|
|
479
|
-
try {
|
|
480
|
-
return Reflect.get(window.parent, "location"), !1;
|
|
481
|
-
} catch {
|
|
482
|
-
return !0;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
candidateUpstream() {
|
|
486
|
-
return this.platform.isWorker ? Pt(this.receive, this.diagnostics) : this.platform.isTopLevelDocument ? this.platform.platform === "openfin" && !this.isOpenFinProvider ? this.ensureOpenFinLink() : null : At(this.receive, this.diagnostics);
|
|
487
|
-
}
|
|
488
|
-
openControlLinks() {
|
|
489
|
-
let e = (e) => {
|
|
490
|
-
e && this.links.push(e);
|
|
491
|
-
};
|
|
492
|
-
this.platform.isTopLevelDocument && (e(jt(this.receive, this.config.bus.trustedOrigins, this.diagnostics)), e(Mt(De, this.receive, this.diagnostics))), (this.platform.platform === "openfin" || this.platform.platform === "openfin_web") && e(this.ensureOpenFinLink());
|
|
493
|
-
}
|
|
494
|
-
ensureOpenFinLink() {
|
|
495
|
-
return this.openFinLink ??= Nt(De, this.platform.openfinUuid, this.receive, this.diagnostics), this.openFinLink;
|
|
496
|
-
}
|
|
497
|
-
handshake(e) {
|
|
498
|
-
return new Promise((t) => {
|
|
499
|
-
let n = !1, r = (e) => {
|
|
500
|
-
n || (n = !0, this.awaitingWelcome = null, clearTimeout(i), t(e));
|
|
501
|
-
};
|
|
502
|
-
this.awaitingWelcome = {
|
|
503
|
-
link: e.kind,
|
|
504
|
-
settle: r
|
|
505
|
-
};
|
|
506
|
-
let i = setTimeout(() => {
|
|
507
|
-
r(!1);
|
|
508
|
-
}, this.handshakeOptions.timeoutMs);
|
|
509
|
-
D(i), e.post({
|
|
510
|
-
t: "hello",
|
|
511
|
-
from: this.contextId,
|
|
512
|
-
tabId: this.tabId
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
announce() {
|
|
517
|
-
this.postOver("broadcast", {
|
|
518
|
-
t: "tab",
|
|
519
|
-
from: this.contextId,
|
|
520
|
-
tabId: this.tabId
|
|
521
|
-
}), this.post({
|
|
522
|
-
t: "journey?",
|
|
523
|
-
from: this.contextId
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
}, A = null;
|
|
527
|
-
function j(e, t) {
|
|
528
|
-
let n = e[t];
|
|
529
|
-
return n !== void 0 && e instanceof n;
|
|
530
|
-
}
|
|
531
|
-
function zt(e) {
|
|
532
|
-
if (A) return A;
|
|
533
|
-
let t = globalThis, n = t.navigator?.userAgent ?? "", r = "browser", i, a, o = !1, s = t.fin?.me;
|
|
534
|
-
return j(t, "ServiceWorkerGlobalScope") ? (r = "service_worker", o = !0) : j(t, "SharedWorkerGlobalScope") ? (r = "shared_worker", o = !0) : j(t, "WorkerGlobalScope") ? (r = "web_worker", o = !0) : s === void 0 ? t.Capacitor !== void 0 || t.Ionic !== void 0 ? r = "ionic" : t.cordova !== void 0 || Bt(n) ? r = "mobile_webview" : typeof document > "u" && typeof process < "u" && (r = "node") : (r = Re.test(n) ? "openfin" : "openfin_web", e.guard("openfin.unavailable", "reading fin.me.identity", () => {
|
|
535
|
-
let e = s.identity;
|
|
536
|
-
i = e?.uuid, a = e?.name;
|
|
537
|
-
})), A = {
|
|
538
|
-
platform: r,
|
|
539
|
-
openfinUuid: i,
|
|
540
|
-
openfinName: a,
|
|
541
|
-
userAgent: n,
|
|
542
|
-
isWorker: o,
|
|
543
|
-
isTopLevelDocument: Vt()
|
|
544
|
-
}, A;
|
|
545
|
-
}
|
|
546
|
-
function Bt(e) {
|
|
547
|
-
return dt.test(e) ? !0 : (Fe.test(e) || je.test(e) && Ne.test(e)) && e.includes("AppleWebKit") && !e.includes("Safari/");
|
|
548
|
-
}
|
|
549
|
-
function Vt() {
|
|
550
|
-
if (typeof window > "u") return !1;
|
|
551
|
-
try {
|
|
552
|
-
return window.self === window.top;
|
|
553
|
-
} catch {
|
|
554
|
-
return !1;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
function Ht() {
|
|
558
|
-
try {
|
|
559
|
-
return typeof location < "u" ? location.href : "";
|
|
560
|
-
} catch {
|
|
561
|
-
return "";
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
function M(e) {
|
|
565
|
-
let t = e.search(/[?#]/);
|
|
566
|
-
return t === -1 ? e : e.slice(0, t);
|
|
567
|
-
}
|
|
568
|
-
//#endregion
|
|
569
|
-
//#region src/capture/errors.ts
|
|
570
|
-
var Ut = class {
|
|
571
|
-
ctx;
|
|
572
|
-
name = "errors";
|
|
573
|
-
installed = !1;
|
|
574
|
-
seen = /* @__PURE__ */ new Map();
|
|
575
|
-
windowStart = 0;
|
|
576
|
-
windowCount = 0;
|
|
577
|
-
constructor(e) {
|
|
578
|
-
this.ctx = e;
|
|
579
|
-
}
|
|
580
|
-
install() {
|
|
581
|
-
this.installed || typeof addEventListener > "u" || (this.installed = !0, addEventListener("error", this.onError, !0), addEventListener("unhandledrejection", this.onRejection));
|
|
582
|
-
}
|
|
583
|
-
uninstall() {
|
|
584
|
-
this.installed && (this.installed = !1, removeEventListener("error", this.onError, !0), removeEventListener("unhandledrejection", this.onRejection), this.seen.clear());
|
|
585
|
-
}
|
|
586
|
-
onError = (e) => {
|
|
587
|
-
let t = e.target, n = t?.src ?? t?.href ?? "";
|
|
588
|
-
if (t !== null && t !== globalThis && n !== "") {
|
|
589
|
-
if (!this.ctx.config.capture.resourceErrors) return;
|
|
590
|
-
let e = this.ctx.config.capture.fullUrls ? n : M(n);
|
|
591
|
-
this.ctx.breadcrumbs.push({
|
|
592
|
-
t: Date.now(),
|
|
593
|
-
category: "http",
|
|
594
|
-
message: `resource failed: ${e}`
|
|
595
|
-
}), this.ctx.logger.warn("resource failed to load", {
|
|
596
|
-
"error.type": "resource",
|
|
597
|
-
"resource.url": e,
|
|
598
|
-
"resource.tag": t.tagName.toLowerCase()
|
|
599
|
-
});
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
if (!this.ctx.config.capture.errors) return;
|
|
603
|
-
let r = e, i = r.message === "" ? "unknown error" : r.message, a = r.error ?? Error(i);
|
|
604
|
-
this.report("window.onerror", a, {
|
|
605
|
-
"error.source": r.filename,
|
|
606
|
-
"error.line": r.lineno,
|
|
607
|
-
"error.column": r.colno
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
onRejection = (e) => {
|
|
611
|
-
this.ctx.config.capture.rejections && this.report("unhandledrejection", e.reason, { "error.type": "unhandledrejection" });
|
|
612
|
-
};
|
|
613
|
-
report(e, t, n) {
|
|
614
|
-
let r = Date.now();
|
|
615
|
-
if (r - this.windowStart > 1e4 && (this.windowStart = r, this.windowCount = 0), this.windowCount++, this.windowCount > 20) {
|
|
616
|
-
this.ctx.diagnostics.report("capture.rate_limited", `more than 20 errors in ${String(_e)}ms, suppressing the rest of this window`);
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
let i = t instanceof Error ? t : Error(String(t)), a = (i.stack ?? "").split("\n")[1] ?? "", o = `${i.name}|${i.message}|${a}`, s = this.seen.get(o);
|
|
620
|
-
if (s && r - s.at < 5e3) {
|
|
621
|
-
s.count++, s.at = r;
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
let c = s ? s.count - 1 : 0;
|
|
625
|
-
if (this.seen.delete(o), this.seen.set(o, {
|
|
626
|
-
at: r,
|
|
627
|
-
count: 1
|
|
628
|
-
}), this.seen.size > 200) {
|
|
629
|
-
let [e] = this.seen.keys();
|
|
630
|
-
this.seen.delete(e);
|
|
631
|
-
}
|
|
632
|
-
this.ctx.logger.error(i.message === "" ? e : i.message, i, {
|
|
633
|
-
...n,
|
|
634
|
-
"error.captured_by": e,
|
|
635
|
-
"error.suppressed_count": c
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
};
|
|
639
|
-
//#endregion
|
|
640
|
-
//#region src/capture/interactions.ts
|
|
641
|
-
function Wt(e) {
|
|
642
|
-
if (e === null) return "unknown";
|
|
643
|
-
let t = e.tagName.toLowerCase(), n = e.getAttribute("data-testid") ?? e.getAttribute("data-test-id");
|
|
644
|
-
if (n !== null) return `[data-testid="${n}"]`;
|
|
645
|
-
if (e.id !== "") return `#${e.id}`;
|
|
646
|
-
let r = e.getAttribute("aria-label");
|
|
647
|
-
if (r !== null) return `${t}[aria-label="${r.slice(0, 40)}"]`;
|
|
648
|
-
let i = e.getAttribute("class")?.trim() ?? "";
|
|
649
|
-
return i === "" ? t : `${t}.${i.split(/\s+/).slice(0, 2).join(".")}`;
|
|
650
|
-
}
|
|
651
|
-
function N() {
|
|
652
|
-
return history;
|
|
653
|
-
}
|
|
654
|
-
var Gt = class {
|
|
655
|
-
ctx;
|
|
656
|
-
name = "interactions";
|
|
657
|
-
installed = !1;
|
|
658
|
-
originalPushState = null;
|
|
659
|
-
originalReplaceState = null;
|
|
660
|
-
lastUrl = "";
|
|
661
|
-
constructor(e) {
|
|
662
|
-
this.ctx = e;
|
|
663
|
-
}
|
|
664
|
-
install() {
|
|
665
|
-
this.installed || typeof document > "u" || (this.installed = !0, this.lastUrl = location.href, this.ctx.config.capture.interactions && addEventListener("click", this.onClick, !0), this.ctx.config.capture.navigation && (this.installHistory(), addEventListener("popstate", this.onNavigate), addEventListener("hashchange", this.onNavigate)));
|
|
666
|
-
}
|
|
667
|
-
uninstall() {
|
|
668
|
-
this.installed && (this.installed = !1, removeEventListener("click", this.onClick, !0), removeEventListener("popstate", this.onNavigate), removeEventListener("hashchange", this.onNavigate), this.originalPushState && (N().pushState = this.originalPushState), this.originalReplaceState && (N().replaceState = this.originalReplaceState), this.originalPushState = null, this.originalReplaceState = null);
|
|
669
|
-
}
|
|
670
|
-
onClick = (e) => {
|
|
671
|
-
let t = e.target, n = Wt(t instanceof Element ? t : null), r = t instanceof HTMLElement ? t.textContent.trim().slice(0, 50) : "";
|
|
672
|
-
this.ctx.tracing.rotate("interaction"), this.ctx.breadcrumbs.push({
|
|
673
|
-
t: Date.now(),
|
|
674
|
-
category: "click",
|
|
675
|
-
message: n,
|
|
676
|
-
data: r === "" ? void 0 : { text: r }
|
|
677
|
-
});
|
|
678
|
-
};
|
|
679
|
-
onNavigate = () => {
|
|
680
|
-
let e = this.lastUrl, t = location.href;
|
|
681
|
-
if (e === t) return;
|
|
682
|
-
this.lastUrl = t;
|
|
683
|
-
let n = this.ctx.config.capture.fullUrls, r = n ? e : M(e), i = n ? t : M(t);
|
|
684
|
-
this.ctx.tracing.rotate("navigation"), this.ctx.breadcrumbs.push({
|
|
685
|
-
t: Date.now(),
|
|
686
|
-
category: "navigation",
|
|
687
|
-
message: `${r} -> ${i}`
|
|
688
|
-
}), this.ctx.logger.logEvent("NAVIGATION", { "page.url.previous": r });
|
|
689
|
-
};
|
|
690
|
-
installHistory() {
|
|
691
|
-
if (typeof history > "u" || this.originalPushState) return;
|
|
692
|
-
let e = N(), t = e.pushState, n = e.replaceState;
|
|
693
|
-
this.originalPushState = t, this.originalReplaceState = n;
|
|
694
|
-
let r = this.onNavigate;
|
|
695
|
-
e.pushState = function(...e) {
|
|
696
|
-
t.apply(this, e), queueMicrotask(r);
|
|
697
|
-
}, e.replaceState = function(...e) {
|
|
698
|
-
n.apply(this, e), queueMicrotask(r);
|
|
699
|
-
};
|
|
700
|
-
}
|
|
701
|
-
};
|
|
702
|
-
//#endregion
|
|
703
|
-
//#region src/capture/types.ts
|
|
704
|
-
function Kt(e, t) {
|
|
705
|
-
return t.some((t) => typeof t == "string" ? e.includes(t) : t.test(e));
|
|
706
|
-
}
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/capture/network.ts
|
|
709
|
-
function P() {
|
|
710
|
-
return XMLHttpRequest.prototype;
|
|
711
|
-
}
|
|
712
|
-
var qt = class {
|
|
713
|
-
ctx;
|
|
714
|
-
name = "network";
|
|
715
|
-
originalFetch = null;
|
|
716
|
-
originalOpen = null;
|
|
717
|
-
originalSend = null;
|
|
718
|
-
constructor(e) {
|
|
719
|
-
this.ctx = e;
|
|
720
|
-
}
|
|
721
|
-
install() {
|
|
722
|
-
this.ctx.config.capture.fetch && this.installFetch(), this.ctx.config.capture.xhr && this.installXhr();
|
|
723
|
-
}
|
|
724
|
-
uninstall() {
|
|
725
|
-
this.originalFetch &&= (globalThis.fetch = this.originalFetch, null), this.originalOpen &&= (P().open = this.originalOpen, null), this.originalSend &&= (P().send = this.originalSend, null);
|
|
726
|
-
}
|
|
727
|
-
ignored(e) {
|
|
728
|
-
return Kt(e, this.ctx.config.capture.ignoreUrls);
|
|
729
|
-
}
|
|
730
|
-
installFetch() {
|
|
731
|
-
if (typeof globalThis.fetch != "function" || this.originalFetch) return;
|
|
732
|
-
let e = globalThis.fetch.bind(globalThis);
|
|
733
|
-
this.originalFetch = globalThis.fetch;
|
|
734
|
-
let t = this.ctx, n = (e) => this.ignored(e), r = (e, t, n, r, i) => {
|
|
735
|
-
this.record(e, t, n, r, i);
|
|
736
|
-
};
|
|
737
|
-
globalThis.fetch = async function(i, a) {
|
|
738
|
-
let o = typeof i == "string" ? i : i instanceof URL ? i.href : i.url, s = (a?.method ?? (i instanceof Request ? i.method : "GET")).toUpperCase();
|
|
739
|
-
if (n(o)) return e(i, a);
|
|
740
|
-
let c = i, l = a;
|
|
741
|
-
if (Kt(o, t.config.capture.propagateTraceHeaderTo)) try {
|
|
742
|
-
let e = Object.entries(t.tracing.headers());
|
|
743
|
-
if (i instanceof Request) {
|
|
744
|
-
let t = new Headers(i.headers);
|
|
745
|
-
for (let [n, r] of e) t.set(n, r);
|
|
746
|
-
c = new Request(i, { headers: t });
|
|
747
|
-
} else {
|
|
748
|
-
let t = new Headers(a?.headers);
|
|
749
|
-
for (let [n, r] of e) t.set(n, r);
|
|
750
|
-
l = {
|
|
751
|
-
...a,
|
|
752
|
-
headers: t
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
} catch (e) {
|
|
756
|
-
c = i, l = a, t.diagnostics.report("capture.header_failed", "could not attach traceparent, sending the request unchanged", { url: o }, e);
|
|
757
|
-
}
|
|
758
|
-
let u = performance.now();
|
|
759
|
-
try {
|
|
760
|
-
let t = await e(c, l);
|
|
761
|
-
return r(s, o, t.status, performance.now() - u, void 0), t;
|
|
762
|
-
} catch (e) {
|
|
763
|
-
throw r(s, o, 0, performance.now() - u, e), e;
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
installXhr() {
|
|
768
|
-
if (typeof XMLHttpRequest > "u" || this.originalOpen) return;
|
|
769
|
-
let e = (e) => this.ignored(e), t = (e, t, n, r) => {
|
|
770
|
-
this.record(e, t, n, r, void 0);
|
|
771
|
-
}, n = P(), r = n.open, i = n.send;
|
|
772
|
-
this.originalOpen = r, this.originalSend = i, n.open = function(e, t, ...n) {
|
|
773
|
-
this.__uiobs = {
|
|
774
|
-
method: e.toUpperCase(),
|
|
775
|
-
url: String(t),
|
|
776
|
-
startedAt: 0
|
|
777
|
-
}, r.apply(this, [
|
|
778
|
-
e,
|
|
779
|
-
t,
|
|
780
|
-
...n
|
|
781
|
-
]);
|
|
782
|
-
}, n.send = function(...n) {
|
|
783
|
-
let r = this.__uiobs;
|
|
784
|
-
r && !e(r.url) && (r.startedAt = performance.now(), this.addEventListener("loadend", () => {
|
|
785
|
-
t(r.method, r.url, this.status, performance.now() - r.startedAt);
|
|
786
|
-
})), i.apply(this, n);
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
record(e, t, n, r, i) {
|
|
790
|
-
let a = this.ctx.config.capture.fullUrls ? t : M(t);
|
|
791
|
-
this.ctx.diagnostics.guard("capture.record_failed", `recording ${e} ${a}`, () => {
|
|
792
|
-
let t = Math.round(r);
|
|
793
|
-
this.ctx.breadcrumbs.push({
|
|
794
|
-
t: Date.now(),
|
|
795
|
-
category: "http",
|
|
796
|
-
message: `${e} ${a} ${n === 0 ? "failed" : String(n)}`,
|
|
797
|
-
data: { durationMs: t }
|
|
798
|
-
});
|
|
799
|
-
let o = {
|
|
800
|
-
"http.request.method": e,
|
|
801
|
-
"url.full": a,
|
|
802
|
-
"http.response.status_code": n,
|
|
803
|
-
"http.duration_ms": t
|
|
804
|
-
};
|
|
805
|
-
if (n === 0) {
|
|
806
|
-
this.ctx.logger.error(`${e} ${a} failed`, i, o);
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
if (n >= 400) {
|
|
810
|
-
this.ctx.logger.warn(`${e} ${a} returned ${String(n)}`, o);
|
|
811
|
-
return;
|
|
812
|
-
}
|
|
813
|
-
this.ctx.logger.debug(`${e} ${a}`, o);
|
|
814
|
-
});
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
//#endregion
|
|
818
|
-
//#region src/capture/web-vitals.ts
|
|
819
|
-
function Jt() {
|
|
820
|
-
return import(
|
|
821
|
-
/* @vite-ignore */
|
|
822
|
-
"web-vitals"
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
var Yt = class {
|
|
826
|
-
ctx;
|
|
827
|
-
name = "web-vitals";
|
|
828
|
-
installed = !1;
|
|
829
|
-
constructor(e) {
|
|
830
|
-
this.ctx = e;
|
|
831
|
-
}
|
|
832
|
-
install() {
|
|
833
|
-
this.installed || (this.installed = !0, this.reportNavigationTiming(), !this.ctx.once.webVitals && (this.ctx.once.webVitals = !0, this.loadWebVitals()));
|
|
834
|
-
}
|
|
835
|
-
uninstall() {
|
|
836
|
-
this.installed = !1;
|
|
837
|
-
}
|
|
838
|
-
async loadWebVitals() {
|
|
839
|
-
let e = this.ctx.config.capture.webVitalsLoader ?? Jt, t = await this.ctx.diagnostics.guardAsync("capture.install_failed", "loading web-vitals", e);
|
|
840
|
-
if (!t) {
|
|
841
|
-
this.ctx.diagnostics.report("capture.install_failed", "web-vitals is not available, so LCP, CLS and INP are unavailable. Navigation timing still works.");
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
let n = (e, t) => (n) => {
|
|
845
|
-
this.ctx.logger.logMetric(`web_vitals.${e}`, Math.round(n.value * 1e3) / 1e3, t, "gauge", {
|
|
846
|
-
"metric.rating": n.rating,
|
|
847
|
-
"metric.id": n.id
|
|
848
|
-
});
|
|
849
|
-
};
|
|
850
|
-
t.onLCP(n("lcp", "ms")), t.onCLS(n("cls", "1")), t.onINP(n("inp", "ms")), t.onFCP(n("fcp", "ms")), t.onTTFB(n("ttfb", "ms"));
|
|
851
|
-
}
|
|
852
|
-
reportNavigationTiming() {
|
|
853
|
-
this.ctx.once.navigationTiming || (this.ctx.once.navigationTiming = !0, this.ctx.diagnostics.guard("capture.install_failed", "reading navigation timing", () => {
|
|
854
|
-
let e = performance.getEntriesByType("navigation")[0];
|
|
855
|
-
if (!e) return;
|
|
856
|
-
let t = {
|
|
857
|
-
"navigation.dns_ms": e.domainLookupEnd - e.domainLookupStart,
|
|
858
|
-
"navigation.tcp_ms": e.connectEnd - e.connectStart,
|
|
859
|
-
"navigation.ttfb_ms": e.responseStart - e.requestStart,
|
|
860
|
-
"navigation.response_ms": e.responseEnd - e.responseStart,
|
|
861
|
-
"navigation.dom_interactive_ms": e.domInteractive,
|
|
862
|
-
"navigation.dom_complete_ms": e.domComplete,
|
|
863
|
-
"navigation.load_ms": e.loadEventEnd
|
|
864
|
-
};
|
|
865
|
-
for (let [n, r] of Object.entries(t)) Number.isFinite(r) && r >= 0 && this.ctx.logger.logMetric(n, Math.round(r), "ms", "gauge", { "navigation.type": e.type });
|
|
866
|
-
}));
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
//#endregion
|
|
870
|
-
//#region src/models/log-record.ts
|
|
871
|
-
function Xt() {
|
|
872
|
-
return `${String(Date.now())}000000`;
|
|
873
|
-
}
|
|
874
|
-
function Zt(e) {
|
|
875
|
-
if (typeof e != "object" || !e) return !1;
|
|
876
|
-
let t = e;
|
|
877
|
-
return typeof t.body == "string" && typeof t.severityText == "string" && typeof t.timeUnixNano == "string" && typeof t.attributes == "object" && t.attributes !== null && typeof t.resource == "object" && t.resource !== null;
|
|
878
|
-
}
|
|
879
|
-
//#endregion
|
|
880
|
-
//#region src/utils/identity.ts
|
|
881
|
-
function F(e) {
|
|
882
|
-
let t = new Uint8Array(e);
|
|
883
|
-
if (typeof crypto < "u" && typeof crypto.getRandomValues == "function") crypto.getRandomValues(t);
|
|
884
|
-
else for (let n = 0; n < e; n++) t[n] = Math.floor(Math.random() * 256);
|
|
885
|
-
return Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
|
|
886
|
-
}
|
|
887
|
-
function I() {
|
|
888
|
-
try {
|
|
889
|
-
if (typeof crypto < "u" && typeof crypto.randomUUID == "function") return crypto.randomUUID();
|
|
890
|
-
} catch {}
|
|
891
|
-
return F(16);
|
|
892
|
-
}
|
|
893
|
-
function Qt(e, t, n) {
|
|
894
|
-
return n.guard("storage.unavailable", `reading ${e}Storage`, () => (e === "local" ? localStorage : sessionStorage).getItem(t)) ?? null;
|
|
895
|
-
}
|
|
896
|
-
function L(e, t, n, r) {
|
|
897
|
-
r.guard("storage.unavailable", `writing ${e}Storage`, () => {
|
|
898
|
-
(e === "local" ? localStorage : sessionStorage).setItem(t, n);
|
|
899
|
-
});
|
|
900
|
-
}
|
|
901
|
-
function $t(e) {
|
|
902
|
-
let t = I(), n = Date.now(), r = I(), i = Qt("local", h, e);
|
|
903
|
-
if (i) try {
|
|
904
|
-
let e = JSON.parse(i);
|
|
905
|
-
e.id && n - (e.lastSeenAt ?? 0) < 18e5 && (r = e.id);
|
|
906
|
-
} catch {
|
|
907
|
-
e.report("storage.degraded", "session record was not JSON, starting a new session");
|
|
908
|
-
}
|
|
909
|
-
let a = JSON.stringify({
|
|
910
|
-
id: r,
|
|
911
|
-
lastSeenAt: n
|
|
912
|
-
});
|
|
913
|
-
L("local", h, a, e);
|
|
914
|
-
let o = Qt("session", "ui-observability.tab", e) ?? "";
|
|
915
|
-
return o || (o = I(), L("session", Pe, o, e)), {
|
|
916
|
-
sessionId: r,
|
|
917
|
-
tabId: o,
|
|
918
|
-
contextId: t
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
var en = class {
|
|
922
|
-
diagnostics;
|
|
923
|
-
lastTouchAt = 0;
|
|
924
|
-
constructor(e) {
|
|
925
|
-
this.diagnostics = e;
|
|
926
|
-
}
|
|
927
|
-
touch(e) {
|
|
928
|
-
let t = Date.now();
|
|
929
|
-
if (t - this.lastTouchAt < 6e4) return;
|
|
930
|
-
this.lastTouchAt = t;
|
|
931
|
-
let n = JSON.stringify({
|
|
932
|
-
id: e,
|
|
933
|
-
lastSeenAt: t
|
|
934
|
-
});
|
|
935
|
-
L("local", h, n, this.diagnostics);
|
|
936
|
-
}
|
|
937
|
-
};
|
|
938
|
-
//#endregion
|
|
939
|
-
//#region src/models/batch.ts
|
|
940
|
-
function tn(e) {
|
|
941
|
-
if (typeof e != "object" || !e) return !1;
|
|
942
|
-
let t = Reflect.get(e, "id"), n = Reflect.get(e, "createdAt"), r = Reflect.get(e, "attempts"), i = Reflect.get(e, "records");
|
|
943
|
-
return typeof t == "string" && typeof n == "number" && typeof r == "number" && Array.isArray(i);
|
|
944
|
-
}
|
|
945
|
-
function nn(e) {
|
|
946
|
-
if (e.records.length < 2) return null;
|
|
947
|
-
let t = Math.floor(e.records.length / 2), n = (t) => ({
|
|
948
|
-
id: I(),
|
|
949
|
-
records: t,
|
|
950
|
-
createdAt: e.createdAt,
|
|
951
|
-
attempts: e.attempts
|
|
952
|
-
});
|
|
953
|
-
return [n(e.records.slice(0, t)), n(e.records.slice(t))];
|
|
954
|
-
}
|
|
955
|
-
//#endregion
|
|
956
|
-
//#region src/utils/deadline.ts
|
|
957
|
-
function R(e, t) {
|
|
958
|
-
let n, r = new Promise((e, r) => {
|
|
959
|
-
let i = setTimeout(() => {
|
|
960
|
-
r(/* @__PURE__ */ Error(`timed out after ${String(t)}ms`));
|
|
961
|
-
}, t);
|
|
962
|
-
n = i, D(i);
|
|
963
|
-
});
|
|
964
|
-
return Promise.race([e, r]).finally(() => {
|
|
965
|
-
clearTimeout(n);
|
|
966
|
-
});
|
|
967
|
-
}
|
|
968
|
-
//#endregion
|
|
969
|
-
//#region src/utils/lock.ts
|
|
970
|
-
function rn(e, t, n, { skipIfBusy: r = !0 } = {}) {
|
|
971
|
-
let i = globalThis.navigator?.locks;
|
|
972
|
-
return i?.request ? t.guardAsync("storage.degraded", `acquiring lock ${e}`, () => i.request(e, { ifAvailable: r }, (e) => e ? n() : Promise.resolve(void 0))) : n();
|
|
973
|
-
}
|
|
974
|
-
//#endregion
|
|
975
|
-
//#region src/storage/keys.ts
|
|
976
|
-
function z(e, t) {
|
|
977
|
-
let n = [];
|
|
978
|
-
return t.guard("storage.unavailable", "enumerating localStorage", () => {
|
|
979
|
-
for (let t = 0; t < localStorage.length; t++) {
|
|
980
|
-
let r = String(localStorage.key(t));
|
|
981
|
-
r.startsWith(e) && n.push(r);
|
|
982
|
-
}
|
|
983
|
-
}), n.sort();
|
|
984
|
-
}
|
|
985
|
-
//#endregion
|
|
986
|
-
//#region src/storage/emergency-queue.ts
|
|
987
|
-
function an(e) {
|
|
988
|
-
let t = String(e.createdAt).padStart(14, "0");
|
|
989
|
-
return `${y}${t}.${e.id}`;
|
|
990
|
-
}
|
|
991
|
-
function on(e, t) {
|
|
992
|
-
let n = t.guard("storage.degraded", "an emergency entry was not JSON and was dropped", () => JSON.parse(e));
|
|
993
|
-
return n === void 0 ? null : tn(n) ? n : (t.report("storage.degraded", "an emergency entry was not a batch and was dropped"), null);
|
|
994
|
-
}
|
|
995
|
-
async function sn(e, t) {
|
|
996
|
-
let n = 0;
|
|
997
|
-
for (let r of z(y, t)) {
|
|
998
|
-
let i = t.guard("storage.unavailable", "reading the emergency queue", () => {
|
|
999
|
-
let e = localStorage.getItem(r);
|
|
1000
|
-
return localStorage.removeItem(r), e;
|
|
1001
|
-
});
|
|
1002
|
-
if (!i) continue;
|
|
1003
|
-
let a = on(i, t);
|
|
1004
|
-
if (a !== null) try {
|
|
1005
|
-
await R(e.save(a), v), n++;
|
|
1006
|
-
} catch (e) {
|
|
1007
|
-
t.report("storage.degraded", "an emergency batch could not be recovered", { key: r }, e);
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
return n;
|
|
1011
|
-
}
|
|
1012
|
-
function cn(e, t) {
|
|
1013
|
-
let n = `writing the emergency queue, ${String(e.records.length)} records`;
|
|
1014
|
-
t.guard("storage.quota_exceeded", n, () => {
|
|
1015
|
-
let n = z(y, t);
|
|
1016
|
-
for (let e of n.slice(0, Math.max(0, n.length - 20 + 1))) localStorage.removeItem(e);
|
|
1017
|
-
localStorage.setItem(an(e), JSON.stringify(e));
|
|
1018
|
-
});
|
|
1019
|
-
}
|
|
1020
|
-
async function ln(e, t) {
|
|
1021
|
-
return await rn("ui-observability.emergency", t, () => sn(e, t), { skipIfBusy: !1 }) ?? 0;
|
|
1022
|
-
}
|
|
1023
|
-
//#endregion
|
|
1024
|
-
//#region src/storage/local-storage.ts
|
|
1025
|
-
function un(e) {
|
|
1026
|
-
let t = String(e.createdAt).padStart(14, "0");
|
|
1027
|
-
return `${T}${t}.${e.id}`;
|
|
1028
|
-
}
|
|
1029
|
-
function dn(e) {
|
|
1030
|
-
let t = T.length, n = Number(e.slice(t, t + 14));
|
|
1031
|
-
return Number.isFinite(n) ? n : null;
|
|
1032
|
-
}
|
|
1033
|
-
var fn = class {
|
|
1034
|
-
limits;
|
|
1035
|
-
diagnostics;
|
|
1036
|
-
onGap;
|
|
1037
|
-
name = ye;
|
|
1038
|
-
constructor(e, t, n) {
|
|
1039
|
-
this.limits = e, this.diagnostics = t, this.onGap = n;
|
|
1040
|
-
}
|
|
1041
|
-
async save(e) {
|
|
1042
|
-
if (this.write(e, "localStorage refused a batch, evicting the oldest")) {
|
|
1043
|
-
await this.prune();
|
|
1044
|
-
return;
|
|
1045
|
-
}
|
|
1046
|
-
this.evictForQuota(), this.write(e, "localStorage refused a batch even after evicting") || this.reportGap({
|
|
1047
|
-
batches: 1,
|
|
1048
|
-
records: e.records.length,
|
|
1049
|
-
reason: "quota"
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
take(e) {
|
|
1053
|
-
let t = [];
|
|
1054
|
-
for (let n of this.keys().slice(0, e)) {
|
|
1055
|
-
let e = this.read(n);
|
|
1056
|
-
if (e === null) {
|
|
1057
|
-
this.removeKey(n);
|
|
1058
|
-
continue;
|
|
1059
|
-
}
|
|
1060
|
-
t.push(e);
|
|
1061
|
-
}
|
|
1062
|
-
return Promise.resolve(t);
|
|
1063
|
-
}
|
|
1064
|
-
remove(e) {
|
|
1065
|
-
let t = this.keyOf(e);
|
|
1066
|
-
return t !== null && this.removeKey(t), Promise.resolve();
|
|
1067
|
-
}
|
|
1068
|
-
bumpAttempts(e, t) {
|
|
1069
|
-
let n = this.keyOf(e);
|
|
1070
|
-
if (n === null) return Promise.resolve();
|
|
1071
|
-
let r = this.read(n);
|
|
1072
|
-
return r === null ? Promise.resolve() : (r.attempts = t, this.diagnostics.guard("storage.degraded", "updating attempts", () => {
|
|
1073
|
-
localStorage.setItem(n, JSON.stringify(r));
|
|
1074
|
-
}), Promise.resolve());
|
|
1075
|
-
}
|
|
1076
|
-
prune() {
|
|
1077
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
1078
|
-
batches: 0,
|
|
1079
|
-
records: 0,
|
|
1080
|
-
reason: "expired"
|
|
1081
|
-
}, n = (e) => {
|
|
1082
|
-
let n = this.read(e);
|
|
1083
|
-
this.removeKey(e), t.batches++, t.records += n?.records.length ?? 0;
|
|
1084
|
-
}, r = [];
|
|
1085
|
-
for (let t of this.keys()) {
|
|
1086
|
-
let i = dn(t);
|
|
1087
|
-
if (i === null || i < e) {
|
|
1088
|
-
n(t);
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
|
-
r.push(t);
|
|
1092
|
-
}
|
|
1093
|
-
let i = r.length - this.limits.maxBatches;
|
|
1094
|
-
if (i > 0) {
|
|
1095
|
-
t.reason = "over_capacity";
|
|
1096
|
-
for (let e of r.slice(0, i)) n(e);
|
|
1097
|
-
}
|
|
1098
|
-
return this.reportGap(t), Promise.resolve(t);
|
|
1099
|
-
}
|
|
1100
|
-
count() {
|
|
1101
|
-
return Promise.resolve(this.keys().length);
|
|
1102
|
-
}
|
|
1103
|
-
clear() {
|
|
1104
|
-
return this.evict(this.keys()), Promise.resolve();
|
|
1105
|
-
}
|
|
1106
|
-
close() {
|
|
1107
|
-
return Promise.resolve();
|
|
1108
|
-
}
|
|
1109
|
-
write(e, t) {
|
|
1110
|
-
return this.diagnostics.guard("storage.quota_exceeded", t, () => (localStorage.setItem(un(e), JSON.stringify(e)), !0)) === !0;
|
|
1111
|
-
}
|
|
1112
|
-
evictForQuota() {
|
|
1113
|
-
let e = this.keys(), t = {
|
|
1114
|
-
batches: 0,
|
|
1115
|
-
records: 0,
|
|
1116
|
-
reason: "quota"
|
|
1117
|
-
};
|
|
1118
|
-
for (let n of e.slice(0, Math.ceil(e.length / 4))) {
|
|
1119
|
-
let e = this.read(n);
|
|
1120
|
-
this.removeKey(n), t.batches++, t.records += e?.records.length ?? 0;
|
|
1121
|
-
}
|
|
1122
|
-
this.reportGap(t);
|
|
1123
|
-
}
|
|
1124
|
-
reportGap(e) {
|
|
1125
|
-
e.batches !== 0 && (this.diagnostics.report("storage.evicted", `dropped ${String(e.batches)} stored batches (${String(e.records)} records)`, { ...e }), this.onGap?.(e));
|
|
1126
|
-
}
|
|
1127
|
-
read(e) {
|
|
1128
|
-
let t = this.diagnostics.guard("storage.unavailable", "reading a stored batch", () => localStorage.getItem(e));
|
|
1129
|
-
if (!t) return null;
|
|
1130
|
-
let n = this.diagnostics.guard("storage.degraded", "a stored batch was corrupt and was removed", () => JSON.parse(t));
|
|
1131
|
-
return n === void 0 ? null : tn(n) ? n : (this.diagnostics.report("storage.degraded", "a stored entry was not a batch and was dropped"), null);
|
|
1132
|
-
}
|
|
1133
|
-
keyOf(e) {
|
|
1134
|
-
return this.keys().find((t) => t.endsWith(`.${e}`)) ?? null;
|
|
1135
|
-
}
|
|
1136
|
-
evict(e) {
|
|
1137
|
-
for (let t of e) this.removeKey(t);
|
|
1138
|
-
}
|
|
1139
|
-
removeKey(e) {
|
|
1140
|
-
this.diagnostics.guard("storage.degraded", "removing a stored batch", () => {
|
|
1141
|
-
localStorage.removeItem(e);
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
keys() {
|
|
1145
|
-
return z(T, this.diagnostics);
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
//#endregion
|
|
1149
|
-
//#region src/storage/memory-storage.ts
|
|
1150
|
-
function pn(e) {
|
|
1151
|
-
return e.reduce((e, t) => e + t.records.length, 0);
|
|
1152
|
-
}
|
|
1153
|
-
var B = class {
|
|
1154
|
-
limits;
|
|
1155
|
-
onGap;
|
|
1156
|
-
name = xe;
|
|
1157
|
-
batches = [];
|
|
1158
|
-
constructor(e, t) {
|
|
1159
|
-
this.limits = e, this.onGap = t;
|
|
1160
|
-
}
|
|
1161
|
-
async save(e) {
|
|
1162
|
-
this.batches.push(e), await this.prune();
|
|
1163
|
-
}
|
|
1164
|
-
take(e) {
|
|
1165
|
-
return Promise.resolve(this.batches.slice(0, e));
|
|
1166
|
-
}
|
|
1167
|
-
remove(e) {
|
|
1168
|
-
return this.batches = this.batches.filter((t) => t.id !== e), Promise.resolve();
|
|
1169
|
-
}
|
|
1170
|
-
bumpAttempts(e, t) {
|
|
1171
|
-
let n = this.batches.find((t) => t.id === e);
|
|
1172
|
-
return n && (n.attempts = t), Promise.resolve();
|
|
1173
|
-
}
|
|
1174
|
-
prune() {
|
|
1175
|
-
let e = Date.now() - this.limits.maxAgeMs, t = {
|
|
1176
|
-
batches: 0,
|
|
1177
|
-
records: 0,
|
|
1178
|
-
reason: "expired"
|
|
1179
|
-
}, n = this.batches.filter((t) => t.createdAt < e);
|
|
1180
|
-
this.batches = this.batches.filter((t) => t.createdAt >= e), t.batches += n.length, t.records += pn(n);
|
|
1181
|
-
let r = this.batches.length - this.limits.maxBatches;
|
|
1182
|
-
if (r > 0) {
|
|
1183
|
-
t.reason = "over_capacity";
|
|
1184
|
-
let e = this.batches.slice(0, r);
|
|
1185
|
-
this.batches = this.batches.slice(r), t.batches += e.length, t.records += pn(e);
|
|
1186
|
-
}
|
|
1187
|
-
return t.batches > 0 && this.onGap?.(t), Promise.resolve(t);
|
|
1188
|
-
}
|
|
1189
|
-
count() {
|
|
1190
|
-
return Promise.resolve(this.batches.length);
|
|
1191
|
-
}
|
|
1192
|
-
clear() {
|
|
1193
|
-
return this.batches = [], Promise.resolve();
|
|
1194
|
-
}
|
|
1195
|
-
close() {
|
|
1196
|
-
return this.batches = [], Promise.resolve();
|
|
1197
|
-
}
|
|
1198
|
-
}, mn = {
|
|
1199
|
-
name: de,
|
|
1200
|
-
save: () => Promise.resolve(),
|
|
1201
|
-
take: () => Promise.resolve([]),
|
|
1202
|
-
remove: () => Promise.resolve(),
|
|
1203
|
-
bumpAttempts: () => Promise.resolve(),
|
|
1204
|
-
prune: () => Promise.resolve({
|
|
1205
|
-
batches: 0,
|
|
1206
|
-
records: 0,
|
|
1207
|
-
reason: "expired"
|
|
1208
|
-
}),
|
|
1209
|
-
count: () => Promise.resolve(0),
|
|
1210
|
-
clear: () => Promise.resolve(),
|
|
1211
|
-
close: () => Promise.resolve()
|
|
1212
|
-
};
|
|
1213
|
-
function hn(e) {
|
|
1214
|
-
return e.guard("storage.unavailable", "reading indexedDB", () => globalThis.indexedDB != null) === !0;
|
|
1215
|
-
}
|
|
1216
|
-
function gn(t) {
|
|
1217
|
-
return t.guard("storage.unavailable", "probing localStorage", () => (localStorage.setItem(e, "1"), localStorage.removeItem(e), !0)) === !0;
|
|
1218
|
-
}
|
|
1219
|
-
async function _n(e, t, n, r, i) {
|
|
1220
|
-
if (e === "none") return mn;
|
|
1221
|
-
if (e === "memory") return new B(n, i);
|
|
1222
|
-
if (e === "indexeddb" || e === "auto") {
|
|
1223
|
-
if (hn(r)) {
|
|
1224
|
-
let e = await r.guardAsync("storage.unavailable", "opening IndexedDB", async () => {
|
|
1225
|
-
let { IndexedDbStorage: e } = await import("./indexeddb-storage-B6uqejZb.js"), a = new e(t, n, r, i);
|
|
1226
|
-
return await a.open(), a;
|
|
1227
|
-
});
|
|
1228
|
-
if (e) return e;
|
|
1229
|
-
}
|
|
1230
|
-
if (e === "indexeddb") return r.report("storage.degraded", "IndexedDB was asked for by name and is unavailable, using memory"), new B(n, i);
|
|
1231
|
-
}
|
|
1232
|
-
return gn(r) ? new fn(n, r, i) : (r.report("storage.degraded", "no persistent storage available, offline logs are memory only"), new B(n, i));
|
|
1233
|
-
}
|
|
1234
|
-
//#endregion
|
|
1235
|
-
//#region src/utils/sanitize.ts
|
|
1236
|
-
function V(e, t) {
|
|
1237
|
-
if (e.length <= t) return e;
|
|
1238
|
-
let n = vn(e.charCodeAt(t - 1)) ? t - 1 : t;
|
|
1239
|
-
return `${e.slice(0, n)}… [truncated ${String(e.length - n)} chars]`;
|
|
1240
|
-
}
|
|
1241
|
-
function vn(e) {
|
|
1242
|
-
return e >= 55296 && e <= 56319;
|
|
1243
|
-
}
|
|
1244
|
-
function yn(e) {
|
|
1245
|
-
return `[Element ${(e.nodeName ?? "NODE").toLowerCase()}${e.id ? `#${e.id}` : ""}${typeof e.className == "string" && e.className ? `.${e.className.trim().split(/\s+/).slice(0, 3).join(".")}` : ""}]`;
|
|
1246
|
-
}
|
|
1247
|
-
function H(e, t) {
|
|
1248
|
-
let n = {
|
|
1249
|
-
bytes: 0,
|
|
1250
|
-
nodes: 0
|
|
1251
|
-
};
|
|
1252
|
-
return {
|
|
1253
|
-
value: W(e, t, /* @__PURE__ */ new WeakSet(), 0, n),
|
|
1254
|
-
bytes: n.bytes
|
|
1255
|
-
};
|
|
1256
|
-
}
|
|
1257
|
-
function U(e, t) {
|
|
1258
|
-
return t.bytes += G(e) + 2, e;
|
|
1259
|
-
}
|
|
1260
|
-
function W(e, t, n, r, i) {
|
|
1261
|
-
if (i.nodes++, i.nodes > t.maxNodes) return U("[MaxNodes]", i);
|
|
1262
|
-
if (e == null) return i.bytes += 4, e;
|
|
1263
|
-
if (typeof e == "string") return U(V(e, t.maxAttributeChars), i);
|
|
1264
|
-
if (typeof e == "number") return i.bytes += 8, Number.isFinite(e) ? e : String(e);
|
|
1265
|
-
if (typeof e == "boolean") return i.bytes += 5, e;
|
|
1266
|
-
if (typeof e == "bigint") return U(`${e.toString()}n`, i);
|
|
1267
|
-
if (typeof e == "symbol") return U(e.toString(), i);
|
|
1268
|
-
if (typeof e == "function") return U(`[Function ${e.name === "" ? "anonymous" : e.name}]`, i);
|
|
1269
|
-
if (r >= t.maxDepth) return U("[MaxDepth]", i);
|
|
1270
|
-
if (n.has(e)) return U("[Circular]", i);
|
|
1271
|
-
n.add(e), i.bytes += 2;
|
|
1272
|
-
try {
|
|
1273
|
-
if (e instanceof Error) return {
|
|
1274
|
-
name: U(e.name, i),
|
|
1275
|
-
message: U(V(e.message, t.maxAttributeChars), i),
|
|
1276
|
-
stack: e.stack ? U(V(e.stack, t.maxStackChars), i) : void 0,
|
|
1277
|
-
cause: e.cause ? W(e.cause, t, n, r + 1, i) : void 0
|
|
1278
|
-
};
|
|
1279
|
-
if (e instanceof Date) return U(e.toISOString(), i);
|
|
1280
|
-
if (e instanceof RegExp) return U(e.toString(), i);
|
|
1281
|
-
if (e instanceof Map) {
|
|
1282
|
-
let a = e, o = {}, s = 0;
|
|
1283
|
-
for (let [e, c] of a) {
|
|
1284
|
-
if (s >= t.maxArrayLength) {
|
|
1285
|
-
o["…"] = U(`[${String(a.size - t.maxArrayLength)} more entries]`, i);
|
|
1286
|
-
break;
|
|
1287
|
-
}
|
|
1288
|
-
s++;
|
|
1289
|
-
let l = String(e);
|
|
1290
|
-
i.bytes += G(l) + 4, o[l] = W(c, t, n, r + 1, i);
|
|
1291
|
-
}
|
|
1292
|
-
return o;
|
|
1293
|
-
}
|
|
1294
|
-
if (e instanceof Set) return W([...e].slice(0, t.maxArrayLength), t, n, r, i);
|
|
1295
|
-
if (ArrayBuffer.isView(e)) {
|
|
1296
|
-
let t = e.length ?? 0;
|
|
1297
|
-
return U(`[${e.constructor.name}(${String(t)})]`, i);
|
|
1298
|
-
}
|
|
1299
|
-
if (e instanceof Promise) return U("[Promise]", i);
|
|
1300
|
-
if (typeof Node < "u" && e instanceof Node) return U(yn(e), i);
|
|
1301
|
-
if (Array.isArray(e)) {
|
|
1302
|
-
let a = e, o = a.slice(0, t.maxArrayLength).map((e) => W(e, t, n, r + 1, i));
|
|
1303
|
-
return a.length > t.maxArrayLength && o.push(U(`[${String(a.length - t.maxArrayLength)} more items]`, i)), o;
|
|
1304
|
-
}
|
|
1305
|
-
let a = e.toJSON;
|
|
1306
|
-
if (typeof a == "function") return W(a.call(e), t, n, r + 1, i);
|
|
1307
|
-
let o = e, s = Object.keys(o), c = {}, l = 0;
|
|
1308
|
-
for (let e of s) {
|
|
1309
|
-
if (l >= t.maxAttributeCount) {
|
|
1310
|
-
c["…"] = U(`[${String(s.length - l)} more keys]`, i);
|
|
1311
|
-
break;
|
|
1312
|
-
}
|
|
1313
|
-
l++, i.bytes += G(e) + 4, c[e] = W(o[e], t, n, r + 1, i);
|
|
1314
|
-
}
|
|
1315
|
-
return c;
|
|
1316
|
-
} catch (e) {
|
|
1317
|
-
return U(`[Unserializable: ${e instanceof Error ? e.name : "error"}]`, i);
|
|
1318
|
-
} finally {
|
|
1319
|
-
n.delete(e);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
function G(e) {
|
|
1323
|
-
let t = 0;
|
|
1324
|
-
for (let n = 0; n < e.length; n++) {
|
|
1325
|
-
let r = e.charCodeAt(n);
|
|
1326
|
-
r < 128 ? t += 1 : r < 2048 ? t += 2 : r >= 55296 && r <= 56319 ? (t += 4, n++) : t += 3;
|
|
1327
|
-
}
|
|
1328
|
-
return t;
|
|
1329
|
-
}
|
|
1330
|
-
//#endregion
|
|
1331
|
-
//#region src/transport/exit-flush.ts
|
|
1332
|
-
var bn = class {
|
|
1333
|
-
deps;
|
|
1334
|
-
installed = !1;
|
|
1335
|
-
onVisibility = () => {
|
|
1336
|
-
document.visibilityState === "hidden" && this.flush("hidden");
|
|
68
|
+
debug = (e, t) => {
|
|
69
|
+
this.write("DEBUG", "system", e, t);
|
|
70
|
+
};
|
|
71
|
+
info = (e, t) => {
|
|
72
|
+
this.write("INFO", "system", e, t);
|
|
1337
73
|
};
|
|
1338
|
-
|
|
1339
|
-
this.
|
|
74
|
+
warn = (e, t) => {
|
|
75
|
+
this.write("WARN", "system", e, t);
|
|
1340
76
|
};
|
|
1341
|
-
|
|
1342
|
-
this.
|
|
77
|
+
error = (e, t, n) => {
|
|
78
|
+
this.writeError("ERROR", e, t, n);
|
|
1343
79
|
};
|
|
1344
|
-
|
|
1345
|
-
this.
|
|
80
|
+
fatal = (e, t, n) => {
|
|
81
|
+
this.writeError("FATAL", e, t, n);
|
|
1346
82
|
};
|
|
1347
|
-
|
|
1348
|
-
this.
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
this.
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
this.installed = !1, typeof document < "u" && (document.removeEventListener("visibilitychange", this.onVisibility), document.removeEventListener("freeze", this.onFreeze)), removeEventListener("pagehide", this.onPageHide);
|
|
1361
|
-
let e = globalThis.fin?.me;
|
|
1362
|
-
this.deps.diagnostics.guard("openfin.unavailable", "releasing close-requested", () => {
|
|
1363
|
-
e?.removeListener?.("close-requested", this.onOpenFinClose);
|
|
83
|
+
logAction = (e, t) => {
|
|
84
|
+
this.write("INFO", "action", e, t);
|
|
85
|
+
};
|
|
86
|
+
logEvent = (e, t) => {
|
|
87
|
+
this.write("INFO", "event", e, t);
|
|
88
|
+
};
|
|
89
|
+
logMetric = (e, t, n = l, r = "gauge", i) => {
|
|
90
|
+
this.write("INFO", "metric", e, {
|
|
91
|
+
"metric.name": e,
|
|
92
|
+
"metric.value": t,
|
|
93
|
+
"metric.unit": n,
|
|
94
|
+
"metric.type": r,
|
|
95
|
+
...i
|
|
1364
96
|
});
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
let
|
|
1370
|
-
if (
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
if (G(i.body) > 6e4) {
|
|
1374
|
-
cn(r, t);
|
|
97
|
+
};
|
|
98
|
+
timeSync = (e, t, n) => Ve(this, e, t, n);
|
|
99
|
+
timeAsync = (e, t, n) => He(this, e, t, n);
|
|
100
|
+
write(e, t, n, r) {
|
|
101
|
+
let i = this.bind();
|
|
102
|
+
if (i.isDestroyed()) return;
|
|
103
|
+
if (!i.builder.isEnabled(e)) {
|
|
104
|
+
this.mirrors(i, e) && this.print(i, e, n, r, void 0, null);
|
|
1375
105
|
return;
|
|
1376
106
|
}
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
this.keepaliveFetch(a, i.body, e);
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
drain(e) {
|
|
1388
|
-
return e === "hidden" ? this.deps.drainPending() : this.deps.drainForExit();
|
|
1389
|
-
}
|
|
1390
|
-
endpointUrl() {
|
|
1391
|
-
let { endpoint: e } = this.deps.config;
|
|
1392
|
-
return e ? this.deps.diagnostics.guard("config.invalid", `the exit flush cannot use endpoint ${e}`, () => new URL(e)) ?? null : null;
|
|
1393
|
-
}
|
|
1394
|
-
beacon(e, t) {
|
|
1395
|
-
return this.deps.diagnostics.guard("transport.http_error", "sendBeacon", () => {
|
|
1396
|
-
let n = globalThis.navigator;
|
|
1397
|
-
return n?.sendBeacon ? n.sendBeacon(e, new Blob([t], { type: "text/plain;charset=UTF-8" })) ? "sent" : "refused" : "unavailable";
|
|
1398
|
-
}) ?? "unavailable";
|
|
1399
|
-
}
|
|
1400
|
-
keepaliveFetch(e, n, r) {
|
|
1401
|
-
let { config: i, diagnostics: a } = this.deps;
|
|
1402
|
-
a.guard("transport.http_error", "the keepalive fetch fallback", () => {
|
|
1403
|
-
fetch(e, {
|
|
1404
|
-
method: "POST",
|
|
1405
|
-
body: n,
|
|
1406
|
-
headers: { [ee]: t },
|
|
1407
|
-
credentials: i.credentials,
|
|
1408
|
-
keepalive: !0
|
|
1409
|
-
}).catch((e) => {
|
|
1410
|
-
a.report("transport.http_error", "the exit flush failed", { reason: r }, e);
|
|
1411
|
-
});
|
|
107
|
+
let { record: a, dropped: o } = i.builder.build({
|
|
108
|
+
level: e,
|
|
109
|
+
type: t,
|
|
110
|
+
body: n,
|
|
111
|
+
namespace: this.namespace,
|
|
112
|
+
scoped: this.options.scopedContext,
|
|
113
|
+
payload: r
|
|
1412
114
|
});
|
|
115
|
+
t !== "metric" && o !== "redact" && i.breadcrumbs.push({
|
|
116
|
+
t: Date.now(),
|
|
117
|
+
category: t === "action" ? "action" : t === "event" ? "event" : "log",
|
|
118
|
+
message: n
|
|
119
|
+
}), this.print(i, e, n, r, void 0, a), i.emit(a);
|
|
1413
120
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
}
|
|
1423
|
-
//#endregion
|
|
1424
|
-
//#region src/transport/errors.ts
|
|
1425
|
-
var K = class extends Error {
|
|
1426
|
-
kind;
|
|
1427
|
-
status;
|
|
1428
|
-
retryAfterMs;
|
|
1429
|
-
maxBytes;
|
|
1430
|
-
constructor(e, t, n, r, i) {
|
|
1431
|
-
super(t), this.kind = e, this.status = n, this.retryAfterMs = r, this.maxBytes = i, this.name = "TransportError";
|
|
1432
|
-
}
|
|
1433
|
-
};
|
|
1434
|
-
function Sn(e) {
|
|
1435
|
-
if (!e) return;
|
|
1436
|
-
let t = Number(e);
|
|
1437
|
-
if (Number.isFinite(t)) return Math.max(0, t * ht);
|
|
1438
|
-
let n = Date.parse(e);
|
|
1439
|
-
return Number.isNaN(n) ? void 0 : Math.max(0, n - Date.now());
|
|
1440
|
-
}
|
|
1441
|
-
//#endregion
|
|
1442
|
-
//#region src/transport/http-transport.ts
|
|
1443
|
-
var Cn = class {
|
|
1444
|
-
config;
|
|
1445
|
-
diagnostics;
|
|
1446
|
-
throttledUntil = 0;
|
|
1447
|
-
constructor(e, t) {
|
|
1448
|
-
this.config = e, this.diagnostics = t;
|
|
1449
|
-
}
|
|
1450
|
-
async send(e) {
|
|
1451
|
-
!this.config.endpoint || e.records.length === 0 || await this.post(e);
|
|
1452
|
-
}
|
|
1453
|
-
throttledForMs() {
|
|
1454
|
-
return Math.max(0, this.throttledUntil - Date.now());
|
|
1455
|
-
}
|
|
1456
|
-
async post(e) {
|
|
1457
|
-
let { config: t } = this, n;
|
|
1458
|
-
try {
|
|
1459
|
-
n = t.serializer.serialize(e.records);
|
|
1460
|
-
} catch (t) {
|
|
1461
|
-
this.diagnostics.report("transport.serialize_failed", "serializer threw, dropping the batch", { batchId: e.id }, t);
|
|
1462
|
-
return;
|
|
1463
|
-
}
|
|
1464
|
-
let r = new Headers(await this.resolveHeaders());
|
|
1465
|
-
r.set(ee, n.contentType), r.set(ne, e.id), r.set(f, String(e.attempts));
|
|
1466
|
-
let i = await this.encodeBody(n.body);
|
|
1467
|
-
typeof i != "string" && r.set(rt, bt);
|
|
1468
|
-
let a = await this.dispatch(r, i);
|
|
1469
|
-
if (a.ok) {
|
|
1470
|
-
this.throttledUntil = 0;
|
|
121
|
+
writeError(e, t, n, r) {
|
|
122
|
+
let i = this.bind();
|
|
123
|
+
if (i.isDestroyed()) return;
|
|
124
|
+
let a = i.builder.isEnabled(e);
|
|
125
|
+
if (!a && !this.mirrors(i, e)) return;
|
|
126
|
+
let o = r === void 0 && We(n), s = o ? n : r, c = o || n === void 0 ? void 0 : Ue(n, i.diagnostics);
|
|
127
|
+
if (!a) {
|
|
128
|
+
this.print(i, e, t, s, c, null);
|
|
1471
129
|
return;
|
|
1472
130
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
headers: e,
|
|
1488
|
-
body: t,
|
|
1489
|
-
credentials: n.credentials,
|
|
1490
|
-
signal: r.signal,
|
|
1491
|
-
cache: "no-store"
|
|
1492
|
-
});
|
|
1493
|
-
} catch {
|
|
1494
|
-
if (r.signal.aborted) throw new K("timeout", `request exceeded ${String(yt)}ms`);
|
|
1495
|
-
let e = globalThis.navigator?.onLine;
|
|
1496
|
-
throw new K(e === !1 ? "offline" : "transient", "network error");
|
|
1497
|
-
} finally {
|
|
1498
|
-
clearTimeout(i);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
async classify(e, t) {
|
|
1502
|
-
let n = e.status, r = Sn(e.headers.get(be));
|
|
1503
|
-
if (n === 401 || n === 403) return this.diagnostics.report("transport.rejected_credentials", `server returned ${String(n)}. In a cross-origin iframe the session cookie is a third-party cookie and is very likely blocked. Forward to the platform document instead of promoting to sender, or issue the cookie with the Partitioned attribute.`, {
|
|
1504
|
-
status: n,
|
|
1505
|
-
endpoint: this.config.endpoint
|
|
1506
|
-
}), new K("permanent", `rejected with ${String(n)}`, n);
|
|
1507
|
-
if (n === 413) return new K("too_large", "payload too large", n, void 0, await this.readMaxBytes(e));
|
|
1508
|
-
if (n === 429 || n === 503) {
|
|
1509
|
-
let e = n === 429;
|
|
1510
|
-
return this.throttledUntil = Date.now() + (r ?? 2e3), e && this.diagnostics.report("transport.throttled", "server throttled us", { retryAfterMs: r }), new K("throttled", e ? "throttled" : "service unavailable", n, r);
|
|
1511
|
-
}
|
|
1512
|
-
return n === 408 || n >= 500 ? new K("transient", `server error ${String(n)}`, n) : (this.diagnostics.report("transport.dropped_permanent", `server rejected the batch with ${String(n)}, dropping it`, {
|
|
1513
|
-
batchId: t,
|
|
1514
|
-
status: n
|
|
1515
|
-
}), new K("permanent", `rejected with ${String(n)}`, n));
|
|
1516
|
-
}
|
|
1517
|
-
async readMaxBytes(e) {
|
|
1518
|
-
return this.diagnostics.guardAsync("transport.http_error", "reading the 413 body", async () => {
|
|
1519
|
-
let t = JSON.parse(await e.text());
|
|
1520
|
-
return typeof t.maxBytes == "number" ? t.maxBytes : void 0;
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
async resolveHeaders() {
|
|
1524
|
-
let { headers: e } = this.config;
|
|
1525
|
-
return e ? typeof e == "function" ? await this.diagnostics.guardAsync("transport.http_error", "headers() threw", () => Promise.resolve(e())) ?? {} : e : {};
|
|
1526
|
-
}
|
|
1527
|
-
}, wn = class {
|
|
1528
|
-
storage;
|
|
1529
|
-
transport;
|
|
1530
|
-
diagnostics;
|
|
1531
|
-
config;
|
|
1532
|
-
batchesPerDrain;
|
|
1533
|
-
timer = null;
|
|
1534
|
-
attempt = 0;
|
|
1535
|
-
draining = !1;
|
|
1536
|
-
stopped = !1;
|
|
1537
|
-
onOnline = () => {
|
|
1538
|
-
this.attempt = 0, this.schedule(0);
|
|
1539
|
-
};
|
|
1540
|
-
constructor(e, t, n, r, i = 20) {
|
|
1541
|
-
this.storage = e, this.transport = t, this.diagnostics = n, this.config = r, this.batchesPerDrain = i;
|
|
1542
|
-
}
|
|
1543
|
-
start() {
|
|
1544
|
-
this.stopped = !1, typeof addEventListener < "u" && addEventListener("online", this.onOnline), this.schedule(_);
|
|
1545
|
-
}
|
|
1546
|
-
nudge() {
|
|
1547
|
-
this.draining || this.schedule(d);
|
|
1548
|
-
}
|
|
1549
|
-
async storeFailed(e, t) {
|
|
1550
|
-
let n = this.toStorable(e, t);
|
|
1551
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
1552
|
-
n.length > 0 && this.nudge();
|
|
1553
|
-
}
|
|
1554
|
-
stop() {
|
|
1555
|
-
this.stopped = !0, typeof removeEventListener < "u" && removeEventListener("online", this.onOnline), this.clearTimer();
|
|
1556
|
-
}
|
|
1557
|
-
schedule(e) {
|
|
1558
|
-
if (this.stopped) return;
|
|
1559
|
-
this.clearTimer();
|
|
1560
|
-
let t = setTimeout(() => {
|
|
1561
|
-
this.drain();
|
|
1562
|
-
}, e);
|
|
1563
|
-
this.timer = t, D(t);
|
|
1564
|
-
}
|
|
1565
|
-
bounded(e) {
|
|
1566
|
-
return R(e, v);
|
|
1567
|
-
}
|
|
1568
|
-
clearTimer() {
|
|
1569
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
1570
|
-
}
|
|
1571
|
-
backoffMs() {
|
|
1572
|
-
let e = Math.min(d * 2 ** this.attempt, re);
|
|
1573
|
-
return Math.random() * e;
|
|
1574
|
-
}
|
|
1575
|
-
async drain() {
|
|
1576
|
-
if (!this.draining) {
|
|
1577
|
-
this.draining = !0;
|
|
1578
|
-
try {
|
|
1579
|
-
await rn("ui-observability.drain", this.diagnostics, () => this.drainLocked()) !== !0 && this.schedule(_);
|
|
1580
|
-
} finally {
|
|
1581
|
-
this.draining = !1;
|
|
131
|
+
let { record: l } = i.builder.build({
|
|
132
|
+
level: e,
|
|
133
|
+
type: "system",
|
|
134
|
+
body: t,
|
|
135
|
+
namespace: this.namespace,
|
|
136
|
+
scoped: this.options.scopedContext,
|
|
137
|
+
payload: {
|
|
138
|
+
...s,
|
|
139
|
+
...c ? {
|
|
140
|
+
"error.type": c.name,
|
|
141
|
+
"error.message": c.message,
|
|
142
|
+
"error.stack_trace": c.stack
|
|
143
|
+
} : {},
|
|
144
|
+
breadcrumbs: i.breadcrumbs.snapshot()
|
|
1582
145
|
}
|
|
1583
|
-
}
|
|
146
|
+
});
|
|
147
|
+
this.print(i, e, t, s, c, l), i.emit(l);
|
|
1584
148
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
if (globalThis.navigator?.onLine === !1) return this.schedule(_), !0;
|
|
1588
|
-
let e = await this.bounded(this.storage.take(this.batchesPerDrain));
|
|
1589
|
-
if (e.length === 0) return this.schedule(_), !0;
|
|
1590
|
-
for (let t of e) if (this.stopped || !await this.deliver(t)) return !0;
|
|
1591
|
-
return this.schedule(e.length === this.batchesPerDrain ? 0 : _), !0;
|
|
1592
|
-
} catch (e) {
|
|
1593
|
-
return this.diagnostics.report("storage.degraded", "the drain loop threw", void 0, e), this.attempt++, this.schedule(this.backoffMs()), !0;
|
|
1594
|
-
}
|
|
149
|
+
print(e, t, n, r, i, a) {
|
|
150
|
+
e.config.redact ? a ? e.console.write(this.namespace, t, a.body, a.attributes) : e.console.write(this.namespace, t, n, void 0, i) : e.console.write(this.namespace, t, n, r, i);
|
|
1595
151
|
}
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
batchId: e.id,
|
|
1599
|
-
records: e.records.length
|
|
1600
|
-
}), await this.bounded(this.storage.remove(e.id)), !0;
|
|
1601
|
-
try {
|
|
1602
|
-
return await this.transport.send(e), await this.bounded(this.storage.remove(e.id)), this.attempt = 0, !0;
|
|
1603
|
-
} catch (t) {
|
|
1604
|
-
let n = t instanceof K ? t : void 0;
|
|
1605
|
-
return n?.kind === "permanent" || n?.kind === "too_large" ? (await this.replaceStored(e, t), !0) : n?.kind === "offline" ? (this.schedule(_), !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);
|
|
1606
|
-
}
|
|
152
|
+
mirrors(e, t) {
|
|
153
|
+
return e.config.enabled && e.console.accepts(t);
|
|
1607
154
|
}
|
|
1608
|
-
|
|
1609
|
-
let n = this.toStorable(e, t);
|
|
1610
|
-
await this.bounded(this.storage.remove(e.id));
|
|
1611
|
-
for (let e of n) await this.bounded(this.storage.save(e));
|
|
1612
|
-
}
|
|
1613
|
-
toStorable(e, t) {
|
|
1614
|
-
let n = t instanceof K ? t : void 0;
|
|
1615
|
-
if (n?.kind === "permanent") return [];
|
|
1616
|
-
if (n?.kind !== "too_large") return [e];
|
|
1617
|
-
let r = nn(e);
|
|
1618
|
-
return r ? (this.diagnostics.report("transport.batch_split", "the server refused the batch as too large", {
|
|
1619
|
-
from: e.records.length,
|
|
1620
|
-
to: r[0].records.length,
|
|
1621
|
-
serverMaxBytes: n.maxBytes
|
|
1622
|
-
}), r) : (this.diagnostics.report("transport.dropped_permanent", "a single record exceeds the server limit and was dropped", {
|
|
1623
|
-
batchId: e.id,
|
|
1624
|
-
bodies: e.records.map((e) => e.body)
|
|
1625
|
-
}), []);
|
|
1626
|
-
}
|
|
1627
|
-
}, Tn = {
|
|
155
|
+
}, Ge = {
|
|
1628
156
|
TRACE: "debug",
|
|
1629
157
|
DEBUG: "debug",
|
|
1630
158
|
INFO: "info",
|
|
1631
159
|
WARN: "warn",
|
|
1632
160
|
ERROR: "error",
|
|
1633
161
|
FATAL: "error"
|
|
1634
|
-
},
|
|
162
|
+
}, Ke = class {
|
|
1635
163
|
minLevel;
|
|
1636
164
|
diagnostics;
|
|
1637
165
|
constructor(e, t) {
|
|
@@ -1640,18 +168,18 @@ var Cn = class {
|
|
|
1640
168
|
update(e) {
|
|
1641
169
|
this.minLevel = e;
|
|
1642
170
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
console[
|
|
171
|
+
accepts(e) {
|
|
172
|
+
return this.minLevel !== null && S[e] >= S[this.minLevel];
|
|
173
|
+
}
|
|
174
|
+
write(e, t, n, i, a) {
|
|
175
|
+
if (!this.accepts(t) || typeof console > "u") return;
|
|
176
|
+
let o = `%c[%s]%c ${t}`, s = Ge[t];
|
|
177
|
+
this.diagnostics.guard("handler.threw", `The library could not print to console.${s}.`, () => {
|
|
178
|
+
let t = [];
|
|
179
|
+
a !== void 0 && t.push(a), i !== void 0 && t.push(Pe(i, b, this.diagnostics)), console[s](o, r, e, "", n, ...t);
|
|
1652
180
|
});
|
|
1653
181
|
}
|
|
1654
|
-
},
|
|
182
|
+
}, qe = class {
|
|
1655
183
|
value = 0;
|
|
1656
184
|
next() {
|
|
1657
185
|
return ++this.value;
|
|
@@ -1659,64 +187,58 @@ var Cn = class {
|
|
|
1659
187
|
reset() {
|
|
1660
188
|
this.value = 0;
|
|
1661
189
|
}
|
|
1662
|
-
},
|
|
1663
|
-
function
|
|
1664
|
-
return
|
|
1665
|
-
/* @vite-ignore */
|
|
1666
|
-
"@opentelemetry/api"
|
|
1667
|
-
);
|
|
1668
|
-
}
|
|
1669
|
-
function Mn(e) {
|
|
1670
|
-
return On.test(e.traceId) && An.test(e.traceId) && kn.test(e.spanId) && An.test(e.spanId);
|
|
190
|
+
}, Je = /^[0-9a-f]{32}$/, Ye = /^[0-9a-f]{16}$/, z = /[1-9a-f]/;
|
|
191
|
+
function Xe(e) {
|
|
192
|
+
return Je.test(e.traceId) && z.test(e.traceId) && Ye.test(e.spanId) && z.test(e.spanId);
|
|
1671
193
|
}
|
|
1672
|
-
function
|
|
1673
|
-
return
|
|
194
|
+
function Ze() {
|
|
195
|
+
return P(16);
|
|
1674
196
|
}
|
|
1675
|
-
function
|
|
1676
|
-
return
|
|
197
|
+
function Qe() {
|
|
198
|
+
return P(8);
|
|
1677
199
|
}
|
|
1678
|
-
function
|
|
200
|
+
function B() {
|
|
1679
201
|
return {
|
|
1680
|
-
traceId:
|
|
1681
|
-
spanId:
|
|
202
|
+
traceId: Ze(),
|
|
203
|
+
spanId: Qe(),
|
|
1682
204
|
traceFlags: 1,
|
|
1683
205
|
startedAt: Date.now()
|
|
1684
206
|
};
|
|
1685
207
|
}
|
|
1686
|
-
function
|
|
208
|
+
function V(e) {
|
|
1687
209
|
return {
|
|
1688
210
|
traceId: e.traceId,
|
|
1689
211
|
spanId: e.spanId,
|
|
1690
212
|
traceFlags: e.traceFlags
|
|
1691
213
|
};
|
|
1692
214
|
}
|
|
1693
|
-
var
|
|
215
|
+
var $e = class {
|
|
1694
216
|
diagnostics;
|
|
1695
217
|
maxAgeMs;
|
|
1696
218
|
load;
|
|
1697
|
-
ambient =
|
|
219
|
+
ambient = B();
|
|
1698
220
|
otel;
|
|
1699
|
-
constructor(e, t =
|
|
221
|
+
constructor(e, t = ve, n) {
|
|
1700
222
|
this.diagnostics = e, this.maxAgeMs = t, this.load = n;
|
|
1701
223
|
}
|
|
1702
224
|
async loadOtel() {
|
|
1703
|
-
try {
|
|
225
|
+
if (this.load) try {
|
|
1704
226
|
this.otel = await this.load();
|
|
1705
227
|
} catch (e) {
|
|
1706
|
-
this.diagnostics.report("trace.otel_failed", "@opentelemetry/api
|
|
228
|
+
this.diagnostics.report("trace.otel_failed", "The library could not load @opentelemetry/api. Records use the trace ids of the library.", void 0, e);
|
|
1707
229
|
}
|
|
1708
230
|
}
|
|
1709
231
|
resolve() {
|
|
1710
232
|
let e = this.activeSpanContext();
|
|
1711
|
-
return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"),
|
|
233
|
+
return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), V(this.ambient)) : e;
|
|
1712
234
|
}
|
|
1713
235
|
activeSpanContext() {
|
|
1714
236
|
let e = this.otel;
|
|
1715
|
-
if (e) return this.diagnostics.guard("trace.otel_failed", "
|
|
237
|
+
if (e) return this.diagnostics.guard("trace.otel_failed", "The library could not read the active OpenTelemetry span.", () => {
|
|
1716
238
|
let t = e.trace.getActiveSpan();
|
|
1717
239
|
if (t === void 0) return;
|
|
1718
240
|
let n = t.spanContext();
|
|
1719
|
-
if (
|
|
241
|
+
if (Xe(n)) return {
|
|
1720
242
|
traceId: n.traceId,
|
|
1721
243
|
spanId: n.spanId,
|
|
1722
244
|
traceFlags: n.traceFlags
|
|
@@ -1724,19 +246,19 @@ var Ln = class {
|
|
|
1724
246
|
});
|
|
1725
247
|
}
|
|
1726
248
|
rotate(e) {
|
|
1727
|
-
return this.ambient =
|
|
249
|
+
return this.ambient = B(), V(this.ambient);
|
|
1728
250
|
}
|
|
1729
251
|
headers() {
|
|
1730
252
|
let e = {}, t = this.otel;
|
|
1731
|
-
if (t && this.diagnostics.guard("trace.otel_failed", "
|
|
253
|
+
if (t && this.diagnostics.guard("trace.otel_failed", "The library could not add the OpenTelemetry headers.", () => {
|
|
1732
254
|
t.propagation.inject(t.context.active(), e);
|
|
1733
255
|
}), !e.traceparent) {
|
|
1734
256
|
let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
|
|
1735
|
-
e[
|
|
257
|
+
e[re] = `00-${t.traceId}-${t.spanId}-${n}`;
|
|
1736
258
|
}
|
|
1737
259
|
return e;
|
|
1738
260
|
}
|
|
1739
|
-
},
|
|
261
|
+
}, et = class {
|
|
1740
262
|
buffer;
|
|
1741
263
|
pointer = 0;
|
|
1742
264
|
filled = !1;
|
|
@@ -1755,152 +277,23 @@ var Ln = class {
|
|
|
1755
277
|
}
|
|
1756
278
|
};
|
|
1757
279
|
//#endregion
|
|
1758
|
-
//#region src/transport/serializers/ecs.ts
|
|
1759
|
-
function zn(e) {
|
|
1760
|
-
return Ie.test(e) ? Number(BigInt(e) / nt) : Date.now();
|
|
1761
|
-
}
|
|
1762
|
-
function Bn(e) {
|
|
1763
|
-
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? e : typeof e == "bigint" ? e.toString() : null;
|
|
1764
|
-
}
|
|
1765
|
-
function Vn(e, t, n) {
|
|
1766
|
-
let r = e[t];
|
|
1767
|
-
if (r === void 0) {
|
|
1768
|
-
e[t] = n;
|
|
1769
|
-
return;
|
|
1770
|
-
}
|
|
1771
|
-
if (Array.isArray(r)) {
|
|
1772
|
-
r.push(n);
|
|
1773
|
-
return;
|
|
1774
|
-
}
|
|
1775
|
-
e[t] = [r, n];
|
|
1776
|
-
}
|
|
1777
|
-
function Hn(e, t, n, r) {
|
|
1778
|
-
let i = Bn(n);
|
|
1779
|
-
if (i !== null) {
|
|
1780
|
-
Vn(e, t, i);
|
|
1781
|
-
return;
|
|
1782
|
-
}
|
|
1783
|
-
if (!(typeof n != "object" || !n || r.has(n))) {
|
|
1784
|
-
if (r.add(n), Array.isArray(n)) for (let i of n) Hn(e, t, i, r);
|
|
1785
|
-
else for (let [i, a] of Object.entries(n)) Hn(e, `${t}.${i}`, a, r);
|
|
1786
|
-
r.delete(n);
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
function Un(e) {
|
|
1790
|
-
let t = Object.create(null), n = /* @__PURE__ */ new WeakSet();
|
|
1791
|
-
for (let [r, i] of Object.entries(e)) Hn(t, r, i, n);
|
|
1792
|
-
return t;
|
|
1793
|
-
}
|
|
1794
|
-
var Wn = {
|
|
1795
|
-
name: "ecs",
|
|
1796
|
-
serialize(e) {
|
|
1797
|
-
return {
|
|
1798
|
-
body: `${e.map((e) => {
|
|
1799
|
-
let t = zn(e.timeUnixNano);
|
|
1800
|
-
return JSON.stringify({
|
|
1801
|
-
"@timestamp": new Date(t).toISOString(),
|
|
1802
|
-
message: e.body,
|
|
1803
|
-
log: { level: g[e.severityText] ?? e.severityText.toLowerCase() },
|
|
1804
|
-
trace: { id: e.traceId },
|
|
1805
|
-
span: { id: e.spanId },
|
|
1806
|
-
service: {
|
|
1807
|
-
name: e.resource[le],
|
|
1808
|
-
version: e.resource[Ke],
|
|
1809
|
-
environment: e.resource[_t]
|
|
1810
|
-
},
|
|
1811
|
-
user_agent: { original: e.resource[me] },
|
|
1812
|
-
url: { full: e.attributes["url.full"] ?? e.attributes["page.url"] },
|
|
1813
|
-
labels: {
|
|
1814
|
-
...Un(e.resource),
|
|
1815
|
-
...Un(e.attributes)
|
|
1816
|
-
}
|
|
1817
|
-
});
|
|
1818
|
-
}).join("\n")}\n`,
|
|
1819
|
-
contentType: Ge
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
|
-
};
|
|
1823
|
-
//#endregion
|
|
1824
|
-
//#region src/transport/serializers/otlp.ts
|
|
1825
|
-
function Gn(e) {
|
|
1826
|
-
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(Gn).filter((e) => e !== null) } } : typeof e == "object" ? { kvlistValue: { values: Kn(e) } } : null;
|
|
1827
|
-
}
|
|
1828
|
-
function Kn(e) {
|
|
1829
|
-
let t = [];
|
|
1830
|
-
for (let [n, r] of Object.entries(e)) {
|
|
1831
|
-
let e = Gn(r);
|
|
1832
|
-
e && t.push({
|
|
1833
|
-
key: n,
|
|
1834
|
-
value: e
|
|
1835
|
-
});
|
|
1836
|
-
}
|
|
1837
|
-
return t;
|
|
1838
|
-
}
|
|
1839
|
-
var qn = /* @__PURE__ */ new WeakMap();
|
|
1840
|
-
function Jn(e) {
|
|
1841
|
-
let t = qn.get(e);
|
|
1842
|
-
if (t !== void 0) return t;
|
|
1843
|
-
let n = JSON.stringify(e);
|
|
1844
|
-
return qn.set(e, n), n;
|
|
1845
|
-
}
|
|
1846
|
-
var Yn = {
|
|
1847
|
-
name: r,
|
|
1848
|
-
serialize(e) {
|
|
1849
|
-
let t = /* @__PURE__ */ new Map();
|
|
1850
|
-
for (let n of e) {
|
|
1851
|
-
let e = Jn(n.resource), r = t.get(e);
|
|
1852
|
-
if (r) {
|
|
1853
|
-
r.records.push(n);
|
|
1854
|
-
continue;
|
|
1855
|
-
}
|
|
1856
|
-
t.set(e, {
|
|
1857
|
-
resource: n.resource,
|
|
1858
|
-
records: [n]
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
let n = [...t.values()].map((e) => ({
|
|
1862
|
-
resource: { attributes: Kn(e.resource) },
|
|
1863
|
-
scopeLogs: [{
|
|
1864
|
-
scope: {
|
|
1865
|
-
name: Ze,
|
|
1866
|
-
version: ot
|
|
1867
|
-
},
|
|
1868
|
-
logRecords: e.records.map((e) => ({
|
|
1869
|
-
timeUnixNano: e.timeUnixNano,
|
|
1870
|
-
observedTimeUnixNano: e.observedTimeUnixNano ?? e.timeUnixNano,
|
|
1871
|
-
severityNumber: e.severityNumber,
|
|
1872
|
-
severityText: e.severityText,
|
|
1873
|
-
body: { stringValue: e.body },
|
|
1874
|
-
traceId: e.traceId,
|
|
1875
|
-
spanId: e.spanId,
|
|
1876
|
-
flags: e.traceFlags,
|
|
1877
|
-
attributes: Kn(e.attributes)
|
|
1878
|
-
}))
|
|
1879
|
-
}]
|
|
1880
|
-
}));
|
|
1881
|
-
return {
|
|
1882
|
-
body: JSON.stringify({ resourceLogs: n }),
|
|
1883
|
-
contentType: ce
|
|
1884
|
-
};
|
|
1885
|
-
}
|
|
1886
|
-
};
|
|
1887
|
-
//#endregion
|
|
1888
280
|
//#region src/core/config.ts
|
|
1889
|
-
function
|
|
281
|
+
function tt(e) {
|
|
1890
282
|
return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
|
|
1891
283
|
}
|
|
1892
|
-
function
|
|
1893
|
-
return e === void 0 ? t ??
|
|
284
|
+
function nt(e, t, n) {
|
|
285
|
+
return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || tt(e) ? e : (n.report("config.invalid", `serializer must be "${v}", "ecs" or an implementation. The library uses "${v}".`), v);
|
|
1894
286
|
}
|
|
1895
|
-
function
|
|
1896
|
-
return e === void 0 ? t : e === !1 ? null : e === !0 ?
|
|
287
|
+
function rt(e, t) {
|
|
288
|
+
return e === void 0 ? t : e === !1 ? null : e === !0 ? a : e;
|
|
1897
289
|
}
|
|
1898
|
-
function
|
|
1899
|
-
let r = n ??
|
|
290
|
+
function H(e, t, n) {
|
|
291
|
+
let r = n ?? C, i = {
|
|
1900
292
|
...r,
|
|
1901
293
|
...e,
|
|
1902
|
-
|
|
1903
|
-
|
|
294
|
+
endpoint: e.endpoint === void 0 ? r.endpoint : e.endpoint,
|
|
295
|
+
serializer: nt(e.serializer, n?.serializer, t),
|
|
296
|
+
console: rt(e.console, r.console),
|
|
1904
297
|
sampling: {
|
|
1905
298
|
...r.sampling,
|
|
1906
299
|
...e.sampling,
|
|
@@ -1918,36 +311,36 @@ function $n(e, t, n) {
|
|
|
1918
311
|
...e.capture
|
|
1919
312
|
}
|
|
1920
313
|
};
|
|
1921
|
-
if (
|
|
1922
|
-
else try {
|
|
314
|
+
if (i.endpoint === "") t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
|
|
315
|
+
else if (i.endpoint !== null) try {
|
|
1923
316
|
new URL(i.endpoint);
|
|
1924
317
|
} catch (e) {
|
|
1925
|
-
t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}
|
|
318
|
+
t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}.`, void 0, e);
|
|
1926
319
|
}
|
|
1927
|
-
i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record
|
|
320
|
+
i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${k}'.`), k);
|
|
1928
321
|
let a = i.sampling.defaultRate;
|
|
1929
|
-
(typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1
|
|
322
|
+
(typeof a != "number" || a < 0 || a > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1. The value is ${String(a)}. The library uses 1.`), i.sampling.defaultRate = 1);
|
|
1930
323
|
let o = Object.entries(i.sampling.rates);
|
|
1931
|
-
for (let [e, n] of o) (typeof n != "number" || n < 0 || n > 1) && (t.report("config.invalid", `sampling.rates["${e}"] must be 0..1
|
|
1932
|
-
return i.capture.ignoreUrls = i.capture.ignoreUrls.filter((e) => e !== n?.endpoint), i.endpoint && !i.capture.ignoreUrls.includes(i.endpoint) && (i.capture.ignoreUrls = [...i.capture.ignoreUrls, i.endpoint]),
|
|
324
|
+
for (let [e, n] of o) (typeof n != "number" || n < 0 || n > 1) && (t.report("config.invalid", `sampling.rates["${e}"] must be 0..1. The value is ${String(n)}. The library uses 1.`), i.sampling.rates[e] = 1);
|
|
325
|
+
return i.capture.ignoreUrls = i.capture.ignoreUrls.filter((e) => e !== n?.endpoint), i.endpoint && !i.capture.ignoreUrls.includes(i.endpoint) && (i.capture.ignoreUrls = [...i.capture.ignoreUrls, i.endpoint]), it(e, t), i;
|
|
1933
326
|
}
|
|
1934
|
-
function
|
|
1935
|
-
let n = /* @__PURE__ */ new Set([...Object.keys(
|
|
1936
|
-
for (let r of Object.keys(e)) n.has(r) || t.report("config.invalid", `unknown config key "${r}"
|
|
1937
|
-
for (let n of
|
|
327
|
+
function it(e, t) {
|
|
328
|
+
let n = /* @__PURE__ */ new Set([...Object.keys(C), ...ae]);
|
|
329
|
+
for (let r of Object.keys(e)) n.has(r) || t.report("config.invalid", `The library ignores the unknown config key "${r}". Check the spelling.`);
|
|
330
|
+
for (let n of _) {
|
|
1938
331
|
let r = e[n];
|
|
1939
332
|
if (typeof r != "object" || !r) continue;
|
|
1940
|
-
let i = /* @__PURE__ */ new Set([...Object.keys(
|
|
1941
|
-
for (let e of Object.keys(r)) i.has(e) || t.report("config.invalid", `unknown config key "${n}.${e}"
|
|
333
|
+
let i = /* @__PURE__ */ new Set([...Object.keys(C[n]), ...me[n]]);
|
|
334
|
+
for (let e of Object.keys(r)) i.has(e) || t.report("config.invalid", `The library ignores the unknown config key "${n}.${e}". Check the spelling.`);
|
|
1942
335
|
}
|
|
1943
336
|
}
|
|
1944
|
-
function
|
|
1945
|
-
for (let n of Object.keys(t))
|
|
1946
|
-
for (let n of
|
|
337
|
+
function at(e, t) {
|
|
338
|
+
for (let n of Object.keys(t)) _.includes(n) || Object.assign(e, { [n]: t[n] });
|
|
339
|
+
for (let n of _) Object.assign(e[n], t[n]);
|
|
1947
340
|
}
|
|
1948
341
|
//#endregion
|
|
1949
342
|
//#region src/core/context.ts
|
|
1950
|
-
var
|
|
343
|
+
var ot = class {
|
|
1951
344
|
map = /* @__PURE__ */ new Map();
|
|
1952
345
|
set(e, t) {
|
|
1953
346
|
this.map.set(e, t);
|
|
@@ -1967,12 +360,12 @@ var nr = class {
|
|
|
1967
360
|
getAll() {
|
|
1968
361
|
return Object.fromEntries(this.map);
|
|
1969
362
|
}
|
|
1970
|
-
},
|
|
363
|
+
}, st = class {
|
|
1971
364
|
handler;
|
|
1972
365
|
throttleMs;
|
|
1973
366
|
counters = /* @__PURE__ */ new Map();
|
|
1974
367
|
lastEmitted = /* @__PURE__ */ new Map();
|
|
1975
|
-
constructor(e, t =
|
|
368
|
+
constructor(e, t = d) {
|
|
1976
369
|
this.handler = e, this.throttleMs = t;
|
|
1977
370
|
}
|
|
1978
371
|
setHandler(e) {
|
|
@@ -1997,7 +390,7 @@ var nr = class {
|
|
|
1997
390
|
if (this.handler) try {
|
|
1998
391
|
this.handler(o);
|
|
1999
392
|
} catch (e) {
|
|
2000
|
-
this.count("handler.threw"), typeof console < "u" && console.warn(`${
|
|
393
|
+
this.count("handler.threw"), typeof console < "u" && console.warn(`${ie} The onDiagnostic handler threw an error.`, e);
|
|
2001
394
|
}
|
|
2002
395
|
}
|
|
2003
396
|
guard(e, t, n) {
|
|
@@ -2022,59 +415,60 @@ var nr = class {
|
|
|
2022
415
|
reset() {
|
|
2023
416
|
this.counters.clear(), this.lastEmitted.clear();
|
|
2024
417
|
}
|
|
2025
|
-
},
|
|
2026
|
-
maxAgeMs:
|
|
418
|
+
}, ct = {
|
|
419
|
+
maxAgeMs: we,
|
|
2027
420
|
endOnOwnerClose: !1,
|
|
2028
|
-
urlParam:
|
|
421
|
+
urlParam: Se
|
|
2029
422
|
};
|
|
2030
|
-
function
|
|
423
|
+
function U(e, t) {
|
|
2031
424
|
let n = Reflect.get(e, t);
|
|
2032
425
|
return typeof n == "string" && n !== "" ? n : void 0;
|
|
2033
426
|
}
|
|
2034
|
-
function
|
|
427
|
+
function W(e, t) {
|
|
2035
428
|
let n = Reflect.get(e, t);
|
|
2036
429
|
return typeof n == "number" && Number.isFinite(n) ? n : void 0;
|
|
2037
430
|
}
|
|
2038
|
-
function
|
|
431
|
+
function lt(e) {
|
|
2039
432
|
if (typeof e != "object" || !e) return null;
|
|
2040
|
-
let t =
|
|
433
|
+
let t = U(e, "id"), n = U(e, "name"), r = W(e, "startedAt");
|
|
2041
434
|
return t === void 0 || n === void 0 || r === void 0 ? null : {
|
|
2042
435
|
id: t,
|
|
2043
436
|
name: n,
|
|
2044
437
|
startedAt: r,
|
|
2045
|
-
parentId:
|
|
2046
|
-
ownerContextId:
|
|
438
|
+
parentId: U(e, "parentId"),
|
|
439
|
+
ownerContextId: U(e, "ownerContextId") ?? ""
|
|
2047
440
|
};
|
|
2048
441
|
}
|
|
2049
|
-
function
|
|
442
|
+
function ut(e) {
|
|
2050
443
|
if (typeof e != "object" || !e) return null;
|
|
2051
|
-
let t =
|
|
444
|
+
let t = U(e, "i"), n = U(e, "n");
|
|
2052
445
|
return t === void 0 || n === void 0 ? null : {
|
|
2053
446
|
id: t,
|
|
2054
447
|
name: n,
|
|
2055
|
-
startedAt:
|
|
448
|
+
startedAt: W(e, "s") ?? Date.now(),
|
|
2056
449
|
parentId: void 0,
|
|
2057
450
|
ownerContextId: ""
|
|
2058
451
|
};
|
|
2059
452
|
}
|
|
2060
|
-
function
|
|
453
|
+
function dt(e) {
|
|
2061
454
|
let t = JSON.stringify({
|
|
2062
455
|
i: e.id,
|
|
2063
456
|
n: e.name.slice(0, 64),
|
|
2064
457
|
s: e.startedAt
|
|
2065
458
|
}), n = new TextEncoder().encode(t), r = "";
|
|
2066
459
|
for (let e of n) r += String.fromCharCode(e);
|
|
2067
|
-
return btoa(r).replace(
|
|
460
|
+
return btoa(r).replace(se, "-").replace(ne, "_").replace(ce, "");
|
|
2068
461
|
}
|
|
2069
|
-
var
|
|
462
|
+
var ft = class {
|
|
2070
463
|
options;
|
|
2071
464
|
diagnostics;
|
|
2072
465
|
contextId;
|
|
2073
466
|
onLocalChange;
|
|
467
|
+
stores;
|
|
2074
468
|
journey = null;
|
|
2075
469
|
expiryTimer = null;
|
|
2076
|
-
constructor(e, t, n, r) {
|
|
2077
|
-
this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r;
|
|
470
|
+
constructor(e, t, n, r, i = A) {
|
|
471
|
+
this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r, this.stores = i;
|
|
2078
472
|
}
|
|
2079
473
|
current() {
|
|
2080
474
|
return this.journey;
|
|
@@ -2082,14 +476,14 @@ var lr = class {
|
|
|
2082
476
|
async bootstrap() {
|
|
2083
477
|
let e = this.readUrlToken();
|
|
2084
478
|
if (e && this.adopt(e, "url")) return;
|
|
2085
|
-
let t = this.diagnostics.guard("storage.unavailable", "
|
|
479
|
+
let t = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(E));
|
|
2086
480
|
if (t && this.restore(t)) return;
|
|
2087
481
|
let n = await this.readOpenFinToken();
|
|
2088
482
|
n !== null && this.adopt(n, "openfin.customData");
|
|
2089
483
|
}
|
|
2090
484
|
start(e, t = {}) {
|
|
2091
485
|
let n = {
|
|
2092
|
-
id: t.id ??
|
|
486
|
+
id: t.id ?? j(this.diagnostics),
|
|
2093
487
|
name: e,
|
|
2094
488
|
startedAt: Date.now(),
|
|
2095
489
|
parentId: t.parent ? this.journey?.id : void 0,
|
|
@@ -2107,19 +501,16 @@ var lr = class {
|
|
|
2107
501
|
getToken() {
|
|
2108
502
|
let e = this.journey;
|
|
2109
503
|
if (e === null) return;
|
|
2110
|
-
let t =
|
|
2111
|
-
if (t.length > 256) {
|
|
2112
|
-
|
|
2113
|
-
return;
|
|
2114
|
-
}
|
|
2115
|
-
return t;
|
|
504
|
+
let t = dt(e);
|
|
505
|
+
if (t.length > 256) this.diagnostics.report("journey.token_too_large", "The journey token is larger than the size limit. The library does not issue it.", { length: t.length });
|
|
506
|
+
else return t;
|
|
2116
507
|
}
|
|
2117
508
|
adopt(e, t, n = !1) {
|
|
2118
509
|
let r = this.decodeToken(e);
|
|
2119
|
-
return r === null ? !1 : Date.now() - r.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "discarded a seeded journey older than maxAgeMs", {
|
|
510
|
+
return r === null ? !1 : Date.now() - r.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "The library discarded a seeded journey older than maxAgeMs.", {
|
|
2120
511
|
source: t,
|
|
2121
512
|
name: r.name
|
|
2122
|
-
}), !1) : (this.setJourney(r), this.diagnostics.report("journey.adopted", `adopted journey "${r.name}"
|
|
513
|
+
}), !1) : (this.setJourney(r), this.diagnostics.report("journey.adopted", `The library adopted the journey "${r.name}".`, {
|
|
2123
514
|
source: t,
|
|
2124
515
|
journeyId: r.id
|
|
2125
516
|
}), n && this.onLocalChange(r), !0);
|
|
@@ -2131,263 +522,51 @@ var lr = class {
|
|
|
2131
522
|
this.clearTimer();
|
|
2132
523
|
}
|
|
2133
524
|
restore(e) {
|
|
2134
|
-
let t =
|
|
2135
|
-
return t === null ? !1 : Date.now() - t.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "discarded a persisted journey older than maxAgeMs", { name: t.name }), this.clearStored(), !1) : (this.setJourney(t), this.diagnostics.report("journey.adopted", `resumed journey "${t.name}"
|
|
525
|
+
let t = lt(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
|
|
526
|
+
return t === null ? !1 : Date.now() - t.startedAt > this.options.maxAgeMs ? (this.diagnostics.report("journey.expired", "The library discarded a persisted journey older than maxAgeMs.", { name: t.name }), this.clearStored(), !1) : (this.setJourney(t), this.diagnostics.report("journey.adopted", `The library resumed the journey "${t.name}".`, {
|
|
2136
527
|
source: "sessionStorage",
|
|
2137
528
|
journeyId: t.id
|
|
2138
529
|
}), !0);
|
|
2139
530
|
}
|
|
2140
531
|
decodeToken(e) {
|
|
2141
|
-
return this.diagnostics.guard("config.invalid", "
|
|
2142
|
-
let t = e.replace(
|
|
2143
|
-
return
|
|
532
|
+
return this.diagnostics.guard("config.invalid", "The library could not decode a seeded journey token.", () => {
|
|
533
|
+
let t = e.replace(ye, "+").replace(he, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
|
|
534
|
+
return ut(JSON.parse(new TextDecoder().decode(i)));
|
|
2144
535
|
}) ?? null;
|
|
2145
536
|
}
|
|
2146
537
|
setJourney(e) {
|
|
2147
|
-
if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "
|
|
2148
|
-
e === null ?
|
|
538
|
+
if (this.journey = e, this.clearTimer(), this.diagnostics.guard("storage.unavailable", "The library could not save the journey.", () => {
|
|
539
|
+
e === null ? this.stores.session().removeItem(E) : this.stores.session().setItem(E, JSON.stringify(e));
|
|
2149
540
|
}), e === null) return;
|
|
2150
541
|
let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
|
|
2151
|
-
this.diagnostics.report("journey.expired", `journey "${e.name}"
|
|
542
|
+
this.diagnostics.report("journey.expired", `The journey "${e.name}" reached maxAgeMs. The library ended it.`, { journeyId: e.id }), this.journey = null, this.expiryTimer = null, this.clearStored();
|
|
2152
543
|
}, t);
|
|
2153
|
-
this.expiryTimer = n,
|
|
544
|
+
this.expiryTimer = n, Be(n);
|
|
2154
545
|
}
|
|
2155
546
|
clearStored() {
|
|
2156
|
-
this.diagnostics.guard("storage.unavailable", "
|
|
2157
|
-
|
|
547
|
+
this.diagnostics.guard("storage.unavailable", "The library could not clear the persisted journey.", () => {
|
|
548
|
+
this.stores.session().removeItem(E);
|
|
2158
549
|
});
|
|
2159
550
|
}
|
|
2160
551
|
clearTimer() {
|
|
2161
552
|
this.expiryTimer !== null && (clearTimeout(this.expiryTimer), this.expiryTimer = null);
|
|
2162
553
|
}
|
|
2163
554
|
readUrlToken() {
|
|
2164
|
-
return this.diagnostics.guard("config.invalid", "
|
|
555
|
+
return this.diagnostics.guard("config.invalid", "The library could not read the journey token from the URL.", () => typeof location > "u" ? null : new URL(location.href).searchParams.get(this.options.urlParam)) ?? null;
|
|
2165
556
|
}
|
|
2166
557
|
async readOpenFinToken() {
|
|
2167
558
|
let e = globalThis.fin?.me, t = e?.getOptions;
|
|
2168
559
|
if (t === void 0) return null;
|
|
2169
|
-
let n = (await this.diagnostics.guardAsync("openfin.unavailable", "
|
|
560
|
+
let n = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => Ae(t.call(e), le)))?.customData?.[ge];
|
|
2170
561
|
return typeof n == "string" ? n : null;
|
|
2171
562
|
}
|
|
2172
563
|
};
|
|
2173
564
|
//#endregion
|
|
2174
|
-
//#region src/core/sampling.ts
|
|
2175
|
-
function ur(e) {
|
|
2176
|
-
let t = m;
|
|
2177
|
-
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, ge);
|
|
2178
|
-
return t >>> 0;
|
|
2179
|
-
}
|
|
2180
|
-
function J(e, t) {
|
|
2181
|
-
let n = e.attributes[t];
|
|
2182
|
-
return typeof n == "string" ? n : "";
|
|
2183
|
-
}
|
|
2184
|
-
function dr(e, t) {
|
|
2185
|
-
let { rates: n, defaultRate: r } = t.sampling, i, a = -1;
|
|
2186
|
-
for (let [t, r] of Object.entries(n)) (e === t || e.startsWith(`${t}.`)) && t.length > a && (i = r, a = t.length);
|
|
2187
|
-
return i ?? r;
|
|
2188
|
-
}
|
|
2189
|
-
function fr(e, t) {
|
|
2190
|
-
if (e.level === "ERROR" || e.level === "FATAL" || t.sampling.alwaysSampleTypes.includes(e.type)) return !0;
|
|
2191
|
-
let n = dr(e.namespace, t);
|
|
2192
|
-
return n >= 1 ? !0 : n <= 0 ? !1 : ur(e.journeyId || e.traceId) / $e < n;
|
|
2193
|
-
}
|
|
2194
|
-
function pr(e, t) {
|
|
2195
|
-
return fr({
|
|
2196
|
-
level: e.severityText,
|
|
2197
|
-
type: J(e, S),
|
|
2198
|
-
namespace: J(e, C),
|
|
2199
|
-
journeyId: J(e, we),
|
|
2200
|
-
traceId: e.traceId
|
|
2201
|
-
}, t);
|
|
2202
|
-
}
|
|
2203
|
-
var mr = class {
|
|
2204
|
-
windowStart = 0;
|
|
2205
|
-
count = 0;
|
|
2206
|
-
allow(e) {
|
|
2207
|
-
if (e.severityText !== "ERROR" && e.severityText !== "FATAL") return !0;
|
|
2208
|
-
let t = Date.now();
|
|
2209
|
-
return t - this.windowStart > 1e4 && (this.windowStart = t, this.count = 0), this.count++, this.count <= 500;
|
|
2210
|
-
}
|
|
2211
|
-
};
|
|
2212
|
-
//#endregion
|
|
2213
|
-
//#region src/core/pipeline.ts
|
|
2214
|
-
function hr(e) {
|
|
2215
|
-
return e.attributes[S] === ut;
|
|
2216
|
-
}
|
|
2217
|
-
var gr = {
|
|
2218
|
-
logs: {
|
|
2219
|
-
flushIntervalMs: et,
|
|
2220
|
-
batchSize: 100
|
|
2221
|
-
},
|
|
2222
|
-
metrics: {
|
|
2223
|
-
flushIntervalMs: Je,
|
|
2224
|
-
batchSize: 500
|
|
2225
|
-
}
|
|
2226
|
-
}, _r = class {
|
|
2227
|
-
options;
|
|
2228
|
-
onFlush;
|
|
2229
|
-
pending = [];
|
|
2230
|
-
timer = null;
|
|
2231
|
-
constructor(e, t) {
|
|
2232
|
-
this.options = e, this.onFlush = t;
|
|
2233
|
-
}
|
|
2234
|
-
add(e) {
|
|
2235
|
-
if (this.pending.push(e), this.pending.length >= this.options.batchSize) {
|
|
2236
|
-
this.onFlush(this);
|
|
2237
|
-
return;
|
|
2238
|
-
}
|
|
2239
|
-
this.arm();
|
|
2240
|
-
}
|
|
2241
|
-
take() {
|
|
2242
|
-
this.clearTimer();
|
|
2243
|
-
let e = this.pending;
|
|
2244
|
-
return this.pending = [], e;
|
|
2245
|
-
}
|
|
2246
|
-
stop() {
|
|
2247
|
-
this.clearTimer();
|
|
2248
|
-
}
|
|
2249
|
-
arm() {
|
|
2250
|
-
if (this.timer !== null) return;
|
|
2251
|
-
let e = setTimeout(() => {
|
|
2252
|
-
this.timer = null, this.onFlush(this);
|
|
2253
|
-
}, this.options.flushIntervalMs);
|
|
2254
|
-
this.timer = e, D(e);
|
|
2255
|
-
}
|
|
2256
|
-
clearTimer() {
|
|
2257
|
-
this.timer !== null && (clearTimeout(this.timer), this.timer = null);
|
|
2258
|
-
}
|
|
2259
|
-
}, vr = class {
|
|
2260
|
-
transport;
|
|
2261
|
-
storage;
|
|
2262
|
-
retry;
|
|
2263
|
-
diagnostics;
|
|
2264
|
-
streams;
|
|
2265
|
-
unconfirmed = /* @__PURE__ */ new Map();
|
|
2266
|
-
queue = [];
|
|
2267
|
-
ceiling = new mr();
|
|
2268
|
-
inFlight = 0;
|
|
2269
|
-
pumpScheduled = !1;
|
|
2270
|
-
stopped = !1;
|
|
2271
|
-
constructor(e, t, n, r, i = gr) {
|
|
2272
|
-
this.transport = e, this.storage = t, this.retry = n, this.diagnostics = r;
|
|
2273
|
-
let a = (e) => {
|
|
2274
|
-
this.claim(e);
|
|
2275
|
-
};
|
|
2276
|
-
this.streams = {
|
|
2277
|
-
logs: new _r(i.logs, a),
|
|
2278
|
-
metrics: new _r(i.metrics, a)
|
|
2279
|
-
};
|
|
2280
|
-
}
|
|
2281
|
-
push(e) {
|
|
2282
|
-
this.stopped || (e.observedTimeUnixNano = Xt(), this.route(e));
|
|
2283
|
-
}
|
|
2284
|
-
drainPending() {
|
|
2285
|
-
return this.toBatch([...this.streams.metrics.take(), ...this.streams.logs.take()]);
|
|
2286
|
-
}
|
|
2287
|
-
drainForExit() {
|
|
2288
|
-
let e = [...this.unconfirmed.values()].flatMap((e) => e.records);
|
|
2289
|
-
return this.unconfirmed.clear(), this.toBatch([
|
|
2290
|
-
...e,
|
|
2291
|
-
...this.streams.metrics.take(),
|
|
2292
|
-
...this.streams.logs.take()
|
|
2293
|
-
]);
|
|
2294
|
-
}
|
|
2295
|
-
destroy() {
|
|
2296
|
-
this.stopped = !0, this.streams.logs.stop(), this.streams.metrics.stop(), this.queue.length = 0;
|
|
2297
|
-
}
|
|
2298
|
-
toBatch(e) {
|
|
2299
|
-
return e.length === 0 ? null : {
|
|
2300
|
-
id: I(),
|
|
2301
|
-
records: e,
|
|
2302
|
-
createdAt: Date.now(),
|
|
2303
|
-
attempts: 0
|
|
2304
|
-
};
|
|
2305
|
-
}
|
|
2306
|
-
route(e) {
|
|
2307
|
-
try {
|
|
2308
|
-
let t = hr(e) ? this.streams.metrics : this.streams.logs;
|
|
2309
|
-
if (!this.ceiling.allow(e)) {
|
|
2310
|
-
this.diagnostics.count("record.dropped_by_ceiling");
|
|
2311
|
-
return;
|
|
2312
|
-
}
|
|
2313
|
-
t.add(e);
|
|
2314
|
-
} catch (e) {
|
|
2315
|
-
this.diagnostics.report("pipeline.crashed", "a record was dropped on its way into a stream", void 0, e);
|
|
2316
|
-
}
|
|
2317
|
-
}
|
|
2318
|
-
claim(e) {
|
|
2319
|
-
let t = e.take(), n = {
|
|
2320
|
-
id: I(),
|
|
2321
|
-
records: t,
|
|
2322
|
-
createdAt: Date.now(),
|
|
2323
|
-
attempts: 0
|
|
2324
|
-
};
|
|
2325
|
-
this.unconfirmed.set(n.id, n), this.enqueue(n);
|
|
2326
|
-
}
|
|
2327
|
-
enqueue(e) {
|
|
2328
|
-
this.queue.push(e), !this.pumpScheduled && (this.pumpScheduled = !0, queueMicrotask(() => {
|
|
2329
|
-
this.pumpScheduled = !1, this.pump();
|
|
2330
|
-
}));
|
|
2331
|
-
}
|
|
2332
|
-
pump() {
|
|
2333
|
-
for (; this.inFlight < 2;) {
|
|
2334
|
-
let e = this.queue.shift();
|
|
2335
|
-
if (!e) return;
|
|
2336
|
-
this.inFlight++, this.run(e);
|
|
2337
|
-
}
|
|
2338
|
-
}
|
|
2339
|
-
async run(e) {
|
|
2340
|
-
try {
|
|
2341
|
-
await this.dispatch(e);
|
|
2342
|
-
} catch (t) {
|
|
2343
|
-
this.diagnostics.report("pipeline.crashed", "dispatch rejected, which it is written never to do", { batchId: e.id }, t);
|
|
2344
|
-
} finally {
|
|
2345
|
-
this.inFlight--, this.pump();
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
async dispatch(e) {
|
|
2349
|
-
try {
|
|
2350
|
-
let t = this.transport.throttledForMs();
|
|
2351
|
-
if (t > 0) {
|
|
2352
|
-
await this.store(e), this.diagnostics.report("transport.throttled", "stored the batch rather than sending it", {
|
|
2353
|
-
batchId: e.id,
|
|
2354
|
-
records: e.records.length,
|
|
2355
|
-
throttledMs: t
|
|
2356
|
-
});
|
|
2357
|
-
return;
|
|
2358
|
-
}
|
|
2359
|
-
try {
|
|
2360
|
-
await this.transport.send(e);
|
|
2361
|
-
} catch (t) {
|
|
2362
|
-
await this.storeFailed({
|
|
2363
|
-
...e,
|
|
2364
|
-
attempts: e.attempts + 1
|
|
2365
|
-
}, t), this.diagnostics.report("transport.http_error", "batch was stored for retry instead of being delivered", {
|
|
2366
|
-
batchId: e.id,
|
|
2367
|
-
records: e.records.length
|
|
2368
|
-
}, t);
|
|
2369
|
-
}
|
|
2370
|
-
} finally {
|
|
2371
|
-
this.unconfirmed.delete(e.id);
|
|
2372
|
-
}
|
|
2373
|
-
}
|
|
2374
|
-
async storeFailed(e, t) {
|
|
2375
|
-
await this.diagnostics.guardAsync("storage.degraded", "persisting an undelivered batch", async () => {
|
|
2376
|
-
await this.retry.storeFailed(e, t);
|
|
2377
|
-
});
|
|
2378
|
-
}
|
|
2379
|
-
async store(e) {
|
|
2380
|
-
await this.diagnostics.guardAsync("storage.degraded", "persisting an undelivered batch", async () => {
|
|
2381
|
-
await R(this.storage.save(e), v), this.retry.nudge();
|
|
2382
|
-
});
|
|
2383
|
-
}
|
|
2384
|
-
};
|
|
2385
|
-
//#endregion
|
|
2386
565
|
//#region src/core/record.ts
|
|
2387
|
-
function
|
|
566
|
+
function G(e) {
|
|
2388
567
|
return e;
|
|
2389
568
|
}
|
|
2390
|
-
var
|
|
569
|
+
var pt = class {
|
|
2391
570
|
deps;
|
|
2392
571
|
resourceCache = null;
|
|
2393
572
|
constructor(e) {
|
|
@@ -2398,7 +577,7 @@ var yr = class {
|
|
|
2398
577
|
}
|
|
2399
578
|
isEnabled(e) {
|
|
2400
579
|
let { config: t } = this.deps;
|
|
2401
|
-
return t.enabled ?
|
|
580
|
+
return t.enabled ? S[e] >= S[t.minLevel] : !1;
|
|
2402
581
|
}
|
|
2403
582
|
build(e) {
|
|
2404
583
|
let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o } = this.deps;
|
|
@@ -2406,115 +585,123 @@ var yr = class {
|
|
|
2406
585
|
record: null,
|
|
2407
586
|
dropped: "level"
|
|
2408
587
|
};
|
|
2409
|
-
let s = r.resolve(),
|
|
2410
|
-
if (!
|
|
588
|
+
let s = r.resolve(), l = i.current();
|
|
589
|
+
if (!Fe({
|
|
2411
590
|
level: e.level,
|
|
2412
591
|
type: e.type,
|
|
2413
592
|
namespace: e.namespace,
|
|
2414
|
-
journeyId:
|
|
593
|
+
journeyId: l?.id ?? "",
|
|
2415
594
|
traceId: s.traceId
|
|
2416
595
|
}, t)) return n.count("record.dropped_by_sampling"), {
|
|
2417
596
|
record: null,
|
|
2418
597
|
dropped: "sampling"
|
|
2419
598
|
};
|
|
2420
|
-
let
|
|
599
|
+
let u = a.next(), d = ze(n), f = t.capture.fullUrls ? d : Re(d), p, m = 0;
|
|
2421
600
|
try {
|
|
2422
|
-
let t =
|
|
2423
|
-
|
|
2424
|
-
...
|
|
2425
|
-
...
|
|
2426
|
-
...
|
|
601
|
+
let t = N(this.deps.context.getAll(), o, n), r = N(e.scoped ?? {}, o, n), i = N(e.payload ?? {}, o, n);
|
|
602
|
+
m = t.bytes + r.bytes + i.bytes, p = {
|
|
603
|
+
...G(t.value),
|
|
604
|
+
...G(r.value),
|
|
605
|
+
...G(i.value)
|
|
2427
606
|
};
|
|
2428
607
|
} catch (e) {
|
|
2429
|
-
n.report("record.sanitize_failed", "
|
|
608
|
+
n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [oe]: !0 };
|
|
2430
609
|
}
|
|
2431
|
-
|
|
2432
|
-
let
|
|
2433
|
-
|
|
2434
|
-
let
|
|
2435
|
-
timeUnixNano:
|
|
610
|
+
p[w] = e.type, p[x] = u, p[T] = e.namespace, p[O] = f, l && (p[y] = l.id, p[D] = l.name, l.parentId !== void 0 && (p[Ce] = l.parentId));
|
|
611
|
+
let h = ke(e.body, o.maxBodyChars);
|
|
612
|
+
h !== e.body && n.count("record.truncated");
|
|
613
|
+
let g = {
|
|
614
|
+
timeUnixNano: De(),
|
|
2436
615
|
traceId: s.traceId,
|
|
2437
616
|
spanId: s.spanId,
|
|
2438
617
|
traceFlags: s.traceFlags,
|
|
2439
|
-
severityNumber:
|
|
618
|
+
severityNumber: c[e.level],
|
|
2440
619
|
severityText: e.level,
|
|
2441
|
-
body:
|
|
2442
|
-
attributes:
|
|
620
|
+
body: h,
|
|
621
|
+
attributes: p,
|
|
2443
622
|
resource: this.resource()
|
|
2444
|
-
},
|
|
2445
|
-
if (
|
|
2446
|
-
let e = n.guard("record.sanitize_failed", "redact hook threw", () => g
|
|
623
|
+
}, _ = t.redact;
|
|
624
|
+
if (_) {
|
|
625
|
+
let e = n.guard("record.sanitize_failed", "The redact hook threw an error.", () => _(g));
|
|
2447
626
|
if (e === null) return n.count("record.dropped_by_redact"), {
|
|
2448
627
|
record: null,
|
|
2449
628
|
dropped: "redact"
|
|
2450
629
|
};
|
|
2451
|
-
if (e !== void 0 && e !==
|
|
2452
|
-
if (
|
|
2453
|
-
let t =
|
|
2454
|
-
|
|
630
|
+
if (e !== void 0 && e !== g) {
|
|
631
|
+
if (M(e)) {
|
|
632
|
+
let t = N(e.attributes, o, n);
|
|
633
|
+
g = {
|
|
2455
634
|
...e,
|
|
2456
|
-
attributes:
|
|
2457
|
-
},
|
|
2458
|
-
} else n.report("record.sanitize_failed", "redact hook returned
|
|
635
|
+
attributes: G(t.value)
|
|
636
|
+
}, m = t.bytes;
|
|
637
|
+
} else n.report("record.sanitize_failed", "The redact hook returned a value that is not a record. The library keeps the original record.");
|
|
2459
638
|
}
|
|
2460
639
|
}
|
|
2461
|
-
if (
|
|
2462
|
-
n.report("record.truncated", "attributes
|
|
2463
|
-
bytes:
|
|
2464
|
-
body:
|
|
640
|
+
if (m > o.maxRecordBytes) {
|
|
641
|
+
n.report("record.truncated", "The attributes are larger than the size limit. The library dropped them.", {
|
|
642
|
+
bytes: m,
|
|
643
|
+
body: g.body
|
|
2465
644
|
});
|
|
2466
645
|
let t = {
|
|
2467
|
-
[
|
|
2468
|
-
[
|
|
2469
|
-
[
|
|
2470
|
-
[
|
|
2471
|
-
[
|
|
2472
|
-
[
|
|
646
|
+
[w]: e.type,
|
|
647
|
+
[x]: u,
|
|
648
|
+
[T]: e.namespace,
|
|
649
|
+
[O]: f,
|
|
650
|
+
[ue]: !0,
|
|
651
|
+
[be]: m
|
|
2473
652
|
};
|
|
2474
|
-
|
|
653
|
+
l && (t[y] = l.id, t[D] = l.name), g.attributes = t;
|
|
2475
654
|
}
|
|
2476
|
-
return { record:
|
|
655
|
+
return { record: g };
|
|
2477
656
|
}
|
|
2478
657
|
resource() {
|
|
2479
658
|
if (this.resourceCache) return this.resourceCache;
|
|
2480
|
-
let { config:
|
|
659
|
+
let { config: t, identity: r, platform: a } = this.deps;
|
|
2481
660
|
return this.resourceCache = {
|
|
2482
|
-
[
|
|
2483
|
-
[
|
|
2484
|
-
[
|
|
2485
|
-
[
|
|
2486
|
-
[
|
|
2487
|
-
[
|
|
2488
|
-
[
|
|
2489
|
-
[
|
|
2490
|
-
[
|
|
2491
|
-
[
|
|
2492
|
-
[
|
|
2493
|
-
...
|
|
2494
|
-
...
|
|
661
|
+
[p]: t.serviceName,
|
|
662
|
+
[pe]: t.serviceVersion,
|
|
663
|
+
[Te]: t.environment,
|
|
664
|
+
[f]: xe,
|
|
665
|
+
[m]: de,
|
|
666
|
+
[u]: _e,
|
|
667
|
+
[ee]: a.platform,
|
|
668
|
+
[e]: r.sessionId,
|
|
669
|
+
[fe]: r.tabId,
|
|
670
|
+
[n]: r.contextId,
|
|
671
|
+
[g]: a.userAgent,
|
|
672
|
+
...a.openfinUuid === void 0 ? {} : { [i]: a.openfinUuid },
|
|
673
|
+
...a.openfinName === void 0 ? {} : { [o]: a.openfinName }
|
|
2495
674
|
}, this.resourceCache;
|
|
2496
675
|
}
|
|
2497
|
-
},
|
|
676
|
+
}, mt = {
|
|
677
|
+
errors: async () => (await import("./errors-Dwm2SzBa.js")).ErrorCapture,
|
|
678
|
+
network: async () => (await import("./network-C4d2uw2Z.js")).NetworkCapture,
|
|
679
|
+
interactions: async () => (await import("./interactions-DZmLu7l2.js")).InteractionCapture,
|
|
680
|
+
webVitals: async () => (await import("./web-vitals-DHZ0yA_H.js")).WebVitalsCapture
|
|
681
|
+
}, K = Symbol.for(h), q = Symbol.for(Ee), J = class e {
|
|
2498
682
|
diagnostics;
|
|
2499
683
|
config;
|
|
2500
684
|
platform;
|
|
2501
685
|
identity;
|
|
686
|
+
stores;
|
|
687
|
+
identityBuiltAs;
|
|
2502
688
|
sessionTouch;
|
|
2503
|
-
context = new
|
|
689
|
+
context = new ot();
|
|
2504
690
|
breadcrumbs;
|
|
2505
691
|
tracing;
|
|
2506
|
-
sequence = new
|
|
692
|
+
sequence = new qe();
|
|
2507
693
|
journey;
|
|
2508
694
|
builder;
|
|
2509
695
|
console;
|
|
2510
|
-
bus;
|
|
2511
|
-
|
|
696
|
+
bus = null;
|
|
697
|
+
busBuilt;
|
|
698
|
+
busLoad;
|
|
2512
699
|
storageBuiltAs;
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
exitFlush;
|
|
700
|
+
sender;
|
|
701
|
+
senderLoad;
|
|
702
|
+
pendingRecords = [];
|
|
2517
703
|
captures = [];
|
|
704
|
+
captureGeneration = 0;
|
|
2518
705
|
captureOnce = {
|
|
2519
706
|
webVitals: !1,
|
|
2520
707
|
navigationTiming: !1
|
|
@@ -2522,15 +709,16 @@ var yr = class {
|
|
|
2522
709
|
bootBuffer = [];
|
|
2523
710
|
forwardBuffer = [];
|
|
2524
711
|
forwardScheduled = !1;
|
|
712
|
+
roleResolved = !1;
|
|
2525
713
|
ready = !1;
|
|
2526
714
|
destroyed = !1;
|
|
2527
715
|
lastGapAt = 0;
|
|
2528
716
|
constructor(e) {
|
|
2529
|
-
this.diagnostics = new
|
|
2530
|
-
this.bus
|
|
2531
|
-
}), this.builder = new
|
|
717
|
+
this.diagnostics = new st(e.onDiagnostic), this.platform = Le(this.diagnostics), this.config = H(e, this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" ? Ie() : A, this.identity = Oe(this.diagnostics, this.stores), this.sessionTouch = new Ne(this.diagnostics, this.stores), this.breadcrumbs = new et(50), this.tracing = new $e(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new Ke(this.config.console, this.diagnostics), this.journey = new ft(ct, this.diagnostics, this.identity.contextId, (e) => {
|
|
718
|
+
this.bus?.broadcastJourney(e);
|
|
719
|
+
}, this.stores), this.builder = new pt({
|
|
2532
720
|
config: this.config,
|
|
2533
|
-
limits:
|
|
721
|
+
limits: b,
|
|
2534
722
|
diagnostics: this.diagnostics,
|
|
2535
723
|
context: this.context,
|
|
2536
724
|
journey: this.journey,
|
|
@@ -2538,129 +726,188 @@ var yr = class {
|
|
|
2538
726
|
sequence: this.sequence,
|
|
2539
727
|
identity: this.identity,
|
|
2540
728
|
platform: this.platform
|
|
2541
|
-
}), this.bus = new Rt(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
|
|
2542
|
-
onRecords: (e) => {
|
|
2543
|
-
this.ingestForwarded(e);
|
|
2544
|
-
},
|
|
2545
|
-
onJourney: (e) => {
|
|
2546
|
-
this.journey.applyRemote(e);
|
|
2547
|
-
},
|
|
2548
|
-
onJourneyRequest: () => this.journey.current(),
|
|
2549
|
-
onTabConflict: () => {
|
|
2550
|
-
this.regenerateTabId();
|
|
2551
|
-
}
|
|
2552
729
|
});
|
|
2553
730
|
}
|
|
2554
731
|
busAccept = (e, t) => {
|
|
2555
|
-
this.destroyed || this.
|
|
2556
|
-
this.bus.
|
|
732
|
+
this.destroyed || this.ensureBus().then((n) => {
|
|
733
|
+
n && !this.destroyed && this.diagnostics.guard("bus.send_failed", "The bus could not accept a direct message from a child frame.", () => {
|
|
734
|
+
n.acceptDirect(e, t);
|
|
735
|
+
});
|
|
2557
736
|
});
|
|
2558
737
|
};
|
|
2559
738
|
static current() {
|
|
2560
|
-
return globalThis[
|
|
739
|
+
return globalThis[K] ?? null;
|
|
740
|
+
}
|
|
741
|
+
static stopped() {
|
|
742
|
+
return globalThis[q] ?? null;
|
|
743
|
+
}
|
|
744
|
+
isDestroyed() {
|
|
745
|
+
return this.destroyed;
|
|
2561
746
|
}
|
|
2562
747
|
static configure(t) {
|
|
2563
748
|
let n = e.current();
|
|
2564
749
|
if (n && !n.destroyed) return n.reconfigure(t), n;
|
|
2565
750
|
let r = new e(t);
|
|
2566
|
-
return globalThis[
|
|
751
|
+
return globalThis[K] = r, Reflect.deleteProperty(globalThis, q), r.init(), r;
|
|
2567
752
|
}
|
|
2568
753
|
reconfigure(e) {
|
|
2569
|
-
|
|
754
|
+
let t = this.keepEndpoint(e);
|
|
755
|
+
at(this.config, H(t, this.diagnostics, this.config)), this.diagnostics.setHandler(this.config.onDiagnostic), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), this.installCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
|
|
2570
756
|
}
|
|
2571
757
|
keepBuiltStorage() {
|
|
2572
758
|
let e = this.storageBuiltAs;
|
|
2573
|
-
e !== void 0 && this.config.storage !== e && (this.diagnostics.report("config.invalid", `storage cannot change after startup
|
|
759
|
+
e !== void 0 && this.config.storage !== e && (this.diagnostics.report("config.invalid", `storage cannot change after startup. It stays ${e}.`, { requested: this.config.storage }), this.config.storage = e);
|
|
760
|
+
}
|
|
761
|
+
keepEndpoint(e) {
|
|
762
|
+
return this.senderLoad === void 0 || e.endpoint !== null && e.endpoint !== "" ? e : (this.diagnostics.report("config.invalid", "You cannot remove the endpoint after the delivery stack loads. The endpoint in force stays."), {
|
|
763
|
+
...e,
|
|
764
|
+
endpoint: void 0
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
keepBuiltIdentity() {
|
|
768
|
+
let e = this.identityBuiltAs;
|
|
769
|
+
this.config.identity !== e && (this.diagnostics.report("config.invalid", `identity cannot change after startup. It stays ${e}.`, { requested: this.config.identity }), this.config.identity = e);
|
|
2574
770
|
}
|
|
2575
771
|
async init() {
|
|
772
|
+
let e = this.installCaptures();
|
|
2576
773
|
try {
|
|
2577
774
|
let e = this.journey.bootstrap();
|
|
2578
|
-
|
|
775
|
+
this.config.bus.mode !== "off" && await this.ensureBus(), this.roleResolved = !0, await this.syncSender(), await e;
|
|
2579
776
|
} catch (e) {
|
|
2580
|
-
this.diagnostics.report("pipeline.crashed", "
|
|
777
|
+
this.diagnostics.report("pipeline.crashed", "Startup failed. The runtime continues with reduced function.", void 0, e);
|
|
2581
778
|
} finally {
|
|
2582
779
|
this.ready = !0, this.releaseBootBuffer();
|
|
2583
780
|
}
|
|
781
|
+
await e;
|
|
2584
782
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
783
|
+
ensureBus() {
|
|
784
|
+
return this.busLoad ??= this.startBus(), this.busLoad;
|
|
785
|
+
}
|
|
786
|
+
constructBus() {
|
|
787
|
+
return this.busBuilt ??= this.buildBus(), this.busBuilt;
|
|
788
|
+
}
|
|
789
|
+
async startBus() {
|
|
790
|
+
let e = await this.constructBus();
|
|
791
|
+
if (!e) return null;
|
|
792
|
+
try {
|
|
793
|
+
return await e.start(), e;
|
|
794
|
+
} catch (e) {
|
|
795
|
+
return this.diagnostics.report("pipeline.crashed", "The bus did not start. This context sends its own records.", void 0, e), null;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
async buildBus() {
|
|
799
|
+
try {
|
|
800
|
+
let { Bus: e } = await import("./bus-BTMuVkDk.js");
|
|
801
|
+
if (this.destroyed) return null;
|
|
802
|
+
let t = new e(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
|
|
803
|
+
onRecords: (e) => {
|
|
804
|
+
this.ingestForwarded(e);
|
|
805
|
+
},
|
|
806
|
+
onJourney: (e) => {
|
|
807
|
+
this.journey.applyRemote(e);
|
|
808
|
+
},
|
|
809
|
+
onJourneyRequest: () => this.journey.current(),
|
|
810
|
+
onTabConflict: () => {
|
|
811
|
+
this.regenerateTabId();
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
return this.bus = t, t;
|
|
815
|
+
} catch (e) {
|
|
816
|
+
return this.diagnostics.report("pipeline.crashed", "The bus did not load. This context sends its own records.", void 0, e), null;
|
|
817
|
+
}
|
|
2592
818
|
}
|
|
2593
|
-
|
|
2594
|
-
|
|
819
|
+
role() {
|
|
820
|
+
return this.bus?.getRole() ?? "sender";
|
|
821
|
+
}
|
|
822
|
+
syncSender() {
|
|
823
|
+
return !this.config.endpoint || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
|
|
824
|
+
}
|
|
825
|
+
loadSender() {
|
|
826
|
+
return this.senderLoad ??= this.buildSender(), this.senderLoad;
|
|
827
|
+
}
|
|
828
|
+
async buildSender() {
|
|
829
|
+
this.storageBuiltAs = this.config.storage;
|
|
830
|
+
try {
|
|
831
|
+
let { Sender: e } = await import("./sender-dpvR_bHM.js"), t = this.destroyed ? null : await e.create({
|
|
832
|
+
config: this.config,
|
|
833
|
+
diagnostics: this.diagnostics,
|
|
834
|
+
onGap: this.reportGap
|
|
835
|
+
});
|
|
836
|
+
if (!t || this.destroyed) {
|
|
837
|
+
await t?.destroy();
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
this.sender = t;
|
|
841
|
+
} catch (e) {
|
|
842
|
+
this.senderLoad = void 0, this.diagnostics.report("pipeline.crashed", "The delivery stack did not load. The library does not send records.", { held: this.pendingRecords.length }, e);
|
|
843
|
+
}
|
|
844
|
+
let e = this.pendingRecords;
|
|
845
|
+
this.pendingRecords = [];
|
|
846
|
+
for (let t of e) this.sender?.push(t);
|
|
847
|
+
}
|
|
848
|
+
async installCaptures() {
|
|
849
|
+
let e = ++this.captureGeneration, n = this.config.capture, r = [];
|
|
850
|
+
(n.errors || n.rejections || n.resourceErrors) && r.push("errors"), (n.fetch || n.xhr) && r.push("network"), (n.interactions || n.navigation) && r.push("interactions"), n.webVitals && r.push("webVitals");
|
|
851
|
+
let i = await Promise.all(r.map((e) => this.loadCapture(e)));
|
|
852
|
+
if (e !== this.captureGeneration || this.destroyed) return;
|
|
853
|
+
this.uninstallCaptures();
|
|
854
|
+
let a = {
|
|
2595
855
|
config: this.config,
|
|
2596
856
|
diagnostics: this.diagnostics,
|
|
2597
857
|
breadcrumbs: this.breadcrumbs,
|
|
2598
858
|
tracing: this.tracing,
|
|
2599
|
-
logger: new
|
|
859
|
+
logger: new R(() => this, t),
|
|
2600
860
|
once: this.captureOnce
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `
|
|
861
|
+
};
|
|
862
|
+
for (let e of i) e && this.captures.push(new e(a));
|
|
863
|
+
for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `The library could not install the ${e.name} capture.`, () => {
|
|
2604
864
|
e.install();
|
|
2605
865
|
});
|
|
2606
866
|
}
|
|
2607
|
-
|
|
2608
|
-
for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `
|
|
867
|
+
uninstallCaptures() {
|
|
868
|
+
for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `The library could not uninstall the ${e.name} capture.`, () => {
|
|
2609
869
|
e.uninstall();
|
|
2610
870
|
});
|
|
2611
|
-
this.captures.length = 0
|
|
871
|
+
this.captures.length = 0;
|
|
872
|
+
}
|
|
873
|
+
loadCapture(e) {
|
|
874
|
+
return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, mt[e]);
|
|
2612
875
|
}
|
|
2613
876
|
registerWorker(e) {
|
|
2614
|
-
this.destroyed || this.
|
|
2615
|
-
this.bus.
|
|
877
|
+
this.destroyed || this.constructBus().then((t) => {
|
|
878
|
+
t && !this.destroyed && (this.diagnostics.guard("bus.send_failed", "The library could not register the worker.", () => {
|
|
879
|
+
t.attachWorker(e);
|
|
880
|
+
}), this.ensureBus());
|
|
2616
881
|
});
|
|
2617
882
|
}
|
|
2618
883
|
async destroy() {
|
|
2619
|
-
if (
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
}
|
|
884
|
+
if (this.destroyed) return;
|
|
885
|
+
this.destroyed = !0, this.uninstallCaptures();
|
|
886
|
+
let t = this.sender?.destroy();
|
|
887
|
+
this.journey.destroy(), this.bus?.destroy(), this.forwardBuffer = [], this.pendingRecords = [], await t, await this.senderLoad, e.current() === this && (Reflect.deleteProperty(globalThis, K), globalThis[q] = this);
|
|
2624
888
|
}
|
|
2625
889
|
emit(e) {
|
|
2626
|
-
|
|
2627
|
-
if (this.sessionTouch.touch(this.identity.sessionId), !this.ready) {
|
|
2628
|
-
this.bootBuffer.length >= 500 && (this.bootBuffer.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), this.bootBuffer.push(e);
|
|
2629
|
-
return;
|
|
2630
|
-
}
|
|
2631
|
-
this.route(e);
|
|
2632
|
-
}
|
|
890
|
+
e && !this.destroyed && (this.sessionTouch.touch(this.identity.sessionId), this.ready ? this.route(e) : this.pushCapped(this.bootBuffer, e));
|
|
2633
891
|
}
|
|
2634
892
|
route(e) {
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
893
|
+
this.role() === "forwarder" ? this.forward(e) : this.deliver(e);
|
|
894
|
+
}
|
|
895
|
+
deliver(e) {
|
|
896
|
+
this.sender ? this.sender.push(e) : this.senderLoad && this.pushCapped(this.pendingRecords, e);
|
|
897
|
+
}
|
|
898
|
+
pushCapped(e, t) {
|
|
899
|
+
e.length >= 500 && (e.shift(), this.diagnostics.count("record.dropped_boot_buffer_full")), e.push(t);
|
|
2640
900
|
}
|
|
2641
901
|
forward(e) {
|
|
2642
902
|
this.forwardBuffer.push(e), !this.forwardScheduled && (this.forwardScheduled = !0, queueMicrotask(() => {
|
|
2643
903
|
this.forwardScheduled = !1;
|
|
2644
904
|
let e = this.forwardBuffer;
|
|
2645
|
-
this.forwardBuffer = [], e.length > 0 && this.bus
|
|
905
|
+
this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
|
|
2646
906
|
}));
|
|
2647
907
|
}
|
|
2648
908
|
ingestForwarded(e) {
|
|
2649
|
-
if (!Array.isArray(e))
|
|
2650
|
-
|
|
2651
|
-
return;
|
|
2652
|
-
}
|
|
2653
|
-
for (let t of e) {
|
|
2654
|
-
if (!Zt(t)) {
|
|
2655
|
-
this.diagnostics.count("record.dropped_malformed");
|
|
2656
|
-
continue;
|
|
2657
|
-
}
|
|
2658
|
-
if (!pr(t, this.config)) {
|
|
2659
|
-
this.diagnostics.count("record.dropped_by_sampling");
|
|
2660
|
-
continue;
|
|
2661
|
-
}
|
|
2662
|
-
this.pipeline?.push(t);
|
|
2663
|
-
}
|
|
909
|
+
if (!Array.isArray(e)) this.diagnostics.count("record.dropped_malformed");
|
|
910
|
+
else for (let t of e) M(t) ? Me(t, this.config) ? this.deliver(t) : this.diagnostics.count("record.dropped_by_sampling") : this.diagnostics.count("record.dropped_malformed");
|
|
2664
911
|
}
|
|
2665
912
|
releaseBootBuffer() {
|
|
2666
913
|
let e = this.bootBuffer;
|
|
@@ -2670,137 +917,119 @@ var yr = class {
|
|
|
2670
917
|
}
|
|
2671
918
|
reportGap = (e) => {
|
|
2672
919
|
let t = Date.now();
|
|
2673
|
-
t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new
|
|
920
|
+
t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new R(() => this, te).warn("stored records were dropped before delivery", {
|
|
2674
921
|
"gap.batches": e.batches,
|
|
2675
922
|
"gap.records": e.records,
|
|
2676
923
|
"gap.reason": e.reason
|
|
2677
924
|
}));
|
|
2678
925
|
};
|
|
2679
926
|
regenerateTabId() {
|
|
2680
|
-
let e =
|
|
2681
|
-
this.diagnostics.report("bus.role_resolved", "
|
|
927
|
+
let e = j(this.diagnostics);
|
|
928
|
+
this.diagnostics.report("bus.role_resolved", "Another context uses this tab id. A duplicated tab is the usual cause. The library makes a new tab id.", {
|
|
2682
929
|
was: this.identity.tabId,
|
|
2683
930
|
now: e
|
|
2684
|
-
}), this.identity.tabId = e, this.diagnostics
|
|
2685
|
-
sessionStorage.setItem(Pe, e);
|
|
2686
|
-
}), this.builder.invalidateResource();
|
|
931
|
+
}), this.identity.tabId = e, je(e, this.diagnostics, this.stores), this.builder.invalidateResource();
|
|
2687
932
|
}
|
|
2688
933
|
async queueDepth() {
|
|
2689
|
-
return await this.
|
|
934
|
+
return await this.senderLoad, await this.sender?.queueDepth() ?? 0;
|
|
2690
935
|
}
|
|
2691
936
|
async flush() {
|
|
2692
|
-
if (this.
|
|
937
|
+
if (this.role() === "forwarder") {
|
|
2693
938
|
let e = this.forwardBuffer;
|
|
2694
|
-
this.forwardBuffer = [], e.length > 0 && this.bus
|
|
2695
|
-
|
|
2696
|
-
}
|
|
2697
|
-
let e = this.pipeline?.drainPending();
|
|
2698
|
-
if (!(!e || !this.transport)) try {
|
|
2699
|
-
await this.transport.send(e);
|
|
2700
|
-
} catch (t) {
|
|
2701
|
-
await this.diagnostics.guardAsync("storage.degraded", "persisting the batch drained by flush()", async () => {
|
|
2702
|
-
await this.retry?.storeFailed({
|
|
2703
|
-
...e,
|
|
2704
|
-
attempts: e.attempts + 1
|
|
2705
|
-
}, t);
|
|
2706
|
-
}), this.diagnostics.report("transport.http_error", "the batch drained by flush() was stored for retry instead of being delivered", {
|
|
2707
|
-
batchId: e.id,
|
|
2708
|
-
records: e.records.length
|
|
2709
|
-
}, t);
|
|
2710
|
-
}
|
|
939
|
+
this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
|
|
940
|
+
} else await this.senderLoad, await this.sender?.flush();
|
|
2711
941
|
}
|
|
2712
|
-
},
|
|
2713
|
-
function
|
|
2714
|
-
return
|
|
942
|
+
}, Y = /* @__PURE__ */ new Map();
|
|
943
|
+
function X() {
|
|
944
|
+
return (J.current() ?? J.stopped()) || J.configure({});
|
|
2715
945
|
}
|
|
2716
|
-
function
|
|
2717
|
-
|
|
946
|
+
function ht(e) {
|
|
947
|
+
J.configure(e);
|
|
2718
948
|
}
|
|
2719
|
-
function
|
|
2720
|
-
if (t) return new
|
|
2721
|
-
let n =
|
|
2722
|
-
return n || (n = new
|
|
949
|
+
function Z(e, t) {
|
|
950
|
+
if (t) return new R(X, e, t);
|
|
951
|
+
let n = Y.get(e);
|
|
952
|
+
return n || (n = new R(X, e), Y.set(e, n)), n;
|
|
2723
953
|
}
|
|
2724
|
-
function
|
|
2725
|
-
return
|
|
954
|
+
function Q() {
|
|
955
|
+
return Z("app");
|
|
2726
956
|
}
|
|
2727
|
-
function
|
|
2728
|
-
|
|
957
|
+
function gt(e, t) {
|
|
958
|
+
Q().trace(e, t);
|
|
2729
959
|
}
|
|
2730
|
-
function
|
|
2731
|
-
|
|
960
|
+
function _t(e, t) {
|
|
961
|
+
Q().debug(e, t);
|
|
2732
962
|
}
|
|
2733
|
-
function
|
|
2734
|
-
|
|
963
|
+
function vt(e, t) {
|
|
964
|
+
Q().info(e, t);
|
|
2735
965
|
}
|
|
2736
|
-
function
|
|
2737
|
-
|
|
966
|
+
function yt(e, t) {
|
|
967
|
+
Q().warn(e, t);
|
|
2738
968
|
}
|
|
2739
|
-
function
|
|
2740
|
-
|
|
969
|
+
function bt(e, t, n) {
|
|
970
|
+
Q().error(e, t, n);
|
|
2741
971
|
}
|
|
2742
|
-
function
|
|
2743
|
-
|
|
972
|
+
function xt(e, t) {
|
|
973
|
+
Q().logAction(e, t);
|
|
2744
974
|
}
|
|
2745
|
-
function
|
|
2746
|
-
|
|
975
|
+
function St(e, t) {
|
|
976
|
+
Q().logEvent(e, t);
|
|
2747
977
|
}
|
|
2748
|
-
function
|
|
2749
|
-
|
|
978
|
+
function Ct(e, t, n, r, i) {
|
|
979
|
+
Q().logMetric(e, t, n, r, i);
|
|
2750
980
|
}
|
|
2751
|
-
function
|
|
2752
|
-
return
|
|
981
|
+
function wt(e, t, n) {
|
|
982
|
+
return Q().timeSync(e, t, n);
|
|
2753
983
|
}
|
|
2754
|
-
function
|
|
2755
|
-
return
|
|
984
|
+
function Tt(e, t, n) {
|
|
985
|
+
return Q().timeAsync(e, t, n);
|
|
2756
986
|
}
|
|
2757
|
-
function
|
|
2758
|
-
|
|
987
|
+
function Et(e, t) {
|
|
988
|
+
X().context.set(e, t);
|
|
2759
989
|
}
|
|
2760
|
-
function
|
|
2761
|
-
|
|
990
|
+
function $(e) {
|
|
991
|
+
X().context.setMany(e);
|
|
2762
992
|
}
|
|
2763
|
-
function
|
|
2764
|
-
|
|
993
|
+
function Dt(e) {
|
|
994
|
+
X().context.remove(e);
|
|
2765
995
|
}
|
|
2766
|
-
function
|
|
2767
|
-
return
|
|
996
|
+
function Ot(e, t) {
|
|
997
|
+
return X().journey.start(e, t);
|
|
2768
998
|
}
|
|
2769
|
-
function
|
|
2770
|
-
|
|
999
|
+
function kt() {
|
|
1000
|
+
X().journey.end();
|
|
2771
1001
|
}
|
|
2772
|
-
function
|
|
2773
|
-
return
|
|
1002
|
+
function At() {
|
|
1003
|
+
return X().journey.current();
|
|
2774
1004
|
}
|
|
2775
|
-
function
|
|
2776
|
-
return
|
|
1005
|
+
function jt() {
|
|
1006
|
+
return X().journey.getToken();
|
|
2777
1007
|
}
|
|
2778
|
-
function
|
|
2779
|
-
return
|
|
1008
|
+
function Mt(e) {
|
|
1009
|
+
return X().journey.adopt(e, "manual", !0);
|
|
2780
1010
|
}
|
|
2781
|
-
function
|
|
2782
|
-
|
|
1011
|
+
function Nt(e) {
|
|
1012
|
+
X().registerWorker(e);
|
|
2783
1013
|
}
|
|
2784
|
-
function
|
|
2785
|
-
|
|
1014
|
+
function Pt() {
|
|
1015
|
+
X().tracing.rotate("explicit");
|
|
2786
1016
|
}
|
|
2787
|
-
function
|
|
2788
|
-
return
|
|
1017
|
+
function Ft() {
|
|
1018
|
+
return X().tracing.headers();
|
|
2789
1019
|
}
|
|
2790
|
-
function
|
|
2791
|
-
return
|
|
1020
|
+
function It() {
|
|
1021
|
+
return X().flush();
|
|
2792
1022
|
}
|
|
2793
|
-
function
|
|
2794
|
-
return
|
|
1023
|
+
function Lt() {
|
|
1024
|
+
return X().queueDepth();
|
|
2795
1025
|
}
|
|
2796
|
-
function
|
|
2797
|
-
return
|
|
1026
|
+
function Rt() {
|
|
1027
|
+
return X().diagnostics.snapshot();
|
|
2798
1028
|
}
|
|
2799
|
-
async function
|
|
2800
|
-
|
|
2801
|
-
Z.clear(), await e?.destroy();
|
|
1029
|
+
async function zt() {
|
|
1030
|
+
await J.current()?.destroy();
|
|
2802
1031
|
}
|
|
2803
1032
|
//#endregion
|
|
2804
|
-
export {
|
|
1033
|
+
export { R as OneLogger, Mt as adoptJourney, ht as configure, At as currentJourney, _t as debug, kt as endJourney, bt as error, It as flush, Rt as getDiagnosticCounters, jt as getJourneyToken, Z as getLogger, Lt as getQueueDepth, Ft as getTraceHeaders, vt as info, xt as logAction, St as logEvent, Ct as logMetric, Nt as registerWorker, Dt as removeContext, Et as setContext, $ as setContextMap, zt as shutdown, Ot as startJourney, Pt as startTrace, Tt as timeAsync, wt as timeSync, gt as trace, yt as warn };
|
|
2805
1034
|
|
|
2806
1035
|
//# sourceMappingURL=index.js.map
|