@utk09/ui-observability 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +189 -25
  3. package/dist/bus/bus.d.ts +30 -0
  4. package/dist/bus-CUXRY0JR.cjs +2 -0
  5. package/dist/bus-CUXRY0JR.cjs.map +1 -0
  6. package/dist/{bus-BTMuVkDk.js → bus-DPDrlUBY.js} +96 -50
  7. package/dist/bus-DPDrlUBY.js.map +1 -0
  8. package/dist/capture/console.d.ts +37 -0
  9. package/dist/capture/errors.d.ts +2 -4
  10. package/dist/capture/long-frames.d.ts +31 -0
  11. package/dist/capture/storm.d.ts +17 -0
  12. package/dist/capture/types.d.ts +2 -0
  13. package/dist/console-CNljJict.js +81 -0
  14. package/dist/console-CNljJict.js.map +1 -0
  15. package/dist/console-PKzc-FmR.cjs +2 -0
  16. package/dist/console-PKzc-FmR.cjs.map +1 -0
  17. package/dist/constants-B28fDv2F.cjs +2 -0
  18. package/dist/constants-B28fDv2F.cjs.map +1 -0
  19. package/dist/constants-Bu49bm39.js +93 -0
  20. package/dist/constants-Bu49bm39.js.map +1 -0
  21. package/dist/constants.d.ts +35 -5
  22. package/dist/core/breadcrumbs.d.ts +1 -1
  23. package/dist/core/pipeline.d.ts +2 -2
  24. package/dist/core/record.d.ts +3 -0
  25. package/dist/core/remote-rules.d.ts +17 -0
  26. package/dist/core/remote-sampling.d.ts +65 -0
  27. package/dist/core/runtime.d.ts +10 -4
  28. package/dist/core/sampling.d.ts +5 -2
  29. package/dist/core/sender.d.ts +3 -0
  30. package/dist/errors-C78ZTjet.cjs +3 -0
  31. package/dist/errors-C78ZTjet.cjs.map +1 -0
  32. package/dist/{errors-Dwm2SzBa.js → errors-Dnc-X4Ec.js} +19 -20
  33. package/dist/errors-Dnc-X4Ec.js.map +1 -0
  34. package/dist/global-scope-BN-Io_yv.cjs +2 -0
  35. package/dist/global-scope-BN-Io_yv.cjs.map +1 -0
  36. package/dist/global-scope-dp2jADRl.js +19 -0
  37. package/dist/global-scope-dp2jADRl.js.map +1 -0
  38. package/dist/index.cjs +1 -1
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.ts +2 -0
  41. package/dist/index.js +307 -241
  42. package/dist/index.js.map +1 -1
  43. package/dist/indexeddb-storage-D0p3iMD0.cjs +2 -0
  44. package/dist/{indexeddb-storage-B5dwq4hW.cjs.map → indexeddb-storage-D0p3iMD0.cjs.map} +1 -1
  45. package/dist/{indexeddb-storage-DjY4Ml6t.js → indexeddb-storage-uD4oaRMc.js} +10 -10
  46. package/dist/{indexeddb-storage-DjY4Ml6t.js.map → indexeddb-storage-uD4oaRMc.js.map} +1 -1
  47. package/dist/{interactions-DVom6eYn.cjs → interactions-CsE2y_fQ.cjs} +2 -2
  48. package/dist/{interactions-DVom6eYn.cjs.map → interactions-CsE2y_fQ.cjs.map} +1 -1
  49. package/dist/{interactions-DZmLu7l2.js → interactions-igKTAJvj.js} +2 -2
  50. package/dist/{interactions-DZmLu7l2.js.map → interactions-igKTAJvj.js.map} +1 -1
  51. package/dist/library-request-Br_T09Bn.cjs +2 -0
  52. package/dist/library-request-Br_T09Bn.cjs.map +1 -0
  53. package/dist/library-request-Dt0fXhcn.js +14 -0
  54. package/dist/library-request-Dt0fXhcn.js.map +1 -0
  55. package/dist/long-frames-6pnjWSSR.js +65 -0
  56. package/dist/long-frames-6pnjWSSR.js.map +1 -0
  57. package/dist/long-frames-DahhqM6u.cjs +2 -0
  58. package/dist/long-frames-DahhqM6u.cjs.map +1 -0
  59. package/dist/models/bus.d.ts +16 -0
  60. package/dist/models/config.d.ts +120 -6
  61. package/dist/network-CZ0aFUsy.cjs +2 -0
  62. package/dist/network-CZ0aFUsy.cjs.map +1 -0
  63. package/dist/{network-C4d2uw2Z.js → network-aSNbwpue.js} +16 -15
  64. package/dist/network-aSNbwpue.js.map +1 -0
  65. package/dist/{platform-CY8S3hUs.js → platform-BwbMRwHm.js} +7 -7
  66. package/dist/{platform-CY8S3hUs.js.map → platform-BwbMRwHm.js.map} +1 -1
  67. package/dist/{platform-CXio0W2n.cjs → platform-D_XkVIF6.cjs} +2 -2
  68. package/dist/{platform-CXio0W2n.cjs.map → platform-D_XkVIF6.cjs.map} +1 -1
  69. package/dist/remote-rules-5UA23alm.js +86 -0
  70. package/dist/remote-rules-5UA23alm.js.map +1 -0
  71. package/dist/remote-rules-rJJZKVG8.cjs +2 -0
  72. package/dist/remote-rules-rJJZKVG8.cjs.map +1 -0
  73. package/dist/sampling-E4x92Nn2.cjs +2 -0
  74. package/dist/sampling-E4x92Nn2.cjs.map +1 -0
  75. package/dist/sampling-J1eahbfT.js +160 -0
  76. package/dist/sampling-J1eahbfT.js.map +1 -0
  77. package/dist/sanitize-BMhh8ghJ.cjs +2 -0
  78. package/dist/sanitize-BMhh8ghJ.cjs.map +1 -0
  79. package/dist/sanitize-UJ-4Lb0n.js +114 -0
  80. package/dist/sanitize-UJ-4Lb0n.js.map +1 -0
  81. package/dist/sender-B6ufz26f.cjs +3 -0
  82. package/dist/sender-B6ufz26f.cjs.map +1 -0
  83. package/dist/{sender-dpvR_bHM.js → sender-G6v4Uqi4.js} +304 -219
  84. package/dist/sender-G6v4Uqi4.js.map +1 -0
  85. package/dist/storm-BtzgLOCX.cjs +2 -0
  86. package/dist/storm-BtzgLOCX.cjs.map +1 -0
  87. package/dist/storm-DJkEZP_8.js +10 -0
  88. package/dist/storm-DJkEZP_8.js.map +1 -0
  89. package/dist/transport/custom-transport.d.ts +20 -0
  90. package/dist/transport/errors.d.ts +2 -1
  91. package/dist/transport/exit-flush.d.ts +15 -0
  92. package/dist/transport/http-transport.d.ts +2 -24
  93. package/dist/transport/memory-transport.d.ts +30 -0
  94. package/dist/transport/retry-engine.d.ts +2 -2
  95. package/dist/transport/serializers/select.d.ts +12 -1
  96. package/dist/transport/status-transport.d.ts +72 -0
  97. package/dist/utils/console.d.ts +7 -6
  98. package/dist/utils/deadline.d.ts +7 -0
  99. package/dist/utils/global-scope.d.ts +20 -0
  100. package/dist/utils/library-console.d.ts +11 -0
  101. package/dist/utils/library-request.d.ts +12 -0
  102. package/package.json +4 -2
  103. package/dist/bus-BTMuVkDk.js.map +0 -1
  104. package/dist/bus-ChIXDAWD.cjs +0 -2
  105. package/dist/bus-ChIXDAWD.cjs.map +0 -1
  106. package/dist/constants-0-YchbAL.js +0 -75
  107. package/dist/constants-0-YchbAL.js.map +0 -1
  108. package/dist/constants-TUFcy95w.cjs +0 -2
  109. package/dist/constants-TUFcy95w.cjs.map +0 -1
  110. package/dist/errors-DRXBRqvm.cjs +0 -3
  111. package/dist/errors-DRXBRqvm.cjs.map +0 -1
  112. package/dist/errors-Dwm2SzBa.js.map +0 -1
  113. package/dist/indexeddb-storage-B5dwq4hW.cjs +0 -2
  114. package/dist/network-C4d2uw2Z.js.map +0 -1
  115. package/dist/network-CuqWadNn.cjs +0 -2
  116. package/dist/network-CuqWadNn.cjs.map +0 -1
  117. package/dist/sampling-CEthcmEX.cjs +0 -2
  118. package/dist/sampling-CEthcmEX.cjs.map +0 -1
  119. package/dist/sampling-CJsI_24L.js +0 -251
  120. package/dist/sampling-CJsI_24L.js.map +0 -1
  121. package/dist/sender-ByFAkXVd.cjs +0 -3
  122. package/dist/sender-ByFAkXVd.cjs.map +0 -1
  123. package/dist/sender-dpvR_bHM.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,55 +1,56 @@
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";
1
+ import { At as e, Bt as t, C as n, Ct as r, D as i, E as a, F as o, Ft as s, Gt as c, It as l, Lt as u, M as d, Mt as f, N as p, Nt as m, Ot as h, Pt as g, Rt as _, T as v, Wt as ee, Zt as te, _ as ne, _t as re, a as y, at as b, c as x, cn as ie, d as ae, dn as oe, fn as se, g as ce, gn as S, h as le, hn as ue, i as de, it as fe, j as C, jt as pe, kt as me, l as w, ln as he, m as ge, mn as _e, n as T, nt as ve, o as E, p as ye, qt as D, r as be, rt as O, s as xe, st as Se, tn as Ce, u as k, un as we, vt as Te, zt as Ee } from "./constants-Bu49bm39.js";
2
+ import { a as De, c as Oe, d as A, f as ke, l as j, m as Ae, n as je, o as M, p as N, r as Me, s as Ne, u as Pe } from "./sampling-J1eahbfT.js";
3
+ import { a as Fe, i as Ie, n as Le, o as P, r as F } from "./sanitize-UJ-4Lb0n.js";
4
+ import { n as Re, r as ze, t as Be } from "./platform-BwbMRwHm.js";
5
+ import { t as Ve } from "./unref-16maCyKA.js";
5
6
  //#region src/utils/timer.ts
6
- function F(e) {
7
- return Math.round((performance.now() - e) * s) / s;
7
+ function I(e) {
8
+ return Math.round((performance.now() - e) * o) / o;
8
9
  }
9
- function I(e, t, n, r, i) {
10
- e.logMetric(`${t}.duration`, F(n), "ms", "histogram", {
10
+ function L(e, t, n, r, i) {
11
+ e.logMetric(`${t}.duration`, I(n), "ms", "histogram", {
11
12
  status: r,
12
13
  ...i
13
14
  });
14
15
  }
15
- function L(e, t, n, r, i) {
16
+ function R(e, t, n, r, i) {
16
17
  e.error(`${t} failed`, r, {
17
- "action.duration_ms": F(n),
18
+ "action.duration_ms": I(n),
18
19
  status: "FAILURE",
19
20
  ...i
20
21
  });
21
22
  }
22
- function Ve(e, t, n, r) {
23
+ function He(e, t, n, r) {
23
24
  let i = performance.now();
24
25
  try {
25
26
  let a = n();
26
- return I(e, t, i, "SUCCESS", r), a;
27
+ return L(e, t, i, "SUCCESS", r), a;
27
28
  } catch (n) {
28
- throw L(e, t, i, n, r), n;
29
+ throw R(e, t, i, n, r), n;
29
30
  }
30
31
  }
31
- async function He(e, t, n, r) {
32
+ async function Ue(e, t, n, r) {
32
33
  let i = performance.now();
33
34
  try {
34
35
  let a = await n();
35
- return I(e, t, i, "SUCCESS", r), a;
36
+ return L(e, t, i, "SUCCESS", r), a;
36
37
  } catch (n) {
37
- throw L(e, t, i, n, r), n;
38
+ throw R(e, t, i, n, r), n;
38
39
  }
39
40
  }
40
41
  //#endregion
41
42
  //#region src/core/logger.ts
42
- function Ue(e, t) {
43
+ function We(e, t) {
43
44
  if (e instanceof Error) return e;
44
45
  let n = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
45
46
  return Error(n ?? typeof e);
46
47
  }
47
- function We(e) {
48
+ function Ge(e) {
48
49
  if (typeof e != "object" || !e || Array.isArray(e) || e instanceof Error) return !1;
49
50
  let t = Object.getPrototypeOf(e);
50
51
  return t === null || Object.getPrototypeOf(t) === null;
51
52
  }
52
- var R = class e {
53
+ var z = class e {
53
54
  bind;
54
55
  namespace;
55
56
  options;
@@ -86,7 +87,7 @@ var R = class e {
86
87
  logEvent = (e, t) => {
87
88
  this.write("INFO", "event", e, t);
88
89
  };
89
- logMetric = (e, t, n = l, r = "gauge", i) => {
90
+ logMetric = (e, t, n = d, r = "gauge", i) => {
90
91
  this.write("INFO", "metric", e, {
91
92
  "metric.name": e,
92
93
  "metric.value": t,
@@ -95,8 +96,8 @@ var R = class e {
95
96
  ...i
96
97
  });
97
98
  };
98
- timeSync = (e, t, n) => Ve(this, e, t, n);
99
- timeAsync = (e, t, n) => He(this, e, t, n);
99
+ timeSync = (e, t, n) => He(this, e, t, n);
100
+ timeAsync = (e, t, n) => Ue(this, e, t, n);
100
101
  write(e, t, n, r) {
101
102
  let i = this.bind();
102
103
  if (i.isDestroyed()) return;
@@ -123,7 +124,7 @@ var R = class e {
123
124
  if (i.isDestroyed()) return;
124
125
  let a = i.builder.isEnabled(e);
125
126
  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
+ let o = r === void 0 && Ge(n), s = o ? n : r, c = o || n === void 0 ? void 0 : We(n, i.diagnostics);
127
128
  if (!a) {
128
129
  this.print(i, e, t, s, c, null);
129
130
  return;
@@ -152,34 +153,36 @@ var R = class e {
152
153
  mirrors(e, t) {
153
154
  return e.config.enabled && e.console.accepts(t);
154
155
  }
155
- }, Ge = {
156
+ }, Ke = {
156
157
  TRACE: "debug",
157
158
  DEBUG: "debug",
158
159
  INFO: "info",
159
160
  WARN: "warn",
160
161
  ERROR: "error",
161
162
  FATAL: "error"
162
- }, Ke = class {
163
- minLevel;
163
+ }, qe = class {
164
+ settings;
164
165
  diagnostics;
165
166
  constructor(e, t) {
166
- this.minLevel = e, this.diagnostics = t;
167
+ this.settings = e, this.diagnostics = t;
167
168
  }
168
169
  update(e) {
169
- this.minLevel = e;
170
+ this.settings = e;
170
171
  }
171
172
  accepts(e) {
172
- return this.minLevel !== null && S[e] >= S[this.minLevel];
173
+ return this.settings.level !== null && b[e] >= b[this.settings.level];
173
174
  }
174
175
  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);
176
+ if (!this.accepts(t) || typeof console > "u" || Fe()) return;
177
+ let o = `%c[%s]%c[${t}]%c`, { styles: s } = this.settings, c = Ke[t];
178
+ this.diagnostics.guard("handler.threw", `The library could not print to console.${c}.`, () => {
179
+ let l = [];
180
+ a !== void 0 && l.push(a), i !== void 0 && l.push(Le(i, r, this.diagnostics)), P(() => {
181
+ console[c](o, s.namespace, e, s[t], "", n, ...l);
182
+ });
180
183
  });
181
184
  }
182
- }, qe = class {
185
+ }, Je = class {
183
186
  value = 0;
184
187
  next() {
185
188
  return ++this.value;
@@ -187,38 +190,38 @@ var R = class e {
187
190
  reset() {
188
191
  this.value = 0;
189
192
  }
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);
193
- }
194
- function Ze() {
195
- return P(16);
193
+ }, Ye = /^[0-9a-f]{32}$/, Xe = /^[0-9a-f]{16}$/, B = /[1-9a-f]/;
194
+ function Ze(e) {
195
+ return Ye.test(e.traceId) && B.test(e.traceId) && Xe.test(e.spanId) && B.test(e.spanId);
196
196
  }
197
197
  function Qe() {
198
- return P(8);
198
+ return A(16);
199
+ }
200
+ function $e() {
201
+ return A(8);
199
202
  }
200
- function B() {
203
+ function V() {
201
204
  return {
202
- traceId: Ze(),
203
- spanId: Qe(),
205
+ traceId: Qe(),
206
+ spanId: $e(),
204
207
  traceFlags: 1,
205
208
  startedAt: Date.now()
206
209
  };
207
210
  }
208
- function V(e) {
211
+ function H(e) {
209
212
  return {
210
213
  traceId: e.traceId,
211
214
  spanId: e.spanId,
212
215
  traceFlags: e.traceFlags
213
216
  };
214
217
  }
215
- var $e = class {
218
+ var et = class {
216
219
  diagnostics;
217
220
  maxAgeMs;
218
221
  load;
219
- ambient = B();
222
+ ambient = V();
220
223
  otel;
221
- constructor(e, t = ve, n) {
224
+ constructor(e, t = se, n) {
222
225
  this.diagnostics = e, this.maxAgeMs = t, this.load = n;
223
226
  }
224
227
  async loadOtel() {
@@ -230,7 +233,7 @@ var $e = class {
230
233
  }
231
234
  resolve() {
232
235
  let e = this.activeSpanContext();
233
- return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), V(this.ambient)) : e;
236
+ return e === void 0 ? (Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), H(this.ambient)) : e;
234
237
  }
235
238
  activeSpanContext() {
236
239
  let e = this.otel;
@@ -238,7 +241,7 @@ var $e = class {
238
241
  let t = e.trace.getActiveSpan();
239
242
  if (t === void 0) return;
240
243
  let n = t.spanContext();
241
- if (Xe(n)) return {
244
+ if (Ze(n)) return {
242
245
  traceId: n.traceId,
243
246
  spanId: n.spanId,
244
247
  traceFlags: n.traceFlags
@@ -246,7 +249,7 @@ var $e = class {
246
249
  });
247
250
  }
248
251
  rotate(e) {
249
- return this.ambient = B(), V(this.ambient);
252
+ return this.ambient = V(), H(this.ambient);
250
253
  }
251
254
  headers() {
252
255
  let e = {}, t = this.otel;
@@ -254,11 +257,11 @@ var $e = class {
254
257
  t.propagation.inject(t.context.active(), e);
255
258
  }), !e.traceparent) {
256
259
  let t = this.resolve(), n = (t.traceFlags & 255).toString(16).padStart(2, "0");
257
- e[re] = `00-${t.traceId}-${t.spanId}-${n}`;
260
+ e[oe] = `00-${t.traceId}-${t.spanId}-${n}`;
258
261
  }
259
262
  return e;
260
263
  }
261
- }, et = class {
264
+ }, tt = class {
262
265
  buffer;
263
266
  pointer = 0;
264
267
  filled = !1;
@@ -278,22 +281,43 @@ var $e = class {
278
281
  };
279
282
  //#endregion
280
283
  //#region src/core/config.ts
281
- function tt(e) {
284
+ function nt(e) {
282
285
  return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
283
286
  }
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);
287
+ function rt(e, t, n) {
288
+ return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || nt(e) ? e : (n.report("config.invalid", `serializer must be "${D}", "ecs" or an implementation. The library uses "${D}".`), D);
286
289
  }
287
- function rt(e, t) {
288
- return e === void 0 ? t : e === !1 ? null : e === !0 ? a : e;
290
+ var it = new Set(Object.keys(i));
291
+ function at(e, t) {
292
+ let n = {}, r = Object.entries(e ?? {});
293
+ for (let [e, i] of r) it.has(e) ? typeof i == "string" ? n[e] = i : t.report("config.invalid", `console.styles.${e} must be a string. The library keeps the style in force.`) : t.report("config.invalid", `The library ignores the unknown console.styles key "${e}". Check the spelling.`);
294
+ return n;
295
+ }
296
+ function ot(e, t, n) {
297
+ return e === void 0 ? t : e === !1 ? {
298
+ level: null,
299
+ styles: t.styles
300
+ } : e === !0 ? {
301
+ level: a,
302
+ styles: t.styles
303
+ } : typeof e == "string" ? {
304
+ level: e,
305
+ styles: t.styles
306
+ } : typeof e != "object" || !e ? (n.report("config.invalid", "console must be a boolean, a level or an object. The console settings in force stay."), t) : {
307
+ level: e.level ?? t.level ?? "DEBUG",
308
+ styles: {
309
+ ...t.styles,
310
+ ...at(e.styles, n)
311
+ }
312
+ };
289
313
  }
290
- function H(e, t, n) {
314
+ function U(e, t, n) {
291
315
  let r = n ?? C, i = {
292
316
  ...r,
293
317
  ...e,
294
318
  endpoint: e.endpoint === void 0 ? r.endpoint : e.endpoint,
295
- serializer: nt(e.serializer, n?.serializer, t),
296
- console: rt(e.console, r.console),
319
+ serializer: rt(e.serializer, n?.serializer, t),
320
+ console: ot(e.console, r.console, t),
297
321
  sampling: {
298
322
  ...r.sampling,
299
323
  ...e.sampling,
@@ -311,36 +335,38 @@ function H(e, t, n) {
311
335
  ...e.capture
312
336
  }
313
337
  };
314
- if (i.endpoint === "") t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
338
+ if (i.transport !== void 0 && typeof i.transport != "function" && (t.report("config.invalid", "transport must be a function. The library ignores the value."), i.transport = r.transport), i.transportOnExit !== void 0 && typeof i.transportOnExit != "function" && (t.report("config.invalid", "transportOnExit must be a function. The library ignores the value."), i.transportOnExit = r.transportOnExit), i.endpoint === "") i.transport === void 0 && t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
315
339
  else if (i.endpoint !== null) try {
316
340
  new URL(i.endpoint);
317
341
  } catch (e) {
318
342
  t.report("config.invalid", `endpoint is not a valid absolute URL: ${i.endpoint}.`, void 0, e);
319
343
  }
320
- i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${k}'.`), k);
344
+ i.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${S}'.`), S);
321
345
  let a = i.sampling.defaultRate;
322
346
  (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);
323
- let o = Object.entries(i.sampling.rates);
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;
347
+ let o = i.sampling.remoteMaxRate;
348
+ (typeof o != "number" || !(o >= 0 && o <= 1)) && (t.report("config.invalid", `sampling.remoteMaxRate must be 0..1. The value is ${String(o)}. The library uses 1.`), i.sampling.remoteMaxRate = 1);
349
+ let s = Object.entries(i.sampling.rates);
350
+ for (let [e, n] of s) (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);
351
+ 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]), st(e, t), i;
326
352
  }
327
- function it(e, t) {
328
- let n = /* @__PURE__ */ new Set([...Object.keys(C), ...ae]);
353
+ function st(e, t) {
354
+ let n = /* @__PURE__ */ new Set([...Object.keys(C), ..._e]);
329
355
  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 _) {
356
+ for (let n of v) {
331
357
  let r = e[n];
332
358
  if (typeof r != "object" || !r) continue;
333
- let i = /* @__PURE__ */ new Set([...Object.keys(C[n]), ...me[n]]);
359
+ let i = /* @__PURE__ */ new Set([...Object.keys(C[n]), ...ue[n]]);
334
360
  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.`);
335
361
  }
336
362
  }
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]);
363
+ function ct(e, t) {
364
+ for (let n of Object.keys(t)) v.includes(n) || Object.assign(e, { [n]: t[n] });
365
+ for (let n of v) Object.assign(e[n], t[n]);
340
366
  }
341
367
  //#endregion
342
368
  //#region src/core/context.ts
343
- var ot = class {
369
+ var lt = class {
344
370
  map = /* @__PURE__ */ new Map();
345
371
  set(e, t) {
346
372
  this.map.set(e, t);
@@ -360,12 +386,12 @@ var ot = class {
360
386
  getAll() {
361
387
  return Object.fromEntries(this.map);
362
388
  }
363
- }, st = class {
389
+ }, ut = class {
364
390
  handler;
365
391
  throttleMs;
366
392
  counters = /* @__PURE__ */ new Map();
367
393
  lastEmitted = /* @__PURE__ */ new Map();
368
- constructor(e, t = d) {
394
+ constructor(e, t = p) {
369
395
  this.handler = e, this.throttleMs = t;
370
396
  }
371
397
  setHandler(e) {
@@ -386,11 +412,15 @@ var ot = class {
386
412
  cause: r,
387
413
  at: a,
388
414
  count: i
389
- };
390
- if (this.handler) try {
391
- this.handler(o);
415
+ }, { handler: s } = this;
416
+ if (s) try {
417
+ P(() => {
418
+ s(o);
419
+ });
392
420
  } catch (e) {
393
- this.count("handler.threw"), typeof console < "u" && console.warn(`${ie} The onDiagnostic handler threw an error.`, e);
421
+ this.count("handler.threw"), typeof console < "u" && P(() => {
422
+ console.warn(`${Se} The onDiagnostic handler threw an error.`, e);
423
+ });
394
424
  }
395
425
  }
396
426
  guard(e, t, n) {
@@ -415,51 +445,51 @@ var ot = class {
415
445
  reset() {
416
446
  this.counters.clear(), this.lastEmitted.clear();
417
447
  }
418
- }, ct = {
419
- maxAgeMs: we,
448
+ }, dt = {
449
+ maxAgeMs: ve,
420
450
  endOnOwnerClose: !1,
421
- urlParam: Se
451
+ urlParam: fe
422
452
  };
423
- function U(e, t) {
453
+ function W(e, t) {
424
454
  let n = Reflect.get(e, t);
425
455
  return typeof n == "string" && n !== "" ? n : void 0;
426
456
  }
427
- function W(e, t) {
457
+ function G(e, t) {
428
458
  let n = Reflect.get(e, t);
429
459
  return typeof n == "number" && Number.isFinite(n) ? n : void 0;
430
460
  }
431
- function lt(e) {
461
+ function ft(e) {
432
462
  if (typeof e != "object" || !e) return null;
433
- let t = U(e, "id"), n = U(e, "name"), r = W(e, "startedAt");
463
+ let t = W(e, "id"), n = W(e, "name"), r = G(e, "startedAt");
434
464
  return t === void 0 || n === void 0 || r === void 0 ? null : {
435
465
  id: t,
436
466
  name: n,
437
467
  startedAt: r,
438
- parentId: U(e, "parentId"),
439
- ownerContextId: U(e, "ownerContextId") ?? ""
468
+ parentId: W(e, "parentId"),
469
+ ownerContextId: W(e, "ownerContextId") ?? ""
440
470
  };
441
471
  }
442
- function ut(e) {
472
+ function pt(e) {
443
473
  if (typeof e != "object" || !e) return null;
444
- let t = U(e, "i"), n = U(e, "n");
474
+ let t = W(e, "i"), n = W(e, "n");
445
475
  return t === void 0 || n === void 0 ? null : {
446
476
  id: t,
447
477
  name: n,
448
- startedAt: W(e, "s") ?? Date.now(),
478
+ startedAt: G(e, "s") ?? Date.now(),
449
479
  parentId: void 0,
450
480
  ownerContextId: ""
451
481
  };
452
482
  }
453
- function dt(e) {
483
+ function mt(e) {
454
484
  let t = JSON.stringify({
455
485
  i: e.id,
456
486
  n: e.name.slice(0, 64),
457
487
  s: e.startedAt
458
488
  }), n = new TextEncoder().encode(t), r = "";
459
489
  for (let e of n) r += String.fromCharCode(e);
460
- return btoa(r).replace(se, "-").replace(ne, "_").replace(ce, "");
490
+ return btoa(r).replace(ce, "-").replace(ne, "_").replace(le, "");
461
491
  }
462
- var ft = class {
492
+ var ht = class {
463
493
  options;
464
494
  diagnostics;
465
495
  contextId;
@@ -467,7 +497,7 @@ var ft = class {
467
497
  stores;
468
498
  journey = null;
469
499
  expiryTimer = null;
470
- constructor(e, t, n, r, i = A) {
500
+ constructor(e, t, n, r, i = M) {
471
501
  this.options = e, this.diagnostics = t, this.contextId = n, this.onLocalChange = r, this.stores = i;
472
502
  }
473
503
  current() {
@@ -476,7 +506,7 @@ var ft = class {
476
506
  async bootstrap() {
477
507
  let e = this.readUrlToken();
478
508
  if (e && this.adopt(e, "url")) return;
479
- let t = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(E));
509
+ let t = this.diagnostics.guard("storage.unavailable", "The library could not read the persisted journey.", () => this.stores.session().getItem(O));
480
510
  if (t && this.restore(t)) return;
481
511
  let n = await this.readOpenFinToken();
482
512
  n !== null && this.adopt(n, "openfin.customData");
@@ -501,7 +531,7 @@ var ft = class {
501
531
  getToken() {
502
532
  let e = this.journey;
503
533
  if (e === null) return;
504
- let t = dt(e);
534
+ let t = mt(e);
505
535
  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
536
  else return t;
507
537
  }
@@ -522,7 +552,7 @@ var ft = class {
522
552
  this.clearTimer();
523
553
  }
524
554
  restore(e) {
525
- let t = lt(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
555
+ let t = ft(this.diagnostics.guard("storage.degraded", "The library could not parse the persisted journey.", () => JSON.parse(e)));
526
556
  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}".`, {
527
557
  source: "sessionStorage",
528
558
  journeyId: t.id
@@ -530,22 +560,22 @@ var ft = class {
530
560
  }
531
561
  decodeToken(e) {
532
562
  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)));
563
+ let t = e.replace(ye, "+").replace(ge, "/"), n = (4 - t.length % 4) % 4, r = "=".repeat(n), i = Uint8Array.from(atob(t + r), (e) => e.charCodeAt(0));
564
+ return pt(JSON.parse(new TextDecoder().decode(i)));
535
565
  }) ?? null;
536
566
  }
537
567
  setJourney(e) {
538
568
  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));
569
+ e === null ? this.stores.session().removeItem(O) : this.stores.session().setItem(O, JSON.stringify(e));
540
570
  }), e === null) return;
541
571
  let t = Math.max(this.options.maxAgeMs - (Date.now() - e.startedAt), 0), n = setTimeout(() => {
542
572
  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();
543
573
  }, t);
544
- this.expiryTimer = n, Be(n);
574
+ this.expiryTimer = n, Ve(n);
545
575
  }
546
576
  clearStored() {
547
577
  this.diagnostics.guard("storage.unavailable", "The library could not clear the persisted journey.", () => {
548
- this.stores.session().removeItem(E);
578
+ this.stores.session().removeItem(O);
549
579
  });
550
580
  }
551
581
  clearTimer() {
@@ -557,16 +587,16 @@ var ft = class {
557
587
  async readOpenFinToken() {
558
588
  let e = globalThis.fin?.me, t = e?.getOptions;
559
589
  if (t === void 0) return null;
560
- let n = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => Ae(t.call(e), le)))?.customData?.[ge];
590
+ let n = (await this.diagnostics.guardAsync("openfin.unavailable", "The library could not read fin.me.getOptions().", () => De(t.call(e), Te)))?.customData?.[re];
561
591
  return typeof n == "string" ? n : null;
562
592
  }
563
593
  };
564
594
  //#endregion
565
595
  //#region src/core/record.ts
566
- function G(e) {
596
+ function K(e) {
567
597
  return e;
568
598
  }
569
- var pt = class {
599
+ var gt = class {
570
600
  deps;
571
601
  resourceCache = null;
572
602
  constructor(e) {
@@ -577,45 +607,47 @@ var pt = class {
577
607
  }
578
608
  isEnabled(e) {
579
609
  let { config: t } = this.deps;
580
- return t.enabled ? S[e] >= S[t.minLevel] : !1;
610
+ if (!t.enabled) return !1;
611
+ let n = this.deps.remote.sampling?.minLevel() ?? t.minLevel;
612
+ return b[e] >= b[n];
581
613
  }
582
614
  build(e) {
583
- let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o } = this.deps;
615
+ let { config: t, diagnostics: n, tracing: r, journey: i, sequence: a, limits: o, remote: s } = this.deps;
584
616
  if (!this.isEnabled(e.level)) return n.count("record.dropped_by_level"), {
585
617
  record: null,
586
618
  dropped: "level"
587
619
  };
588
- let s = r.resolve(), l = i.current();
589
- if (!Fe({
620
+ let c = r.resolve(), l = i.current();
621
+ if (!Me({
590
622
  level: e.level,
591
623
  type: e.type,
592
624
  namespace: e.namespace,
593
625
  journeyId: l?.id ?? "",
594
- traceId: s.traceId
595
- }, t)) return n.count("record.dropped_by_sampling"), {
626
+ traceId: c.traceId
627
+ }, t, s.sampling?.current() ?? null)) return n.count("record.dropped_by_sampling"), {
596
628
  record: null,
597
629
  dropped: "sampling"
598
630
  };
599
- let u = a.next(), d = ze(n), f = t.capture.fullUrls ? d : Re(d), p, m = 0;
631
+ let u = a.next(), d = Be(n), f = t.capture.fullUrls ? d : ze(d), p, m = 0;
600
632
  try {
601
- let t = N(this.deps.context.getAll(), o, n), r = N(e.scoped ?? {}, o, n), i = N(e.payload ?? {}, o, n);
633
+ let t = F(this.deps.context.getAll(), o, n), r = F(e.scoped ?? {}, o, n), i = F(e.payload ?? {}, o, n);
602
634
  m = t.bytes + r.bytes + i.bytes, p = {
603
- ...G(t.value),
604
- ...G(r.value),
605
- ...G(i.value)
635
+ ...K(t.value),
636
+ ...K(r.value),
637
+ ...K(i.value)
606
638
  };
607
639
  } catch (e) {
608
- n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [oe]: !0 };
640
+ n.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), p = { [ae]: !0 };
609
641
  }
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);
642
+ p[w] = e.type, p[x] = u, p[T] = e.namespace, p[k] = f, l && (p[y] = l.id, p[E] = l.name, l.parentId !== void 0 && (p[xe] = l.parentId));
643
+ let h = Ie(e.body, o.maxBodyChars);
612
644
  h !== e.body && n.count("record.truncated");
613
645
  let g = {
614
- timeUnixNano: De(),
615
- traceId: s.traceId,
616
- spanId: s.spanId,
617
- traceFlags: s.traceFlags,
618
- severityNumber: c[e.level],
646
+ timeUnixNano: Ae(),
647
+ traceId: c.traceId,
648
+ spanId: c.spanId,
649
+ traceFlags: c.traceFlags,
650
+ severityNumber: te[e.level],
619
651
  severityText: e.level,
620
652
  body: h,
621
653
  attributes: p,
@@ -628,11 +660,11 @@ var pt = class {
628
660
  dropped: "redact"
629
661
  };
630
662
  if (e !== void 0 && e !== g) {
631
- if (M(e)) {
632
- let t = N(e.attributes, o, n);
663
+ if (N(e)) {
664
+ let t = F(e.attributes, o, n);
633
665
  g = {
634
666
  ...e,
635
- attributes: G(t.value)
667
+ attributes: K(t.value)
636
668
  }, m = t.bytes;
637
669
  } else n.report("record.sanitize_failed", "The redact hook returned a value that is not a record. The library keeps the original record.");
638
670
  }
@@ -646,39 +678,41 @@ var pt = class {
646
678
  [w]: e.type,
647
679
  [x]: u,
648
680
  [T]: e.namespace,
649
- [O]: f,
650
- [ue]: !0,
681
+ [k]: f,
682
+ [de]: !0,
651
683
  [be]: m
652
684
  };
653
- l && (t[y] = l.id, t[D] = l.name), g.attributes = t;
685
+ l && (t[y] = l.id, t[E] = l.name), g.attributes = t;
654
686
  }
655
687
  return { record: g };
656
688
  }
657
689
  resource() {
658
690
  if (this.resourceCache) return this.resourceCache;
659
- let { config: t, identity: r, platform: a } = this.deps;
691
+ let { config: n, identity: r, platform: i } = this.deps;
660
692
  return this.resourceCache = {
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 }
693
+ [g]: n.serviceName,
694
+ [s]: n.serviceVersion,
695
+ [e]: n.environment,
696
+ [Ee]: he,
697
+ [t]: we,
698
+ [_]: ie,
699
+ [pe]: i.platform,
700
+ [l]: r.sessionId,
701
+ [u]: r.tabId,
702
+ [me]: r.contextId,
703
+ [h]: i.userAgent,
704
+ ...i.openfinUuid === void 0 ? {} : { [m]: i.openfinUuid },
705
+ ...i.openfinName === void 0 ? {} : { [f]: i.openfinName }
674
706
  }, this.resourceCache;
675
707
  }
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 {
708
+ }, _t = {
709
+ errors: async () => (await import("./errors-Dnc-X4Ec.js")).ErrorCapture,
710
+ network: async () => (await import("./network-aSNbwpue.js")).NetworkCapture,
711
+ interactions: async () => (await import("./interactions-igKTAJvj.js")).InteractionCapture,
712
+ webVitals: async () => (await import("./web-vitals-DHZ0yA_H.js")).WebVitalsCapture,
713
+ longFrames: async () => (await import("./long-frames-6pnjWSSR.js")).LongFrameCapture,
714
+ console: async () => (await import("./console-CNljJict.js")).ConsoleCapture
715
+ }, q = Symbol.for(ee), J = Symbol.for(c), Y = class e {
682
716
  diagnostics;
683
717
  config;
684
718
  platform;
@@ -686,12 +720,13 @@ var pt = class {
686
720
  stores;
687
721
  identityBuiltAs;
688
722
  sessionTouch;
689
- context = new ot();
723
+ context = new lt();
690
724
  breadcrumbs;
691
725
  tracing;
692
- sequence = new qe();
726
+ sequence = new Je();
693
727
  journey;
694
728
  builder;
729
+ remote = { sampling: null };
695
730
  console;
696
731
  bus = null;
697
732
  busBuilt;
@@ -704,21 +739,24 @@ var pt = class {
704
739
  captureGeneration = 0;
705
740
  captureOnce = {
706
741
  webVitals: !1,
707
- navigationTiming: !1
742
+ navigationTiming: !1,
743
+ longFrames: !1
708
744
  };
709
745
  bootBuffer = [];
710
746
  forwardBuffer = [];
711
747
  forwardScheduled = !1;
712
748
  roleResolved = !1;
749
+ started = Promise.resolve();
713
750
  ready = !1;
714
751
  destroyed = !1;
715
752
  lastGapAt = 0;
716
753
  constructor(e) {
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) => {
754
+ this.diagnostics = new ut(e.onDiagnostic), this.platform = Re(this.diagnostics), this.config = U(e, this.diagnostics), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" ? Oe() : M, this.identity = ke(this.diagnostics, this.stores), this.sessionTouch = new Ne(this.diagnostics, this.stores), this.breadcrumbs = new tt(50), this.tracing = new et(this.diagnostics, void 0, this.config.otelLoader), this.tracing.loadOtel(), this.console = new qe(this.config.console, this.diagnostics), this.journey = new ht(dt, this.diagnostics, this.identity.contextId, (e) => {
718
755
  this.bus?.broadcastJourney(e);
719
- }, this.stores), this.builder = new pt({
756
+ }, this.stores), this.builder = new gt({
757
+ remote: this.remote,
720
758
  config: this.config,
721
- limits: b,
759
+ limits: r,
722
760
  diagnostics: this.diagnostics,
723
761
  context: this.context,
724
762
  journey: this.journey,
@@ -736,10 +774,10 @@ var pt = class {
736
774
  });
737
775
  };
738
776
  static current() {
739
- return globalThis[K] ?? null;
777
+ return globalThis[q] ?? null;
740
778
  }
741
779
  static stopped() {
742
- return globalThis[q] ?? null;
780
+ return globalThis[J] ?? null;
743
781
  }
744
782
  isDestroyed() {
745
783
  return this.destroyed;
@@ -748,21 +786,23 @@ var pt = class {
748
786
  let n = e.current();
749
787
  if (n && !n.destroyed) return n.reconfigure(t), n;
750
788
  let r = new e(t);
751
- return globalThis[K] = r, Reflect.deleteProperty(globalThis, q), r.init(), r;
789
+ return globalThis[q] = r, Reflect.deleteProperty(globalThis, J), r.init(), r;
752
790
  }
753
791
  reconfigure(e) {
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.");
792
+ let t = this.keepDestination(e);
793
+ ct(this.config, U(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.");
756
794
  }
757
795
  keepBuiltStorage() {
758
796
  let e = this.storageBuiltAs;
759
797
  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
798
  }
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,
799
+ keepDestination(e) {
800
+ if (this.senderLoad === void 0) return e;
801
+ let t = e;
802
+ return "transport" in e && e.transport === void 0 != (this.config.transport === void 0) && (this.diagnostics.report("config.invalid", "You cannot add or remove transport after the delivery stack loads. The transport in force stays."), t = { ...t }, delete t.transport), (t.endpoint === null || t.endpoint === "") && this.config.transport === void 0 && (this.diagnostics.report("config.invalid", "You cannot remove the endpoint after the delivery stack loads. The endpoint in force stays."), t = {
803
+ ...t,
764
804
  endpoint: void 0
765
- });
805
+ }), t;
766
806
  }
767
807
  keepBuiltIdentity() {
768
808
  let e = this.identityBuiltAs;
@@ -770,6 +810,9 @@ var pt = class {
770
810
  }
771
811
  async init() {
772
812
  let e = this.installCaptures();
813
+ this.started = this.boot(), await this.started, await e;
814
+ }
815
+ async boot() {
773
816
  try {
774
817
  let e = this.journey.bootstrap();
775
818
  this.config.bus.mode !== "off" && await this.ensureBus(), this.roleResolved = !0, await this.syncSender(), await e;
@@ -778,7 +821,6 @@ var pt = class {
778
821
  } finally {
779
822
  this.ready = !0, this.releaseBootBuffer();
780
823
  }
781
- await e;
782
824
  }
783
825
  ensureBus() {
784
826
  return this.busLoad ??= this.startBus(), this.busLoad;
@@ -797,7 +839,7 @@ var pt = class {
797
839
  }
798
840
  async buildBus() {
799
841
  try {
800
- let { Bus: e } = await import("./bus-BTMuVkDk.js");
842
+ let { Bus: e } = await import("./bus-DPDrlUBY.js");
801
843
  if (this.destroyed) return null;
802
844
  let t = new e(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
803
845
  onRecords: (e) => {
@@ -809,7 +851,8 @@ var pt = class {
809
851
  onJourneyRequest: () => this.journey.current(),
810
852
  onTabConflict: () => {
811
853
  this.regenerateTabId();
812
- }
854
+ },
855
+ remote: this.remote
813
856
  });
814
857
  return this.bus = t, t;
815
858
  } catch (e) {
@@ -820,7 +863,7 @@ var pt = class {
820
863
  return this.bus?.getRole() ?? "sender";
821
864
  }
822
865
  syncSender() {
823
- return !this.config.endpoint || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
866
+ return !(this.config.endpoint || this.config.transport !== void 0) || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
824
867
  }
825
868
  loadSender() {
826
869
  return this.senderLoad ??= this.buildSender(), this.senderLoad;
@@ -828,10 +871,11 @@ var pt = class {
828
871
  async buildSender() {
829
872
  this.storageBuiltAs = this.config.storage;
830
873
  try {
831
- let { Sender: e } = await import("./sender-dpvR_bHM.js"), t = this.destroyed ? null : await e.create({
874
+ let { Sender: e } = await import("./sender-G6v4Uqi4.js"), t = this.destroyed ? null : await e.create({
832
875
  config: this.config,
833
876
  diagnostics: this.diagnostics,
834
- onGap: this.reportGap
877
+ onGap: this.reportGap,
878
+ remote: this.remote
835
879
  });
836
880
  if (!t || this.destroyed) {
837
881
  await t?.destroy();
@@ -846,8 +890,8 @@ var pt = class {
846
890
  for (let t of e) this.sender?.push(t);
847
891
  }
848
892
  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");
893
+ let e = ++this.captureGeneration, t = this.config.capture, r = [];
894
+ (t.errors || t.rejections || t.resourceErrors) && r.push("errors"), (t.fetch || t.xhr) && r.push("network"), (t.interactions || t.navigation) && r.push("interactions"), t.webVitals && r.push("webVitals"), t.longFrames && r.push("longFrames"), (Array.isArray(t.console) ? t.console.length > 0 : t.console) && r.push("console");
851
895
  let i = await Promise.all(r.map((e) => this.loadCapture(e)));
852
896
  if (e !== this.captureGeneration || this.destroyed) return;
853
897
  this.uninstallCaptures();
@@ -856,7 +900,7 @@ var pt = class {
856
900
  diagnostics: this.diagnostics,
857
901
  breadcrumbs: this.breadcrumbs,
858
902
  tracing: this.tracing,
859
- logger: new R(() => this, t),
903
+ logger: new z(() => this, n),
860
904
  once: this.captureOnce
861
905
  };
862
906
  for (let e of i) e && this.captures.push(new e(a));
@@ -871,7 +915,7 @@ var pt = class {
871
915
  this.captures.length = 0;
872
916
  }
873
917
  loadCapture(e) {
874
- return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, mt[e]);
918
+ return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, _t[e]);
875
919
  }
876
920
  registerWorker(e) {
877
921
  this.destroyed || this.constructBus().then((t) => {
@@ -884,7 +928,7 @@ var pt = class {
884
928
  if (this.destroyed) return;
885
929
  this.destroyed = !0, this.uninstallCaptures();
886
930
  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);
931
+ this.journey.destroy(), this.bus?.destroy(), this.forwardBuffer = [], this.pendingRecords = [], await t, await this.senderLoad, e.current() === this && (Reflect.deleteProperty(globalThis, q), globalThis[J] = this);
888
932
  }
889
933
  emit(e) {
890
934
  e && !this.destroyed && (this.sessionTouch.touch(this.identity.sessionId), this.ready ? this.route(e) : this.pushCapped(this.bootBuffer, e));
@@ -907,7 +951,7 @@ var pt = class {
907
951
  }
908
952
  ingestForwarded(e) {
909
953
  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");
954
+ else for (let t of e) N(t) ? je(t, this.config, this.remote.sampling?.current() ?? null) ? this.deliver(t) : this.diagnostics.count("record.dropped_by_sampling") : this.diagnostics.count("record.dropped_malformed");
911
955
  }
912
956
  releaseBootBuffer() {
913
957
  let e = this.bootBuffer;
@@ -917,7 +961,7 @@ var pt = class {
917
961
  }
918
962
  reportGap = (e) => {
919
963
  let t = Date.now();
920
- t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new R(() => this, te).warn("stored records were dropped before delivery", {
964
+ t - this.lastGapAt < 6e4 || (this.lastGapAt = t, new z(() => this, Ce).warn("stored records were dropped before delivery", {
921
965
  "gap.batches": e.batches,
922
966
  "gap.records": e.records,
923
967
  "gap.reason": e.reason
@@ -928,108 +972,130 @@ var pt = class {
928
972
  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.", {
929
973
  was: this.identity.tabId,
930
974
  now: e
931
- }), this.identity.tabId = e, je(e, this.diagnostics, this.stores), this.builder.invalidateResource();
975
+ }), this.identity.tabId = e, Pe(e, this.diagnostics, this.stores), this.builder.invalidateResource();
932
976
  }
933
977
  async queueDepth() {
934
978
  return await this.senderLoad, await this.sender?.queueDepth() ?? 0;
935
979
  }
936
980
  async flush() {
937
- if (this.role() === "forwarder") {
981
+ if (this.ready || await this.started, this.role() === "forwarder") {
938
982
  let e = this.forwardBuffer;
939
983
  this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
940
984
  } else await this.senderLoad, await this.sender?.flush();
941
985
  }
942
- }, Y = /* @__PURE__ */ new Map();
943
- function X() {
944
- return (J.current() ?? J.stopped()) || J.configure({});
945
- }
946
- function ht(e) {
947
- J.configure(e);
948
- }
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;
953
- }
954
- function Q() {
955
- return Z("app");
986
+ };
987
+ //#endregion
988
+ //#region src/transport/memory-transport.ts
989
+ function vt() {
990
+ let e = [], t = [], n = { status: 200 };
991
+ return {
992
+ transport: (r) => (e.push(r), n.status >= 200 && n.status < 300 && t.push(r), Promise.resolve({ ...n })),
993
+ records: () => t.flatMap((e) => [...e.records]),
994
+ batches: () => [...e],
995
+ clear: () => {
996
+ e.length = 0, t.length = 0;
997
+ },
998
+ respondWith: (e, t) => {
999
+ n = t === void 0 ? { status: e } : {
1000
+ status: e,
1001
+ retryAfterMs: t
1002
+ };
1003
+ }
1004
+ };
956
1005
  }
957
- function gt(e, t) {
958
- Q().trace(e, t);
1006
+ //#endregion
1007
+ //#region src/index.ts
1008
+ var X = /* @__PURE__ */ new Map();
1009
+ function Z() {
1010
+ return (Y.current() ?? Y.stopped()) || Y.configure({});
959
1011
  }
960
- function _t(e, t) {
961
- Q().debug(e, t);
1012
+ function yt(e) {
1013
+ Y.configure(e);
962
1014
  }
963
- function vt(e, t) {
964
- Q().info(e, t);
1015
+ function Q(e, t) {
1016
+ if (t) return new z(Z, e, t);
1017
+ let n = X.get(e);
1018
+ return n || (n = new z(Z, e), X.set(e, n)), n;
965
1019
  }
966
- function yt(e, t) {
967
- Q().warn(e, t);
1020
+ function $() {
1021
+ return Q("app");
968
1022
  }
969
- function bt(e, t, n) {
970
- Q().error(e, t, n);
1023
+ function bt(e, t) {
1024
+ $().trace(e, t);
971
1025
  }
972
1026
  function xt(e, t) {
973
- Q().logAction(e, t);
1027
+ $().debug(e, t);
974
1028
  }
975
1029
  function St(e, t) {
976
- Q().logEvent(e, t);
1030
+ $().info(e, t);
977
1031
  }
978
- function Ct(e, t, n, r, i) {
979
- Q().logMetric(e, t, n, r, i);
1032
+ function Ct(e, t) {
1033
+ $().warn(e, t);
980
1034
  }
981
1035
  function wt(e, t, n) {
982
- return Q().timeSync(e, t, n);
1036
+ $().error(e, t, n);
983
1037
  }
984
- function Tt(e, t, n) {
985
- return Q().timeAsync(e, t, n);
1038
+ function Tt(e, t) {
1039
+ $().logAction(e, t);
986
1040
  }
987
1041
  function Et(e, t) {
988
- X().context.set(e, t);
1042
+ $().logEvent(e, t);
989
1043
  }
990
- function $(e) {
991
- X().context.setMany(e);
1044
+ function Dt(e, t, n, r, i) {
1045
+ $().logMetric(e, t, n, r, i);
992
1046
  }
993
- function Dt(e) {
994
- X().context.remove(e);
1047
+ function Ot(e, t, n) {
1048
+ return $().timeSync(e, t, n);
995
1049
  }
996
- function Ot(e, t) {
997
- return X().journey.start(e, t);
1050
+ function kt(e, t, n) {
1051
+ return $().timeAsync(e, t, n);
998
1052
  }
999
- function kt() {
1000
- X().journey.end();
1053
+ function At(e, t) {
1054
+ Z().context.set(e, t);
1001
1055
  }
1002
- function At() {
1003
- return X().journey.current();
1004
- }
1005
- function jt() {
1006
- return X().journey.getToken();
1056
+ function jt(e) {
1057
+ Z().context.setMany(e);
1007
1058
  }
1008
1059
  function Mt(e) {
1009
- return X().journey.adopt(e, "manual", !0);
1060
+ Z().context.remove(e);
1010
1061
  }
1011
- function Nt(e) {
1012
- X().registerWorker(e);
1062
+ function Nt(e, t) {
1063
+ return Z().journey.start(e, t);
1013
1064
  }
1014
1065
  function Pt() {
1015
- X().tracing.rotate("explicit");
1066
+ Z().journey.end();
1016
1067
  }
1017
1068
  function Ft() {
1018
- return X().tracing.headers();
1069
+ return Z().journey.current();
1019
1070
  }
1020
1071
  function It() {
1021
- return X().flush();
1072
+ return Z().journey.getToken();
1073
+ }
1074
+ function Lt(e) {
1075
+ return Z().journey.adopt(e, "manual", !0);
1076
+ }
1077
+ function Rt(e) {
1078
+ Z().registerWorker(e);
1079
+ }
1080
+ function zt() {
1081
+ Z().tracing.rotate("explicit");
1082
+ }
1083
+ function Bt() {
1084
+ return Z().tracing.headers();
1085
+ }
1086
+ function Vt() {
1087
+ return Z().flush();
1022
1088
  }
1023
- function Lt() {
1024
- return X().queueDepth();
1089
+ function Ht() {
1090
+ return Z().queueDepth();
1025
1091
  }
1026
- function Rt() {
1027
- return X().diagnostics.snapshot();
1092
+ function Ut() {
1093
+ return Z().diagnostics.snapshot();
1028
1094
  }
1029
- async function zt() {
1030
- await J.current()?.destroy();
1095
+ async function Wt() {
1096
+ await Y.current()?.destroy();
1031
1097
  }
1032
1098
  //#endregion
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 };
1099
+ export { z as OneLogger, Lt as adoptJourney, yt as configure, vt as createMemoryTransport, Ft as currentJourney, xt as debug, Pt as endJourney, wt as error, Vt as flush, Ut as getDiagnosticCounters, It as getJourneyToken, Q as getLogger, Ht as getQueueDepth, Bt as getTraceHeaders, St as info, Tt as logAction, Et as logEvent, Dt as logMetric, Rt as registerWorker, Mt as removeContext, At as setContext, jt as setContextMap, Wt as shutdown, Nt as startJourney, zt as startTrace, kt as timeAsync, Ot as timeSync, bt as trace, Ct as warn };
1034
1100
 
1035
1101
  //# sourceMappingURL=index.js.map