@utk09/ui-observability 0.10.0 → 0.11.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 (186) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/README.md +50 -11
  3. package/dist/{batch-BHXypM1j.cjs → batch-C8OcWR2L.cjs} +2 -2
  4. package/dist/{batch-BHXypM1j.cjs.map → batch-C8OcWR2L.cjs.map} +1 -1
  5. package/dist/{batch-BMdT9mKm.js → batch-CL9uWYY3.js} +4 -5
  6. package/dist/{batch-BMdT9mKm.js.map → batch-CL9uWYY3.js.map} +1 -1
  7. package/dist/{bus-DKfBaica.js → bus-BZ0GldpT.js} +23 -27
  8. package/dist/{bus-DKfBaica.js.map → bus-BZ0GldpT.js.map} +1 -1
  9. package/dist/{bus-Dea9rVhy.cjs → bus-VWlmM5xs.cjs} +2 -2
  10. package/dist/{bus-Dea9rVhy.cjs.map → bus-VWlmM5xs.cjs.map} +1 -1
  11. package/dist/console-BPZCuSLc.cjs +2 -0
  12. package/dist/{console-DZEcs7FL.cjs.map → console-BPZCuSLc.cjs.map} +1 -1
  13. package/dist/{console-BX_0UCV7.js → console-BeCF7n59.js} +14 -15
  14. package/dist/{console-BX_0UCV7.js.map → console-BeCF7n59.js.map} +1 -1
  15. package/dist/{constants-CL0ZdI2f.cjs → constants-DqKJH_MP.cjs} +2 -2
  16. package/dist/{constants-CL0ZdI2f.cjs.map → constants-DqKJH_MP.cjs.map} +1 -1
  17. package/dist/{constants-CU60FG4w.js → constants-zyrqveN4.js} +3 -4
  18. package/dist/{constants-CU60FG4w.js.map → constants-zyrqveN4.js.map} +1 -1
  19. package/dist/context-storage-BjzeBSxH.cjs.map +1 -1
  20. package/dist/{context-storage-DxZf4Gfh.js → context-storage-BzkoHzkQ.js} +2 -3
  21. package/dist/{context-storage-DxZf4Gfh.js.map → context-storage-BzkoHzkQ.js.map} +1 -1
  22. package/dist/{deadline-5_PecIl5.js → deadline-BOjOxNHj.js} +3 -5
  23. package/dist/{deadline-5_PecIl5.js.map → deadline-BOjOxNHj.js.map} +1 -1
  24. package/dist/deadline-XSnm95pg.cjs.map +1 -1
  25. package/dist/{debug-bundle-yRkrU1ny.cjs → debug-bundle-BzJNpbF0.cjs} +2 -2
  26. package/dist/{debug-bundle-yRkrU1ny.cjs.map → debug-bundle-BzJNpbF0.cjs.map} +1 -1
  27. package/dist/{debug-bundle-CZZ6SQQh.js → debug-bundle-C7UkHZ-q.js} +5 -6
  28. package/dist/{debug-bundle-CZZ6SQQh.js.map → debug-bundle-C7UkHZ-q.js.map} +1 -1
  29. package/dist/doctor.cjs +1 -1
  30. package/dist/doctor.cjs.map +1 -1
  31. package/dist/doctor.js +3 -4
  32. package/dist/{emergency-queue-CQ-9acZf.cjs → emergency-queue-CNTRui5t.cjs} +2 -2
  33. package/dist/{emergency-queue-CQ-9acZf.cjs.map → emergency-queue-CNTRui5t.cjs.map} +1 -1
  34. package/dist/{emergency-queue-Cs8-i2xw.js → emergency-queue-Zy6lNafo.js} +15 -17
  35. package/dist/{emergency-queue-Cs8-i2xw.js.map → emergency-queue-Zy6lNafo.js.map} +1 -1
  36. package/dist/{error-like-Ywo5uRHo.js → error-like-B11pB4aL.js} +2 -3
  37. package/dist/{error-like-Ywo5uRHo.js.map → error-like-B11pB4aL.js.map} +1 -1
  38. package/dist/error-like-gGRx2s36.cjs.map +1 -1
  39. package/dist/{errors-oyxrpHjY.js → errors-Dh7kef0i.js} +5 -6
  40. package/dist/{errors-oyxrpHjY.js.map → errors-Dh7kef0i.js.map} +1 -1
  41. package/dist/{errors-CigX45pL.cjs → errors-tfEr48bS.cjs} +2 -2
  42. package/dist/{errors-CigX45pL.cjs.map → errors-tfEr48bS.cjs.map} +1 -1
  43. package/dist/{factory-Bgsky_e0.js → factory-BonqI3NL.js} +9 -13
  44. package/dist/{factory-Bgsky_e0.js.map → factory-BonqI3NL.js.map} +1 -1
  45. package/dist/{factory-BkjNzPYL.cjs → factory-CJXVYp0R.cjs} +2 -2
  46. package/dist/{factory-BkjNzPYL.cjs.map → factory-CJXVYp0R.cjs.map} +1 -1
  47. package/dist/fixed-window-CvESpFYV.cjs.map +1 -1
  48. package/dist/{fixed-window-CtaFHanJ.js → fixed-window-Dq3MLUUv.js} +2 -3
  49. package/dist/{fixed-window-CtaFHanJ.js.map → fixed-window-Dq3MLUUv.js.map} +1 -1
  50. package/dist/global-scope-BN-Io_yv.cjs.map +1 -1
  51. package/dist/{global-scope-dp2jADRl.js → global-scope-D9I8s-oN.js} +2 -3
  52. package/dist/{global-scope-dp2jADRl.js.map → global-scope-D9I8s-oN.js.map} +1 -1
  53. package/dist/{guards-CpvOpJL6.js → guards-Cidk71ME.js} +2 -3
  54. package/dist/{guards-CpvOpJL6.js.map → guards-Cidk71ME.js.map} +1 -1
  55. package/dist/guards-nJ70syPt.cjs.map +1 -1
  56. package/dist/{identity-BMlKGHUM.cjs → identity-Cxgj6pZX.cjs} +2 -2
  57. package/dist/{identity-BMlKGHUM.cjs.map → identity-Cxgj6pZX.cjs.map} +1 -1
  58. package/dist/{identity-DOaHdfhT.js → identity-DT5VmvXy.js} +3 -4
  59. package/dist/{identity-DOaHdfhT.js.map → identity-DT5VmvXy.js.map} +1 -1
  60. package/dist/index.cjs +1 -1
  61. package/dist/index.cjs.map +1 -1
  62. package/dist/index.js +46 -56
  63. package/dist/index.js.map +1 -1
  64. package/dist/{indexeddb-storage-D-lUW_5P.js → indexeddb-storage-BJVtiQKm.js} +5 -6
  65. package/dist/{indexeddb-storage-D-lUW_5P.js.map → indexeddb-storage-BJVtiQKm.js.map} +1 -1
  66. package/dist/{indexeddb-storage-CaXGJqDD.cjs → indexeddb-storage-CIoW21Xd.cjs} +2 -2
  67. package/dist/{indexeddb-storage-CaXGJqDD.cjs.map → indexeddb-storage-CIoW21Xd.cjs.map} +1 -1
  68. package/dist/{interactions-CqDNrtIR.js → interactions-DTgKy_6K.js} +10 -11
  69. package/dist/{interactions-CqDNrtIR.js.map → interactions-DTgKy_6K.js.map} +1 -1
  70. package/dist/{interactions-8DgxtmgO.cjs → interactions-fEN6FbVo.cjs} +2 -2
  71. package/dist/{interactions-8DgxtmgO.cjs.map → interactions-fEN6FbVo.cjs.map} +1 -1
  72. package/dist/{journey-DgIjhrIc.js → journey-CuJrHzEg.js} +9 -10
  73. package/dist/{journey-DgIjhrIc.js.map → journey-CuJrHzEg.js.map} +1 -1
  74. package/dist/{journey-5tcxEbnG.cjs → journey-pffMVMfa.cjs} +2 -2
  75. package/dist/{journey-5tcxEbnG.cjs.map → journey-pffMVMfa.cjs.map} +1 -1
  76. package/dist/keys-BHhw_0Wh.cjs.map +1 -1
  77. package/dist/{keys-D5r_GH9q.js → keys-BU9j5YqW.js} +2 -3
  78. package/dist/{keys-D5r_GH9q.js.map → keys-BU9j5YqW.js.map} +1 -1
  79. package/dist/library-console-C1m6g1BR.js +13 -0
  80. package/dist/{library-console-CabK2j2-.js.map → library-console-C1m6g1BR.js.map} +1 -1
  81. package/dist/{library-console-g_VU-wzP.cjs → library-console-D2GY9Or6.cjs} +2 -2
  82. package/dist/{library-console-g_VU-wzP.cjs.map → library-console-D2GY9Or6.cjs.map} +1 -1
  83. package/dist/{library-request-FQaiWjCP.cjs → library-request-1BX_UlaX.cjs} +2 -2
  84. package/dist/{library-request-FQaiWjCP.cjs.map → library-request-1BX_UlaX.cjs.map} +1 -1
  85. package/dist/{library-request-CyC-9IOk.js → library-request-BQBT9N9Q.js} +4 -5
  86. package/dist/{library-request-CyC-9IOk.js.map → library-request-BQBT9N9Q.js.map} +1 -1
  87. package/dist/{lifecycle-C2z_d8OX.cjs → lifecycle-2EtUaRpo.cjs} +2 -2
  88. package/dist/{lifecycle-C2z_d8OX.cjs.map → lifecycle-2EtUaRpo.cjs.map} +1 -1
  89. package/dist/{lifecycle-BLC4VU7c.js → lifecycle-BaKx_-32.js} +3 -4
  90. package/dist/{lifecycle-BLC4VU7c.js.map → lifecycle-BaKx_-32.js.map} +1 -1
  91. package/dist/{log-record-CndanC-p.js → log-record-CAoGBBf3.js} +3 -4
  92. package/dist/{log-record-CndanC-p.js.map → log-record-CAoGBBf3.js.map} +1 -1
  93. package/dist/{log-record-DKvo-B-d.cjs → log-record-i9zOTkpQ.cjs} +2 -2
  94. package/dist/{log-record-DKvo-B-d.cjs.map → log-record-i9zOTkpQ.cjs.map} +1 -1
  95. package/dist/{long-frames-CV5ZG2cx.cjs → long-frames-BVg4i5SC.cjs} +2 -2
  96. package/dist/{long-frames-CV5ZG2cx.cjs.map → long-frames-BVg4i5SC.cjs.map} +1 -1
  97. package/dist/{long-frames-BQef9rXR.js → long-frames-Czk7IupC.js} +4 -5
  98. package/dist/{long-frames-BQef9rXR.js.map → long-frames-Czk7IupC.js.map} +1 -1
  99. package/dist/{network-CvkvYzRU.js → network-DBNwApoF.js} +22 -24
  100. package/dist/{network-CvkvYzRU.js.map → network-DBNwApoF.js.map} +1 -1
  101. package/dist/{network-CqnQOqon.cjs → network-xbbuvG_6.cjs} +2 -2
  102. package/dist/{network-CqnQOqon.cjs.map → network-xbbuvG_6.cjs.map} +1 -1
  103. package/dist/openfin-Bxelt0yg.js +7 -0
  104. package/dist/{openfin-BwEN0uj4.js.map → openfin-Bxelt0yg.js.map} +1 -1
  105. package/dist/openfin-DtH2f7zX.cjs.map +1 -1
  106. package/dist/{otlp-RVbkNQRh.cjs → otlp-BDvFrLnc.cjs} +2 -2
  107. package/dist/{otlp-RVbkNQRh.cjs.map → otlp-BDvFrLnc.cjs.map} +1 -1
  108. package/dist/{otlp-CYIL7MOE.js → otlp-BTJdIa6F.js} +4 -6
  109. package/dist/{otlp-CYIL7MOE.js.map → otlp-BTJdIa6F.js.map} +1 -1
  110. package/dist/patch-BX8KrPCT.cjs.map +1 -1
  111. package/dist/{patch-CCWfuEY7.js → patch-UdPz1ea8.js} +2 -3
  112. package/dist/{patch-CCWfuEY7.js.map → patch-UdPz1ea8.js.map} +1 -1
  113. package/dist/{platform-KMWkoI-v.cjs → platform-C2Ez5kDc.cjs} +2 -2
  114. package/dist/{platform-KMWkoI-v.cjs.map → platform-C2Ez5kDc.cjs.map} +1 -1
  115. package/dist/{platform-wcAkkv9F.js → platform-DkcuXwe-.js} +4 -5
  116. package/dist/{platform-wcAkkv9F.js.map → platform-DkcuXwe-.js.map} +1 -1
  117. package/dist/{remote-rules-CH_7PphT.js → remote-rules-Cfb4K-Nl.js} +5 -6
  118. package/dist/{remote-rules-CH_7PphT.js.map → remote-rules-Cfb4K-Nl.js.map} +1 -1
  119. package/dist/{remote-rules-BL8km4xk.cjs → remote-rules-vzvk7aKf.cjs} +2 -2
  120. package/dist/{remote-rules-BL8km4xk.cjs.map → remote-rules-vzvk7aKf.cjs.map} +1 -1
  121. package/dist/{reports-Bh_-KpZ2.cjs → reports-Dk2YhKIh.cjs} +2 -2
  122. package/dist/{reports-Bh_-KpZ2.cjs.map → reports-Dk2YhKIh.cjs.map} +1 -1
  123. package/dist/{reports-BOKyY3_A.js → reports-TA-zInnq.js} +4 -5
  124. package/dist/{reports-BOKyY3_A.js.map → reports-TA-zInnq.js.map} +1 -1
  125. package/dist/{resource-timing-BROnEJ0E.js → resource-timing-BLv3EA2A.js} +6 -7
  126. package/dist/{resource-timing-BROnEJ0E.js.map → resource-timing-BLv3EA2A.js.map} +1 -1
  127. package/dist/{resource-timing-CbgwNpog.cjs → resource-timing-Cysw1S1f.cjs} +2 -2
  128. package/dist/{resource-timing-CbgwNpog.cjs.map → resource-timing-Cysw1S1f.cjs.map} +1 -1
  129. package/dist/{sampling-BLO_pcV4.js → sampling-C4VV-1MS.js} +4 -5
  130. package/dist/{sampling-BLO_pcV4.js.map → sampling-C4VV-1MS.js.map} +1 -1
  131. package/dist/{sampling-ECGVYiDD.cjs → sampling-Ckh2yW9k.cjs} +2 -2
  132. package/dist/{sampling-ECGVYiDD.cjs.map → sampling-Ckh2yW9k.cjs.map} +1 -1
  133. package/dist/{sanitize-DS0G4_ea.js → sanitize-6ymPlVvP.js} +4 -5
  134. package/dist/{sanitize-DS0G4_ea.js.map → sanitize-6ymPlVvP.js.map} +1 -1
  135. package/dist/{sanitize-Bsn8HQWC.cjs → sanitize-BAWzkZt0.cjs} +2 -2
  136. package/dist/{sanitize-Bsn8HQWC.cjs.map → sanitize-BAWzkZt0.cjs.map} +1 -1
  137. package/dist/{select-DWO0-w8_.cjs → select-ZF4by-lF.cjs} +2 -2
  138. package/dist/{select-DWO0-w8_.cjs.map → select-ZF4by-lF.cjs.map} +1 -1
  139. package/dist/{select-wqt9Wxio.js → select-xtQaenIi.js} +7 -10
  140. package/dist/{select-wqt9Wxio.js.map → select-xtQaenIi.js.map} +1 -1
  141. package/dist/{sender-BkAVt-Rq.js → sender-CiMHC9YG.js} +92 -96
  142. package/dist/{sender-BkAVt-Rq.js.map → sender-CiMHC9YG.js.map} +1 -1
  143. package/dist/{sender-D82PxlCY.cjs → sender-D5wBoXA8.cjs} +2 -2
  144. package/dist/{sender-D82PxlCY.cjs.map → sender-D5wBoXA8.cjs.map} +1 -1
  145. package/dist/storage-BA9RqRO-.cjs.map +1 -1
  146. package/dist/{storage-w7Tslvlq.js → storage-DZwed89z.js} +2 -3
  147. package/dist/{storage-w7Tslvlq.js.map → storage-DZwed89z.js.map} +1 -1
  148. package/dist/{storm-DCEsqViG.cjs → storm-CYi9Swpx.cjs} +2 -2
  149. package/dist/{storm-DCEsqViG.cjs.map → storm-CYi9Swpx.cjs.map} +1 -1
  150. package/dist/{storm-DD4cUkoL.js → storm-VR024_QN.js} +4 -5
  151. package/dist/{storm-DD4cUkoL.js.map → storm-VR024_QN.js.map} +1 -1
  152. package/dist/{types-BR9t_w28.js → types-BAerHgCq.js} +2 -3
  153. package/dist/{types-BR9t_w28.js.map → types-BAerHgCq.js.map} +1 -1
  154. package/dist/types-C7WNpnG1.cjs.map +1 -1
  155. package/dist/{unclean-exit-BYZ5yaSI.js → unclean-exit-CwcUhFOn.js} +3 -4
  156. package/dist/{unclean-exit-BYZ5yaSI.js.map → unclean-exit-CwcUhFOn.js.map} +1 -1
  157. package/dist/{unclean-exit-CwdpbUDg.cjs → unclean-exit-DFUN57wY.cjs} +2 -2
  158. package/dist/{unclean-exit-CwdpbUDg.cjs.map → unclean-exit-DFUN57wY.cjs.map} +1 -1
  159. package/dist/{user-timing-C1kB3JEg.cjs → user-timing-C9kfRq3J.cjs} +2 -2
  160. package/dist/{user-timing-C1kB3JEg.cjs.map → user-timing-C9kfRq3J.cjs.map} +1 -1
  161. package/dist/{user-timing-Di2ra5DB.js → user-timing-_jZIhDKI.js} +4 -5
  162. package/dist/{user-timing-Di2ra5DB.js.map → user-timing-_jZIhDKI.js.map} +1 -1
  163. package/dist/{web-socket-DwBNhgre.cjs → web-socket-BWUoqBh8.cjs} +2 -2
  164. package/dist/{web-socket-DwBNhgre.cjs.map → web-socket-BWUoqBh8.cjs.map} +1 -1
  165. package/dist/{web-socket-B-5qqPy7.js → web-socket-CV7yIMnm.js} +14 -15
  166. package/dist/{web-socket-B-5qqPy7.js.map → web-socket-CV7yIMnm.js.map} +1 -1
  167. package/dist/{web-vitals-Bflr5jSA.js → web-vitals-Bq4WFHQo.js} +2 -3
  168. package/dist/{web-vitals-Bflr5jSA.js.map → web-vitals-Bq4WFHQo.js.map} +1 -1
  169. package/dist/web-vitals-DFuoTQbZ.cjs.map +1 -1
  170. package/dist/{worker-protocol-DXekoADQ.cjs → worker-protocol-Bai7GAIA.cjs} +2 -2
  171. package/dist/{worker-protocol-DXekoADQ.cjs.map → worker-protocol-Bai7GAIA.cjs.map} +1 -1
  172. package/dist/{worker-protocol-0HMf4-kY.js → worker-protocol-CrsdSDLn.js} +6 -7
  173. package/dist/{worker-protocol-0HMf4-kY.js.map → worker-protocol-CrsdSDLn.js.map} +1 -1
  174. package/dist/worker-server-BrIYkfoa.cjs +2 -0
  175. package/dist/{worker-server-BQK5z2yl.cjs.map → worker-server-BrIYkfoa.cjs.map} +1 -1
  176. package/dist/{worker-server-CKcmX5m5.js → worker-server-Dp5HYm4b.js} +25 -26
  177. package/dist/{worker-server-CKcmX5m5.js.map → worker-server-Dp5HYm4b.js.map} +1 -1
  178. package/dist/{worker-transport-Dj2yCQN5.cjs → worker-transport-Bwej4N2e.cjs} +2 -2
  179. package/dist/{worker-transport-Dj2yCQN5.cjs.map → worker-transport-Bwej4N2e.cjs.map} +1 -1
  180. package/dist/{worker-transport-2220ghFZ.js → worker-transport-D6jtgpqN.js} +9 -11
  181. package/dist/{worker-transport-2220ghFZ.js.map → worker-transport-D6jtgpqN.js.map} +1 -1
  182. package/package.json +27 -41
  183. package/dist/console-DZEcs7FL.cjs +0 -2
  184. package/dist/library-console-CabK2j2-.js +0 -14
  185. package/dist/openfin-BwEN0uj4.js +0 -8
  186. package/dist/worker-server-BQK5z2yl.cjs +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"remote-rules-CH_7PphT.js","names":["REMOTE_SAMPLING_MAX_CHARS","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","LEVEL_ORDER","isObject","levelFor","longestPrefix","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay.\n// The library does not write them into the config. A later configure() and the TTL then stay simple.\n// Only the lazy chunks import this class. The main bundle imports the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate for each namespace prefix. They apply over the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Each context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level that the library sends. It can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level for each namespace prefix. It can only lower the level of the config. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the shape of the header. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Slot of the runtime for the overlay. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** Remote sampling rules in force for this context. */\nexport class RemoteSampling {\n /** Rules in force, or null. */\n private rules: RemoteRules | null = null;\n\n /** Time that the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** Time that the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules in force. They replace the rules in force.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the rules in force.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off. Turning it on again must not bring them back.\n // Guard against a clock that moves back. The rules then stay longer than their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level that the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`. A remote level applies only when it is lower than the config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the config level of the namespace.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the rules in force in the shape of the header, with the remaining TTL.\n * @returns The rules, or null if no rules are in force.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them in force.\n// The sender and the bus import this module.\n// The main bundle does not include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** Failure of one validation step. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Tests if a value is a rate.\n * @param value Value to test.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Reads the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or is not JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is not valid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for each namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is not valid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && Object.hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @param maxRate Highest rate that a remote rule can set.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is not valid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (\n minLevel !== undefined &&\n !(typeof minLevel === \"string\" && Object.hasOwn(LEVEL_ORDER, minLevel))\n ) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. A rule that is not valid rejects all the rules.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are not valid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules in force in the slot of the runtime. It makes the overlay for the first rules.\n * @param slot Slot of the runtime.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":";;;;AAkDA,IAAaO,IAAb,MAA4B;CAaG;CAX7B,QAAoC;CAGpC,aAAqB;CAGrB,QAAgB;CAKhB,YAAY,GAAyC;EAAxB,KAAA,SAAAC;CAAyB;CAMtD,MAAM,GAAmC;EACvC,IAAI,CAACC,GAAQ;GACX,KAAK,QAAQ;GACb;EACF;EAEA,IAAMC,IAAM,KAAK,IAAI;EAIrB,AAFA,KAAK,QAAQD,EAAO,OACpB,KAAK,aAAaC,GAClB,KAAK,QAAQA,IAAMD,EAAO;CAC5B;CAMA,UAA8B;EAC5B,IAAI,CAAC,KAAK,OACR,OAAO;EAGT,IAAMC,IAAM,KAAK,IAAI;EASrB,OALI,CAAC,KAAK,OAAO,SAAS,UAAUA,IAAM,KAAK,cAAcA,KAAO,KAAK,SACvE,KAAK,QAAQ,MACN,QAGF,KAAK;CACd;CAQA,YAAY,GAA6B;EACvC,IAAMC,IAAQN,EAASO,GAAW,KAAK,MAAM,GACvCC,IAAQ,KAAK,QAAQ,GACrBC,IAASR,EAAcM,GAAWC,GAAO,aAAa,CAAC,CAAC,CAAC,EAAE,SAASA,GAAO;EAEjF,OAAOC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AAG,IAAIA,CAAG;CACjE,SAASC,GAAO;EACd,IAAMC,IAASD,aAAiBtB,IAAY,IAAIsB,EAAM,YAAY;EAQlE,OANAE,EAAY,OACV,kBACA,0DAA0DD,KAC1D,KAAA,GACAD,CACF,GACO;CACT;AACF;AAQA,SAAgBG,EACd,GACA,GACA,GACM;CAMN,AALI/B,MACF,EAAK,aAAa,IAAIF,EAAeC,CAAM,IAG7CiC,EAAK,UAAU,MAAMhC,CAAM,GAC3BgC,EAAK,UAAU;AACjB"}
1
+ {"version":3,"file":"remote-rules-Cfb4K-Nl.js","names":["REMOTE_SAMPLING_MAX_CHARS","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","LEVEL_ORDER","isObject","levelFor","longestPrefix","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay.\n// The library does not write them into the config. A later configure() and the TTL then stay simple.\n// Only the lazy chunks import this class. The main bundle imports the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate for each namespace prefix. They apply over the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Each context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level that the library sends. It can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level for each namespace prefix. It can only lower the level of the config. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the shape of the header. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Slot of the runtime for the overlay. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** Remote sampling rules in force for this context. */\nexport class RemoteSampling {\n /** Rules in force, or null. */\n private rules: RemoteRules | null = null;\n\n /** Time that the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** Time that the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules in force. They replace the rules in force.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the rules in force.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off. Turning it on again must not bring them back.\n // Guard against a clock that moves back. The rules then stay longer than their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level that the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`. A remote level applies only when it is lower than the config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the config level of the namespace.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the rules in force in the shape of the header, with the remaining TTL.\n * @returns The rules, or null if no rules are in force.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them in force.\n// The sender and the bus import this module.\n// The main bundle does not include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** Failure of one validation step. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Tests if a value is a rate.\n * @param value Value to test.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Reads the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or is not JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is not valid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for each namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is not valid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && Object.hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @param maxRate Highest rate that a remote rule can set.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is not valid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (\n minLevel !== undefined &&\n !(typeof minLevel === \"string\" && Object.hasOwn(LEVEL_ORDER, minLevel))\n ) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. A rule that is not valid rejects all the rules.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are not valid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules in force in the slot of the runtime. It makes the overlay for the first rules.\n * @param slot Slot of the runtime.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n\n slot.sampling?.apply(update);\n slot.changed?.();\n}\n"],"mappings":";;;;AAkDA,IAAaO,IAAb,MAA4B;CAaG;CAX7B,QAAoC;CAGpC,aAAqB;CAGrB,QAAgB;CAKhB,YAAY,GAAyC;EAAxB,KAAA,SAAAC;CAAyB;CAMtD,MAAM,GAAmC;EACvC,IAAI,CAACC,GAAQ;GACX,KAAK,QAAQ;GACb;EACF;EAEA,IAAMC,IAAM,KAAK,IAAI;EAIrB,AAFA,KAAK,QAAQD,EAAO,OACpB,KAAK,aAAaC,GAClB,KAAK,QAAQA,IAAMD,EAAO;CAC5B;CAMA,UAA8B;EAC5B,IAAI,CAAC,KAAK,OACR,OAAO;EAGT,IAAMC,IAAM,KAAK,IAAI;EASrB,OALI,CAAC,KAAK,OAAO,SAAS,UAAUA,IAAM,KAAK,cAAcA,KAAO,KAAK,SACvE,KAAK,QAAQ,MACN,QAGF,KAAK;CACd;CAQA,YAAY,GAA6B;EACvC,IAAMC,IAAQN,EAASO,GAAW,KAAK,MAAM,GACvCC,IAAQ,KAAK,QAAQ,GACrBC,IAASR,EAAcM,GAAWC,GAAO,aAAa,CAAC,CAAC,CAAC,EAAE,SAASA,GAAO;EAEjF,OAAOC,MAAW,KAAA,KAAaX,EAAYW,KAAUX,EAAYQ,KAASG,IAASH;CACrF;CAMA,OAA0B;EACxB,IAAME,IAAQ,KAAK,QAAQ;EAM3B,OAJKA,IAIE;GAAE,GAAGA;GAAO,GAAA;GAA4B,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ACT;AACF;AAQA,SAAgBG,EACd,GACA,GACA,GACM;CAMN,AALI/B,MACF,EAAK,aAAa,IAAIF,EAAeC,CAAM,IAG7CiC,EAAK,UAAU,MAAMhC,CAAM,GAC3BgC,EAAK,UAAU;AACjB"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-CL0ZdI2f.cjs"),t=require("./guards-nJ70syPt.cjs"),n=require("./sampling-ECGVYiDD.cjs");var r=class{config;rules=null;receivedAt=0;until=0;constructor(e){this.config=e}apply(e){if(!e){this.rules=null;return}let t=Date.now();this.rules=e.rules,this.receivedAt=t,this.until=t+e.ttlMs}current(){if(!this.rules)return null;let e=Date.now();return!this.config.sampling.remote||e<this.receivedAt||e>=this.until?(this.rules=null,null):this.rules}minLevelFor(t){let r=n.n(t,this.config),i=this.current(),a=n.r(t,i?.minLevels??{})?.value??i?.minLevel;return a!==void 0&&e.wt[a]<e.wt[r]?a:r}wire(){let e=this.current();return e?{...e,v:1,ttlMs:this.until-Date.now()}:null}},i=class extends Error{};function a(e){return typeof e==`number`&&e>=0&&e<=1}function o(t){if(t.length>4096)throw new i(`The header is longer than ${String(e.Jt)} characters.`);try{return JSON.parse(t)}catch{throw new i(`The header is not valid JSON.`)}}function s(e){if(e===void 0)return{};let n=`rates must be an object with at most 100 rates from 0 to 1.`;if(!t.t(e))throw new i(n);let r=Object.entries(e);if(r.length>100||!r.every(([,e])=>a(e)))throw new i(n);return Object.fromEntries(r)}function c(n){let r=`minLevels must be an object with at most 100 level names.`;if(!t.t(n))throw new i(r);let a=Object.entries(n),o=a.every(([,t])=>typeof t==`string`&&Object.hasOwn(e.wt,t));if(a.length>100||!o)throw new i(r);return Object.fromEntries(a)}function l(n){if(!t.t(n))throw new i(`The rules must be an object.`);if(n.v!==1)throw new i(`The version must be 1.`);let{ttlMs:r,defaultRate:o,minLevel:l}=n;if(typeof r!=`number`||!(r>0&&r<=36e5))throw new i(`ttlMs must be a number more than 0 and at most ${String(e.Yt)}.`);if(o!==void 0&&!a(o))throw new i(`defaultRate must be a number from 0 to 1.`);if(l!==void 0&&!(typeof l==`string`&&Object.hasOwn(e.wt,l)))throw new i(`minLevel must be a level name, for example DEBUG.`);let u={rates:s(n.rates)};if(o!==void 0&&(u.defaultRate=o),l!==void 0&&(u.minLevel=l),n.minLevels!==void 0&&(u.minLevels=c(n.minLevels)),n.capture!==void 0){let r=n.capture;if(!t.t(r))throw new i(`capture must be an object of capture switches.`);let a=Object.entries(r);if(!a.every(([t,n])=>e.qt.some(e=>e===t)&&typeof n==`boolean`))throw new i(`capture must contain boolean capture switches without privacy controls.`);u.capture=Object.fromEntries(a)}return{rules:u,ttlMs:r}}function u(e,t){try{return l(typeof e==`string`?o(e):e)}catch(e){let n=e instanceof i?` ${e.message}`:``;return t.report(`config.invalid`,`The library ignores the sampling rules from the server.${n}`,void 0,e),null}}function d(e,t,n){n&&(e.sampling??=new r(t)),e.sampling?.apply(n),e.changed?.()}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
2
- //# sourceMappingURL=remote-rules-BL8km4xk.cjs.map
1
+ const e=require("./constants-DqKJH_MP.cjs"),t=require("./guards-nJ70syPt.cjs"),n=require("./sampling-Ckh2yW9k.cjs");var r=class{config;rules=null;receivedAt=0;until=0;constructor(e){this.config=e}apply(e){if(!e){this.rules=null;return}let t=Date.now();this.rules=e.rules,this.receivedAt=t,this.until=t+e.ttlMs}current(){if(!this.rules)return null;let e=Date.now();return!this.config.sampling.remote||e<this.receivedAt||e>=this.until?(this.rules=null,null):this.rules}minLevelFor(t){let r=n.n(t,this.config),i=this.current(),a=n.r(t,i?.minLevels??{})?.value??i?.minLevel;return a!==void 0&&e.wt[a]<e.wt[r]?a:r}wire(){let e=this.current();return e?{...e,v:1,ttlMs:this.until-Date.now()}:null}},i=class extends Error{};function a(e){return typeof e==`number`&&e>=0&&e<=1}function o(t){if(t.length>4096)throw new i(`The header is longer than ${String(e.Jt)} characters.`);try{return JSON.parse(t)}catch{throw new i(`The header is not valid JSON.`)}}function s(e){if(e===void 0)return{};let n=`rates must be an object with at most 100 rates from 0 to 1.`;if(!t.t(e))throw new i(n);let r=Object.entries(e);if(r.length>100||!r.every(([,e])=>a(e)))throw new i(n);return Object.fromEntries(r)}function c(n){let r=`minLevels must be an object with at most 100 level names.`;if(!t.t(n))throw new i(r);let a=Object.entries(n),o=a.every(([,t])=>typeof t==`string`&&Object.hasOwn(e.wt,t));if(a.length>100||!o)throw new i(r);return Object.fromEntries(a)}function l(n){if(!t.t(n))throw new i(`The rules must be an object.`);if(n.v!==1)throw new i(`The version must be 1.`);let{ttlMs:r,defaultRate:o,minLevel:l}=n;if(typeof r!=`number`||!(r>0&&r<=36e5))throw new i(`ttlMs must be a number more than 0 and at most ${String(e.Yt)}.`);if(o!==void 0&&!a(o))throw new i(`defaultRate must be a number from 0 to 1.`);if(l!==void 0&&!(typeof l==`string`&&Object.hasOwn(e.wt,l)))throw new i(`minLevel must be a level name, for example DEBUG.`);let u={rates:s(n.rates)};if(o!==void 0&&(u.defaultRate=o),l!==void 0&&(u.minLevel=l),n.minLevels!==void 0&&(u.minLevels=c(n.minLevels)),n.capture!==void 0){let r=n.capture;if(!t.t(r))throw new i(`capture must be an object of capture switches.`);let a=Object.entries(r);if(!a.every(([t,n])=>e.qt.some(e=>e===t)&&typeof n==`boolean`))throw new i(`capture must contain boolean capture switches without privacy controls.`);u.capture=Object.fromEntries(a)}return{rules:u,ttlMs:r}}function u(e,t){try{return l(typeof e==`string`?o(e):e)}catch(e){let n=e instanceof i?` ${e.message}`:``;return t.report(`config.invalid`,`The library ignores the sampling rules from the server.${n}`,void 0,e),null}}function d(e,t,n){n&&(e.sampling??=new r(t)),e.sampling?.apply(n),e.changed?.()}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
2
+ //# sourceMappingURL=remote-rules-vzvk7aKf.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-rules-BL8km4xk.cjs","names":["levelFor","longestPrefix","LEVEL_ORDER","REMOTE_SAMPLING_MAX_CHARS","isObject","LEVEL_ORDER","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","require_constants","require_guards","require_sampling","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay.\n// The library does not write them into the config. A later configure() and the TTL then stay simple.\n// Only the lazy chunks import this class. The main bundle imports the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate for each namespace prefix. They apply over the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Each context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level that the library sends. It can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level for each namespace prefix. It can only lower the level of the config. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the shape of the header. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Slot of the runtime for the overlay. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** Remote sampling rules in force for this context. */\nexport class RemoteSampling {\n /** Rules in force, or null. */\n private rules: RemoteRules | null = null;\n\n /** Time that the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** Time that the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules in force. They replace the rules in force.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the rules in force.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off. Turning it on again must not bring them back.\n // Guard against a clock that moves back. The rules then stay longer than their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level that the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`. A remote level applies only when it is lower than the config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the config level of the namespace.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the rules in force in the shape of the header, with the remaining TTL.\n * @returns The rules, or null if no rules are in force.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them in force.\n// The sender and the bus import this module.\n// The main bundle does not include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** Failure of one validation step. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Tests if a value is a rate.\n * @param value Value to test.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Reads the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or is not JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is not valid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for each namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is not valid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && Object.hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @param maxRate Highest rate that a remote rule can set.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is not valid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (\n minLevel !== undefined &&\n !(typeof minLevel === \"string\" && Object.hasOwn(LEVEL_ORDER, minLevel))\n ) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. A rule that is not valid rejects all the rules.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are not valid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules in force in the slot of the runtime. It makes the overlay for the first rules.\n * @param slot Slot of the runtime.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n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names":["levelFor","longestPrefix","LEVEL_ORDER","REMOTE_SAMPLING_MAX_CHARS","isObject","LEVEL_ORDER","REMOTE_SAMPLING_MAX_TTL_MS","REMOTE_CAPTURE_FLAGS","require_constants","require_guards","require_sampling","RemoteSampling","config","update","now","local","namespace","rules","remote","RuleError","isRate","value","parseText","text","readRates","rule","entries","rate","readMinLevels","valid","level","readRules","ttlMs","defaultRate","minLevel","capture","key","flag","name","parseRemoteRules","raw","error","reason","diagnostics","applyRemote","slot"],"sources":["../src/core/remote-sampling.ts","../src/core/remote-rules.ts"],"sourcesContent":["// src/core/remote-sampling.ts\n//\n// Holds the sampling rules from the ingest server for their TTL. The rules are an overlay.\n// The library does not write them into the config. A later configure() and the TTL then stay simple.\n// Only the lazy chunks import this class. The main bundle imports the types.\n\nimport { LEVEL_ORDER, REMOTE_SAMPLING_VERSION } from \"../constants\";\nimport type { RemoteCaptureFlag, ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { levelFor, longestPrefix } from \"./sampling\";\n\n/** Sampling rules from the ingest server, after validation. */\nexport interface RemoteRules {\n /** Rate when no namespace rate matches. Without it, the config rate applies. */\n defaultRate?: number;\n /** Rate for each namespace prefix. They apply over the config rates. */\n rates: Record<string, number>;\n /** Temporary capture switches. Each context applies its own allowlist. */\n capture?: Partial<Record<RemoteCaptureFlag, boolean>>;\n /** Lowest level that the library sends. It can only lower `minLevel`. */\n minLevel?: LogLevel;\n /** Lowest level for each namespace prefix. It can only lower the level of the config. */\n minLevels?: Record<string, LogLevel>;\n}\n\n/** Rules and their TTL, after validation. */\nexport interface RemoteUpdate {\n /** Validated rules. */\n rules: RemoteRules;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Rules in the shape of the header. A context sends them to a forwarder over the bus. */\nexport interface RemoteWire extends RemoteRules {\n /** Rules version. */\n v: typeof REMOTE_SAMPLING_VERSION;\n /** Time that the rules stay in force, in milliseconds. */\n ttlMs: number;\n}\n\n/** Slot of the runtime for the overlay. The sender or the bus fills it when the first rules arrive. */\nexport interface RemoteSlot {\n /** Overlay, or null before the first rules. */\n sampling: RemoteSampling | null;\n /** Refreshes captures after a trusted rule update. */\n changed?: () => void;\n}\n\n/** Remote sampling rules in force for this context. */\nexport class RemoteSampling {\n /** Rules in force, or null. */\n private rules: RemoteRules | null = null;\n\n /** Time that the rules arrived, in epoch milliseconds. */\n private receivedAt = 0;\n\n /** Time that the rules end, in epoch milliseconds. */\n private until = 0;\n\n /**\n * @param config Active configuration instance. A reconfigure changes it in place.\n */\n constructor(private readonly config: ResolvedConfig) {}\n\n /**\n * Puts new rules in force. They replace the rules in force.\n * @param update Validated rules and their TTL, or null when the upstream has no rules.\n */\n apply(update: RemoteUpdate | null): void {\n if (!update) {\n this.rules = null;\n return;\n }\n\n const now = Date.now();\n\n this.rules = update.rules;\n this.receivedAt = now;\n this.until = now + update.ttlMs;\n }\n\n /**\n * Returns the rules in force.\n * @returns The rules, or null after the TTL or when `sampling.remote` is off.\n */\n current(): RemoteRules | null {\n if (!this.rules) {\n return null;\n }\n\n const now = Date.now();\n\n // Drop the rules when remote sampling is off. Turning it on again must not bring them back.\n // Guard against a clock that moves back. The rules then stay longer than their TTL.\n if (!this.config.sampling.remote || now < this.receivedAt || now >= this.until) {\n this.rules = null;\n return null;\n }\n\n return this.rules;\n }\n\n /**\n * Returns the lowest level that the library sends for a namespace. A remote prefix level wins\n * over the remote `minLevel`. A remote level applies only when it is lower than the config level.\n * @param namespace Target application namespace.\n * @returns The lower of the remote level and the config level of the namespace.\n */\n minLevelFor(namespace: string): LogLevel {\n const local = levelFor(namespace, this.config);\n const rules = this.current();\n const remote = longestPrefix(namespace, rules?.minLevels ?? {})?.value ?? rules?.minLevel;\n\n return remote !== undefined && LEVEL_ORDER[remote] < LEVEL_ORDER[local] ? remote : local;\n }\n\n /**\n * Returns the rules in force in the shape of the header, with the remaining TTL.\n * @returns The rules, or null if no rules are in force.\n */\n wire(): RemoteWire | null {\n const rules = this.current();\n\n if (!rules) {\n return null;\n }\n\n return { ...rules, v: REMOTE_SAMPLING_VERSION, ttlMs: this.until - Date.now() };\n }\n}\n","// src/core/remote-rules.ts\n//\n// Validates the sampling rules from the ingest server and puts them in force.\n// The sender and the bus import this module.\n// The main bundle does not include it.\n\nimport {\n LEVEL_ORDER,\n REMOTE_CAPTURE_FLAGS,\n REMOTE_SAMPLING_MAX_CHARS,\n REMOTE_SAMPLING_MAX_RATES,\n REMOTE_SAMPLING_MAX_TTL_MS,\n REMOTE_SAMPLING_VERSION,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel } from \"../models/log-record\";\nimport { isObject } from \"../utils/guards\";\nimport type { Diagnostics } from \"./diagnostics\";\nimport {\n type RemoteRules,\n RemoteSampling,\n type RemoteSlot,\n type RemoteUpdate,\n} from \"./remote-sampling\";\n\n/** Failure of one validation step. The message states the rule. */\nclass RuleError extends Error {}\n\n/**\n * Tests if a value is a rate.\n * @param value Value to test.\n * @returns True for a number from 0 to 1. NaN fails.\n */\nfunction isRate(value: unknown): value is number {\n return typeof value === \"number\" && value >= SAMPLING_RATE_MIN && value <= SAMPLING_RATE_MAX;\n}\n\n/**\n * Reads the header text as JSON.\n * @param text Header text.\n * @returns The parsed value.\n * @throws RuleError when the text is too long or is not JSON.\n */\nfunction parseText(text: string): unknown {\n if (text.length > REMOTE_SAMPLING_MAX_CHARS) {\n throw new RuleError(\n `The header is longer than ${String(REMOTE_SAMPLING_MAX_CHARS)} characters.`,\n );\n }\n\n try {\n return JSON.parse(text);\n } catch {\n // The caller reports the RuleError.\n throw new RuleError(\"The header is not valid JSON.\");\n }\n}\n\n/**\n * Reads the namespace rates.\n * @param value Value of `rates`.\n * @returns The rates.\n * @throws RuleError when a rate is not valid.\n */\nfunction readRates(value: unknown): Record<string, number> {\n if (value === undefined) {\n return {};\n }\n\n const rule = `rates must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} rates from 0 to 1.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !entries.every(([, rate]) => isRate(rate))) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, number>;\n}\n\n/**\n * Reads the level for each namespace prefix.\n * @param value Value of `minLevels`.\n * @returns The levels.\n * @throws RuleError when a level is not valid.\n */\nfunction readMinLevels(value: unknown): Record<string, LogLevel> {\n const rule = `minLevels must be an object with at most ${String(REMOTE_SAMPLING_MAX_RATES)} level names.`;\n\n if (!isObject(value)) {\n throw new RuleError(rule);\n }\n\n const entries = Object.entries(value);\n const valid = entries.every(\n ([, level]) => typeof level === \"string\" && Object.hasOwn(LEVEL_ORDER, level),\n );\n\n if (entries.length > REMOTE_SAMPLING_MAX_RATES || !valid) {\n throw new RuleError(rule);\n }\n\n // fromEntries makes own properties. A \"__proto__\" key then cannot change the prototype.\n return Object.fromEntries(entries) as Record<string, LogLevel>;\n}\n\n/**\n * Validates the rules. Sampling applies `remoteMaxRate` when it reads them.\n * @param value Parsed header value.\n * @param maxRate Highest rate that a remote rule can set.\n * @returns The rules and their TTL.\n * @throws RuleError when a field is not valid.\n */\nfunction readRules(value: unknown): RemoteUpdate {\n if (!isObject(value)) {\n throw new RuleError(\"The rules must be an object.\");\n }\n\n if (value.v !== REMOTE_SAMPLING_VERSION) {\n throw new RuleError(`The version must be ${String(REMOTE_SAMPLING_VERSION)}.`);\n }\n\n const { ttlMs, defaultRate, minLevel } = value;\n\n if (typeof ttlMs !== \"number\" || !(ttlMs > 0 && ttlMs <= REMOTE_SAMPLING_MAX_TTL_MS)) {\n throw new RuleError(\n `ttlMs must be a number more than 0 and at most ${String(REMOTE_SAMPLING_MAX_TTL_MS)}.`,\n );\n }\n\n if (defaultRate !== undefined && !isRate(defaultRate)) {\n throw new RuleError(\"defaultRate must be a number from 0 to 1.\");\n }\n\n if (\n minLevel !== undefined &&\n !(typeof minLevel === \"string\" && Object.hasOwn(LEVEL_ORDER, minLevel))\n ) {\n throw new RuleError(\"minLevel must be a level name, for example DEBUG.\");\n }\n\n const rules: RemoteRules = { rates: readRates(value.rates) };\n\n if (defaultRate !== undefined) {\n rules.defaultRate = defaultRate;\n }\n\n if (minLevel !== undefined) {\n rules.minLevel = minLevel as LogLevel;\n }\n\n if (value.minLevels !== undefined) {\n rules.minLevels = readMinLevels(value.minLevels);\n }\n\n if (value.capture !== undefined) {\n const capture = value.capture;\n if (!isObject(capture)) {\n throw new RuleError(\"capture must be an object of capture switches.\");\n }\n\n const entries = Object.entries(capture);\n if (\n !entries.every(\n ([key, flag]) =>\n REMOTE_CAPTURE_FLAGS.some((name) => name === key) && typeof flag === \"boolean\",\n )\n ) {\n throw new RuleError(\n \"capture must contain boolean capture switches without privacy controls.\",\n );\n }\n\n rules.capture = Object.fromEntries(entries);\n }\n\n return { rules, ttlMs };\n}\n\n/**\n * Validates sampling rules from the server. A rule that is not valid rejects all the rules.\n * @param raw Header text, or a parsed object from a custom transport or the bus.\n * @param diagnostics Diagnostics reporter.\n * @returns The rules and their TTL, or null if they are not valid.\n */\nexport function parseRemoteRules(raw: unknown, diagnostics: Diagnostics): RemoteUpdate | null {\n try {\n return readRules(typeof raw === \"string\" ? parseText(raw) : raw);\n } catch (error) {\n const reason = error instanceof RuleError ? ` ${error.message}` : \"\";\n\n diagnostics.report(\n \"config.invalid\",\n `The library ignores the sampling rules from the server.${reason}`,\n undefined,\n error,\n );\n return null;\n }\n}\n\n/**\n * Puts rules in force in the slot of the runtime. It makes the overlay for the first rules.\n * @param slot Slot of the runtime.\n * @param config Active configuration instance.\n * @param update Validated rules, or null when the upstream has no rules.\n */\nexport function applyRemote(\n slot: RemoteSlot,\n config: ResolvedConfig,\n update: RemoteUpdate | null,\n): void {\n if (update) {\n slot.sampling ??= new RemoteSampling(config);\n }\n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");var n=class{ctx;name=`reports`;installed=!1;observer;window={start:0,count:0};constructor(e){this.ctx=e}install(){if(this.installed)return;this.installed=!0,document.addEventListener(`securitypolicyviolation`,this.onCsp);let e=typeof ReportingObserver>`u`?void 0:ReportingObserver;e?(this.observer=new e(e=>{for(let t of e)this.record(t)},{types:[`deprecation`,`intervention`],buffered:!1}),this.observer.observe()):this.ctx.diagnostics.report(`capture.install_failed`,`The browser does not support ReportingObserver. Only CSP events are captured.`)}uninstall(){this.installed=!1,this.observer?.disconnect(),this.observer=void 0,document.removeEventListener(`securitypolicyviolation`,this.onCsp)}onCsp=e=>{this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not read a CSP event.`,()=>{this.record({type:`csp-violation`,url:e.documentURI,body:{sourceFile:e.sourceFile,lineNumber:e.lineNumber,columnNumber:e.columnNumber,effectiveDirective:e.effectiveDirective,blockedURL:e.blockedURI}})})};record(n){if(!this.installed||this.ctx.isActive?.()===!1)return;let{capturePolicy:r,limits:i}=this.ctx.config;t.t(this.window,r.reportsPerWindow,this.ctx.diagnostics,`browser reports`,r.windowMs)&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a browser report.`,()=>{if(![`deprecation`,`intervention`,`csp-violation`].includes(n.type))return;let t=n.body,r=t=>e.i(t,!1,void 0,this.ctx.diagnostics);this.ctx.logger.warn(`ui.report`,{"report.type":n.type,"report.url":r(n.url),...t.id?{"report.id":t.id.slice(0,i.maxAttributeChars)}:{},...t.sourceFile?{"report.source":r(t.sourceFile)}:{},...t.lineNumber===void 0?{}:{"report.line":t.lineNumber},...t.columnNumber===void 0?{}:{"report.column":t.columnNumber},...t.effectiveDirective?{"report.directive":t.effectiveDirective}:{},...t.blockedURL?{"report.blocked_url":r(t.blockedURL)}:{}})})}};exports.ReportCapture=n;
2
- //# sourceMappingURL=reports-Bh_-KpZ2.cjs.map
1
+ const e=require("./platform-C2Ez5kDc.cjs"),t=require("./storm-CYi9Swpx.cjs");var n=class{ctx;name=`reports`;installed=!1;observer;window={start:0,count:0};constructor(e){this.ctx=e}install(){if(this.installed)return;this.installed=!0,document.addEventListener(`securitypolicyviolation`,this.onCsp);let e=typeof ReportingObserver>`u`?void 0:ReportingObserver;e?(this.observer=new e(e=>{for(let t of e)this.record(t)},{types:[`deprecation`,`intervention`],buffered:!1}),this.observer.observe()):this.ctx.diagnostics.report(`capture.install_failed`,`The browser does not support ReportingObserver. Only CSP events are captured.`)}uninstall(){this.installed=!1,this.observer?.disconnect(),this.observer=void 0,document.removeEventListener(`securitypolicyviolation`,this.onCsp)}onCsp=e=>{this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not read a CSP event.`,()=>{this.record({type:`csp-violation`,url:e.documentURI,body:{sourceFile:e.sourceFile,lineNumber:e.lineNumber,columnNumber:e.columnNumber,effectiveDirective:e.effectiveDirective,blockedURL:e.blockedURI}})})};record(n){if(!this.installed||this.ctx.isActive?.()===!1)return;let{capturePolicy:r,limits:i}=this.ctx.config;t.t(this.window,r.reportsPerWindow,this.ctx.diagnostics,`browser reports`,r.windowMs)&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a browser report.`,()=>{if(![`deprecation`,`intervention`,`csp-violation`].includes(n.type))return;let t=n.body,r=t=>e.i(t,!1,void 0,this.ctx.diagnostics);this.ctx.logger.warn(`ui.report`,{"report.type":n.type,"report.url":r(n.url),...t.id?{"report.id":t.id.slice(0,i.maxAttributeChars)}:{},...t.sourceFile?{"report.source":r(t.sourceFile)}:{},...t.lineNumber===void 0?{}:{"report.line":t.lineNumber},...t.columnNumber===void 0?{}:{"report.column":t.columnNumber},...t.effectiveDirective?{"report.directive":t.effectiveDirective}:{},...t.blockedURL?{"report.blocked_url":r(t.blockedURL)}:{}})})}};exports.ReportCapture=n;
2
+ //# sourceMappingURL=reports-Dk2YhKIh.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"reports-Bh_-KpZ2.cjs","names":["allowInWindow","recordedUrl","require_platform","require_storm","ReportCapture","ctx","Observer","report","reports","event","capturePolicy","body","url","value","limits"],"sources":["../src/capture/reports.ts"],"sourcesContent":["import { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Report fields that this capture reads. Message text and samples stay out. */\ninterface BrowserReport {\n type: string;\n url: string;\n body: {\n id?: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n effectiveDirective?: string;\n blockedURL?: string;\n };\n}\n\n/** Records browser reports without message text, code samples or URL queries. */\nexport class ReportCapture implements Capture {\n readonly name = \"reports\";\n\n private installed = false;\n\n private observer: ReportingObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Installs report and CSP listeners. CSP reports do not need ReportingObserver. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n document.addEventListener(\"securitypolicyviolation\", this.onCsp);\n\n const Observer = typeof ReportingObserver === \"undefined\" ? undefined : ReportingObserver;\n\n if (!Observer) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not support ReportingObserver. Only CSP events are captured.\",\n );\n return;\n }\n\n this.observer = new Observer(\n (reports) => {\n for (const report of reports) {\n this.record(report as unknown as BrowserReport);\n }\n },\n { types: [\"deprecation\", \"intervention\"], buffered: false },\n );\n this.observer.observe();\n }\n\n /** Disconnects the observer and removes the CSP listener. */\n uninstall(): void {\n this.installed = false;\n this.observer?.disconnect();\n this.observer = undefined;\n document.removeEventListener(\"securitypolicyviolation\", this.onCsp);\n }\n\n private readonly onCsp = (event: SecurityPolicyViolationEvent): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a CSP event.\",\n () => {\n this.record({\n type: \"csp-violation\",\n url: event.documentURI,\n body: {\n sourceFile: event.sourceFile,\n lineNumber: event.lineNumber,\n columnNumber: event.columnNumber,\n effectiveDirective: event.effectiveDirective,\n blockedURL: event.blockedURI,\n },\n });\n },\n );\n };\n\n /** Reads only fixed report fields. The diagnostics guard contains a failed field read. */\n private record(report: BrowserReport): void {\n if (!this.installed || this.ctx.isActive?.() === false) {\n return;\n }\n\n const { capturePolicy, limits } = this.ctx.config;\n if (\n !allowInWindow(\n this.window,\n capturePolicy.reportsPerWindow,\n this.ctx.diagnostics,\n \"browser reports\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a browser report.\",\n () => {\n if (![\"deprecation\", \"intervention\", \"csp-violation\"].includes(report.type)) {\n return;\n }\n\n const body = report.body;\n const url = (value: string): string =>\n recordedUrl(value, false, undefined, this.ctx.diagnostics);\n this.ctx.logger.warn(\"ui.report\", {\n \"report.type\": report.type,\n \"report.url\": url(report.url),\n ...(body.id ? { \"report.id\": body.id.slice(0, limits.maxAttributeChars) } : {}),\n ...(body.sourceFile ? { \"report.source\": url(body.sourceFile) } : {}),\n ...(body.lineNumber !== undefined ? { \"report.line\": body.lineNumber } : {}),\n ...(body.columnNumber !== undefined ? { \"report.column\": body.columnNumber } : {}),\n ...(body.effectiveDirective ? { \"report.directive\": body.effectiveDirective } : {}),\n ...(body.blockedURL ? { \"report.blocked_url\": url(body.blockedURL) } : {}),\n });\n },\n );\n }\n}\n"],"mappings":"6EAmBA,IAAaI,EAAb,KAA8C,CASf,IAR7B,KAAgB,UAEhB,UAAoB,GAEpB,SAEA,OAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,EAE5D,YAAY,EAAsC,CAArB,KAAA,IAAAC,CAAsB,CAGnD,SAAgB,CACd,GAAI,KAAK,UACP,OAEF,KAAK,UAAY,GACjB,SAAS,iBAAiB,0BAA2B,KAAK,KAAK,EAE/D,IAAMC,EAAW,OAAO,kBAAsB,IAAc,IAAA,GAAY,kBAEnEA,GAQL,KAAK,SAAW,IAAIA,EACjB,GAAY,CACX,IAAK,IAAMC,KAAUC,EACnB,KAAK,OAAOD,CAAkC,CAElD,EACA,CAAE,MAAO,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AC,EAAtC,CAAE,cAAeA,EAAK,UAAW,EACrE,GAAIA,EAAK,eAAiB,IAAA,GAAqD,CAAC,EAA1C,CAAE,gBAAiBA,EAAK,YAAa,EAC3E,GAAIA,EAAK,mBAAqB,CAAE,mBAAoBA,EAAK,kBAAmB,EAAI,CAAC,EACjF,GAAIA,EAAK,WAAa,CAAE,qBAAsBC,EAAID,EAAK,UAAU,CAAE,EAAI,CAAC,CAC1E,CAAC,CACH,CACF,CACF,CACF"}
1
+ {"version":3,"file":"reports-Dk2YhKIh.cjs","names":["allowInWindow","recordedUrl","require_platform","require_storm","ReportCapture","ctx","Observer","report","reports","event","capturePolicy","body","url","value","limits"],"sources":["../src/capture/reports.ts"],"sourcesContent":["import { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Report fields that this capture reads. Message text and samples stay out. */\ninterface BrowserReport {\n type: string;\n url: string;\n body: {\n id?: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n effectiveDirective?: string;\n blockedURL?: string;\n };\n}\n\n/** Records browser reports without message text, code samples or URL queries. */\nexport class ReportCapture implements Capture {\n readonly name = \"reports\";\n\n private installed = false;\n\n private observer: ReportingObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Installs report and CSP listeners. CSP reports do not need ReportingObserver. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n document.addEventListener(\"securitypolicyviolation\", this.onCsp);\n\n const Observer = typeof ReportingObserver === \"undefined\" ? undefined : ReportingObserver;\n\n if (!Observer) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not support ReportingObserver. Only CSP events are captured.\",\n );\n return;\n }\n\n this.observer = new Observer(\n (reports) => {\n for (const report of reports) {\n this.record(report as unknown as BrowserReport);\n }\n },\n { types: [\"deprecation\", \"intervention\"], buffered: false },\n );\n this.observer.observe();\n }\n\n /** Disconnects the observer and removes the CSP listener. */\n uninstall(): void {\n this.installed = false;\n this.observer?.disconnect();\n this.observer = undefined;\n document.removeEventListener(\"securitypolicyviolation\", this.onCsp);\n }\n\n private readonly onCsp = (event: SecurityPolicyViolationEvent): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a CSP event.\",\n () => {\n this.record({\n type: \"csp-violation\",\n url: event.documentURI,\n body: {\n sourceFile: event.sourceFile,\n lineNumber: event.lineNumber,\n columnNumber: event.columnNumber,\n effectiveDirective: event.effectiveDirective,\n blockedURL: event.blockedURI,\n },\n });\n },\n );\n };\n\n /** Reads only fixed report fields. The diagnostics guard contains a failed field read. */\n private record(report: BrowserReport): void {\n if (!this.installed || this.ctx.isActive?.() === false) {\n return;\n }\n\n const { capturePolicy, limits } = this.ctx.config;\n if (\n !allowInWindow(\n this.window,\n capturePolicy.reportsPerWindow,\n this.ctx.diagnostics,\n \"browser reports\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a browser report.\",\n () => {\n if (![\"deprecation\", \"intervention\", \"csp-violation\"].includes(report.type)) {\n return;\n }\n\n const body = report.body;\n const url = (value: string): string =>\n recordedUrl(value, false, undefined, this.ctx.diagnostics);\n this.ctx.logger.warn(\"ui.report\", {\n \"report.type\": report.type,\n \"report.url\": url(report.url),\n ...(body.id ? { \"report.id\": body.id.slice(0, limits.maxAttributeChars) } : {}),\n ...(body.sourceFile ? { \"report.source\": url(body.sourceFile) } : {}),\n ...(body.lineNumber !== undefined ? { \"report.line\": body.lineNumber } : {}),\n ...(body.columnNumber !== undefined ? { \"report.column\": body.columnNumber } : {}),\n ...(body.effectiveDirective ? { \"report.directive\": body.effectiveDirective } : {}),\n ...(body.blockedURL ? { \"report.blocked_url\": url(body.blockedURL) } : {}),\n });\n },\n );\n }\n}\n"],"mappings":"A,6EAmBA,IAAaI,EAAb,KAA8C,CAS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AMI,EAAOJ,EAAO,KACdK,EAAO,GACXX,EAAAA,EAAYY,EAAO,GAAO,IAAA,GAAW,KAAK,IAAI,WAAW,EAC3D,KAAK,IAAI,OAAO,KAAK,YAAa,CAChC,cAAeN,EAAO,KACtB,aAAcK,EAAIL,EAAO,GAAG,EAC5B,GAAII,EAAK,GAAK,CAAE,YAAaA,EAAK,GAAG,MAAM,EAAGG,EAAO,iBAAiB,CAAE,EAAI,CAAC,EAC7E,GAAIH,EAAK,WAAa,CAAE,gBAAiBC,EAAID,EAAK,UAAU,CAAE,EAAI,CAAC,EACnE,GAAIA,EAAK,aAAe,IAAA,GAAiD,CAAC,EAAtC,CAAE,cAAeA,EAAK,UAAW,EACrE,GAAIA,EAAK,eAAiB,IAAA,GAAqD,CAAC,EAA1C,CAAE,gBAAiBA,EAAK,YAAa,EAC3E,GAAIA,EAAK,mBAAqB,CAAE,mBAAoBA,EAAK,kBAAmB,EAAI,CAAC,EACjF,GAAIA,EAAK,WAAa,CAAE,qBAAsBC,EAAID,EAAK,UAAU,CAAE,EAAI,CAAC,CAC1E,CAAC,CACH,CACF,CACF,CACF,E"}
@@ -1,6 +1,6 @@
1
- import { i as e } from "./platform-wcAkkv9F.js";
2
- import { t } from "./storm-DD4cUkoL.js";
3
- //#region src/capture/reports.ts
1
+ import { i as e } from "./platform-DkcuXwe-.js";
2
+ import { t } from "./storm-VR024_QN.js";
3
+ // src/capture/reports.ts
4
4
  var n = class {
5
5
  ctx;
6
6
  name = "reports";
@@ -65,7 +65,6 @@ var n = class {
65
65
  });
66
66
  }
67
67
  };
68
- //#endregion
69
68
  export { n as ReportCapture };
70
69
 
71
- //# sourceMappingURL=reports-BOKyY3_A.js.map
70
+ //# sourceMappingURL=reports-TA-zInnq.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reports-BOKyY3_A.js","names":["recordedUrl","ReportCapture","ctx","Observer","report","reports","event","allowInWindow","capturePolicy","body","url","value","limits"],"sources":["../src/capture/reports.ts"],"sourcesContent":["import { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Report fields that this capture reads. Message text and samples stay out. */\ninterface BrowserReport {\n type: string;\n url: string;\n body: {\n id?: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n effectiveDirective?: string;\n blockedURL?: string;\n };\n}\n\n/** Records browser reports without message text, code samples or URL queries. */\nexport class ReportCapture implements Capture {\n readonly name = \"reports\";\n\n private installed = false;\n\n private observer: ReportingObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Installs report and CSP listeners. CSP reports do not need ReportingObserver. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n document.addEventListener(\"securitypolicyviolation\", this.onCsp);\n\n const Observer = typeof ReportingObserver === \"undefined\" ? undefined : ReportingObserver;\n\n if (!Observer) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not support ReportingObserver. Only CSP events are captured.\",\n );\n return;\n }\n\n this.observer = new Observer(\n (reports) => {\n for (const report of reports) {\n this.record(report as unknown as BrowserReport);\n }\n },\n { types: [\"deprecation\", \"intervention\"], buffered: false },\n );\n this.observer.observe();\n }\n\n /** Disconnects the observer and removes the CSP listener. */\n uninstall(): void {\n this.installed = false;\n this.observer?.disconnect();\n this.observer = undefined;\n document.removeEventListener(\"securitypolicyviolation\", this.onCsp);\n }\n\n private readonly onCsp = (event: SecurityPolicyViolationEvent): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a CSP event.\",\n () => {\n this.record({\n type: \"csp-violation\",\n url: event.documentURI,\n body: {\n sourceFile: event.sourceFile,\n lineNumber: event.lineNumber,\n columnNumber: event.columnNumber,\n effectiveDirective: event.effectiveDirective,\n blockedURL: event.blockedURI,\n },\n });\n },\n );\n };\n\n /** Reads only fixed report fields. The diagnostics guard contains a failed field read. */\n private record(report: BrowserReport): void {\n if (!this.installed || this.ctx.isActive?.() === false) {\n return;\n }\n\n const { capturePolicy, limits } = this.ctx.config;\n if (\n !allowInWindow(\n this.window,\n capturePolicy.reportsPerWindow,\n this.ctx.diagnostics,\n \"browser reports\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a browser report.\",\n () => {\n if (![\"deprecation\", \"intervention\", \"csp-violation\"].includes(report.type)) {\n return;\n }\n\n const body = report.body;\n const url = (value: string): string =>\n recordedUrl(value, false, undefined, this.ctx.diagnostics);\n this.ctx.logger.warn(\"ui.report\", {\n \"report.type\": report.type,\n \"report.url\": url(report.url),\n ...(body.id ? { \"report.id\": body.id.slice(0, limits.maxAttributeChars) } : {}),\n ...(body.sourceFile ? { \"report.source\": url(body.sourceFile) } : {}),\n ...(body.lineNumber !== undefined ? { \"report.line\": body.lineNumber } : {}),\n ...(body.columnNumber !== undefined ? { \"report.column\": body.columnNumber } : {}),\n ...(body.effectiveDirective ? { \"report.directive\": body.effectiveDirective } : {}),\n ...(body.blockedURL ? { \"report.blocked_url\": url(body.blockedURL) } : {}),\n });\n },\n );\n }\n}\n"],"mappings":";;;AAmBA,IAAaC,IAAb,MAA8C;CASf;CAR7B,OAAgB;CAEhB,YAAoB;CAEpB;CAEA,SAAuC;EAAE,OAAO;EAAG,OAAO;CAAE;CAE5D,YAAY,GAAsC;EAArB,KAAA,MAAAC;CAAsB;CAGnD,UAAgB;EACd,IAAI,KAAK,WACP;EAGF,AADA,KAAK,YAAY,IACjB,SAAS,iBAAiB,2BAA2B,KAAK,KAAK;EAE/D,IAAMC,IAAW,OAAO,oBAAsB,MAAc,KAAA,IAAY;EAExE,AAAKA,KAQL,KAAK,WAAW,IAAIA,GACjB,MAAY;GACX,KAAK,IAAMC,KAAUC,GACnB,KAAK,OAAOD,CAAkC;EAElD,GACA;GAAE,OAAO,CAAC,eAAe,cAAc;GAAG,UAAU;EAAM,CAC5D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AIA,EAAK,iBAAiB,KAAA,IAAqD,CAAC,IAA1C,EAAE,iBAAiBA,EAAK,aAAa;IAC3E,GAAIA,EAAK,qBAAqB,EAAE,oBAAoBA,EAAK,mBAAmB,IAAI,CAAC;IACjF,GAAIA,EAAK,aAAa,EAAE,sBAAsBC,EAAID,EAAK,UAAU,EAAE,IAAI,CAAC;GAC1E,CAAC;EACH,CACF;CACF;AACF"}
1
+ {"version":3,"file":"reports-TA-zInnq.js","names":["recordedUrl","ReportCapture","ctx","Observer","report","reports","event","allowInWindow","capturePolicy","body","url","value","limits"],"sources":["../src/capture/reports.ts"],"sourcesContent":["import { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport type { Capture, CaptureContext } from \"./types\";\n\n/** Report fields that this capture reads. Message text and samples stay out. */\ninterface BrowserReport {\n type: string;\n url: string;\n body: {\n id?: string;\n sourceFile?: string;\n lineNumber?: number;\n columnNumber?: number;\n effectiveDirective?: string;\n blockedURL?: string;\n };\n}\n\n/** Records browser reports without message text, code samples or URL queries. */\nexport class ReportCapture implements Capture {\n readonly name = \"reports\";\n\n private installed = false;\n\n private observer: ReportingObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Installs report and CSP listeners. CSP reports do not need ReportingObserver. */\n install(): void {\n if (this.installed) {\n return;\n }\n this.installed = true;\n document.addEventListener(\"securitypolicyviolation\", this.onCsp);\n\n const Observer = typeof ReportingObserver === \"undefined\" ? undefined : ReportingObserver;\n\n if (!Observer) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not support ReportingObserver. Only CSP events are captured.\",\n );\n return;\n }\n\n this.observer = new Observer(\n (reports) => {\n for (const report of reports) {\n this.record(report as unknown as BrowserReport);\n }\n },\n { types: [\"deprecation\", \"intervention\"], buffered: false },\n );\n this.observer.observe();\n }\n\n /** Disconnects the observer and removes the CSP listener. */\n uninstall(): void {\n this.installed = false;\n this.observer?.disconnect();\n this.observer = undefined;\n document.removeEventListener(\"securitypolicyviolation\", this.onCsp);\n }\n\n private readonly onCsp = (event: SecurityPolicyViolationEvent): void => {\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not read a CSP event.\",\n () => {\n this.record({\n type: \"csp-violation\",\n url: event.documentURI,\n body: {\n sourceFile: event.sourceFile,\n lineNumber: event.lineNumber,\n columnNumber: event.columnNumber,\n effectiveDirective: event.effectiveDirective,\n blockedURL: event.blockedURI,\n },\n });\n },\n );\n };\n\n /** Reads only fixed report fields. The diagnostics guard contains a failed field read. */\n private record(report: BrowserReport): void {\n if (!this.installed || this.ctx.isActive?.() === false) {\n return;\n }\n\n const { capturePolicy, limits } = this.ctx.config;\n if (\n !allowInWindow(\n this.window,\n capturePolicy.reportsPerWindow,\n this.ctx.diagnostics,\n \"browser reports\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a browser report.\",\n () => {\n if (![\"deprecation\", \"intervention\", \"csp-violation\"].includes(report.type)) {\n return;\n }\n\n const body = report.body;\n const url = (value: string): string =>\n recordedUrl(value, false, undefined, this.ctx.diagnostics);\n this.ctx.logger.warn(\"ui.report\", {\n \"report.type\": report.type,\n \"report.url\": url(report.url),\n ...(body.id ? { \"report.id\": body.id.slice(0, limits.maxAttributeChars) } : {}),\n ...(body.sourceFile ? { \"report.source\": url(body.sourceFile) } : {}),\n ...(body.lineNumber !== undefined ? { \"report.line\": body.lineNumber } : {}),\n ...(body.columnNumber !== undefined ? { \"report.column\": body.columnNumber } : {}),\n ...(body.effectiveDirective ? { \"report.directive\": body.effectiveDirective } : {}),\n ...(body.blockedURL ? { \"report.blocked_url\": url(body.blockedURL) } : {}),\n });\n },\n );\n }\n}\n"],"mappings":";;;AAmBA,IAAaC,IAAb,MAA8C;CASf;CAR7B,OAAgB;CAEhB,YAAoB;CAEpB;CAEA,SAAuC;EAAE,OAA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,IAAO,KAAA,GAAW,KAAK,IAAI,WAAW;GAC3D,KAAK,IAAI,OAAO,KAAK,aAAa;IAChC,eAAeP,EAAO;IACtB,cAAcM,EAAIN,EAAO,GAAG;IAC5B,GAAIK,EAAK,KAAK,EAAE,aAAaA,EAAK,GAAG,MAAM,GAAGG,EAAO,iBAAiB,EAAE,IAAI,CAAC;IAC7E,GAAIH,EAAK,aAAa,EAAE,iBAAiBC,EAAID,EAAK,UAAU,EAAE,IAAI,CAAC;IACnE,GAAIA,EAAK,eAAe,KAAA,IAAiD,CAAC,IAAtC,EAAE,eAAeA,EAAK,WAAW;IACrE,GAAIA,EAAK,iBAAiB,KAAA,IAAqD,CAAC,IAA1C,EAAE,iBAAiBA,EAAK,aAAa;IAC3E,GAAIA,EAAK,qBAAqB,EAAE,oBAAoBA,EAAK,mBAAmB,IAAI,CAAC;IACjF,GAAIA,EAAK,aAAa,EAAE,sBAAsBC,EAAID,EAAK,UAAU,EAAE,IAAI,CAAC;GAC1E,CAAC;EACH,CACF;CACF;AACF"}
@@ -1,8 +1,8 @@
1
- import { on as e } from "./constants-CU60FG4w.js";
2
- import { i as t } from "./platform-wcAkkv9F.js";
3
- import { t as n } from "./storm-DD4cUkoL.js";
4
- import { t as r } from "./types-BR9t_w28.js";
5
- //#region src/capture/resource-timing.ts
1
+ import { on as e } from "./constants-zyrqveN4.js";
2
+ import { i as t } from "./platform-DkcuXwe-.js";
3
+ import { t as n } from "./storm-VR024_QN.js";
4
+ import { t as r } from "./types-BAerHgCq.js";
5
+ // src/capture/resource-timing.ts
6
6
  var i = {
7
7
  name: "ui.resource.duration",
8
8
  kind: "histogram",
@@ -71,7 +71,6 @@ var i = {
71
71
  });
72
72
  }
73
73
  };
74
- //#endregion
75
74
  export { a as ResourceTimingCapture };
76
75
 
77
- //# sourceMappingURL=resource-timing-BROnEJ0E.js.map
76
+ //# sourceMappingURL=resource-timing-BLv3EA2A.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-timing-BROnEJ0E.js","names":["RESOURCE_SLOW_MS","recordedUrl","allowInWindow","matchesAny","RESOURCE_DURATION","ResourceTimingCapture","ctx","first","entry","list","url","endpoints","capture","endpoint","capturePolicy","attributes","slowMs"],"sources":["../src/capture/resource-timing.ts"],"sourcesContent":["import { RESOURCE_SLOW_MS } from \"../constants\";\nimport type { InstrumentDef } from \"../models/metric\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Resource durations in milliseconds. URLs and paths do not create metric series. */\nconst RESOURCE_DURATION: InstrumentDef = {\n name: \"ui.resource.duration\",\n kind: \"histogram\",\n unit: \"ms\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n};\n\n/** Records bounded resource timings and slow resource events. */\nexport class ResourceTimingCapture implements Capture {\n readonly name = \"resourceTiming\";\n\n private observer: PerformanceObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reads buffered resources only at the first install in this document. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n if (!supported?.includes(\"resource\")) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report resource timing entries. The resource timing capture is off.\",\n );\n return;\n }\n\n const first = !this.ctx.once.resourceTiming;\n this.observer = new PerformanceObserver((list) => {\n for (const entry of list.getEntries()) {\n this.record(entry as PerformanceResourceTiming);\n }\n });\n this.observer.observe({ type: \"resource\", buffered: first });\n this.ctx.once.resourceTiming = true;\n }\n\n /** Disconnects the observer. */\n uninstall(): void {\n this.observer?.disconnect();\n this.observer = undefined;\n }\n\n private record(entry: PerformanceResourceTiming): void {\n if (!this.observer || this.ctx.isActive?.() === false) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a resource timing entry.\",\n () => {\n const { capture, capturePolicy } = this.ctx.config;\n const url = new URL(entry.name, location.href);\n const endpoints = [\n this.ctx.config.endpoint,\n this.ctx.config.metricsEndpoint,\n this.ctx.config.tracesEndpoint,\n ];\n if (\n matchesAny(entry.name, capture.ignoreUrls) ||\n endpoints.some(\n (endpoint) => endpoint && url.href.startsWith(new URL(endpoint, location.href).href),\n )\n ) {\n return;\n }\n if (\n !Number.isFinite(entry.duration) ||\n entry.duration < 0 ||\n ![\"http:\", \"https:\"].includes(url.protocol)\n ) {\n return;\n }\n if (\n !allowInWindow(\n this.window,\n capturePolicy.resourcesPerWindow,\n this.ctx.diagnostics,\n \"resource entries\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n const attributes = {\n \"resource.initiator_type\": entry.initiatorType,\n \"server.address\": url.hostname,\n };\n this.ctx.recordMetric(RESOURCE_DURATION, entry.duration, attributes);\n\n const slowMs =\n typeof capture.resourceTiming === \"object\"\n ? (capture.resourceTiming.slowMs ?? RESOURCE_SLOW_MS)\n : RESOURCE_SLOW_MS;\n if (slowMs > 0 && entry.duration >= slowMs) {\n this.ctx.logger.logEvent(\"ui.resource.slow\", {\n ...attributes,\n \"resource.duration_ms\": entry.duration,\n \"url.full\": recordedUrl(\n entry.name,\n capture.fullUrls,\n capture.urlTransform,\n this.ctx.diagnostics,\n ),\n });\n }\n },\n );\n }\n}\n"],"mappings":";;;;;AAOA,IAAMI,IAAmC;CACvC,MAAM;CACN,MAAM;CACN,MAAM;CACN,YAAY;EAAC;EAAG;EAAG;EAAI;EAAI;EAAI;EAAK;EAAK;EAAK;EAAM;EAAM;EAAM;CAAK;AACvE,GAGaC,IAAb,MAAsD;CAOvB;CAN7B,OAAgB;CAEhB;CAEA,SAAuC;EAAE,OAAO;EAAG,OAAO;CAAE;CAE5D,YAAY,GAAsC;EAArB,KAAA,MAAAC;CAAsB;CAGnD,UAAgB;EACd,IAAI,KAAK,UACP;EAOF,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AAM,UAAUO,CAAU;GAEnE,IAAMC,IACJ,OAAOJ,EAAQ,kBAAmB,WAC7BA,EAAQ,eAAe,UAAA,MACxBZ;GACN,AAAIgB,IAAS,KAAKR,EAAM,YAAYQ,KAClC,KAAK,IAAI,OAAO,SAAS,oBAAoB;IAC3C,GAAGD;IACH,wBAAwBP,EAAM;IAC9B,YAAYP,EACVO,EAAM,MACNI,EAAQ,UACRA,EAAQ,cACR,KAAK,IAAI,WACX;GACF,CAAC;EAEL,CACF;CACF;AACF"}
1
+ {"version":3,"file":"resource-timing-BLv3EA2A.js","names":["RESOURCE_SLOW_MS","recordedUrl","allowInWindow","matchesAny","RESOURCE_DURATION","ResourceTimingCapture","ctx","first","entry","list","url","endpoints","capture","endpoint","capturePolicy","attributes","slowMs"],"sources":["../src/capture/resource-timing.ts"],"sourcesContent":["import { RESOURCE_SLOW_MS } from \"../constants\";\nimport type { InstrumentDef } from \"../models/metric\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Resource durations in milliseconds. URLs and paths do not create metric series. */\nconst RESOURCE_DURATION: InstrumentDef = {\n name: \"ui.resource.duration\",\n kind: \"histogram\",\n unit: \"ms\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n};\n\n/** Records bounded resource timings and slow resource events. */\nexport class ResourceTimingCapture implements Capture {\n readonly name = \"resourceTiming\";\n\n private observer: PerformanceObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reads buffered resources only at the first install in this document. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n if (!supported?.includes(\"resource\")) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report resource timing entries. The resource timing capture is off.\",\n );\n return;\n }\n\n const first = !this.ctx.once.resourceTiming;\n this.observer = new PerformanceObserver((list) => {\n for (const entry of list.getEntries()) {\n this.record(entry as PerformanceResourceTiming);\n }\n });\n this.observer.observe({ type: \"resource\", buffered: first });\n this.ctx.once.resourceTiming = true;\n }\n\n /** Disconnects the observer. */\n uninstall(): void {\n this.observer?.disconnect();\n this.observer = undefined;\n }\n\n private record(entry: PerformanceResourceTiming): void {\n if (!this.observer || this.ctx.isActive?.() === false) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a resource timing entry.\",\n () => {\n const { capture, capturePolicy } = this.ctx.config;\n const url = new URL(entry.name, location.href);\n const endpoints = [\n this.ctx.config.endpoint,\n this.ctx.config.metricsEndpoint,\n this.ctx.config.tracesEndpoint,\n ];\n if (\n matchesAny(entry.name, capture.ignoreUrls) ||\n endpoints.some(\n (endpoint) => endpoint && url.href.startsWith(new URL(endpoint, location.href).href),\n )\n ) {\n return;\n }\n if (\n !Number.isFinite(entry.duration) ||\n entry.duration < 0 ||\n ![\"http:\", \"https:\"].includes(url.protocol)\n ) {\n return;\n }\n if (\n !allowInWindow(\n this.window,\n capturePolicy.resourcesPerWindow,\n this.ctx.diagnostics,\n \"resource entries\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n const attributes = {\n \"resource.initiator_type\": entry.initiatorType,\n \"server.address\": url.hostname,\n };\n this.ctx.recordMetric(RESOURCE_DURATION, entry.duration, attributes);\n\n const slowMs =\n typeof capture.resourceTiming === \"object\"\n ? (capture.resourceTiming.slowMs ?? RESOURCE_SLOW_MS)\n : RESOURCE_SLOW_MS;\n if (slowMs > 0 && entry.duration >= slowMs) {\n this.ctx.logger.logEvent(\"ui.resource.slow\", {\n ...attributes,\n \"resource.duration_ms\": entry.duration,\n \"url.full\": recordedUrl(\n entry.name,\n capture.fullUrls,\n capture.urlTransform,\n this.ctx.diagnostics,\n ),\n });\n }\n },\n );\n }\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,GAAU,SAAS,IAAI,CAAC,CAAC,IAAI,CACrF,KAKA,CAAC,OAAO,SAASL,EAAM,QAAQ,KAC/BA,EAAM,WAAW,KACjB,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,SAASE,EAAI,QAAQ,KAK1C,CAACR,EACC,KAAK,QACLY,EAAc,oBACd,KAAK,IAAI,aACT,oBACAA,EAAc,QAChB,GAEA;GAGF,IAAMC,IAAa;IACjB,2BAA2BP,EAAM;IACjC,kBAAkBE,EAAI;GACxB;GACA,KAAK,IAAI,aAAaN,GAAmBI,EAAM,UAAUO,CAAU;GAEnE,IAAMC,IACJ,OAAOJ,EAAQ,kBAAmB,WAC7BA,EAAQ,eAAe,UAAA,MACxBZ;GACN,AAAIgB,IAAS,KAAKR,EAAM,YAAYQ,KAClC,KAAK,IAAI,OAAO,SAAS,oBAAoB;IAC3C,GAAGD;IACH,wBAAwBP,EAAM;IAC9B,YAAYP,EACVO,EAAM,MACNI,EAAQ,UACRA,EAAQ,cACR,KAAK,IAAI,WACX;GACF,CAAC;EAEL,CACF;CACF;AACF"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-CL0ZdI2f.cjs"),t=require("./platform-KMWkoI-v.cjs"),n=require("./storm-DCEsqViG.cjs"),r=require("./types-C7WNpnG1.cjs");var i={name:`ui.resource.duration`,kind:`histogram`,unit:`ms`,boundaries:[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4]},a=class{ctx;name=`resourceTiming`;observer;window={start:0,count:0};constructor(e){this.ctx=e}install(){if(this.observer)return;if(!(typeof PerformanceObserver>`u`?void 0:PerformanceObserver.supportedEntryTypes)?.includes(`resource`)){this.ctx.diagnostics.report(`capture.install_failed`,`The browser does not report resource timing entries. The resource timing capture is off.`);return}let e=!this.ctx.once.resourceTiming;this.observer=new PerformanceObserver(e=>{for(let t of e.getEntries())this.record(t)}),this.observer.observe({type:`resource`,buffered:e}),this.ctx.once.resourceTiming=!0}uninstall(){this.observer?.disconnect(),this.observer=void 0}record(a){this.observer&&this.ctx.isActive?.()!==!1&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a resource timing entry.`,()=>{let{capture:o,capturePolicy:s}=this.ctx.config,c=new URL(a.name,location.href),l=[this.ctx.config.endpoint,this.ctx.config.metricsEndpoint,this.ctx.config.tracesEndpoint];if(r.t(a.name,o.ignoreUrls)||l.some(e=>e&&c.href.startsWith(new URL(e,location.href).href))||!Number.isFinite(a.duration)||a.duration<0||![`http:`,`https:`].includes(c.protocol)||!n.t(this.window,s.resourcesPerWindow,this.ctx.diagnostics,`resource entries`,s.windowMs))return;let u={"resource.initiator_type":a.initiatorType,"server.address":c.hostname};this.ctx.recordMetric(i,a.duration,u);let d=typeof o.resourceTiming==`object`?o.resourceTiming.slowMs??1e3:e.on;d>0&&a.duration>=d&&this.ctx.logger.logEvent(`ui.resource.slow`,{...u,"resource.duration_ms":a.duration,"url.full":t.i(a.name,o.fullUrls,o.urlTransform,this.ctx.diagnostics)})})}};exports.ResourceTimingCapture=a;
2
- //# sourceMappingURL=resource-timing-CbgwNpog.cjs.map
1
+ const e=require("./constants-DqKJH_MP.cjs"),t=require("./platform-C2Ez5kDc.cjs"),n=require("./storm-CYi9Swpx.cjs"),r=require("./types-C7WNpnG1.cjs");var i={name:`ui.resource.duration`,kind:`histogram`,unit:`ms`,boundaries:[1,5,10,25,50,100,250,500,1e3,2500,5e3,1e4]},a=class{ctx;name=`resourceTiming`;observer;window={start:0,count:0};constructor(e){this.ctx=e}install(){if(this.observer)return;if(!(typeof PerformanceObserver>`u`?void 0:PerformanceObserver.supportedEntryTypes)?.includes(`resource`)){this.ctx.diagnostics.report(`capture.install_failed`,`The browser does not report resource timing entries. The resource timing capture is off.`);return}let e=!this.ctx.once.resourceTiming;this.observer=new PerformanceObserver(e=>{for(let t of e.getEntries())this.record(t)}),this.observer.observe({type:`resource`,buffered:e}),this.ctx.once.resourceTiming=!0}uninstall(){this.observer?.disconnect(),this.observer=void 0}record(a){this.observer&&this.ctx.isActive?.()!==!1&&this.ctx.diagnostics.guard(`capture.record_failed`,`The library could not record a resource timing entry.`,()=>{let{capture:o,capturePolicy:s}=this.ctx.config,c=new URL(a.name,location.href),l=[this.ctx.config.endpoint,this.ctx.config.metricsEndpoint,this.ctx.config.tracesEndpoint];if(r.t(a.name,o.ignoreUrls)||l.some(e=>e&&c.href.startsWith(new URL(e,location.href).href))||!Number.isFinite(a.duration)||a.duration<0||![`http:`,`https:`].includes(c.protocol)||!n.t(this.window,s.resourcesPerWindow,this.ctx.diagnostics,`resource entries`,s.windowMs))return;let u={"resource.initiator_type":a.initiatorType,"server.address":c.hostname};this.ctx.recordMetric(i,a.duration,u);let d=typeof o.resourceTiming==`object`?o.resourceTiming.slowMs??1e3:e.on;d>0&&a.duration>=d&&this.ctx.logger.logEvent(`ui.resource.slow`,{...u,"resource.duration_ms":a.duration,"url.full":t.i(a.name,o.fullUrls,o.urlTransform,this.ctx.diagnostics)})})}};exports.ResourceTimingCapture=a;
2
+ //# sourceMappingURL=resource-timing-Cysw1S1f.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resource-timing-CbgwNpog.cjs","names":["matchesAny","allowInWindow","RESOURCE_SLOW_MS","recordedUrl","require_constants","require_platform","require_storm","require_types","RESOURCE_DURATION","ResourceTimingCapture","ctx","first","entry","list","url","endpoints","capture","endpoint","capturePolicy","attributes","slowMs"],"sources":["../src/capture/resource-timing.ts"],"sourcesContent":["import { RESOURCE_SLOW_MS } from \"../constants\";\nimport type { InstrumentDef } from \"../models/metric\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Resource durations in milliseconds. URLs and paths do not create metric series. */\nconst RESOURCE_DURATION: InstrumentDef = {\n name: \"ui.resource.duration\",\n kind: \"histogram\",\n unit: \"ms\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n};\n\n/** Records bounded resource timings and slow resource events. */\nexport class ResourceTimingCapture implements Capture {\n readonly name = \"resourceTiming\";\n\n private observer: PerformanceObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reads buffered resources only at the first install in this document. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n if (!supported?.includes(\"resource\")) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report resource timing entries. The resource timing capture is off.\",\n );\n return;\n }\n\n const first = !this.ctx.once.resourceTiming;\n this.observer = new PerformanceObserver((list) => {\n for (const entry of list.getEntries()) {\n this.record(entry as PerformanceResourceTiming);\n }\n });\n this.observer.observe({ type: \"resource\", buffered: first });\n this.ctx.once.resourceTiming = true;\n }\n\n /** Disconnects the observer. */\n uninstall(): void {\n this.observer?.disconnect();\n this.observer = undefined;\n }\n\n private record(entry: PerformanceResourceTiming): void {\n if (!this.observer || this.ctx.isActive?.() === false) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a resource timing entry.\",\n () => {\n const { capture, capturePolicy } = this.ctx.config;\n const url = new URL(entry.name, location.href);\n const endpoints = [\n this.ctx.config.endpoint,\n this.ctx.config.metricsEndpoint,\n this.ctx.config.tracesEndpoint,\n ];\n if (\n matchesAny(entry.name, capture.ignoreUrls) ||\n endpoints.some(\n (endpoint) => endpoint && url.href.startsWith(new URL(endpoint, location.href).href),\n )\n ) {\n return;\n }\n if (\n !Number.isFinite(entry.duration) ||\n entry.duration < 0 ||\n ![\"http:\", \"https:\"].includes(url.protocol)\n ) {\n return;\n }\n if (\n !allowInWindow(\n this.window,\n capturePolicy.resourcesPerWindow,\n this.ctx.diagnostics,\n \"resource entries\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n const attributes = {\n \"resource.initiator_type\": entry.initiatorType,\n \"server.address\": url.hostname,\n };\n this.ctx.recordMetric(RESOURCE_DURATION, entry.duration, attributes);\n\n const slowMs =\n typeof capture.resourceTiming === \"object\"\n ? (capture.resourceTiming.slowMs ?? RESOURCE_SLOW_MS)\n : RESOURCE_SLOW_MS;\n if (slowMs > 0 && entry.duration >= slowMs) {\n this.ctx.logger.logEvent(\"ui.resource.slow\", {\n ...attributes,\n \"resource.duration_ms\": entry.duration,\n \"url.full\": recordedUrl(\n entry.name,\n capture.fullUrls,\n capture.urlTransform,\n this.ctx.diagnostics,\n ),\n });\n }\n },\n );\n }\n}\n"],"mappings":"qJAOA,IAAMQ,EAAmC,CACvC,KAAM,uBACN,KAAM,YACN,KAAM,KACN,WAAY,CAAC,EAAG,EAAG,GAAI,GAAI,GAAI,IAAK,IAAK,IAAK,IAAM,KAAM,IAAM,GAAK,CACvE,EAGaC,EAAb,KAAsD,CAOvB,IAN7B,KAAgB,iBAEhB,SAEA,OAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,EAE5D,YAAY,EAAsC,CAArB,KAAA,IAAAC,CAAsB,CAGnD,SAAgB,CACd,GAAI,KAAK,SACP,OAOF,GAAI,EAHF,OAAO,oBAAwB,IAC3B,IAAA,GACA,oBAAoB,oBAAA,EACV,SAAS,UAAU,EAAG,CACpC,KAAK,IAAI,YAAY,OACnB,yBACA,0FACF,EACA,MACF,CAEA,IAAMC,EAAQ,CAAC,KAAK,IAAI,KAAK,eAC7B,KAAK,SAAW,IAAI,oBAAqB,GAAS,CAChD,IAAK,IAAMC,KAASC,EAAK,WAAW,EAClC,KAAK,OAAOD,CAAkC,CAElD,CAAC,EACD,KAAK,SAAS,QAAQ,CAAE,KAAM,WAAY,SAAUD,CAAM,CAAC,EAC3D,KAAK,IAAI,KAAK,eAAiB,EACjC,CAGA,WAAkB,CAChB,KAAK,UAAU,WAAW,EAC1B,KAAK,SAAW,IAAA,EAClB,CAEA,OAAe,EAAwC,CAChD,KAAK,UAAY,KAAK,IAAI,WAAW,IAAM,IAIhD,KAAK,IAAI,YAAY,MACnB,wBACA,4DACM,CACJ,GAAM,CAAE,UAAS,iBAAkB,KAAK,IAAI,OACtCG,EAAM,IAAI,IAAIF,EAAM,KAAM,SAAS,IAAI,EACvCG,EAAY,CAChB,KAAK,IAAI,OAAO,SAChB,KAAK,IAAI,OAAO,gBAChB,KAAK,IAAI,OAAO,cAClB,EAgBA,GAdEf,EAAAA,EAAWY,EAAM,KAAMI,EAAQ,UAAU,GACzCD,EAAU,KACP,GAAaE,GAAYH,EAAI,KAAK,WAAW,IAAI,IAAIG,EAAU,SAAS,IAAI,CAAC,CAAC,IAAI,CACrF,GAKA,CAAC,OAAO,SAASL,EAAM,QAAQ,GAC/BA,EAAM,SAAW,GACjB,CAAC,CAAC,QAAS,QAAQ,CAAC,CAAC,SAASE,EAAI,QAAQ,GAK1C,CAACb,EAAAA,EACC,KAAK,OACLiB,EAAc,mBACd,KAAK,IAAI,YACT,mBACAA,EAAc,QAChB,EAEA,OAGF,IAAMC,EAAa,CACjB,0BAA2BP,EAAM,cACjC,iBAAkBE,EAAI,QACxB,EACA,KAAK,IAAI,aAAaN,EAAmBI,EAAM,SAAUO,CAAU,EAEnE,IAAMC,EACJ,OAAOJ,EAAQ,gBAAmB,SAC7BA,EAAQ,eAAe,QAAA,IACxBd,EAAAA,GACFkB,EAAS,GAAKR,EAAM,UAAYQ,GAClC,KAAK,IAAI,OAAO,SAAS,mBAAoB,CAC3C,GAAGD,EACH,uBAAwBP,EAAM,SAC9B,WAAYT,EAAAA,EACVS,EAAM,KACNI,EAAQ,SACRA,EAAQ,aACR,KAAK,IAAI,WACX,CACF,CAAC,CAEL,CACF,CACF,CACF"}
1
+ {"version":3,"file":"resource-timing-Cysw1S1f.cjs","names":["matchesAny","allowInWindow","RESOURCE_SLOW_MS","recordedUrl","require_constants","require_platform","require_storm","require_types","RESOURCE_DURATION","ResourceTimingCapture","ctx","first","entry","list","url","endpoints","capture","endpoint","capturePolicy","attributes","slowMs"],"sources":["../src/capture/resource-timing.ts"],"sourcesContent":["import { RESOURCE_SLOW_MS } from \"../constants\";\nimport type { InstrumentDef } from \"../models/metric\";\nimport { recordedUrl } from \"../utils/platform\";\nimport { allowInWindow, type StormWindow } from \"./storm\";\nimport { type Capture, type CaptureContext, matchesAny } from \"./types\";\n\n/** Resource durations in milliseconds. URLs and paths do not create metric series. */\nconst RESOURCE_DURATION: InstrumentDef = {\n name: \"ui.resource.duration\",\n kind: \"histogram\",\n unit: \"ms\",\n boundaries: [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000],\n};\n\n/** Records bounded resource timings and slow resource events. */\nexport class ResourceTimingCapture implements Capture {\n readonly name = \"resourceTiming\";\n\n private observer: PerformanceObserver | undefined;\n\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n constructor(private readonly ctx: CaptureContext) {}\n\n /** Reads buffered resources only at the first install in this document. */\n install(): void {\n if (this.observer) {\n return;\n }\n\n const supported: readonly string[] | undefined =\n typeof PerformanceObserver === \"undefined\"\n ? undefined\n : PerformanceObserver.supportedEntryTypes;\n if (!supported?.includes(\"resource\")) {\n this.ctx.diagnostics.report(\n \"capture.install_failed\",\n \"The browser does not report resource timing entries. The resource timing capture is off.\",\n );\n return;\n }\n\n const first = !this.ctx.once.resourceTiming;\n this.observer = new PerformanceObserver((list) => {\n for (const entry of list.getEntries()) {\n this.record(entry as PerformanceResourceTiming);\n }\n });\n this.observer.observe({ type: \"resource\", buffered: first });\n this.ctx.once.resourceTiming = true;\n }\n\n /** Disconnects the observer. */\n uninstall(): void {\n this.observer?.disconnect();\n this.observer = undefined;\n }\n\n private record(entry: PerformanceResourceTiming): void {\n if (!this.observer || this.ctx.isActive?.() === false) {\n return;\n }\n\n this.ctx.diagnostics.guard(\n \"capture.record_failed\",\n \"The library could not record a resource timing entry.\",\n () => {\n const { capture, capturePolicy } = this.ctx.config;\n const url = new URL(entry.name, location.href);\n const endpoints = [\n this.ctx.config.endpoint,\n this.ctx.config.metricsEndpoint,\n this.ctx.config.tracesEndpoint,\n ];\n if (\n matchesAny(entry.name, capture.ignoreUrls) ||\n endpoints.some(\n (endpoint) => endpoint && url.href.startsWith(new URL(endpoint, location.href).href),\n )\n ) {\n return;\n }\n if (\n !Number.isFinite(entry.duration) ||\n entry.duration < 0 ||\n ![\"http:\", \"https:\"].includes(url.protocol)\n ) {\n return;\n }\n if (\n !allowInWindow(\n this.window,\n capturePolicy.resourcesPerWindow,\n this.ctx.diagnostics,\n \"resource entries\",\n capturePolicy.windowMs,\n )\n ) {\n return;\n }\n\n const attributes = {\n \"resource.initiator_type\": entry.initiatorType,\n \"server.address\": url.hostname,\n };\n this.ctx.recordMetric(RESOURCE_DURATION, entry.duration, attributes);\n\n const slowMs =\n typeof capture.resourceTiming === \"object\"\n ? (capture.resourceTiming.slowMs ?? RESOURCE_SLOW_MS)\n : RESOURCE_SLOW_MS;\n if (slowMs > 0 && entry.duration >= slowMs) {\n this.ctx.logger.logEvent(\"ui.resource.slow\", {\n ...attributes,\n \"resource.duration_ms\": entry.duration,\n \"url.full\": recordedUrl(\n entry.name,\n capture.fullUrls,\n capture.urlTransform,\n this.ctx.diagnostics,\n ),\n });\n }\n },\n );\n }\n}\n"],"mappings":"A,qJAOA,IAAMQ,EAAmC,CACvC,KAAM,uBACN,KAAM,YACN,KAAM,KACN,WAAY,CAAC,EAAG,EAAG,GAAI,GAAI,GAAI,IAAK,IAAK,IAAK,IAAM,KAAM,IAAM,GAAK,CACvE,EAGaC,EAAb,KAAsD,CAOvB,IAN7B,KAAgB,iBAEhB,SAEA,OAAuC,CAAE,MAAO,EAAG,MAAO,CAAE,EAE5D,YAAY,EAAsC,CAArB,KAAA,IAAAC,CAAsB,CAGnD,SAAgB,CACd,GAAI,KAAK,SACP,OAOF,GAAI,EAHF,OAAO,oBAAwB,IAC3B,IAAA,GACA,oBAAoB,oBAAA,EACV,SAAS,UAAU,EAAG,CACpC,KAAK,IAAI,YAAY,OACnB,yBACA,0FACF,EACA,M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UAAYQ,GAClC,KAAK,IAAI,OAAO,SAAS,mBAAoB,CAC3C,GAAGD,EACH,uBAAwBP,EAAM,SAC9B,WAAYT,EAAAA,EACVS,EAAM,KACNI,EAAQ,SACRA,EAAQ,aACR,KAAK,IAAI,WACX,CACF,CAAC,CAEL,CACF,CACF,CACF,E"}
@@ -1,6 +1,6 @@
1
- import { Ct as e, Nt as t, Vn as n, a as r, f as i, g as a, it as o, nt as s, rt as c, wt as l } from "./constants-CU60FG4w.js";
2
- import { t as u } from "./fixed-window-CtaFHanJ.js";
3
- //#region src/core/sampling.ts
1
+ import { Ct as e, Nt as t, Vn as n, a as r, f as i, g as a, it as o, nt as s, rt as c, wt as l } from "./constants-zyrqveN4.js";
2
+ import { t as u } from "./fixed-window-Dq3MLUUv.js";
3
+ // src/core/sampling.ts
4
4
  function d(e) {
5
5
  let t = c;
6
6
  for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, o);
@@ -55,7 +55,6 @@ var b = class {
55
55
  return !g(e.severityText, r) || t === 0 || u(this.window, t, n);
56
56
  }
57
57
  };
58
- //#endregion
59
58
  export { y as a, _ as i, m as n, v as o, p as r, b as t };
60
59
 
61
- //# sourceMappingURL=sampling-BLO_pcV4.js.map
60
+ //# sourceMappingURL=sampling-C4VV-1MS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sampling-BLO_pcV4.js","names":["LEVEL_BYPASS_TYPES","METRIC_KEYS","UINT32_MAX","ATTR_APP_NAMESPACE","ATTR_JOURNEY_ID","ATTR_LOG_TYPE","FNV_PRIME","ERROR_STORM_WINDOW_MS","FNV_OFFSET_BASIS","LEVEL_ORDER","countInWindow","hash","h","i","value","readAttr","record","key","longestPrefix","best","prefix","values","namespace","levelFor","config","rateFor","local","rates","fromRemote","remote","remoteMaxRate","defaultRate","atOrAbove","level","from","sampleKey","rate","shouldSampleInput","input","configLevel","belowMinLevel","shouldSample","ErrorCeiling","limit","windowMs"],"sources":["../src/core/sampling.ts"],"sourcesContent":["// src/core/sampling.ts\n//\n// This module samples records by namespace rule, journey ID and trace ID.\n// The journey ID is the sampling key. The module keeps or drops a full journey.\n// The result is the same across windows and reloads.\n\nimport {\n ATTR_APP_NAMESPACE,\n ATTR_JOURNEY_ID,\n ATTR_LOG_TYPE,\n ERROR_CEILING_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n FNV_OFFSET_BASIS,\n FNV_PRIME,\n LEVEL_BYPASS_TYPES,\n LEVEL_ORDER,\n LOG_TYPE_SPAN,\n METRIC_KEYS,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n UINT32_MAX,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel, LogRecord, LogType } from \"../models/log-record\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\nimport type { RemoteRules } from \"./remote-sampling\";\n\n/**\n * Computes the 32-bit FNV-1a hash of a string. Do not use it as a security hash.\n * @param value Key string to hash.\n * @returns Unsigned 32-bit integer hash.\n */\nfunction hash(value: string): number {\n let h = FNV_OFFSET_BASIS;\n\n for (let i = 0; i < value.length; i++) {\n h ^= value.charCodeAt(i);\n h = Math.imul(h, FNV_PRIME);\n }\n\n return h >>> 0;\n}\n\n/**\n * Reads a string attribute from a log record. It returns an empty string for an absent\n * or non-string value. A forwarded record has passed only a shape check.\n * @param record Log record to test.\n * @param key Attribute key.\n * @returns String attribute value, or empty string if missing or non-string.\n */\nfunction readAttr(record: LogRecord, key: string): string {\n const value: unknown = record.attributes[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** Value of the longest prefix that matches a namespace. */\ninterface PrefixMatch<T> {\n /** Value of the prefix, for example a rate or a level. */\n value: T;\n /** Length of the prefix. */\n length: number;\n}\n\n/**\n * Finds the longest prefix in a map that matches a namespace.\n * For example, trading.ticks overrides trading.\n * @param namespace Target application namespace.\n * @param values Value for each namespace prefix.\n * @returns The match, or undefined if no prefix matches.\n */\nexport function longestPrefix<T>(\n namespace: string,\n values: Record<string, T>,\n): PrefixMatch<T> | undefined {\n let best: PrefixMatch<T> | undefined;\n\n for (const [prefix, value] of Object.entries(values)) {\n const matches = namespace === prefix || namespace.startsWith(`${prefix}.`);\n\n if (matches && prefix.length > (best?.length ?? -1)) {\n best = { value, length: prefix.length };\n }\n }\n\n return best;\n}\n\n/**\n * Finds the minimum level of a namespace in the config. The longest matching prefix of\n * `minLevels` wins. A namespace with no match uses `minLevel`.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @returns The minimum level of the namespace.\n */\nexport function levelFor(namespace: string, config: ResolvedConfig): LogLevel {\n return longestPrefix(namespace, config.minLevels)?.value ?? config.minLevel;\n}\n\n/**\n * Finds the sampling rate for a namespace. The longest matching prefix wins.\n * A remote prefix wins over a config prefix of the same length.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns Matched namespace sampling rate or default rate.\n */\nfunction rateFor(namespace: string, config: ResolvedConfig, remote: RemoteRules | null): number {\n const { rates, defaultRate, remoteMaxRate } = config.sampling;\n const local = longestPrefix(namespace, rates);\n const fromRemote = remote ? longestPrefix(namespace, remote.rates) : undefined;\n\n // Cap a remote rate when sampling reads it. A configure() that lowers the cap then applies\n // immediately.\n if (fromRemote && fromRemote.length >= (local?.length ?? -1)) {\n return Math.min(fromRemote.value, remoteMaxRate);\n }\n\n if (local) {\n return local.value;\n }\n\n return remote?.defaultRate === undefined\n ? defaultRate\n : Math.min(remote.defaultRate, remoteMaxRate);\n}\n\n/**\n * Checks if a level is at or above a threshold level.\n * @param level Level of the record. A forwarded record can hold any string.\n * @param from Threshold level.\n * @returns True for a known level that is not below the threshold.\n */\nfunction atOrAbove(level: string, from: LogLevel): boolean {\n return LEVEL_ORDER[level as LogLevel] >= LEVEL_ORDER[from];\n}\n\n/**\n * Decides if sampling keeps a key at a rate. One key always gives the same result.\n * @param key Journey ID or trace ID.\n * @param rate Sampling rate, 0..1.\n * @returns True if sampling keeps the key.\n */\nexport function sampleKey(key: string, rate: number): boolean {\n if (rate >= SAMPLING_RATE_MAX) {\n return true;\n }\n if (rate <= SAMPLING_RATE_MIN) {\n return false;\n }\n\n return hash(key) / UINT32_MAX < rate;\n}\n\n/** Fields that sampling reads. The caller knows all of them before it builds a record. */\nexport interface SampleInput {\n /** Severity level of the entry. */\n level: string;\n /** Telemetry type classification. */\n type: string;\n /** Originating application namespace. */\n namespace: string;\n /** Active journey ID. It is empty when no journey runs. */\n journeyId: string;\n /** Trace ID. It is the sampling key when no journey runs. */\n traceId: string;\n /** True for a point of a counter or histogram. A sample of a sum gives a false sum. */\n aggregated?: boolean;\n}\n\n/**\n * Decides if sampling keeps an entry. It reads fields, not a record.\n * This lets the caller drop an entry before the attribute walk runs.\n * @param input Fields the sampling decision reads.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the entry.\n */\nexport function shouldSampleInput(\n input: SampleInput,\n config: ResolvedConfig,\n remote: RemoteRules | null,\n): boolean {\n // Records at or above alwaysSampleFrom and aggregated points bypass sampling filters. The\n // runtime samples a span by its trace before it records the span.\n if (\n input.aggregated === true ||\n input.type === LOG_TYPE_SPAN ||\n atOrAbove(input.level, config.sampling.alwaysSampleFrom)\n ) {\n return true;\n }\n\n if (config.sampling.alwaysSampleTypes.includes(input.type)) {\n return true;\n }\n\n let rate = rateFor(input.namespace, config, remote);\n\n // A remote level adds the records below the config level of the namespace. Cap them too, or they\n // ship at the config rate. The level does not apply to an action or a metric. Do not cap them.\n const configLevel = levelFor(input.namespace, config);\n const belowMinLevel = LEVEL_ORDER[input.level as LogLevel] < LEVEL_ORDER[configLevel];\n if (remote && belowMinLevel && !LEVEL_BYPASS_TYPES.includes(input.type as LogType)) {\n rate = Math.min(rate, config.sampling.remoteMaxRate);\n }\n\n // Use the trace ID when the journey ID is absent. The trace ID still groups one\n // operation.\n return sampleKey(input.journeyId || input.traceId, rate);\n}\n\n/**\n * Decides if sampling keeps a built log record. The runtime uses it for records\n * that a child context sends over the bus.\n * @param record Record to evaluate.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the record.\n */\nexport function shouldSample(\n record: LogRecord,\n config: ResolvedConfig,\n remote: RemoteRules | null = null,\n): boolean {\n return shouldSampleInput(\n {\n level: record.severityText,\n type: readAttr(record, ATTR_LOG_TYPE),\n namespace: readAttr(record, ATTR_APP_NAMESPACE),\n journeyId: readAttr(record, ATTR_JOURNEY_ID),\n traceId: record.traceId,\n aggregated:\n readAttr(record, ATTR_LOG_TYPE) === \"metric\" && readAttr(record, METRIC_KEYS.start) !== \"\",\n },\n config,\n remote,\n );\n}\n\n/**\n * Sets a fixed-window limit on the records that bypass sampling by their level.\n *\n * ErrorCapture already limits auto-captured errors. This class limits the remaining case.\n * An example is application code that calls logger.error in a render loop.\n */\nexport class ErrorCeiling {\n /** Records at or above the threshold level admitted in the current window. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * Checks a record against the limit. It counts only records at or above `from`.\n * @param record Record about to enter a stream.\n * @param limit Maximum records in one window. Set 0 for no limit.\n * @param windowMs Rate limit window, in milliseconds.\n * @param from Lowest level that bypasses sampling.\n * @returns False when the window has no allowance left. The caller must drop the record.\n */\n allow(\n record: LogRecord,\n limit = ERROR_CEILING_MAX_PER_WINDOW,\n windowMs = ERROR_STORM_WINDOW_MS,\n from: LogLevel = \"ERROR\",\n ): boolean {\n if (!atOrAbove(record.severityText, from)) {\n return true;\n }\n\n // Use a fixed window, not a sliding window. A quiet period adds no allowance.\n return limit === 0 || countInWindow(this.window, limit, windowMs);\n }\n}\n"],"mappings":";;;AAgCA,SAASW,EAAK,GAAuB;CACnC,IAAIC,IAAIJ;CAER,KAAK,IAAIK,IAAI,GAAGA,IAAIC,EAAM,QAAQ,KAEhC,AADA,KAAKA,EAAM,WAAWD,CAAC,GACvB,IAAI,KAAK,KAAKD,GAAGN,CAAS;CAG5B,OAAOM,MAAM;AACf;AASA,SA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IAAIF,IAAOX,EAAQa,EAAM,WAAWd,GAAQK,CAAM,GAI5CU,IAAchB,EAASe,EAAM,WAAWd,CAAM,GAC9CgB,IAAgB/B,EAAY6B,EAAM,SAAqB7B,EAAY8B;CAOzE,OANIV,KAAUW,KAAiB,CAACxC,EAAmB,SAASsC,EAAM,IAAe,MAC/E,IAAO,KAAK,IAAIF,GAAMZ,EAAO,SAAS,aAAa,IAK9CW,EAAUG,EAAM,aAAaA,EAAM,SAASF,CAAI;AACzD;AAUA,SAAgBK,EACd,GACA,GACA,IAA6B,MACpB;CACT,OAAOJ,EACL;EACE,OAAOrB,EAAO;EACd,MAAMD,EAASC,GAAQX,CAAa;EACpC,WAAWU,EAASC,GAAQb,CAAkB;EAC9C,WAAWY,EAASC,GAAQZ,CAAe;EAC3C,SAASY,EAAO;EAChB,YACED,EAASC,GAAA,UAAqB,MAAM,YAAYD,EAASC,GAAQf,EAAY,KAAK,MAAM;CAC5F,GACAuB,GACAK,CACF;AACF;AAQA,IAAaa,IAAb,MAA0B;CAExB,SAAuC;EAAE,OAAO;EAAG,OAAO;CAAE;CAU5D,MACE,GACA,IAAA,KACA,IAAWnC,GACX,IAAiB,SACR;EAMT,OALA,CAAKyB,EAAUhB,EAAO,cAAckB,CAAI,KAKjCS,MAAU,KAAKjC,EAAc,KAAK,QAAQiC,GAAOC,CAAQ;CAClE;AACF"}
1
+ {"version":3,"file":"sampling-C4VV-1MS.js","names":["LEVEL_BYPASS_TYPES","METRIC_KEYS","UINT32_MAX","ATTR_APP_NAMESPACE","ATTR_JOURNEY_ID","ATTR_LOG_TYPE","FNV_PRIME","ERROR_STORM_WINDOW_MS","FNV_OFFSET_BASIS","LEVEL_ORDER","countInWindow","hash","h","i","value","readAttr","record","key","longestPrefix","best","prefix","values","namespace","levelFor","config","rateFor","local","rates","fromRemote","remote","remoteMaxRate","defaultRate","atOrAbove","level","from","sampleKey","rate","shouldSampleInput","input","configLevel","belowMinLevel","shouldSample","ErrorCeiling","limit","windowMs"],"sources":["../src/core/sampling.ts"],"sourcesContent":["// src/core/sampling.ts\n//\n// This module samples records by namespace rule, journey ID and trace ID.\n// The journey ID is the sampling key. The module keeps or drops a full journey.\n// The result is the same across windows and reloads.\n\nimport {\n ATTR_APP_NAMESPACE,\n ATTR_JOURNEY_ID,\n ATTR_LOG_TYPE,\n ERROR_CEILING_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n FNV_OFFSET_BASIS,\n FNV_PRIME,\n LEVEL_BYPASS_TYPES,\n LEVEL_ORDER,\n LOG_TYPE_SPAN,\n METRIC_KEYS,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n UINT32_MAX,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel, LogRecord, LogType } from \"../models/log-record\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\nimport type { RemoteRules } from \"./remote-sampling\";\n\n/**\n * Computes the 32-bit FNV-1a hash of a string. Do not use it as a security hash.\n * @param value Key string to hash.\n * @returns Unsigned 32-bit integer hash.\n */\nfunction hash(value: string): number {\n let h = FNV_OFFSET_BASIS;\n\n for (let i = 0; i < value.length; i++) {\n h ^= value.charCodeAt(i);\n h = Math.imul(h, FNV_PRIME);\n }\n\n return h >>> 0;\n}\n\n/**\n * Reads a string attribute from a log record. It returns an empty string for an absent\n * or non-string value. A forwarded record has passed only a shape check.\n * @param record Log record to test.\n * @param key Attribute key.\n * @returns String attribute value, or empty string if missing or non-string.\n */\nfunction readAttr(record: LogRecord, key: string): string {\n const value: unknown = record.attributes[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** Value of the longest prefix that matches a namespace. */\ninterface PrefixMatch<T> {\n /** Value of the prefix, for example a rate or a level. */\n value: T;\n /** Length of the prefix. */\n length: number;\n}\n\n/**\n * Finds the longest prefix in a map that matches a namespace.\n * For example, trading.ticks overrides trading.\n * @param namespace Target application namespace.\n * @param values Value for each namespace prefix.\n * @returns The match, or undefined if no prefix matches.\n */\nexport function longestPrefix<T>(\n namespace: string,\n values: Record<string, T>,\n): PrefixMatch<T> | undefined {\n let best: PrefixMatch<T> | undefined;\n\n for (const [prefix, value] of Object.entries(values)) {\n const matches = namespace === prefix || namespace.startsWith(`${prefix}.`);\n\n if (matches && prefix.length > (best?.length ?? -1)) {\n best = { value, length: prefix.length };\n }\n }\n\n return best;\n}\n\n/**\n * Finds the minimum level of a namespace in the config. The longest matching prefix of\n * `minLevels` wins. A namespace with no match uses `minLevel`.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @returns The minimum level of the namespace.\n */\nexport function levelFor(namespace: string, config: ResolvedConfig): LogLevel {\n return longestPrefix(namespace, config.minLevels)?.value ?? config.minLevel;\n}\n\n/**\n * Finds the sampling rate for a namespace. The longest matching prefix wins.\n * A remote prefix wins over a config prefix of the same length.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns Matched namespace sampling rate or default rate.\n */\nfunction rateFor(namespace: string, config: ResolvedConfig, remote: RemoteRules | null): number {\n const { rates, defaultRate, remoteMaxRate } = config.sampling;\n const local = longestPrefix(namespace, rates);\n const fromRemote = remote ? longestPrefix(namespace, remote.rates) : undefined;\n\n // Cap a remote rate when sampling reads it. A configure() that lowers the cap then applies\n // immediately.\n if (fromRemote && fromRemote.length >= (local?.length ?? -1)) {\n return Math.min(fromRemote.value, remoteMaxRate);\n }\n\n if (local) {\n return local.value;\n }\n\n return remote?.defaultRate === undefined\n ? defaultRate\n : Math.min(remote.defaultRate, remoteMaxRate);\n}\n\n/**\n * Checks if a level is at or above a threshold level.\n * @param level Level of the record. A forwarded record can hold any string.\n * @param from Threshold level.\n * @returns True for a known level that is not below the threshold.\n */\nfunction atOrAbove(level: string, from: LogLevel): boolean {\n return LEVEL_ORDER[level as LogLevel] >= LEVEL_ORDER[from];\n}\n\n/**\n * Decides if sampling keeps a key at a rate. One key always gives the same result.\n * @param key Journey ID or trace ID.\n * @param rate Sampling rate, 0..1.\n * @returns True if sampling keeps the key.\n */\nexport function sampleKey(key: string, rate: number): boolean {\n if (rate >= SAMPLING_RATE_MAX) {\n return true;\n }\n if (rate <= SAMPLING_RATE_MIN) {\n return false;\n }\n\n return hash(key) / UINT32_MAX < rate;\n}\n\n/** Fields that sampling reads. The caller knows all of them before it builds a record. */\nexport interface SampleInput {\n /** Severity level of the entry. */\n level: string;\n /** Telemetry type classification. */\n type: string;\n /** Originating application namespace. */\n namespace: string;\n /** Active journey ID. It is empty when no journey runs. */\n journeyId: string;\n /** Trace ID. It is the sampling key when no journey runs. */\n traceId: string;\n /** True for a point of a counter or histogram. A sample of a sum gives a false sum. */\n aggregated?: boolean;\n}\n\n/**\n * Decides if sampling keeps an entry. It reads fields, not a record.\n * This lets the caller drop an entry before the attribute walk runs.\n * @param input Fields the sampling decision reads.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the entry.\n */\nexport function shouldSampleInput(\n input: SampleInput,\n config: ResolvedConfig,\n remote: RemoteRules | null,\n): boolean {\n // Records at or above alwaysSampleFrom and aggregated points bypass sampling filters. The\n // runtime samples a span by its trace before it records the span.\n if (\n input.aggregated === true ||\n input.type === LOG_TYPE_SPAN ||\n atOrAbove(input.level, config.sampling.alwaysSampleFrom)\n ) {\n return true;\n }\n\n if (config.sampling.alwaysSampleTypes.includes(input.type)) {\n return true;\n }\n\n let rate = rateFor(input.namespace, config, remote);\n\n // A remote level adds the records below the config level of the namespace. Cap them too, or they\n // ship at the config rate. The level does not apply to an action or a metric. Do not cap them.\n const configLevel = levelFor(input.namespace, config);\n const belowMinLevel = LEVEL_ORDER[input.level as LogLevel] < LEVEL_ORDER[configLevel];\n if (remote && belowMinLevel && !LEVEL_BYPASS_TYPES.includes(input.type as LogType)) {\n rate = Math.min(rate, config.sampling.remoteMaxRate);\n }\n\n // Use the trace ID when the journey ID is absent. The trace ID still groups one\n // operation.\n return sampleKey(input.journeyId || input.traceId, rate);\n}\n\n/**\n * Decides if sampling keeps a built log record. The runtime uses it for records\n * that a child context sends over the bus.\n * @param record Record to evaluate.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the record.\n */\nexport function shouldSample(\n record: LogRecord,\n config: ResolvedConfig,\n remote: RemoteRules | null = null,\n): boolean {\n return shouldSampleInput(\n {\n level: record.severityText,\n type: readAttr(record, ATTR_LOG_TYPE),\n namespace: readAttr(record, ATTR_APP_NAMESPACE),\n journeyId: readAttr(record, ATTR_JOURNEY_ID),\n traceId: record.traceId,\n aggregated:\n readAttr(record, ATTR_LOG_TYPE) === \"metric\" && readAttr(record, METRIC_KEYS.start) !== \"\",\n },\n config,\n remote,\n );\n}\n\n/**\n * Sets a fixed-window limit on the records that bypass sampling by their level.\n *\n * ErrorCapture already limits auto-captured errors. This class limits the remaining case.\n * An example is application code that calls logger.error in a render loop.\n */\nexport class ErrorCeiling {\n /** Records at or above the threshold level admitted in the current window. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * Checks a record against the limit. It counts only records at or above `from`.\n * @param record Record about to enter a stream.\n * @param limit Maximum records in one window. Set 0 for no limit.\n * @param windowMs Rate limit window, in milliseconds.\n * @param from Lowest level that bypasses sampling.\n * @returns False when the window has no allowance left. The caller must drop the record.\n */\n allow(\n record: LogRecord,\n limit = ERROR_CEILING_MAX_PER_WINDOW,\n windowMs = ERROR_STORM_WINDOW_MS,\n from: LogLevel = \"ERROR\",\n ): boolean {\n if (!atOrAbove(record.severityText, from)) {\n return true;\n }\n\n // Use a fixed window, not a sliding window. A quiet period adds no allowance.\n return limit === 0 || countInWindow(this.window, limit, windowMs);\n }\n}\n"],"mappings":";;;AAgCA,SAASW,EAAK,GAAuB;CACnC,IAAIC,IAAIJ;CAER,KAAK,IAAIK,IAAI,GAAGA,IAAIC,EAAM,QAAQ,KAEhC,AADA,KAAKA,EAAM,WAAWD,CAAC,GACvB,IAAI,KAAK,KAAKD,GAAGN,CAAS;CAG5B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M,IAAI,GACvD,OAAO;CAGT,IAAIF,IAAOX,EAAQa,EAAM,WAAWd,GAAQK,CAAM,GAI5CU,IAAchB,EAASe,EAAM,WAAWd,CAAM,GAC9CgB,IAAgB/B,EAAY6B,EAAM,SAAqB7B,EAAY8B;CAOzE,OANIV,KAAUW,KAAiB,CAACxC,EAAmB,SAASsC,EAAM,IAAe,MAC/E,IAAO,KAAK,IAAIF,GAAMZ,EAAO,SAAS,aAAa,IAK9CW,EAAUG,EAAM,aAAaA,EAAM,SAASF,CAAI;AACzD;AAUA,SAAgBK,EACd,GACA,GACA,IAA6B,MACpB;CACT,OAAOJ,EACL;EACE,OAAOrB,EAAO;EACd,MAAMD,EAASC,GAAQX,CAAa;EACpC,WAAWU,EAASC,GAAQb,CAAkB;EAC9C,WAAWY,EAASC,GAAQZ,CAAe;EAC3C,SAASY,EAAO;EAChB,YACED,EAASC,GAAA,UAAqB,MAAM,YAAYD,EAASC,GAAQf,EAAY,KAAK,MAAM;CAC5F,GACAuB,GACAK,CACF;AACF;AAQA,IAAaa,IAAb,MAA0B;CAExB,SAAuC;EAAE,OAAO;EAAG,OAAO;CAAE;CAU5D,MACE,GACA,IAAA,KACA,IAAWnC,GACX,IAAiB,SACR;EAMT,OALA,CAAKyB,EAAUhB,EAAO,cAAckB,CAAI,KAKjCS,MAAU,KAAKjC,EAAc,KAAK,QAAQiC,GAAOC,CAAQ;CAClE;AACF"}
@@ -1,2 +1,2 @@
1
- const e=require("./constants-CL0ZdI2f.cjs"),t=require("./fixed-window-CvESpFYV.cjs");function n(t){let n=e.rt;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,e.it);return n>>>0}function r(e,t){let n=e.attributes[t];return typeof n==`string`?n:``}function i(e,t){let n;for(let[r,i]of Object.entries(t))(e===r||e.startsWith(`${r}.`))&&r.length>(n?.length??-1)&&(n={value:i,length:r.length});return n}function a(e,t){return i(e,t.minLevels)?.value??t.minLevel}function o(e,t,n){let{rates:r,defaultRate:a,remoteMaxRate:o}=t.sampling,s=i(e,r),c=n?i(e,n.rates):void 0;return c&&c.length>=(s?.length??-1)?Math.min(c.value,o):s?s.value:n?.defaultRate===void 0?a:Math.min(n.defaultRate,o)}function s(t,n){return e.wt[t]>=e.wt[n]}function c(t,r){return r>=1?!0:r<=0?!1:n(t)/e.Vn<r}function l(t,n,r){if(t.aggregated===!0||t.type===`span`||s(t.level,n.sampling.alwaysSampleFrom)||n.sampling.alwaysSampleTypes.includes(t.type))return!0;let i=o(t.namespace,n,r),l=a(t.namespace,n),u=e.wt[t.level]<e.wt[l];return r&&u&&!e.Ct.includes(t.type)&&(i=Math.min(i,n.sampling.remoteMaxRate)),c(t.journeyId||t.traceId,i)}function u(t,n,i=null){return l({level:t.severityText,type:r(t,e.g),namespace:r(t,e.a),journeyId:r(t,e.f),traceId:t.traceId,aggregated:r(t,`log.type`)===`metric`&&r(t,e.Nt.start)!==``},n,i)}var d=class{window={start:0,count:0};allow(n,r=500,i=e.nt,a=`ERROR`){return!s(n.severityText,a)||r===0||t.t(this.window,r,i)}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
2
- //# sourceMappingURL=sampling-ECGVYiDD.cjs.map
1
+ const e=require("./constants-DqKJH_MP.cjs"),t=require("./fixed-window-CvESpFYV.cjs");function n(t){let n=e.rt;for(let r=0;r<t.length;r++)n^=t.charCodeAt(r),n=Math.imul(n,e.it);return n>>>0}function r(e,t){let n=e.attributes[t];return typeof n==`string`?n:``}function i(e,t){let n;for(let[r,i]of Object.entries(t))(e===r||e.startsWith(`${r}.`))&&r.length>(n?.length??-1)&&(n={value:i,length:r.length});return n}function a(e,t){return i(e,t.minLevels)?.value??t.minLevel}function o(e,t,n){let{rates:r,defaultRate:a,remoteMaxRate:o}=t.sampling,s=i(e,r),c=n?i(e,n.rates):void 0;return c&&c.length>=(s?.length??-1)?Math.min(c.value,o):s?s.value:n?.defaultRate===void 0?a:Math.min(n.defaultRate,o)}function s(t,n){return e.wt[t]>=e.wt[n]}function c(t,r){return r>=1?!0:r<=0?!1:n(t)/e.Vn<r}function l(t,n,r){if(t.aggregated===!0||t.type===`span`||s(t.level,n.sampling.alwaysSampleFrom)||n.sampling.alwaysSampleTypes.includes(t.type))return!0;let i=o(t.namespace,n,r),l=a(t.namespace,n),u=e.wt[t.level]<e.wt[l];return r&&u&&!e.Ct.includes(t.type)&&(i=Math.min(i,n.sampling.remoteMaxRate)),c(t.journeyId||t.traceId,i)}function u(t,n,i=null){return l({level:t.severityText,type:r(t,e.g),namespace:r(t,e.a),journeyId:r(t,e.f),traceId:t.traceId,aggregated:r(t,`log.type`)===`metric`&&r(t,e.Nt.start)!==``},n,i)}var d=class{window={start:0,count:0};allow(n,r=500,i=e.nt,a=`ERROR`){return!s(n.severityText,a)||r===0||t.t(this.window,r,i)}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return d}});
2
+ //# sourceMappingURL=sampling-Ckh2yW9k.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"sampling-ECGVYiDD.cjs","names":["FNV_OFFSET_BASIS","FNV_PRIME","LEVEL_ORDER","UINT32_MAX","LEVEL_BYPASS_TYPES","ATTR_LOG_TYPE","ATTR_APP_NAMESPACE","ATTR_JOURNEY_ID","METRIC_KEYS","ERROR_STORM_WINDOW_MS","countInWindow","require_constants","require_fixed_window","hash","h","i","value","readAttr","record","key","longestPrefix","best","prefix","values","namespace","levelFor","config","rateFor","local","rates","fromRemote","remote","remoteMaxRate","defaultRate","atOrAbove","level","from","sampleKey","rate","shouldSampleInput","input","configLevel","belowMinLevel","shouldSample","ErrorCeiling","limit","windowMs"],"sources":["../src/core/sampling.ts"],"sourcesContent":["// src/core/sampling.ts\n//\n// This module samples records by namespace rule, journey ID and trace ID.\n// The journey ID is the sampling key. The module keeps or drops a full journey.\n// The result is the same across windows and reloads.\n\nimport {\n ATTR_APP_NAMESPACE,\n ATTR_JOURNEY_ID,\n ATTR_LOG_TYPE,\n ERROR_CEILING_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n FNV_OFFSET_BASIS,\n FNV_PRIME,\n LEVEL_BYPASS_TYPES,\n LEVEL_ORDER,\n LOG_TYPE_SPAN,\n METRIC_KEYS,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n UINT32_MAX,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel, LogRecord, LogType } from \"../models/log-record\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\nimport type { RemoteRules } from \"./remote-sampling\";\n\n/**\n * Computes the 32-bit FNV-1a hash of a string. Do not use it as a security hash.\n * @param value Key string to hash.\n * @returns Unsigned 32-bit integer hash.\n */\nfunction hash(value: string): number {\n let h = FNV_OFFSET_BASIS;\n\n for (let i = 0; i < value.length; i++) {\n h ^= value.charCodeAt(i);\n h = Math.imul(h, FNV_PRIME);\n }\n\n return h >>> 0;\n}\n\n/**\n * Reads a string attribute from a log record. It returns an empty string for an absent\n * or non-string value. A forwarded record has passed only a shape check.\n * @param record Log record to test.\n * @param key Attribute key.\n * @returns String attribute value, or empty string if missing or non-string.\n */\nfunction readAttr(record: LogRecord, key: string): string {\n const value: unknown = record.attributes[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** Value of the longest prefix that matches a namespace. */\ninterface PrefixMatch<T> {\n /** Value of the prefix, for example a rate or a level. */\n value: T;\n /** Length of the prefix. */\n length: number;\n}\n\n/**\n * Finds the longest prefix in a map that matches a namespace.\n * For example, trading.ticks overrides trading.\n * @param namespace Target application namespace.\n * @param values Value for each namespace prefix.\n * @returns The match, or undefined if no prefix matches.\n */\nexport function longestPrefix<T>(\n namespace: string,\n values: Record<string, T>,\n): PrefixMatch<T> | undefined {\n let best: PrefixMatch<T> | undefined;\n\n for (const [prefix, value] of Object.entries(values)) {\n const matches = namespace === prefix || namespace.startsWith(`${prefix}.`);\n\n if (matches && prefix.length > (best?.length ?? -1)) {\n best = { value, length: prefix.length };\n }\n }\n\n return best;\n}\n\n/**\n * Finds the minimum level of a namespace in the config. The longest matching prefix of\n * `minLevels` wins. A namespace with no match uses `minLevel`.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @returns The minimum level of the namespace.\n */\nexport function levelFor(namespace: string, config: ResolvedConfig): LogLevel {\n return longestPrefix(namespace, config.minLevels)?.value ?? config.minLevel;\n}\n\n/**\n * Finds the sampling rate for a namespace. The longest matching prefix wins.\n * A remote prefix wins over a config prefix of the same length.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns Matched namespace sampling rate or default rate.\n */\nfunction rateFor(namespace: string, config: ResolvedConfig, remote: RemoteRules | null): number {\n const { rates, defaultRate, remoteMaxRate } = config.sampling;\n const local = longestPrefix(namespace, rates);\n const fromRemote = remote ? longestPrefix(namespace, remote.rates) : undefined;\n\n // Cap a remote rate when sampling reads it. A configure() that lowers the cap then applies\n // immediately.\n if (fromRemote && fromRemote.length >= (local?.length ?? -1)) {\n return Math.min(fromRemote.value, remoteMaxRate);\n }\n\n if (local) {\n return local.value;\n }\n\n return remote?.defaultRate === undefined\n ? defaultRate\n : Math.min(remote.defaultRate, remoteMaxRate);\n}\n\n/**\n * Checks if a level is at or above a threshold level.\n * @param level Level of the record. A forwarded record can hold any string.\n * @param from Threshold level.\n * @returns True for a known level that is not below the threshold.\n */\nfunction atOrAbove(level: string, from: LogLevel): boolean {\n return LEVEL_ORDER[level as LogLevel] >= LEVEL_ORDER[from];\n}\n\n/**\n * Decides if sampling keeps a key at a rate. One key always gives the same result.\n * @param key Journey ID or trace ID.\n * @param rate Sampling rate, 0..1.\n * @returns True if sampling keeps the key.\n */\nexport function sampleKey(key: string, rate: number): boolean {\n if (rate >= SAMPLING_RATE_MAX) {\n return true;\n }\n if (rate <= SAMPLING_RATE_MIN) {\n return false;\n }\n\n return hash(key) / UINT32_MAX < rate;\n}\n\n/** Fields that sampling reads. The caller knows all of them before it builds a record. */\nexport interface SampleInput {\n /** Severity level of the entry. */\n level: string;\n /** Telemetry type classification. */\n type: string;\n /** Originating application namespace. */\n namespace: string;\n /** Active journey ID. It is empty when no journey runs. */\n journeyId: string;\n /** Trace ID. It is the sampling key when no journey runs. */\n traceId: string;\n /** True for a point of a counter or histogram. A sample of a sum gives a false sum. */\n aggregated?: boolean;\n}\n\n/**\n * Decides if sampling keeps an entry. It reads fields, not a record.\n * This lets the caller drop an entry before the attribute walk runs.\n * @param input Fields the sampling decision reads.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the entry.\n */\nexport function shouldSampleInput(\n input: SampleInput,\n config: ResolvedConfig,\n remote: RemoteRules | null,\n): boolean {\n // Records at or above alwaysSampleFrom and aggregated points bypass sampling filters. The\n // runtime samples a span by its trace before it records the span.\n if (\n input.aggregated === true ||\n input.type === LOG_TYPE_SPAN ||\n atOrAbove(input.level, config.sampling.alwaysSampleFrom)\n ) {\n return true;\n }\n\n if (config.sampling.alwaysSampleTypes.includes(input.type)) {\n return true;\n }\n\n let rate = rateFor(input.namespace, config, remote);\n\n // A remote level adds the records below the config level of the namespace. Cap them too, or they\n // ship at the config rate. The level does not apply to an action or a metric. Do not cap them.\n const configLevel = levelFor(input.namespace, config);\n const belowMinLevel = LEVEL_ORDER[input.level as LogLevel] < LEVEL_ORDER[configLevel];\n if (remote && belowMinLevel && !LEVEL_BYPASS_TYPES.includes(input.type as LogType)) {\n rate = Math.min(rate, config.sampling.remoteMaxRate);\n }\n\n // Use the trace ID when the journey ID is absent. The trace ID still groups one\n // operation.\n return sampleKey(input.journeyId || input.traceId, rate);\n}\n\n/**\n * Decides if sampling keeps a built log record. The runtime uses it for records\n * that a child context sends over the bus.\n * @param record Record to evaluate.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the record.\n */\nexport function shouldSample(\n record: LogRecord,\n config: ResolvedConfig,\n remote: RemoteRules | null = null,\n): boolean {\n return shouldSampleInput(\n {\n level: record.severityText,\n type: readAttr(record, ATTR_LOG_TYPE),\n namespace: readAttr(record, ATTR_APP_NAMESPACE),\n journeyId: readAttr(record, ATTR_JOURNEY_ID),\n traceId: record.traceId,\n aggregated:\n readAttr(record, ATTR_LOG_TYPE) === \"metric\" && readAttr(record, METRIC_KEYS.start) !== \"\",\n },\n config,\n remote,\n );\n}\n\n/**\n * Sets a fixed-window limit on the records that bypass sampling by their level.\n *\n * ErrorCapture already limits auto-captured errors. This class limits the remaining case.\n * An example is application code that calls logger.error in a render loop.\n */\nexport class ErrorCeiling {\n /** Records at or above the threshold level admitted in the current window. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * Checks a record against the limit. It counts only records at or above `from`.\n * @param record Record about to enter a stream.\n * @param limit Maximum records in one window. Set 0 for no limit.\n * @param windowMs Rate limit window, in milliseconds.\n * @param from Lowest level that bypasses sampling.\n * @returns False when the window has no allowance left. The caller must drop the record.\n */\n allow(\n record: LogRecord,\n limit = ERROR_CEILING_MAX_PER_WINDOW,\n windowMs = ERROR_STORM_WINDOW_MS,\n from: LogLevel = \"ERROR\",\n ): boolean {\n if (!atOrAbove(record.severityText, from)) {\n return true;\n }\n\n // Use a fixed window, not a sliding window. A quiet period adds no allowance.\n return limit === 0 || countInWindow(this.window, limit, windowMs);\n }\n}\n"],"mappings":"qFAgCA,SAAS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EL_BYPASS_TYPES","ATTR_LOG_TYPE","ATTR_APP_NAMESPACE","ATTR_JOURNEY_ID","METRIC_KEYS","ERROR_STORM_WINDOW_MS","countInWindow","require_constants","require_fixed_window","hash","h","i","value","readAttr","record","key","longestPrefix","best","prefix","values","namespace","levelFor","config","rateFor","local","rates","fromRemote","remote","remoteMaxRate","defaultRate","atOrAbove","level","from","sampleKey","rate","shouldSampleInput","input","configLevel","belowMinLevel","shouldSample","ErrorCeiling","limit","windowMs"],"sources":["../src/core/sampling.ts"],"sourcesContent":["// src/core/sampling.ts\n//\n// This module samples records by namespace rule, journey ID and trace ID.\n// The journey ID is the sampling key. The module keeps or drops a full journey.\n// The result is the same across windows and reloads.\n\nimport {\n ATTR_APP_NAMESPACE,\n ATTR_JOURNEY_ID,\n ATTR_LOG_TYPE,\n ERROR_CEILING_MAX_PER_WINDOW,\n ERROR_STORM_WINDOW_MS,\n FNV_OFFSET_BASIS,\n FNV_PRIME,\n LEVEL_BYPASS_TYPES,\n LEVEL_ORDER,\n LOG_TYPE_SPAN,\n METRIC_KEYS,\n SAMPLING_RATE_MAX,\n SAMPLING_RATE_MIN,\n UINT32_MAX,\n} from \"../constants\";\nimport type { ResolvedConfig } from \"../models/config\";\nimport type { LogLevel, LogRecord, LogType } from \"../models/log-record\";\nimport { countInWindow, type StormWindow } from \"../utils/fixed-window\";\nimport type { RemoteRules } from \"./remote-sampling\";\n\n/**\n * Computes the 32-bit FNV-1a hash of a string. Do not use it as a security hash.\n * @param value Key string to hash.\n * @returns Unsigned 32-bit integer hash.\n */\nfunction hash(value: string): number {\n let h = FNV_OFFSET_BASIS;\n\n for (let i = 0; i < value.length; i++) {\n h ^= value.charCodeAt(i);\n h = Math.imul(h, FNV_PRIME);\n }\n\n return h >>> 0;\n}\n\n/**\n * Reads a string attribute from a log record. It returns an empty string for an absent\n * or non-string value. A forwarded record has passed only a shape check.\n * @param record Log record to test.\n * @param key Attribute key.\n * @returns String attribute value, or empty string if missing or non-string.\n */\nfunction readAttr(record: LogRecord, key: string): string {\n const value: unknown = record.attributes[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\n/** Value of the longest prefix that matches a namespace. */\ninterface PrefixMatch<T> {\n /** Value of the prefix, for example a rate or a level. */\n value: T;\n /** Length of the prefix. */\n length: number;\n}\n\n/**\n * Finds the longest prefix in a map that matches a namespace.\n * For example, trading.ticks overrides trading.\n * @param namespace Target application namespace.\n * @param values Value for each namespace prefix.\n * @returns The match, or undefined if no prefix matches.\n */\nexport function longestPrefix<T>(\n namespace: string,\n values: Record<string, T>,\n): PrefixMatch<T> | undefined {\n let best: PrefixMatch<T> | undefined;\n\n for (const [prefix, value] of Object.entries(values)) {\n const matches = namespace === prefix || namespace.startsWith(`${prefix}.`);\n\n if (matches && prefix.length > (best?.length ?? -1)) {\n best = { value, length: prefix.length };\n }\n }\n\n return best;\n}\n\n/**\n * Finds the minimum level of a namespace in the config. The longest matching prefix of\n * `minLevels` wins. A namespace with no match uses `minLevel`.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @returns The minimum level of the namespace.\n */\nexport function levelFor(namespace: string, config: ResolvedConfig): LogLevel {\n return longestPrefix(namespace, config.minLevels)?.value ?? config.minLevel;\n}\n\n/**\n * Finds the sampling rate for a namespace. The longest matching prefix wins.\n * A remote prefix wins over a config prefix of the same length.\n * @param namespace Target application namespace.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns Matched namespace sampling rate or default rate.\n */\nfunction rateFor(namespace: string, config: ResolvedConfig, remote: RemoteRules | null): number {\n const { rates, defaultRate, remoteMaxRate } = config.sampling;\n const local = longestPrefix(namespace, rates);\n const fromRemote = remote ? longestPrefix(namespace, remote.rates) : undefined;\n\n // Cap a remote rate when sampling reads it. A configure() that lowers the cap then applies\n // immediately.\n if (fromRemote && fromRemote.length >= (local?.length ?? -1)) {\n return Math.min(fromRemote.value, remoteMaxRate);\n }\n\n if (local) {\n return local.value;\n }\n\n return remote?.defaultRate === undefined\n ? defaultRate\n : Math.min(remote.defaultRate, remoteMaxRate);\n}\n\n/**\n * Checks if a level is at or above a threshold level.\n * @param level Level of the record. A forwarded record can hold any string.\n * @param from Threshold level.\n * @returns True for a known level that is not below the threshold.\n */\nfunction atOrAbove(level: string, from: LogLevel): boolean {\n return LEVEL_ORDER[level as LogLevel] >= LEVEL_ORDER[from];\n}\n\n/**\n * Decides if sampling keeps a key at a rate. One key always gives the same result.\n * @param key Journey ID or trace ID.\n * @param rate Sampling rate, 0..1.\n * @returns True if sampling keeps the key.\n */\nexport function sampleKey(key: string, rate: number): boolean {\n if (rate >= SAMPLING_RATE_MAX) {\n return true;\n }\n if (rate <= SAMPLING_RATE_MIN) {\n return false;\n }\n\n return hash(key) / UINT32_MAX < rate;\n}\n\n/** Fields that sampling reads. The caller knows all of them before it builds a record. */\nexport interface SampleInput {\n /** Severity level of the entry. */\n level: string;\n /** Telemetry type classification. */\n type: string;\n /** Originating application namespace. */\n namespace: string;\n /** Active journey ID. It is empty when no journey runs. */\n journeyId: string;\n /** Trace ID. It is the sampling key when no journey runs. */\n traceId: string;\n /** True for a point of a counter or histogram. A sample of a sum gives a false sum. */\n aggregated?: boolean;\n}\n\n/**\n * Decides if sampling keeps an entry. It reads fields, not a record.\n * This lets the caller drop an entry before the attribute walk runs.\n * @param input Fields the sampling decision reads.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the entry.\n */\nexport function shouldSampleInput(\n input: SampleInput,\n config: ResolvedConfig,\n remote: RemoteRules | null,\n): boolean {\n // Records at or above alwaysSampleFrom and aggregated points bypass sampling filters. The\n // runtime samples a span by its trace before it records the span.\n if (\n input.aggregated === true ||\n input.type === LOG_TYPE_SPAN ||\n atOrAbove(input.level, config.sampling.alwaysSampleFrom)\n ) {\n return true;\n }\n\n if (config.sampling.alwaysSampleTypes.includes(input.type)) {\n return true;\n }\n\n let rate = rateFor(input.namespace, config, remote);\n\n // A remote level adds the records below the config level of the namespace. Cap them too, or they\n // ship at the config rate. The level does not apply to an action or a metric. Do not cap them.\n const configLevel = levelFor(input.namespace, config);\n const belowMinLevel = LEVEL_ORDER[input.level as LogLevel] < LEVEL_ORDER[configLevel];\n if (remote && belowMinLevel && !LEVEL_BYPASS_TYPES.includes(input.type as LogType)) {\n rate = Math.min(rate, config.sampling.remoteMaxRate);\n }\n\n // Use the trace ID when the journey ID is absent. The trace ID still groups one\n // operation.\n return sampleKey(input.journeyId || input.traceId, rate);\n}\n\n/**\n * Decides if sampling keeps a built log record. The runtime uses it for records\n * that a child context sends over the bus.\n * @param record Record to evaluate.\n * @param config Active configuration instance.\n * @param remote Remote rules in force, or null.\n * @returns True if the runtime keeps and sends the record.\n */\nexport function shouldSample(\n record: LogRecord,\n config: ResolvedConfig,\n remote: RemoteRules | null = null,\n): boolean {\n return shouldSampleInput(\n {\n level: record.severityText,\n type: readAttr(record, ATTR_LOG_TYPE),\n namespace: readAttr(record, ATTR_APP_NAMESPACE),\n journeyId: readAttr(record, ATTR_JOURNEY_ID),\n traceId: record.traceId,\n aggregated:\n readAttr(record, ATTR_LOG_TYPE) === \"metric\" && readAttr(record, METRIC_KEYS.start) !== \"\",\n },\n config,\n remote,\n );\n}\n\n/**\n * Sets a fixed-window limit on the records that bypass sampling by their level.\n *\n * ErrorCapture already limits auto-captured errors. This class limits the remaining case.\n * An example is application code that calls logger.error in a render loop.\n */\nexport class ErrorCeiling {\n /** Records at or above the threshold level admitted in the current window. */\n private readonly window: StormWindow = { start: 0, count: 0 };\n\n /**\n * Checks a record against the limit. It counts only records at or above `from`.\n * @param record Record about to enter a stream.\n * @param limit Maximum records in one window. Set 0 for no limit.\n * @param windowMs Rate limit window, in milliseconds.\n * @param from Lowest level that bypasses sampling.\n * @returns False when the window has no allowance left. The caller must drop the record.\n */\n allow(\n record: LogRecord,\n limit = ERROR_CEILING_MAX_PER_WINDOW,\n windowMs = ERROR_STORM_WINDOW_MS,\n from: LogLevel = \"ERROR\",\n ): boolean {\n if (!atOrAbove(record.severityText, from)) {\n return true;\n }\n\n // Use a fixed window, not a sliding window. A quiet period adds no allowance.\n return limit === 0 || countInWindow(this.window, limit, windowMs);\n }\n}\n"],"mappings":"A,qFAgCA,SAASa,EAAK,EAAuB,CACnC,IAAIC,EAAId,EAAAA,GAER,IAAK,IAAIe,EAAI,EAAGA,EAAIC,EAAM,OAAQ,IAChC,GAAKA,EAAM,WAAWD,CAAC,EACvB,EAAI,KAAK,KAAKD,EAAGb,EAAAA,EAAS,EAG5B,OAAOa,IAAM,CACf,CASA,SAASG,EAAS,EAAmB,EAAqB,CACxD,IAAMD,EAAiBE,EAAO,WAAWC,GACzC,OAAO,OAAOH,GAAU,SAAWA,EAAQ,EAC7C,CAiBA,SAAgBI,EACd,EACA,EAC4B,CAC5B,IAAIC,EAEJ,IAAK,GAAM,CAACC,EAAQN,KAAU,OAAO,QAAQO,CAAM,GACjCC,IAAcF,GAAUE,EAAU,WAAW,GAAGF,EAAO,EAAE,IAE1DA,EAAO,QAAUD,GAAM,QAAU,MAC9C,EAAO,CAAE,QAAO,OAAQC,EAAO,MAAO,GAI1C,OAAOD,CACT,CASA,SAAgBI,EAAS,EAAmB,EAAkC,CAC5E,OAAOL,EAAcI,EAAWE,EAAO,SAAS,CAAC,EAAE,OAASA,EAAO,QACrE,CAUA,SAASC,EAAQ,EAAmB,EAAwB,EAAoC,CAC9F,GAAM,CAAE,QAAO,cAAa,iBAAkBD,EAAO,SAC/CE,EAAQR,EAAcI,EAAWK,CAAK,EACtCC,EAAaC,EAASX,EAAcI,EAAWO,EAAO,KAAK,EAAI,IAAA,GAYrE,OARID,GAAcA,EAAW,SAAWF,GAAO,QAAU,IAChD,KAAK,IAAIE,EAAW,MAAOE,CAAa,EAG7CJ,EACKA,EAAM,MAGRG,GAAQ,cAAgB,IAAA,GAC3BE,EACA,KAAK,IAAIF,EAAO,YAAaC,CAAa,CAChD,CAQA,SAASE,EAAU,EAAe,EAAyB,CACzD,OAAOhC,EAAAA,GAAYiC,IAA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mC,EAAOC,CAAQ,CAClE,CACF,E"}
@@ -1,6 +1,6 @@
1
- import "./constants-CU60FG4w.js";
2
- import { n as e, t } from "./error-like-Ywo5uRHo.js";
3
- //#region src/utils/sanitize.ts
1
+ import "./constants-zyrqveN4.js";
2
+ import { n as e, t } from "./error-like-B11pB4aL.js";
3
+ // src/utils/sanitize.ts
4
4
  function n(e, t) {
5
5
  if (e.length <= t) return e;
6
6
  let n = r(e.charCodeAt(t - 1)) ? t - 1 : t;
@@ -107,7 +107,6 @@ function l(e) {
107
107
  }
108
108
  return t;
109
109
  }
110
- //#endregion
111
110
  export { n as i, a as n, o as r, l as t };
112
111
 
113
- //# sourceMappingURL=sanitize-DS0G4_ea.js.map
112
+ //# sourceMappingURL=sanitize-6ymPlVvP.js.map