@utk09/ui-observability 0.11.0 → 1.0.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 (557) hide show
  1. package/CHANGELOG.md +481 -0
  2. package/README.md +73 -669
  3. package/bin/uiobs.mjs +1 -1
  4. package/dist/{batch-CL9uWYY3.js → batch-CXmPmTse.js} +3 -3
  5. package/dist/batch-CXmPmTse.js.map +1 -0
  6. package/dist/{batch-C8OcWR2L.cjs → batch-mmPigCpi.cjs} +2 -2
  7. package/dist/batch-mmPigCpi.cjs.map +1 -0
  8. package/dist/bus/bus.d.cts +331 -0
  9. package/dist/bus/bus.d.ts +108 -57
  10. package/dist/bus/links.d.cts +132 -0
  11. package/dist/bus/links.d.ts +22 -7
  12. package/dist/bus/validation.d.cts +16 -0
  13. package/dist/bus/validation.d.ts +11 -2
  14. package/dist/bus-C39wspFV.js +775 -0
  15. package/dist/bus-C39wspFV.js.map +1 -0
  16. package/dist/bus-_EaOVPGq.cjs +2 -0
  17. package/dist/bus-_EaOVPGq.cjs.map +1 -0
  18. package/dist/capture/console.d.cts +37 -0
  19. package/dist/capture/console.d.ts +11 -11
  20. package/dist/capture/errors.d.cts +32 -0
  21. package/dist/capture/errors.d.ts +7 -7
  22. package/dist/capture/interactions.d.cts +48 -0
  23. package/dist/capture/interactions.d.ts +15 -15
  24. package/dist/capture/lifecycle.d.cts +20 -0
  25. package/dist/capture/lifecycle.d.ts +4 -4
  26. package/dist/capture/long-frames.d.cts +31 -0
  27. package/dist/capture/long-frames.d.ts +7 -7
  28. package/dist/capture/network.d.cts +57 -0
  29. package/dist/capture/network.d.ts +18 -18
  30. package/dist/capture/profiler-frames.d.cts +44 -0
  31. package/dist/capture/profiler-frames.d.ts +44 -0
  32. package/dist/capture/replay-buffer.d.cts +45 -0
  33. package/dist/capture/replay-buffer.d.ts +45 -0
  34. package/dist/capture/replay-upload.d.cts +79 -0
  35. package/dist/capture/replay-upload.d.ts +79 -0
  36. package/dist/capture/replay.d.cts +114 -0
  37. package/dist/capture/replay.d.ts +114 -0
  38. package/dist/capture/reports.d.cts +17 -0
  39. package/dist/capture/reports.d.ts +3 -3
  40. package/dist/capture/resource-timing.d.cts +14 -0
  41. package/dist/capture/resource-timing.d.ts +2 -2
  42. package/dist/capture/server-timing.d.cts +19 -0
  43. package/dist/capture/server-timing.d.ts +3 -3
  44. package/dist/capture/storm.d.cts +13 -0
  45. package/dist/capture/storm.d.ts +7 -7
  46. package/dist/capture/types.d.cts +128 -0
  47. package/dist/capture/types.d.ts +54 -41
  48. package/dist/capture/unclean-exit.d.cts +31 -0
  49. package/dist/capture/unclean-exit.d.ts +9 -9
  50. package/dist/capture/user-timing.d.cts +22 -0
  51. package/dist/capture/user-timing.d.ts +4 -4
  52. package/dist/capture/web-socket.d.cts +40 -0
  53. package/dist/capture/web-socket.d.ts +14 -14
  54. package/dist/capture/web-vitals.d.cts +40 -0
  55. package/dist/capture/web-vitals.d.ts +21 -8
  56. package/dist/compression-CvED_Jel.cjs +2 -0
  57. package/dist/compression-CvED_Jel.cjs.map +1 -0
  58. package/dist/compression-tVtXwVjX.js +11 -0
  59. package/dist/compression-tVtXwVjX.js.map +1 -0
  60. package/dist/config-DUs7uHHt.cjs +2 -0
  61. package/dist/config-DUs7uHHt.cjs.map +1 -0
  62. package/dist/config-SgQcCP1_.js +560 -0
  63. package/dist/config-SgQcCP1_.js.map +1 -0
  64. package/dist/console-BGgGnjSi.js +81 -0
  65. package/dist/console-BGgGnjSi.js.map +1 -0
  66. package/dist/console-CSZ5_Vx5.cjs +2 -0
  67. package/dist/console-CSZ5_Vx5.cjs.map +1 -0
  68. package/dist/constants-CUyd9cTZ.js +357 -0
  69. package/dist/constants-CUyd9cTZ.js.map +1 -0
  70. package/dist/constants-CqdJhTxH.cjs +2 -0
  71. package/dist/constants-CqdJhTxH.cjs.map +1 -0
  72. package/dist/constants.d.cts +751 -0
  73. package/dist/constants.d.ts +231 -116
  74. package/dist/core/breadcrumbs.d.cts +54 -0
  75. package/dist/core/breadcrumbs.d.ts +21 -15
  76. package/dist/core/config.d.cts +45 -0
  77. package/dist/core/config.d.ts +33 -5
  78. package/dist/core/context.d.cts +24 -0
  79. package/dist/core/context.d.ts +8 -13
  80. package/dist/core/debug-buffer.d.cts +34 -0
  81. package/dist/core/debug-buffer.d.ts +13 -13
  82. package/dist/core/debug-bundle.d.cts +12 -0
  83. package/dist/core/debug-bundle.d.ts +6 -6
  84. package/dist/core/deferred.d.cts +7 -0
  85. package/dist/core/deferred.d.ts +4 -4
  86. package/dist/core/diagnostics.d.cts +86 -0
  87. package/dist/core/diagnostics.d.ts +25 -22
  88. package/dist/core/drops.d.cts +39 -0
  89. package/dist/core/drops.d.ts +22 -12
  90. package/dist/core/hold-buffer.d.cts +36 -0
  91. package/dist/core/hold-buffer.d.ts +16 -7
  92. package/dist/core/journey.d.cts +148 -0
  93. package/dist/core/journey.d.ts +28 -29
  94. package/dist/core/logger.d.cts +141 -0
  95. package/dist/core/logger.d.ts +45 -51
  96. package/dist/core/measure.d.cts +30 -0
  97. package/dist/core/measure.d.ts +21 -10
  98. package/dist/core/meter.d.cts +78 -0
  99. package/dist/core/meter.d.ts +38 -28
  100. package/dist/core/pipeline.d.cts +227 -0
  101. package/dist/core/pipeline.d.ts +114 -50
  102. package/dist/core/profile-buckets.d.cts +31 -0
  103. package/dist/core/profile-buckets.d.ts +31 -0
  104. package/dist/core/profiler.d.cts +218 -0
  105. package/dist/core/profiler.d.ts +218 -0
  106. package/dist/core/record.d.cts +190 -0
  107. package/dist/core/record.d.ts +67 -35
  108. package/dist/core/remote-rules.d.cts +17 -0
  109. package/dist/core/remote-rules.d.ts +7 -7
  110. package/dist/core/remote-sampling.d.cts +74 -0
  111. package/dist/core/remote-sampling.d.ts +24 -23
  112. package/dist/core/rotation.d.cts +75 -0
  113. package/dist/core/rotation.d.ts +75 -0
  114. package/dist/core/runtime.d.cts +765 -0
  115. package/dist/core/runtime.d.ts +430 -186
  116. package/dist/core/sampling.d.cts +86 -0
  117. package/dist/core/sampling.d.ts +22 -22
  118. package/dist/core/sender.d.cts +161 -0
  119. package/dist/core/sender.d.ts +80 -34
  120. package/dist/core/spans.d.cts +39 -0
  121. package/dist/core/spans.d.ts +6 -6
  122. package/dist/{deadline-BOjOxNHj.js → deadline-C4ccAuk5.js} +3 -6
  123. package/dist/deadline-C4ccAuk5.js.map +1 -0
  124. package/dist/deadline-CUGbto-y.cjs +2 -0
  125. package/dist/deadline-CUGbto-y.cjs.map +1 -0
  126. package/dist/debug-bundle-BXIlwDKM.cjs +2 -0
  127. package/dist/debug-bundle-BXIlwDKM.cjs.map +1 -0
  128. package/dist/debug-bundle-CRpYV_ui.js +35 -0
  129. package/dist/debug-bundle-CRpYV_ui.js.map +1 -0
  130. package/dist/defineProperty-X1c4tIPD.cjs +1 -0
  131. package/dist/defineProperty-s2S8BXUc.js +35 -0
  132. package/dist/doctor.cjs +1 -1
  133. package/dist/doctor.cjs.map +1 -1
  134. package/dist/doctor.d.cts +36 -0
  135. package/dist/doctor.d.ts +19 -6
  136. package/dist/doctor.js +180 -53
  137. package/dist/doctor.js.map +1 -1
  138. package/dist/error-like-B11pB4aL.js.map +1 -1
  139. package/dist/error-like-gGRx2s36.cjs.map +1 -1
  140. package/dist/errors-BE_EZV7Q.js +86 -0
  141. package/dist/errors-BE_EZV7Q.js.map +1 -0
  142. package/dist/errors-CNPbesMs.cjs +3 -0
  143. package/dist/errors-CNPbesMs.cjs.map +1 -0
  144. package/dist/factory-CTi0Is3F.js +404 -0
  145. package/dist/factory-CTi0Is3F.js.map +1 -0
  146. package/dist/factory-hRrH32v5.cjs +2 -0
  147. package/dist/factory-hRrH32v5.cjs.map +1 -0
  148. package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
  149. package/dist/fixed-window-Dq3MLUUv.js.map +1 -1
  150. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  151. package/dist/global-scope-D9I8s-oN.js.map +1 -1
  152. package/dist/guards-BlYGRK4l.js +10 -0
  153. package/dist/guards-BlYGRK4l.js.map +1 -0
  154. package/dist/guards-EjG3ahFp.cjs +2 -0
  155. package/dist/guards-EjG3ahFp.cjs.map +1 -0
  156. package/dist/{identity-DT5VmvXy.js → identity-DdhKgrpk.js} +11 -15
  157. package/dist/identity-DdhKgrpk.js.map +1 -0
  158. package/dist/identity-DlWRIuwy.cjs +2 -0
  159. package/dist/identity-DlWRIuwy.cjs.map +1 -0
  160. package/dist/index.cjs +1 -1
  161. package/dist/index.cjs.map +1 -1
  162. package/dist/index.d.cts +300 -0
  163. package/dist/index.d.ts +165 -141
  164. package/dist/index.js +1283 -1468
  165. package/dist/index.js.map +1 -1
  166. package/dist/indexeddb-storage-CL9uqBCy.cjs +2 -0
  167. package/dist/indexeddb-storage-CL9uqBCy.cjs.map +1 -0
  168. package/dist/{indexeddb-storage-BJVtiQKm.js → indexeddb-storage-GHdl0t8A.js} +51 -47
  169. package/dist/indexeddb-storage-GHdl0t8A.js.map +1 -0
  170. package/dist/interactions-CUkzK8sR.cjs +2 -0
  171. package/dist/interactions-CUkzK8sR.cjs.map +1 -0
  172. package/dist/{interactions-DTgKy_6K.js → interactions-DiFvCosX.js} +41 -49
  173. package/dist/interactions-DiFvCosX.js.map +1 -0
  174. package/dist/journey-B4Adltjm.cjs +2 -0
  175. package/dist/journey-B4Adltjm.cjs.map +1 -0
  176. package/dist/{journey-CuJrHzEg.js → journey-D2_sia57.js} +51 -53
  177. package/dist/journey-D2_sia57.js.map +1 -0
  178. package/dist/{library-console-C1m6g1BR.js → library-console-Btrzt814.js} +2 -2
  179. package/dist/library-console-Btrzt814.js.map +1 -0
  180. package/dist/{library-console-D2GY9Or6.cjs → library-console-CPW6bvZH.cjs} +2 -2
  181. package/dist/library-console-CPW6bvZH.cjs.map +1 -0
  182. package/dist/{library-request-BQBT9N9Q.js → library-request-BJ9PLRaD.js} +2 -2
  183. package/dist/library-request-BJ9PLRaD.js.map +1 -0
  184. package/dist/{library-request-1BX_UlaX.cjs → library-request-D7OvTxZV.cjs} +2 -2
  185. package/dist/library-request-D7OvTxZV.cjs.map +1 -0
  186. package/dist/{lifecycle-BaKx_-32.js → lifecycle-22CUCrc9.js} +21 -29
  187. package/dist/lifecycle-22CUCrc9.js.map +1 -0
  188. package/dist/lifecycle-IaAm1mOC.cjs +2 -0
  189. package/dist/lifecycle-IaAm1mOC.cjs.map +1 -0
  190. package/dist/{log-record-CAoGBBf3.js → log-record-BNiLfqtL.js} +8 -7
  191. package/dist/log-record-BNiLfqtL.js.map +1 -0
  192. package/dist/log-record-CkivuiEl.cjs +2 -0
  193. package/dist/log-record-CkivuiEl.cjs.map +1 -0
  194. package/dist/long-frames-BUUbXd-B.cjs +2 -0
  195. package/dist/long-frames-BUUbXd-B.cjs.map +1 -0
  196. package/dist/long-frames-DNFaRnC3.js +62 -0
  197. package/dist/long-frames-DNFaRnC3.js.map +1 -0
  198. package/dist/models/batch.d.cts +57 -0
  199. package/dist/models/batch.d.ts +16 -17
  200. package/dist/models/bus.d.cts +158 -0
  201. package/dist/models/bus.d.ts +46 -26
  202. package/dist/models/config.d.cts +1540 -0
  203. package/dist/models/config.d.ts +692 -405
  204. package/dist/models/drop.d.cts +54 -0
  205. package/dist/models/drop.d.ts +29 -14
  206. package/dist/models/health.d.cts +148 -0
  207. package/dist/models/health.d.ts +119 -23
  208. package/dist/models/log-record.d.cts +61 -0
  209. package/dist/models/log-record.d.ts +13 -14
  210. package/dist/models/metric.d.cts +139 -0
  211. package/dist/models/metric.d.ts +94 -18
  212. package/dist/models/plugin.d.cts +47 -0
  213. package/dist/models/plugin.d.ts +16 -16
  214. package/dist/models/replay.d.cts +60 -0
  215. package/dist/models/replay.d.ts +60 -0
  216. package/dist/models/serializer.d.cts +23 -0
  217. package/dist/models/serializer.d.ts +3 -4
  218. package/dist/models/storage.d.cts +95 -0
  219. package/dist/models/storage.d.ts +17 -14
  220. package/dist/network-CGMLQ-mA.cjs +2 -0
  221. package/dist/network-CGMLQ-mA.cjs.map +1 -0
  222. package/dist/{network-DBNwApoF.js → network-on2zZT6H.js} +57 -57
  223. package/dist/network-on2zZT6H.js.map +1 -0
  224. package/dist/openfin-Bxelt0yg.js.map +1 -1
  225. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  226. package/dist/otlp-BENHf3g9.cjs +2 -0
  227. package/dist/otlp-BENHf3g9.cjs.map +1 -0
  228. package/dist/{otlp-BTJdIa6F.js → otlp-DimfrRor.js} +22 -29
  229. package/dist/otlp-DimfrRor.js.map +1 -0
  230. package/dist/patch-BX8KrPCT.cjs.map +1 -1
  231. package/dist/patch-UdPz1ea8.js.map +1 -1
  232. package/dist/{platform-DkcuXwe-.js → platform-BaaFIPCU.js} +8 -8
  233. package/dist/platform-BaaFIPCU.js.map +1 -0
  234. package/dist/{platform-C2Ez5kDc.cjs → platform-CfA3-7sJ.cjs} +2 -2
  235. package/dist/platform-CfA3-7sJ.cjs.map +1 -0
  236. package/dist/profiler-BAZoh7A4.js +292 -0
  237. package/dist/profiler-BAZoh7A4.js.map +1 -0
  238. package/dist/profiler-D4tJpDRc.cjs +2 -0
  239. package/dist/profiler-D4tJpDRc.cjs.map +1 -0
  240. package/dist/profiler-frames-C4xr7KfH.cjs +2 -0
  241. package/dist/profiler-frames-C4xr7KfH.cjs.map +1 -0
  242. package/dist/profiler-frames-cJMx9wNM.js +78 -0
  243. package/dist/profiler-frames-cJMx9wNM.js.map +1 -0
  244. package/dist/remote-rules-Dz9MRAsB.js +95 -0
  245. package/dist/remote-rules-Dz9MRAsB.js.map +1 -0
  246. package/dist/remote-rules-_tY0zj5o.cjs +2 -0
  247. package/dist/remote-rules-_tY0zj5o.cjs.map +1 -0
  248. package/dist/replay-B3gFXIZd.cjs +2 -0
  249. package/dist/replay-B3gFXIZd.cjs.map +1 -0
  250. package/dist/replay-Ds-ANH34.js +310 -0
  251. package/dist/replay-Ds-ANH34.js.map +1 -0
  252. package/dist/reports-BDSe4dFH.cjs +2 -0
  253. package/dist/reports-BDSe4dFH.cjs.map +1 -0
  254. package/dist/{reports-TA-zInnq.js → reports-C-thq-bk.js} +25 -30
  255. package/dist/reports-C-thq-bk.js.map +1 -0
  256. package/dist/resource-timing-C576gFIQ.cjs +2 -0
  257. package/dist/resource-timing-C576gFIQ.cjs.map +1 -0
  258. package/dist/{resource-timing-BLv3EA2A.js → resource-timing-eUl2dNgC.js} +20 -23
  259. package/dist/resource-timing-eUl2dNgC.js.map +1 -0
  260. package/dist/response-body-YdNl-HkR.cjs +3 -0
  261. package/dist/response-body-YdNl-HkR.cjs.map +1 -0
  262. package/dist/response-body-eoSQpLiH.js +331 -0
  263. package/dist/response-body-eoSQpLiH.js.map +1 -0
  264. package/dist/rotation-Cwct4ckk.js +94 -0
  265. package/dist/rotation-Cwct4ckk.js.map +1 -0
  266. package/dist/rotation-D4qUAHAu.cjs +2 -0
  267. package/dist/rotation-D4qUAHAu.cjs.map +1 -0
  268. package/dist/sampling-BlrI8jor.js +63 -0
  269. package/dist/sampling-BlrI8jor.js.map +1 -0
  270. package/dist/sampling-mXt4dstx.cjs +2 -0
  271. package/dist/sampling-mXt4dstx.cjs.map +1 -0
  272. package/dist/{sanitize-6ymPlVvP.js → sanitize-Ba0KqU06.js} +2 -2
  273. package/dist/sanitize-Ba0KqU06.js.map +1 -0
  274. package/dist/{sanitize-BAWzkZt0.cjs → sanitize-DQyiI_KY.cjs} +2 -2
  275. package/dist/sanitize-DQyiI_KY.cjs.map +1 -0
  276. package/dist/sender-BdRuNVhF.cjs +2 -0
  277. package/dist/sender-BdRuNVhF.cjs.map +1 -0
  278. package/dist/sender-Dv8rAmpV.js +979 -0
  279. package/dist/sender-Dv8rAmpV.js.map +1 -0
  280. package/dist/storage/context-storage.d.cts +90 -0
  281. package/dist/storage/context-storage.d.ts +38 -37
  282. package/dist/storage/emergency-queue.d.cts +27 -0
  283. package/dist/storage/emergency-queue.d.ts +13 -13
  284. package/dist/storage/eviction.d.cts +40 -0
  285. package/dist/storage/eviction.d.ts +13 -13
  286. package/dist/storage/factory.d.cts +21 -0
  287. package/dist/storage/factory.d.ts +11 -10
  288. package/dist/storage/gap.d.cts +20 -0
  289. package/dist/storage/gap.d.ts +9 -9
  290. package/dist/storage/idb-driver.d.cts +93 -0
  291. package/dist/storage/idb-driver.d.ts +32 -33
  292. package/dist/storage/indexeddb-storage.d.cts +97 -0
  293. package/dist/storage/indexeddb-storage.d.ts +38 -31
  294. package/dist/storage/keys.d.cts +17 -0
  295. package/dist/storage/keys.d.ts +9 -9
  296. package/dist/storage/local-storage.d.cts +139 -0
  297. package/dist/storage/local-storage.d.ts +49 -42
  298. package/dist/storage/memory-storage.d.cts +73 -0
  299. package/dist/storage/memory-storage.d.ts +25 -25
  300. package/dist/storage/persistence.d.cts +8 -0
  301. package/dist/storage/persistence.d.ts +3 -3
  302. package/dist/storage/stored-context.d.cts +34 -0
  303. package/dist/storage/stored-context.d.ts +34 -0
  304. package/dist/stored-context-B2EzVuYm.js +51 -0
  305. package/dist/stored-context-B2EzVuYm.js.map +1 -0
  306. package/dist/stored-context-CXt7eHZL.cjs +2 -0
  307. package/dist/stored-context-CXt7eHZL.cjs.map +1 -0
  308. package/dist/storm-C-zYSdDX.cjs +2 -0
  309. package/dist/storm-C-zYSdDX.cjs.map +1 -0
  310. package/dist/storm-DjKetLKZ.js +9 -0
  311. package/dist/storm-DjKetLKZ.js.map +1 -0
  312. package/dist/transport/compression.d.cts +7 -0
  313. package/dist/transport/compression.d.ts +2 -2
  314. package/dist/transport/custom-transport.d.cts +22 -0
  315. package/dist/transport/custom-transport.d.ts +6 -5
  316. package/dist/transport/errors.d.cts +31 -0
  317. package/dist/transport/errors.d.ts +7 -7
  318. package/dist/transport/exit-flush.d.cts +135 -0
  319. package/dist/transport/exit-flush.d.ts +62 -45
  320. package/dist/transport/headers.d.cts +8 -0
  321. package/dist/transport/headers.d.ts +4 -4
  322. package/dist/transport/http-transport.d.cts +116 -0
  323. package/dist/transport/http-transport.d.ts +48 -35
  324. package/dist/transport/memory-transport.d.cts +30 -0
  325. package/dist/transport/memory-transport.d.ts +8 -8
  326. package/dist/transport/response-body.d.cts +49 -0
  327. package/dist/transport/response-body.d.ts +49 -0
  328. package/dist/transport/retry-engine.d.cts +129 -0
  329. package/dist/transport/retry-engine.d.ts +62 -43
  330. package/dist/transport/serializers/ecs.d.cts +3 -0
  331. package/dist/transport/serializers/ecs.d.ts +2 -2
  332. package/dist/transport/serializers/otlp-metrics.d.cts +3 -0
  333. package/dist/transport/serializers/otlp-metrics.d.ts +2 -2
  334. package/dist/transport/serializers/otlp-traces.d.cts +3 -0
  335. package/dist/transport/serializers/otlp-traces.d.ts +2 -2
  336. package/dist/transport/serializers/otlp.d.cts +47 -0
  337. package/dist/transport/serializers/otlp.d.ts +18 -18
  338. package/dist/transport/serializers/select.d.cts +38 -0
  339. package/dist/transport/serializers/select.d.ts +11 -11
  340. package/dist/transport/status-transport.d.cts +129 -0
  341. package/dist/transport/status-transport.d.ts +45 -28
  342. package/dist/transport/worker-client.d.cts +23 -0
  343. package/dist/transport/worker-client.d.ts +12 -3
  344. package/dist/transport/worker-entry.d.cts +5 -0
  345. package/dist/transport/worker-entry.d.ts +1 -1
  346. package/dist/transport/worker-protocol.d.cts +38 -0
  347. package/dist/transport/worker-protocol.d.ts +7 -5
  348. package/dist/transport/worker-server.d.cts +3 -0
  349. package/dist/transport/worker-server.d.ts +1 -1
  350. package/dist/transport/worker-transport.d.cts +10 -0
  351. package/dist/transport/worker-transport.d.ts +5 -4
  352. package/dist/types-BAerHgCq.js.map +1 -1
  353. package/dist/types-C7WNpnG1.cjs.map +1 -1
  354. package/dist/{unclean-exit-CwcUhFOn.js → unclean-exit-DQD1cT7c.js} +23 -30
  355. package/dist/unclean-exit-DQD1cT7c.js.map +1 -0
  356. package/dist/unclean-exit-py99ApzT.cjs +2 -0
  357. package/dist/unclean-exit-py99ApzT.cjs.map +1 -0
  358. package/dist/unref-CU9Nyz_9.cjs +2 -0
  359. package/dist/unref-CU9Nyz_9.cjs.map +1 -0
  360. package/dist/unref-DgHPQeWv.js +7 -0
  361. package/dist/unref-DgHPQeWv.js.map +1 -0
  362. package/dist/{user-timing-_jZIhDKI.js → user-timing-BePqb1uN.js} +18 -18
  363. package/dist/user-timing-BePqb1uN.js.map +1 -0
  364. package/dist/user-timing-D6XTmpuM.cjs +2 -0
  365. package/dist/user-timing-D6XTmpuM.cjs.map +1 -0
  366. package/dist/utils/console.d.cts +36 -0
  367. package/dist/utils/console.d.ts +6 -6
  368. package/dist/utils/deadline.d.cts +14 -0
  369. package/dist/utils/deadline.d.ts +4 -4
  370. package/dist/utils/error-like.d.cts +25 -0
  371. package/dist/utils/error-like.d.ts +7 -7
  372. package/dist/utils/fixed-window.d.cts +25 -0
  373. package/dist/utils/fixed-window.d.ts +9 -8
  374. package/dist/utils/global-scope.d.cts +20 -0
  375. package/dist/utils/global-scope.d.ts +8 -8
  376. package/dist/utils/guards.d.cts +14 -0
  377. package/dist/utils/guards.d.ts +10 -2
  378. package/dist/utils/identity.d.cts +109 -0
  379. package/dist/utils/identity.d.ts +20 -21
  380. package/dist/utils/library-console.d.cts +11 -0
  381. package/dist/utils/library-console.d.ts +4 -4
  382. package/dist/utils/library-request.d.cts +24 -0
  383. package/dist/utils/library-request.d.ts +10 -10
  384. package/dist/utils/lock.d.cts +24 -0
  385. package/dist/utils/lock.d.ts +11 -10
  386. package/dist/utils/openfin.d.cts +48 -0
  387. package/dist/utils/openfin.d.ts +5 -5
  388. package/dist/utils/patch.d.cts +9 -0
  389. package/dist/utils/patch.d.ts +6 -6
  390. package/dist/utils/platform.d.cts +62 -0
  391. package/dist/utils/platform.d.ts +15 -13
  392. package/dist/utils/sanitize.d.cts +52 -0
  393. package/dist/utils/sanitize.d.ts +5 -5
  394. package/dist/utils/sequence.d.cts +10 -0
  395. package/dist/utils/tracing.d.cts +158 -0
  396. package/dist/utils/tracing.d.ts +49 -42
  397. package/dist/utils/unref.d.cts +9 -0
  398. package/dist/utils/unref.d.ts +3 -3
  399. package/dist/web-socket-CoIUBM3C.cjs +2 -0
  400. package/dist/web-socket-CoIUBM3C.cjs.map +1 -0
  401. package/dist/{web-socket-CV7yIMnm.js → web-socket-DSHgDiZ6.js} +23 -28
  402. package/dist/web-socket-DSHgDiZ6.js.map +1 -0
  403. package/dist/web-vitals-4pWACwaR.js +71 -0
  404. package/dist/web-vitals-4pWACwaR.js.map +1 -0
  405. package/dist/web-vitals-__X7t4pj.cjs +2 -0
  406. package/dist/web-vitals-__X7t4pj.cjs.map +1 -0
  407. package/dist/worker-protocol-QbvqNazn.cjs +2 -0
  408. package/dist/worker-protocol-QbvqNazn.cjs.map +1 -0
  409. package/dist/{worker-protocol-CrsdSDLn.js → worker-protocol-x074Rpet.js} +14 -11
  410. package/dist/worker-protocol-x074Rpet.js.map +1 -0
  411. package/dist/worker-server-CFe4nvos.cjs +2 -0
  412. package/dist/worker-server-CFe4nvos.cjs.map +1 -0
  413. package/dist/worker-server-iUVSjH8L.js +94 -0
  414. package/dist/worker-server-iUVSjH8L.js.map +1 -0
  415. package/dist/worker-transport-CRAX-09c.cjs +2 -0
  416. package/dist/worker-transport-CRAX-09c.cjs.map +1 -0
  417. package/dist/worker-transport-Dy1KMA7t.js +190 -0
  418. package/dist/worker-transport-Dy1KMA7t.js.map +1 -0
  419. package/llms.txt +397 -0
  420. package/package.json +55 -41
  421. package/dist/batch-C8OcWR2L.cjs.map +0 -1
  422. package/dist/batch-CL9uWYY3.js.map +0 -1
  423. package/dist/bus-BZ0GldpT.js +0 -660
  424. package/dist/bus-BZ0GldpT.js.map +0 -1
  425. package/dist/bus-VWlmM5xs.cjs +0 -2
  426. package/dist/bus-VWlmM5xs.cjs.map +0 -1
  427. package/dist/console-BPZCuSLc.cjs +0 -2
  428. package/dist/console-BPZCuSLc.cjs.map +0 -1
  429. package/dist/console-BeCF7n59.js +0 -82
  430. package/dist/console-BeCF7n59.js.map +0 -1
  431. package/dist/constants-DqKJH_MP.cjs +0 -2
  432. package/dist/constants-DqKJH_MP.cjs.map +0 -1
  433. package/dist/constants-zyrqveN4.js +0 -304
  434. package/dist/constants-zyrqveN4.js.map +0 -1
  435. package/dist/context-storage-BjzeBSxH.cjs +0 -2
  436. package/dist/context-storage-BjzeBSxH.cjs.map +0 -1
  437. package/dist/context-storage-BzkoHzkQ.js +0 -51
  438. package/dist/context-storage-BzkoHzkQ.js.map +0 -1
  439. package/dist/deadline-BOjOxNHj.js.map +0 -1
  440. package/dist/deadline-XSnm95pg.cjs +0 -2
  441. package/dist/deadline-XSnm95pg.cjs.map +0 -1
  442. package/dist/debug-bundle-BzJNpbF0.cjs +0 -2
  443. package/dist/debug-bundle-BzJNpbF0.cjs.map +0 -1
  444. package/dist/debug-bundle-C7UkHZ-q.js +0 -25
  445. package/dist/debug-bundle-C7UkHZ-q.js.map +0 -1
  446. package/dist/emergency-queue-CNTRui5t.cjs +0 -2
  447. package/dist/emergency-queue-CNTRui5t.cjs.map +0 -1
  448. package/dist/emergency-queue-Zy6lNafo.js +0 -67
  449. package/dist/emergency-queue-Zy6lNafo.js.map +0 -1
  450. package/dist/errors-Dh7kef0i.js +0 -92
  451. package/dist/errors-Dh7kef0i.js.map +0 -1
  452. package/dist/errors-tfEr48bS.cjs +0 -3
  453. package/dist/errors-tfEr48bS.cjs.map +0 -1
  454. package/dist/factory-BonqI3NL.js +0 -276
  455. package/dist/factory-BonqI3NL.js.map +0 -1
  456. package/dist/factory-CJXVYp0R.cjs +0 -2
  457. package/dist/factory-CJXVYp0R.cjs.map +0 -1
  458. package/dist/guards-Cidk71ME.js +0 -7
  459. package/dist/guards-Cidk71ME.js.map +0 -1
  460. package/dist/guards-nJ70syPt.cjs +0 -2
  461. package/dist/guards-nJ70syPt.cjs.map +0 -1
  462. package/dist/identity-Cxgj6pZX.cjs +0 -2
  463. package/dist/identity-Cxgj6pZX.cjs.map +0 -1
  464. package/dist/identity-DT5VmvXy.js.map +0 -1
  465. package/dist/indexeddb-storage-BJVtiQKm.js.map +0 -1
  466. package/dist/indexeddb-storage-CIoW21Xd.cjs +0 -2
  467. package/dist/indexeddb-storage-CIoW21Xd.cjs.map +0 -1
  468. package/dist/interactions-DTgKy_6K.js.map +0 -1
  469. package/dist/interactions-fEN6FbVo.cjs +0 -2
  470. package/dist/interactions-fEN6FbVo.cjs.map +0 -1
  471. package/dist/journey-CuJrHzEg.js.map +0 -1
  472. package/dist/journey-pffMVMfa.cjs +0 -2
  473. package/dist/journey-pffMVMfa.cjs.map +0 -1
  474. package/dist/keys-BHhw_0Wh.cjs +0 -2
  475. package/dist/keys-BHhw_0Wh.cjs.map +0 -1
  476. package/dist/keys-BU9j5YqW.js +0 -16
  477. package/dist/keys-BU9j5YqW.js.map +0 -1
  478. package/dist/library-console-C1m6g1BR.js.map +0 -1
  479. package/dist/library-console-D2GY9Or6.cjs.map +0 -1
  480. package/dist/library-request-1BX_UlaX.cjs.map +0 -1
  481. package/dist/library-request-BQBT9N9Q.js.map +0 -1
  482. package/dist/lifecycle-2EtUaRpo.cjs +0 -2
  483. package/dist/lifecycle-2EtUaRpo.cjs.map +0 -1
  484. package/dist/lifecycle-BaKx_-32.js.map +0 -1
  485. package/dist/log-record-CAoGBBf3.js.map +0 -1
  486. package/dist/log-record-i9zOTkpQ.cjs +0 -2
  487. package/dist/log-record-i9zOTkpQ.cjs.map +0 -1
  488. package/dist/long-frames-BVg4i5SC.cjs +0 -2
  489. package/dist/long-frames-BVg4i5SC.cjs.map +0 -1
  490. package/dist/long-frames-Czk7IupC.js +0 -64
  491. package/dist/long-frames-Czk7IupC.js.map +0 -1
  492. package/dist/models/stats.d.ts +0 -11
  493. package/dist/network-DBNwApoF.js.map +0 -1
  494. package/dist/network-xbbuvG_6.cjs +0 -2
  495. package/dist/network-xbbuvG_6.cjs.map +0 -1
  496. package/dist/otlp-BDvFrLnc.cjs +0 -2
  497. package/dist/otlp-BDvFrLnc.cjs.map +0 -1
  498. package/dist/otlp-BTJdIa6F.js.map +0 -1
  499. package/dist/platform-C2Ez5kDc.cjs.map +0 -1
  500. package/dist/platform-DkcuXwe-.js.map +0 -1
  501. package/dist/remote-rules-Cfb4K-Nl.js +0 -98
  502. package/dist/remote-rules-Cfb4K-Nl.js.map +0 -1
  503. package/dist/remote-rules-vzvk7aKf.cjs +0 -2
  504. package/dist/remote-rules-vzvk7aKf.cjs.map +0 -1
  505. package/dist/reports-Dk2YhKIh.cjs +0 -2
  506. package/dist/reports-Dk2YhKIh.cjs.map +0 -1
  507. package/dist/reports-TA-zInnq.js.map +0 -1
  508. package/dist/resource-timing-BLv3EA2A.js.map +0 -1
  509. package/dist/resource-timing-Cysw1S1f.cjs +0 -2
  510. package/dist/resource-timing-Cysw1S1f.cjs.map +0 -1
  511. package/dist/sampling-C4VV-1MS.js +0 -60
  512. package/dist/sampling-C4VV-1MS.js.map +0 -1
  513. package/dist/sampling-Ckh2yW9k.cjs +0 -2
  514. package/dist/sampling-Ckh2yW9k.cjs.map +0 -1
  515. package/dist/sanitize-6ymPlVvP.js.map +0 -1
  516. package/dist/sanitize-BAWzkZt0.cjs.map +0 -1
  517. package/dist/select-ZF4by-lF.cjs +0 -3
  518. package/dist/select-ZF4by-lF.cjs.map +0 -1
  519. package/dist/select-xtQaenIi.js +0 -270
  520. package/dist/select-xtQaenIi.js.map +0 -1
  521. package/dist/sender-CiMHC9YG.js +0 -856
  522. package/dist/sender-CiMHC9YG.js.map +0 -1
  523. package/dist/sender-D5wBoXA8.cjs +0 -2
  524. package/dist/sender-D5wBoXA8.cjs.map +0 -1
  525. package/dist/storage-BA9RqRO-.cjs +0 -2
  526. package/dist/storage-BA9RqRO-.cjs.map +0 -1
  527. package/dist/storage-DZwed89z.js +0 -16
  528. package/dist/storage-DZwed89z.js.map +0 -1
  529. package/dist/storm-CYi9Swpx.cjs +0 -2
  530. package/dist/storm-CYi9Swpx.cjs.map +0 -1
  531. package/dist/storm-VR024_QN.js +0 -9
  532. package/dist/storm-VR024_QN.js.map +0 -1
  533. package/dist/unclean-exit-CwcUhFOn.js.map +0 -1
  534. package/dist/unclean-exit-DFUN57wY.cjs +0 -2
  535. package/dist/unclean-exit-DFUN57wY.cjs.map +0 -1
  536. package/dist/user-timing-C9kfRq3J.cjs +0 -2
  537. package/dist/user-timing-C9kfRq3J.cjs.map +0 -1
  538. package/dist/user-timing-_jZIhDKI.js.map +0 -1
  539. package/dist/utils/timer.d.ts +0 -19
  540. package/dist/web-socket-BWUoqBh8.cjs +0 -2
  541. package/dist/web-socket-BWUoqBh8.cjs.map +0 -1
  542. package/dist/web-socket-CV7yIMnm.js.map +0 -1
  543. package/dist/web-vitals-Bq4WFHQo.js +0 -52
  544. package/dist/web-vitals-Bq4WFHQo.js.map +0 -1
  545. package/dist/web-vitals-DFuoTQbZ.cjs +0 -2
  546. package/dist/web-vitals-DFuoTQbZ.cjs.map +0 -1
  547. package/dist/worker-protocol-Bai7GAIA.cjs +0 -2
  548. package/dist/worker-protocol-Bai7GAIA.cjs.map +0 -1
  549. package/dist/worker-protocol-CrsdSDLn.js.map +0 -1
  550. package/dist/worker-server-BrIYkfoa.cjs +0 -2
  551. package/dist/worker-server-BrIYkfoa.cjs.map +0 -1
  552. package/dist/worker-server-Dp5HYm4b.js +0 -83
  553. package/dist/worker-server-Dp5HYm4b.js.map +0 -1
  554. package/dist/worker-transport-Bwej4N2e.cjs +0 -2
  555. package/dist/worker-transport-Bwej4N2e.cjs.map +0 -1
  556. package/dist/worker-transport-D6jtgpqN.js +0 -199
  557. package/dist/worker-transport-D6jtgpqN.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,79 +1,46 @@
1
- import { $t as e, Bn as t, Ct as n, D as r, Et as i, F as a, Fn as o, G as s, Hn as c, I as l, In as u, J as d, K as f, Kt as p, L as m, Mn as h, Mt as g, N as _, Nn as v, Nt as y, Pn as ee, Pt as te, Qt as ne, U as re, Un as ie, W as ae, Wn as oe, X as se, Zt as ce, _ as le, a as ue, an as de, bn as fe, c as b, cn as pe, d as me, dn as he, en as ge, f as x, fn as _e, g as ve, h as ye, in as be, jn as xe, ln as Se, m as Ce, mn as S, nn as we, o as Te, on as Ee, p as De, q as Oe, qt as ke, rn as Ae, s as je, sn as Me, tn as Ne, u as Pe, un as Fe, v as C, wn as Ie, wt as w, xn as T, y as Le, zn as Re } from "./constants-zyrqveN4.js";
2
- import { n as ze, r as Be, t as Ve } from "./log-record-CAoGBBf3.js";
3
- import { n as He, r as Ue, t as We } from "./error-like-B11pB4aL.js";
4
- import { t as E } from "./guards-Cidk71ME.js";
5
- import { r as Ge } from "./deadline-BOjOxNHj.js";
6
- import { i as D, n as Ke, t as qe } from "./platform-DkcuXwe-.js";
7
- import { n as O, t as Je } from "./library-console-C1m6g1BR.js";
8
- import { i as Ye, n as Xe, r as k } from "./sanitize-6ymPlVvP.js";
9
- import { a as Ze, i as A, n as Qe, o as $e, r as et, s as tt, t as nt } from "./identity-DT5VmvXy.js";
10
- import { r as rt } from "./library-request-BQBT9N9Q.js";
11
- import { r as it, t as at } from "./batch-CL9uWYY3.js";
12
- import { n as ot, t as st } from "./journey-CuJrHzEg.js";
13
- import { a as ct, i as lt, n as ut, o as dt } from "./sampling-C4VV-1MS.js";
14
- // src/utils/timer.ts
15
- function ft(e) {
16
- return Math.round((performance.now() - e) * se) / se;
17
- }
18
- function pt(e, t, n, r, i) {
19
- e.logMetric(`${t}.duration`, n, "ms", "histogram", {
20
- status: r,
21
- ...i
22
- });
23
- }
24
- function mt(e, t, n, r, i) {
25
- let a = ft(n);
26
- e.error(`${t} failed`, r, {
27
- "action.duration_ms": a,
28
- status: "FAILURE",
29
- ...i
30
- }), pt(e, t, a, "FAILURE", i);
31
- }
32
- function ht(e, t, n, r) {
33
- let i = performance.now();
34
- try {
35
- let a = n();
36
- return pt(e, t, ft(i), "SUCCESS", r), a;
37
- } catch (n) {
38
- throw mt(e, t, i, n, r), n;
39
- }
40
- }
41
- async function gt(e, t, n, r) {
42
- let i = performance.now();
43
- try {
44
- let a = await n();
45
- return pt(e, t, ft(i), "SUCCESS", r), a;
46
- } catch (n) {
47
- throw mt(e, t, i, n, r), n;
48
- }
49
- }
1
+ import { $n as e, An as t, Bt as n, Dn as r, En as i, G as a, Gn as o, Hn as s, J as c, K as l, Lt as u, M as d, Mn as f, Nn as p, Ot as m, P as h, Qn as g, Sn as ee, Tn as _, Vn as te, Y as ne, _ as re, _n as ie, a as v, at as ae, bn as oe, c as y, d as se, er as b, f as x, g as S, gn as ce, h as C, hn as le, j as ue, jt as de, kt as w, m as fe, mn as pe, nr as me, o as he, on as ge, or as _e, p as ve, q as ye, rr as be, rt as xe, s as Se, sn as Ce, sr as we, tr as Te, u as Ee, v as T, vn as De, wn as Oe, xn as ke, xt as Ae, y as je, yn as Me, zt as E } from "./constants-CUyd9cTZ.js";
2
+ import { n as Ne, r as Pe, t as Fe } from "./log-record-BNiLfqtL.js";
3
+ import { n as Ie, r as Le, t as Re } from "./error-like-B11pB4aL.js";
4
+ import { n as D, t as ze } from "./guards-BlYGRK4l.js";
5
+ import { t as O } from "./unref-DgHPQeWv.js";
6
+ import { i as Be, n as Ve, t as He } from "./platform-BaaFIPCU.js";
7
+ import { t as k } from "./defineProperty-s2S8BXUc.js";
8
+ import { a as Ue, i as A, n as We, o as Ge, r as Ke, s as qe, t as Je } from "./identity-DdhKgrpk.js";
9
+ import { t as j } from "./profiler-BAZoh7A4.js";
10
+ import { n as M, t as Ye } from "./library-console-Btrzt814.js";
11
+ import { i as Xe, n as Ze, r as N } from "./sanitize-Ba0KqU06.js";
12
+ import { r as Qe } from "./library-request-BJ9PLRaD.js";
13
+ import { n as $e, r as P, t as F } from "./config-SgQcCP1_.js";
14
+ import { r as et, t as tt } from "./batch-CXmPmTse.js";
15
+ import { n as nt, t as rt } from "./journey-D2_sia57.js";
16
+ import { a as it, i as at, n as ot, o as st } from "./sampling-BlrI8jor.js";
50
17
  // src/core/deferred.ts
51
- var j = /* @__PURE__ */ new WeakMap();
52
- function _t(e) {
18
+ var I = /* @__PURE__ */ new WeakMap();
19
+ function ct(e) {
53
20
  let t = e.idle;
54
21
  t !== void 0 && (e.diagnostics.guard("pipeline.crashed", "The idle callback could not be cancelled.", () => {
55
22
  cancelIdleCallback(t);
56
23
  }), e.idle = void 0), clearTimeout(e.timer), e.timer = void 0;
57
24
  }
58
- function vt(e, t) {
25
+ function lt(e, t) {
59
26
  typeof requestIdleCallback == "function" && typeof cancelIdleCallback == "function" && (t.idle = t.diagnostics.guard("pipeline.crashed", "The idle callback could not be scheduled.", () => requestIdleCallback((n) => {
60
- M(e, t, n);
61
- }, { timeout: s })), t.idle !== void 0) || (t.timer = setTimeout(() => {
62
- M(e, t);
63
- }, 0), Ge(t.timer));
64
- }
65
- function M(e, t, n) {
66
- if (j.get(e) !== t || t.draining) return;
67
- _t(t), t.draining = !0;
27
+ L(e, t, n);
28
+ }, { timeout: l })), t.idle !== void 0) || (t.timer = setTimeout(() => {
29
+ L(e, t);
30
+ }, 0), O(t.timer));
31
+ }
32
+ function L(e, t, n) {
33
+ if (I.get(e) !== t || t.draining) return;
34
+ ct(t), t.draining = !0;
68
35
  let r = t.work;
69
36
  t.work = [];
70
37
  let i = 0;
71
- for (; i < r.length && (!n || n.didTimeout && i === 0 || n.timeRemaining() > 0);) if (t.diagnostics.guard("pipeline.crashed", "The library could not build a deferred record.", r[i]), i++, j.get(e) !== t) return;
72
- t.work = [...r.slice(i), ...t.work], t.draining = !1, t.work.length > 0 ? vt(e, t) : j.delete(e);
38
+ for (; i < r.length && (!n || n.didTimeout && i === 0 || n.timeRemaining() > 0);) if (t.diagnostics.guard("pipeline.crashed", "The library could not build a deferred record.", r[i]), i++, I.get(e) !== t) return;
39
+ t.work = [...r.slice(i), ...t.work], t.draining = !1, t.work.length > 0 ? lt(e, t) : I.delete(e);
73
40
  }
74
- function yt(e, t, n, r) {
75
- let i = j.get(e), a = r > 0 ? Math.min(r, f) : f;
76
- if (i && i.work.length >= a && !i.draining && (M(e, i), i = j.get(e)), i) {
41
+ function ut(e, t, n, r) {
42
+ let i = I.get(e), a = r === null ? ye : Math.min(r, ye);
43
+ if (i && i.work.length >= a && !i.draining && (L(e, i), i = I.get(e)), i) {
77
44
  if (i.work.length >= a) {
78
45
  n.count("record.dropped_by_ceiling");
79
46
  return;
@@ -83,29 +50,29 @@ function yt(e, t, n, r) {
83
50
  work: [t],
84
51
  diagnostics: n,
85
52
  draining: !1
86
- }, j.set(e, i), vt(e, i);
53
+ }, I.set(e, i), lt(e, i);
87
54
  }
88
- function N(e) {
89
- let t = j.get(e);
90
- t && M(e, t);
55
+ function R(e) {
56
+ let t = I.get(e);
57
+ t && L(e, t);
91
58
  }
92
- function bt(e) {
93
- let t = j.get(e);
59
+ function dt(e) {
60
+ let t = I.get(e);
94
61
  if (t) {
95
- _t(t), j.delete(e);
62
+ ct(t), I.delete(e);
96
63
  for (let e of t.work) t.diagnostics.count("record.dropped_by_ceiling");
97
64
  t.work = [];
98
65
  }
99
66
  }
100
67
  // src/core/logger.ts
101
- var xt = [
102
- _,
103
- Ie,
104
- Oe
68
+ var ft = [
69
+ h,
70
+ o,
71
+ c
105
72
  ];
106
- function St(e, t) {
73
+ function pt(e, t) {
107
74
  let n = t.guard("record.sanitize_failed", "The library could not read the error reason.", () => {
108
- if (!(e instanceof Error) && !Ue(e)) return;
75
+ if (!(e instanceof Error) && !Le(e)) return;
109
76
  let t = Error(e.message);
110
77
  return t.name = e.name, t.stack = e.stack, t;
111
78
  });
@@ -113,38 +80,50 @@ function St(e, t) {
113
80
  let r = t.guard("record.sanitize_failed", "The library could not convert the error reason to text.", () => String(e));
114
81
  return Error(r ?? typeof e);
115
82
  }
116
- function Ct(e, t, n) {
83
+ function mt(e, t, n) {
117
84
  return n.guard("record.sanitize_failed", "The library could not read the error reason.", () => e instanceof Error ? e : t) ?? t;
118
85
  }
119
- function wt(e, t) {
86
+ function ht(e, t) {
120
87
  if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint" || typeof e == "symbol") return e;
121
88
  if (typeof e == "object" && e) return t.guard("record.sanitize_failed", "The library could not read the properties of the error reason.", () => {
122
- let t = e, n = Ue(e), r = {}, i = 0;
89
+ let t = e, n = Le(e), r = {}, i = 0;
123
90
  for (let e of Object.keys(t)) {
124
91
  let a = t[e];
125
- n && We.has(e) || !He(a) || (r[e] = a, i++);
92
+ n && Re.has(e) || !Ie(a) || (r[e] = a, i++);
126
93
  }
127
94
  return i === 0 ? void 0 : r;
128
95
  });
129
96
  }
130
- function Tt(e) {
131
- if (!E(e) || e instanceof Error) return !1;
97
+ function gt(e) {
98
+ if (!D(e) || e instanceof Error) return !1;
132
99
  let t = Object.getPrototypeOf(e);
133
100
  return t === null || Object.getPrototypeOf(t) === null;
134
101
  }
135
- function Et(e) {
136
- return xt.some((t) => e === t || e.startsWith(`${t}.`)) ? "system" : "log";
102
+ function _t(e) {
103
+ return ft.some((t) => e === t || e.startsWith(`${t}.`)) ? "system" : "log";
137
104
  }
138
- function P(e, t) {
105
+ function z(e, t) {
139
106
  return e === void 0 ? {} : t.guard("record.sanitize_failed", "The library could not read the payload.", () => ({ ...e })) ?? { "uiobs.sanitize_failed": !0 };
140
107
  }
141
- var F = class e {
142
- bind;
143
- namespace;
144
- options;
145
- levelType;
108
+ var B = class e {
146
109
  constructor(e, t, n = {}) {
147
- this.bind = e, this.namespace = t, this.options = n, this.levelType = Et(t);
110
+ k(this, "bind", void 0), k(this, "namespace", void 0), k(this, "options", void 0), k(this, "levelType", void 0), k(this, "trace", (e, t) => {
111
+ this.write("TRACE", this.levelType, e, t);
112
+ }), k(this, "debug", (e, t) => {
113
+ this.write("DEBUG", this.levelType, e, t);
114
+ }), k(this, "info", (e, t) => {
115
+ this.write("INFO", this.levelType, e, t);
116
+ }), k(this, "warn", (e, t) => {
117
+ this.write("WARN", this.levelType, e, t);
118
+ }), k(this, "error", (e, t, n) => {
119
+ this.writeError("ERROR", e, t, n);
120
+ }), k(this, "fatal", (e, t, n) => {
121
+ this.writeError("FATAL", e, t, n);
122
+ }), k(this, "logAction", (e, t) => {
123
+ this.write("INFO", "action", e, t);
124
+ }), k(this, "logEvent", (e, t) => {
125
+ this.write("INFO", "event", e, t);
126
+ }), this.bind = e, this.namespace = t, this.options = n, this.levelType = _t(t);
148
127
  }
149
128
  child(t, n = {}) {
150
129
  return new e(this.bind, `${this.namespace}.${t}`, { scopedContext: {
@@ -152,50 +131,6 @@ var F = class e {
152
131
  ...n.scopedContext
153
132
  } });
154
133
  }
155
- trace = (e, t) => {
156
- this.write("TRACE", this.levelType, e, t);
157
- };
158
- debug = (e, t) => {
159
- this.write("DEBUG", this.levelType, e, t);
160
- };
161
- info = (e, t) => {
162
- this.write("INFO", this.levelType, e, t);
163
- };
164
- warn = (e, t) => {
165
- this.write("WARN", this.levelType, e, t);
166
- };
167
- error = (e, t, n) => {
168
- this.writeError("ERROR", e, t, n);
169
- };
170
- fatal = (e, t, n) => {
171
- this.writeError("FATAL", e, t, n);
172
- };
173
- logAction = (e, t) => {
174
- this.write("INFO", "action", e, t);
175
- };
176
- logEvent = (e, t) => {
177
- this.write("INFO", "event", e, t);
178
- };
179
- logMetric = (e, t, n = ae, r = "gauge", i) => {
180
- if (!Number.isFinite(t)) {
181
- this.bind().diagnostics.report("record.dropped_malformed", "The metric value is not a finite number. The library dropped the metric.", { "metric.name": e });
182
- return;
183
- }
184
- let a = this.bind();
185
- this.submit(a, "INFO", "metric", (o) => {
186
- let s = P(i, a.diagnostics), c = {
187
- ...s,
188
- "metric.name": e,
189
- "metric.value": t,
190
- "metric.unit": n,
191
- "metric.type": r,
192
- [y.attributeKeys]: Object.keys(s)
193
- };
194
- this.writeNow(a, "INFO", "metric", e, c, !0, o);
195
- });
196
- };
197
- timeSync = (e, t, n) => ht(this, e, t, n);
198
- timeAsync = (e, t, n) => gt(this, e, t, n);
199
134
  write(e, t, n, r) {
200
135
  let i = this.bind();
201
136
  this.submit(i, e, t, (a) => {
@@ -208,13 +143,13 @@ var F = class e {
208
143
  else if (e.config.payloadMode === "defer" && e.config.enabled && !e.config.debugBuffer.enabled && this.namespace !== "uiobs.diagnostics") {
209
144
  if (!e.builder.isEnabled(t, this.namespace, n) && !this.mirrors(e, t)) return;
210
145
  let i = e.journey.current(), a = {
211
- timeUnixNano: Be(),
146
+ timeUnixNano: Pe(),
212
147
  trace: e.tracing.resolve(),
213
148
  journey: i ? { ...i } : null,
214
149
  context: e.context.getAll(),
215
- url: qe(e.diagnostics)
150
+ url: He(e.diagnostics)
216
151
  };
217
- yt(e, () => {
152
+ ut(e, () => {
218
153
  r(a);
219
154
  }, e.diagnostics, e.config.buffering.maxPendingRecords);
220
155
  } else r();
@@ -232,8 +167,8 @@ var F = class e {
232
167
  body: r,
233
168
  namespace: this.namespace,
234
169
  scoped: this.options.scopedContext,
235
- payload: a ? i : P(i, e.diagnostics)
236
- }, { record: c, dropped: l } = e.builder.build(s), u = !!e.config.redact || e.config.processors.length > 0, d = n !== "metric" && e.config.capturePolicy.breadcrumbs > 0, f = l === "sampling" && u && d ? e.builder.build(s, !0) : void 0, p = c ?? f?.record ?? null, m = p ? p.body : l === "sampling" && !u ? r : void 0;
170
+ payload: a ? i : z(i, e.diagnostics)
171
+ }, { record: c, dropped: l } = e.builder.build(s), u = !!e.config.redact || e.config.processors.length > 0, d = n !== "metric" && e.config.captureLimits.breadcrumbs > 0, f = l === "sampling" && u && d ? e.builder.build(s, !0) : void 0, p = c ?? f?.record ?? null, m = p ? p.body : l === "sampling" && !u ? r : void 0;
237
172
  d && m !== void 0 && e.breadcrumbs.push({
238
173
  t: o ? Number(o.timeUnixNano.slice(0, -6)) : Date.now(),
239
174
  category: n === "action" ? "action" : n === "event" ? "event" : "log",
@@ -249,12 +184,12 @@ var F = class e {
249
184
  writeErrorNow(e, t, n, r, i, a) {
250
185
  let o = e.builder.isEnabled(t, this.namespace);
251
186
  if (!o && !this.mirrors(e, t)) return;
252
- let s = i === void 0 && (e.diagnostics.guard("record.sanitize_failed", "The library could not read the error slot.", () => Tt(r)) ?? !1), c = s ? r : i, l = s ? void 0 : r, u = l === void 0 ? void 0 : St(l, e.diagnostics), d = u === void 0 ? void 0 : Ct(l, u, e.diagnostics);
187
+ let s = i === void 0 && (e.diagnostics.guard("record.sanitize_failed", "The library could not read the error slot.", () => gt(r)) ?? !1), c = s ? r : i, l = s ? void 0 : r, u = l === void 0 ? void 0 : pt(l, e.diagnostics), d = u === void 0 ? void 0 : mt(l, u, e.diagnostics);
253
188
  if (!o) {
254
189
  this.print(e, t, n, c, d, null, void 0, a);
255
190
  return;
256
191
  }
257
- let f = u ? wt(l, e.diagnostics) : void 0, { record: p, dropped: m } = e.builder.build({
192
+ let f = u ? ht(l, e.diagnostics) : void 0, { record: p, dropped: m } = e.builder.build({
258
193
  snapshot: a,
259
194
  level: t,
260
195
  type: this.levelType,
@@ -262,14 +197,14 @@ var F = class e {
262
197
  namespace: this.namespace,
263
198
  scoped: this.options.scopedContext,
264
199
  payload: {
265
- ...P(c, e.diagnostics),
200
+ ...z(c, e.diagnostics),
266
201
  ...u ? {
267
202
  "error.type": u.name,
268
203
  "error.message": u.message,
269
204
  "error.stack_trace": u.stack
270
205
  } : {},
271
- ...f === void 0 ? {} : { [me]: f },
272
- [b]: e.breadcrumbs.snapshot()
206
+ ...f === void 0 ? {} : { [se]: f },
207
+ [y]: e.breadcrumbs.snapshot()
273
208
  }
274
209
  });
275
210
  this.print(e, t, n, c, d, p, m, a), e.emit(p);
@@ -292,7 +227,7 @@ var F = class e {
292
227
  namespace: this.namespace,
293
228
  scoped: this.options.scopedContext,
294
229
  payload: {
295
- ...P(r, e.diagnostics),
230
+ ...z(r, e.diagnostics),
296
231
  ...i ? {
297
232
  "error.type": i.name,
298
233
  "error.message": i.message,
@@ -305,117 +240,336 @@ var F = class e {
305
240
  mirrors(e, t) {
306
241
  return e.config.enabled && e.console.accepts(t);
307
242
  }
308
- }, Dt = "overflow", Ot = /* @__PURE__ */ new Set([
309
- ve,
310
- ye,
311
- ue,
243
+ }, vt = class extends B {
244
+ constructor(...e) {
245
+ super(...e), k(this, "logMetric", (e, t, n = a, r = "gauge", i, o) => {
246
+ if (!Number.isFinite(t)) {
247
+ this.bind().diagnostics.report("record.dropped_malformed", "The metric value is not a finite number. The library dropped the metric.", { "metric.name": e });
248
+ return;
249
+ }
250
+ let s = this.bind();
251
+ this.submit(s, "INFO", "metric", (a) => {
252
+ let c = z(i, s.diagnostics), l = {
253
+ ...z(o, s.diagnostics),
254
+ ...c,
255
+ "metric.name": e,
256
+ "metric.value": t,
257
+ "metric.unit": n,
258
+ "metric.type": r,
259
+ [E.attributeKeys]: Object.keys(c)
260
+ };
261
+ this.writeNow(s, "INFO", "metric", e, l, !0, a);
262
+ });
263
+ });
264
+ }
265
+ }, yt = /^[0-9a-f]{32}$/, bt = /^[0-9a-f]{16}$/, xt = /[1-9a-f]/;
266
+ function St(e) {
267
+ return yt.test(e.traceId) && xt.test(e.traceId) && bt.test(e.spanId) && xt.test(e.spanId);
268
+ }
269
+ function Ct() {
270
+ return Ge(16);
271
+ }
272
+ function wt() {
273
+ return Ge(8);
274
+ }
275
+ function Tt(e) {
276
+ return {
277
+ traceId: Ct(),
278
+ spanId: wt(),
279
+ traceFlags: 1,
280
+ startedAt: Date.now(),
281
+ reason: e,
282
+ ended: !1
283
+ };
284
+ }
285
+ function Et(e, t, n) {
286
+ return `00-${e}-${t}-${(n & 255).toString(16).padStart(2, "0")}`;
287
+ }
288
+ function Dt(e) {
289
+ return {
290
+ traceId: e.traceId,
291
+ spanId: e.spanId,
292
+ traceFlags: e.traceFlags
293
+ };
294
+ }
295
+ var Ot = class {
296
+ constructor(e, t = me, n, r) {
297
+ k(this, "diagnostics", void 0), k(this, "maxAgeMs", void 0), k(this, "load", void 0), k(this, "spans", void 0), k(this, "ambient", Tt("start")), k(this, "otel", void 0), this.diagnostics = e, this.maxAgeMs = t, this.load = n, this.spans = r;
298
+ }
299
+ setup(e, t) {
300
+ this.maxAgeMs = e, this.load = t;
301
+ }
302
+ async loadOtel() {
303
+ if (this.load) try {
304
+ this.otel = await this.load();
305
+ } catch (e) {
306
+ this.diagnostics.report("trace.otel_failed", "The library could not load @opentelemetry/api. Records use the trace ids of the library.", void 0, e);
307
+ }
308
+ }
309
+ resolve() {
310
+ return this.activeSpanContext() ?? this.ambientContext();
311
+ }
312
+ ambientContext() {
313
+ return Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), Dt(this.ambient);
314
+ }
315
+ activeSpanContext() {
316
+ let e = this.otel;
317
+ if (e) return this.diagnostics.guard("trace.otel_failed", "The library could not read the active OpenTelemetry span.", () => {
318
+ let t = e.trace.getActiveSpan();
319
+ if (t === void 0) return;
320
+ let n = t.spanContext();
321
+ if (St(n)) return {
322
+ traceId: n.traceId,
323
+ spanId: n.spanId,
324
+ traceFlags: n.traceFlags
325
+ };
326
+ });
327
+ }
328
+ rotate(e) {
329
+ let t = this.ambient;
330
+ this.ambient = Tt(e);
331
+ let n = Dt(this.ambient);
332
+ return this.finish(t), n;
333
+ }
334
+ end() {
335
+ this.finish(this.ambient);
336
+ }
337
+ finish(e) {
338
+ e.ended || (e.ended = !0, this.spans?.onEnd({
339
+ traceId: e.traceId,
340
+ spanId: e.spanId,
341
+ reason: e.reason,
342
+ startedAt: e.startedAt,
343
+ endedAt: Date.now()
344
+ }));
345
+ }
346
+ headers() {
347
+ return this.trace(!1).headers;
348
+ }
349
+ request() {
350
+ return this.trace(!0);
351
+ }
352
+ trace(e) {
353
+ let t = {}, n = this.otel;
354
+ if (n && this.diagnostics.guard("trace.otel_failed", "The library could not add the OpenTelemetry headers.", () => {
355
+ n.propagation.inject(n.context.active(), t);
356
+ }), t.traceparent) return { headers: t };
357
+ let r = this.activeSpanContext(), i = r ?? this.ambientContext(), a = r ? void 0 : this.spans;
358
+ if (!a?.enabled()) return t[Te] = Et(i.traceId, i.spanId, i.traceFlags), { headers: t };
359
+ let o = a.keeps(i.traceId), s = o ? i.traceFlags : i.traceFlags & -2, c = e ? wt() : i.spanId;
360
+ return t[Te] = Et(i.traceId, c, s), !e || !o ? { headers: t } : {
361
+ headers: t,
362
+ span: {
363
+ traceId: i.traceId,
364
+ spanId: c,
365
+ parentSpanId: i.spanId
366
+ }
367
+ };
368
+ }
369
+ }, kt = {
370
+ name: "ui.measure.duration",
371
+ kind: "histogram",
372
+ unit: "ms",
373
+ boundaries: u
374
+ }, At = {
375
+ name: "ui.measure.phase.duration",
376
+ kind: "histogram",
377
+ unit: "ms",
378
+ boundaries: u
379
+ };
380
+ function jt(e, t, n, r) {
381
+ let i = String(e), a = Date.now(), o = performance.now(), s, c = !1, l = (e) => a + e - o, u = (e, a) => {
382
+ s &&= (r.metric(At, e - s.at, {
383
+ ...t,
384
+ "measure.name": i,
385
+ "measure.phase": s.name
386
+ }), n && r.span({
387
+ name: s.name,
388
+ kind: "internal",
389
+ traceId: n.traceId,
390
+ spanId: wt(),
391
+ parentSpanId: n.spanId,
392
+ startMs: l(s.at),
393
+ endMs: l(e),
394
+ error: a,
395
+ attributes: { "measure.name": i }
396
+ }), void 0);
397
+ };
398
+ return {
399
+ phase: (e) => {
400
+ if (c) return;
401
+ let t = performance.now();
402
+ u(t, !1), s = {
403
+ name: String(e),
404
+ at: t
405
+ };
406
+ },
407
+ end: (e = "ok") => {
408
+ if (c) return;
409
+ c = !0;
410
+ let s = performance.now(), d = e === "error";
411
+ u(s, d);
412
+ let f = {
413
+ ...t,
414
+ "measure.outcome": e
415
+ };
416
+ r.metric(kt, s - o, {
417
+ ...f,
418
+ "measure.name": i
419
+ }), n && r.span({
420
+ ...n,
421
+ name: i,
422
+ kind: "internal",
423
+ startMs: a,
424
+ endMs: l(s),
425
+ error: d,
426
+ attributes: f
427
+ });
428
+ }
429
+ };
430
+ }
431
+ function Mt(e, t, n) {
432
+ let r = "error";
433
+ try {
434
+ let i = t(), a = n.guard("record.sanitize_failed", "The library could not read what the function of the measure returned. The measure ends now.", () => i?.then);
435
+ if (typeof a != "function") return r = "ok", i;
436
+ let o = a.call(i, (t) => (e.end(), t), (t) => {
437
+ throw e.end("error"), t;
438
+ });
439
+ return r = void 0, o;
440
+ } finally {
441
+ r !== void 0 && e.end(r);
442
+ }
443
+ }
444
+ // src/core/meter.ts
445
+ var Nt = "overflow", Pt = /* @__PURE__ */ new Set([
446
+ S,
312
447
  C,
448
+ v,
449
+ T,
313
450
  x,
314
- De,
315
- Ce
451
+ ve,
452
+ fe
316
453
  ]);
317
- function kt(e = {}) {
454
+ function Ft(e = {}) {
318
455
  let t = {};
319
456
  for (let n of Object.keys(e).sort()) {
320
- if (n.startsWith("metric.") || Ot.has(n)) continue;
457
+ if (n.startsWith("metric.") || Pt.has(n)) continue;
321
458
  let r = e[n];
322
459
  (typeof r == "string" || typeof r == "boolean" || typeof r == "number" && Number.isFinite(r)) && (t[n] = r);
323
460
  }
324
461
  return t;
325
462
  }
326
- function At(e, t) {
463
+ function It(e, t) {
327
464
  if (!Array.isArray(e)) return null;
328
- let n = t === 0 ? e.length : Math.min(e.length, t + 1);
465
+ let n = t === null ? e.length : Math.min(e.length, t + 1);
329
466
  return Array.from({ length: n }, (t, n) => e[n]);
330
467
  }
331
- function jt(e, t) {
332
- return Array.isArray(e) && (t === 0 || e.length <= t) && e.every((t, n) => typeof t == "number" && Number.isFinite(t) && (n === 0 || t > e[n - 1]));
468
+ function Lt(e, t) {
469
+ return Array.isArray(e) && (t === null || e.length <= t) && e.every((t, n) => typeof t == "number" && Number.isFinite(t) && (n === 0 || t > e[n - 1]));
333
470
  }
334
- function Mt(e, t, n) {
471
+ function Rt(e, t, n) {
335
472
  let r = {
336
473
  "metric.name": e.name,
337
474
  "metric.unit": e.unit,
338
475
  "metric.type": e.kind,
339
- [y.start]: n,
340
- [y.attributeKeys]: Object.keys(t.attributes)
476
+ [E.start]: n,
477
+ [E.attributeKeys]: Object.keys(t.attributes)
341
478
  };
342
- return e.kind === "counter" ? (r["metric.value"] = t.sum, r) : {
479
+ return e.kind === "histogram" ? {
343
480
  ...r,
344
- [y.count]: t.count,
345
- [y.sum]: t.sum,
346
- [y.min]: t.min,
347
- [y.max]: t.max,
348
- [y.bounds]: e.boundaries,
349
- [y.buckets]: t.buckets
350
- };
481
+ [E.count]: t.count,
482
+ [E.sum]: t.sum,
483
+ [E.min]: t.min,
484
+ [E.max]: t.max,
485
+ [E.bounds]: e.boundaries,
486
+ [E.buckets]: t.buckets
487
+ } : (r["metric.value"] = e.kind === "gauge" ? t.last : t.sum, r);
488
+ }
489
+ function zt(e, t) {
490
+ try {
491
+ return {
492
+ unit: e.unit,
493
+ boundaries: e.boundaries
494
+ };
495
+ } catch (e) {
496
+ return t(e), {
497
+ unit: void 0,
498
+ boundaries: void 0
499
+ };
500
+ }
351
501
  }
352
- function Nt(e, t, n) {
353
- let r = {
502
+ function Bt(e, t, n, r) {
503
+ return {
354
504
  name: e,
355
- kind: "counter",
356
- unit: t.unit ?? "count",
505
+ kind: t,
506
+ unit: zt(n, r).unit ?? "count",
357
507
  boundaries: []
358
508
  };
509
+ }
510
+ function Vt(e, t, n, r) {
511
+ let i = Bt(e, "counter", t, r);
359
512
  return { add: (e, t) => {
360
- n(r, e, t);
513
+ n(i, e, t);
361
514
  } };
362
515
  }
363
- function Pt(e, t, n) {
364
- let r = {
516
+ function Ht(e, t, n, r) {
517
+ let i = Bt(e, "gauge", t, r);
518
+ return { set: (e, t) => {
519
+ n(i, e, t);
520
+ } };
521
+ }
522
+ function Ut(e, t, n, r) {
523
+ let { unit: i, boundaries: a } = zt(t, r), o = {
365
524
  name: e,
366
525
  kind: "histogram",
367
- unit: t.unit ?? "count",
368
- boundaries: t.boundaries ?? g
526
+ unit: i ?? "count",
527
+ boundaries: a ?? u,
528
+ fromApp: a !== void 0
369
529
  };
370
530
  return { record: (e, t) => {
371
- n(r, e, t);
531
+ n(o, e, t);
372
532
  } };
373
533
  }
374
- var Ft = class {
375
- intervalMs;
376
- emit;
377
- diagnostics;
378
- policy;
379
- instruments = /* @__PURE__ */ new Map();
380
- timer = null;
381
- startedAt = 0;
534
+ var Wt = class {
382
535
  constructor(e, t, n, r = {
383
536
  maxSeries: 100,
384
537
  maxInstruments: 1e3,
385
538
  maxHistogramBoundaries: 50
386
539
  }) {
387
- this.intervalMs = e, this.emit = t, this.diagnostics = n, this.policy = r;
540
+ k(this, "intervalMs", void 0), k(this, "emit", void 0), k(this, "diagnostics", void 0), k(this, "policy", void 0), k(this, "instruments", /* @__PURE__ */ new Map()), k(this, "timer", null), k(this, "startedAt", 0), this.intervalMs = e, this.emit = t, this.diagnostics = n, this.policy = r;
388
541
  }
389
542
  record(e, t, n) {
390
543
  !Number.isFinite(t) || e.kind === "counter" && t < 0 ? this.diagnostics.report("record.dropped_malformed", `The value of the metric ${e.name} is not valid. The library dropped it.`, { "metric.name": e.name }) : this.diagnostics.guard("record.sanitize_failed", `The library could not read the attributes of the metric ${e.name}.`, () => {
391
544
  let r = this.instrumentOf(e);
392
- r && (this.add(r, t, kt(n)), this.arm());
545
+ r && (this.add(r, t, Ft(n)), this.arm());
393
546
  });
394
547
  }
395
548
  collect() {
396
549
  this.timer !== null && (clearTimeout(this.timer), this.timer = null);
397
550
  let e = `${String(this.startedAt)}000000`, t = [...this.instruments.values()];
398
551
  this.instruments.clear();
399
- for (let { def: n, series: r } of t) for (let t of r.values()) this.emit(n.name, t.attributes, Mt(n, t, e));
552
+ for (let { def: n, series: r } of t) for (let t of r.values()) this.emit(n.name, t.attributes, Rt(n, t, e));
400
553
  }
401
554
  instrumentOf(e) {
402
555
  let t = this.instruments.get(e.name);
403
- if (t) return t.def.kind === e.kind ? t : (this.diagnostics.report("record.dropped_malformed", `The metric ${e.name} is a counter and a histogram. The library dropped the value.`, { "metric.name": e.name }), null);
404
- if (this.policy.maxInstruments && this.instruments.size >= this.policy.maxInstruments) return this.diagnostics.count("record.dropped_by_ceiling"), null;
405
- let n = At(e.boundaries, this.policy.maxHistogramBoundaries), r = jt(n, this.policy.maxHistogramBoundaries);
406
- e.kind === "histogram" && !r && this.diagnostics.report("config.invalid", `The boundaries of the metric ${e.name} must meet metrics.maxHistogramBoundaries and contain finite numbers in ascending order. The library uses the default boundaries.`);
407
- let i = {
556
+ if (t) return t.def.kind === e.kind ? t : (this.diagnostics.report("record.dropped_malformed", `The metric ${e.name} is a ${t.def.kind} and a ${e.kind}. The library dropped the value.`, { "metric.name": e.name }), null);
557
+ let { maxInstruments: n } = this.policy;
558
+ if (n !== null && this.instruments.size >= n) return this.diagnostics.count("record.dropped_by_ceiling"), null;
559
+ let r = e.fromApp === !0 ? this.policy.maxHistogramBoundaries : null, i = It(e.boundaries, r), a = Lt(i, r);
560
+ e.kind === "histogram" && !a && this.diagnostics.report("config.invalid", `The boundaries of the metric ${e.name} must meet metrics.maxHistogramBoundaries and contain finite numbers in ascending order. The library uses the default boundaries.`);
561
+ let o = {
408
562
  def: {
409
563
  ...e,
410
- boundaries: r ? n : [...g]
564
+ boundaries: a ? i : [...u]
411
565
  },
412
566
  series: /* @__PURE__ */ new Map()
413
567
  };
414
- return this.instruments.set(e.name, i), i;
568
+ return this.instruments.set(e.name, o), o;
415
569
  }
416
570
  add(e, t, n) {
417
- let r = JSON.stringify(n), i = e.series.get(r), a = n;
418
- if (!i && this.policy.maxSeries > 0 && e.series.size >= this.policy.maxSeries && (r = Dt, i = e.series.get(r), a = { [le]: !0 }), !i) {
571
+ let r = JSON.stringify(n), i = e.series.get(r), a = n, { maxSeries: o } = this.policy;
572
+ if (!i && o !== null && e.series.size >= o && (r = Nt, i = e.series.get(r), a = { [re]: !0 }), !i) {
419
573
  let n = e.def.kind === "histogram" ? e.def.boundaries.length + 1 : 0, o = Array(n).fill(0);
420
574
  i = {
421
575
  attributes: a,
@@ -423,10 +577,11 @@ var Ft = class {
423
577
  sum: 0,
424
578
  min: t,
425
579
  max: t,
580
+ last: t,
426
581
  buckets: o
427
582
  }, e.series.set(r, i);
428
583
  }
429
- if (i.count += 1, i.sum += t, i.min = Math.min(i.min, t), i.max = Math.max(i.max, t), i.buckets.length > 0) {
584
+ if (i.count += 1, i.sum += t, i.min = Math.min(i.min, t), i.max = Math.max(i.max, t), i.last = t, i.buckets.length > 0) {
430
585
  let n = e.def.boundaries.findIndex((e) => t <= e);
431
586
  i.buckets[n === -1 ? i.buckets.length - 1 : n] += 1;
432
587
  }
@@ -434,157 +589,45 @@ var Ft = class {
434
589
  arm() {
435
590
  this.timer === null && (this.startedAt = Date.now(), this.timer = setTimeout(() => {
436
591
  this.collect();
437
- }, this.intervalMs()), Ge(this.timer));
592
+ }, this.intervalMs()), O(this.timer));
438
593
  }
439
- }, It = {
594
+ }, Gt = {
440
595
  TRACE: "debug",
441
596
  DEBUG: "debug",
442
597
  INFO: "info",
443
598
  WARN: "warn",
444
599
  ERROR: "error",
445
600
  FATAL: "error"
446
- }, Lt = class {
447
- settings;
448
- diagnostics;
449
- limits;
450
- constructor(e, t, n = p) {
451
- this.settings = e, this.diagnostics = t, this.limits = n;
601
+ }, Kt = class {
602
+ constructor(e, t, n = ge) {
603
+ k(this, "settings", void 0), k(this, "diagnostics", void 0), k(this, "limits", void 0), this.settings = e, this.diagnostics = t, this.limits = n;
452
604
  }
453
605
  update(e) {
454
606
  this.settings = e;
455
607
  }
456
608
  accepts(e) {
457
- return this.settings.level === null || !Object.hasOwn(w, this.settings.level) ? !1 : w[e] >= w[this.settings.level];
609
+ return this.settings.level === null || !ze(w, this.settings.level) ? !1 : w[e] >= w[this.settings.level];
458
610
  }
459
611
  write(e, t, n, r, i) {
460
- if (!this.accepts(t) || typeof console > "u" || Je()) return;
461
- let a = `%c[%s]%c[${t}]%c`, { styles: o } = this.settings, s = It[t];
612
+ if (!this.accepts(t) || typeof console > "u" || Ye()) return;
613
+ let a = `%c[%s]%c[${t}]%c`, { styles: o } = this.settings, s = Gt[t];
462
614
  this.diagnostics.guard("handler.threw", `The library could not print to console.${s}.`, () => {
463
615
  let c = [];
464
- i !== void 0 && c.push(i), r !== void 0 && c.push(Xe(r, this.limits, this.diagnostics)), O(() => {
616
+ i !== void 0 && c.push(i), r !== void 0 && c.push(Ze(r, this.limits, this.diagnostics)), M(() => {
465
617
  console[s](a, o.namespace, e, o[t], "", n, ...c);
466
618
  });
467
619
  });
468
620
  }
469
- }, Rt = class {
470
- value = 0;
621
+ }, qt = class {
622
+ constructor() {
623
+ k(this, "value", 0);
624
+ }
471
625
  next() {
472
626
  return ++this.value;
473
627
  }
474
- }, zt = /^[0-9a-f]{32}$/, Bt = /^[0-9a-f]{16}$/, Vt = /[1-9a-f]/;
475
- function Ht(e) {
476
- return zt.test(e.traceId) && Vt.test(e.traceId) && Bt.test(e.spanId) && Vt.test(e.spanId);
477
- }
478
- function Ut() {
479
- return $e(16);
480
- }
481
- function Wt() {
482
- return $e(8);
483
- }
484
- function Gt(e) {
485
- return {
486
- traceId: Ut(),
487
- spanId: Wt(),
488
- traceFlags: 1,
489
- startedAt: Date.now(),
490
- reason: e,
491
- ended: !1
492
- };
493
- }
494
- function Kt(e, t, n) {
495
- return `00-${e}-${t}-${(n & 255).toString(16).padStart(2, "0")}`;
496
- }
497
- function qt(e) {
498
- return {
499
- traceId: e.traceId,
500
- spanId: e.spanId,
501
- traceFlags: e.traceFlags
502
- };
503
- }
504
- var Jt = class {
505
- diagnostics;
506
- maxAgeMs;
507
- load;
508
- spans;
509
- ambient = Gt("start");
510
- otel;
511
- constructor(e, t = o, n, r) {
512
- this.diagnostics = e, this.maxAgeMs = t, this.load = n, this.spans = r;
513
- }
514
- async loadOtel() {
515
- if (this.load) try {
516
- this.otel = await this.load();
517
- } catch (e) {
518
- this.diagnostics.report("trace.otel_failed", "The library could not load @opentelemetry/api. Records use the trace ids of the library.", void 0, e);
519
- }
520
- }
521
- resolve() {
522
- return this.activeSpanContext() ?? this.ambientContext();
523
- }
524
- ambientContext() {
525
- return Date.now() - this.ambient.startedAt > this.maxAgeMs && this.rotate("maxAge"), qt(this.ambient);
526
- }
527
- activeSpanContext() {
528
- let e = this.otel;
529
- if (e) return this.diagnostics.guard("trace.otel_failed", "The library could not read the active OpenTelemetry span.", () => {
530
- let t = e.trace.getActiveSpan();
531
- if (t === void 0) return;
532
- let n = t.spanContext();
533
- if (Ht(n)) return {
534
- traceId: n.traceId,
535
- spanId: n.spanId,
536
- traceFlags: n.traceFlags
537
- };
538
- });
539
- }
540
- rotate(e) {
541
- let t = this.ambient;
542
- this.ambient = Gt(e);
543
- let n = qt(this.ambient);
544
- return this.finish(t), n;
545
- }
546
- end() {
547
- this.finish(this.ambient);
548
- }
549
- finish(e) {
550
- e.ended || (e.ended = !0, this.spans?.onEnd({
551
- traceId: e.traceId,
552
- spanId: e.spanId,
553
- reason: e.reason,
554
- startedAt: e.startedAt,
555
- endedAt: Date.now()
556
- }));
557
- }
558
- headers() {
559
- return this.trace(!1).headers;
560
- }
561
- request() {
562
- return this.trace(!0);
563
- }
564
- trace(e) {
565
- let t = {}, n = this.otel;
566
- if (n && this.diagnostics.guard("trace.otel_failed", "The library could not add the OpenTelemetry headers.", () => {
567
- n.propagation.inject(n.context.active(), t);
568
- }), t.traceparent) return { headers: t };
569
- let r = this.activeSpanContext(), i = r ?? this.ambientContext(), a = r ? void 0 : this.spans;
570
- if (!a?.enabled()) return t[ee] = Kt(i.traceId, i.spanId, i.traceFlags), { headers: t };
571
- let o = a.keeps(i.traceId), s = o ? i.traceFlags : i.traceFlags & -2, c = e ? Wt() : i.spanId;
572
- return t[ee] = Kt(i.traceId, c, s), !e || !o ? { headers: t } : {
573
- headers: t,
574
- span: {
575
- traceId: i.traceId,
576
- spanId: c,
577
- parentSpanId: i.spanId
578
- }
579
- };
580
- }
581
- }, Yt = class {
582
- buffer;
583
- pointer = 0;
584
- filled = !1;
585
- capacity;
628
+ }, Jt = class {
586
629
  constructor(e) {
587
- this.capacity = e === 0 ? 0 : Math.max(e, 1), this.buffer = Array(this.capacity);
630
+ k(this, "buffer", void 0), k(this, "pointer", 0), k(this, "filled", !1), k(this, "capacity", void 0), this.capacity = e === 0 ? 0 : Math.max(e, 1), this.buffer = Array(this.capacity);
588
631
  }
589
632
  resize(e) {
590
633
  let t = this.snapshot().slice(-e);
@@ -593,467 +636,23 @@ var Jt = class {
593
636
  push(e) {
594
637
  this.capacity !== 0 && (this.buffer[this.pointer] = e, this.pointer = (this.pointer + 1) % this.capacity, this.pointer === 0 && (this.filled = !0));
595
638
  }
639
+ retain(e) {
640
+ let t = this.snapshot().filter(e);
641
+ this.clear();
642
+ for (let e of t) this.push(e);
643
+ }
596
644
  clear() {
597
645
  this.buffer.fill(void 0), this.pointer = 0, this.filled = !1;
598
646
  }
599
- snapshot() {
600
- return (this.filled ? [...this.buffer.slice(this.pointer), ...this.buffer.slice(0, this.pointer)] : this.buffer.slice(0, this.pointer)).filter((e) => e !== void 0);
601
- }
602
- }, Xt = Object.keys(w), Zt = ["gzip", "none"], Qt = [
603
- "omit",
604
- "same-origin",
605
- "include"
606
- ], $t = [
607
- "auto",
608
- "indexeddb",
609
- "localstorage",
610
- "memory",
611
- "none"
612
- ], en = ["storage", "memory"], tn = [
613
- "auto",
614
- "sender",
615
- "forwarder",
616
- "off"
617
- ], nn = [
618
- "auto",
619
- "provider",
620
- "client"
621
- ], rn = [
622
- "auto",
623
- "context",
624
- "tab",
625
- "origin"
626
- ], an = [
627
- "error",
628
- "warn",
629
- "info",
630
- "log"
631
- ], on = ["limited", "until-delivered"], sn = {
632
- logFlushIntervalMs: [100, 6e4],
633
- logBatchSize: [1, 1e3],
634
- metricFlushIntervalMs: [100, 6e4],
635
- metricBatchSize: [1, 1e3]
636
- }, cn = {
637
- maxBatches: [1, 5e3],
638
- maxAgeMs: [6e4, 6048e5],
639
- maxAttempts: [1, 20]
640
- }, ln = {
641
- maxBodyChars: [256, 65536],
642
- maxAttributeChars: [256, 65536],
643
- maxAttributeCount: [1, 1024],
644
- maxStackChars: [256, 65536],
645
- maxDepth: [1, 16],
646
- maxArrayLength: [1, 1e4],
647
- maxNodes: [100, 1e5],
648
- maxRecordBytes: [1024, r]
649
- }, un = [6e4, 864e5], I = [0, 2147483647], L = [0, 2 ** 53 - 1], dn = [1, 2 ** 53 - 1], fn = [100, 1e4], pn = {
650
- capturePolicy: { ranges: {
651
- breadcrumbs: [0, 1e6],
652
- errorDedupeMs: I,
653
- maxErrorSignatures: L,
654
- errorsPerWindow: L,
655
- consolePerWindow: L,
656
- longFramesPerWindow: L,
657
- webSocketPerWindow: L,
658
- reportsPerWindow: L,
659
- resourcesPerWindow: L,
660
- lifecyclePerWindow: L,
661
- windowMs: I,
662
- errorCeiling: L
663
- } },
664
- metadata: { ranges: {} },
665
- persistence: { ranges: {} },
666
- diagnostics: {
667
- ranges: { throttleMs: I },
668
- custom: { records: jn }
669
- },
670
- correlation: { ranges: {
671
- sessionIdleMs: I,
672
- sessionTouchMs: I,
673
- traceMaxAgeMs: I
674
- } },
675
- metrics: { ranges: {
676
- maxSeries: L,
677
- maxInstruments: L,
678
- maxHistogramBoundaries: L
679
- } },
680
- buffering: {
681
- ranges: {
682
- maxPendingRecords: L,
683
- maxPendingBytes: L
684
- },
685
- choices: { overflow: [
686
- "drop-oldest",
687
- "drop-newest",
688
- "persist"
689
- ] }
690
- },
691
- delivery: {
692
- ranges: {
693
- requestTimeoutMs: [1, I[1]],
694
- maxConcurrentRequests: dn,
695
- retryBaseDelayMs: I,
696
- retryMaxDelayMs: I,
697
- retryIdleDelayMs: I,
698
- batchesPerDrain: dn
699
- },
700
- choices: { priority: [
701
- "low",
702
- "auto",
703
- "high"
704
- ] }
705
- },
706
- debugBuffer: { ranges: {
707
- maxRecords: [1, 1e4],
708
- maxAgeMs: I
709
- } }
710
- }, mn = [
711
- "errors",
712
- "rejections",
713
- "resourceErrors",
714
- "fetch",
715
- "xhr",
716
- "httpMetrics",
717
- "navigation",
718
- "webVitals",
719
- "longFrames",
720
- "fullUrls",
721
- "webSocket",
722
- "uncleanExit",
723
- "userTiming",
724
- "serverTiming",
725
- "reports",
726
- "lifecycle"
727
- ], hn = "null", R = `a level name: ${Sn(Xt)}`, gn = `true, false or a list of ${Sn(an)}`, _n = "a list of strings and RegExp patterns", vn = "a list of origin URLs such as \"https://api.example\" and RegExp patterns", yn = "a list of origin URLs such as \"https://app.example\". For a sandboxed frame, set bus.mode: \"sender\" in the frame", bn = "a list of strings", xn = "true, false or a list of diagnostic codes";
728
- function Sn(e) {
729
- let t = e.map((e) => `"${e}"`);
730
- return `${t.slice(0, -1).join(", ")} or ${t[t.length - 1]}`;
731
- }
732
- function Cn(e) {
733
- return typeof e == "string" ? `"${e}"` : typeof e == "function" ? "a function" : typeof e == "object" && e ? "an object" : String(e);
734
- }
735
- function z(e, t, n, r, i) {
736
- e.report("config.invalid", `${t} must be ${n}. The value is ${Cn(r)}. The library keeps ${i}.`);
737
- }
738
- function B(e, t, n, r, i) {
739
- if (t === void 0) return r;
740
- let a = n.find((e) => e === t);
741
- return a === void 0 ? (z(i, e, Sn(n), t, `"${r}"`), r) : a;
742
- }
743
- function V(e, t, n, r) {
744
- return t === void 0 ? n : typeof t == "boolean" ? t : (z(r, e, "true or false", t, String(n)), n);
745
- }
746
- function wn(e, t, n, r) {
747
- return t === void 0 ? n : typeof t == "number" && Number.isFinite(t) && t >= 0 ? t : (z(r, e, "a finite number of 0 or more", t, String(n)), n);
748
- }
749
- function H(e, t, n, r, i) {
750
- if (t === void 0) return r;
751
- let [a, o] = n;
752
- return typeof t == "number" && Number.isInteger(t) && t >= a && t <= o ? t : (z(i, e, `an integer from ${String(a)} to ${String(o)}`, t, String(r)), r);
753
- }
754
- function Tn(e, t, n) {
755
- return e === void 0 ? t : e === null ? null : typeof e == "number" && Number.isSafeInteger(e) && e >= 0 ? e : (z(n, "loggerCache.maxEntries", "a nonnegative safe integer or null", e, String(t)), t);
756
- }
757
- function En(e, t, n, r, i) {
758
- let a = t ?? {}, o = Object.keys(r);
759
- return Object.fromEntries(o.map((t) => [t, H(`${e}.${t}`, a[t], r[t], n[t], i)]));
760
- }
761
- function U(e) {
762
- if (typeof e != "string") return;
763
- let t = e.toUpperCase();
764
- return Xt.find((e) => e === t);
765
- }
766
- function Dn(e, t, n, r) {
767
- if (t === void 0) return n;
768
- let i = U(t);
769
- return i === void 0 ? (z(r, e, R, t, `"${n}"`), n) : i;
770
- }
771
- function On(e, t, n) {
772
- if (e === void 0) return t;
773
- if (!E(e)) return z(n, "minLevels", "an object of level names", e, "the value in force"), t;
774
- let r = [];
775
- for (let [t, i] of Object.entries(e)) {
776
- let e = U(i);
777
- t !== "" && e !== void 0 ? r.push([t, e]) : z(n, `minLevels["${t}"]`, R, i, "minLevel for it");
778
- }
779
- return Object.fromEntries(r);
780
- }
781
- function W(e, t, n, r, i, a) {
782
- if (t === void 0) return n;
783
- if (!Array.isArray(t)) return z(a, e, r, t, "the list in force"), n;
784
- let o = [], s = t;
785
- for (let t of s) {
786
- let n = i(t);
787
- n === void 0 ? a.report("config.invalid", `The library ignores the ${e} entry ${Cn(t)}. ${e} must be ${r}.`) : o.push(n);
788
- }
789
- return o;
790
- }
791
- function kn(e) {
792
- return typeof e == "function" ? e : void 0;
793
- }
794
- function An(e) {
795
- return E(e) && typeof e.name == "string" && e.name !== "" && typeof e.install == "function" && typeof e.uninstall == "function" ? e : void 0;
796
- }
797
- function jn(e, t, n, r) {
798
- return t === void 0 || typeof t == "boolean" ? t ?? n : Array.isArray(t) ? W(e, t, [], xn, Mn, r) : (z(r, e, xn, t, "the value in force"), n);
799
- }
800
- function Mn(e) {
801
- return typeof e == "string" ? e : void 0;
802
- }
803
- function Nn(e) {
804
- return typeof e == "string" || e instanceof RegExp ? e : void 0;
805
- }
806
- function Pn(e) {
807
- return an.find((t) => t === e);
808
- }
809
- function Fn(e) {
810
- if (typeof e == "string") try {
811
- let { origin: t } = new URL(e);
812
- return t === hn ? void 0 : t;
813
- } catch {
814
- return;
815
- }
816
- }
817
- function In(e) {
818
- return e instanceof RegExp ? e : Fn(e);
819
- }
820
- function Ln(e) {
821
- return E(e) ? Object.values(e).every((e) => typeof e == "string") : !1;
822
- }
823
- function Rn(e, t, n) {
824
- if (e !== void 0) return typeof e == "function" || Ln(e) ? e : (n.report("config.invalid", "headers must be an object of strings or a function. The library keeps the headers in force."), t);
825
- }
826
- function zn(e) {
827
- return typeof e != "object" || !e ? !1 : typeof Reflect.get(e, "serialize") == "function";
828
- }
829
- function Bn(e, t, n) {
830
- return e === void 0 ? t ?? "otlp" : e === "otlp" || e === "ecs" || zn(e) ? e : (n.report("config.invalid", `serializer must be "${S}", "ecs" or an implementation. The library uses "${S}".`), S);
831
- }
832
- var Vn = new Set(Object.keys(m));
833
- function Hn(e, t) {
834
- let n = {}, r = Object.entries(e ?? {});
835
- for (let [e, i] of r) Vn.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.`);
836
- return n;
837
- }
838
- function Un(e, t, n) {
839
- if (e === void 0) return t ?? "DEBUG";
840
- let r = U(e);
841
- return r === void 0 ? (z(n, "console.level", R, e, "the console level in force"), t) : r;
842
- }
843
- function Wn(e, t, n) {
844
- if (e === void 0) return t;
845
- if (e === !1) return {
846
- level: null,
847
- styles: t.styles
848
- };
849
- if (e === !0) return {
850
- level: l,
851
- styles: t.styles
852
- };
853
- if (typeof e == "string") {
854
- let r = U(e);
855
- return r === void 0 ? (z(n, "console", R, e, "the console level in force"), t) : {
856
- level: r,
857
- styles: t.styles
858
- };
859
- }
860
- return 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) : {
861
- level: Un(e.level, t.level, n),
862
- styles: {
863
- ...t.styles,
864
- ...Hn(e.styles, n)
865
- }
866
- };
867
- }
868
- function Gn(e, t, n) {
869
- let r = e ?? {};
870
- return {
871
- ...t,
872
- ...r,
873
- rates: {
874
- ...t.rates,
875
- ...r.rates
876
- },
877
- alwaysSampleTypes: W("sampling.alwaysSampleTypes", r.alwaysSampleTypes, t.alwaysSampleTypes, bn, Mn, n),
878
- alwaysSampleFrom: Dn("sampling.alwaysSampleFrom", r.alwaysSampleFrom, t.alwaysSampleFrom, n),
879
- remote: V("sampling.remote", r.remote, t.remote, n)
880
- };
881
- }
882
- function Kn(e, t, n) {
883
- let r = e ?? {};
884
- return {
885
- maxTrackedSources: H("bus.maxTrackedSources", r.maxTrackedSources, [0, 2 ** 53 - 1], t.maxTrackedSources, n),
886
- sourcePolicy: B("bus.sourcePolicy", r.sourcePolicy, ["registered", "trusted-origin"], t.sourcePolicy, n),
887
- validation: B("bus.validation", r.validation, ["strict", "envelope"], t.validation, n),
888
- maxMessageBytes: H("bus.maxMessageBytes", r.maxMessageBytes, [0, 2 ** 53 - 1], t.maxMessageBytes, n),
889
- maxRecordsPerMessage: H("bus.maxRecordsPerMessage", r.maxRecordsPerMessage, [0, 2 ** 53 - 1], t.maxRecordsPerMessage, n),
890
- maxMessagesPerSecond: H("bus.maxMessagesPerSecond", r.maxMessagesPerSecond, [0, 2 ** 53 - 1], t.maxMessagesPerSecond, n),
891
- mode: B("bus.mode", r.mode, tn, t.mode, n),
892
- trustedOrigins: W("bus.trustedOrigins", r.trustedOrigins, t.trustedOrigins, yn, Fn, n),
893
- openFinRole: B("bus.openFinRole", r.openFinRole, nn, t.openFinRole, n)
894
- };
895
- }
896
- function qn(e, t, n) {
897
- let r = e ?? {};
898
- return {
899
- scope: B("journey.scope", r.scope, rn, t.scope, n),
900
- maxAgeMs: H("journey.maxAgeMs", r.maxAgeMs, un, t.maxAgeMs, n)
901
- };
902
- }
903
- function Jn(e, t, n) {
904
- let r = e ?? {};
905
- return {
906
- mode: B("retention.mode", r.mode, on, t.mode, n),
907
- ...En("retention", r, t, cn, n)
908
- };
909
- }
910
- function Yn(e, t, n) {
911
- return e === void 0 ? t : typeof e == "boolean" ? e : Array.isArray(e) ? W("capture.console", e, [], gn, Pn, n) : (z(n, "capture.console", gn, e, "the value in force"), t);
912
- }
913
- function Xn(e, t, n) {
914
- let r = e ?? {}, i = {
915
- ...t,
916
- ...r,
917
- remoteToggles: W("capture.remoteToggles", r.remoteToggles, t.remoteToggles, "a list of capture switch names without privacy controls", (e) => ke.find((t) => t === e), n),
918
- resourceTiming: Zn(r.resourceTiming, t.resourceTiming, n),
919
- interactions: Qn(r.interactions, t.interactions, n),
920
- console: Yn(r.console, t.console, n),
921
- longFrameThresholdMs: wn("capture.longFrameThresholdMs", r.longFrameThresholdMs, t.longFrameThresholdMs, n),
922
- ignoreUrls: W("capture.ignoreUrls", r.ignoreUrls, t.ignoreUrls, _n, Nn, n),
923
- userTimingInclude: W("capture.userTimingInclude", r.userTimingInclude, t.userTimingInclude, _n, Nn, n),
924
- propagateTraceHeaderTo: W("capture.propagateTraceHeaderTo", r.propagateTraceHeaderTo, t.propagateTraceHeaderTo, vn, In, n),
925
- plugins: W("capture.plugins", r.plugins, t.plugins, "a list of objects with a name, install() and uninstall()", An, n)
926
- };
927
- for (let e of mn) i[e] = V(`capture.${e}`, r[e], t[e], n);
928
- return i;
929
- }
930
- function Zn(e, t, n) {
931
- return e === void 0 ? t : typeof e == "boolean" ? e : E(e) ? { slowMs: wn("capture.resourceTiming.slowMs", e.slowMs, typeof t == "object" ? t.slowMs ?? 1e3 : Ee, n) } : (n.report("config.invalid", "capture.resourceTiming must be a boolean or an options object."), t);
932
- }
933
- function Qn(e, t, n) {
934
- if (e === void 0) return t;
935
- if (typeof e == "boolean") return e;
936
- if (!E(e)) return n.report("config.invalid", "capture.interactions must be a boolean or an options object."), t;
937
- let r = typeof t == "object" ? t : {}, i = e.ignoreSelector, a = i === void 0 ? r.ignoreSelector : i;
938
- if (a != null) try {
939
- if (typeof a != "string") throw Error("Invalid selector");
940
- typeof document < "u" && document.createElement("div").matches(a);
941
- } catch {
942
- n.report("config.invalid", "capture.interactions.ignoreSelector must be a valid CSS selector or null."), a = r.ignoreSelector;
943
- }
944
- let o = r.actionAttribute ?? "data-observability-action";
945
- return e.actionAttribute !== void 0 && (typeof e.actionAttribute == "string" && /^[a-z][\w-]*$/i.test(e.actionAttribute) ? o = e.actionAttribute : z(n, "capture.interactions.actionAttribute", "an attribute name of letters, digits, hyphens and underscores", e.actionAttribute, `"${o}"`)), {
946
- actionAttribute: o,
947
- text: V("capture.interactions.text", e.text, r.text ?? !1, n),
948
- selector: V("capture.interactions.selector", e.selector, r.selector ?? !1, n),
949
- ignoreSelector: typeof a == "string" || a === null ? a : void 0,
950
- maxTextChars: H("capture.interactions.maxTextChars", e.maxTextChars, [0, 2 ** 53 - 1], r.maxTextChars ?? 50, n),
951
- rageClicks: V("capture.interactions.rageClicks", e.rageClicks, r.rageClicks ?? !1, n),
952
- rageClickCount: H("capture.interactions.rageClickCount", e.rageClickCount, [2, 20], r.rageClickCount ?? 3, n),
953
- rageClickWindowMs: H("capture.interactions.rageClickWindowMs", e.rageClickWindowMs, fn, r.rageClickWindowMs ?? 1e3, n),
954
- deadClicks: V("capture.interactions.deadClicks", e.deadClicks, r.deadClicks ?? !1, n),
955
- deadClickMs: H("capture.interactions.deadClickMs", e.deadClickMs, fn, r.deadClickMs ?? 1e3, n)
956
- };
957
- }
958
- var $n = {
959
- metricsEndpoint: "The library sends metric records as log records.",
960
- tracesEndpoint: "The library sends no span."
961
- };
962
- function er(e, t, n, r, i) {
963
- let a = n;
964
- if (typeof t == "string" && t !== "") try {
965
- new URL(t), a = t;
966
- } catch (n) {
967
- i.report("config.invalid", `${e} is not a valid absolute URL: ${D(t, !1)}. The library keeps the value in force.`, void 0, n);
968
- }
969
- else t === "" ? a = "" : t !== void 0 && z(i, e, "a URL string", t, "the value in force");
970
- return a !== "" && r !== "otlp" ? (i.report("config.invalid", `${e} needs serializer "${S}". ${$n[e]}`), "") : a;
971
- }
972
- function tr(e, t, n, r, i) {
973
- let a = { ...n };
974
- for (let o of Object.keys(n)) {
975
- let s = t?.[o], c = n[o], l = r.ranges[o], u = r.choices?.[o], d = r.custom?.[o], f = c;
976
- d ? f = d(`${e}.${o}`, s, c, i) : typeof c == "number" && l ? f = H(`${e}.${o}`, s, l, c, i) : typeof c == "boolean" ? f = V(`${e}.${o}`, s, c, i) : u ? f = B(`${e}.${o}`, s, u, String(c), i) : s === void 0 || typeof s == "string" ? f = s ?? c : z(i, `${e}.${o}`, "a string", s, String(c)), Object.assign(a, { [o]: f });
977
- }
978
- return a;
979
- }
980
- function G(e, t, n) {
981
- let r = n ?? re, i = Object.fromEntries(Object.keys(pn).map((n) => [n, tr(n, e[n], r[n], pn[n], t)])), a = {
982
- ...r,
983
- ...e,
984
- ...i,
985
- lockConfiguration: V("lockConfiguration", e.lockConfiguration, r.lockConfiguration, t),
986
- loggerCache: { maxEntries: Tn(e.loggerCache?.maxEntries, r.loggerCache.maxEntries, t) },
987
- securityContext: {
988
- id: typeof e.securityContext?.id == "string" && e.securityContext.id || r.securityContext.id,
989
- isolation: V("securityContext.isolation", e.securityContext?.isolation, r.securityContext.isolation, t)
990
- },
991
- endpoint: e.endpoint === void 0 ? r.endpoint : e.endpoint,
992
- enabled: V("enabled", e.enabled, r.enabled, t),
993
- payloadMode: B("payloadMode", e.payloadMode, ["copy", "defer"], r.payloadMode, t),
994
- minLevel: Dn("minLevel", e.minLevel, r.minLevel, t),
995
- minLevels: On(e.minLevels, r.minLevels, t),
996
- processors: W("processors", e.processors, r.processors, "a list of functions", kn, t),
997
- compression: B("compression", e.compression, Zt, r.compression, t),
998
- credentials: B("credentials", e.credentials, Qt, r.credentials, t),
999
- headers: "headers" in e ? Rn(e.headers, r.headers, t) : r.headers,
1000
- storage: B("storage", e.storage, $t, r.storage, t),
1001
- identity: B("identity", e.identity, en, r.identity, t),
1002
- serializer: Bn(e.serializer, n?.serializer, t),
1003
- console: Wn(e.console, r.console, t),
1004
- sampling: Gn(e.sampling, r.sampling, t),
1005
- bus: Kn(e.bus, r.bus, t),
1006
- batching: En("batching", e.batching, r.batching, sn, t),
1007
- retention: Jn(e.retention, r.retention, t),
1008
- limits: En("limits", e.limits, r.limits, ln, t),
1009
- journey: qn(e.journey, r.journey, t),
1010
- capture: Xn(e.capture, r.capture, t)
1011
- };
1012
- for (let n of ["metricsEndpoint", "tracesEndpoint"]) a[n] = er(n, e[n], r[n], a.serializer, t);
1013
- if (a.transport !== void 0 && typeof a.transport != "function" && (t.report("config.invalid", "transport must be a function. The library ignores the value."), a.transport = r.transport), a.onDrop !== void 0 && typeof a.onDrop != "function" && (t.report("config.invalid", "onDrop must be a function. The library ignores the value."), a.onDrop = r.onDrop), a.contextProvider !== void 0 && typeof a.contextProvider != "function" && (t.report("config.invalid", "contextProvider must be a function. The library ignores the value."), a.contextProvider = r.contextProvider), a.transportWorker !== void 0 && typeof a.transportWorker != "function" && (t.report("config.invalid", "transportWorker must be a function. The library keeps the value in force."), a.transportWorker = r.transportWorker), a.transportOnExit !== void 0 && typeof a.transportOnExit != "function" && (t.report("config.invalid", "transportOnExit must be a function. The library ignores the value."), a.transportOnExit = r.transportOnExit), a.endpoint === "") a.transport === void 0 && t.report("config.invalid", "endpoint is missing. The library drops each record. Set endpoint: null for console-only mode.");
1014
- else if (a.endpoint !== null) try {
1015
- new URL(a.endpoint);
1016
- } catch (e) {
1017
- t.report("config.invalid", `endpoint is not a valid absolute URL: ${D(a.endpoint, !1)}.`, void 0, e);
1018
- }
1019
- for (let e of ["metricsEndpoint", "tracesEndpoint"]) a[e] !== "" && a.endpoint === null && !a.transport && t.report("config.invalid", `${e} needs endpoint or transport. The library sends nothing to ${e}.`);
1020
- a.serviceName ||= (t.report("config.invalid", `serviceName is missing. Every record reports service.name as '${oe}'.`), oe);
1021
- let o = a.sampling.defaultRate;
1022
- (typeof o != "number" || o < 0 || o > 1) && (t.report("config.invalid", `sampling.defaultRate must be 0..1. The value is ${String(o)}. The library uses 1.`), a.sampling.defaultRate = 1);
1023
- let s = a.sampling.remoteMaxRate;
1024
- typeof s == "number" && s >= 0 && s <= 1 || (t.report("config.invalid", `sampling.remoteMaxRate must be 0..1. The value is ${String(s)}. The library uses 1.`), a.sampling.remoteMaxRate = 1);
1025
- let c = Object.entries(a.sampling.rates);
1026
- for (let [e, n] of c) (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.`), a.sampling.rates[e] = 1);
1027
- a.capture.ignoreUrls = a.capture.ignoreUrls.filter((e) => e !== n?.endpoint && e !== n?.metricsEndpoint && e !== n?.tracesEndpoint);
1028
- for (let e of [
1029
- a.endpoint,
1030
- a.metricsEndpoint,
1031
- a.tracesEndpoint
1032
- ]) e && !a.capture.ignoreUrls.includes(e) && (a.capture.ignoreUrls = [...a.capture.ignoreUrls, e]);
1033
- return a.delivery.retryMaxDelayMs < a.delivery.retryBaseDelayMs && (t.report("config.invalid", "delivery.retryMaxDelayMs must be at least retryBaseDelayMs."), a.delivery.retryBaseDelayMs = r.delivery.retryBaseDelayMs, a.delivery.retryMaxDelayMs = r.delivery.retryMaxDelayMs), a.capture.urlTransform !== void 0 && typeof a.capture.urlTransform != "function" && (t.report("config.invalid", "capture.urlTransform must be a function."), a.capture.urlTransform = r.capture.urlTransform), nr(e, t), a;
1034
- }
1035
- function nr(e, t) {
1036
- let n = /* @__PURE__ */ new Set([...Object.keys(re), ...c]);
1037
- 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.`);
1038
- for (let n of a) {
1039
- let r = e[n];
1040
- if (typeof r != "object" || !r) continue;
1041
- let i = /* @__PURE__ */ new Set([...Object.keys(re[n]), ...ie[n]]);
1042
- 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.`);
647
+ snapshot() {
648
+ return (this.filled ? [...this.buffer.slice(this.pointer), ...this.buffer.slice(0, this.pointer)] : this.buffer.slice(0, this.pointer)).filter((e) => e !== void 0);
1043
649
  }
1044
- }
1045
- function rr(e, t) {
1046
- for (let n of Object.keys(t)) a.includes(n) || Object.assign(e, { [n]: t[n] });
1047
- for (let n of a) Object.assign(e[n], t[n]);
1048
- }
1049
- // src/core/context.ts
1050
- var ir = class {
1051
- map = /* @__PURE__ */ new Map();
1052
- set(e, t) {
1053
- this.map.set(e, t);
650
+ }, Yt = class {
651
+ constructor() {
652
+ k(this, "map", /* @__PURE__ */ new Map());
1054
653
  }
1055
- setMany(e) {
1056
- for (let [t, n] of Object.entries(e)) this.map.set(t, n);
654
+ merge(e) {
655
+ for (let [t, n] of Object.entries(e)) n === null ? this.map.delete(t) : n !== void 0 && this.map.set(t, n);
1057
656
  }
1058
657
  remove(e) {
1059
658
  this.map.delete(e);
@@ -1064,11 +663,9 @@ var ir = class {
1064
663
  getAll() {
1065
664
  return Object.fromEntries(this.map);
1066
665
  }
1067
- }, ar = class {
1068
- policy;
1069
- kept = [];
666
+ }, Xt = class {
1070
667
  constructor(e) {
1071
- this.policy = e;
668
+ k(this, "policy", void 0), k(this, "kept", []), this.policy = e;
1072
669
  }
1073
670
  push(e) {
1074
671
  let { enabled: t, maxRecords: n } = this.policy();
@@ -1083,7 +680,7 @@ var ir = class {
1083
680
  ...e,
1084
681
  attributes: {
1085
682
  ...e.attributes,
1086
- [Pe]: !0
683
+ [Ee]: !0
1087
684
  }
1088
685
  }));
1089
686
  }
@@ -1093,20 +690,15 @@ var ir = class {
1093
690
  live() {
1094
691
  let { enabled: e, maxRecords: t, maxAgeMs: n } = this.policy();
1095
692
  if (!e) return this.kept = [], [];
1096
- let r = n === 0 ? -Infinity : Date.now() - n;
693
+ let r = n === null ? -Infinity : Date.now() - n;
1097
694
  return this.kept.slice(-t).filter((e) => e.at >= r);
1098
695
  }
1099
696
  clear() {
1100
697
  this.kept = [];
1101
698
  }
1102
- }, or = class {
1103
- handler;
1104
- throttleMs;
1105
- consoleFallback;
1106
- counters = /* @__PURE__ */ new Map();
1107
- lastEmitted = /* @__PURE__ */ new Map();
1108
- constructor(e, t = d, n = !1) {
1109
- this.handler = e, this.throttleMs = t, this.consoleFallback = n;
699
+ }, V = class {
700
+ constructor(e, t = ne, n = !1) {
701
+ k(this, "handler", void 0), k(this, "throttleMs", void 0), k(this, "consoleFallback", void 0), k(this, "counters", /* @__PURE__ */ new Map()), k(this, "lastEmitted", /* @__PURE__ */ new Map()), this.handler = e, this.throttleMs = t, this.consoleFallback = n;
1110
702
  }
1111
703
  setPolicy(e, t) {
1112
704
  this.throttleMs = e, this.consoleFallback = t;
@@ -1119,26 +711,28 @@ var ir = class {
1119
711
  return this.counters.set(e, n), n;
1120
712
  }
1121
713
  report(e, t, n, r) {
1122
- let a = this.count(e), o = Date.now();
1123
- if (o - (this.lastEmitted.get(e) ?? 0) < this.throttleMs) return;
1124
- this.lastEmitted.set(e, o);
1125
- let s = {
714
+ let i = this.count(e), a = Date.now();
715
+ if (a - (this.lastEmitted.get(e) ?? 0) < this.throttleMs) return !1;
716
+ this.lastEmitted.set(e, a);
717
+ let o = {
1126
718
  code: e,
1127
719
  message: t,
1128
720
  detail: n,
1129
721
  cause: r,
1130
- at: o,
1131
- count: a
1132
- }, { handler: c } = this;
1133
- if (c) try {
1134
- O(() => {
1135
- c(s);
722
+ at: a,
723
+ count: i
724
+ }, { handler: s } = this;
725
+ if (!s) return !0;
726
+ try {
727
+ M(() => {
728
+ s(o);
1136
729
  });
1137
730
  } catch {
1138
- this.count("handler.threw"), this.consoleFallback && typeof console < "u" && O(() => {
1139
- console.warn(`${i} The onDiagnostic handler threw an error.`);
731
+ this.count("handler.threw"), this.consoleFallback && typeof console < "u" && M(() => {
732
+ console.warn(`${de} The onDiagnostic handler threw an error.`);
1140
733
  });
1141
734
  }
735
+ return !0;
1142
736
  }
1143
737
  guard(e, t, n) {
1144
738
  try {
@@ -1161,39 +755,37 @@ var ir = class {
1161
755
  }
1162
756
  };
1163
757
  // src/core/drops.ts
1164
- function sr(e, t) {
758
+ function Zt(e, t) {
1165
759
  e.length < 20 && !e.includes(t) && e.push(t);
1166
760
  }
1167
- var cr = class {
1168
- config;
1169
- diagnostics;
1170
- pending = /* @__PURE__ */ new Map();
1171
- scheduled = !1;
1172
- reporting = !1;
761
+ var Qt = class {
1173
762
  constructor(e, t) {
1174
- this.config = e, this.diagnostics = t;
763
+ k(this, "config", void 0), k(this, "diagnostics", void 0), k(this, "pending", /* @__PURE__ */ new Map()), k(this, "scheduled", !1), k(this, "reporting", !1), k(this, "lost", {}), this.config = e, this.diagnostics = t;
1175
764
  }
1176
- add(e, t, n = []) {
1177
- if (!this.config.onDrop || this.reporting || t.length === 0 && n.length === 0) return;
1178
- let r = this.pending.get(e);
1179
- r || (r = {
765
+ add(e, t, n = [], r = t.length) {
766
+ if (r > 0 && (this.lost[e] = (this.lost[e] ?? 0) + r), !this.config.onDrop || this.reporting || t.length === 0 && n.length === 0) return;
767
+ let i = this.pending.get(e);
768
+ i || (i = {
1180
769
  reason: e,
1181
770
  records: 0,
1182
771
  batchIds: [],
1183
772
  journeyIds: [],
1184
773
  actions: []
1185
- }, this.pending.set(e, r)), r.records += t.length;
1186
- for (let e of n) sr(r.batchIds, e);
774
+ }, this.pending.set(e, i)), i.records += r;
775
+ for (let e of n) Zt(i.batchIds, e);
1187
776
  for (let e of t) {
1188
- let t = at(e, x);
1189
- typeof t == "string" && sr(r.journeyIds, t);
1190
- let n = it(e) ? e.body : void 0;
1191
- typeof n == "string" && sr(r.actions, n);
777
+ let t = tt(e, x);
778
+ typeof t == "string" && Zt(i.journeyIds, t);
779
+ let n = et(e) ? e.body : void 0;
780
+ typeof n == "string" && Zt(i.actions, n);
1192
781
  }
1193
782
  this.scheduled || (this.scheduled = !0, queueMicrotask(() => {
1194
783
  this.flush();
1195
784
  }));
1196
785
  }
786
+ counts() {
787
+ return { ...this.lost };
788
+ }
1197
789
  flush() {
1198
790
  this.scheduled = !1;
1199
791
  let e = [...this.pending.values()];
@@ -1202,8 +794,8 @@ var cr = class {
1202
794
  if (t) {
1203
795
  this.reporting = !0;
1204
796
  for (let n of e) this.diagnostics.guard("handler.threw", "The onDrop hook threw an error.", () => {
1205
- rt(() => {
1206
- O(() => {
797
+ Qe(() => {
798
+ M(() => {
1207
799
  t(n);
1208
800
  });
1209
801
  });
@@ -1211,137 +803,121 @@ var cr = class {
1211
803
  this.reporting = !1;
1212
804
  }
1213
805
  }
1214
- }, lr = class {
1215
- onDrop;
1216
- held = [];
1217
- actions = 0;
806
+ }, $t = class {
1218
807
  constructor(e) {
1219
- this.onDrop = e;
808
+ k(this, "onDrop", void 0), k(this, "actions", {
809
+ head: [],
810
+ tail: []
811
+ }), k(this, "others", {
812
+ head: [],
813
+ tail: []
814
+ }), k(this, "arrivals", 0), this.onDrop = e;
1220
815
  }
1221
816
  get records() {
1222
- return this.held;
817
+ return this.inOrder();
1223
818
  }
1224
819
  get length() {
1225
- return this.held.length;
820
+ let { actions: e, others: t } = this;
821
+ return e.head.length + e.tail.length + t.head.length + t.tail.length;
1226
822
  }
1227
- push(e) {
1228
- let t = it(e);
1229
- if ((t ? this.actions : this.held.length - this.actions) < (t ? 2e3 : 500)) this.actions += +!!t;
1230
- else {
1231
- let e = this.held.findIndex((e) => it(e) === t), [n] = this.held.splice(e, 1);
1232
- this.onDrop(n);
823
+ push(e, t) {
824
+ let n = et(e), r = n ? this.actions : this.others, i = n ? ue : t, a = {
825
+ record: e,
826
+ arrival: this.arrivals
827
+ };
828
+ if (this.arrivals += 1, r.head.length < 100) r.head.push(a);
829
+ else if (r.tail.push(a), r.head.length + r.tail.length > i) {
830
+ let e = r.tail[0];
831
+ r.tail.shift(), this.onDrop(e.record);
1233
832
  }
1234
- this.held.push(e);
1235
833
  }
1236
834
  take() {
1237
- let e = this.held;
1238
- return this.held = [], this.actions = 0, e;
1239
- }
1240
- }, ur = {
1241
- name: "ui.measure.duration",
1242
- kind: "histogram",
1243
- unit: "ms",
1244
- boundaries: g
1245
- }, dr = {
1246
- name: "ui.measure.phase.duration",
1247
- kind: "histogram",
1248
- unit: "ms",
1249
- boundaries: g
1250
- };
1251
- function fr(e, t, n, r) {
1252
- let i = String(e), a = Date.now(), o = performance.now(), s, c = !1, l = (e) => a + e - o, u = (e, a) => {
1253
- s &&= (r.metric(dr, e - s.at, {
1254
- ...t,
1255
- "measure.name": i,
1256
- "measure.phase": s.name
1257
- }), n && r.span({
1258
- name: s.name,
1259
- kind: "internal",
1260
- traceId: n.traceId,
1261
- spanId: Wt(),
1262
- parentSpanId: n.spanId,
1263
- startMs: l(s.at),
1264
- endMs: l(e),
1265
- error: a,
1266
- attributes: { "measure.name": i }
1267
- }), void 0);
1268
- };
1269
- return {
1270
- phase: (e) => {
1271
- if (c) return;
1272
- let t = performance.now();
1273
- u(t, !1), s = {
1274
- name: String(e),
1275
- at: t
1276
- };
1277
- },
1278
- end: (e = "ok") => {
1279
- if (c) return;
1280
- c = !0;
1281
- let s = performance.now(), d = e === "error";
1282
- u(s, d);
1283
- let f = {
1284
- ...t,
1285
- "measure.outcome": e
1286
- };
1287
- r.metric(ur, s - o, {
1288
- ...f,
1289
- "measure.name": i
1290
- }), n && r.span({
1291
- ...n,
1292
- name: i,
1293
- kind: "internal",
1294
- startMs: a,
1295
- endMs: l(s),
1296
- error: d,
1297
- attributes: f
1298
- });
1299
- }
1300
- };
1301
- }
1302
- // src/core/record.ts
1303
- var pr = "error.", mr = [
1304
- C,
835
+ let e = this.inOrder();
836
+ return this.actions = {
837
+ head: [],
838
+ tail: []
839
+ }, this.others = {
840
+ head: [],
841
+ tail: []
842
+ }, this.arrivals = 0, e;
843
+ }
844
+ inOrder() {
845
+ let { actions: e, others: t } = this;
846
+ return [
847
+ ...e.head,
848
+ ...e.tail,
849
+ ...t.head,
850
+ ...t.tail
851
+ ].sort((e, t) => e.arrival - t.arrival).map((e) => e.record);
852
+ }
853
+ }, en = "error.", tn = [
854
+ T,
1305
855
  x,
1306
- De
1307
- ], hr = {
856
+ ve
857
+ ], nn = {
1308
858
  processor: {
1309
859
  label: "A processor",
1310
- code: "record.dropped_by_processor"
860
+ code: "record.dropped_by_processor",
861
+ refused: "processors is not a list of functions. The library drops each record until processors is a list of functions or []."
1311
862
  },
1312
863
  redact: {
1313
864
  label: "The redact hook",
1314
- code: "record.dropped_by_redact"
1315
- }
1316
- }, gr = [
1317
- "metric.name",
1318
- "metric.unit",
1319
- "metric.type",
1320
- "metric.value",
1321
- ...Object.values(y),
1322
- ...Object.values(T)
1323
- ];
1324
- function _r(e) {
1325
- return Object.fromEntries(gr.filter((t) => t in e).map((t) => [t, e[t]]));
865
+ code: "record.dropped_by_redact",
866
+ refused: "redact is not a function. The library drops each record until redact is a function or null."
867
+ }
868
+ }, H = (e) => typeof e == "number" && Number.isFinite(e), rn = (e) => Array.isArray(e) && e.every(H), U = (e) => typeof e == "string" && /^\d{1,20}$/.test(e), an = (e) => typeof e == "string" && /^[0-9a-f]{32}$/.test(e), on = (e) => typeof e == "string" && /^[0-9a-f]{16}$/.test(e), sn = (e) => e === "" || on(e), cn = (e) => e === "counter", ln = (e) => e === "histogram", un = (e) => e === "client" || e === "internal", dn = (e) => e === "error" || e === "unset", fn = {
869
+ "metric.type": cn,
870
+ "metric.value": H,
871
+ [E.start]: U
872
+ }, pn = {
873
+ "metric.type": ln,
874
+ [E.start]: U,
875
+ [E.count]: H,
876
+ [E.sum]: H,
877
+ [E.min]: H,
878
+ [E.max]: H,
879
+ [E.bounds]: rn,
880
+ [E.buckets]: rn
881
+ }, mn = {
882
+ [s.kind]: un,
883
+ [s.parentId]: sn,
884
+ [s.start]: U,
885
+ [s.end]: U,
886
+ [s.status]: dn
887
+ }, hn = {
888
+ [s.linkTraceId]: an,
889
+ [s.linkSpanId]: on
890
+ };
891
+ function gn(e) {
892
+ let t = e[S], n = e[v];
893
+ return t === "span" && n === "uiobs.traces" ? [mn, hn] : t !== "metric" || n !== "uiobs.metrics" ? [] : e["metric.type"] === "histogram" ? [pn] : [fn];
1326
894
  }
1327
- function K(e) {
895
+ function _n(e) {
896
+ let t = {};
897
+ for (let n of gn(e)) {
898
+ let r = Object.keys(n);
899
+ if (r.every((t) => n[t](e[t]))) for (let n of r) t[n] = e[n];
900
+ }
901
+ return t;
902
+ }
903
+ function W(e) {
1328
904
  return e;
1329
905
  }
1330
- var vr = class {
1331
- deps;
1332
- resourceCache = null;
906
+ var vn = class {
1333
907
  constructor(e) {
1334
- this.deps = e;
908
+ k(this, "deps", void 0), k(this, "resourceCache", null), this.deps = e;
1335
909
  }
1336
910
  invalidateResource() {
1337
911
  this.resourceCache = null;
1338
912
  }
1339
- isEnabled(e, t, r) {
1340
- let { config: i } = this.deps;
1341
- if (!i.enabled) return !1;
1342
- if (r !== void 0 && n.includes(r)) return !0;
1343
- let a = this.deps.remote.sampling?.minLevelFor(t) ?? ut(t, i);
1344
- return w[e] >= w[a];
913
+ isEnabled(e, t, n) {
914
+ return this.deps.config.enabled && this.passesLevel(e, t, n);
915
+ }
916
+ passesLevel(e, t, n) {
917
+ let { config: r } = this.deps;
918
+ if (n !== void 0 && m.includes(n)) return !0;
919
+ let i = this.deps.remote.sampling?.minLevelFor(t) ?? ot(t, r);
920
+ return w[e] >= w[i];
1345
921
  }
1346
922
  keepForDebug(e) {
1347
923
  let { config: t, debug: n } = this.deps;
@@ -1355,7 +931,7 @@ var vr = class {
1355
931
  record: null,
1356
932
  dropped: "level"
1357
933
  };
1358
- let l = e.trace ?? e.snapshot?.trace ?? i.resolve(), u = e.snapshot ? e.snapshot.journey : a.current(), d = dt({
934
+ let l = e.trace ?? e.snapshot?.trace ?? i.resolve(), u = e.snapshot ? e.snapshot.journey : a.current(), d = st({
1359
935
  level: e.level,
1360
936
  type: e.type,
1361
937
  namespace: e.namespace,
@@ -1367,71 +943,96 @@ var vr = class {
1367
943
  record: null,
1368
944
  dropped: "sampling"
1369
945
  };
1370
- let f = o.next(), p = e.snapshot?.url ?? qe(r), m = n.metadata.pageUrl ? D(p, n.capture.fullUrls, n.capture.urlTransform, r) : "", h, g = 0;
946
+ let f = o.next(), p = e.snapshot?.url ?? He(r), m = n.metadata.pageUrl ? Be(p, n.capture.fullUrls, n.capture.urlTransform, r) : "", h, g = 0;
1371
947
  try {
1372
- let t = k(e.snapshot?.context ?? this.deps.context.getAll(), s, r), n = k(this.provided(), s, r), i = k(e.scoped ?? {}, s, r), a = k(e.payload ?? {}, s, r);
948
+ let t = N(e.snapshot?.context ?? this.deps.context.getAll(), s, r), n = N(this.provided(), s, r), i = N(e.scoped ?? {}, s, r), a = N(e.payload ?? {}, s, r);
1373
949
  g = t.bytes + n.bytes + i.bytes + a.bytes, h = {
1374
- ...K(t.value),
1375
- ...K(n.value),
1376
- ...K(i.value),
1377
- ...K(a.value)
950
+ ...W(t.value),
951
+ ...W(n.value),
952
+ ...W(i.value),
953
+ ...W(a.value)
1378
954
  };
1379
955
  } catch (e) {
1380
- r.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), h = { [Le]: !0 };
956
+ r.report("record.sanitize_failed", "The library could not sanitize the attributes.", void 0, e), h = { [je]: !0 };
1381
957
  }
1382
- Object.assign(h, e.fixed), h[ve] = e.type, h[ye] = f, h[ue] = e.namespace, h[C] = m, u && (h[x] = u.id, h[De] = u.name, u.parentId !== void 0 && (h[Ce] = u.parentId));
1383
- let _ = Ye(e.body, s.maxBodyChars);
1384
- _ !== e.body && r.count("record.truncated");
1385
- let v = {
1386
- timeUnixNano: e.snapshot?.timeUnixNano ?? Be(),
958
+ Object.assign(h, e.fixed), h[S] = e.type, h[C] = f, h[v] = e.namespace, h[T] = m, u && (h[x] = u.id, h[ve] = u.name, u.parentId !== void 0 && (h[fe] = u.parentId));
959
+ let ee = Xe(e.body, s.maxBodyChars);
960
+ ee !== e.body && r.count("record.truncated");
961
+ let _ = {
962
+ timeUnixNano: e.snapshot?.timeUnixNano ?? Pe(),
1387
963
  traceId: l.traceId,
1388
964
  spanId: l.spanId,
1389
965
  traceFlags: l.traceFlags,
1390
- severityNumber: fe[e.level],
966
+ severityNumber: te[e.level],
1391
967
  severityText: e.level,
1392
- body: _,
968
+ body: ee,
1393
969
  attributes: h,
1394
970
  resource: this.resource()
1395
- }, y = n.processors.map((e) => [e, "processor"]);
1396
- if (n.redact && y.push([n.redact, "redact"]), y.length > 0) {
1397
- let t = this.applyHooks(v, y, e.fixed);
971
+ }, ne = this.hookStages();
972
+ if (ne.length > 0) {
973
+ let t = this.applyHooks(_, ne, e.fixed);
1398
974
  if (typeof t == "string") return {
1399
975
  record: null,
1400
976
  dropped: t
1401
977
  };
1402
- ({record: v, bytes: g} = t);
1403
- }
1404
- if (g > s.maxRecordBytes) {
1405
- r.report("record.truncated", "The attributes are larger than the size limit. The library dropped the caller attributes.", {
1406
- bytes: g,
1407
- body: v.body
1408
- });
1409
- let t = {
1410
- [ve]: e.type,
1411
- [ye]: f,
1412
- [ue]: e.namespace,
1413
- [je]: !0,
1414
- [Te]: g
1415
- };
1416
- for (let e of mr) e in v.attributes && (t[e] = v.attributes[e]);
1417
- for (let [e, n] of Object.entries(v.attributes)) e.startsWith(pr) && (t[e] = n);
1418
- let n = k(t, s, r).bytes;
1419
- n > s.maxRecordBytes && "error.data" in t && (Reflect.deleteProperty(t, me), n = k(t, s, r).bytes);
1420
- let i = v.attributes[b];
1421
- if (i !== void 0) {
1422
- let e = k(i, s, r).bytes;
1423
- n + e <= s.maxRecordBytes && (t[b] = i);
1424
- }
1425
- Object.assign(t, e.fixed), v.attributes = t;
978
+ ({record: _, bytes: g} = t);
1426
979
  }
1427
- return { record: v };
980
+ let re = {
981
+ [S]: e.type,
982
+ [C]: f,
983
+ [v]: e.namespace
984
+ };
985
+ return { record: this.fit(_, g, re, e.fixed) };
1428
986
  }
1429
987
  redactForwarded(e) {
1430
988
  let { redact: t } = this.deps.config;
1431
989
  if (!t) return e;
1432
- let n = [[t, "redact"]], r = this.applyHooks(e, n, _r(e.attributes));
990
+ let n = [[t, "redact"]], r = this.applyHooks(e, n, _n(e.attributes));
1433
991
  return typeof r == "string" ? null : r.record;
1434
992
  }
993
+ rehook(e) {
994
+ let { config: t, diagnostics: n, limits: r, remote: i, debug: a } = this.deps, { attributes: o } = e, s = String(o[v]), c = this.passesLevel(e.severityText, s, o[S]), l = c && it(e, t, i.sampling?.current() ?? null), u = t.metadata.pageUrl ? Be(String(o[T]), t.capture.fullUrls, t.capture.urlTransform, n) : "", d = Xe(e.body, r.maxBodyChars);
995
+ d !== e.body && n.count("record.truncated");
996
+ let f = _n(o), p = {
997
+ ...e,
998
+ body: d,
999
+ attributes: {
1000
+ ...o,
1001
+ [T]: u
1002
+ },
1003
+ resource: this.resource()
1004
+ }, m = this.applyHooks(p, this.hookStages(), f), h = typeof m == "string" ? null : this.fit(m.record, m.bytes, o, f);
1005
+ return l ? h : (n.count(c ? "record.dropped_by_sampling" : "record.dropped_by_level"), h && a && t.enabled && t.debugBuffer.enabled && a.push(h), null);
1006
+ }
1007
+ fit(e, t, n, r) {
1008
+ let { diagnostics: i, limits: a } = this.deps;
1009
+ if (t <= a.maxRecordBytes) return e;
1010
+ i.report("record.truncated", "The attributes are larger than the size limit. The library dropped the caller attributes.", {
1011
+ bytes: t,
1012
+ body: e.body
1013
+ });
1014
+ let o = {
1015
+ [S]: n[S],
1016
+ [C]: n[C],
1017
+ [v]: n[v],
1018
+ [Se]: !0,
1019
+ [he]: t
1020
+ };
1021
+ for (let t of tn) t in e.attributes && (o[t] = e.attributes[t]);
1022
+ for (let [t, n] of Object.entries(e.attributes)) t.startsWith(en) && (o[t] = n);
1023
+ let s = N(o, a, i).bytes;
1024
+ s > a.maxRecordBytes && "error.data" in o && (Reflect.deleteProperty(o, se), s = N(o, a, i).bytes);
1025
+ let c = e.attributes[y];
1026
+ if (c !== void 0) {
1027
+ let e = N(c, a, i).bytes;
1028
+ s + e <= a.maxRecordBytes && (o[y] = c);
1029
+ }
1030
+ return Object.assign(o, r), e.attributes = o, e;
1031
+ }
1032
+ hookStages() {
1033
+ let { processors: e, redact: t } = this.deps.config, n = e.map((e) => [e, "processor"]);
1034
+ return t && n.push([t, "redact"]), n;
1035
+ }
1435
1036
  applyHooks(e, t, n) {
1436
1037
  let r = e;
1437
1038
  for (let [e, n] of t) {
@@ -1439,7 +1040,7 @@ var vr = class {
1439
1040
  if (typeof t == "string") return t;
1440
1041
  r = t;
1441
1042
  }
1442
- let { diagnostics: i, limits: a } = this.deps, o = k(r.attributes, a, i), s = K(o.value);
1043
+ let { diagnostics: i, limits: a } = this.deps, o = N(r.attributes, a, i), s = W(o.value);
1443
1044
  return Object.assign(s, n), {
1444
1045
  record: {
1445
1046
  ...r,
@@ -1449,60 +1050,60 @@ var vr = class {
1449
1050
  };
1450
1051
  }
1451
1052
  runHook(e, t, n) {
1452
- let { diagnostics: r } = this.deps, { label: i, code: a } = hr[t], o;
1053
+ let { diagnostics: r } = this.deps, { label: i, code: a, refused: o } = nn[t], s;
1453
1054
  try {
1454
- o = e(n);
1055
+ s = e(n);
1455
1056
  } catch (e) {
1456
1057
  return r.report(a, `${i} threw an error. The library dropped the record.`, void 0, e), t;
1457
1058
  }
1458
- if (o === null) return r.count(a), t;
1459
- let s = o ?? n;
1460
- return ze(s) ? Ve(s.severityText) ? {
1461
- ...s,
1462
- severityNumber: fe[s.severityText]
1463
- } : (r.report("record.dropped_malformed", `${i} set a severityText that is not a log level. The library dropped the record.`), "malformed") : s === n ? (r.report("record.dropped_malformed", `${i} changed the record to a shape that is not a record. The library dropped it.`), "malformed") : (r.report(a, `${i} returned a value that is not a record. The library dropped the record.`), t);
1059
+ if (s === null) return e === F ? r.report(a, o) : r.count(a), t;
1060
+ let c = s ?? n;
1061
+ return Ne(c) ? Fe(c.severityText) ? {
1062
+ ...c,
1063
+ severityNumber: te[c.severityText]
1064
+ } : (r.report("record.dropped_malformed", `${i} set a severityText that is not a log level. The library dropped the record.`), "malformed") : c === n ? (r.report("record.dropped_malformed", `${i} changed the record to a shape that is not a record. The library dropped it.`), "malformed") : (r.report(a, `${i} returned a value that is not a record. The library dropped the record.`), t);
1464
1065
  }
1465
1066
  provided() {
1466
1067
  let e = this.deps.config.contextProvider;
1467
1068
  if (!e) return {};
1468
1069
  let { diagnostics: t } = this.deps, n = t.guard("handler.threw", "The contextProvider threw an error. The record has no attributes from it.", () => {
1469
1070
  let t = e();
1470
- return t === void 0 ? {} : E(t) && typeof t.then != "function" ? t : null;
1071
+ return t === void 0 ? {} : D(t) && typeof t.then != "function" ? t : null;
1471
1072
  });
1472
1073
  return n === null && t.report("config.invalid", "contextProvider must return an object of attributes. The library ignores the value."), n ?? {};
1473
1074
  }
1474
1075
  resource() {
1475
1076
  if (this.resourceCache) return this.resourceCache;
1476
- let { config: t, identity: n, platform: r } = this.deps;
1077
+ let { config: t, identity: n, platform: a } = this.deps;
1477
1078
  return this.resourceCache = {
1478
- [Ae]: t.serviceName,
1479
- [be]: t.serviceVersion,
1480
- [e]: t.environment,
1481
- [Se]: h,
1482
- [Fe]: v,
1483
- [pe]: xe,
1484
- [ge]: r.platform,
1485
- [de]: n.sessionId,
1486
- [Me]: n.tabId,
1487
- [ne]: n.contextId,
1488
- ...t.metadata.userAgent ? { [ce]: r.userAgent } : {},
1489
- ...!t.metadata.openfin || r.openfinUuid === void 0 ? {} : { [we]: r.openfinUuid },
1490
- ...!t.metadata.openfin || r.openfinName === void 0 ? {} : { [Ne]: r.openfinName }
1079
+ [oe]: t.serviceName,
1080
+ [ke]: t.serviceVersion,
1081
+ [ce]: t.environment,
1082
+ [i]: e,
1083
+ [r]: b,
1084
+ [_]: g,
1085
+ [ie]: a.platform,
1086
+ [ee]: n.sessionId,
1087
+ [Oe]: n.tabId,
1088
+ [le]: n.contextId,
1089
+ ...t.metadata.userAgent ? { [pe]: a.userAgent } : {},
1090
+ ...!t.metadata.openfin || a.openfinUuid === void 0 ? {} : { [Me]: a.openfinUuid },
1091
+ ...!t.metadata.openfin || a.openfinName === void 0 ? {} : { [De]: a.openfinName }
1491
1092
  }, this.resourceCache;
1492
1093
  }
1493
- }, yr = 1e3, br = {
1094
+ }, yn = 1e3, bn = {
1494
1095
  start: "ui.start",
1495
1096
  interaction: "ui.interaction",
1496
1097
  navigation: "ui.navigation",
1497
1098
  explicit: "ui.trace",
1498
1099
  maxAge: "ui.trace"
1499
1100
  };
1500
- function xr(e) {
1501
- return `${String(Math.round(e * yr))}000`;
1101
+ function xn(e) {
1102
+ return `${String(Math.round(e * yn))}000`;
1502
1103
  }
1503
- function Sr(e) {
1104
+ function Sn(e) {
1504
1105
  return {
1505
- name: br[e.reason],
1106
+ name: bn[e.reason],
1506
1107
  kind: "internal",
1507
1108
  traceId: e.traceId,
1508
1109
  spanId: e.spanId,
@@ -1513,191 +1114,166 @@ function Sr(e) {
1513
1114
  attributes: {}
1514
1115
  };
1515
1116
  }
1516
- function Cr(e) {
1117
+ function Cn(e) {
1517
1118
  return {
1518
- [T.kind]: e.kind,
1519
- [T.parentId]: e.parentSpanId,
1520
- [T.start]: xr(e.startMs),
1521
- [T.end]: xr(e.endMs),
1522
- [T.status]: e.error ? "error" : "unset",
1119
+ [s.kind]: e.kind,
1120
+ [s.parentId]: e.parentSpanId,
1121
+ [s.start]: xn(e.startMs),
1122
+ [s.end]: xn(e.endMs),
1123
+ [s.status]: e.error ? "error" : "unset",
1523
1124
  ...e.link ? {
1524
- [T.linkTraceId]: e.link.traceId,
1525
- [T.linkSpanId]: e.link.spanId
1125
+ [s.linkTraceId]: e.link.traceId,
1126
+ [s.linkSpanId]: e.link.spanId
1526
1127
  } : {}
1527
1128
  };
1528
1129
  }
1529
1130
  // src/core/runtime.ts
1530
- var wr = {
1531
- errors: async () => (await import("./errors-Dh7kef0i.js")).ErrorCapture,
1532
- network: async () => (await import("./network-DBNwApoF.js")).NetworkCapture,
1533
- interactions: async () => (await import("./interactions-DTgKy_6K.js")).InteractionCapture,
1534
- webVitals: async () => (await import("./web-vitals-Bq4WFHQo.js")).WebVitalsCapture,
1535
- longFrames: async () => (await import("./long-frames-Czk7IupC.js")).LongFrameCapture,
1536
- console: async () => (await import("./console-BeCF7n59.js")).ConsoleCapture,
1537
- uncleanExit: async () => (await import("./unclean-exit-CwcUhFOn.js")).UncleanExitCapture,
1538
- userTiming: async () => (await import("./user-timing-_jZIhDKI.js")).UserTimingCapture,
1539
- reports: async () => (await import("./reports-TA-zInnq.js")).ReportCapture,
1540
- resourceTiming: async () => (await import("./resource-timing-BLv3EA2A.js")).ResourceTimingCapture,
1541
- lifecycle: async () => (await import("./lifecycle-BaKx_-32.js")).LifecycleCapture
1542
- }, Tr = /* @__PURE__ */ new WeakMap(), Er = 0;
1543
- function Dr(e) {
1544
- let t = Tr.get(e);
1545
- return t === void 0 && (t = ++Er, Tr.set(e, t)), t;
1546
- }
1547
- var Or = Symbol.for(he), kr = Symbol.for(_e), Ar = ["batching", "retention"], jr = {
1548
- endpoint: null,
1549
- metricsEndpoint: "",
1550
- tracesEndpoint: "",
1551
- headers: void 0,
1552
- credentials: "omit",
1553
- transport: void 0,
1554
- transportOnExit: void 0,
1555
- transportWorker: void 0
1556
- }, Mr = Object.keys(jr), Nr = /* @__PURE__ */ new Set([
1131
+ var wn = {
1132
+ errors: async () => (await import("./errors-BE_EZV7Q.js")).ErrorCapture,
1133
+ network: async () => (await import("./network-on2zZT6H.js")).NetworkCapture,
1134
+ interactions: async () => (await import("./interactions-DiFvCosX.js")).InteractionCapture,
1135
+ webVitals: async () => (await import("./web-vitals-4pWACwaR.js")).WebVitalsCapture,
1136
+ longFrames: async () => (await import("./long-frames-DNFaRnC3.js")).LongFrameCapture,
1137
+ console: async () => (await import("./console-BGgGnjSi.js")).ConsoleCapture,
1138
+ uncleanExit: async () => (await import("./unclean-exit-DQD1cT7c.js")).UncleanExitCapture,
1139
+ userTiming: async () => (await import("./user-timing-BePqb1uN.js")).UserTimingCapture,
1140
+ reports: async () => (await import("./reports-C-thq-bk.js")).ReportCapture,
1141
+ resourceTiming: async () => (await import("./resource-timing-eUl2dNgC.js")).ResourceTimingCapture,
1142
+ lifecycle: async () => (await import("./lifecycle-22CUCrc9.js")).LifecycleCapture,
1143
+ framePhases: async () => (await import("./profiler-frames-cJMx9wNM.js")).FramePhasesCapture,
1144
+ framePacing: async () => (await import("./profiler-frames-cJMx9wNM.js")).FramePacingCapture,
1145
+ replay: async () => (await import("./replay-Ds-ANH34.js")).ReplayCapture
1146
+ }, Tn = /* @__PURE__ */ new WeakMap(), En = 0;
1147
+ function G(e) {
1148
+ let t = Tn.get(e);
1149
+ return t === void 0 && (t = ++En, Tn.set(e, t)), t;
1150
+ }
1151
+ var Dn = Symbol.for(f), On = Symbol.for(p), kn = ["batching", "retention"], An = [
1152
+ "log",
1153
+ "event",
1154
+ "action"
1155
+ ], jn = "configure() could not read its options. The library drops each record and installs no capture until a configure() call sets redact to a function or null.", Mn = "shutdown() got invalid options. The library discards the records in memory. An invalid clearStorage removes the \"context\" scope.", Nn = "flush() got invalid options. The library waits the default 5000 ms.", Pn = /* @__PURE__ */ new Set([
1557
1156
  "bus.role_resolved",
1558
1157
  "config.reconfigured",
1559
1158
  "security.rotated",
1560
1159
  "journey.adopted",
1561
1160
  "journey.expired"
1562
1161
  ]);
1563
- function Pr(e) {
1162
+ function Fn(e) {
1564
1163
  return JSON.stringify({
1565
1164
  ...e,
1566
- urlTransform: e.urlTransform ? Dr(e.urlTransform) : void 0,
1567
- webVitalsLoader: e.webVitalsLoader !== void 0,
1165
+ urlTransform: e.urlTransform ? G(e.urlTransform) : void 0,
1166
+ webVitals: typeof e.webVitals == "object" ? { loader: e.webVitals.loader !== void 0 } : e.webVitals,
1568
1167
  ignoreUrls: e.ignoreUrls.map(String),
1569
1168
  propagateTraceHeaderTo: e.propagateTraceHeaderTo.map(String),
1570
- userTimingInclude: e.userTimingInclude.map(String),
1571
- plugins: e.plugins.map(Dr)
1169
+ userTiming: typeof e.userTiming == "object" ? { include: e.userTiming.include?.map(String) } : e.userTiming,
1170
+ plugins: e.plugins.map(G)
1572
1171
  });
1573
1172
  }
1574
- function Fr(e) {
1575
- if (!E(e)) return e;
1173
+ function In(e) {
1174
+ if (!D(e)) return e;
1576
1175
  let t = { ...e };
1577
1176
  for (let e of ["url", "endpoint"]) {
1578
1177
  let n = t[e];
1579
- typeof n == "string" && (t[e] = D(n, !1));
1178
+ typeof n == "string" && (t[e] = Be(n, !1));
1580
1179
  }
1581
1180
  return t;
1582
1181
  }
1583
- function Ir(e) {
1182
+ function Ln(e) {
1584
1183
  return {
1585
1184
  ...e,
1586
1185
  endpoint: null,
1587
- metricsEndpoint: "",
1588
- tracesEndpoint: "",
1589
- transport: void 0,
1590
- transportOnExit: void 0,
1591
- transportWorker: void 0,
1186
+ metricsEndpoint: null,
1187
+ tracesEndpoint: null,
1188
+ transport: null,
1189
+ transportOnExit: null,
1190
+ transportWorker: null,
1592
1191
  bus: {
1593
1192
  ...e.bus,
1594
1193
  mode: "off"
1595
1194
  }
1596
1195
  };
1597
1196
  }
1598
- function Lr(e) {
1599
- return !!e.endpoint || !!e.metricsEndpoint || !!e.tracesEndpoint || e.transport !== void 0 || e.transportWorker !== void 0;
1197
+ function Rn(e) {
1198
+ return !!e.endpoint || !!e.metricsEndpoint || !!e.tracesEndpoint || !!e.transport || !!e.transportWorker;
1199
+ }
1200
+ function zn(e, t) {
1201
+ return {
1202
+ status: e,
1203
+ accepted: 0,
1204
+ stored: 0,
1205
+ dropped: 0,
1206
+ forwarded: 0,
1207
+ pending: 0,
1208
+ ...t
1209
+ };
1210
+ }
1211
+ function K(e) {
1212
+ return zn(e.pending > 0 ? "timeout" : "complete", e);
1600
1213
  }
1601
- function Rr(e) {
1602
- return e.sdkVersion === v;
1214
+ function Bn(e) {
1215
+ return e.sdkVersion === b;
1603
1216
  }
1604
1217
  var q = class e {
1605
- rotating = !1;
1606
- closingContext = !1;
1607
- mismatchVersion = null;
1608
- contextMismatch = !1;
1609
- rotation;
1610
- memoryStorage;
1611
- storagePersistence = "off";
1612
- recordingDiagnostic = !1;
1613
- diagnosticLogger = new F(() => this, Oe);
1614
- debugBuffer = new ar(() => this.config.debugBuffer);
1615
- explicitSecurityContext;
1616
- ownerAdopted = !1;
1617
1218
  isRotating() {
1618
1219
  return this.rotating;
1619
1220
  }
1620
1221
  setConfigurationLocked(e) {
1621
1222
  typeof e == "boolean" && (this.config.lockConfiguration = e);
1622
1223
  }
1623
- static local = null;
1624
- sdkVersion = v;
1625
- diagnostics;
1626
- config;
1627
- platform;
1628
- identity;
1629
- stores;
1630
- identityBuiltAs;
1631
- sessionTouch;
1632
- context = new ir();
1633
- breadcrumbs;
1634
- tracing;
1635
- sequence = new Rt();
1636
- journey;
1637
- builder;
1638
- remote = {
1639
- sampling: null,
1640
- changed: () => {
1641
- this.refreshCaptures();
1642
- }
1643
- };
1644
- identityEpoch = 0;
1645
- remoteCaptureTimer;
1646
- installedCaptureKey = "";
1647
- console;
1648
- drops;
1649
- meter;
1650
- bus = null;
1651
- busBuilt;
1652
- busLoad;
1653
- storageBuiltAs;
1654
- sender;
1655
- senderLoad;
1656
- pendingRecords = new lr((e) => {
1657
- this.dropHeld(e);
1658
- });
1659
- captures = [];
1660
- captureGeneration = 0;
1661
- captureOnce = {
1662
- webVitals: !1,
1663
- navigationTiming: !1,
1664
- longFrames: !1,
1665
- uncleanExit: !1,
1666
- userTiming: !1
1667
- };
1668
- bootBuffer = new lr((e) => {
1669
- this.dropHeld(e);
1670
- });
1671
- forwardBuffer = [];
1672
- forwardScheduled = !1;
1673
- roleResolved = !1;
1674
- started = Promise.resolve();
1675
- ready = !1;
1676
- destroyed = !1;
1677
- lastGapAt = 0;
1678
- limits;
1679
- journeyOptions;
1680
- tunablesLocked = !0;
1681
- degraded;
1682
- serverReported = !1;
1683
- onPageHide = () => {
1684
- N(this), this.role() === "forwarder" && (this.tracing.end(), this.sendForwarded());
1685
- };
1686
- constructor(e, t = !1) {
1687
- this.diagnostics = new or(e.onDiagnostic), this.platform = Ke(this.diagnostics), this.degraded = t || this.onServer(), this.config = G(this.allowed(e), this.diagnostics), this.explicitSecurityContext = !!e.securityContext?.id, this.config.securityContext.id ||= A(this.diagnostics), this.diagnostics.setPolicy(this.config.diagnostics.throttleMs, this.config.diagnostics.consoleFallback), this.identityBuiltAs = this.config.identity, this.stores = this.identityBuiltAs === "memory" || this.onServer() ? et() : nt, this.identity = tt(this.diagnostics, this.stores, this.config.correlation.sessionIdleMs), this.sessionTouch = new Qe(this.diagnostics, this.stores, this.config.correlation.sessionTouchMs, this.config.correlation.sessionIdleMs), this.breadcrumbs = new Yt(this.config.capturePolicy.breadcrumbs);
1688
- let n = (e) => lt(e, this.config.sampling.defaultRate);
1689
- this.tracing = new Jt(this.diagnostics, this.config.correlation.traceMaxAgeMs || Infinity, this.config.otelLoader, {
1690
- enabled: () => this.config.tracesEndpoint !== "",
1224
+ constructor(e, t) {
1225
+ k(this, "rotating", !1), k(this, "rotationSeq", 0), k(this, "profilerOn", !1), k(this, "closingContext", !1), k(this, "mismatchVersion", null), k(this, "contextMismatch", !1), k(this, "rotation", void 0), k(this, "memoryStorage", void 0), k(this, "storagePersistence", "off"), k(this, "recordingDiagnostic", !1), k(this, "diagnosticLogger", new B(() => this, c)), k(this, "debugBuffer", new Xt(() => this.config.debugBuffer)), k(this, "explicitSecurityContext", void 0), k(this, "ownerAdopted", !1), k(this, "sdkVersion", b), k(this, "protocol", d), k(this, "diagnostics", void 0), k(this, "config", void 0), k(this, "platform", void 0), k(this, "identity", void 0), k(this, "backing", Ke()), k(this, "stores", {
1226
+ local: () => this.backing.local(),
1227
+ session: () => this.backing.session()
1228
+ }), k(this, "identityBuiltAs", void 0), k(this, "sessionTouch", void 0), k(this, "context", new Yt()), k(this, "breadcrumbs", void 0), k(this, "tracing", void 0), k(this, "sequence", new qt()), k(this, "journey", void 0), k(this, "builder", void 0), k(this, "remote", {
1229
+ sampling: null,
1230
+ changed: () => {
1231
+ this.refreshCaptures();
1232
+ }
1233
+ }), k(this, "identityEpoch", 0), k(this, "errorHook", void 0), k(this, "replayConsent", void 0), k(this, "replay", void 0), k(this, "remoteCaptureTimer", void 0), k(this, "installedCaptureKey", ""), k(this, "replayBuiltKey", ""), k(this, "console", void 0), k(this, "drops", void 0), k(this, "meter", void 0), k(this, "bus", null), k(this, "busBuilt", void 0), k(this, "busLoad", void 0), k(this, "sender", void 0), k(this, "senderLoad", void 0), k(this, "pendingRecords", new $t((e) => {
1234
+ this.dropHeld(e);
1235
+ })), k(this, "pausedLoss", /* @__PURE__ */ new WeakSet()), k(this, "carried", []), k(this, "sessionPicked", !1), k(this, "deliveryClosed", !1), k(this, "parkedSender", void 0), k(this, "retiring", void 0), k(this, "startFailed", !1), k(this, "running", !1), k(this, "openGate", void 0), k(this, "startGate", new Promise((e) => {
1236
+ this.openGate = e;
1237
+ })), k(this, "captures", []), k(this, "captureGeneration", 0), k(this, "captureOnce", {
1238
+ webVitals: !1,
1239
+ navigationTiming: !1,
1240
+ longFrames: !1,
1241
+ uncleanExit: !1,
1242
+ userTiming: !1
1243
+ }), k(this, "bootBuffer", new $t((e) => {
1244
+ this.dropHeld(e);
1245
+ })), k(this, "forwardBuffer", []), k(this, "forwardScheduled", !1), k(this, "roleResolved", !1), k(this, "started", Promise.resolve()), k(this, "ready", !1), k(this, "destroyed", !1), k(this, "stopping", void 0), k(this, "lastSendAt", null), k(this, "lastGapAt", 0), k(this, "limits", void 0), k(this, "journeyOptions", void 0), k(this, "tunablesLocked", !1), k(this, "degraded", void 0), k(this, "serverReported", !1), k(this, "onPageHide", () => {
1246
+ R(this), this.dropPaused(), this.role() === "forwarder" && (this.tracing.end(), this.sendForwarded());
1247
+ }), k(this, "busCanAccept", (e, t) => this.bus?.isRegistered(e, t) ?? !1), k(this, "busAccept", (e, t, n) => {
1248
+ this.destroyed || this.ensureBus().then((r) => {
1249
+ r && !this.destroyed && this.diagnostics.guard("bus.send_failed", "The bus could not accept a direct message from a child frame.", () => {
1250
+ r.acceptDirect(e, t, n);
1251
+ });
1252
+ });
1253
+ }), k(this, "reportLoss", (e, t, n, r) => {
1254
+ this.drops.add(e, t, n, r);
1255
+ }), k(this, "reportGap", (e, t) => {
1256
+ this.drops.add(e.reason, t.flatMap((e) => e.records), t.map((e) => e.id));
1257
+ let n = Date.now();
1258
+ n - this.lastGapAt < 6e4 || (this.lastGapAt = n, new B(() => this, o).warn("stored records were dropped before delivery", {
1259
+ "gap.batches": e.batches,
1260
+ "gap.records": e.records,
1261
+ "gap.reason": e.reason
1262
+ }));
1263
+ }), this.diagnostics = new V(typeof e.onDiagnostic == "function" ? e.onDiagnostic : void 0), this.platform = Ve(this.diagnostics), this.degraded = t || this.onServer(), this.config = P(this.allowed(e), this.diagnostics), this.explicitSecurityContext = !!e.securityContext?.id, this.config.securityContext.id ||= A(this.diagnostics), this.diagnostics.setPolicy(this.config.diagnostics.throttleMs, this.config.diagnostics.consoleFallback), this.identityBuiltAs = this.config.identity, this.identity = qe(this.diagnostics, this.stores, this.config.correlation.sessionIdleMs), this.sessionTouch = new We(this.diagnostics, this.stores, this.config.correlation.sessionIdleMs), this.breadcrumbs = new Jt(this.config.captureLimits.breadcrumbs);
1264
+ let n = (e) => at(e, this.config.sampling.defaultRate);
1265
+ this.tracing = new Ot(this.diagnostics, this.config.correlation.traceMaxAgeMs ?? Infinity, this.config.otelLoader, {
1266
+ enabled: () => this.config.tracesEndpoint !== null,
1691
1267
  keeps: n,
1692
1268
  onEnd: (e) => {
1693
- n(e.traceId) && this.recordSpan(Sr(e));
1269
+ n(e.traceId) && this.recordSpan(Sn(e));
1694
1270
  }
1695
- }), this.tracing.loadOtel(), this.limits = { ...this.config.limits }, this.console = new Lt(this.config.console, this.diagnostics, this.limits), this.drops = new cr(this.config, this.diagnostics), this.journeyOptions = {
1696
- ...st,
1271
+ }), this.limits = { ...this.config.limits }, this.console = new Kt(this.config.consoleOutput, this.diagnostics, this.limits), this.drops = new Qt(this.config, this.diagnostics), this.journeyOptions = {
1272
+ ...rt,
1697
1273
  maxAgeMs: this.config.journey.maxAgeMs
1698
- }, this.journey = new ot(this.journeyOptions, this.diagnostics, this.identity.contextId, (e) => {
1274
+ }, this.journey = new nt(this.journeyOptions, this.diagnostics, this.identity.contextId, (e) => {
1699
1275
  this.bus?.broadcastJourney(e);
1700
- }, this.stores), this.builder = new vr({
1276
+ }, this.stores), this.builder = new vn({
1701
1277
  remote: this.remote,
1702
1278
  config: this.config,
1703
1279
  limits: this.limits,
@@ -1709,9 +1285,9 @@ var q = class e {
1709
1285
  identity: this.identity,
1710
1286
  platform: this.platform,
1711
1287
  debug: this.debugBuffer
1712
- }), this.meter = new Ft(() => this.config.batching.metricFlushIntervalMs, (e, t, n) => {
1288
+ }), this.meter = new Wt(() => this.config.metrics.intervalMs, (e, t, n) => {
1713
1289
  this.emitPoint(e, t, n);
1714
- }, this.diagnostics, this.config.metrics), this.diagnostics.setHandler(this.diagnosticHandler());
1290
+ }, this.diagnostics, this.config.metrics), this.diagnostics.setHandler(this.diagnosticHandler()), this.syncProfiler();
1715
1291
  }
1716
1292
  diagnosticHandler() {
1717
1293
  return this.config.diagnostics.records === !1 ? this.config.onDiagnostic : (e) => {
@@ -1723,10 +1299,10 @@ var q = class e {
1723
1299
  if ((t === !0 || t !== !1 && t.includes(e.code)) && !this.recordingDiagnostic) {
1724
1300
  this.recordingDiagnostic = !0;
1725
1301
  try {
1726
- (Nr.has(e.code) ? this.diagnosticLogger.info : this.diagnosticLogger.warn)(e.message, {
1302
+ (Pn.has(e.code) ? this.diagnosticLogger.info : this.diagnosticLogger.warn)(e.message, {
1727
1303
  "diagnostic.code": e.code,
1728
1304
  "diagnostic.count": e.count,
1729
- "diagnostic.detail": Fr(e.detail)
1305
+ "diagnostic.detail": In(e.detail)
1730
1306
  });
1731
1307
  } finally {
1732
1308
  this.recordingDiagnostic = !1;
@@ -1738,21 +1314,21 @@ var q = class e {
1738
1314
  let n = {
1739
1315
  t: Date.now(),
1740
1316
  category: "custom",
1741
- message: Ye(String(e), this.limits.maxBodyChars)
1317
+ message: Xe(String(e), this.limits.maxBodyChars)
1742
1318
  };
1743
1319
  if (t !== void 0) {
1744
- let e = Xe(t, this.limits, this.diagnostics);
1745
- n.data = E(e) ? e : { value: e };
1320
+ let e = Ze(t, this.limits, this.diagnostics);
1321
+ n.data = D(e) ? e : { value: e };
1746
1322
  }
1747
1323
  this.breadcrumbs.push(n);
1748
1324
  });
1749
1325
  }
1750
1326
  recordMetric(e, t, n) {
1751
- !this.destroyed && !this.rotating && this.meter.record(e, t, n);
1327
+ !this.destroyed && !this.rotating && this.config.enabled && this.meter.record(e, t, n);
1752
1328
  }
1753
1329
  startMeasure(e, t) {
1754
- let n = this.identityEpoch, r = () => !this.destroyed && !this.rotating && (!this.config.securityContext.isolation || this.identityEpoch === n);
1755
- return fr(e, this.diagnostics.guard("record.sanitize_failed", "The library could not read the attributes of the measure.", () => ({ ...t })) ?? {}, this.tracing.request().span, {
1330
+ let n = this.identityEpoch, r = () => !this.destroyed && !this.rotating && (!this.config.securityContext.isolation || this.identityEpoch === n), i = this.diagnostics.guard("record.sanitize_failed", "The library could not read the attributes of the measure.", () => ({ ...t }));
1331
+ return jt(this.diagnostics.guard("record.sanitize_failed", "The library could not read the name of the measure.", () => `${e}`) ?? "", i ?? {}, this.tracing.request().span, {
1756
1332
  metric: (e, t, n) => {
1757
1333
  r() && this.recordMetric(e, t, n);
1758
1334
  },
@@ -1762,14 +1338,14 @@ var q = class e {
1762
1338
  });
1763
1339
  }
1764
1340
  recordSpan(e) {
1765
- if (this.config.tracesEndpoint === "") return;
1341
+ if (this.config.tracesEndpoint === null) return;
1766
1342
  let { record: t } = this.builder.build({
1767
1343
  level: "INFO",
1768
1344
  type: "span",
1769
1345
  body: e.name,
1770
- namespace: u,
1346
+ namespace: be,
1771
1347
  payload: e.attributes,
1772
- fixed: Cr(e),
1348
+ fixed: Cn(e),
1773
1349
  trace: {
1774
1350
  traceId: e.traceId,
1775
1351
  spanId: e.spanId,
@@ -1778,64 +1354,110 @@ var q = class e {
1778
1354
  });
1779
1355
  this.emit(t);
1780
1356
  }
1781
- emitPoint(e, t, n) {
1782
- let { record: r } = this.builder.build({
1357
+ emitPoint(e, t, r) {
1358
+ if (this.destroyed) return;
1359
+ let { record: i } = this.builder.build({
1783
1360
  level: "INFO",
1784
1361
  type: "metric",
1785
1362
  body: e,
1786
- namespace: te,
1363
+ namespace: n,
1787
1364
  payload: t,
1788
- fixed: n,
1365
+ fixed: r,
1789
1366
  aggregated: !0
1790
1367
  });
1791
- this.emit(r);
1368
+ this.emit(i);
1369
+ }
1370
+ syncProfiler() {
1371
+ let e = this.config.profiler.enabled && this.config.enabled;
1372
+ if (e === this.profilerOn) return;
1373
+ this.profilerOn = e;
1374
+ let t = j();
1375
+ if (!e) {
1376
+ t.collect(!1), t.detach();
1377
+ return;
1378
+ }
1379
+ let n = {
1380
+ capacity: this.config.profiler.maxProbes,
1381
+ intervalMs: () => this.config.metrics.intervalMs,
1382
+ emit: (e, t, n) => {
1383
+ this.emitPoint(e, t, n);
1384
+ },
1385
+ diagnostics: this.diagnostics,
1386
+ ready: () => !this.rotating || this.closingContext,
1387
+ outlier: (e, t) => {
1388
+ this.breadcrumbs.push({
1389
+ t: Date.now(),
1390
+ category: "profile",
1391
+ message: `${e} ${String(Math.round(t))} ms`
1392
+ });
1393
+ }
1394
+ };
1395
+ t.attach(n);
1396
+ }
1397
+ setReplay(e) {
1398
+ this.replayConsent = e, e ? this.replay?.start() : this.replay?.stop();
1399
+ }
1400
+ collectPoints() {
1401
+ this.meter.collect(), this.profilerOn && j().collect(!1);
1402
+ }
1403
+ advanceIdentity() {
1404
+ this.identityEpoch++, this.profilerOn && this.config.securityContext.isolation && j().reset(), this.remote.sampling = null, this.refreshCaptures();
1792
1405
  }
1793
- busCanAccept = (e, t) => this.bus?.isRegistered(e, t) ?? !1;
1794
- busAccept = (e, t, n) => {
1795
- this.destroyed || this.ensureBus().then((r) => {
1796
- r && !this.destroyed && this.diagnostics.guard("bus.send_failed", "The bus could not accept a direct message from a child frame.", () => {
1797
- r.acceptDirect(e, t, n);
1798
- });
1799
- });
1800
- };
1801
1406
  static pinned() {
1802
- return globalThis[Or] ?? null;
1407
+ return globalThis[Dn] ?? null;
1803
1408
  }
1804
1409
  static current() {
1805
1410
  let t = e.local;
1806
1411
  if (t) return t.destroyed ? null : t;
1807
1412
  let n = e.pinned();
1808
- return n && Rr(n) ? n : null;
1413
+ return n && Bn(n) ? n : null;
1809
1414
  }
1810
1415
  static stopped() {
1811
1416
  let t = e.local;
1812
1417
  if (t?.destroyed) return t;
1813
- let n = globalThis[kr];
1814
- return n && Rr(n) ? n : null;
1418
+ let n = globalThis[On];
1419
+ return n && Bn(n) ? n : null;
1815
1420
  }
1816
1421
  isDestroyed() {
1817
1422
  return this.destroyed;
1818
1423
  }
1819
1424
  static configure(t, n = !1) {
1425
+ try {
1426
+ return e.startOrUpdate(t, n);
1427
+ } catch (t) {
1428
+ let n = e.current();
1429
+ if (n?.tunablesLocked) return n.diagnostics.report("config.invalid", "configure() could not read its options. The library keeps the current settings.", void 0, t), n;
1430
+ let r = n ?? e.startOrUpdate({}, !0);
1431
+ return r.refuse(t), r;
1432
+ }
1433
+ }
1434
+ refuse(e) {
1435
+ this.startFailed = !0;
1436
+ let t = P({ redact: F }, new V(), this.config);
1437
+ $e(this.config, t), M(() => {
1438
+ console.warn(`${de} ${jn}`);
1439
+ }), this.diagnostics.report("config.invalid", jn, void 0, e), this.rehookHeld();
1440
+ }
1441
+ static startOrUpdate(t, n) {
1820
1442
  let r = e.local;
1821
1443
  if (r && !r.destroyed) return r.reconfigure(t), r;
1822
1444
  e.local = null;
1823
1445
  let i = e.pinned();
1824
1446
  if (i) {
1825
- if (!Rr(i)) return e.startDegraded(t, i.sdkVersion);
1447
+ if (!Bn(i)) return e.startDegraded(t, i.sdkVersion, n);
1826
1448
  if (!i.destroyed) return i.reconfigure(t), i;
1827
1449
  }
1828
- let a = new e(t);
1829
- return a.tunablesLocked = !n, globalThis[Or] = a, Reflect.deleteProperty(globalThis, kr), a.init(), a;
1830
- }
1831
- static startDegraded(t, n) {
1832
- let r = new e(t, !0);
1833
- e.local = r;
1834
- let i = typeof n == "string" ? n : "before 0.9.0";
1835
- return r.mismatchVersion = i, r.diagnostics.report("runtime.version_mismatch", `Another copy of the library, version ${i}, owns the page runtime. This copy, version ${v}, runs in console-only mode and installs no capture. Load one version of the library on the page.`, {
1836
- found: i,
1837
- own: v
1838
- }), r.init(), r;
1450
+ let a = new e(t, !1);
1451
+ return globalThis[Dn] = a, Reflect.deleteProperty(globalThis, On), n || a.launch(), a;
1452
+ }
1453
+ static startDegraded(t, n, r) {
1454
+ let i = new e(t, !0);
1455
+ e.local = i;
1456
+ let a = typeof n == "string" ? n : "before 0.9.0";
1457
+ return i.mismatchVersion = a, i.diagnostics.report("runtime.version_mismatch", `Another copy of the library, version ${a}, owns the page runtime. This copy, version ${b}, runs in console-only mode and installs no capture. Load one version of the library on the page.`, {
1458
+ found: a,
1459
+ own: b
1460
+ }), r || i.launch(), i;
1839
1461
  }
1840
1462
  reconfigure(e) {
1841
1463
  if (this.rotating) {
@@ -1843,69 +1465,85 @@ var q = class e {
1843
1465
  return;
1844
1466
  }
1845
1467
  if (this.config.lockConfiguration) {
1846
- let t = G(e, this.diagnostics, this.config);
1468
+ let t = P(e, this.diagnostics, this.config);
1847
1469
  J(this.config, t) || this.diagnostics.report("config.locked", "Runtime configuration is locked. Use setConfigurationLocked(false) to unlock it explicitly.");
1848
1470
  return;
1849
1471
  }
1850
- N(this);
1472
+ R(this);
1851
1473
  let t = this.keepDestination(this.keepRouting(this.allowed(e)));
1852
1474
  !this.tunablesLocked && t.securityContext?.id && (this.explicitSecurityContext = !0);
1853
- for (let e of ["correlation", "persistence"]) (e !== "persistence" || this.tunablesLocked || this.senderLoad !== void 0) && t[e] && !J({
1854
- ...this.config[e],
1855
- ...t[e]
1856
- }, this.config[e]) && (this.diagnostics.report("config.invalid", `${e} cannot change after startup.`), Object.assign(t, { [e]: this.config[e] }));
1857
- let n = G(t, this.diagnostics, this.config);
1475
+ let n = P(t, this.diagnostics, this.config), r = this.tunablesLocked ? ["correlation", "storage"] : [];
1476
+ for (let e of r) J(n[e], this.config[e]) || (this.diagnostics.report("config.invalid", `${e} cannot change after startup. The library keeps the current settings.`), Object.assign(n, { [e]: this.config[e] }));
1858
1477
  this.keepStartupTunables(n);
1859
- let { redact: r, processors: i } = this.config;
1860
- rr(this.config, n), (this.config.redact !== r || this.config.processors !== i) && this.debugBuffer.clear(), this.breadcrumbs.resize(this.config.capturePolicy.breadcrumbs), this.diagnostics.setHandler(this.diagnosticHandler()), this.diagnostics.setPolicy(this.config.diagnostics.throttleMs, this.config.diagnostics.consoleFallback), this.builder.invalidateResource(), this.console.update(this.config.console), this.keepBuiltStorage(), this.keepBuiltIdentity(), this.refreshCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1478
+ let { redact: i, processors: a, enabled: o } = this.config;
1479
+ o && !n.enabled && this.collectPoints(), $e(this.config, n), this.config.redact !== F && (this.startFailed = !1), (this.config.redact !== i || this.config.processors !== a) && this.debugBuffer.clear(), this.breadcrumbs.resize(this.config.captureLimits.breadcrumbs), this.diagnostics.setHandler(this.diagnosticHandler()), this.diagnostics.setPolicy(this.config.diagnostics.throttleMs, this.config.diagnostics.consoleFallback), this.builder.invalidateResource(), this.console.update(this.config.consoleOutput), this.keepBuiltIdentity(), this.syncProfiler(), this.launch(), this.running && o !== this.config.enabled && this.sender?.hold(!this.config.enabled), this.refreshCaptures(), this.roleResolved && this.syncSender(), this.diagnostics.report("config.reconfigured", "A later configure() call updated the runtime.");
1861
1480
  }
1862
1481
  onServer() {
1863
1482
  return this.platform.platform === "node";
1864
1483
  }
1865
1484
  allowed(e) {
1866
- return this.degraded ? (this.onServer() && !this.serverReported && Lr(e) && (this.serverReported = !0, this.diagnostics.report("config.invalid", "The library runs console-only on Node. It sends no record and installs no capture. It ignores endpoint, metricsEndpoint, tracesEndpoint, transport and transportWorker.")), Ir(e)) : e;
1485
+ return this.degraded ? (this.onServer() && !this.serverReported && Rn(e) && (this.serverReported = !0, this.diagnostics.report("config.invalid", "The library runs console-only on Node. It sends no record and installs no capture. It ignores endpoint, metricsEndpoint, tracesEndpoint, transport and transportWorker.")), Ln(e)) : e;
1867
1486
  }
1868
1487
  keepRouting(e) {
1869
1488
  if (!this.tunablesLocked || this.degraded || !this.config.securityContext.isolation) return e;
1870
- let t = G(e, new or(), this.config), n = Mr.filter((e) => !J(t[e], this.config[e]));
1871
- if (t.securityContext.id !== this.config.securityContext.id && n.push("securityContext.id"), n.length === 0) return e;
1872
- let r = { ...e };
1873
- for (let e of Mr) n.includes(e) && Reflect.deleteProperty(r, e);
1874
- if (n.includes("securityContext.id")) {
1489
+ let n = P(e, new V(), this.config), r = t.filter((e) => !J(n[e], this.config[e]));
1490
+ if (n.securityContext.id !== this.config.securityContext.id && r.push("securityContext.id"), r.length === 0) return e;
1491
+ let i = { ...e };
1492
+ for (let e of t) r.includes(e) && Reflect.deleteProperty(i, e);
1493
+ if (r.includes("securityContext.id")) {
1875
1494
  let t = { ...e.securityContext };
1876
- Reflect.deleteProperty(t, "id"), r.securityContext = t;
1495
+ Reflect.deleteProperty(t, "id"), i.securityContext = t;
1877
1496
  }
1878
- return this.diagnostics.report("config.invalid", `Isolation refuses changes to ${n.join(", ")}. Use rotateSecurityContext() for these changes. To permit them, set securityContext.isolation: false in a separate configure() call. The other settings apply.`), r;
1497
+ return this.diagnostics.report("config.invalid", `Isolation refuses changes to ${r.join(", ")}. Use rotateSecurityContext() for these changes. To permit them, set securityContext.isolation: false in a separate configure() call. The other settings apply.`), i;
1879
1498
  }
1880
1499
  keepStartupTunables(e) {
1881
- if (this.senderLoad !== void 0 && this.keepSections(e, Ar), !this.tunablesLocked) {
1882
- this.tunablesLocked = !0, Object.assign(this.limits, e.limits), this.journeyOptions.maxAgeMs = e.journey.maxAgeMs;
1500
+ if (this.senderLoad !== void 0 && this.keepSections(e, kn), !this.tunablesLocked) {
1501
+ Object.assign(this.limits, e.limits), this.journeyOptions.maxAgeMs = e.journey.maxAgeMs;
1883
1502
  return;
1884
1503
  }
1885
1504
  this.keepSections(e, ["limits"]);
1505
+ for (let t of ["mode", "openFinRole"]) e.bus[t] !== this.config.bus[t] && (this.diagnostics.report("config.invalid", `bus.${t} cannot change after startup. The library keeps "${this.config.bus[t]}".`, { requested: e.bus[t] }), Object.assign(e.bus, { [t]: this.config.bus[t] }));
1886
1506
  let { maxAgeMs: t } = this.config.journey;
1887
1507
  e.journey.maxAgeMs !== t && (this.diagnostics.report("config.invalid", `journey.maxAgeMs cannot change after startup. It stays ${String(t)}.`, { requested: e.journey.maxAgeMs }), e.journey.maxAgeMs = t);
1508
+ let { maxProbes: n } = this.config.profiler;
1509
+ e.profiler.maxProbes !== n && (this.diagnostics.report("config.invalid", `profiler.maxProbes cannot change after startup. It stays ${String(n)}.`, { requested: e.profiler.maxProbes }), e.profiler.maxProbes = n);
1888
1510
  }
1889
1511
  keepSections(e, t) {
1890
- for (let n of t) J(e[n], this.config[n]) || (this.diagnostics.report("config.invalid", `${n} cannot change after startup. The values in force stay.`, { requested: e[n] }), Object.assign(e, { [n]: this.config[n] }));
1891
- }
1892
- keepBuiltStorage() {
1893
- let e = this.storageBuiltAs;
1894
- 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);
1512
+ for (let n of t) J(e[n], this.config[n]) || (this.diagnostics.report("config.invalid", `${n} cannot change after startup. The current values stay.`, { requested: e[n] }), Object.assign(e, { [n]: this.config[n] }));
1895
1513
  }
1896
1514
  keepDestination(e) {
1897
1515
  if (this.senderLoad === void 0) return e;
1898
1516
  let t = e;
1899
- for (let n of ["transport", "transportWorker"]) n in e && e[n] === void 0 != (this.config[n] === void 0) && (this.diagnostics.report("config.invalid", `You cannot add or remove ${n} after the delivery stack loads. The transport in force stays.`), t = { ...t }, Reflect.deleteProperty(t, n));
1900
- return (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 = {
1517
+ for (let n of ["transport", "transportWorker"]) {
1518
+ let r = e[n], i = typeof r == "function" && this.config[n] === void 0, a = r === null && this.config[n] !== void 0;
1519
+ (i || a) && (this.diagnostics.report("config.invalid", `You cannot add or remove ${n} after the delivery stack loads. The current transport stays.`), t = { ...t }, Reflect.deleteProperty(t, n));
1520
+ }
1521
+ return (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 current endpoint stays."), t = {
1901
1522
  ...t,
1902
1523
  endpoint: void 0
1903
1524
  }), t;
1904
1525
  }
1905
1526
  keepBuiltIdentity() {
1527
+ if (!this.tunablesLocked) {
1528
+ this.identityBuiltAs = this.config.identity;
1529
+ return;
1530
+ }
1906
1531
  let e = this.identityBuiltAs;
1907
1532
  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);
1908
1533
  }
1534
+ launch() {
1535
+ this.startFailed || (this.tunablesLocked || (this.tunablesLocked = !0, this.config.enabled || this.drops.add("disabled", this.rehookHeld())), !this.running && this.config.enabled && this.start());
1536
+ }
1537
+ start() {
1538
+ this.running = !0, this.identityBuiltAs === "storage" && !this.onServer() && (this.backing = Je);
1539
+ let { sessionIdleMs: e, traceMaxAgeMs: t } = this.config.correlation, { sessionId: n, tabId: r } = qe(this.diagnostics, this.stores, e);
1540
+ this.sessionTouch = new We(this.diagnostics, this.stores, e), this.sessionPicked ? this.sessionTouch.restart(this.identity.sessionId) : this.identity.sessionId = n, this.identity.tabId = r, this.builder.invalidateResource(), this.breadcrumbs.retain((e) => !An.includes(e.category)), this.tracing.setup(t ?? Infinity, this.config.otelLoader), this.tracing.loadOtel();
1541
+ for (let e of this.rehookHeld()) this.bootBuffer.push(e, this.config.buffering.maxHeldRecords);
1542
+ this.openGate(), this.init();
1543
+ }
1544
+ rehookHeld() {
1545
+ return this.bootBuffer.take().map((e) => this.builder.rehook(e)).filter((e) => e !== null);
1546
+ }
1909
1547
  async init() {
1910
1548
  this.degraded || addEventListener("pagehide", this.onPageHide);
1911
1549
  let e = this.installCaptures();
@@ -1938,22 +1576,23 @@ var q = class e {
1938
1576
  }
1939
1577
  async buildBus() {
1940
1578
  try {
1941
- let { Bus: e } = await import("./bus-BZ0GldpT.js");
1579
+ await this.startGate;
1580
+ let { Bus: e } = await import("./bus-C39wspFV.js");
1942
1581
  if (this.destroyed) return null;
1943
1582
  let t = new e(this.config, this.diagnostics, this.platform, this.identity.contextId, this.identity.tabId, {
1944
1583
  onSecurityContext: (e) => {
1945
1584
  if (this.explicitSecurityContext && this.config.securityContext.id !== e) return this.contextMismatch = !0, this.diagnostics.report("security.context_mismatch", "The configured security context differs from the upstream owner."), !1;
1946
1585
  if (this.contextMismatch = !1, this.config.securityContext.id !== e) {
1947
1586
  if (this.ownerAdopted) {
1948
- N(this), this.drops.add("security_context", [
1587
+ R(this), this.drops.add("security_context", [
1949
1588
  ...this.bootBuffer.take(),
1950
1589
  ...this.pendingRecords.take(),
1951
1590
  ...this.forwardBuffer
1952
1591
  ]), this.forwardBuffer = [], this.context.clear(), this.breadcrumbs.clear();
1953
1592
  let e = this.rotating;
1954
- this.rotating = !0, this.meter.collect();
1593
+ this.rotating = !0, this.collectPoints(), this.profilerOn && j().reset();
1955
1594
  let t = this.sessionTouch.stored();
1956
- this.resetSession(t !== void 0 && t !== this.identity.sessionId ? t : A(this.diagnostics)), this.rotating = e, this.identityEpoch++, this.remote.sampling = null, this.refreshCaptures();
1595
+ this.resetSession(t !== void 0 && t !== this.identity.sessionId ? t : A(this.diagnostics)), this.rotating = e, this.advanceIdentity();
1957
1596
  }
1958
1597
  this.config.securityContext.id = e;
1959
1598
  }
@@ -1962,6 +1601,7 @@ var q = class e {
1962
1601
  onRecords: (e) => {
1963
1602
  this.ingestForwarded(e);
1964
1603
  },
1604
+ paused: () => !this.config.enabled,
1965
1605
  onJourney: (e) => {
1966
1606
  this.journey.applyRemote(e);
1967
1607
  },
@@ -1969,6 +1609,7 @@ var q = class e {
1969
1609
  onTabConflict: () => {
1970
1610
  this.regenerateTabId();
1971
1611
  },
1612
+ onFlush: (e) => this.flushFor(e, !1),
1972
1613
  remote: this.remote
1973
1614
  });
1974
1615
  return this.bus = t, t;
@@ -1980,7 +1621,7 @@ var q = class e {
1980
1621
  return this.bus?.getRole() ?? "sender";
1981
1622
  }
1982
1623
  syncSender() {
1983
- return !this.hasDestination() || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
1624
+ return !this.running || !this.config.enabled || this.deliveryClosed || this.destroyed || !this.hasDestination() || this.role() !== "sender" ? Promise.resolve() : this.loadSender();
1984
1625
  }
1985
1626
  hasDestination() {
1986
1627
  return !!this.config.endpoint || this.config.transport !== void 0;
@@ -1989,9 +1630,8 @@ var q = class e {
1989
1630
  return this.senderLoad ??= this.buildSender(), this.senderLoad;
1990
1631
  }
1991
1632
  async buildSender() {
1992
- this.storageBuiltAs = this.config.storage;
1993
1633
  try {
1994
- let { Sender: e } = await import("./sender-CiMHC9YG.js"), t = this.destroyed ? null : await e.create({
1634
+ let { Sender: e } = await import("./sender-Dv8rAmpV.js"), t = this.destroyed ? null : await e.create({
1995
1635
  storage: this.memoryStorage,
1996
1636
  onStorage: (e) => {
1997
1637
  e.name === "memory" && (this.memoryStorage = e);
@@ -2005,29 +1645,65 @@ var q = class e {
2005
1645
  onLoss: this.reportLoss,
2006
1646
  remote: this.remote,
2007
1647
  beforeExit: () => {
2008
- N(this), this.meter.collect(), this.tracing.end();
1648
+ R(this), this.collectPoints(), this.tracing.end();
1649
+ },
1650
+ onSent: (e) => {
1651
+ this.lastSendAt = e;
2009
1652
  }
2010
1653
  });
2011
1654
  if (!t || this.destroyed) {
2012
- await t?.destroy();
1655
+ await t?.discard();
2013
1656
  return;
2014
1657
  }
2015
- this.sender = t;
1658
+ if (this.deliveryClosed) {
1659
+ await this.parkSender(t);
1660
+ return;
1661
+ }
1662
+ this.sender = t, this.config.enabled || t.hold(!0);
2016
1663
  } catch (e) {
2017
1664
  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), this.drops.add("load_failed", this.pendingRecords.records);
2018
1665
  }
2019
1666
  for (let e of this.pendingRecords.take()) this.sender?.push(e);
1667
+ let e = this.carried;
1668
+ this.carried = [], this.sender && e.length > 0 && await this.adoptStored(this.sender, e);
1669
+ }
1670
+ async adoptStored(e, t) {
1671
+ await this.diagnostics.guardAsync("storage.degraded", "The library could not store the carried batches under the new context.", () => e.adopt(t, this.config.securityContext.id));
2020
1672
  }
2021
1673
  refreshCaptures() {
2022
1674
  if (clearTimeout(this.remoteCaptureTimer), this.remoteCaptureTimer = void 0, this.destroyed) return;
2023
1675
  let e = this.remote.sampling?.wire();
2024
1676
  e && (this.remoteCaptureTimer = setTimeout(() => {
2025
1677
  this.refreshCaptures();
2026
- }, e.ttlMs), Ge(this.remoteCaptureTimer)), Pr(this.effectiveCapture()) !== this.installedCaptureKey && this.installCaptures();
1678
+ }, e.ttlMs), O(this.remoteCaptureTimer)), this.captureState(this.effectiveCapture()) !== this.installedCaptureKey && this.installCaptures();
1679
+ }
1680
+ captureState(e) {
1681
+ let { enabled: t, framePhases: n, framePacing: r } = this.config.profiler;
1682
+ return `${String(this.config.enabled)}${Fn(e)}${String(t && n)}${String(t && r)}${this.replayState(e)}`;
1683
+ }
1684
+ replayState(e) {
1685
+ let { replay: t } = this.config;
1686
+ return t.enabled ? JSON.stringify([
1687
+ t.loader && G(t.loader),
1688
+ t.onSegment && G(t.onSegment),
1689
+ G(t.recordOptions),
1690
+ t.endpoint,
1691
+ t.requireConsent,
1692
+ t.mode,
1693
+ t.maskText,
1694
+ t.maskInputs,
1695
+ t.maskSelectors,
1696
+ t.blockSelectors,
1697
+ t.recordCanvas,
1698
+ t.bufferMs,
1699
+ t.plugins.map(G),
1700
+ e.fullUrls,
1701
+ e.ignoreUrls.map(String)
1702
+ ]) : "";
2027
1703
  }
2028
1704
  effectiveCapture() {
2029
1705
  let e = { ...this.config.capture }, t = this.remote.sampling?.current()?.capture;
2030
- for (let n of ke) {
1706
+ for (let n of Ce) {
2031
1707
  let r = t?.[n];
2032
1708
  if (e.remoteToggles.includes(n) && r !== void 0) {
2033
1709
  if (r && typeof e[n] == "object") continue;
@@ -2037,21 +1713,26 @@ var q = class e {
2037
1713
  return e;
2038
1714
  }
2039
1715
  async installCaptures() {
2040
- if (this.degraded) return;
1716
+ if (this.degraded || !this.running) return;
2041
1717
  let e = ++this.captureGeneration, t = this.effectiveCapture();
2042
- this.installedCaptureKey = Pr(t);
2043
- let n = [];
2044
- (t.errors || t.rejections || t.resourceErrors) && n.push("errors"), (t.fetch || t.xhr) && n.push("network"), (t.interactions || t.navigation) && n.push("interactions"), t.webVitals && n.push("webVitals"), t.longFrames && n.push("longFrames"), (Array.isArray(t.console) ? t.console.length > 0 : t.console) && n.push("console"), t.uncleanExit && n.push("uncleanExit"), t.userTiming && n.push("userTiming"), t.reports && n.push("reports"), t.resourceTiming && n.push("resourceTiming"), t.lifecycle && n.push("lifecycle");
2045
- let [r, i] = await Promise.all([Promise.all(n.map((e) => this.loadCapture(e))), t.webSocket ? this.loadWebSocket() : void 0]);
1718
+ if (this.installedCaptureKey = this.captureState(t), !this.config.enabled) {
1719
+ this.uninstallCaptures();
1720
+ return;
1721
+ }
1722
+ let n = this.replayState(t);
1723
+ n !== this.replayBuiltKey && (this.replayBuiltKey = "");
1724
+ let r = n !== "" && n === this.replayBuiltKey ? this.replay : void 0, i = [], { profiler: a } = this.config;
1725
+ (t.errors || t.rejections || t.resourceErrors) && i.push("errors"), (t.fetch || t.xhr) && i.push("network"), (t.interactions || t.navigation) && i.push("interactions"), t.webVitals && i.push("webVitals"), t.longFrames && i.push("longFrames"), (typeof t.console == "object" ? t.console.levels?.length !== 0 : t.console) && i.push("console"), t.uncleanExit && i.push("uncleanExit"), t.userTiming && i.push("userTiming"), t.reports && i.push("reports"), t.resourceTiming && i.push("resourceTiming"), t.lifecycle && i.push("lifecycle"), a.enabled && a.framePhases && i.push("framePhases"), a.enabled && a.framePacing && i.push("framePacing"), this.config.replay.enabled && !r && i.push("replay");
1726
+ let [o, s] = await Promise.all([Promise.all(i.map((e) => this.loadCapture(e))), t.webSocket ? this.loadWebSocket() : void 0]);
2046
1727
  if (e !== this.captureGeneration || this.destroyed) return;
2047
- this.uninstallCaptures();
2048
- let a = {
1728
+ this.uninstallCaptures(r);
1729
+ let c = {
2049
1730
  isActive: () => !this.destroyed && !this.rotating,
2050
1731
  config: Object.assign(Object.create(this.config), { capture: t }),
2051
1732
  diagnostics: this.diagnostics,
2052
1733
  breadcrumbs: this.breadcrumbs,
2053
1734
  tracing: this.tracing,
2054
- logger: new F(() => this, _),
1735
+ logger: new vt(() => this, h),
2055
1736
  once: this.captureOnce,
2056
1737
  recordMetric: (e, t, n) => {
2057
1738
  this.recordMetric(e, t, n);
@@ -2059,40 +1740,54 @@ var q = class e {
2059
1740
  recordSpan: (e) => {
2060
1741
  this.recordSpan(e);
2061
1742
  },
2062
- sessionId: () => this.identity.sessionId
1743
+ sessionId: () => this.identity.sessionId,
1744
+ onError: (e) => {
1745
+ this.errorHook = e;
1746
+ },
1747
+ setContext: (e, t) => {
1748
+ this.context.merge({ [e]: t ?? null });
1749
+ },
1750
+ replayConsent: () => this.replayConsent
2063
1751
  };
2064
- for (let e of r) e && this.captures.push(new e(a));
2065
- let o = i ? [...t.plugins, new i(this.diagnostics, a.config)] : t.plugins;
2066
- for (let e of o) this.captures.push(this.pluginCapture(e));
1752
+ o.forEach((e, t) => {
1753
+ if (e) {
1754
+ let r = new e(c);
1755
+ this.captures.push(r), i[t] === "replay" && (this.replay = r, this.replayBuiltKey = n);
1756
+ }
1757
+ });
1758
+ let l = s ? [...t.plugins, new s(this.diagnostics, c.config)] : t.plugins;
1759
+ for (let e of l) this.captures.push(this.pluginCapture(e));
2067
1760
  for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `The library could not install the ${e.name} capture.`, () => {
2068
1761
  e.install();
2069
1762
  });
2070
1763
  }
2071
- uninstallCaptures() {
2072
- for (let e of this.captures) this.diagnostics.guard("capture.install_failed", `The library could not uninstall the ${e.name} capture.`, () => {
2073
- e.uninstall();
1764
+ uninstallCaptures(e) {
1765
+ for (let t of this.captures) t !== e && this.diagnostics.guard("capture.install_failed", `The library could not uninstall the ${t.name} capture.`, () => {
1766
+ t.uninstall();
2074
1767
  });
2075
- this.captures.length = 0;
1768
+ this.captures.length = 0, this.replay = e, e && this.captures.push(e);
2076
1769
  }
2077
1770
  loadWebSocket() {
2078
- return this.diagnostics.guardAsync("capture.install_failed", "The library could not load the webSocket capture.", async () => (await import("./web-socket-CV7yIMnm.js")).WebSocketCapture);
1771
+ return this.diagnostics.guardAsync("capture.install_failed", "The library could not load the webSocket capture.", async () => (await import("./web-socket-DSHgDiZ6.js")).WebSocketCapture);
2079
1772
  }
2080
1773
  pluginCapture(e) {
2081
1774
  let { name: t } = e, n = (e, t, n) => {
2082
1775
  this.recordMetric(e, t, n);
2083
- }, r = {
2084
- logger: new F(() => this, `${_}.${t}`),
2085
- counter: (e, t = {}) => Nt(e, t, n),
2086
- histogram: (e, t = {}) => Pt(e, t, n),
1776
+ }, r = (e) => {
1777
+ this.diagnostics.report("config.invalid", Ae, void 0, e);
1778
+ }, i = {
1779
+ logger: new B(() => this, `${h}.${t}`),
1780
+ counter: (e, t = {}) => Vt(e, t, n, r),
1781
+ histogram: (e, t = {}) => Ut(e, t, n, r),
2087
1782
  addBreadcrumb: (e, t) => {
2088
1783
  this.addBreadcrumb(e, t);
2089
1784
  },
2090
- ownRequest: rt
1785
+ ownRequest: Qe
2091
1786
  };
2092
1787
  return {
2093
1788
  name: t,
2094
1789
  install: () => {
2095
- e.install(r);
1790
+ e.install(i);
2096
1791
  },
2097
1792
  uninstall: () => {
2098
1793
  e.uninstall();
@@ -2100,7 +1795,7 @@ var q = class e {
2100
1795
  };
2101
1796
  }
2102
1797
  loadCapture(e) {
2103
- return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, wr[e]);
1798
+ return this.diagnostics.guardAsync("capture.install_failed", `The library could not load the ${e} capture.`, wn[e]);
2104
1799
  }
2105
1800
  registerWorker(e, t = {}) {
2106
1801
  let n = !1, r;
@@ -2120,23 +1815,85 @@ var q = class e {
2120
1815
  n = !0, r?.();
2121
1816
  };
2122
1817
  }
2123
- async destroy() {
2124
- if (this.destroyed) return;
2125
- N(this), this.meter.collect(), this.tracing.end(), this.destroyed = !0, bt(this), clearTimeout(this.remoteCaptureTimer), this.remoteCaptureTimer = void 0, this.degraded || removeEventListener("pagehide", this.onPageHide), this.uninstallCaptures();
2126
- let t = this.sender?.destroy();
2127
- this.journey.destroy(), this.sendForwarded(), this.bus?.destroy(), this.drops.add("load_failed", this.pendingRecords.take()), await t, await this.senderLoad, await this.rotation?.catch(() => void 0), await this.memoryStorage?.close(), e.pinned() === this && (Reflect.deleteProperty(globalThis, Or), globalThis[kr] = this);
1818
+ async destroy(e) {
1819
+ let { discard: t, scope: n } = this.shutdownRule(e);
1820
+ this.stopping ??= this.stop(t), await this.stopping, n !== void 0 && await this.clearStorage(n);
1821
+ }
1822
+ async stop(t) {
1823
+ t || (R(this), this.collectPoints(), this.tracing.end()), this.profilerOn && (this.profilerOn = !1, j().detach()), this.destroyed = !0, this.backing = Ke(), dt(this), this.collectPoints(), clearTimeout(this.remoteCaptureTimer), this.remoteCaptureTimer = void 0, this.degraded || removeEventListener("pagehide", this.onPageHide), this.uninstallCaptures();
1824
+ let n = t ? this.discardHeld() : this.flushHeld();
1825
+ this.journey.destroy(), this.bus?.destroy(), await n, await this.senderLoad, await this.rotation?.catch(() => void 0);
1826
+ let r = this.parkedSender;
1827
+ this.parkedSender = void 0, await this.diagnostics.guardAsync("pipeline.crashed", "The delivery stack of the old context did not stop at shutdown. The library leaves its stored batches in storage.", async () => {
1828
+ await (t ? r?.discard() : r?.retire("retain", 0, this.config.securityContext.id));
1829
+ }), await this.memoryStorage?.close(), e.pinned() === this && (Reflect.deleteProperty(globalThis, Dn), globalThis[On] = this);
1830
+ }
1831
+ shutdownRule(e) {
1832
+ let t = this.readOptions(e, Mn);
1833
+ if (t === void 0) return { discard: !0 };
1834
+ let { pending: n, clearStorage: r } = t, i = r == null, a = i || r === "context" || r === "namespace", o;
1835
+ i || (o = r === "namespace" ? "namespace" : "context");
1836
+ let s = n === void 0 || n === "flush";
1837
+ return (!a || !(s || n === "discard") || n === "flush" && o) && this.diagnostics.report("config.invalid", Mn), {
1838
+ discard: !s || o !== void 0,
1839
+ scope: o
1840
+ };
1841
+ }
1842
+ async flushHeld() {
1843
+ this.dropPaused();
1844
+ let e = this.sender?.destroy();
1845
+ this.sendForwarded(), this.drops.add("load_failed", this.unreported(this.pendingRecords.take())), await e;
1846
+ }
1847
+ async discardHeld() {
1848
+ let e = [
1849
+ ...this.bootBuffer.take(),
1850
+ ...this.pendingRecords.take(),
1851
+ ...this.forwardBuffer
1852
+ ];
1853
+ this.forwardBuffer = [], this.breadcrumbs.clear(), this.debugBuffer.clear(), this.context.clear(), this.journey.applyRemote(null);
1854
+ let t = await this.sender?.discard() ?? [];
1855
+ this.drops.add("discarded", this.unreported([...e, ...t]));
1856
+ }
1857
+ async clearStorage(e) {
1858
+ this.tunablesLocked && await this.diagnostics.guardAsync("storage.degraded", "The library could not remove the stored batches at shutdown.", async () => {
1859
+ let { clearStored: t } = await import("./stored-context-B2EzVuYm.js"), n = this.carried.map((e) => e.id);
1860
+ this.carried = [], await t(this.storeAccess(), e, n, this.identityBuiltAs === "storage" && !this.onServer());
1861
+ });
2128
1862
  }
2129
1863
  emit(e) {
2130
- if (!e || this.destroyed || this.rotating && !this.closingContext) return;
1864
+ if (!e || this.destroyed) return;
1865
+ if (this.rotating && !this.closingContext) {
1866
+ this.drops.add("security_context", [e]);
1867
+ return;
1868
+ }
2131
1869
  this.sessionTouch.touch(this.identity.sessionId);
2132
- let t = e.severityText === "ERROR" || e.severityText === "FATAL" ? [...this.debugBuffer.drain(), e] : [e];
2133
- for (let e of t) this.ready ? this.route(e) : this.bootBuffer.push(e);
1870
+ let t = e.severityText === "ERROR" || e.severityText === "FATAL", n = t ? [...this.debugBuffer.drain(), e] : [e];
1871
+ t && this.errorHook?.(e);
1872
+ for (let e of n) this.ready ? this.route(e) : this.bootBuffer.push(e, this.config.buffering.maxHeldRecords);
2134
1873
  }
2135
1874
  route(e) {
2136
1875
  this.role() === "forwarder" ? this.forward(e) : this.deliver(e);
2137
1876
  }
2138
1877
  deliver(e) {
2139
- this.sender ? this.sender.push(e) : this.senderLoad ? this.pendingRecords.push(e) : (this.diagnostics.count("record.dropped_no_destination"), this.hasDestination() && this.drops.add("load_failed", [e]));
1878
+ if (this.deliveryClosed) {
1879
+ this.drops.add("security_context", [e]);
1880
+ return;
1881
+ }
1882
+ if (this.sender) {
1883
+ this.sender.push(e);
1884
+ return;
1885
+ }
1886
+ let t = !this.config.enabled && this.hasDestination();
1887
+ !this.senderLoad && !t ? (this.diagnostics.count("record.dropped_no_destination"), this.hasDestination() && this.drops.add("load_failed", [e])) : this.pendingRecords.push(e, this.config.buffering.maxHeldRecords);
1888
+ }
1889
+ dropPaused() {
1890
+ if (this.config.enabled) return;
1891
+ let e = this.unreported([...this.pendingRecords.records, ...this.sender?.records() ?? []]);
1892
+ for (let t of e) this.pausedLoss.add(t);
1893
+ this.drops.add("disabled", e);
1894
+ }
1895
+ unreported(e) {
1896
+ return e.filter((e) => !this.pausedLoss.has(e));
2140
1897
  }
2141
1898
  dropHeld(e) {
2142
1899
  this.diagnostics.count("record.dropped_boot_buffer_full"), this.drops.add("buffer_full", [e]);
@@ -2148,7 +1905,9 @@ var q = class e {
2148
1905
  }
2149
1906
  sendForwarded() {
2150
1907
  let e = this.forwardBuffer;
2151
- this.forwardBuffer = [], e.length > 0 && this.bus?.sendRecords(e);
1908
+ this.forwardBuffer = [];
1909
+ let { bus: t } = this;
1910
+ return e.length === 0 || !t ? 0 : t.sendRecords(e);
2152
1911
  }
2153
1912
  ingestForwarded(e) {
2154
1913
  if (this.destroyed) return;
@@ -2158,11 +1917,11 @@ var q = class e {
2158
1917
  }
2159
1918
  let t = [];
2160
1919
  for (let n of e) {
2161
- if (!ze(n)) {
1920
+ if (!Ne(n)) {
2162
1921
  this.diagnostics.count("record.dropped_malformed");
2163
1922
  continue;
2164
1923
  }
2165
- if (n.attributes["uiobs.debug_buffer"] !== !0 && !ct(n, this.config, this.remote.sampling?.current() ?? null)) {
1924
+ if (n.attributes["uiobs.debug_buffer"] !== !0 && !it(n, this.config, this.remote.sampling?.current() ?? null)) {
2166
1925
  this.diagnostics.count("record.dropped_by_sampling");
2167
1926
  continue;
2168
1927
  }
@@ -2170,108 +1929,118 @@ var q = class e {
2170
1929
  e && t.push(e);
2171
1930
  }
2172
1931
  if (this.rotating) this.drops.add("security_context", t);
1932
+ else if (!this.config.enabled) this.drops.add("disabled", t);
2173
1933
  else for (let e of t) this.deliver(e);
2174
1934
  }
2175
1935
  releaseBootBuffer() {
2176
1936
  let e = this.bootBuffer.take(), { processors: t, redact: n } = this.config, r = t.length === 0 && n === void 0 ? this.journey.current() : null;
2177
1937
  for (let t of e) r && !t.attributes["journey.id"] && (t.attributes["journey.id"] = r.id, t.attributes["journey.name"] = r.name), this.route(t);
2178
1938
  }
2179
- reportLoss = (e, t, n) => {
2180
- this.drops.add(e, t, n);
2181
- };
2182
- reportGap = (e, t) => {
2183
- this.drops.add(e.reason, t.flatMap((e) => e.records), t.map((e) => e.id));
2184
- let n = Date.now();
2185
- n - this.lastGapAt < 6e4 || (this.lastGapAt = n, new F(() => this, Ie).warn("stored records were dropped before delivery", {
2186
- "gap.batches": e.batches,
2187
- "gap.records": e.records,
2188
- "gap.reason": e.reason
2189
- }));
2190
- };
2191
1939
  regenerateTabId() {
2192
1940
  let e = A(this.diagnostics);
2193
1941
  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.", {
2194
1942
  was: this.identity.tabId,
2195
1943
  now: e
2196
- }), this.identity.tabId = e, Ze(e, this.diagnostics, this.stores), this.builder.invalidateResource();
1944
+ }), this.identity.tabId = e, Ue(e, this.diagnostics, this.stores), this.builder.invalidateResource();
2197
1945
  }
2198
1946
  newSession() {
2199
- this.destroyed || (N(this), this.resetSession(A(this.diagnostics)));
1947
+ this.destroyed || (R(this), this.resetSession(A(this.diagnostics)));
2200
1948
  }
2201
1949
  resetSession(e) {
2202
- this.meter.collect(), this.tracing.rotate("explicit"), this.journey.end(), this.breadcrumbs.clear(), this.debugBuffer.clear(), this.identity.sessionId = e, this.sessionTouch.restart(e), this.builder.invalidateResource();
1950
+ this.sessionPicked = !0, this.collectPoints(), this.tracing.rotate("explicit"), this.journey.end(), this.breadcrumbs.clear(), this.debugBuffer.clear(), this.replay?.reset(), this.identity.sessionId = e, this.sessionTouch.restart(e), this.builder.invalidateResource();
2203
1951
  }
2204
1952
  rotateSecurityContext(e, t = {}) {
2205
- if (this.rotation) return Promise.reject(/* @__PURE__ */ Error("A security-context rotation is already running."));
2206
- let n = t.pending ?? "discard", r = t.timeoutMs ?? 5e3;
2207
- return !E(e) || !E(e.delivery) || ![
2208
- "discard",
2209
- "flush",
2210
- "retain",
2211
- "carry"
2212
- ].includes(n) || !Number.isFinite(r) || r < 0 || e.id !== void 0 && (typeof e.id != "string" || e.id.length === 0) ? Promise.reject(/* @__PURE__ */ Error("Invalid security-context rotation options.")) : this.destroyed ? Promise.reject(/* @__PURE__ */ Error("The runtime has stopped.")) : (N(this), this.rotating = !0, this.rotation = this.rotateContext(e, n, r).finally(() => {
2213
- this.rotating = !1, this.rotation = void 0;
2214
- }), this.rotation);
2215
- }
2216
- async rotateContext(e, t, n) {
1953
+ if (this.destroyed) return Promise.reject(/* @__PURE__ */ Error("The runtime has stopped."));
1954
+ if (!this.tunablesLocked) return Promise.reject(/* @__PURE__ */ Error("The runtime is not configured. Call configure() before rotateSecurityContext()."));
1955
+ R(this), this.rotating = !0;
1956
+ let n = ++this.rotationSeq, r = (this.rotation ?? Promise.resolve()).catch(() => void 0).then(() => this.runRotation(e, t, n));
1957
+ this.rotation = r;
1958
+ let i = () => {
1959
+ this.rotation === r && (this.rotation = void 0, this.rotating = !1, this.retiring = void 0);
1960
+ };
1961
+ return r.then(i, i), r;
1962
+ }
1963
+ async runRotation(e, t, n) {
1964
+ if (this.destroyed) throw Error("The runtime has stopped.");
2217
1965
  if (await this.started, this.role() === "forwarder") throw Error("Rotate the security context on the upstream owner, or use bus.mode: sender for an independent identity.");
2218
- await this.senderLoad;
2219
- let r = this.config.securityContext.id, i = e.id ?? A(this.diagnostics);
2220
- if (i === r) throw Error("A rotation requires a different security-context id.");
2221
- let a = {
2222
- ...jr,
2223
- ...e.delivery
2224
- }, o = this.diagnostics.snapshot()["config.invalid"] ?? 0, s = G(this.allowed({
2225
- ...a,
2226
- securityContext: { id: i }
2227
- }), this.diagnostics, {
2228
- ...this.config,
2229
- ...jr
2230
- });
2231
- if ((this.diagnostics.snapshot()["config.invalid"] ?? 0) !== o) throw Error("Invalid delivery settings for the next security context.");
2232
- let c = e.context ? Object.fromEntries(Object.entries(e.context)) : void 0, l = /* @__PURE__ */ new Set([
2233
- this.config.endpoint,
2234
- this.config.metricsEndpoint,
2235
- this.config.tracesEndpoint
2236
- ]), u = /* @__PURE__ */ new Set([
2237
- s.endpoint,
2238
- s.metricsEndpoint,
2239
- s.tracesEndpoint
2240
- ]);
2241
- s.capture.ignoreUrls = s.capture.ignoreUrls.filter((e) => !l.has(e) || u.has(e)), this.closingContext = !0;
1966
+ let r;
2242
1967
  try {
2243
- this.meter.collect(), this.tracing.end(), this.journey.end();
2244
- } finally {
2245
- this.closingContext = !1;
1968
+ r = (await import("./rotation-Cwct4ckk.js")).rotateContext;
1969
+ } catch (e) {
1970
+ throw this.diagnostics.report("pipeline.crashed", "The library could not load the security-context rotation.", void 0, e), await this.closeDelivery(), e;
2246
1971
  }
2247
- let d = [
2248
- ...this.bootBuffer.take(),
2249
- ...this.pendingRecords.take(),
2250
- ...this.forwardBuffer
2251
- ];
2252
- this.forwardBuffer = [];
2253
- let f = this.sender;
2254
- this.sender = void 0, this.senderLoad = void 0;
2255
- let p = await f?.retire(t, n, r) ?? {
2256
- buffered: [],
2257
- stored: []
1972
+ if (this.isDestroyed()) throw Error("The runtime has stopped.");
1973
+ await r(this.rotationHost(), e, t, n);
1974
+ }
1975
+ rotationHost() {
1976
+ return {
1977
+ runtime: this,
1978
+ quiet: new V(),
1979
+ senderLoaded: async () => {
1980
+ await this.senderLoad;
1981
+ },
1982
+ allowed: (e) => this.allowed(e),
1983
+ closeDelivery: () => this.closeDelivery(),
1984
+ closeContext: () => {
1985
+ this.closingContext = !0;
1986
+ try {
1987
+ this.collectPoints(), this.tracing.end(), this.journey.end();
1988
+ } finally {
1989
+ this.closingContext = !1;
1990
+ }
1991
+ },
1992
+ takeOld: () => {
1993
+ let e = [
1994
+ ...this.bootBuffer.take(),
1995
+ ...this.pendingRecords.take(),
1996
+ ...this.forwardBuffer
1997
+ ], t = this.sender ?? this.parkedSender;
1998
+ this.retiring = t;
1999
+ let n = this.carried;
2000
+ return this.forwardBuffer = [], this.carried = [], this.sender = void 0, this.senderLoad = void 0, this.parkedSender = void 0, {
2001
+ held: e,
2002
+ sender: t,
2003
+ closed: this.deliveryClosed,
2004
+ carried: n
2005
+ };
2006
+ },
2007
+ drop: (e) => {
2008
+ this.drops.add("security_context", this.unreported(e));
2009
+ },
2010
+ storeAccess: () => this.storeAccess(),
2011
+ advanceIdentity: () => {
2012
+ this.advanceIdentity();
2013
+ },
2014
+ openDelivery: async () => {
2015
+ this.deliveryClosed = !1, await this.syncSender(), this.bus?.rotateContext();
2016
+ },
2017
+ endRotation: (e) => {
2018
+ this.rotating = e !== this.rotationSeq;
2019
+ },
2020
+ route: (e) => {
2021
+ this.route(e);
2022
+ },
2023
+ adopt: async (e) => {
2024
+ this.config.enabled ? await this.sender?.adopt(e, this.config.securityContext.id) : this.carried = [...e];
2025
+ }
2258
2026
  };
2259
- if (this.destroyed) return;
2260
- let m = [...d, ...p.buffered], h = p.stored.flatMap((e) => e.records);
2261
- t !== "retain" && t !== "carry" && this.drops.add("security_context", [...m, ...h]), s.lockConfiguration = this.config.lockConfiguration, rr(this.config, s), this.identityEpoch++, this.remote.sampling = null, this.refreshCaptures(), this.context.clear(), c && this.context.setMany(c), this.breadcrumbs.clear(), this.newSession(), this.builder.invalidateResource(), await this.syncSender(), this.bus?.rotateContext(), this.rotating = !1, t === "carry" && await this.carry(m, p.stored), this.diagnostics.report("security.rotated", "The runtime rotated its security context.", { pending: t });
2262
2027
  }
2263
- async carry(e, t) {
2264
- for (let t of e) this.route(t);
2265
- this.sender && await this.sender.adopt(t, this.config.securityContext.id);
2028
+ async closeDelivery() {
2029
+ this.deliveryClosed = !0, this.diagnostics.report("security.rotation_failed", "The security-context rotation failed. The library sends no record until a rotation succeeds."), await this.senderLoad;
2030
+ let e = this.sender;
2031
+ this.sender = void 0, this.senderLoad = void 0, e && await this.parkSender(e), this.drops.add("security_context", this.unreported(this.pendingRecords.take()));
2032
+ }
2033
+ async parkSender(e) {
2034
+ this.parkedSender = e, await this.diagnostics.guardAsync("pipeline.crashed", "The delivery stack of the old context did not stop. The next rotation that succeeds retires it.", () => e.pause(this.config.securityContext.id));
2266
2035
  }
2267
2036
  async debugBundle(e) {
2268
- let { configSummary: t } = await import("./debug-bundle-C7UkHZ-q.js"), { record: n } = this.builder.build({
2037
+ let { configSummary: t } = await import("./debug-bundle-CRpYV_ui.js"), { record: n } = this.builder.build({
2269
2038
  level: "INFO",
2270
2039
  type: "system",
2271
2040
  body: "debug bundle",
2272
- namespace: Oe,
2273
- payload: { [b]: this.breadcrumbs.snapshot() }
2274
- }, !0), r = n?.attributes ?? {}, i = r[b], a = r[C];
2041
+ namespace: c,
2042
+ payload: { [y]: this.breadcrumbs.snapshot() }
2043
+ }, !0), r = n?.attributes ?? {}, i = r[y], a = r[T];
2275
2044
  return {
2276
2045
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
2277
2046
  sdkVersion: this.sdkVersion,
@@ -2285,72 +2054,114 @@ var q = class e {
2285
2054
  };
2286
2055
  }
2287
2056
  async health() {
2288
- let e = this.sender?.stats() ?? {
2289
- pending: 0,
2290
- inFlight: 0,
2291
- lastSendAt: null
2292
- }, t = [];
2293
- this.mismatchVersion && t.push("runtime.version_mismatch"), this.contextMismatch && t.push("security.context_mismatch"), this.ready && this.hasDestination() && this.role() === "sender" && !this.sender && t.push("sender.unavailable");
2294
- let { sourcePolicy: n, validation: r, maxMessageBytes: i, maxRecordsPerMessage: a, maxMessagesPerSecond: o, maxTrackedSources: s } = this.config.bus;
2057
+ let e = this.sender?.stats(), t = [];
2058
+ this.mismatchVersion && t.push("runtime.version_mismatch"), this.contextMismatch && t.push("security.context_mismatch");
2059
+ let { redact: n, processors: r } = this.config;
2060
+ (n === F || r.includes(F)) && t.push("records.refused"), this.deliveryClosed ? t.push("security.rotation_failed") : this.ready && this.config.enabled && this.hasDestination() && this.role() === "sender" && !this.sender && t.push("sender.unavailable");
2061
+ let { sourcePolicy: i, maxMessageBytes: a, maxRecordsPerMessage: o, maxMessagesPerSecond: s } = this.config.bus;
2295
2062
  return {
2296
- ...e,
2297
- pending: e.pending + this.bootBuffer.length + this.pendingRecords.length + this.forwardBuffer.length,
2298
- stored: await this.sender?.queueDepth() ?? 0,
2063
+ delivery: {
2064
+ pending: (e?.pending ?? 0) + this.heldRecords(),
2065
+ inFlight: e?.inFlight ?? 0,
2066
+ stored: await this.storedBatches(),
2067
+ lastSendAt: this.lastSendAt,
2068
+ lastFailureAt: e?.lastFailureAt ?? null,
2069
+ consecutiveFailures: e?.consecutiveFailures ?? 0,
2070
+ throttledUntil: e?.throttledUntil ?? null,
2071
+ dropped: this.drops.counts()
2072
+ },
2299
2073
  sdkVersion: this.sdkVersion,
2300
2074
  owningSdkVersion: this.mismatchVersion,
2301
- status: this.destroyed ? "stopped" : this.rotating ? "rotating" : t.length ? "degraded" : this.ready ? "ready" : "starting",
2075
+ status: this.destroyed ? "stopped" : this.tunablesLocked ? this.config.enabled ? this.rotating ? "rotating" : t.length ? "degraded" : this.ready ? "ready" : "starting" : "disabled" : "unconfigured",
2302
2076
  mode: this.role() === "forwarder" ? "forwarder" : this.hasDestination() ? "sender" : "console-only",
2303
- senderReady: this.sender !== void 0 && !this.destroyed && !this.rotating,
2077
+ senderReady: this.sender !== void 0 && this.config.enabled && !this.destroyed && !this.rotating && !this.deliveryClosed,
2304
2078
  configurationLocked: this.config.lockConfiguration,
2305
2079
  issues: t,
2306
2080
  securityContext: { ...this.config.securityContext },
2307
2081
  storagePersistence: this.storagePersistence,
2308
2082
  bus: {
2309
- sourcePolicy: n,
2310
- validation: r,
2311
- maxMessageBytes: i,
2312
- maxRecordsPerMessage: a,
2313
- maxMessagesPerSecond: o,
2314
- maxTrackedSources: s
2083
+ sourcePolicy: i,
2084
+ maxMessageBytes: a,
2085
+ maxRecordsPerMessage: o,
2086
+ maxMessagesPerSecond: s
2315
2087
  }
2316
2088
  };
2317
2089
  }
2318
- async stats() {
2319
- let e = await this.queueDepth(), t = this.sender?.stats() ?? {
2320
- pending: 0,
2321
- inFlight: 0,
2322
- lastSendAt: null
2323
- }, n = this.bootBuffer.length + this.pendingRecords.length + this.forwardBuffer.length;
2090
+ storeAccess() {
2324
2091
  return {
2325
- ...t,
2326
- pending: t.pending + n,
2327
- stored: e
2092
+ config: this.config,
2093
+ diagnostics: this.diagnostics,
2094
+ memory: this.memoryStorage
2328
2095
  };
2329
2096
  }
2330
- async clearPersisted(e) {
2331
- if (await this.senderLoad, this.sender) {
2332
- await this.sender.clearPersisted(e, this.config.securityContext.id);
2333
- return;
2334
- }
2335
- let [{ createStorage: t, storageName: n }, { ContextStorage: r }, { storageLimits: i }, { clearEmergencyContext: a }] = await Promise.all([
2336
- import("./factory-BonqI3NL.js"),
2337
- import("./context-storage-BzkoHzkQ.js"),
2338
- import("./storage-DZwed89z.js"),
2339
- import("./emergency-queue-Zy6lNafo.js")
2340
- ]), o = this.config.persistence.namespace, s = this.memoryStorage ?? await t(this.config.storage, n(o), i(this.config.retention), this.diagnostics, void 0, o), c = new r(s, this.config.securityContext, o);
2097
+ async storedBatches() {
2098
+ return await (this.sender ?? this.parkedSender)?.queueDepth() ?? 0;
2099
+ }
2100
+ flush(e) {
2101
+ return this.flushFor(this.flushTimeout(e), !0);
2102
+ }
2103
+ async flushFor(e, t) {
2104
+ R(this), t && this.collectPoints();
2105
+ let n = this.idle();
2106
+ if (n) return n;
2107
+ let r = Date.now() + e, i, a = new Promise((t) => {
2108
+ let n = setTimeout(t, e);
2109
+ O(n), i = () => {
2110
+ clearTimeout(n);
2111
+ };
2112
+ });
2341
2113
  try {
2342
- e === "namespace" ? await c.clearNamespace() : await c.clear(), a(this.config.securityContext.id, this.diagnostics, o, e === "namespace");
2114
+ return await this.flushBefore(r, a);
2343
2115
  } finally {
2344
- s !== this.memoryStorage && await c.close();
2116
+ i();
2117
+ }
2118
+ }
2119
+ async flushBefore(e, t) {
2120
+ let n = this.heldRecords(), r = this.ready ? this.senderLoad : this.started;
2121
+ if (r && (!this.ready || !this.sender) && !await Promise.race([r.then(() => !0), t.then(() => !1)])) return K({ pending: this.waiting() });
2122
+ let { bus: i } = this, a = i?.getRole() === "forwarder", o = this.idle();
2123
+ if (o) return o;
2124
+ if (a) {
2125
+ let n = this.forwardBuffer.length, r = this.sendForwarded(), a = n - r, o = Math.floor(Math.max(0, e - Date.now()) * xe), s = await i.requestFlush(o, t);
2126
+ return s ? {
2127
+ ...s,
2128
+ forwarded: r,
2129
+ dropped: s.dropped + a
2130
+ } : K({
2131
+ forwarded: r,
2132
+ pending: r,
2133
+ dropped: a
2134
+ });
2135
+ }
2136
+ let { sender: s } = this;
2137
+ return s ? K(await s.flushUntil(t)) : this.rotating ? K({ pending: n + this.waiting() }) : zn("complete", { dropped: n });
2138
+ }
2139
+ idle() {
2140
+ return this.tunablesLocked && this.config.enabled && !this.destroyed ? null : zn("inactive", { pending: this.destroyed ? 0 : this.waiting() });
2141
+ }
2142
+ heldRecords() {
2143
+ return this.bootBuffer.length + this.pendingRecords.length + this.forwardBuffer.length;
2144
+ }
2145
+ waiting() {
2146
+ let e = this.heldRecords();
2147
+ for (let t of [this.sender, this.retiring]) {
2148
+ let n = t?.stats();
2149
+ e += n ? n.pending + n.inFlight : 0;
2345
2150
  }
2151
+ return e;
2346
2152
  }
2347
- async queueDepth() {
2348
- return await this.senderLoad, await this.sender?.queueDepth() ?? 0;
2153
+ readOptions(e, t) {
2154
+ if (typeof e != "object" && e !== void 0) this.diagnostics.report("config.invalid", t);
2155
+ else return this.diagnostics.guard("config.invalid", t, () => ({ ...e }));
2349
2156
  }
2350
- async flush() {
2351
- N(this), this.meter.collect(), this.ready || await this.started, this.role() === "forwarder" ? this.sendForwarded() : (await this.senderLoad, await this.sender?.flush());
2157
+ flushTimeout(e) {
2158
+ let t = this.readOptions(e, Nn);
2159
+ if (!t) return ae;
2160
+ let n = t.timeoutMs ?? 5e3;
2161
+ return typeof n == "number" && n >= 0 && n <= 6e5 ? n : (this.diagnostics.report("config.invalid", Nn), ae);
2352
2162
  }
2353
2163
  };
2164
+ k(q, "local", null);
2354
2165
  function J(e, t, n = /* @__PURE__ */ new WeakMap()) {
2355
2166
  if (Object.is(e, t)) return !0;
2356
2167
  if (e instanceof RegExp && t instanceof RegExp) return String(e) === String(t);
@@ -2358,38 +2169,38 @@ function J(e, t, n = /* @__PURE__ */ new WeakMap()) {
2358
2169
  if (n.has(e)) return n.get(e) === t;
2359
2170
  n.set(e, t);
2360
2171
  let r = Object.keys(e), i = Object.keys(t);
2361
- return r.length === i.length && r.every((r) => Object.hasOwn(t, r) && J(Reflect.get(e, r), Reflect.get(t, r), n));
2172
+ return r.length === i.length && r.every((r) => ze(t, r) && J(Reflect.get(e, r), Reflect.get(t, r), n));
2362
2173
  }
2363
2174
  // src/transport/worker-entry.ts
2364
2175
  var Y;
2365
- function zr(e = {}) {
2176
+ function Vn(e = {}) {
2366
2177
  if (Y) return Y;
2367
- let n = new or(e.onDiagnostic);
2368
- if (typeof document < "u" || typeof addEventListener != "function") return n.report("config.invalid", "Call serveTransportWorker() in a dedicated worker."), () => void 0;
2369
- let r = !1, i, a, o = (e) => {
2370
- n.guard("transport.http_error", "The transport worker could not read its connection.", () => {
2371
- let o = e.data;
2372
- if (!E(o) || o.p !== "ui-observability.transport/1" || o.t !== t.connect || e.ports.length === 0) return;
2373
- let s = e.ports[0];
2374
- i || o.v !== "0.11.0" ? (s.postMessage(Re), s.close()) : (i = s, import("./worker-server-Dp5HYm4b.js").then((e) => {
2375
- r || (a = e.serveWorkerPort(s, n));
2178
+ let t = new V(e.onDiagnostic);
2179
+ if (typeof document < "u" || typeof addEventListener != "function") return t.report("config.invalid", "Call serveTransportWorker() in a dedicated worker."), () => void 0;
2180
+ let n = !1, r, i, a = (e) => {
2181
+ t.guard("transport.http_error", "The transport worker could not read its connection.", () => {
2182
+ let a = e.data;
2183
+ if (!D(a) || a.p !== "ui-observability.transport/1" || a.t !== we.connect || e.ports.length === 0) return;
2184
+ let o = e.ports[0];
2185
+ r || a.v !== "1.0.0" ? (o.postMessage(_e), o.close()) : (r = o, import("./worker-server-iUVSjH8L.js").then((e) => {
2186
+ n || (i = e.serveWorkerPort(o, t));
2376
2187
  }).catch((e) => {
2377
- n.report("transport.http_error", "The transport worker delivery module could not load.", void 0, e), n.guard("transport.http_error", "The failed transport port could not be closed.", () => {
2378
- s.postMessage(Re), s.close();
2188
+ t.report("transport.http_error", "The transport worker delivery module could not load.", void 0, e), t.guard("transport.http_error", "The failed transport port could not be closed.", () => {
2189
+ o.postMessage(_e), o.close();
2379
2190
  });
2380
2191
  }));
2381
2192
  });
2382
- }, s = () => {
2383
- r || (r = !0, Y = void 0, removeEventListener("message", o), a?.(), n.guard("transport.http_error", "The transport service could not close its port.", () => {
2384
- i?.postMessage(Re);
2385
- }), n.guard("transport.http_error", "The transport port could not close.", () => {
2386
- i?.close();
2193
+ }, o = () => {
2194
+ n || (n = !0, Y = void 0, removeEventListener("message", a), i?.(), t.guard("transport.http_error", "The transport service could not close its port.", () => {
2195
+ r?.postMessage(_e);
2196
+ }), t.guard("transport.http_error", "The transport port could not close.", () => {
2197
+ r?.close();
2387
2198
  }));
2388
2199
  };
2389
- return addEventListener("message", o), Y = s, s;
2200
+ return addEventListener("message", a), Y = o, o;
2390
2201
  }
2391
2202
  // src/transport/memory-transport.ts
2392
- function Br() {
2203
+ function Hn() {
2393
2204
  let e = [], t = [], n = { status: 200 };
2394
2205
  return {
2395
2206
  transport: (r) => (e.push(r), n.status >= 200 && n.status < 300 && t.push(r), Promise.resolve({ ...n })),
@@ -2411,19 +2222,16 @@ var X = /* @__PURE__ */ new Map();
2411
2222
  function Z() {
2412
2223
  return (q.current() ?? q.stopped()) || q.configure({}, !0);
2413
2224
  }
2414
- function Vr(e = "context") {
2415
- return ["context", "namespace"].includes(e) ? Z().clearPersisted(e) : Promise.reject(/* @__PURE__ */ Error("Invalid persistence scope."));
2416
- }
2417
- function Hr(e) {
2225
+ function Un(e) {
2418
2226
  q.configure(e), Q();
2419
2227
  }
2420
- function Ur(e) {
2228
+ function Wn(e) {
2421
2229
  Z().setConfigurationLocked(e);
2422
2230
  }
2423
- function Wr(e, t) {
2231
+ function Gn(e, t) {
2424
2232
  return Z().rotateSecurityContext(e, t);
2425
2233
  }
2426
- async function Gr() {
2234
+ async function Kn() {
2427
2235
  let e = Z();
2428
2236
  return Q(), {
2429
2237
  ...await e.health(),
@@ -2433,8 +2241,8 @@ async function Gr() {
2433
2241
  }
2434
2242
  };
2435
2243
  }
2436
- async function Kr() {
2437
- let e = await Gr();
2244
+ async function qn() {
2245
+ let e = await Kn();
2438
2246
  return Z().debugBundle(e);
2439
2247
  }
2440
2248
  function Q() {
@@ -2445,118 +2253,125 @@ function Q() {
2445
2253
  }
2446
2254
  return t;
2447
2255
  }
2448
- function qr(e, t) {
2256
+ function Jn(e, t) {
2449
2257
  let n = Q();
2450
- if (t || n === 0) return new F(Z, e, t);
2258
+ if (t || n === 0) return new B(Z, e, t);
2451
2259
  let r = X.get(e);
2452
- return r ??= new F(Z, e), X.delete(e), X.set(e, r), Q(), r;
2260
+ return r ??= new B(Z, e), X.delete(e), X.set(e, r), Q(), r;
2453
2261
  }
2454
2262
  function $() {
2455
- return qr("app");
2263
+ return Jn("app");
2456
2264
  }
2457
- function Jr(e, t) {
2265
+ function Yn(e, t) {
2458
2266
  $().trace(e, t);
2459
2267
  }
2460
- function Yr(e, t) {
2268
+ function Xn(e, t) {
2461
2269
  $().debug(e, t);
2462
2270
  }
2463
- function Xr(e, t) {
2271
+ function Zn(e, t) {
2464
2272
  $().info(e, t);
2465
2273
  }
2466
- function Zr(e, t) {
2274
+ function Qn(e, t) {
2467
2275
  $().warn(e, t);
2468
2276
  }
2469
- function Qr(e, t, n) {
2277
+ function $n(e, t, n) {
2470
2278
  $().error(e, t, n);
2471
2279
  }
2472
- function $r(e, t, n) {
2280
+ function er(e, t, n) {
2473
2281
  $().fatal(e, t, n);
2474
2282
  }
2475
- function ei(e, t) {
2283
+ function tr(e, t) {
2476
2284
  $().logAction(e, t);
2477
2285
  }
2478
- function ti(e, t) {
2286
+ function nr(e, t) {
2479
2287
  $().logEvent(e, t);
2480
2288
  }
2481
- function ni(e, t, n, r, i) {
2482
- $().logMetric(e, t, n, r, i);
2289
+ function rr(e) {
2290
+ q.current()?.diagnostics.report("config.invalid", Ae, void 0, e);
2483
2291
  }
2484
- function ri(e, t = {}) {
2485
- return Nt(e, t, (e, t, n) => {
2292
+ function ir(e, t = {}) {
2293
+ return Vt(e, t, (e, t, n) => {
2486
2294
  Z().recordMetric(e, t, n);
2487
- });
2295
+ }, rr);
2488
2296
  }
2489
- function ii(e, t = {}) {
2490
- return Pt(e, t, (e, t, n) => {
2297
+ function ar(e, t = {}) {
2298
+ return Ht(e, t, (e, t, n) => {
2491
2299
  Z().recordMetric(e, t, n);
2492
- });
2300
+ }, rr);
2493
2301
  }
2494
- function ai(e, t) {
2302
+ function or(e, t = {}) {
2303
+ return Ut(e, t, (e, t, n) => {
2304
+ Z().recordMetric(e, t, n);
2305
+ }, rr);
2306
+ }
2307
+ function sr(e, t) {
2495
2308
  return Z().startMeasure(e, t);
2496
2309
  }
2497
- function oi(e, t, n) {
2498
- return $().timeSync(e, t, n);
2310
+ function cr(e, t, n) {
2311
+ let r = Z();
2312
+ return Mt(r.startMeasure(e, n), t, r.diagnostics);
2499
2313
  }
2500
- function si(e, t, n) {
2501
- return $().timeAsync(e, t, n);
2314
+ function lr() {
2315
+ Z().setReplay(!0);
2502
2316
  }
2503
- function ci(e, t) {
2504
- Z().addBreadcrumb(e, t);
2317
+ function ur() {
2318
+ Z().setReplay(!1);
2505
2319
  }
2506
- function li(e, t) {
2507
- Z().context.set(e, t);
2320
+ var dr = {
2321
+ probe: (e, t) => j().probe(e, t, q.current()?.diagnostics),
2322
+ time: (e, t) => j().time(e, t, q.current()?.diagnostics)
2323
+ };
2324
+ function fr(e, t) {
2325
+ Z().addBreadcrumb(e, t);
2508
2326
  }
2509
- function ui(e) {
2510
- Z().context.setMany(e);
2327
+ function pr(e) {
2328
+ let t = Z();
2329
+ D(e) ? t.diagnostics.guard("record.sanitize_failed", "The library could not read the values of setContext().", () => {
2330
+ t.context.merge(e);
2331
+ }) : t.diagnostics.report("config.invalid", "setContext() takes an object. The library keeps the current context.");
2511
2332
  }
2512
- function di(e) {
2333
+ function mr(e) {
2513
2334
  Z().context.remove(e);
2514
2335
  }
2515
- function fi(e, t) {
2336
+ function hr(e, t) {
2516
2337
  return Z().journey.start(e, t);
2517
2338
  }
2518
- function pi() {
2339
+ function gr() {
2519
2340
  Z().journey.end();
2520
2341
  }
2521
- function mi() {
2342
+ function _r() {
2522
2343
  return Z().journey.current();
2523
2344
  }
2524
- function hi() {
2345
+ function vr() {
2525
2346
  return Z().journey.getToken();
2526
2347
  }
2527
- function gi(e) {
2348
+ function yr(e) {
2528
2349
  return Z().journey.adopt(e, "manual", !0);
2529
2350
  }
2530
- function _i(e, t) {
2351
+ function br(e, t) {
2531
2352
  return Z().registerWorker(e, t);
2532
2353
  }
2533
- function vi(e, t) {
2354
+ function xr(e, t) {
2534
2355
  return Z().registerFrame(e, t);
2535
2356
  }
2536
- function yi() {
2357
+ function Sr() {
2537
2358
  Z().tracing.rotate("explicit");
2538
2359
  }
2539
- function bi() {
2360
+ function Cr() {
2540
2361
  return Z().tracing.headers();
2541
2362
  }
2542
- function xi() {
2543
- return Z().flush();
2544
- }
2545
- function Si() {
2546
- return Z().queueDepth();
2547
- }
2548
- function Ci() {
2549
- return Z().stats();
2363
+ function wr(e) {
2364
+ return Z().flush(e);
2550
2365
  }
2551
- function wi() {
2366
+ function Tr() {
2552
2367
  Z().newSession();
2553
2368
  }
2554
- function Ti() {
2369
+ function Er() {
2555
2370
  return Z().diagnostics.snapshot();
2556
2371
  }
2557
- async function Ei() {
2558
- await q.current()?.destroy();
2372
+ async function Dr(e) {
2373
+ await (q.current() ?? q.stopped())?.destroy(e);
2559
2374
  }
2560
- export { F as OneLogger, ci as addBreadcrumb, gi as adoptJourney, Vr as clearPersistedLogs, Kr as collectDebugBundle, Hr as configure, ri as counter, Br as createMemoryTransport, mi as currentJourney, Yr as debug, pi as endJourney, Qr as error, $r as fatal, xi as flush, Ti as getDiagnosticCounters, Gr as getHealth, hi as getJourneyToken, qr as getLogger, Si as getQueueDepth, Ci as getStats, bi as getTraceHeaders, ii as histogram, Xr as info, ei as logAction, ti as logEvent, ni as logMetric, wi as newSession, vi as registerFrame, _i as registerWorker, di as removeContext, Wr as rotateSecurityContext, zr as serveTransportWorker, Ur as setConfigurationLocked, li as setContext, ui as setContextMap, Ei as shutdown, fi as startJourney, ai as startMeasure, yi as startTrace, si as timeAsync, oi as timeSync, Jr as trace, Zr as warn };
2375
+ export { fr as addBreadcrumb, yr as adoptJourney, qn as collectDebugBundle, Un as configure, ir as counter, Hn as createMemoryTransport, _r as currentJourney, Xn as debug, gr as endJourney, $n as error, er as fatal, wr as flush, ar as gauge, Er as getDiagnosticCounters, Kn as getHealth, vr as getJourneyToken, Jn as getLogger, Cr as getTraceHeaders, or as histogram, Zn as info, tr as logAction, nr as logEvent, cr as measure, Tr as newSession, Sr as newTrace, dr as profiler, xr as registerFrame, br as registerWorker, mr as removeContext, Gn as rotateSecurityContext, Vn as serveTransportWorker, Wn as setConfigurationLocked, pr as setContext, Dr as shutdown, hr as startJourney, sr as startMeasure, lr as startReplay, ur as stopReplay, Yn as trace, Qn as warn };
2561
2376
 
2562
2377
  //# sourceMappingURL=index.js.map