@utk09/ui-observability 0.12.0 → 1.1.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 (523) hide show
  1. package/CHANGELOG.md +280 -10
  2. package/README.md +70 -839
  3. package/dist/{batch-BjQUwjA6.js → batch-D3NHhF9L.js} +4 -4
  4. package/dist/{batch-BjQUwjA6.js.map → batch-D3NHhF9L.js.map} +1 -1
  5. package/dist/{batch-D5LlU4Q9.cjs → batch-DnYRJqhU.cjs} +2 -2
  6. package/dist/{batch-D5LlU4Q9.cjs.map → batch-DnYRJqhU.cjs.map} +1 -1
  7. package/dist/bus/bus.d.cts +355 -0
  8. package/dist/bus/bus.d.ts +86 -12
  9. package/dist/bus/links.d.cts +132 -0
  10. package/dist/bus/links.d.ts +18 -3
  11. package/dist/bus/validation.d.cts +16 -0
  12. package/dist/bus/validation.d.ts +10 -1
  13. package/dist/bus-B__467mL.cjs +2 -0
  14. package/dist/bus-B__467mL.cjs.map +1 -0
  15. package/dist/bus-dw7T92sO.js +788 -0
  16. package/dist/bus-dw7T92sO.js.map +1 -0
  17. package/dist/capture/console.d.cts +37 -0
  18. package/dist/capture/console.d.ts +1 -1
  19. package/dist/capture/errors.d.cts +32 -0
  20. package/dist/capture/errors.d.ts +1 -1
  21. package/dist/capture/interactions.d.cts +80 -0
  22. package/dist/capture/interactions.d.ts +36 -4
  23. package/dist/capture/lifecycle.d.cts +20 -0
  24. package/dist/capture/lifecycle.d.ts +1 -1
  25. package/dist/capture/long-frames.d.cts +31 -0
  26. package/dist/capture/long-frames.d.ts +1 -1
  27. package/dist/capture/network.d.cts +57 -0
  28. package/dist/capture/network.d.ts +1 -1
  29. package/dist/capture/observed-windows.d.cts +51 -0
  30. package/dist/capture/observed-windows.d.ts +51 -0
  31. package/dist/capture/profiler-frames.d.cts +44 -0
  32. package/dist/capture/profiler-frames.d.ts +1 -1
  33. package/dist/capture/replay-buffer.d.cts +45 -0
  34. package/dist/capture/replay-buffer.d.ts +9 -10
  35. package/dist/capture/replay-upload.d.cts +79 -0
  36. package/dist/capture/replay-upload.d.ts +7 -2
  37. package/dist/capture/replay.d.cts +114 -0
  38. package/dist/capture/replay.d.ts +1 -1
  39. package/dist/capture/reports.d.cts +17 -0
  40. package/dist/capture/reports.d.ts +1 -1
  41. package/dist/capture/resource-timing.d.cts +14 -0
  42. package/dist/capture/resource-timing.d.ts +1 -1
  43. package/dist/capture/server-timing.d.cts +19 -0
  44. package/dist/capture/storm.d.cts +13 -0
  45. package/dist/capture/storm.d.ts +5 -5
  46. package/dist/capture/types.d.cts +128 -0
  47. package/dist/capture/types.d.ts +10 -9
  48. package/dist/capture/unclean-exit.d.cts +31 -0
  49. package/dist/capture/unclean-exit.d.ts +1 -1
  50. package/dist/capture/user-timing.d.cts +22 -0
  51. package/dist/capture/user-timing.d.ts +2 -2
  52. package/dist/capture/web-socket.d.cts +40 -0
  53. package/dist/capture/web-socket.d.ts +3 -3
  54. package/dist/capture/web-vitals.d.cts +40 -0
  55. package/dist/capture/web-vitals.d.ts +1 -1
  56. package/dist/{compression-lD9abCcO.cjs → compression-C0hUHKR-.cjs} +2 -2
  57. package/dist/{compression-lD9abCcO.cjs.map → compression-C0hUHKR-.cjs.map} +1 -1
  58. package/dist/{compression-AJJCMBOa.js → compression-SHPAvS4U.js} +2 -2
  59. package/dist/{compression-AJJCMBOa.js.map → compression-SHPAvS4U.js.map} +1 -1
  60. package/dist/config-CSNcS7OZ.js +558 -0
  61. package/dist/config-CSNcS7OZ.js.map +1 -0
  62. package/dist/config-CybPP5VM.cjs +2 -0
  63. package/dist/config-CybPP5VM.cjs.map +1 -0
  64. package/dist/console-BsM-fSCQ.js +81 -0
  65. package/dist/console-BsM-fSCQ.js.map +1 -0
  66. package/dist/console-Dkxs6IVQ.cjs +2 -0
  67. package/dist/console-Dkxs6IVQ.cjs.map +1 -0
  68. package/dist/constants-BwJDXzj6.js +357 -0
  69. package/dist/constants-BwJDXzj6.js.map +1 -0
  70. package/dist/constants-CtF52hIV.cjs +2 -0
  71. package/dist/constants-CtF52hIV.cjs.map +1 -0
  72. package/dist/constants.d.cts +763 -0
  73. package/dist/constants.d.ts +100 -20
  74. package/dist/core/breadcrumbs.d.cts +54 -0
  75. package/dist/core/breadcrumbs.d.ts +5 -0
  76. package/dist/core/config.d.cts +45 -0
  77. package/dist/core/config.d.ts +30 -2
  78. package/dist/core/context.d.cts +24 -0
  79. package/dist/core/context.d.ts +3 -8
  80. package/dist/core/debug-buffer.d.cts +34 -0
  81. package/dist/core/debug-buffer.d.ts +3 -3
  82. package/dist/core/debug-bundle.d.cts +12 -0
  83. package/dist/core/debug-bundle.d.ts +3 -3
  84. package/dist/core/deferred.d.cts +7 -0
  85. package/dist/core/deferred.d.ts +2 -2
  86. package/dist/core/diagnostics.d.cts +86 -0
  87. package/dist/core/diagnostics.d.ts +1 -1
  88. package/dist/core/drops.d.cts +39 -0
  89. package/dist/core/drops.d.ts +16 -6
  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 +7 -7
  94. package/dist/core/logger.d.cts +141 -0
  95. package/dist/core/logger.d.ts +23 -30
  96. package/dist/core/measure.d.cts +30 -0
  97. package/dist/core/measure.d.ts +14 -3
  98. package/dist/core/meter.d.cts +78 -0
  99. package/dist/core/meter.d.ts +14 -8
  100. package/dist/core/pipeline.d.cts +227 -0
  101. package/dist/core/pipeline.d.ts +73 -10
  102. package/dist/core/profile-buckets.d.cts +31 -0
  103. package/dist/core/profiler.d.cts +218 -0
  104. package/dist/core/profiler.d.ts +2 -2
  105. package/dist/core/record.d.cts +190 -0
  106. package/dist/core/record.d.ts +44 -12
  107. package/dist/core/remote-rules.d.cts +17 -0
  108. package/dist/core/remote-rules.d.ts +3 -3
  109. package/dist/core/remote-sampling.d.cts +74 -0
  110. package/dist/core/remote-sampling.d.ts +3 -3
  111. package/dist/core/rotation.d.cts +99 -0
  112. package/dist/core/rotation.d.ts +99 -0
  113. package/dist/core/runtime.d.cts +774 -0
  114. package/dist/core/runtime.d.ts +254 -70
  115. package/dist/core/sampling.d.cts +86 -0
  116. package/dist/core/sampling.d.ts +5 -5
  117. package/dist/core/sender.d.cts +161 -0
  118. package/dist/core/sender.d.ts +59 -15
  119. package/dist/core/spans.d.cts +39 -0
  120. package/dist/core/spans.d.ts +1 -1
  121. package/dist/debug-bundle-B2v6Cym-.cjs +2 -0
  122. package/dist/debug-bundle-B2v6Cym-.cjs.map +1 -0
  123. package/dist/debug-bundle-Cs_YWzTa.js +35 -0
  124. package/dist/debug-bundle-Cs_YWzTa.js.map +1 -0
  125. package/dist/defineProperty-X1c4tIPD.cjs +1 -0
  126. package/dist/defineProperty-s2S8BXUc.js +35 -0
  127. package/dist/doctor.cjs +1 -1
  128. package/dist/doctor.cjs.map +1 -1
  129. package/dist/doctor.d.cts +36 -0
  130. package/dist/doctor.d.ts +5 -2
  131. package/dist/doctor.js +119 -87
  132. package/dist/doctor.js.map +1 -1
  133. package/dist/errors-DP2RUm4V.cjs +3 -0
  134. package/dist/errors-DP2RUm4V.cjs.map +1 -0
  135. package/dist/errors-Q3Ng1ciC.js +86 -0
  136. package/dist/errors-Q3Ng1ciC.js.map +1 -0
  137. package/dist/factory-DV17sm2p.js +404 -0
  138. package/dist/factory-DV17sm2p.js.map +1 -0
  139. package/dist/factory-K8O6gpux.cjs +2 -0
  140. package/dist/factory-K8O6gpux.cjs.map +1 -0
  141. package/dist/guards-BlYGRK4l.js +10 -0
  142. package/dist/guards-BlYGRK4l.js.map +1 -0
  143. package/dist/guards-EjG3ahFp.cjs +2 -0
  144. package/dist/guards-EjG3ahFp.cjs.map +1 -0
  145. package/dist/{identity-BrQp_5J5.js → identity-BgtHyY4u.js} +33 -26
  146. package/dist/identity-BgtHyY4u.js.map +1 -0
  147. package/dist/identity-CvuyqZk7.cjs +2 -0
  148. package/dist/identity-CvuyqZk7.cjs.map +1 -0
  149. package/dist/index.cjs +1 -1
  150. package/dist/index.cjs.map +1 -1
  151. package/dist/index.d.cts +301 -0
  152. package/dist/index.d.ts +90 -98
  153. package/dist/index.js +1253 -1555
  154. package/dist/index.js.map +1 -1
  155. package/dist/indexeddb-storage-D4KVcqdD.cjs +2 -0
  156. package/dist/indexeddb-storage-D4KVcqdD.cjs.map +1 -0
  157. package/dist/{indexeddb-storage-DLXQzAGh.js → indexeddb-storage-e-13ZLWm.js} +61 -57
  158. package/dist/indexeddb-storage-e-13ZLWm.js.map +1 -0
  159. package/dist/interactions-Byxf1C82.js +207 -0
  160. package/dist/interactions-Byxf1C82.js.map +1 -0
  161. package/dist/interactions-OK85T-Dk.cjs +2 -0
  162. package/dist/interactions-OK85T-Dk.cjs.map +1 -0
  163. package/dist/{journey-35yCMNFo.js → journey-C93FTYcs.js} +46 -49
  164. package/dist/journey-C93FTYcs.js.map +1 -0
  165. package/dist/journey-nMbob3OB.cjs +2 -0
  166. package/dist/journey-nMbob3OB.cjs.map +1 -0
  167. package/dist/{library-console-BFWEuQsl.cjs → library-console-DJUQzcgM.cjs} +2 -2
  168. package/dist/{library-console-BFWEuQsl.cjs.map → library-console-DJUQzcgM.cjs.map} +1 -1
  169. package/dist/{library-console-Dl_Ly6DQ.js → library-console-DklSmucS.js} +2 -2
  170. package/dist/{library-console-Dl_Ly6DQ.js.map → library-console-DklSmucS.js.map} +1 -1
  171. package/dist/{library-request-nI6pvI6I.js → library-request-UGEwOHpf.js} +2 -2
  172. package/dist/{library-request-nI6pvI6I.js.map → library-request-UGEwOHpf.js.map} +1 -1
  173. package/dist/{library-request-Da-CHKzT.cjs → library-request-kY9iTpIF.cjs} +2 -2
  174. package/dist/{library-request-Da-CHKzT.cjs.map → library-request-kY9iTpIF.cjs.map} +1 -1
  175. package/dist/{lifecycle-CZ6RRXc6.js → lifecycle-B2PlIuQu.js} +21 -29
  176. package/dist/lifecycle-B2PlIuQu.js.map +1 -0
  177. package/dist/lifecycle-DaMdH_X7.cjs +2 -0
  178. package/dist/lifecycle-DaMdH_X7.cjs.map +1 -0
  179. package/dist/log-record-Bmx6etMh.cjs +2 -0
  180. package/dist/log-record-Bmx6etMh.cjs.map +1 -0
  181. package/dist/{log-record-DIA6McNr.js → log-record-DSt2P-Sr.js} +8 -7
  182. package/dist/log-record-DSt2P-Sr.js.map +1 -0
  183. package/dist/{long-frames-430_85Da.js → long-frames-Bamjs1WV.js} +18 -22
  184. package/dist/long-frames-Bamjs1WV.js.map +1 -0
  185. package/dist/long-frames-lhtONgGt.cjs +2 -0
  186. package/dist/long-frames-lhtONgGt.cjs.map +1 -0
  187. package/dist/models/batch.d.cts +57 -0
  188. package/dist/models/batch.d.ts +2 -2
  189. package/dist/models/bus.d.cts +163 -0
  190. package/dist/models/bus.d.ts +28 -3
  191. package/dist/models/config.d.cts +1555 -0
  192. package/dist/models/config.d.ts +377 -261
  193. package/dist/models/drop.d.cts +54 -0
  194. package/dist/models/drop.d.ts +16 -3
  195. package/dist/models/health.d.cts +148 -0
  196. package/dist/models/health.d.ts +108 -12
  197. package/dist/models/log-record.d.cts +61 -0
  198. package/dist/models/metric.d.cts +139 -0
  199. package/dist/models/metric.d.ts +13 -2
  200. package/dist/models/plugin.d.cts +47 -0
  201. package/dist/models/plugin.d.ts +3 -3
  202. package/dist/models/replay.d.cts +60 -0
  203. package/dist/models/serializer.d.cts +25 -0
  204. package/dist/models/serializer.d.ts +4 -2
  205. package/dist/models/storage.d.cts +95 -0
  206. package/dist/models/storage.d.ts +7 -5
  207. package/dist/network-BCn8Gn47.cjs +2 -0
  208. package/dist/network-BCn8Gn47.cjs.map +1 -0
  209. package/dist/{network-C7SkLf4v.js → network-Cg1L2w2r.js} +57 -57
  210. package/dist/network-Cg1L2w2r.js.map +1 -0
  211. package/dist/observed-windows-B3gJkdql.cjs +2 -0
  212. package/dist/observed-windows-B3gJkdql.cjs.map +1 -0
  213. package/dist/observed-windows-BrwaJNlj.js +64 -0
  214. package/dist/observed-windows-BrwaJNlj.js.map +1 -0
  215. package/dist/{otlp-2MCrC3kd.cjs → otlp-CrAWkQdO.cjs} +2 -2
  216. package/dist/{otlp-2MCrC3kd.cjs.map → otlp-CrAWkQdO.cjs.map} +1 -1
  217. package/dist/{otlp-COq033e3.js → otlp-D6dRZyB8.js} +9 -9
  218. package/dist/{otlp-COq033e3.js.map → otlp-D6dRZyB8.js.map} +1 -1
  219. package/dist/{platform-CVewe4wQ.js → platform-8DLhjddo.js} +9 -9
  220. package/dist/{platform-CVewe4wQ.js.map → platform-8DLhjddo.js.map} +1 -1
  221. package/dist/{platform-12uR7kBQ.cjs → platform-BqRc-7RO.cjs} +2 -2
  222. package/dist/{platform-12uR7kBQ.cjs.map → platform-BqRc-7RO.cjs.map} +1 -1
  223. package/dist/{profiler-BVWIOgnq.js → profiler-BaXSqCfz.js} +78 -96
  224. package/dist/profiler-BaXSqCfz.js.map +1 -0
  225. package/dist/profiler-BvWW2kNM.cjs +2 -0
  226. package/dist/profiler-BvWW2kNM.cjs.map +1 -0
  227. package/dist/{profiler-frames-CLXlT_xL.js → profiler-frames-C4ySHN0X.js} +21 -29
  228. package/dist/profiler-frames-C4ySHN0X.js.map +1 -0
  229. package/dist/profiler-frames-DeaBiB-5.cjs +2 -0
  230. package/dist/profiler-frames-DeaBiB-5.cjs.map +1 -0
  231. package/dist/remote-rules-D7L6D_D2.cjs +2 -0
  232. package/dist/remote-rules-D7L6D_D2.cjs.map +1 -0
  233. package/dist/remote-rules-Dq9xe7Qn.js +95 -0
  234. package/dist/remote-rules-Dq9xe7Qn.js.map +1 -0
  235. package/dist/replay-B0M8kWz_.js +310 -0
  236. package/dist/replay-B0M8kWz_.js.map +1 -0
  237. package/dist/replay-QOFBpAXh.cjs +2 -0
  238. package/dist/replay-QOFBpAXh.cjs.map +1 -0
  239. package/dist/{reports-BuXekPOS.js → reports--8APRLa-.js} +25 -30
  240. package/dist/reports--8APRLa-.js.map +1 -0
  241. package/dist/reports-ojuMKGO7.cjs +2 -0
  242. package/dist/reports-ojuMKGO7.cjs.map +1 -0
  243. package/dist/{resource-timing-CXGHwFRD.js → resource-timing-BzR05rE-.js} +20 -23
  244. package/dist/resource-timing-BzR05rE-.js.map +1 -0
  245. package/dist/resource-timing-pAG3ZhB5.cjs +2 -0
  246. package/dist/resource-timing-pAG3ZhB5.cjs.map +1 -0
  247. package/dist/response-body-BWvwKQ2p.js +331 -0
  248. package/dist/response-body-BWvwKQ2p.js.map +1 -0
  249. package/dist/response-body-CKEJ5itk.cjs +3 -0
  250. package/dist/response-body-CKEJ5itk.cjs.map +1 -0
  251. package/dist/rotation-BylN1B9e.js +93 -0
  252. package/dist/rotation-BylN1B9e.js.map +1 -0
  253. package/dist/rotation-E2eKClIs.cjs +2 -0
  254. package/dist/rotation-E2eKClIs.cjs.map +1 -0
  255. package/dist/sampling-B46LW0cy.cjs +2 -0
  256. package/dist/sampling-B46LW0cy.cjs.map +1 -0
  257. package/dist/sampling-zXA6r-Nw.js +63 -0
  258. package/dist/sampling-zXA6r-Nw.js.map +1 -0
  259. package/dist/{sanitize-CNmsD9r3.js → sanitize-DjnR6RXR.js} +2 -2
  260. package/dist/sanitize-DjnR6RXR.js.map +1 -0
  261. package/dist/{sanitize-ChLn97Ch.cjs → sanitize-Qj6LuZqp.cjs} +2 -2
  262. package/dist/sanitize-Qj6LuZqp.cjs.map +1 -0
  263. package/dist/sender-Bdp-TAS4.js +979 -0
  264. package/dist/sender-Bdp-TAS4.js.map +1 -0
  265. package/dist/sender-DR7ZycZY.cjs +2 -0
  266. package/dist/sender-DR7ZycZY.cjs.map +1 -0
  267. package/dist/storage/context-storage.d.cts +90 -0
  268. package/dist/storage/context-storage.d.ts +5 -5
  269. package/dist/storage/emergency-queue.d.cts +27 -0
  270. package/dist/storage/emergency-queue.d.ts +4 -4
  271. package/dist/storage/eviction.d.cts +40 -0
  272. package/dist/storage/eviction.d.ts +1 -1
  273. package/dist/storage/factory.d.cts +21 -0
  274. package/dist/storage/factory.d.ts +3 -3
  275. package/dist/storage/gap.d.cts +20 -0
  276. package/dist/storage/gap.d.ts +3 -3
  277. package/dist/storage/idb-driver.d.cts +93 -0
  278. package/dist/storage/idb-driver.d.ts +1 -1
  279. package/dist/storage/indexeddb-storage.d.cts +97 -0
  280. package/dist/storage/indexeddb-storage.d.ts +12 -4
  281. package/dist/storage/keys.d.cts +17 -0
  282. package/dist/storage/keys.d.ts +2 -2
  283. package/dist/storage/local-storage.d.cts +139 -0
  284. package/dist/storage/local-storage.d.ts +11 -4
  285. package/dist/storage/memory-storage.d.cts +73 -0
  286. package/dist/storage/memory-storage.d.ts +4 -3
  287. package/dist/storage/persistence.d.cts +8 -0
  288. package/dist/storage/persistence.d.ts +2 -2
  289. package/dist/storage/stored-context.d.cts +34 -0
  290. package/dist/storage/stored-context.d.ts +34 -0
  291. package/dist/stored-context-BOu54M8Y.cjs +2 -0
  292. package/dist/stored-context-BOu54M8Y.cjs.map +1 -0
  293. package/dist/stored-context-CSttrAsw.js +51 -0
  294. package/dist/stored-context-CSttrAsw.js.map +1 -0
  295. package/dist/storm-BHgI12iS.cjs +2 -0
  296. package/dist/storm-BHgI12iS.cjs.map +1 -0
  297. package/dist/storm-DKlpv0FL.js +9 -0
  298. package/dist/storm-DKlpv0FL.js.map +1 -0
  299. package/dist/transport/compression.d.cts +7 -0
  300. package/dist/transport/custom-transport.d.cts +22 -0
  301. package/dist/transport/custom-transport.d.ts +6 -5
  302. package/dist/transport/errors.d.cts +31 -0
  303. package/dist/transport/exit-flush.d.cts +135 -0
  304. package/dist/transport/exit-flush.d.ts +30 -13
  305. package/dist/transport/headers.d.cts +8 -0
  306. package/dist/transport/headers.d.ts +2 -2
  307. package/dist/transport/http-transport.d.cts +116 -0
  308. package/dist/transport/http-transport.d.ts +20 -8
  309. package/dist/transport/memory-transport.d.cts +30 -0
  310. package/dist/transport/memory-transport.d.ts +2 -2
  311. package/dist/transport/response-body.d.cts +49 -0
  312. package/dist/transport/response-body.d.ts +49 -0
  313. package/dist/transport/retry-engine.d.cts +129 -0
  314. package/dist/transport/retry-engine.d.ts +27 -9
  315. package/dist/transport/serializers/ecs.d.cts +3 -0
  316. package/dist/transport/serializers/ecs.d.ts +1 -1
  317. package/dist/transport/serializers/otlp-metrics.d.cts +3 -0
  318. package/dist/transport/serializers/otlp-metrics.d.ts +1 -1
  319. package/dist/transport/serializers/otlp-traces.d.cts +3 -0
  320. package/dist/transport/serializers/otlp-traces.d.ts +1 -1
  321. package/dist/transport/serializers/otlp.d.cts +47 -0
  322. package/dist/transport/serializers/otlp.d.ts +2 -2
  323. package/dist/transport/serializers/select.d.cts +38 -0
  324. package/dist/transport/serializers/select.d.ts +5 -5
  325. package/dist/transport/status-transport.d.cts +129 -0
  326. package/dist/transport/status-transport.d.ts +25 -8
  327. package/dist/transport/worker-client.d.cts +23 -0
  328. package/dist/transport/worker-client.d.ts +12 -3
  329. package/dist/transport/worker-entry.d.cts +5 -0
  330. package/dist/transport/worker-entry.d.ts +1 -1
  331. package/dist/transport/worker-protocol.d.cts +38 -0
  332. package/dist/transport/worker-protocol.d.ts +4 -2
  333. package/dist/transport/worker-server.d.cts +3 -0
  334. package/dist/transport/worker-server.d.ts +1 -1
  335. package/dist/transport/worker-transport.d.cts +10 -0
  336. package/dist/transport/worker-transport.d.ts +5 -4
  337. package/dist/types-BAerHgCq.js.map +1 -1
  338. package/dist/types-C7WNpnG1.cjs.map +1 -1
  339. package/dist/unclean-exit-BYPYYkQ5.cjs +2 -0
  340. package/dist/unclean-exit-BYPYYkQ5.cjs.map +1 -0
  341. package/dist/{unclean-exit-Cob_jyTv.js → unclean-exit-BcOB8A2e.js} +23 -30
  342. package/dist/unclean-exit-BcOB8A2e.js.map +1 -0
  343. package/dist/{user-timing-DgHubxCI.js → user-timing-4KIJ74Vi.js} +15 -17
  344. package/dist/user-timing-4KIJ74Vi.js.map +1 -0
  345. package/dist/user-timing-BsU2wQKE.cjs +2 -0
  346. package/dist/user-timing-BsU2wQKE.cjs.map +1 -0
  347. package/dist/utils/console.d.cts +36 -0
  348. package/dist/utils/console.d.ts +4 -4
  349. package/dist/utils/deadline.d.cts +14 -0
  350. package/dist/utils/error-like.d.cts +25 -0
  351. package/dist/utils/fixed-window.d.cts +25 -0
  352. package/dist/utils/global-scope.d.cts +20 -0
  353. package/dist/utils/guards.d.cts +14 -0
  354. package/dist/utils/guards.d.ts +8 -0
  355. package/dist/utils/identity.d.cts +114 -0
  356. package/dist/utils/identity.d.ts +8 -4
  357. package/dist/utils/library-console.d.cts +11 -0
  358. package/dist/utils/library-request.d.cts +24 -0
  359. package/dist/utils/lock.d.cts +24 -0
  360. package/dist/utils/lock.d.ts +1 -1
  361. package/dist/utils/openfin.d.cts +48 -0
  362. package/dist/utils/patch.d.cts +9 -0
  363. package/dist/utils/platform.d.cts +62 -0
  364. package/dist/utils/platform.d.ts +2 -2
  365. package/dist/utils/sanitize.d.cts +52 -0
  366. package/dist/utils/sanitize.d.ts +1 -1
  367. package/dist/utils/sequence.d.cts +10 -0
  368. package/dist/utils/tracing.d.cts +158 -0
  369. package/dist/utils/tracing.d.ts +11 -4
  370. package/dist/utils/unref.d.cts +9 -0
  371. package/dist/web-socket-Cs1ZbmmN.cjs +2 -0
  372. package/dist/{web-socket-DthJuSAg.js.map → web-socket-Cs1ZbmmN.cjs.map} +1 -1
  373. package/dist/{web-socket-DthJuSAg.js → web-socket-Zg0hj1LB.js} +23 -28
  374. package/dist/web-socket-Zg0hj1LB.js.map +1 -0
  375. package/dist/{web-vitals-CsGCWnUr.js → web-vitals-4pWACwaR.js} +15 -21
  376. package/dist/web-vitals-4pWACwaR.js.map +1 -0
  377. package/dist/web-vitals-__X7t4pj.cjs +2 -0
  378. package/dist/web-vitals-__X7t4pj.cjs.map +1 -0
  379. package/dist/{worker-protocol-B0_8rWy5.js → worker-protocol-CYpAbrVl.js} +14 -11
  380. package/dist/worker-protocol-CYpAbrVl.js.map +1 -0
  381. package/dist/worker-protocol-DFYXIFus.cjs +2 -0
  382. package/dist/worker-protocol-DFYXIFus.cjs.map +1 -0
  383. package/dist/worker-server--yGTadTA.cjs +2 -0
  384. package/dist/worker-server--yGTadTA.cjs.map +1 -0
  385. package/dist/worker-server-BokySIII.js +94 -0
  386. package/dist/worker-server-BokySIII.js.map +1 -0
  387. package/dist/worker-transport-BdEvh_-a.cjs +2 -0
  388. package/dist/worker-transport-BdEvh_-a.cjs.map +1 -0
  389. package/dist/worker-transport-JK-Fby9J.js +194 -0
  390. package/dist/worker-transport-JK-Fby9J.js.map +1 -0
  391. package/llms.txt +400 -0
  392. package/package.json +65 -49
  393. package/dist/bus-D_7pd7RN.cjs +0 -2
  394. package/dist/bus-D_7pd7RN.cjs.map +0 -1
  395. package/dist/bus-ecxUNTja.js +0 -660
  396. package/dist/bus-ecxUNTja.js.map +0 -1
  397. package/dist/console-CLz_PvFn.cjs +0 -2
  398. package/dist/console-CLz_PvFn.cjs.map +0 -1
  399. package/dist/console-cwgHKXvM.js +0 -82
  400. package/dist/console-cwgHKXvM.js.map +0 -1
  401. package/dist/constants-Bwl_YtQi.js +0 -349
  402. package/dist/constants-Bwl_YtQi.js.map +0 -1
  403. package/dist/constants-DakMxVB2.cjs +0 -2
  404. package/dist/constants-DakMxVB2.cjs.map +0 -1
  405. package/dist/context-storage-BjzeBSxH.cjs +0 -2
  406. package/dist/context-storage-BjzeBSxH.cjs.map +0 -1
  407. package/dist/context-storage-BzkoHzkQ.js +0 -51
  408. package/dist/context-storage-BzkoHzkQ.js.map +0 -1
  409. package/dist/debug-bundle-BOdYmCeV.js +0 -32
  410. package/dist/debug-bundle-BOdYmCeV.js.map +0 -1
  411. package/dist/debug-bundle-Ex4L_LSP.cjs +0 -2
  412. package/dist/debug-bundle-Ex4L_LSP.cjs.map +0 -1
  413. package/dist/emergency-queue-B9WZxanZ.js +0 -67
  414. package/dist/emergency-queue-B9WZxanZ.js.map +0 -1
  415. package/dist/emergency-queue-HBpL5r3V.cjs +0 -2
  416. package/dist/emergency-queue-HBpL5r3V.cjs.map +0 -1
  417. package/dist/errors-D6bwgJtO.js +0 -92
  418. package/dist/errors-D6bwgJtO.js.map +0 -1
  419. package/dist/errors-DCOCRdSi.cjs +0 -3
  420. package/dist/errors-DCOCRdSi.cjs.map +0 -1
  421. package/dist/factory-DLFDjdLv.cjs +0 -2
  422. package/dist/factory-DLFDjdLv.cjs.map +0 -1
  423. package/dist/factory-e9Qo3K0z.js +0 -276
  424. package/dist/factory-e9Qo3K0z.js.map +0 -1
  425. package/dist/guards-Cidk71ME.js +0 -7
  426. package/dist/guards-Cidk71ME.js.map +0 -1
  427. package/dist/guards-nJ70syPt.cjs +0 -2
  428. package/dist/guards-nJ70syPt.cjs.map +0 -1
  429. package/dist/identity-BlvlgjrU.cjs +0 -2
  430. package/dist/identity-BlvlgjrU.cjs.map +0 -1
  431. package/dist/identity-BrQp_5J5.js.map +0 -1
  432. package/dist/indexeddb-storage-CtLvZH1r.cjs +0 -2
  433. package/dist/indexeddb-storage-CtLvZH1r.cjs.map +0 -1
  434. package/dist/indexeddb-storage-DLXQzAGh.js.map +0 -1
  435. package/dist/interactions-B6z2I4tU.js +0 -119
  436. package/dist/interactions-B6z2I4tU.js.map +0 -1
  437. package/dist/interactions-P6pz08Jn.cjs +0 -2
  438. package/dist/interactions-P6pz08Jn.cjs.map +0 -1
  439. package/dist/journey-35yCMNFo.js.map +0 -1
  440. package/dist/journey-DAGh5h9k.cjs +0 -2
  441. package/dist/journey-DAGh5h9k.cjs.map +0 -1
  442. package/dist/keys-BHhw_0Wh.cjs +0 -2
  443. package/dist/keys-BHhw_0Wh.cjs.map +0 -1
  444. package/dist/keys-BU9j5YqW.js +0 -16
  445. package/dist/keys-BU9j5YqW.js.map +0 -1
  446. package/dist/lifecycle-BGGOcN4N.cjs +0 -2
  447. package/dist/lifecycle-BGGOcN4N.cjs.map +0 -1
  448. package/dist/lifecycle-CZ6RRXc6.js.map +0 -1
  449. package/dist/log-record-D7bA1RPb.cjs +0 -2
  450. package/dist/log-record-D7bA1RPb.cjs.map +0 -1
  451. package/dist/log-record-DIA6McNr.js.map +0 -1
  452. package/dist/long-frames-430_85Da.js.map +0 -1
  453. package/dist/long-frames-Dd8tsi2U.cjs +0 -2
  454. package/dist/long-frames-Dd8tsi2U.cjs.map +0 -1
  455. package/dist/models/stats.d.ts +0 -11
  456. package/dist/network-C7SkLf4v.js.map +0 -1
  457. package/dist/network-pEX3PAJv.cjs +0 -2
  458. package/dist/network-pEX3PAJv.cjs.map +0 -1
  459. package/dist/profiler-BVWIOgnq.js.map +0 -1
  460. package/dist/profiler-eVCknCzS.cjs +0 -2
  461. package/dist/profiler-eVCknCzS.cjs.map +0 -1
  462. package/dist/profiler-frames-CLXlT_xL.js.map +0 -1
  463. package/dist/profiler-frames-Dg2OebB2.cjs +0 -2
  464. package/dist/profiler-frames-Dg2OebB2.cjs.map +0 -1
  465. package/dist/remote-rules-BJGDJGwA.js +0 -98
  466. package/dist/remote-rules-BJGDJGwA.js.map +0 -1
  467. package/dist/remote-rules-CJD3ToVk.cjs +0 -2
  468. package/dist/remote-rules-CJD3ToVk.cjs.map +0 -1
  469. package/dist/replay-0zAJv9T3.js +0 -338
  470. package/dist/replay-0zAJv9T3.js.map +0 -1
  471. package/dist/replay-DomJpXqW.cjs +0 -2
  472. package/dist/replay-DomJpXqW.cjs.map +0 -1
  473. package/dist/reports-BsbqmP8h.cjs +0 -2
  474. package/dist/reports-BsbqmP8h.cjs.map +0 -1
  475. package/dist/reports-BuXekPOS.js.map +0 -1
  476. package/dist/resource-timing-CXGHwFRD.js.map +0 -1
  477. package/dist/resource-timing-DkycFGDa.cjs +0 -2
  478. package/dist/resource-timing-DkycFGDa.cjs.map +0 -1
  479. package/dist/sampling-Dd0wllyq.cjs +0 -2
  480. package/dist/sampling-Dd0wllyq.cjs.map +0 -1
  481. package/dist/sampling-UUDbi3K0.js +0 -60
  482. package/dist/sampling-UUDbi3K0.js.map +0 -1
  483. package/dist/sanitize-CNmsD9r3.js.map +0 -1
  484. package/dist/sanitize-ChLn97Ch.cjs.map +0 -1
  485. package/dist/select-CTk-K5mG.cjs +0 -3
  486. package/dist/select-CTk-K5mG.cjs.map +0 -1
  487. package/dist/select-DPv_j6wq.js +0 -270
  488. package/dist/select-DPv_j6wq.js.map +0 -1
  489. package/dist/sender-15zEsZpr.js +0 -857
  490. package/dist/sender-15zEsZpr.js.map +0 -1
  491. package/dist/sender-Bfpv9tad.cjs +0 -2
  492. package/dist/sender-Bfpv9tad.cjs.map +0 -1
  493. package/dist/storage-BA9RqRO-.cjs +0 -2
  494. package/dist/storage-BA9RqRO-.cjs.map +0 -1
  495. package/dist/storage-DZwed89z.js +0 -16
  496. package/dist/storage-DZwed89z.js.map +0 -1
  497. package/dist/storm-BTSNTIWI.js +0 -9
  498. package/dist/storm-BTSNTIWI.js.map +0 -1
  499. package/dist/storm-D0_qZOEg.cjs +0 -2
  500. package/dist/storm-D0_qZOEg.cjs.map +0 -1
  501. package/dist/unclean-exit-ClGzrc2A.cjs +0 -2
  502. package/dist/unclean-exit-ClGzrc2A.cjs.map +0 -1
  503. package/dist/unclean-exit-Cob_jyTv.js.map +0 -1
  504. package/dist/user-timing-CdYqx3PF.cjs +0 -2
  505. package/dist/user-timing-CdYqx3PF.cjs.map +0 -1
  506. package/dist/user-timing-DgHubxCI.js.map +0 -1
  507. package/dist/utils/timer.d.ts +0 -19
  508. package/dist/web-socket-BTuvYoJI.cjs +0 -2
  509. package/dist/web-socket-BTuvYoJI.cjs.map +0 -1
  510. package/dist/web-vitals-Ch5BpDmo.cjs +0 -2
  511. package/dist/web-vitals-Ch5BpDmo.cjs.map +0 -1
  512. package/dist/web-vitals-CsGCWnUr.js.map +0 -1
  513. package/dist/worker-protocol-B0_8rWy5.js.map +0 -1
  514. package/dist/worker-protocol-BjzFORfq.cjs +0 -2
  515. package/dist/worker-protocol-BjzFORfq.cjs.map +0 -1
  516. package/dist/worker-server-4en-Lt-3.cjs +0 -2
  517. package/dist/worker-server-4en-Lt-3.cjs.map +0 -1
  518. package/dist/worker-server-Cne9MX9I.js +0 -83
  519. package/dist/worker-server-Cne9MX9I.js.map +0 -1
  520. package/dist/worker-transport-B-GF4Aqn.cjs +0 -2
  521. package/dist/worker-transport-B-GF4Aqn.cjs.map +0 -1
  522. package/dist/worker-transport-C3SjJAEC.js +0 -200
  523. package/dist/worker-transport-C3SjJAEC.js.map +0 -1
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # @utk09/ui-observability
2
2
 
3
- Structured logging and UI observability for browsers, embedded webviews and OpenFin containers. The library imports no framework.
3
+ Structured logging and UI observability for browsers, embedded webviews and OpenFin containers. The library imports no framework. OpenFin support is not validated on a real OpenFin runtime.
4
4
 
5
5
  The library batches records and sends them over HTTP as OTLP/JSON. It stores a batch that fails to send, and sends it again later. When the page closes, the library sends the records that are left. Iframes, workers and OpenFin windows share one sender through the bus. A log call never throws.
6
6
 
7
- > **Status: early development.** A minor release can change a public API. Pin the exact version.
7
+ > **Status: stable from 1.0.0.** A minor release or a patch release does not make a breaking change. The [release contract](docs/release-and-support.md) states what a breaking change is. To upgrade from 0.12.x, read the [migration guide](docs/migration-v1.md).
8
8
 
9
9
  ---
10
10
 
@@ -23,23 +23,15 @@ pnpm add --save-exact @utk09/ui-observability
23
23
  yarn add --exact @utk09/ui-observability
24
24
  ```
25
25
 
26
+ The package has an ES module entry and a CommonJS entry. Each entry has its own type declarations. The types work with `moduleResolution` set to `NodeNext` or `Bundler`. They also work with `skipLibCheck: false`. Use one module format in one application. The two entries are separate copies with separate state and separate types.
27
+
26
28
  ### Peer Dependencies
27
29
 
28
30
  Each peer is optional. The library has no runtime dependency.
29
31
 
30
- Install `@rrweb/record` (`^2`) for the session replay, and set `replay.loader`. See [Session replay](#session-replay).
31
-
32
- Install `web-vitals` (`^4 || ^5 || ^6`) for `capture.webVitals`, and set `capture.webVitalsLoader`. Without the loader, the library reports `config.invalid`:
32
+ Install `@rrweb/record` (`^2`) for the session replay, and set `replay.loader`. See [Session replay](docs/api.md#session-replay).
33
33
 
34
- ```ts
35
- configure({
36
- endpoint: "https://telemetry.example.com/v1/logs",
37
- capture: {
38
- webVitals: true,
39
- webVitalsLoader: () => import("web-vitals"),
40
- },
41
- });
42
- ```
34
+ Install `web-vitals` (`^4 || ^5 || ^6`) for `capture.webVitals`, and set `capture.webVitals.loader`. The object turns the capture on. Without the loader, the library reports `config.invalid`. LCP, CLS, INP, FCP and TTFB then stay off, and the navigation timing continues.
43
35
 
44
36
  Install `@opentelemetry/api` (`^1`) to put records on the traces of your spans. Set `otelLoader` to load it. Without `otelLoader`, OTel is off. The library then makes its own `trace_id`.
45
37
 
@@ -48,7 +40,11 @@ The library never imports a peer by name. A missing peer cannot break your bundl
48
40
  ```ts
49
41
  configure({
50
42
  endpoint: "https://telemetry.example.com/v1/logs",
43
+ serviceName: "equities-blotter",
51
44
  otelLoader: () => import("@opentelemetry/api"),
45
+ capture: {
46
+ webVitals: { loader: () => import("web-vitals") },
47
+ },
52
48
  });
53
49
  ```
54
50
 
@@ -75,13 +71,19 @@ log.logAction("ORDER_SUBMIT", { orderId: "ORD-1001", qty: 100 });
75
71
  log.error("pricing call failed", caughtError);
76
72
  ```
77
73
 
78
- - `configure()` is idempotent. A later call updates an unlocked runtime singleton in place. Delivery/identity changes require `rotateSecurityContext()` by default. You cannot change `storage`, `identity`, `batching`, `retention`, `limits`, `journey.maxAgeMs` or `profiler.maxProbes` after startup. The library reports that change and ignores it.
79
- - Call `configure()` from one context in each document. A second call changes `service.name` on the records of every other context. In a composed page, the shell calls `configure()`. Each microfrontend uses its own namespace.
74
+ - Nothing starts before the first `configure()` call that works. Before it, a log call does not throw. The record waits in memory. The library sends nothing and writes nothing to storage.
75
+ - An app that never calls `configure()` sends nothing. The console output is off by default, so it prints nothing.
76
+ - Call `configure()` from one context in each document. In a composed page, the shell calls `configure()`. Each microfrontend uses its own namespace. A second call changes `service.name` on the records of every other context.
80
77
  - You can call `getLogger()` at module top level, before `configure()`. The logger finds the runtime on its first write.
81
- - A write before the first `configure()` starts a runtime with default settings. It does not throw. The first `configure()` then sets `limits`, `journey.maxAgeMs`, `profiler.maxProbes`, `persistence.namespace` and an explicit `securityContext.id` of that runtime.
82
- - After `shutdown()`, logging does nothing until the next `configure()`; health/stats remain inspectable.
78
+ - A repeated `configure()` call with the same values and the same function references changes no setting. A later call updates an unlocked runtime in place. Some settings are fixed after startup. Use `rotateSecurityContext()` to change the delivery identity or the routing settings.
79
+ - `enabled: false` pauses the library. It does not stop it. `shutdown()` stops it. After `shutdown()`, logging does nothing until the next `configure()`.
80
+ - [Initialization order](docs/production-recipes.md#initialization-order) gives each rule of the startup. [Settings that are fixed after startup](docs/production-recipes.md#settings-that-are-fixed-after-startup) gives the rule for each key.
83
81
 
84
- ### Console Only (No Network)
82
+ ---
83
+
84
+ ## Recipes
85
+
86
+ ### Console only
85
87
 
86
88
  Set `endpoint: null`. The library sends nothing. It prints records to the console only.
87
89
 
@@ -90,61 +92,15 @@ configure({
90
92
  endpoint: null,
91
93
  serviceName: "skardela",
92
94
  identity: "memory",
93
- storage: "none",
95
+ storage: { backend: "none" },
94
96
  bus: { mode: "off" },
95
- console: import.meta.env.DEV ? "DEBUG" : "WARN",
96
- });
97
- ```
98
-
99
- - `endpoint: null` loads no transport, no storage and no exit flush. It reports no diagnostic.
100
- - `identity: "memory"` writes no key to `localStorage` or `sessionStorage`.
101
- - `console` and `minLevel` are independent. `console` sets what the library prints. `minLevel` sets what the library sends.
102
- - The console output does not depend on the bus or the endpoint.
103
- - With a `redact` hook, the console shows only what `redact` returns. A record that a processor or `redact` drops prints no line. With `redact` or `processors`, a record below `minLevel` or outside the sample also goes through them before the console prints it. Without hooks, such a record shows its message, payload and error as given.
104
-
105
- ### Console Output
106
-
107
- Each console line has the form `[namespace][LEVEL] message payload`:
108
-
109
- ```text
110
- [app.puzzle-page][INFO] The puzzle page loaded {puzzleId: 'colour-binary-0006', difficulty: 'easy'}
111
- ```
112
-
113
- The namespace and the level each have a color. To change the colors, use the object form of `console`:
114
-
115
- ```ts
116
- configure({
117
- console: {
118
- level: "DEBUG",
119
- styles: {
120
- namespace: "color:#888",
121
- INFO: "color:#0a7;font-weight:bold",
122
- WARN: "color:#c80;font-weight:bold",
123
- },
124
- },
97
+ consoleOutput: import.meta.env.DEV ? "DEBUG" : "WARN",
125
98
  });
126
99
  ```
127
100
 
128
- - Each style is a CSS string. A browser applies it with `%c`. Node prints the text without the style.
129
- - A style can set the text color and the background together. This example shows the level as a badge:
130
-
131
- ```ts
132
- configure({
133
- console: {
134
- styles: {
135
- INFO: "color:#fff;background:#1e6fd9;padding:0 4px;border-radius:3px",
136
- ERROR: "color:#fff;background:#d32f2f;padding:0 4px;border-radius:3px",
137
- },
138
- },
139
- });
140
- ```
141
-
142
- - The style keys are `namespace`, `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR` and `FATAL`. A key that you do not set keeps its style.
143
- - The default namespace color is gray. The default levels are gray for `TRACE` and `DEBUG`, blue for `INFO`, orange for `WARN`, and red for `ERROR` and `FATAL`.
144
- - A later `configure({ console: "WARN" })` changes the level. The styles stay.
145
- - A later `configure({ console: { styles } })` changes the styles. The level stays.
101
+ [Console Only](docs/guides.md#console-only-no-network) gives the rules of this mode. [Console Output](docs/guides.md#console-output) gives the line format and the colors.
146
102
 
147
- ### Custom Transport
103
+ ### Custom transport
148
104
 
149
105
  Set `transport` to send batches through a channel of your app, for example an API client with token refresh, a WebSocket, Electron IPC or an OpenFin channel. With `transport`, `endpoint` is optional.
150
106
 
@@ -165,803 +121,78 @@ configure({
165
121
  });
166
122
  ```
167
123
 
168
- - The library keeps batching, retry, storage, splitting and the exit flush.
169
- - The status code that you return has the meaning of the ingest contract. `2xx` accepts the batch. `413` splits it. `429` and `503` throttle. `408` and `5xx` retry. Each other code drops the batch.
170
- - A rejected promise counts as a network error. The library sends the batch again later. A call that does not settle in 15 seconds counts as a timeout.
171
- - The library does not compress `request.body`. Compress it in your transport if necessary.
172
- - `request.records` holds the built records after `redact`. Do not change them, because the retry engine can send them again.
173
- - `request.kind` is `"metrics"` for a batch of metric records when `metricsEndpoint` is set. `request.body` is then an OTLP `ExportMetricsServiceRequest`. Send it to your metrics endpoint.
174
- - `request.kind` is `"traces"` for a batch of span records. `request.body` is then an OTLP `ExportTraceServiceRequest`. Send it to your traces endpoint. Each other batch has the kind `"logs"`.
175
- - Without `transportOnExit`, the last batch goes to the emergency queue when the page closes. The next page load sends it.
176
- - With `storage: "none"`, the next page load cannot keep that batch. Set `transportOnExit`, or the library loses the last batch.
177
- - The library ignores a `retryAfterMs` or a `maxBytes` that is not a finite number. It uses 0 for a negative value.
178
- - `request.signal` aborts at `shutdown()` and at a rotation. Check it to cancel your work. A stored batch of that request stays in storage.
179
- - Return the `Date` header of a `2xx` answer in `date`. The library then computes `uiobs.clock_offset_ms`.
180
- - After the delivery stack loads, you cannot add or remove `transport`. You can replace it with another function.
181
- - Network capture skips a request that your transport starts before its first `await`. Put your telemetry URL in `capture.ignoreUrls` too. A request after an `await` is outside that scope.
182
- - Without that URL in `capture.ignoreUrls`, each send records a value of the `http.client.request.duration` histogram. That value causes the next send, and the sends do not stop. Network capture reports `capture.transport_request` one time when it sees a request during a transport call.
183
-
184
- ### Worker transport
185
-
186
- The app creates a dedicated module worker. Configure its factory at startup.
187
-
188
- ```ts
189
- configure({
190
- endpoint: "https://ingest.example/v1/logs",
191
- serviceName: "orders",
192
- transportWorker: () =>
193
- new Worker(new URL("./transport.worker.ts", import.meta.url), { type: "module" }),
194
- });
195
- ```
196
-
197
- In `transport.worker.ts`:
198
-
199
- ```ts
200
- import { serveTransportWorker } from "@utk09/ui-observability";
201
-
202
- serveTransportWorker();
203
- ```
204
-
205
- The worker encodes OTLP or ECS, compresses the payload and sends HTTP requests. Record construction, privacy hooks, queue accounting, retry and storage stay on the main thread. The `headers` function also stays there. The worker receives only its resolved headers and built records after the privacy hooks.
206
-
207
- - Return a fresh worker from each factory call. The library owns that worker until shutdown or rotation.
208
- - Bundle and serve the worker script with the app. Its worker policy and CORS rules must permit the script and the ingest endpoint.
209
- - Use the same exact library version in the worker and the page. A private transferred port carries a fixed protocol tag and that version.
210
- - `serveTransportWorker()` installs its connection listener at once. It loads the worker delivery code after the connection. Its return value stops the service. Its optional `onDiagnostic` handler runs in the worker.
211
- - One request deadline covers header resolution, transfer, encoding, compression and delivery. The main thread handles status codes, sampling rules and clock offset.
212
- - A startup failure or a channel failure during a send switches that sender to HTTP. A worker that does not connect before the request deadline is a startup failure. A new factory or a rotation permits another worker. A timeout or network failure follows the normal retry policy.
213
- - Hidden-page sends use the main HTTP keepalive path. The exit flush also stays on the main thread. It uses the same cached headers.
214
- - `transport` takes precedence over `transportWorker`. A custom serializer runs on the main thread. Functions do not cross the worker channel.
215
- - With isolation on, change the factory through `rotateSecurityContext()`. After the stack loads, `configure()` cannot add or remove `transportWorker`.
216
- - The helper does not join the context bus. Node remains console-only.
217
-
218
- The vanilla playground has links for the worker and main-thread paths. Verify both paths in a real browser before release.
219
-
220
- ### Testing
221
-
222
- Use `createMemoryTransport()` to check what your code logs. It needs no network and no `fetch` mock.
223
-
224
- ```ts
225
- import {
226
- configure,
227
- createMemoryTransport,
228
- flush,
229
- getLogger,
230
- shutdown,
231
- } from "@utk09/ui-observability";
232
-
233
- const memory = createMemoryTransport();
234
-
235
- beforeEach(() => {
236
- configure({
237
- serviceName: "orders",
238
- transport: memory.transport,
239
- storage: "none",
240
- bus: { mode: "off" },
241
- identity: "memory",
242
- });
243
- });
244
-
245
- afterEach(async () => {
246
- memory.clear();
247
- await shutdown();
248
- });
249
-
250
- it("logs the order submit", async () => {
251
- getLogger("orders.ticket").logAction("ORDER_SUBMIT", { orderId: "ORD-1" });
252
- await flush();
253
-
254
- expect(memory.records()).toContainEqual(expect.objectContaining({ body: "ORDER_SUBMIT" }));
255
- });
256
- ```
257
-
258
- - `records()` returns the records of each accepted batch. `batches()` returns each request, accepted or refused.
259
- - `respondWith(status, retryAfterMs?)` sets the answer for each later batch. Use it to test a `413`, `429` or `500` answer. The default answer is `200`.
260
- - `flush()` waits for startup. A record that you log directly after `configure()` is in the flushed batch.
261
- - After `shutdown()`, each call does nothing until the next `configure()`.
262
- - Set `storage: "none"` in tests. Without it, `shutdown()` stores the unsent records, and the next test can receive them.
263
-
264
- ---
265
-
266
- ### Remote Sampling
267
-
268
- With `sampling: { remote: true }`, the ingest server can change the sampling during an incident. You do not deploy the app again.
269
-
270
- ```http
271
- X-UiObs-Sampling: {"v":1,"ttlMs":600000,"defaultRate":0.1,"rates":{"blotter.grid":1},"minLevel":"DEBUG"}
272
- ```
273
-
274
- - The library reads the header only on a `2xx` answer to a batch that it sent. A custom transport returns the rules in `TransportResponse.sampling`, as text or as an object.
275
- - `v` must be `1`. `ttlMs` is mandatory, from more than 0 to 3,600,000 (1 hour). After the TTL, the rules from `configure()` apply again.
276
- - `rates` apply over the `configure()` rates. The other `configure()` rates stay. `defaultRate` applies only if the header has it.
277
- - `minLevel` can only lower the level that the library sends. It does not change the console level.
278
- - `minLevels` sets a level for each namespace prefix, for example `{"trading.ticks":"DEBUG"}`. A remote prefix wins over the remote `minLevel`. A remote level applies only when it is lower than the `configure()` level of the namespace. At most 100 prefixes.
279
- - `sampling.remoteMaxRate` caps each remote rate. It also caps the records that a remote `minLevel` adds. Set it below 1 to limit the traffic that a compromised server can cause.
280
- - The library rejects all the rules if one field is not valid, for example a rate outside 0 to 1, more than 100 `rates` or a header longer than 4096 characters. It reports `config.invalid`.
281
- - The library keeps the rules in memory only. A reload uses the `configure()` rules until the next accepted batch.
282
- - A child frame, a worker or an OpenFin view asks its owner for the rules at start and each 30 seconds. Set `sampling.remote: true` in each context.
283
- - A frame accepts rules from a parent only if the parent origin is the page origin or is in `bus.trustedOrigins`. A page that embeds your app cannot lower `minLevel`.
284
- - Under the default `bus.sourcePolicy: "registered"`, a parent sends rules only to a frame or a worker that it registered with the `sampling:read` permission.
285
- - Each OpenFin view of one app can read the bus messages of the others. Load only trusted content into a view that has the `fin` API.
286
-
287
- ## API Reference
288
-
289
- ### Lifecycle & Setup
290
-
291
- | Function | Description |
292
- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
293
- | `configure(config)` | Starts the runtime singleton, or updates it. |
294
- | `shutdown()` | Sends pending records and stops every subsystem. It cancels a request that is still open after the final flush. Later calls do nothing until the next `configure()`. |
295
- | `rotateSecurityContext(update, options?)` | Changes the delivery identity and the delivery settings together. Use it at logout or a tenant change. See [runtime policies](docs/runtime-policies.md#security-context-rotation). |
296
- | `setConfigurationLocked(locked)` | Locks or unlocks changes through `configure()`. |
297
-
298
- ### Logging Methods
299
-
300
- | Function | Description |
301
- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
302
- | `getLogger(namespace, options?)` | Returns the cached logger for a namespace. With `options`, it returns a new logger that is not cached. |
303
- | `trace(msg, payload?)` | Logs a TRACE record. |
304
- | `debug(msg, payload?)` | Logs a DEBUG record. |
305
- | `info(msg, payload?)` | Logs an INFO record. |
306
- | `warn(msg, payload?)` | Logs a WARN record. |
307
- | `error(msg, err?, payload?)` | Logs an ERROR record with the error and the breadcrumb trail. |
308
- | `fatal(msg, err?, payload?)` | Logs a FATAL record with the error and the breadcrumb trail. |
309
- | `logAction(name, payload?)` | Logs one user action. |
310
- | `logEvent(name, payload?)` | Logs one domain or lifecycle event. |
311
- | `logMetric(name, value, unit?, type?, attrs?)` | Logs a measurement (`gauge`, `counter`, `histogram`). |
312
- | `counter(name, { unit? })` | Gives a counter. `add(value, attrs?)` sums a value of 0 or larger in memory. The library sends one point for each attribute set at each interval. |
313
- | `histogram(name, { unit?, boundaries? })` | Gives a histogram. `record(value, attrs?)` counts a value in buckets in memory. The library sends one point for each attribute set at each interval. |
314
- | `timeSync(label, fn, attrs?)` | Times a function and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
315
- | `timeAsync(label, fn, attrs?)` | Times a promise and emits a duration histogram with `status` `SUCCESS` or `FAILURE`. |
316
- | `startMeasure(name, attrs?)` | Times an operation with named phases. See [Measures](#measures). |
317
- | `profiler.probe(name, options?)` | Gives a probe that times code spans with a small fixed cost. See [Profiler](#profiler). |
318
- | `profiler.time(name, fn)` | Calls `fn` and times the call with the probe of the name. A promise result ends the span when it settles. See [Profiler](#profiler). |
319
- | `startReplay()` | Starts the session replay recorder. With `replay.requireConsent`, nothing records before this call. See [Session replay](#session-replay). |
320
- | `stopReplay()` | Stops the session replay recorder and drops each replay event that is not sent. |
321
-
322
- The level methods give records with `log.type: "log"`. Records of the library itself have `log.type: "system"`. `logMetric` drops a value that is not finite and counts `record.dropped_malformed`.
323
-
324
- `counter` and `histogram` sum their values for `batching.metricFlushIntervalMs`. Then they send one point for each attribute set. 1000 calls of `add(1)` give one point with the value 1000. Sampling and `minLevel` do not drop a point. The console does not print it. Each instrument keeps at most 100 attribute sets in each interval. The values of more sets go to one set with `otel.metric.overflow: true`. Attribute values must be strings, finite numbers or booleans. The library drops an attribute key that starts with `metric.`. It also drops the keys that it sets on each record, for example `page.url` and `log.type`. The record limits do not cut the metric fields of a point, for example the bucket counts. `redact` cannot change them. Do not use a user id or a URL as an attribute. Each value makes a new series in the backend. The default histogram boundaries are `[0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000]`. The points of the open interval go out at `flush()`, at `shutdown()` and before the exit flush. A frame that forwards its records sends its points at the interval, at `flush()` and at `shutdown()` only.
325
-
326
- ### Measures
327
-
328
- `startMeasure()` times an operation with named phases.
329
-
330
- ```ts
331
- const measure = startMeasure("checkout", { tier: "gold" });
332
- measure.phase("validate");
333
- await validate();
334
- measure.phase("payment");
335
- await pay();
336
- measure.end();
337
- ```
338
-
339
- - `phase(name)` closes the open phase and starts the next phase. `end(outcome?)` closes the open phase and records the total. Later calls of the handle do nothing.
340
- - Each phase goes into the histogram `ui.measure.phase.duration` with `measure.name` and `measure.phase`. The total goes into `ui.measure.duration` with `measure.name` and `measure.outcome`. Both are in milliseconds.
341
- - The default outcome is `"ok"`. Each name, outcome and attribute set makes one series. Keep these values small in number.
342
- - With `tracesEndpoint`, the measure is a span of kind INTERNAL with one child span for each phase. The outcome `"error"` marks the measure span and its open phase as failed.
343
- - A shutdown drops a measure that has no end. With isolation, a new delivery identity also drops it.
344
-
345
- ### Profiler
346
-
347
- `profiler.probe()` gives a probe that times a span that runs very often, for example a grid transaction, a sort or a render. `startMeasure()` makes a handle for each operation. A probe is one handle for all spans of its name. The profiler code makes no object for a `begin()` and `end()` pair, except one timer at the first value of each interval. The clock read of the platform can make one, for example in Node.js. The library sends one summary record for each probe at each interval, not one record for each span.
348
-
349
- ```ts
350
- configure({ profiler: { enabled: true } });
351
-
352
- const probe = profiler.probe("grid.applyTransaction");
353
-
354
- const token = probe.begin();
355
- grid.applyTransaction(update);
356
- probe.end(token);
357
-
358
- // Add a duration from another source, in milliseconds.
359
- probe.record(durationMs);
360
-
361
- // Measure one span of each 10 spans.
362
- const sort = profiler.probe("grid.sort", { sampleEvery: 10 });
363
-
364
- // End the span after the next paint. A span longer than 16 ms adds a breadcrumb.
365
- const render = profiler.probe("grid.render", { slowMs: 16 });
366
- const renderToken = render.begin();
367
- grid.render();
368
- render.endAfterPaint(renderToken);
369
-
370
- // Time one call of a function. A promise result ends the span when it settles.
371
- const rows = await profiler.time("rows.fetch", () => fetchRows());
372
-
373
- // A span that an await splits needs an async probe.
374
- const load = profiler.probe("blotter.load", { async: true });
375
- ```
376
-
377
- - The profiler is off by default. While it is off, `begin()` returns `-1`. A probe then reads no clock.
378
- - A probe stays valid across `configure()` and `shutdown()`. An app can make a probe before `configure()`. The same name gives the same probe. The first options of a name stay. A call never throws.
379
- - A probe sums its durations for `profiler.flushIntervalMs`. The default is 10 seconds. Then the library sends one `ui.profile.duration` histogram record for each probe with data. `flush()`, `shutdown()`, `newSession()` and the exit flush also send the open interval.
380
- - A record has the count, the sum, the minimum, the maximum and the buckets. Its attributes are `profile.probe`, `profile.sample_every`, `profile.p50`, `profile.p90`, `profile.p99`, `profile.self_p99` and `profile.overhead_ns`. See [Profile Attributes](docs/attributes.md#profile-attributes).
381
- - The library counts each duration in a bucket, in whole microseconds. Each power of two has 16 buckets. Below 16 microseconds, a bucket is 1 microsecond wide. Above that, a bucket is at most 6.25 percent wide. The minimum and the maximum are exact. A duration above approximately 67 seconds counts in the last bucket. A record has at most 100 buckets. For a wider range of durations, the library merges adjacent buckets in the record.
382
- - `sampleEvery: n` measures one span of each `n` spans. The probe uses a counter, not a random number. A span that the probe does not measure reads no clock. Its `begin()` returns `-1`. `record()` uses the same counter. The count in the record is the count of measured spans. A backend multiplies it by `profile.sample_every` for an estimate of all spans.
383
- - A record of a probe with nested spans also has `profile.self_p99`. The self time of a span is its duration without the durations of the measured spans inside it. The library keeps the open spans on a stack of 32 levels. A span gets a self time when its `begin()` and `end()` run in nested order.
384
- - A span with no `end()` call loses its stack level when a span around it ends, or when the stack is full. A span at level 33 clears the stack. The spans below it keep their durations and get no self time.
385
- - `async: true` is for a probe with a span that an `await` splits. Its spans are not on the stack. They give the total time only. They take no time from the self time of another span. Without the option, the spans of other tasks count as spans inside the open span.
386
- - `profiler.time(name, fn)` calls `fn` and times the call with the probe of the name. An error of `fn` goes to the caller. For a result with a `then` function, the span ends when the result settles. `time()` then returns the result of that `then` call, not the result of `fn`.
387
- - `endAfterPaint(token)` ends the span in the first task after the next paint. The duration then includes the style, the layout and the paint of the browser. In a hidden page, or in a context with no `requestAnimationFrame`, it ends the span at once. A page that becomes hidden ends each span that waits. The span has no self time. `endAfterPaint()` and a `wrap()` call with a promise make a small number of objects.
388
- - `slowMs` adds a breadcrumb for each span that is longer than the value. The breadcrumb has the category `profile` and a message such as `grid.render 48 ms`. The next error record carries it. Use a threshold that only a slow span passes, because each breadcrumb is an object.
389
- - `profiler.framePhases: true` adds the phases of each long animation frame to each probe with a span of 1 ms or more in that frame. The library sends them as the histogram `ui.profile.frame.duration` with the attributes `profile.probe` and `profile.frame_phase`. The phases are `script`, `render`, `style_layout` and `forced_layout`. `forced_layout` is the layout time that a script forced with a read after a write. It is a part of the `script` phase.
390
- - `framePhases` uses the last 256 spans of the probes that are not async. `capturePolicy.longFramesPerWindow` limits the frames in each window. A browser with no long animation frames reports `capture.install_failed` one time. `framePhases` is then off. Firefox and Safari are such browsers.
391
- - `profiler.framePacing: true` measures the time between two frames with the probe `frame.interval`. The probe uses one of the `maxProbes` slots. The library runs one frame callback for each frame while the page is visible. The first frame after a hidden time gives no value.
392
- - `framePhases` and `framePacing` load as a separate chunk. They need `profiler.enabled`.
393
- - `profiler.maxProbes` is the maximum number of probes. The default is 64. The range is 1 to 1024. You cannot change it after startup. A probe above the limit does nothing. The library reports `config.invalid` one time for each start of the profiler. The diagnostics throttle can drop that report. The library then reports again each time it collects the profiler points, until one report passes the throttle. Each try adds 1 to the `config.invalid` counter.
394
- - Each probe slot holds 2 times 368 bucket counts of 4 bytes, 4 numbers of 8 bytes and 2 numbers of 4 bytes. One slot is 2984 bytes. The library allocates one slot more than `maxProbes` when the profiler first turns on. The default of 64 probes uses 65 slots. That is 193,960 bytes.
395
- - At the end of the first interval with data, the library measures the cost of one `begin()` and `end()` pair. The measurement runs one time. It blocks the thread for approximately 2 ms to 3 ms. Each record from that time has the result as `profile.overhead_ns`. The result is the cost of a pair in a short loop. A pair in app code can cost more or less. `flush()`, `shutdown()` and the exit flush do not run the measurement. A clock that is too coarse gives no value. The measurement can then block for longer.
396
- - With `metricsEndpoint`, a record is an OTLP histogram point. Its point attributes are `profile.probe` and `profile.sample_every` only. The percentiles and the overhead value are on the log record and the ECS document only. A backend computes percentiles from the buckets.
397
- - `processors` and `redact` apply to the `profile.*` attributes of the record. Use a small number of fixed probe names, because each name is one series.
398
- - A rotation sends the open interval as records of the old context. With `securityContext.isolation` (the default), the values of the rotation add no value. Each span that is open at its end also adds no value. On a coarse clock, this includes a span that begins in the last clock tick of the rotation.
399
- - A span that is open when `configure()` turns the profiler off adds no value. During a rotation, `shutdown()` and the exit flush do not send the open interval.
400
- - A name that is not a string, or an empty name, gives a probe that does nothing. A `sampleEvery` value that is not an integer from 1 to 2147483647 uses 1. A `slowMs` value that is not a finite number of 0 or more adds no breadcrumb. An `async` value that is not a boolean uses `false`. Each of these reports `config.invalid` to the current runtime. A call before the first `configure()` reports nothing.
401
- - A probe name stays for the life of the page. The library keeps at most 1024 names. The order of the `probe()` calls decides which probes are in the `maxProbes` limit.
402
- - The clock of the platform limits the resolution of one span. A browser rounds `performance.now()`, for example to 0.1 ms or to 1 ms. A span shorter than one clock step reads 0 or one step.
403
- - Give `end()` only the token of `begin()`. `end(-1)` does nothing. Another token that is not a number, is below 0 or gives a negative duration adds no value. While the profiler is on, the library counts that token as `record.dropped_malformed`.
404
-
405
- ### Session replay
406
-
407
- The session replay records the DOM of the page with the recorder of your app, [`@rrweb/record`](https://rrweb.com/docs/guide). The library keeps the recent events in memory. After an ERROR or FATAL record, it sends them in segments to a separate endpoint. A person can then watch what the user saw before the error.
124
+ [Custom Transport](docs/guides.md#custom-transport) gives the status codes, the retry rules and the exit send. [Worker transport](docs/guides.md#worker-transport) sends the batches from a dedicated worker.
408
125
 
409
- ```ts
410
- configure({
411
- replay: {
412
- enabled: true,
413
- endpoint: "https://replay.example/v1/replay",
414
- // Your app owns the import. The library has no recorder of its own.
415
- loader: () => import("@rrweb/record"),
416
- },
417
- });
418
- ```
126
+ ### Frames and workers
419
127
 
420
- - The replay is off by default. `@rrweb/record` is an optional peer. An app with the replay off does not need it.
421
- - The buffer keeps the last `replay.bufferMs` (60 seconds by default), and at most 1.5 times that. The recorder takes a full snapshot at each half of that time. `replay.maxBufferBytes` limits the buffer. Above it, the buffer drops its oldest part and reports `capture.rate_limited` at the next upload.
422
- - An ERROR or FATAL record starts an upload. The library sends the buffer, then each new event for `replay.afterErrorMs`. An error in that time is a part of the same upload and does not extend the time. `replay.uploadsPerWindow` limits the uploads in each window of `capturePolicy.windowMs`. A stream of errors then cannot upload the full session. An upload always starts with a full snapshot. For an empty buffer, the library takes a new one.
423
- - The library sends the events in segments. A segment closes at `replay.batchSize` events, at `replay.batchBytes` or after `replay.flushIntervalMs`. One event that is larger than `batchBytes` is a segment of its own. A full snapshot of a large page is such an event.
424
- - One segment is in flight at a time. A failed send has `replay.maxAttempts` attempts, with the wait of `delivery.retryBaseDelayMs` and `delivery.retryMaxDelayMs`. `delivery.requestTimeoutMs` limits each request. The segments that wait have the limit `replay.maxQueueBytes`. A segment is only in memory. The exit flush sends no segment.
425
- - The request has the headers of `replay.headers`, an object or a function. It does not have the `headers` of the log endpoint, because that token can be for another host. `credentials` applies to the replay request also.
426
- - `replay.maxBufferBytes`, `replay.batchBytes` and `replay.maxQueueBytes` count the length of the JSON text. A text with a character above U+00FF uses 2 bytes of memory for each character.
427
- - Each segment has `replay.id`, `session.id`, `tab.id`, `service.name` and a `sequence` number. Each record has the attribute `replay.id` while the recorder runs. Use it to find the replay of a log record.
428
- - `replay.onSegment` gets each segment in place of the request. Use it for your own transport. A call that does not end in `delivery.requestTimeoutMs` drops the segment. If the function sends a request, add its URL to `capture.ignoreUrls`. Without that, a failed request gives an error record, and that record gives a new upload.
429
- - **Privacy.** The recorder masks the text of each element. It masks the value of each `input`, `textarea` and `select`, also of a hidden input and a file input. A masked value is `********`. A masked text keeps the length of each word. The text in an element with the attribute `data-observability-unmask` stays. `replay.maskSelectors` is a list of CSS selectors with text that is always masked. `replay.blockSelectors` is a list of CSS selectors of elements that the recorder does not record. A password input is always masked. `redact` and `processors` do not apply to a replay event.
430
- - **What stays in clear text.** The recorder does not mask an attribute value, for example `title`, `alt`, `placeholder`, `aria-label`, `data-*`, `id` and `class`. It does not mask the `value` of a checkbox, a radio button, a button and an `<option>`. It does not mask a URL in `href` or `src` with its query, the CSS text, the content of a `<meta>` element and a comment. It records the mouse positions and the scroll positions. The library removes the query of the page URL unless `capture.fullUrls` is set. Block an element with `replay.blockSelectors` when one of these can identify a person or an account.
431
- - Do not put `data-observability-unmask` on an element that shows content from a user. That content can then add text that stays in clear text. With `replay.maskText: false`, a `maskSelectors` entry does not reach an element inside a shadow root.
432
- - A `maskSelectors` or `blockSelectors` entry that is not valid CSS reports `config.invalid`. The replay then does not start, because a missing mask shows text that you wanted to hide.
433
- - With `replay.requireConsent: true`, nothing records before `startReplay()`. `stopReplay()` stops the recorder, stops the request in flight and drops each event that is not sent. The recorder then stays off until the next `startReplay()`, also after a later `configure()`.
434
- - `newSession()` and `rotateSecurityContext()` drop the buffer and start a new recording with a new `replay.id`. The next user of a shared device does not get the page of the previous user.
435
- - A change of another capture setting in `configure()` keeps the recording and its buffer. A change of `replay.endpoint`, a mask setting, a selector list, `recordCanvas`, `bufferMs`, `requireConsent`, `capture.fullUrls` or `capture.ignoreUrls` starts a new recording with a new `replay.id` and drops the buffer. The batch settings, the limits and `replay.headers` apply to the recording that runs. See [Runtime policies](docs/runtime-policies.md).
436
- - `replay.recordOptions` gives other options to the recorder. The library accepts `sampling`, `slimDOMOptions`, `ignoreClass`, `ignoreSelector`, `ignoreCSSAttributes`, `userTriggeredOnInput`, `recordAfter`, `inlineStylesheet` and `dataURLOptions`. It sets each mask, block, canvas, plugin and event option itself. It ignores another key and reports `config.invalid`.
437
- - The recorder reads each DOM change. A change of many nodes costs time and memory. Block a large list with `replay.blockSelectors` when its content is not necessary in the replay.
438
-
439
- `replay.plugins` is a list of functions that make the record plugins of the recorder. Your app owns each import.
128
+ A child frame or a worker forwards its records to the page over the bus. The page batches, stores and sends them, and its `redact` runs on them. Register each child in the page before the child starts. Each child calls `configure()` too. A cross-origin child also needs the origin of the page in `bus.trustedOrigins`. A child that starts before the page runtime gets no owner. After a timeout, it sends its own records with its own `redact`.
440
129
 
441
130
  ```ts
442
- configure({
443
- replay: {
444
- plugins: [
445
- async () =>
446
- (await import("@rrweb/rrweb-plugin-sequential-id-record")).getRecordSequentialIdPlugin(),
447
- async () =>
448
- (await import("@rrweb/rrweb-plugin-console-record")).getRecordConsolePlugin({
449
- level: ["warn", "error"],
450
- }),
451
- async ({ transformRequest }) =>
452
- (await import("@rrweb/rrweb-plugin-network-record")).getRecordNetworkPlugin({
453
- recordHeaders: false,
454
- recordBody: false,
455
- transformRequestFn: transformRequest,
456
- }),
457
- ],
458
- },
459
- });
460
- ```
131
+ import { flush, registerFrame, registerWorker } from "@utk09/ui-observability";
461
132
 
462
- - The sequential id plugin numbers each event. A server can then find a lost event.
463
- - The console plugin and the network plugin wrap the same functions as the console capture and the network capture of the library. Both pairs work together. A plugin event does not pass through `redact`. Do not record headers or bodies unless you mask them in the options of the plugin.
464
- - Give `transformRequest` to the network plugin. It skips each request to a URL in `capture.ignoreUrls`. That list has each endpoint of the library, also `replay.endpoint`. Without it, an upload gives a new event, and that event gives a new upload. It also removes the query of a URL unless `capture.fullUrls` is set.
465
- - The network plugin gives its event some time after the request. An upload directly after a request does not have that event.
466
- - A new `loader` function, `onSegment` function, `recordOptions` object or plugin function in `configure()` starts a new recording and drops the buffer. The library compares the references. Keep them stable, and do not make a new function or object in each `configure()` call.
467
-
468
- ### Context & Correlation
469
-
470
- | Function | Description |
471
- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
472
- | `setContext(key, value)` | Sets one ambient attribute on every later record. |
473
- | `setContextMap(values)` | Merges an attribute map into the ambient context. |
474
- | `removeContext(key)` | Removes one attribute from the ambient context. |
475
- | `addBreadcrumb(message, data?)` | Adds a breadcrumb with the category `custom`. The next error record carries the trail. The library copies `data` at the call. |
476
- | `startJourney(name, options?)` | Starts a journey across windows. `options.parent: true` links the active journey as the parent. `options.id` sets the id, 1 to 64 letters, digits, `_`, `.`, `:` or `-`. Another value gives a new id and a `config.invalid` report. |
477
- | `endJourney()` | Ends the active journey. |
478
- | `currentJourney()` | Returns the active `Journey`, or null. |
479
- | `getJourneyToken()` | Serializes the active journey into a URL token. |
480
- | `adoptJourney(token)` | Adopts a journey token into this context. |
481
- | `startTrace()` | Rotates the ambient trace context. |
482
- | `getTraceHeaders()` | Returns the W3C `traceparent` header for an outgoing request. |
483
- | `registerWorker(worker, options?)` | Attaches a Web Worker or MessagePort to the bus, with its permissions. Returns a function that removes the registration. |
484
- | `registerFrame(frame, options)` | Registers a child iframe element or window at its exact origin, with its permissions. Returns a function that removes the registration. A child frame forwards only after its registration, unless `bus.sourcePolicy` is `trusted-origin`. |
485
- | `newSession()` | Rotates correlation in this tab. Use `rotateSecurityContext()` for logout or tenant changes. It sends the open metric points, ends the active trace and journey, and clears the breadcrumbs. Other tabs read the new id at their next startup. |
486
-
487
- See [runtime policies, operational budgets and migration](docs/runtime-policies.md) for `rotateSecurityContext()`, `registerFrame()`, source permissions, `setConfigurationLocked()`, `getHealth()` and configurable cache/bus budgets. Defaults favor privacy and isolation; applications can explicitly choose broader capture and delivery policies.
488
-
489
- `serveTransportWorker({ onDiagnostic? })` starts the dedicated transport worker service. It returns a function that stops the service.
490
-
491
- ### Delivery & Diagnostics
492
-
493
- | Function | Description |
494
- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
495
- | `flush()` | Sends the records held in the pipeline or the forward buffer, and waits for the batches in flight. |
496
- | `getQueueDepth()` | Returns the number of batches in storage. |
497
- | `getStats()` | Returns `{ pending, inFlight, stored, lastSendAt }`. `pending` counts the records in the buffers. `inFlight` counts the records in requests. `stored` counts the batches in storage. `lastSendAt` is the epoch time in ms of the last batch that the server accepted, or null. A forwarder reports only its own buffers. |
498
- | `getDiagnosticCounters()` | Returns the count of each diagnostic code. |
499
- | `getHealth()` | Returns the state of this SDK copy. It has the SDK version, the status, the delivery role and counts, the lock and cache state, the issue codes and the policies. |
500
- | `collectDebugBundle()` | Returns a JSON-safe bundle for a support ticket. It has the health, the diagnostic counters, the resource, the breadcrumbs, the debug buffer and a config summary. The summary has no headers and no URL query. A plugin or a custom serializer shows only its name. The privacy hooks process the breadcrumbs. A debug buffer record keeps its context attributes. Your app decides where to send it. |
501
- | `clearPersistedLogs(scope?)` | Removes the stored records of the active context. With `"namespace"`, it removes the stored records of each context in the persistence namespace. |
133
+ // In the page, after configure(). The frame is in the document and has no src yet.
134
+ const frame = document.body.appendChild(document.createElement("iframe"));
135
+ registerFrame(frame, { origin: "https://ticket.example" });
502
136
 
503
- ---
504
-
505
- ## Configuration Options
506
-
507
- No key is required. Set `endpoint` to send records. A value of the wrong type or outside its range reports `config.invalid`. The current value stays. Level names can have any case. You cannot change `batching` and `retention` after the delivery stack loads. You cannot change `limits`, `journey.maxAgeMs` and `profiler.maxProbes` after the first `configure()`. [Runtime policies](docs/runtime-policies.md) gives each default and range of the policy sections.
508
-
509
- | Key | Default | Description |
510
- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
511
- | `endpoint` | `""` | HTTP endpoint that receives the batches. `null` selects console-only mode. `""` reports `config.invalid`. |
512
- | `metricsEndpoint` | `""` | OTLP metrics endpoint, for example `https://ingest.example/v1/metrics`. With it, each batch of metric records goes there as an OTLP `ExportMetricsServiceRequest`. Without it, metric records are log records on `endpoint`. It needs `serializer: "otlp"`, and `endpoint` or `transport`. |
513
- | `tracesEndpoint` | `""` | OTLP traces endpoint, for example `https://ingest.example/v1/traces`. With it, the library records spans and sends them there as an OTLP `ExportTraceServiceRequest`. Without it, the library sends no span. It needs `serializer: "otlp"`, and `endpoint` or `transport`. See [Spans](#spans). |
514
- | `serviceName` | `""` | `service.name` on every record. |
515
- | `serviceVersion` | `""` | `service.version` on every record. |
516
- | `environment` | `""` | `deployment.environment` on every record. |
517
- | `enabled` | `true` | Set `false` to stop all logging. Every log call then does nothing. |
518
- | `payloadMode` | `"copy"` | `"defer"` keeps payload references until idle time. The debug buffer always builds records at the call. |
519
- | `minLevel` | `"INFO"` | Lowest level that the library sends (`TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`). It does not drop actions and metrics. |
520
- | `minLevels` | `{}` | Lowest level for each namespace prefix, for example `{ "trading.ticks": "DEBUG" }`. The longest matching prefix wins. A prefix matches its own namespace and the namespaces below it after a dot. A namespace with no match uses `minLevel`. A new map replaces the current map. |
521
- | `compression` | `"gzip"` | `gzip` or `none`. The library compresses a payload above 1 KB only. |
522
- | `serializer` | `"otlp"` | `otlp`, `ecs`, or a custom `LogSerializer`. `ecs` writes ECS 8.10 NDJSON. It maps `app.namespace` to `log.logger`, `error.type`, `error.message` and `error.stack_trace` to `error.*`, and `log.type` to `event.kind`. The other attributes go to `labels`. |
523
- | `credentials` | `"omit"` | Fetch credentials mode. Set `"include"` for cookie auth. |
524
- | `headers` | `{}` | Static headers, or a function that returns them. After a 401 or 403, a function gets one more call and the batch one more send. The exit flush sends the last headers. Before a function gives its first result, the exit flush puts the batch in the emergency queue. `headers: undefined` removes the headers. |
525
- | `storage` | `"auto"` | Store for undelivered batches: `auto`, `indexeddb`, `localstorage`, `memory` or `none`. Fixed at startup. |
526
- | `identity` | `"storage"` | Store for session, tab and journey ids. `memory` writes no key. Fixed at startup. |
527
- | `sampling.defaultRate` | `1` | Keep rate for a namespace with no rule. |
528
- | `sampling.rates` | `{}` | Keep rate per namespace. The longest matching prefix wins. |
529
- | `sampling.alwaysSampleTypes` | `["action"]` | Record types that ignore the rate. |
530
- | `sampling.alwaysSampleFrom` | `"ERROR"` | Lowest level that ignores the rate. `capturePolicy.errorCeiling` limits these log records. |
531
- | `sampling.remote` | `false` | Reads sampling rules from the `X-UiObs-Sampling` header of each accepted batch (see Remote Sampling). |
532
- | `sampling.remoteMaxRate` | `1` | Highest rate that a remote rule can set. It applies to the remote `defaultRate` and to each remote namespace rate. |
533
- | `bus.mode` | `"auto"` | `auto`, `sender`, `forwarder` or `off`. With `off`, this context sends its own records and opens no link. A same-origin child frame that the page registers can still forward to it. |
534
- | `bus.trustedOrigins` | `[]` | Origins of other documents that this document trusts. A cross-origin child frame forwards its records only to a parent on these origins. With `bus.sourcePolicy: "trusted-origin"`, a parent also accepts records from a child frame on these origins. With the default policy, use `registerFrame()`. The library keeps the origin of each URL. For a sandboxed frame, set `bus.mode: "sender"` in the frame. A trusted origin is also trusted for metric points. Its points bypass the sampling and the limit of 100 attribute sets of this document. |
535
- | `bus.sourcePolicy` | `"registered"` | `registered` accepts only the frames and workers that the page registers. `trusted-origin` also accepts each frame on the page origin or in `bus.trustedOrigins`. |
536
- | `bus.validation` | `"strict"` | `strict` checks the fields of each bus message. `envelope` checks the envelope only. |
537
- | `bus.maxMessageBytes`, `bus.maxRecordsPerMessage`, `bus.maxMessagesPerSecond`, `bus.maxTrackedSources` | `262144`, `100`, `100`, `256` | Bus budgets for each message and each source. `0` turns a limit off. |
538
- | `bus.openFinRole` | `"auto"` | `auto`, `provider` or `client`. |
539
- | `journey.scope` | `"auto"` | Which contexts adopt a journey. `context`: each context keeps its own. `tab`: a frame or a worker adopts the journey of its owner. `origin`: each context of the origin, also in other tabs. `auto` is `origin` in OpenFin and `tab` in a browser. |
540
- | `journey.maxAgeMs` | `1800000` | Maximum open time of a journey, in milliseconds. Then the library ends it. The range is 60000 to 86400000. |
541
- | `batching.logFlushIntervalMs` | `2000` | Maximum wait of a partial log batch, in milliseconds. The range is 100 to 60000. |
542
- | `batching.logBatchSize` | `100` | Maximum records in one log batch. The range is 1 to 1000. |
543
- | `batching.metricFlushIntervalMs` | `10000` | Maximum wait of a partial metric batch, in milliseconds. The range is 100 to 60000. |
544
- | `batching.metricBatchSize` | `500` | Maximum records in one metric batch. The range is 1 to 1000. |
545
- | `retention.mode` | `"limited"` | `limited` or `until-delivered`. With `until-delivered`, a stored batch has no age limit and no attempt limit. `retention.maxBatches` still applies. A permanent error still drops the batch. A batch that always gets a temporary error stays first. The batches of the same endpoint behind it wait. |
546
- | `retention.maxBatches` | `500` | Maximum stored batches. A new batch evicts the oldest batch without an action first. The range is 1 to 5000. |
547
- | `retention.maxAgeMs` | `86400000` | Maximum age of a stored batch, in milliseconds. The range is 60000 to 604800000. |
548
- | `retention.maxAttempts` | `5` | Maximum send attempts of a stored batch. The range is 1 to 20. |
549
- | `limits.maxBodyChars` | `4096` | Maximum body length, in characters. The range is 256 to 65536. |
550
- | `limits.maxAttributeChars` | `8192` | Maximum length of a string attribute, in characters. The range is 256 to 65536. |
551
- | `limits.maxAttributeCount` | `128` | Maximum keys in one object. The range is 1 to 1024. |
552
- | `limits.maxStackChars` | `8192` | Maximum length of an error stack, in characters. The range is 256 to 65536. |
553
- | `limits.maxDepth` | `6` | Maximum depth of a nested value. The range is 1 to 16. |
554
- | `limits.maxArrayLength` | `100` | Maximum items in one array, set or map. The range is 1 to 10000. |
555
- | `limits.maxNodes` | `10000` | Maximum values in one sanitize pass. The range is 100 to 100000. |
556
- | `limits.maxRecordBytes` | `32768` | Maximum attribute bytes of one record. Above it, the library drops the caller attributes. The range is 1024 to 60000. |
557
- | `securityContext.id` | Generated | Delivery identity of this runtime. Supply a stable opaque id to send stored batches after a reload. Do not put secrets or personal data in it. |
558
- | `securityContext.isolation` | `true` | Keeps the stored batches of each identity apart. Delivery changes then need `rotateSecurityContext()`. |
559
- | `lockConfiguration` | `false` | Refuses changes through `configure()`. Identical repeated settings are accepted. `setConfigurationLocked(false)` unlocks. |
560
- | `loggerCache.maxEntries` | `256` | LRU limit of cached loggers. `0` turns the cache off. `null` sets no limit. |
561
- | `delivery` | See policies | Request timeout, request concurrency, retry delays, batches in one retry pass and fetch priority (`"low"` by default). |
562
- | `buffering` | 10,000 records, 16 MiB, `"drop-oldest"` | Limits of the live buffers, and the overflow rule. |
563
- | `debugBuffer` | `{ enabled: false, maxRecords: 200, maxAgeMs: 60000 }` | Keeps the records that `minLevel` or sampling drops. An ERROR or FATAL record of this context sends them first, with `uiobs.debug_buffer: true`. A later change of `redact` or `processors` empties the buffer. |
564
- | `profiler` | `{ enabled: false, flushIntervalMs: 10000, maxProbes: 64, framePhases: false, framePacing: false }` | Times code spans with probes. The library sends one histogram summary record for each probe at each interval of `flushIntervalMs`. The range of `flushIntervalMs` is 1000 to 600000. This range is different from the range of `batching.metricFlushIntervalMs`. The range of `maxProbes` is 1 to 1024. `maxProbes` is fixed at startup. `framePhases` adds the phases of each long animation frame to the probes in that frame. `framePacing` measures the time between two frames. See [Profiler](#profiler). |
565
- | `replay` | `{ enabled: false, mode: "onError", bufferMs: 60000, maxBufferBytes: 10000000, afterErrorMs: 5000, batchSize: 200, batchBytes: 512000, flushIntervalMs: 2000, maskText: true, maskInputs: true, ... }` | Records the DOM with the recorder of your app and sends the recent events in segments after an error. It needs `loader`, and `endpoint` or `onSegment`. See [Session replay](#session-replay) and [Runtime policies](docs/runtime-policies.md) for each key and range. |
566
- | `metrics` | See policies | Limits of instrument names, attribute sets and histogram boundaries. |
567
- | `correlation` | See policies | Session idle time, session write interval and trace age. Fixed at startup. |
568
- | `capturePolicy` | See policies | Breadcrumb capacity, error duplicate check, capture rate limits and the error ceiling. |
569
- | `diagnostics` | `{ throttleMs: 1000, consoleFallback: false, records: false }` | Report interval of each diagnostic code, and the console fallback when `onDiagnostic` throws. `records: true`, or a list of codes, also sends each report as a record in the namespace `uiobs.diagnostics`. |
570
- | `persistence.namespace` | `""` | Separates the batch stores, the emergency queue and the retry locks of one application. Fixed at startup. |
571
- | `persistence.requestPersistent` | `false` | Asks the browser to keep the stored batches under storage pressure. Firefox can show a prompt. `getHealth()` reports the answer. Fixed at startup. |
572
- | `metadata` | All `true` | `pageUrl`, `userAgent` and `openfin` include `page.url`, `browser.user_agent` and the OpenFin fields. `clockOffset` adds `uiobs.clock_offset_ms` to logs and spans. |
573
- | `capture` | See below | Auto-capture settings. |
574
- | `capture.remoteToggles` | `[]` | Capture switches that remote rules can change for their TTL. Requires `sampling.remote`. Privacy controls stay local. |
575
- | `capture.serverTiming` | `false` | Adds Server-Timing response entries to fetch and XHR records. Links a valid traceparent entry to the client span. |
576
- | `capture.reports` | `false` | Records deprecations, interventions and CSP reports as WARN `ui.report`. |
577
- | `capture.resourceTiming` | `false` | Records `ui.resource.duration` by initiator type and host. Accepts `true` or an object with `slowMs`. |
578
- | `capture.resourceTiming.slowMs` | `1000` | Minimum duration of a `ui.resource.slow` event, in milliseconds. Set `0` for no slow events. |
579
- | `capture.lifecycle` | `false` | Records visible, hidden, frozen, resumed and restored states with the duration of the previous state. |
580
- | `capturePolicy.reportsPerWindow` | `20` | Maximum browser reports in each capture window. Set `0` for no limit. |
581
- | `capturePolicy.resourcesPerWindow` | `100` | Maximum resource entries in each capture window. Set `0` for no limit. |
582
- | `capturePolicy.lifecyclePerWindow` | `20` | Maximum lifecycle events in each capture window. Set `0` for no limit. |
583
- | `console` | `false` | Prints records to devtools. `true` prints from `DEBUG` up. A level name prints from that level up. An object sets `level` and `styles` (see Console Output). It does not depend on `minLevel`. |
584
- | `transport(request)` | `undefined` | Sends batches through a channel of your app in place of HTTP (see Custom Transport). |
585
- | `transportWorker()` | `undefined` | Creates a dedicated HTTP worker. It calls `serveTransportWorker()`. Retry, storage, header functions and exit sends stay on the main thread. |
586
- | `transportOnExit(request)` | `undefined` | Sends the last batch while the page closes. It must return a boolean and must not wait. |
587
- | `otelLoader()` | `undefined` | Loads `@opentelemetry/api`. Without it, OTel is off. |
588
- | `contextProvider()` | `undefined` | Returns attributes for each built record, including console/breadcrumb-only candidates, for example the current route. Its values override `setContext()` values. The logger scope and the call payload override its values. Keep it fast and synchronous. A provider that throws reports `handler.threw`. A value that is not an object reports `config.invalid`. The record is still built. |
589
- | `processors` | `[]` | Functions that change or drop a record. They run in list order, before `redact`. A processor has the contract of `redact`. Return the record or a new record to keep it, or `null` to drop it. If a processor throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_processor`. A new list replaces the current list. |
590
- | `redact(record)` | `undefined` | Changes a record before the library sends or prints it, including console-only candidates. Return `null` to drop the record. If the hook throws or returns a value that is not a record, the library drops the record. It counts `record.dropped_by_redact`. The sender also runs its `redact` on each record from a frame or a worker. A record that the child already redacted then runs through `redact` again. Write `redact` so that a second run gives the same result. |
591
- | `onDiagnostic(event)` | `undefined` | Receives the faults of the library itself. |
592
- | `onDrop(summary)` | `undefined` | Receives a summary when the library loses records that it built. The summary has `reason`, `records`, `batchIds`, `journeyIds` and `actions`. Sampling, `minLevel`, `processors` and `redact` do not cause a loss. Do not log through the library in the hook. A record from the hook can evict a stored batch. A batch that storage evicts during its send can still reach the server. |
593
-
594
- ### Deferred payloads
137
+ const worker = new Worker(new URL("./pricing.worker.ts", import.meta.url), { type: "module" });
138
+ registerWorker(worker);
595
139
 
596
- ```ts
597
- configure({ payloadMode: "defer" });
598
- const payload = { status: "before" };
599
- getLogger("orders").info("Order state", payload);
600
- payload.status = "after";
140
+ // The registrations start with the runtime. A frame that loads before that finds no owner.
141
+ await flush();
142
+ frame.src = "https://ticket.example/";
601
143
  ```
602
144
 
603
- With `defer`, the record sees `status: "after"` if the idle build runs after the assignment. With the default `copy`, it sees `"before"`. The queue keeps the payload reference without reading its fields. Error reasons and metric attributes also wait for the build. Console output and breadcrumbs wait with the record. A call below the level queues nothing unless the console uses it. Sampling checks use the current rules at build time.
604
-
605
- The call keeps its timestamp, trace, journey and a shallow copy of the ambient context. The builder reads `contextProvider`, scoped context and payload fields at build time. Processors and `redact` also run at build time. The queue can hold raw values until then. Debug bundle output does not include those raw queued values.
606
-
607
- `requestIdleCallback` builds records while idle time remains. A callback timeout of 1000 ms permits one build without idle time. A timer runs the build when the idle API is absent. `flush()`, shutdown and page exit build pending records first. Reconfiguration, session changes and delivery identity changes also drain pending calls first.
608
-
609
- The queue holds at most 1000 calls for each runtime. A lower positive `buffering.maxPendingRecords` also lowers this cap. A full queue builds its calls before it accepts another payload reference. Calls from a hook wait for the next callback. Extra calls from a hook at the cap increment `record.dropped_by_ceiling`. The library does not build those calls.
610
-
611
- The deferred cap is separate from the delivery buffer. Delivery byte budgets and stats apply to built records. With `debugBuffer.enabled`, the logger builds every record at the call, also with `payloadMode: "defer"`. This preserves the debug buffer's immediate privacy processing.
612
-
613
- ### Remote capture switches
614
-
615
145
  ```ts
146
+ // In the frame on https://ticket.example. A same-origin frame or a worker needs no trustedOrigins.
616
147
  configure({
617
- sampling: { remote: true },
618
- capture: { remoteToggles: ["fetch", "resourceTiming", "lifecycle"] },
148
+ endpoint: "https://telemetry.example.com/v1/logs",
149
+ serviceName: "ticket",
150
+ bus: { trustedOrigins: ["https://app.example"] },
619
151
  });
620
152
  ```
621
153
 
622
- ```http
623
- X-UiObs-Sampling: {"v":1,"ttlMs":60000,"capture":{"fetch":true,"lifecycle":false}}
624
- ```
625
-
626
- The rules change only the switches in this context's `remoteToggles`. The empty default list permits no changes. Each switch is boolean. An invalid switch or a privacy control rejects the whole header. The allowed names are `errors`, `rejections`, `resourceErrors`, `fetch`, `xhr`, `httpMetrics`, `interactions`, `navigation`, `webVitals`, `longFrames`, `console`, `webSocket`, `uncleanExit`, `userTiming`, `serverTiming`, `reports`, `resourceTiming` and `lifecycle`.
627
-
628
- A remote enable keeps the local options of a capture, for example click privacy settings or a console method list. The server cannot change text capture, selectors, URL rules, trace propagation, plugins or thresholds. The library restores local settings when the TTL ends, remote sampling stops, or the delivery identity changes. The trusted sampling path also sends these rules to forwarders. Each forwarder applies its own allowlist.
629
-
630
- ### Auto-Capture Options
631
-
632
- ```ts
633
- capture: {
634
- errors: true, // Uncaught window.onerror exceptions (default: true)
635
- rejections: true, // Unhandled promise rejections (default: true)
636
- resourceErrors: false, // <img>, <script>, <link> load failures
637
- fetch: false, // window.fetch duration and status codes
638
- xhr: false, // XMLHttpRequest duration and status codes
639
- httpMetrics: true, // http.client.request.duration histogram of fetch and xhr requests, in seconds.
640
- // Attributes: http.request.method, http.response.status_code, server.address, error.type
641
- interactions: false, // Click action names. The object form sets actionAttribute, text, selector,
642
- // rageClicks and deadClicks
643
- navigation: false, // Single-page navigation URL changes
644
- webVitals: false, // Core Web Vitals (LCP, CLS, INP, FCP, TTFB)
645
- longFrames: false, // Frames that freeze the page, as ui.long_frame.duration
646
- longFrameMs: 100, // Minimum frame duration that longFrames records
647
- console: false, // App console calls: true, or a list such as ["error", "warn", "info"]
648
- fullUrls: false, // Keep query strings and fragments on recorded URLs
649
- urlTransform: undefined, // Function that replaces the default URL rule
650
- ignoreUrls: [], // URL patterns excluded from network capture
651
- propagateTraceHeaderTo: [], // Origins, or RegExp patterns, that receive traceparent
652
- webSocket: false, // WebSocket open, close and error, and ui.websocket.messages
653
- uncleanExit: false, // WARN ui.unclean_exit when the previous page of the tab did not close cleanly
654
- userTiming: false, // performance.measure() as ui.user_timing.duration. A mark gives a breadcrumb
655
- userTimingInclude: [], // Mark and measure names that userTiming records. Empty records each name
656
- remoteToggles: [], // Capture switches that a remote rule can change for its TTL
657
- serverTiming: false, // Server-Timing entries on fetch and XHR records
658
- reports: false, // Browser reports as WARN ui.report
659
- resourceTiming: false, // Resource durations. An object sets slowMs, with default 1000
660
- lifecycle: false, // Page states and the duration of the previous state
661
- plugins: [], // Capture plugins of your app
662
- }
663
- ```
664
-
665
- `interactions: { rageClicks: true, deadClicks: true }` finds frustrated clicks. Each event names only the action, in `click.action`.
666
-
667
- - A rage click is `rageClickCount` clicks (default 3) on one element in `rageClickWindowMs` (default 1000). It gives the event `ui.rage_click` with `click.count`. More clicks in the same burst give no second event. A burst ends when no click stays in the window.
668
- - A dead click is a click on a control that gives no DOM change, no navigation and no scroll in `deadClickMs` (default 1000). It gives the event `ui.dead_click`. A control is a button, a link, a `role="button"` element or an element with the action attribute. A click on a `target="_blank"` or `download` link gives no event.
669
- - A request alone is not a response. A page that changes its DOM all the time gives no dead click.
670
-
671
- `uncleanExit` finds a page of this tab that stopped without a clean close, for example after a crash. The top document keeps a marker in `sessionStorage`. A clean close removes it. The next page of the tab logs WARN `ui.unclean_exit`. A popup with an opener reports nothing, because it copies the `sessionStorage` of its opener. A duplicated tab copies it too, and can report a false exit. `identity: "memory"` turns this capture off, because that mode writes nothing to the device.
672
-
673
- - The attributes are `exit.session_id`, `exit.last_seen_ms`, `exit.visibility` and `exit.discarded`.
674
- - The marker updates every 30 seconds and at each visibility change. `exit.last_seen_ms` is correct to about 30 seconds.
675
- - A mobile OS can stop a hidden page with no close event. `exit.visibility: "hidden"` shows this case. `exit.discarded: true` shows a page that the browser discarded to free memory.
676
-
677
- `userTiming` records each `performance.measure()` of the app in the histogram `ui.user_timing.duration`, in milliseconds, with the attribute `user_timing.name`. Each `performance.mark()` adds a breadcrumb. Frameworks create many marks and measures. Set `userTimingInclude`, for example `[/^app\./]`, to keep only the names of your app. `metrics.maxSeries` limits the number of names in one interval. Names follow `fullUrls`. Without it, a name loses the part after the first `?` or `#`.
678
-
679
- `serverTiming` reads the `Server-Timing` response header of captured fetch and XHR requests. It adds `server.timing` entries with `name`, `duration` and `description`. A valid `traceparent;desc="00-<trace-id>-<span-id>-01"` adds an OTLP link to the client span. The client span keeps its own trace and parent. Set `tracesEndpoint` and `propagateTraceHeaderTo` to record client spans.
680
-
681
- For cross-origin requests, expose `Server-Timing` with `Access-Control-Expose-Headers`. Also send `Timing-Allow-Origin` for access through browser performance tools. The [Server Timing specification](https://www.w3.org/TR/server-timing/) defines that interface. The library reads at most 4096 header characters and 32 entries. The privacy hooks process the entries before delivery.
682
-
683
- `reports` records deprecations and interventions through ReportingObserver. CSP reports use the `securitypolicyviolation` event. Each WARN `ui.report` has the type, the URL and the available source location or CSP directive. Report URLs never keep credentials, queries or fragments. This rule also applies with `fullUrls` or `urlTransform`. Message text and code samples stay out.
684
-
685
- `resourceTiming: true` records the histogram `ui.resource.duration` in milliseconds. Its attributes are `resource.initiator_type` and `server.address`. Each resource at or above 1000 ms also gives `ui.resource.slow`. Set `resourceTiming: { slowMs: 500 }` to change the threshold. Set `slowMs: 0` for no slow events. The capture skips ingest endpoints, ignored URLs and non-HTTP resources. Only the first install reads buffered resources. `metrics.maxSeries` limits the host and initiator series.
686
-
687
- `lifecycle` records `ui.lifecycle` at install and on each state change. The states are `visible`, `hidden`, `frozen`, `resumed` and `restored`. `restored` means a back-forward cache restore. Each event has `lifecycle.previous_state` and `lifecycle.duration_ms`. A monotonic clock measures the duration.
688
-
689
- The three captures have separate rate limits in `capturePolicy`. They use `capturePolicy.windowMs`, which defaults to 10000 ms. Disabling a capture removes its listeners or disconnects its observer.
690
-
691
- `longFrames` records each frame at or above `longFrameMs` as the histogram `ui.long_frame.duration`. Each long frame also adds a breadcrumb. The next error record then shows the freeze before it.
692
-
693
- - The library observes `long-animation-frame`. A browser without it gives `longtask` entries, with no script attributes.
694
- - The attributes are `frame.type`, `frame.blocking_ms`, `frame.script.invoker` and `frame.script.source`. The source URL follows `fullUrls`.
695
- - The library records at most 20 long frames in each 10-second window.
696
-
697
- `capture.console` records the console calls of your app and of third-party code. It is different from the top-level `console` option, which prints records.
698
-
699
- > **Set `redact` before you turn on `capture.console`.** A call such as `console.error("Request failed", error.response)` sends the request headers, for example `Authorization`. Third-party code on the page writes such lines too.
700
-
701
- - `true` wraps `console.error` and `console.warn`. A list selects from `error`, `warn`, `info` and `log`.
702
- - `error` gives an ERROR record, and `warn` gives a WARN record. `info` and `log` give a breadcrumb only.
703
- - The first string is the message. The first `Error` of an `error` call gives the `error.*` fields. The other arguments go into `console.args`.
704
- - The wrapper calls the original method first. Devtools shows the same text. The source link of the line points to the library wrapper.
705
- - The library does not record the lines that it prints itself.
706
- - The library records at most 20 `error` and `warn` calls in each 10-second window. The error capture has a separate limit. Console noise cannot hide an uncaught error.
707
- - To record an argument, the library reads each property, also a getter. A getter with a side effect then runs during the console call.
708
- - On `shutdown()`, the library restores each method. If another script wrapped the method later, the library leaves it and reports `capture.install_failed`.
709
-
710
- `webSocket` records the lifecycle of each WebSocket that the app opens after the capture loads.
711
-
712
- - `websocket.open` and `websocket.close` are events. `websocket.error` is a WARN record. Each has `url.full` and `server.address`.
713
- - `websocket.close` adds `websocket.close.code` and `websocket.close.clean`.
714
- - `url.full` has no user info, no query and no fragment, also with `fullUrls`. A socket URL often holds a token. Only `urlTransform` can record more of the URL.
715
- - The counter `ui.websocket.messages` counts the messages, with `network.io.direction` (`transmit` or `receive`) and `server.address`.
716
- - The library never reads the content of a message.
717
- - The library records at most 20 lifecycle records in each 10-second window. The counter counts each message.
718
-
719
- `plugins` adds your own capture modules. A plugin is an object with `name`, `install(ctx)` and `uninstall()`.
720
-
721
- - `ctx` gives `logger`, `counter()`, `histogram()`, `addBreadcrumb()` and `ownRequest(fn)`. The logger namespace is `uiobs.capture.<name>`.
722
- - `ownRequest(fn)` runs `fn`. The network capture does not record a request that `fn` starts before its first `await`, and does not add `traceparent` to it.
723
- - A `configure()` that changes the capture section calls `uninstall()`, then `install(ctx)` again. `shutdown()` calls `uninstall()`.
724
- - If `install()` or `uninstall()` throws, the library reports `capture.install_failed`. The other capture modules keep working.
725
- - The console-only runtime next to another version of the library installs no plugin.
726
-
727
- ```ts
728
- import { type CapturePlugin, configure } from "@utk09/ui-observability";
729
-
730
- let onChange: (() => void) | undefined;
731
-
732
- const visibility: CapturePlugin = {
733
- name: "visibility",
734
- install(ctx) {
735
- onChange = () => {
736
- ctx.logger.logEvent("page.visibility", { state: document.visibilityState });
737
- };
738
- document.addEventListener("visibilitychange", onChange);
739
- },
740
- uninstall() {
741
- if (onChange) {
742
- document.removeEventListener("visibilitychange", onChange);
743
- }
744
- },
745
- };
746
-
747
- configure({ endpoint: "https://ingest.example/v1/logs", capture: { plugins: [visibility] } });
748
- ```
749
-
750
- `fullUrls` is off by default. The library then cuts each recorded URL at the first `?` or `#`. This applies to the page URL, the request target and the URL of a failed resource. `ignoreUrls` and a RegExp in `propagateTraceHeaderTo` match the full URL. `urlTransform` replaces this rule. It receives the original URL. If it throws, the library records an empty URL and reports `capture.record_failed`.
751
-
752
- A string in `propagateTraceHeaderTo` is an origin, for example `"https://api.example"`. It matches a request to that origin only. A URL with a path gives its origin. A relative request URL resolves against the page. To match a path, use a RegExp. A RegExp tests the request URL in the form that the caller gives. Start each RegExp with `^`. Without it, `/\/api\//` also matches `https://vendor.example/api/`. For example, `/^https:\/\/api\.example\/v2\//` matches one path on one origin. `/^\/api\//` matches a relative request URL only.
753
-
754
- ### Spans
755
-
756
- With `tracesEndpoint`, the library sends spans. The backend then has a root span for each trace of the library.
757
-
758
- - **Root span:** Each ambient trace has one root span of kind INTERNAL. It starts with the trace and ends when the trace rotates. Its name tells why the trace started: `ui.start`, `ui.interaction`, `ui.navigation` or `ui.trace`.
759
- - **Client span:** Each `fetch` or XHR request that gets `traceparent` from `capture.propagateTraceHeaderTo` has one span of kind CLIENT. The `traceparent` names the client span, and the root span is its parent. Its name is the HTTP method. Its attributes are `http.request.method`, `url.full`, `server.address`, `http.response.status_code` and `error.type`. A status of 0 or 400 and more sets the status ERROR.
760
- - **Measure span:** Each `startMeasure()` call has one span of kind INTERNAL under the root span. Each phase has one child span. Sampling and the OpenTelemetry rule apply to it as to a client span.
761
- - **Sampling:** `sampling.defaultRate` samples each trace by its trace id. The whole trace stays or goes. `minLevel` does not apply to a span. For a trace that sampling drops, the `traceparent` has the sampled flag off. A downstream service then drops its spans too.
762
- - **Exit:** The exit flush and `shutdown()` end the root span of the active trace. The root span of a trace ends one time. A tab that becomes hidden ends it too, because a mobile OS can stop a hidden page.
763
- - **OpenTelemetry:** With `otelLoader`, a trace from the OpenTelemetry API keeps its own spans. The library sends no span for it.
764
- - `getTraceHeaders()` names the root span. Your server span is then a child of the root span.
765
- - Span records go through `processors` and `redact`. They also carry the context attributes of a record, for example `page.url` and `journey.id`.
766
-
767
- ### Browser Storage Keys
768
-
769
- | Key | Store | Written when | Option that stops it |
770
- | ------------------------------ | ---------------- | ---------------------------------------------------------------- | ---------------------------------------------------- |
771
- | `ui-observability.session` | `localStorage` | At startup, then at most one time each minute while logging | `identity: "memory"` |
772
- | `ui-observability.tab` | `sessionStorage` | At startup, and when the bus finds a duplicated tab | `identity: "memory"` |
773
- | `ui-observability.journey` | `sessionStorage` | When a journey starts or ends | `identity: "memory"` |
774
- | `ui-observability.alive` | `sessionStorage` | At startup, at each visibility change and at each interval | `capture.uncleanExit: false` or `identity: "memory"` |
775
- | `ui-observability.batch.*` | `localStorage` | When a send fails and the `localstorage` adapter holds the batch | `storage` other than `auto` or `localstorage` |
776
- | `ui-observability.emergency.*` | `localStorage` | When the exit flush cannot send a batch | `endpoint: null`, `storage: "memory"` or `"none"` |
777
- | `ui-observability.probe` | `localStorage` | One write and one remove, when the library tests `localStorage` | `storage` other than `auto` or `localstorage` |
778
-
779
- IndexedDB holds undelivered batches with `storage: "auto"` or `"indexeddb"`, in the database `UiObservability`.
780
-
781
- With `persistence.namespace`, the batch keys start with `ui-observability:namespaced:<namespace>:batch:`, the emergency keys start with `ui-observability:namespaced:<namespace>:emergency:`, and the database is `UiObservability:<namespace>`.
782
-
783
- ---
784
-
785
- ## Reference Documents
786
-
787
- - [Attribute reference](docs/attributes.md): each attribute that the library writes, and its type.
788
- - [Browser support](docs/browser-support.md): the browser APIs that the library uses, and the fallback for each.
789
- - [Delivery guarantees](docs/delivery-guarantees.md): duplicates, order, each loss and its `onDrop` reason, retention, the exit flush and rotation.
790
- - [Threat model](docs/threat-model.md): the trust boundaries, the threats and the controls.
791
- - [Runtime policies and migration](docs/runtime-policies.md): the defaults, the overrides, security-context rotation, registered bus sources, health and the upgrade steps.
792
-
793
- ---
794
-
795
- ## Core Architecture
796
-
797
- - **Code splitting:** The main chunk holds the logger, the record builder and the console sink. The delivery stack loads only when you set an endpoint. The bus loads only when the context needs it. Each capture module loads only when you enable it.
798
- - **Document singleton:** The library keeps the runtime at `globalThis[Symbol.for("ui-observability.runtime")]`. Federated microfrontends and separate bundles share one buffer, one sequence and one transport.
799
- - **One sender:** Iframes, workers and OpenFin views find the nearest long-lived context. They forward their records to it over the bus. That context batches, stores and sends for all of them. By default, a parent accepts only the frames and workers that it registers with `registerFrame()` and `registerWorker()`. A frame that knows its owner relays the records of its own children.
800
- - **One sender for each tab:** Each top-level tab or window has its own sender. Two tabs of one origin send their records separately. They have the same `session.id` and a different `tab.id`. A retry of stored batches runs in one tab at a time, under a Web Lock for each persistence namespace.
801
- - **Five correlation ids:** Each record carries `session.id`, `tab.id`, `context.id`, `journey.id` and `trace_id`.
802
- - **Durability and exit flush:** The library stores a batch that fails to send, in IndexedDB or localStorage. It sends the batch again with exponential backoff and jitter. When the document becomes hidden, the library runs a normal flush with the headers, gzip and retry. While the document is hidden, a send of 60 KB or less uses `keepalive`. A mobile OS can stop a hidden page with no `pagehide`. On `pagehide`, `freeze` or OpenFin close, it sends pending records with `navigator.sendBeacon` if they are below 60 KB. With `headers`, it uses a keepalive fetch with the last headers, because a beacon cannot set a header. A larger payload goes to the emergency queue. `shutdown()` runs a normal flush before the exit flush. It then cancels a request that is still open. A stored batch of that request stays in storage. An action is an audit fact. When storage is over `retention.maxBatches` or over the quota of the browser, it removes the batches without an action first. Before startup, the hold buffers keep up to 2000 actions. The 500-record limit applies only to other records. `onDrop` tells the app about each loss.
803
- - **Server (Node):** On Node, for example during server-side rendering, the library runs console-only. It installs no capture, keeps the ids in memory, uses no storage and has no exit flush. If you set `endpoint`, `metricsEndpoint`, `tracesEndpoint` or `transport`, it reports `config.invalid` one time.
804
- - **One library version on a page:** If a copy of another version owns the page runtime, this copy runs console-only. It installs no capture and reports `runtime.version_mismatch`. Load one version of the library on the page.
805
- - **Emergency queue:** The emergency queue is best effort. With `storage: "memory"` or `"none"`, the exit flush does not use it. A batch that it cannot send is then lost, and `onDrop` reports `not_stored`. It writes to `localStorage` synchronously, because no other storage works while the page unloads. If the browser refuses the write, the library reports `storage.quota_exceeded`. The library then loses the batch.
806
- - **Configuration after startup:** A second `configure()` call merges accepted options into an unlocked live runtime. Isolation is on by default. Then `configure()` refuses changes to delivery settings and to the context ID. It keeps the current values, reports `config.invalid` and applies the other settings. Use `rotateSecurityContext()` for these changes. `securityContext.isolation: false` restores ordinary mutable routing. The runtime also refuses these 6 changes and reports `config.invalid` for each:
807
- - A change to `storage`. The stored batches stay in the adapter that the runtime built at startup.
808
- - A change to `identity`. The ids exist from startup.
809
- - A change to `batching` or `retention` after the delivery stack loads. The stack reads them one time.
810
- - A change to `limits` or `journey.maxAgeMs` after the first `configure()`. The record builder and the journey engine read them one time.
811
- - A change to `profiler.maxProbes` after the first `configure()`. The profiler sets the size of its typed arrays from the startup value.
812
- - An `endpoint` change to `null` or `""` after the delivery stack loads. Without an endpoint, the stored batches would be lost. With isolation off, a change to another endpoint URL is accepted.
813
- - **Deterministic sampling:** FNV-1a hashing applies one keep rate to a whole journey. Sampling always keeps an explicit action and each record at or above `sampling.alwaysSampleFrom`, default `"ERROR"`.
154
+ [Registered bus sources](docs/runtime-policies.md#registered-bus-sources) gives the permissions of a child. [Guides](docs/guides.md) also has [Testing](docs/guides.md#testing) and [Remote Sampling](docs/guides.md#remote-sampling). [Production recipes](docs/production-recipes.md) has login, logout, tenant rotation, token refresh and consent withdrawal.
814
155
 
815
156
  ---
816
157
 
817
- ## Ingest Server Requirements
818
-
819
- The ingest server must meet these requirements:
820
-
821
- 1. **Protocol:** Accept `POST` with `Content-Type: application/json` or `text/plain;charset=UTF-8`. `sendBeacon` sends the second one to avoid a CORS preflight.
822
- 2. **Preflight:** Answer `OPTIONS` on the ingest path, and allow the request headers:
823
-
824
- ```http
825
- Access-Control-Allow-Headers: content-type, content-encoding, x-uiobs-batch-id, x-uiobs-attempt
826
- ```
827
-
828
- - The transport sends `X-UiObs-Batch-Id` and `X-UiObs-Attempt` with each batch.
829
- - Above 1 KiB, it also sends `Content-Encoding: gzip`.
830
- - Each of these headers causes a CORS preflight. If the server does not allow them, each preflight fails.
831
- - After a failed preflight, the library tries the batch 5 more times. It then drops the batch.
832
- - Only the beacon records of the exit flush arrive, because a beacon sends no custom header.
833
-
834
- 3. **Deduplication:** Deduplicate on the `X-UiObs-Batch-Id` header and the `uiobs_batch_id` query parameter. Keep the ids for at least 24 hours.
835
- 4. **Throttling:** Return `429` or `503` with `Retry-After`. Expose the header with `Access-Control-Expose-Headers: retry-after`. The library waits 60 s at most.
836
- 5. **Status codes:** `200`, `202` and `204` accept the batch. `413` makes the library split the batch. With a `headers` function, a `401` or `403` gets one more send with new headers. The library drops a batch that gets any other `4xx`.
837
- 6. **Metrics and traces endpoints (optional):** With `metricsEndpoint`, the library sends each batch of metric records there as an OTLP/JSON `ExportMetricsServiceRequest`. With `tracesEndpoint`, it sends each batch of span records there as an OTLP/JSON `ExportTraceServiceRequest`. The rules 1 to 5 also apply to these endpoints. A throttle or a failed batch of one endpoint does not hold back the batches of another endpoint. `headers` applies to each endpoint. Each point is a delta from the previous point of its attribute set. A histogram point with a negative value has no `sum`.
838
- 7. **Remote sampling (optional):** To send sampling rules, add `X-UiObs-Sampling` to a `2xx` answer. Expose the header with `Access-Control-Expose-Headers: x-uiobs-sampling`.
839
- 8. **Clock offset (optional):** Expose the `Date` header with `Access-Control-Expose-Headers: date`. Each later log and span record then carries `uiobs.clock_offset_ms`.
840
-
841
- **Replay endpoint (only with `replay.endpoint`).** It is a separate URL. It gets one `POST` for each segment of the session replay.
842
-
843
- - The body is JSON, with `Content-Encoding: gzip` when `compression` is `gzip`. It has `replay.id`, `session.id`, `tab.id`, `service.name`, `sequence`, `bytes` and `events`. `events` is the list of recorder events.
844
- - The request has `X-UiObs-Batch-Id` with the value `<replay.id>-<sequence>`, `X-UiObs-Attempt` and the headers of your `replay.headers` option. Allow them in the preflight, as for the log endpoint. Store a segment one time for each batch id.
845
- - Answer `2xx` for a stored segment. The library sends a segment again after `429`, `5xx`, `401` and `403`. It drops a segment after another `4xx` status.
846
- - Accept a large body. The first segment of an upload has a full snapshot of the page. One snapshot of a page with 35,000 table cells was 4.7 MB of JSON. The library does not split one event.
847
- - Keep the segments of one `replay.id` in the order of `sequence`. A player needs the segment with the full snapshot before the later segments.
848
- - `tools/mock-ingest-server.mjs` and `tools/reference-collector.mjs` accept `/v1/replay` and print one line for each segment. The reference collector accepts a replay body of at most `MAX_REPLAY_BODY_BYTES` (16 MB by default). `uiobs doctor` tests the replay endpoint with the option `--replay`. See [Check an ingest server](#check-an-ingest-server).
849
-
850
- `tools/reference-collector.mjs` implements each rule with no dependencies. It is not part of the package. Run `node tools/reference-collector.mjs`. Set `ALLOWED_ORIGINS` to the origins of your app. Set `UPSTREAM_URL` to an OTLP/HTTP collector, for example `http://localhost:4318`, to forward each OTLP batch there. The file lists the other settings: `PORT`, `AUTH_TOKEN`, `SAMPLING_RULES`, `MAX_BODY_BYTES` and `MAX_REQUESTS_PER_SECOND`.
851
-
852
- ### Check an ingest server
853
-
854
- Run the command line tool against your ingest URL. Give the origin of your app.
855
-
856
- ```bash
857
- pnpm dlx @utk09/ui-observability doctor https://ingest.example/v1/logs --origin https://app.example
858
- ```
859
-
860
- The tool prints `PASS` or `FAIL` for each rule. The exit code is 0 when each rule passes, 1 when a rule fails and 2 for a wrong command.
861
-
862
- | Rule | Check |
863
- | ----------------- | ------------------------------------------------------------------------------------------------ |
864
- | `preflight` | `OPTIONS` answers with a `2xx` status and permits the origin. |
865
- | `allowed headers` | The preflight allows each request header of the library. |
866
- | `test batch` | A `POST` of an OTLP batch gets a `2xx` status and permits the origin. |
867
- | `exposed headers` | The batch answer exposes `Retry-After`. The output names optional headers that stay hidden. |
868
- | `gzip` | A `POST` with `Content-Encoding: gzip` gets a `2xx` status. |
869
- | `deduplication` | A second `POST` with the same `X-UiObs-Batch-Id` gets a `2xx` status. |
870
- | `beacon` | A `POST` with `Content-Type: text/plain;charset=UTF-8` and no custom header gets a `2xx` status. |
871
-
872
- - The tool sends real test batches. Each record has `service.name: "uiobs-doctor"`. Expect four test batches in the store of the server.
873
- - The `beacon` batch has its batch id in `uiobs_batch_id` and the reason `pagehide` in `uiobs_exit`, as in the exit flush of the library.
874
- - The tool sends no credentials by default. Add a request header with `--header "Name: value"`. You can give the option more than one time.
875
-
876
- ```bash
877
- pnpm dlx @utk09/ui-observability doctor https://ingest.example/v1/logs --origin https://app.example --header "Authorization: Bearer $TOKEN"
878
- ```
879
-
880
- - The tool sends each custom header with each batch. The preflight names the header, and `allowed headers` tests that the server allows it.
881
- - With a custom header, the tool sends no beacon. The exit flush of the library then uses a keepalive fetch, because `sendBeacon` cannot set a header.
882
-
883
- To test a replay endpoint, give the value of `replay.endpoint` and add `--replay` directly after the origin. Give each header of your `replay.headers` option with `--header`.
884
-
885
- ```bash
886
- pnpm dlx @utk09/ui-observability doctor https://ingest.example/v1/replay --origin https://app.example --replay
887
- ```
888
-
889
- | Rule | Check |
890
- | ----------------- | ------------------------------------------------------------------------ |
891
- | `preflight` | `OPTIONS` answers with a `2xx` status and permits the origin. |
892
- | `allowed headers` | The preflight allows each request header of the library. |
893
- | `test segment` | A `POST` of a small segment gets a `2xx` status and permits the origin. |
894
- | `gzip` | A `POST` of a segment with `Content-Encoding: gzip` gets a `2xx` status. |
895
- | `large segment` | A `POST` of a segment of 5 MB without gzip gets a `2xx` status. |
896
- | `deduplication` | A second `POST` with the same `X-UiObs-Batch-Id` gets a `2xx` status. |
897
-
898
- - The tool sends four real test segments with one `replay.id`. Each segment has `service.name: "uiobs-doctor"` and one custom event of the recorder. One segment has 5 MB.
899
- - The `large segment` rule finds a body limit that is too low. The library drops a segment after a `413` status, and the first segment of an upload has a full snapshot of the page.
900
- - The tool sends no beacon to a replay endpoint, because the exit flush sends no segment.
901
- - The tool prints no header value. A header value stays in the history of your shell. Use an environment variable for a token.
902
- - A custom header cannot have the name of a header that the tool sets, for example `Content-Type` or `Origin`.
903
- - A client cannot see the store of the server. `deduplication` proves only that the server accepts a repeated id.
904
- - The tool follows no redirect. A `3xx` answer is a failure, because a browser refuses a preflight that redirects.
905
- - An origin has no path and no trailing slash. A wrong command prints the usage and the arguments that the tool received.
906
- - The tool needs Node 22.22.3 or later.
158
+ ## Documentation
159
+
160
+ | Document | Content |
161
+ | --- | --- |
162
+ | [API Reference](docs/api.md) | Each exported function, the delivery health, the flush result and the shutdown options. |
163
+ | [Configuration Options](docs/configuration.md) | Each config key and its default, auto-capture, spans and the browser storage keys. |
164
+ | [Guides](docs/guides.md) | Console output, custom transport, worker transport, testing and remote sampling. |
165
+ | [Production recipes](docs/production-recipes.md) | Login, logout, tenant rotation, token refresh, consent withdrawal and the initialization order. |
166
+ | [Ingest Server Requirements](docs/ingest-server.md) | The ingest contract and the `uiobs doctor` check of an ingest server. |
167
+ | [Migration to 1.0.0](docs/migration-v1.md) | Each change from 0.12.x, with the new code. |
168
+ | [Release and support](docs/release-and-support.md) | The stable API contract, the supported environments and the release evidence. |
169
+ | [Runtime policies and migration](docs/runtime-policies.md) | Each default, each range, security-context rotation and the upgrade steps. |
170
+ | [Delivery guarantees](docs/delivery-guarantees.md) | Duplicates, order, each loss and its `onDrop` reason, retention, the exit flush and rotation. |
171
+ | [Attribute reference](docs/attributes.md) | Each attribute that the library writes, and its type. |
172
+ | [Browser support](docs/browser-support.md) | The minimum browser versions, the browser APIs that the library uses, and the fallback for each. |
173
+ | [Architecture](docs/architecture.md) | The core architecture, the layers of the library and the path of a record. |
174
+ | [Threat model](docs/threat-model.md) | The trust boundaries, the threats and the controls. |
175
+ | [Performance](docs/performance.md) | The release benchmark, its baselines and its budgets. |
176
+ | [Development](docs/development.md) | The workspace, the checks and the example applications. |
177
+ | [Browser tests](e2e/README.md) | The Playwright tests and the coverage that is still missing. |
178
+ | [Collector check](e2e/collector/README.md) | The check against a pinned OpenTelemetry Collector. |
179
+ | [Playground guide](playground/README.md) | The six example applications and how to start each one. |
180
+ | [Security policy](SECURITY.md) | How to report a vulnerability. |
181
+ | [llms.txt](llms.txt) | A summary of the library for a large language model. The package includes it. |
907
182
 
908
183
  ---
909
184
 
910
185
  ## Development
911
186
 
912
- Use Node 22.22.3 or later and pnpm 12.18.0. `.nvmrc` selects the minimum Node version.
913
- The `packageManager` field pins pnpm. See the [pnpm installation instructions](https://pnpm.io/installation).
914
- Angular supports Node `^22.22.3 || ^24.15.0 || >=26.0.0`.
915
- Use one of these Node versions for the complete workspace.
916
-
917
- Install from the repository root. The first pnpm install creates `pnpm-lock.yaml`.
918
- Commit that file with dependency changes. Use `pnpm install --frozen-lockfile` for later installs that must keep the resolved versions.
919
-
920
- `pnpm-workspace.yaml` holds separate catalogs for `library`, `vanilla`, `react`, `angular`, `console-only`, `mf-host`, `mf-blotter` and `mf-ticket`.
921
- Each manifest uses its named catalog for external dependencies.
922
- The consumer playgrounds use `workspace:*` for the local library. The vanilla playground loads the library source.
923
- Change versions in the relevant catalog, then run `pnpm install`.
924
-
925
- Dependency versions use the current stable releases checked on 2026-11-07.
926
- TypeScript uses 6.0.3 because Angular 22 and typescript-eslint require TypeScript below 6.1.
927
- The workspace enables install scripts for `@parcel/watcher`, `esbuild`, `fsevents`, `lmdb` and `msgpackr-extract`.
187
+ To work on this repository, use Node 22.22.3 or later and pnpm 12.21.0. An app that uses the package can use Node 22 or later.
928
188
 
929
189
  ```bash
930
190
  pnpm install
931
- pnpm run dev # Playground, mock ingest server and iframe host
932
- pnpm run verify # Format check, typecheck, build, lint, peer, size and dev-server checks, tests
933
- ```
934
-
935
- - Vanilla playground: `http://localhost:5173/playground/vanilla/index.html`. Add `?worker=1` to send through the transport worker.
936
- - Mock ingest server: `http://localhost:8787`. It accepts `/v1/logs`, `/v1/metrics` and `/v1/traces`. It prints one line for each record and for each metric point.
937
- - Cross-origin child frame: `http://localhost:5174`. The vanilla playground registers it and its same-origin child frame before they load.
938
- - The React example sends its counter, histogram and HTTP duration points to `/v1/metrics`.
939
- - After a build, run `node bin/uiobs.mjs doctor http://localhost:8787/v1/logs --origin http://localhost:5173` to test the command line tool on the mock server.
940
-
941
- After dependency changes, run these checks:
942
-
943
- ```bash
944
- pnpm run lint:fix
945
- pnpm run format
946
- pnpm run verify
947
- pnpm --filter './playground/**' --if-present run build
191
+ pnpm run dev # Playground, mock ingest server and iframe host
192
+ pnpm run verify # Format check, typecheck, build, lint, peer, size, dev-server and consumer checks, tests
948
193
  ```
949
194
 
950
- `verify` checks the library. The last command builds each consumer playground that has a build script.
951
- Check the vanilla frames, React and Angular in a browser before a release.
952
- To clear the React dependency cache, run `pnpm --filter @example/react run dev --force`.
953
-
954
- ### Example Applications
955
-
956
- Build the package first:
957
-
958
- ```bash
959
- pnpm run build
960
- pnpm run example:react # http://localhost:5180
961
- pnpm run example:angular # http://localhost:4200
962
- pnpm run example:microfrontend # Shell on http://localhost:5191, remotes on 5192 and 5193
963
- pnpm run example:console-only # http://localhost:5195
964
- ```
195
+ [Development](docs/development.md) gives the workspace rules, the release checks and the example applications.
965
196
 
966
197
  ---
967
198