@safaricom-mxl/web-sdk 0.1.3 → 0.1.5

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 (606) hide show
  1. package/README.md +18 -14
  2. package/UPGRADING.md +23 -1
  3. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.cjs +12 -1
  4. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.cjs.map +1 -1
  5. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.d.cts +2 -0
  6. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.d.cts.map +1 -1
  7. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.d.ts +2 -0
  8. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.d.ts.map +1 -1
  9. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.js +12 -1
  10. package/dist/api-page/manager/ProxyPageManager/ProxyPageManager.js.map +1 -1
  11. package/dist/api-page/manager/types.d.cts +2 -1
  12. package/dist/api-page/manager/types.d.cts.map +1 -1
  13. package/dist/api-page/manager/types.d.ts +2 -1
  14. package/dist/api-page/manager/types.d.ts.map +1 -1
  15. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.cjs +1 -1
  16. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.cjs.map +1 -1
  17. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.d.cts +1 -1
  18. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.d.cts.map +1 -1
  19. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.d.ts +1 -1
  20. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.d.ts.map +1 -1
  21. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.js +1 -1
  22. package/dist/api-sessions/manager/NoOpUserSessionManager/NoOpUserSessionManager.js.map +1 -1
  23. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.cjs +2 -2
  24. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.cjs.map +1 -1
  25. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.d.cts +1 -1
  26. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.d.cts.map +1 -1
  27. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.d.ts +1 -1
  28. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.d.ts.map +1 -1
  29. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.js +2 -2
  30. package/dist/api-sessions/manager/ProxyUserSessionManager/ProxyUserSessionManager.js.map +1 -1
  31. package/dist/constants/attributes.cjs +12 -0
  32. package/dist/constants/attributes.cjs.map +1 -1
  33. package/dist/constants/attributes.d.cts +7 -1
  34. package/dist/constants/attributes.d.cts.map +1 -1
  35. package/dist/constants/attributes.d.ts +7 -1
  36. package/dist/constants/attributes.d.ts.map +1 -1
  37. package/dist/constants/attributes.js +7 -1
  38. package/dist/constants/attributes.js.map +1 -1
  39. package/dist/exporters/BaseFetchExporter/BaseFetchExporter.d.ts +1 -1
  40. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.cjs +1 -2
  41. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.cjs.map +1 -1
  42. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.d.cts +3 -4
  43. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.d.cts.map +1 -1
  44. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.d.ts +1 -2
  45. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.d.ts.map +1 -1
  46. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.js +1 -2
  47. package/dist/instrumentations/InstrumentationAbstract/InstrumentationAbstract.js.map +1 -1
  48. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.cjs +12 -2
  49. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.cjs.map +1 -1
  50. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.d.cts +5 -2
  51. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.d.cts.map +1 -1
  52. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.d.ts +5 -2
  53. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.d.ts.map +1 -1
  54. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.js +12 -2
  55. package/dist/instrumentations/MXLInstrumentationBase/MXLInstrumentationBase.js.map +1 -1
  56. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.cjs +1 -2
  57. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.cjs.map +1 -1
  58. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.d.cts.map +1 -1
  59. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.d.ts.map +1 -1
  60. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.js +1 -2
  61. package/dist/instrumentations/clicks/ClicksInstrumentation/ClicksInstrumentation.js.map +1 -1
  62. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.cjs +29 -33
  63. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.cjs.map +1 -1
  64. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.d.cts +4 -2
  65. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.d.cts.map +1 -1
  66. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.d.ts +4 -2
  67. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.d.ts.map +1 -1
  68. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.js +29 -33
  69. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/DocumentLoadInstrumentation.js.map +1 -1
  70. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.cjs +14 -12
  71. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.cjs.map +1 -1
  72. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.cts +3 -2
  73. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.cts.map +1 -1
  74. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.ts +3 -2
  75. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.d.ts.map +1 -1
  76. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.js +14 -12
  77. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/networkEvents.js.map +1 -1
  78. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/types.d.cts +1 -2
  79. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/types.d.cts.map +1 -1
  80. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/types.d.ts +1 -2
  81. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/types.d.ts.map +1 -1
  82. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.cjs +1 -1
  83. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.cjs.map +1 -1
  84. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.js +1 -1
  85. package/dist/instrumentations/document-load/DocumentLoadInstrumentation/utils.js.map +1 -1
  86. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.cjs +3 -5
  87. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.cjs.map +1 -1
  88. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.d.cts.map +1 -1
  89. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.d.ts.map +1 -1
  90. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.js +3 -5
  91. package/dist/instrumentations/element-timing/ElementTimingInstrumentation/ElementTimingInstrumentation.js.map +1 -1
  92. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.cjs +7 -3
  93. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.cjs.map +1 -1
  94. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.d.cts +1 -0
  95. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.d.cts.map +1 -1
  96. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.d.ts +1 -0
  97. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.d.ts.map +1 -1
  98. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.js +7 -3
  99. package/dist/instrumentations/empty-root/EmptyRootInstrumentation/EmptyRootInstrumentation.js.map +1 -1
  100. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.cjs +2 -3
  101. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.cjs.map +1 -1
  102. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.d.cts.map +1 -1
  103. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.d.ts.map +1 -1
  104. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.js +2 -3
  105. package/dist/instrumentations/exceptions/GlobalExceptionInstrumentation/GlobalExceptionInstrumentation.js.map +1 -1
  106. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.cjs +4 -5
  107. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.cjs.map +1 -1
  108. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.d.cts.map +1 -1
  109. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.d.ts.map +1 -1
  110. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.js +3 -4
  111. package/dist/instrumentations/first-interaction/FirstInteractionInstrumentation/FirstInteractionInstrumentation.js.map +1 -1
  112. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.cjs +172 -0
  113. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.cjs.map +1 -0
  114. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.d.cts +38 -0
  115. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.d.cts.map +1 -0
  116. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.d.ts +38 -0
  117. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.d.ts.map +1 -0
  118. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.js +170 -0
  119. package/dist/instrumentations/js-profiler/JsProfilerInstrumentation.js.map +1 -0
  120. package/dist/instrumentations/js-profiler/constants.cjs +21 -0
  121. package/dist/instrumentations/js-profiler/constants.cjs.map +1 -0
  122. package/dist/instrumentations/js-profiler/constants.d.cts +13 -0
  123. package/dist/instrumentations/js-profiler/constants.d.cts.map +1 -0
  124. package/dist/instrumentations/js-profiler/constants.d.ts +13 -0
  125. package/dist/instrumentations/js-profiler/constants.d.ts.map +1 -0
  126. package/dist/instrumentations/js-profiler/constants.js +13 -0
  127. package/dist/instrumentations/js-profiler/constants.js.map +1 -0
  128. package/dist/instrumentations/js-profiler/fixture.cjs +54 -0
  129. package/dist/instrumentations/js-profiler/fixture.cjs.map +1 -0
  130. package/dist/instrumentations/js-profiler/fixture.d.cts +7 -0
  131. package/dist/instrumentations/js-profiler/fixture.d.cts.map +1 -0
  132. package/dist/instrumentations/js-profiler/fixture.d.ts +7 -0
  133. package/dist/instrumentations/js-profiler/fixture.d.ts.map +1 -0
  134. package/dist/instrumentations/js-profiler/fixture.js +53 -0
  135. package/dist/instrumentations/js-profiler/fixture.js.map +1 -0
  136. package/dist/instrumentations/js-profiler/reduceProfilerTrace.cjs +63 -0
  137. package/dist/instrumentations/js-profiler/reduceProfilerTrace.cjs.map +1 -0
  138. package/dist/instrumentations/js-profiler/reduceProfilerTrace.d.cts +7 -0
  139. package/dist/instrumentations/js-profiler/reduceProfilerTrace.d.cts.map +1 -0
  140. package/dist/instrumentations/js-profiler/reduceProfilerTrace.d.ts +7 -0
  141. package/dist/instrumentations/js-profiler/reduceProfilerTrace.d.ts.map +1 -0
  142. package/dist/instrumentations/js-profiler/reduceProfilerTrace.js +62 -0
  143. package/dist/instrumentations/js-profiler/reduceProfilerTrace.js.map +1 -0
  144. package/dist/instrumentations/js-profiler/types.cjs +0 -0
  145. package/dist/instrumentations/js-profiler/types.d.cts +51 -0
  146. package/dist/instrumentations/js-profiler/types.d.cts.map +1 -0
  147. package/dist/instrumentations/js-profiler/types.d.ts +51 -0
  148. package/dist/instrumentations/js-profiler/types.d.ts.map +1 -0
  149. package/dist/instrumentations/js-profiler/types.js +0 -0
  150. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.cjs +3 -5
  151. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.cjs.map +1 -1
  152. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.d.cts.map +1 -1
  153. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.d.ts.map +1 -1
  154. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.js +1 -3
  155. package/dist/instrumentations/loaf/LoafInstrumentation/LoafInstrumentation.js.map +1 -1
  156. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.cjs +2 -3
  157. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.cjs.map +1 -1
  158. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.d.cts.map +1 -1
  159. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.d.ts.map +1 -1
  160. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.js +1 -2
  161. package/dist/instrumentations/max-scroll-depth/MaxScrollDepthInstrumentation/MaxScrollDepthInstrumentation.js.map +1 -1
  162. package/dist/instrumentations/memory/MemoryInstrumentation.cjs +216 -0
  163. package/dist/instrumentations/memory/MemoryInstrumentation.cjs.map +1 -0
  164. package/dist/instrumentations/memory/MemoryInstrumentation.d.cts +55 -0
  165. package/dist/instrumentations/memory/MemoryInstrumentation.d.cts.map +1 -0
  166. package/dist/instrumentations/memory/MemoryInstrumentation.d.ts +55 -0
  167. package/dist/instrumentations/memory/MemoryInstrumentation.d.ts.map +1 -0
  168. package/dist/instrumentations/memory/MemoryInstrumentation.js +215 -0
  169. package/dist/instrumentations/memory/MemoryInstrumentation.js.map +1 -0
  170. package/dist/instrumentations/memory/browserFamily.cjs +13 -0
  171. package/dist/instrumentations/memory/browserFamily.cjs.map +1 -0
  172. package/dist/instrumentations/memory/browserFamily.d.cts +5 -0
  173. package/dist/instrumentations/memory/browserFamily.d.cts.map +1 -0
  174. package/dist/instrumentations/memory/browserFamily.d.ts +5 -0
  175. package/dist/instrumentations/memory/browserFamily.d.ts.map +1 -0
  176. package/dist/instrumentations/memory/browserFamily.js +12 -0
  177. package/dist/instrumentations/memory/browserFamily.js.map +1 -0
  178. package/dist/instrumentations/memory/constants.cjs +25 -0
  179. package/dist/instrumentations/memory/constants.cjs.map +1 -0
  180. package/dist/instrumentations/memory/constants.d.cts +13 -0
  181. package/dist/instrumentations/memory/constants.d.cts.map +1 -0
  182. package/dist/instrumentations/memory/constants.d.ts +13 -0
  183. package/dist/instrumentations/memory/constants.d.ts.map +1 -0
  184. package/dist/instrumentations/memory/constants.js +22 -0
  185. package/dist/instrumentations/memory/constants.js.map +1 -0
  186. package/dist/instrumentations/memory/resource.cjs +30 -0
  187. package/dist/instrumentations/memory/resource.cjs.map +1 -0
  188. package/dist/instrumentations/memory/resource.d.cts +16 -0
  189. package/dist/instrumentations/memory/resource.d.cts.map +1 -0
  190. package/dist/instrumentations/memory/resource.d.ts +16 -0
  191. package/dist/instrumentations/memory/resource.d.ts.map +1 -0
  192. package/dist/instrumentations/memory/resource.js +27 -0
  193. package/dist/instrumentations/memory/resource.js.map +1 -0
  194. package/dist/instrumentations/memory/startMemoryMeterProvider.cjs +27 -0
  195. package/dist/instrumentations/memory/startMemoryMeterProvider.cjs.map +1 -0
  196. package/dist/instrumentations/memory/startMemoryMeterProvider.d.cts +7 -0
  197. package/dist/instrumentations/memory/startMemoryMeterProvider.d.cts.map +1 -0
  198. package/dist/instrumentations/memory/startMemoryMeterProvider.d.ts +7 -0
  199. package/dist/instrumentations/memory/startMemoryMeterProvider.d.ts.map +1 -0
  200. package/dist/instrumentations/memory/startMemoryMeterProvider.js +25 -0
  201. package/dist/instrumentations/memory/startMemoryMeterProvider.js.map +1 -0
  202. package/dist/instrumentations/memory/types.cjs +0 -0
  203. package/dist/instrumentations/memory/types.d.cts +47 -0
  204. package/dist/instrumentations/memory/types.d.cts.map +1 -0
  205. package/dist/instrumentations/memory/types.d.ts +47 -0
  206. package/dist/instrumentations/memory/types.d.ts.map +1 -0
  207. package/dist/instrumentations/memory/types.js +0 -0
  208. package/dist/instrumentations/memory/visibility.cjs +25 -0
  209. package/dist/instrumentations/memory/visibility.cjs.map +1 -0
  210. package/dist/instrumentations/memory/visibility.d.cts +14 -0
  211. package/dist/instrumentations/memory/visibility.d.cts.map +1 -0
  212. package/dist/instrumentations/memory/visibility.d.ts +14 -0
  213. package/dist/instrumentations/memory/visibility.d.ts.map +1 -0
  214. package/dist/instrumentations/memory/visibility.js +24 -0
  215. package/dist/instrumentations/memory/visibility.js.map +1 -0
  216. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.cjs +62 -55
  217. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.cjs.map +1 -1
  218. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.d.cts +16 -5
  219. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.d.cts.map +1 -1
  220. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.d.ts +16 -5
  221. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.d.ts.map +1 -1
  222. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.js +62 -55
  223. package/dist/instrumentations/navigation/NavigationInstrumentation/NavigationInstrumentation.js.map +1 -1
  224. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.cjs +3 -3
  225. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.cjs.map +1 -1
  226. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.d.cts.map +1 -1
  227. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.d.ts.map +1 -1
  228. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.js +3 -3
  229. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV5/withMXLRoutingLegacy.js.map +1 -1
  230. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.cjs +10 -13
  231. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.cjs.map +1 -1
  232. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.d.cts.map +1 -1
  233. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.d.ts.map +1 -1
  234. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.js +10 -13
  235. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Data/listenToRouterChanges.js.map +1 -1
  236. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.cjs +8 -4
  237. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.cjs.map +1 -1
  238. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.d.cts.map +1 -1
  239. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.d.ts.map +1 -1
  240. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.js +8 -4
  241. package/dist/instrumentations/navigation/NavigationInstrumentation/react/reactRouterV6Declarative/withMXLRouting.js.map +1 -1
  242. package/dist/instrumentations/navigation/NavigationInstrumentation/types.d.cts +2 -0
  243. package/dist/instrumentations/navigation/NavigationInstrumentation/types.d.cts.map +1 -1
  244. package/dist/instrumentations/navigation/NavigationInstrumentation/types.d.ts +2 -0
  245. package/dist/instrumentations/navigation/NavigationInstrumentation/types.d.ts.map +1 -1
  246. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.cjs +14 -13
  247. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.cjs.map +1 -1
  248. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.d.cts +1 -0
  249. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.d.cts.map +1 -1
  250. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.d.ts +1 -0
  251. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.d.ts.map +1 -1
  252. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.js +13 -12
  253. package/dist/instrumentations/rage-click/RageClickInstrumentation/RageClickInstrumentation.js.map +1 -1
  254. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.cjs +0 -2
  255. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.cjs.map +1 -1
  256. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.d.cts.map +1 -1
  257. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.d.ts.map +1 -1
  258. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.js +0 -2
  259. package/dist/instrumentations/replay/ReplayInstrumentation/ReplayInstrumentation.js.map +1 -1
  260. package/dist/instrumentations/replay/ReplayInstrumentation/types.d.cts +1 -1
  261. package/dist/instrumentations/replay/ReplayInstrumentation/types.d.ts +1 -1
  262. package/dist/instrumentations/replay/events/capture/network.cjs +31 -22
  263. package/dist/instrumentations/replay/events/capture/network.cjs.map +1 -1
  264. package/dist/instrumentations/replay/events/capture/network.js +31 -22
  265. package/dist/instrumentations/replay/events/capture/network.js.map +1 -1
  266. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.cjs +2 -2
  267. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.cjs.map +1 -1
  268. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.d.cts.map +1 -1
  269. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.d.ts.map +1 -1
  270. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.js +2 -2
  271. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.esm.js.map +1 -1
  272. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.iife.cjs +1 -1
  273. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.iife.cjs.map +1 -1
  274. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.iife.js +1 -1
  275. package/dist/instrumentations/replay/rrwebLoader/loadRrwebModule.iife.js.map +1 -1
  276. package/dist/instrumentations/replay/rrwebLoader/types.d.cts +4 -2
  277. package/dist/instrumentations/replay/rrwebLoader/types.d.cts.map +1 -1
  278. package/dist/instrumentations/replay/rrwebLoader/types.d.ts +4 -2
  279. package/dist/instrumentations/replay/rrwebLoader/types.d.ts.map +1 -1
  280. package/dist/instrumentations/replay/transport/idleFlushTimer.cjs.map +1 -1
  281. package/dist/instrumentations/replay/transport/idleFlushTimer.d.cts.map +1 -1
  282. package/dist/instrumentations/replay/transport/idleFlushTimer.d.ts.map +1 -1
  283. package/dist/instrumentations/replay/transport/idleFlushTimer.js.map +1 -1
  284. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.cjs +4 -18
  285. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.cjs.map +1 -1
  286. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.d.cts +0 -2
  287. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.d.cts.map +1 -1
  288. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.d.ts +0 -2
  289. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.d.ts.map +1 -1
  290. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.js +3 -17
  291. package/dist/instrumentations/server-timing/ServerTimingInstrumentation/ServerTimingInstrumentation.js.map +1 -1
  292. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.cjs +8 -11
  293. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.cjs.map +1 -1
  294. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.d.cts.map +1 -1
  295. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.d.ts.map +1 -1
  296. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.js +8 -11
  297. package/dist/instrumentations/soft-navigation-performance/SoftNavigationPerformanceInstrumentation/SoftNavigationPerformanceInstrumentation.js.map +1 -1
  298. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.cjs +7 -10
  299. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.cjs.map +1 -1
  300. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.d.cts.map +1 -1
  301. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.d.ts.map +1 -1
  302. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.js +6 -9
  303. package/dist/instrumentations/user-timing/UserTimingInstrumentation/UserTimingInstrumentation.js.map +1 -1
  304. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.cjs +24 -16
  305. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.cjs.map +1 -1
  306. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.cts +3 -2
  307. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.cts.map +1 -1
  308. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.ts +3 -2
  309. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.ts.map +1 -1
  310. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.js +24 -16
  311. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.js.map +1 -1
  312. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.cjs +11 -63
  313. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.cjs.map +1 -1
  314. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.d.cts +4 -56
  315. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.d.cts.map +1 -1
  316. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.d.ts +4 -56
  317. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.d.ts.map +1 -1
  318. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.js +11 -62
  319. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/constants.js.map +1 -1
  320. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/types.d.cts +1 -2
  321. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/types.d.cts.map +1 -1
  322. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/types.d.ts +1 -2
  323. package/dist/instrumentations/web-vitals/WebVitalsInstrumentation/types.d.ts.map +1 -1
  324. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.cjs +5 -5
  325. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.cjs.map +1 -1
  326. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.d.cts.map +1 -1
  327. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.d.ts.map +1 -1
  328. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.js +4 -4
  329. package/dist/managers/MXLAnalyticsManager/MXLAnalyticsManager.js.map +1 -1
  330. package/dist/managers/MXLAnalyticsManager/types.d.cts +1 -2
  331. package/dist/managers/MXLAnalyticsManager/types.d.cts.map +1 -1
  332. package/dist/managers/MXLAnalyticsManager/types.d.ts +1 -2
  333. package/dist/managers/MXLAnalyticsManager/types.d.ts.map +1 -1
  334. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.cjs +14 -0
  335. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.cjs.map +1 -1
  336. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.d.cts +4 -1
  337. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.d.cts.map +1 -1
  338. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.d.ts +4 -1
  339. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.d.ts.map +1 -1
  340. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.js +14 -0
  341. package/dist/managers/MXLConfigManager/MXLDynamicConfigManager.js.map +1 -1
  342. package/dist/managers/MXLConfigManager/performanceDefaults.cjs +21 -0
  343. package/dist/managers/MXLConfigManager/performanceDefaults.cjs.map +1 -0
  344. package/dist/managers/MXLConfigManager/performanceDefaults.d.cts +12 -0
  345. package/dist/managers/MXLConfigManager/performanceDefaults.d.cts.map +1 -0
  346. package/dist/managers/MXLConfigManager/performanceDefaults.d.ts +12 -0
  347. package/dist/managers/MXLConfigManager/performanceDefaults.d.ts.map +1 -0
  348. package/dist/managers/MXLConfigManager/performanceDefaults.js +13 -0
  349. package/dist/managers/MXLConfigManager/performanceDefaults.js.map +1 -0
  350. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.cjs +29 -0
  351. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.cjs.map +1 -0
  352. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.d.cts +40 -0
  353. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.d.cts.map +1 -0
  354. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.d.ts +40 -0
  355. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.d.ts.map +1 -0
  356. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.js +27 -0
  357. package/dist/managers/MXLConfigManager/resolveEffectivePerformance.js.map +1 -0
  358. package/dist/managers/MXLConfigManager/types.d.cts +18 -1
  359. package/dist/managers/MXLConfigManager/types.d.cts.map +1 -1
  360. package/dist/managers/MXLConfigManager/types.d.ts +18 -1
  361. package/dist/managers/MXLConfigManager/types.d.ts.map +1 -1
  362. package/dist/managers/MXLConfigManager/utils.cjs +37 -0
  363. package/dist/managers/MXLConfigManager/utils.cjs.map +1 -1
  364. package/dist/managers/MXLConfigManager/utils.d.cts.map +1 -1
  365. package/dist/managers/MXLConfigManager/utils.d.ts.map +1 -1
  366. package/dist/managers/MXLConfigManager/utils.js +37 -0
  367. package/dist/managers/MXLConfigManager/utils.js.map +1 -1
  368. package/dist/managers/MXLLogManager/MXLLogManager.cjs +7 -8
  369. package/dist/managers/MXLLogManager/MXLLogManager.cjs.map +1 -1
  370. package/dist/managers/MXLLogManager/MXLLogManager.js +3 -4
  371. package/dist/managers/MXLLogManager/MXLLogManager.js.map +1 -1
  372. package/dist/managers/MXLLogManager/MXLLoggerProvider.cjs +46 -0
  373. package/dist/managers/MXLLogManager/MXLLoggerProvider.cjs.map +1 -0
  374. package/dist/managers/MXLLogManager/MXLLoggerProvider.d.cts +22 -0
  375. package/dist/managers/MXLLogManager/MXLLoggerProvider.d.cts.map +1 -0
  376. package/dist/managers/MXLLogManager/MXLLoggerProvider.d.ts +22 -0
  377. package/dist/managers/MXLLogManager/MXLLoggerProvider.d.ts.map +1 -0
  378. package/dist/managers/MXLLogManager/MXLLoggerProvider.js +44 -0
  379. package/dist/managers/MXLLogManager/MXLLoggerProvider.js.map +1 -0
  380. package/dist/managers/MXLLogManager/types.d.cts +9 -3
  381. package/dist/managers/MXLLogManager/types.d.cts.map +1 -1
  382. package/dist/managers/MXLLogManager/types.d.ts +9 -3
  383. package/dist/managers/MXLLogManager/types.d.ts.map +1 -1
  384. package/dist/managers/MXLPageManager/MXLPageManager.cjs +6 -5
  385. package/dist/managers/MXLPageManager/MXLPageManager.cjs.map +1 -1
  386. package/dist/managers/MXLPageManager/MXLPageManager.d.cts.map +1 -1
  387. package/dist/managers/MXLPageManager/MXLPageManager.d.ts.map +1 -1
  388. package/dist/managers/MXLPageManager/MXLPageManager.js +7 -6
  389. package/dist/managers/MXLPageManager/MXLPageManager.js.map +1 -1
  390. package/dist/managers/MXLTraceManager/MXLExtendedSpan.cjs +56 -9
  391. package/dist/managers/MXLTraceManager/MXLExtendedSpan.cjs.map +1 -1
  392. package/dist/managers/MXLTraceManager/MXLExtendedSpan.d.cts +21 -5
  393. package/dist/managers/MXLTraceManager/MXLExtendedSpan.d.cts.map +1 -1
  394. package/dist/managers/MXLTraceManager/MXLExtendedSpan.d.ts +21 -5
  395. package/dist/managers/MXLTraceManager/MXLExtendedSpan.d.ts.map +1 -1
  396. package/dist/managers/MXLTraceManager/MXLExtendedSpan.js +56 -10
  397. package/dist/managers/MXLTraceManager/MXLExtendedSpan.js.map +1 -1
  398. package/dist/managers/MXLTraceManager/MXLTraceManager.cjs +2 -2
  399. package/dist/managers/MXLTraceManager/MXLTraceManager.cjs.map +1 -1
  400. package/dist/managers/MXLTraceManager/MXLTraceManager.js +2 -2
  401. package/dist/managers/MXLTraceManager/MXLTraceManager.js.map +1 -1
  402. package/dist/managers/MXLTraceManager/MXLTracerProvider.cjs +42 -0
  403. package/dist/managers/MXLTraceManager/MXLTracerProvider.cjs.map +1 -0
  404. package/dist/managers/MXLTraceManager/MXLTracerProvider.d.cts +22 -0
  405. package/dist/managers/MXLTraceManager/MXLTracerProvider.d.cts.map +1 -0
  406. package/dist/managers/MXLTraceManager/MXLTracerProvider.d.ts +22 -0
  407. package/dist/managers/MXLTraceManager/MXLTracerProvider.d.ts.map +1 -0
  408. package/dist/managers/MXLTraceManager/MXLTracerProvider.js +40 -0
  409. package/dist/managers/MXLTraceManager/MXLTracerProvider.js.map +1 -0
  410. package/dist/managers/MXLTraceManager/types.cjs +0 -0
  411. package/dist/managers/MXLTraceManager/types.d.cts +10 -0
  412. package/dist/managers/MXLTraceManager/types.d.cts.map +1 -0
  413. package/dist/managers/MXLTraceManager/types.d.ts +10 -0
  414. package/dist/managers/MXLTraceManager/types.d.ts.map +1 -0
  415. package/dist/managers/MXLTraceManager/types.js +0 -0
  416. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.cjs +30 -20
  417. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.cjs.map +1 -1
  418. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.d.cts +3 -3
  419. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.d.cts.map +1 -1
  420. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.d.ts +3 -3
  421. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.d.ts.map +1 -1
  422. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.js +31 -21
  423. package/dist/managers/MXLUserSessionManager/MXLUserSessionManager.js.map +1 -1
  424. package/dist/managers/MXLUserSessionManager/types.d.cts +10 -2
  425. package/dist/managers/MXLUserSessionManager/types.d.cts.map +1 -1
  426. package/dist/managers/MXLUserSessionManager/types.d.ts +10 -2
  427. package/dist/managers/MXLUserSessionManager/types.d.ts.map +1 -1
  428. package/dist/mxl-web-sdk.js +12 -2
  429. package/dist/mxl-web-sdk.js.map +1 -1
  430. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.cjs.map +1 -1
  431. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.d.cts +2 -2
  432. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.d.cts.map +1 -1
  433. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.d.ts +2 -2
  434. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.d.ts.map +1 -1
  435. package/dist/processors/BrowserLogRecordProcessor/BrowserLogRecordProcessor.js.map +1 -1
  436. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.cjs.map +1 -1
  437. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.d.cts +2 -2
  438. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.d.cts.map +1 -1
  439. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.d.ts +2 -2
  440. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.d.ts.map +1 -1
  441. package/dist/processors/LogRecordScrubProcessor/LogRecordScrubProcessor.js.map +1 -1
  442. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.cjs.map +1 -1
  443. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.d.cts +2 -2
  444. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.d.cts.map +1 -1
  445. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.d.ts +2 -2
  446. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.d.ts.map +1 -1
  447. package/dist/processors/MXLLogRecordProcessor/MXLLogRecordProcessor.js.map +1 -1
  448. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.cjs +1 -1
  449. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.cjs.map +1 -1
  450. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.d.cts +2 -2
  451. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.d.cts.map +1 -1
  452. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.d.ts +2 -2
  453. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.d.ts.map +1 -1
  454. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.js +1 -1
  455. package/dist/processors/PageLogRecordProcessor/PageLogRecordProcessor.js.map +1 -1
  456. package/dist/processors/PageSpanProcessor/PageSpanProcessor.cjs +1 -1
  457. package/dist/processors/PageSpanProcessor/PageSpanProcessor.cjs.map +1 -1
  458. package/dist/processors/PageSpanProcessor/PageSpanProcessor.d.cts.map +1 -1
  459. package/dist/processors/PageSpanProcessor/PageSpanProcessor.d.ts.map +1 -1
  460. package/dist/processors/PageSpanProcessor/PageSpanProcessor.js +1 -1
  461. package/dist/processors/PageSpanProcessor/PageSpanProcessor.js.map +1 -1
  462. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.cjs +26 -0
  463. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.cjs.map +1 -0
  464. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.d.cts +20 -0
  465. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.d.cts.map +1 -0
  466. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.d.ts +20 -0
  467. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.d.ts.map +1 -0
  468. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.js +25 -0
  469. package/dist/processors/PerfClockLagLogRecordProcessor/PerfClockLagLogRecordProcessor.js.map +1 -0
  470. package/dist/processors/PerfClockLagLogRecordProcessor/types.cjs +0 -0
  471. package/dist/processors/PerfClockLagLogRecordProcessor/types.d.cts +9 -0
  472. package/dist/processors/PerfClockLagLogRecordProcessor/types.d.cts.map +1 -0
  473. package/dist/processors/PerfClockLagLogRecordProcessor/types.d.ts +9 -0
  474. package/dist/processors/PerfClockLagLogRecordProcessor/types.d.ts.map +1 -0
  475. package/dist/processors/PerfClockLagLogRecordProcessor/types.js +0 -0
  476. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.cjs +27 -0
  477. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.cjs.map +1 -0
  478. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.d.cts +21 -0
  479. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.d.cts.map +1 -0
  480. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.d.ts +21 -0
  481. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.d.ts.map +1 -0
  482. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.js +26 -0
  483. package/dist/processors/PerfClockLagSpanProcessor/PerfClockLagSpanProcessor.js.map +1 -0
  484. package/dist/processors/PerfClockLagSpanProcessor/types.cjs +0 -0
  485. package/dist/processors/PerfClockLagSpanProcessor/types.d.cts +9 -0
  486. package/dist/processors/PerfClockLagSpanProcessor/types.d.cts.map +1 -0
  487. package/dist/processors/PerfClockLagSpanProcessor/types.d.ts +9 -0
  488. package/dist/processors/PerfClockLagSpanProcessor/types.d.ts.map +1 -0
  489. package/dist/processors/PerfClockLagSpanProcessor/types.js +0 -0
  490. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.cjs +1 -1
  491. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.cjs.map +1 -1
  492. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.d.cts +2 -2
  493. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.d.cts.map +1 -1
  494. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.d.ts +2 -2
  495. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.d.ts.map +1 -1
  496. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.js +1 -1
  497. package/dist/processors/SignalCorrelationLogRecordProcessor/SignalCorrelationLogRecordProcessor.js.map +1 -1
  498. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.cjs.map +1 -1
  499. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.d.cts +2 -2
  500. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.d.cts.map +1 -1
  501. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.d.ts +2 -2
  502. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.d.ts.map +1 -1
  503. package/dist/processors/UserLogRecordProcessor/UserLogRecordProcessor.js.map +1 -1
  504. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.cjs.map +1 -1
  505. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.d.cts +2 -2
  506. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.d.cts.map +1 -1
  507. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.d.ts +2 -2
  508. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.d.ts.map +1 -1
  509. package/dist/processors/UserSessionLogRecordProcessor/UserSessionLogRecordProcessor.js.map +1 -1
  510. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.cjs +30 -0
  511. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.cjs.map +1 -0
  512. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.d.cts +22 -0
  513. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.d.cts.map +1 -0
  514. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.d.ts +22 -0
  515. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.d.ts.map +1 -0
  516. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.js +29 -0
  517. package/dist/processors/UserSessionSpanProcessor/UserSessionSpanProcessor.js.map +1 -0
  518. package/dist/processors/UserSessionSpanProcessor/types.cjs +0 -0
  519. package/dist/processors/UserSessionSpanProcessor/types.d.cts +9 -0
  520. package/dist/processors/UserSessionSpanProcessor/types.d.cts.map +1 -0
  521. package/dist/processors/UserSessionSpanProcessor/types.d.ts +9 -0
  522. package/dist/processors/UserSessionSpanProcessor/types.d.ts.map +1 -0
  523. package/dist/processors/UserSessionSpanProcessor/types.js +0 -0
  524. package/dist/resources/sdkConstants.cjs +1 -1
  525. package/dist/resources/sdkConstants.cjs.map +1 -1
  526. package/dist/resources/sdkConstants.d.cts +1 -1
  527. package/dist/resources/sdkConstants.d.ts +1 -1
  528. package/dist/resources/sdkConstants.js +1 -1
  529. package/dist/resources/sdkConstants.js.map +1 -1
  530. package/dist/sdk/endpoints.cjs +2 -2
  531. package/dist/sdk/endpoints.cjs.map +1 -1
  532. package/dist/sdk/endpoints.d.cts +1 -1
  533. package/dist/sdk/endpoints.d.ts +1 -1
  534. package/dist/sdk/endpoints.js +2 -2
  535. package/dist/sdk/endpoints.js.map +1 -1
  536. package/dist/sdk/initSDK.cjs +43 -12
  537. package/dist/sdk/initSDK.cjs.map +1 -1
  538. package/dist/sdk/initSDK.js +46 -15
  539. package/dist/sdk/initSDK.js.map +1 -1
  540. package/dist/sdk/networkInstrumentations.cjs +1 -1
  541. package/dist/sdk/networkInstrumentations.cjs.map +1 -1
  542. package/dist/sdk/networkInstrumentations.d.cts.map +1 -1
  543. package/dist/sdk/networkInstrumentations.d.ts.map +1 -1
  544. package/dist/sdk/networkInstrumentations.js +1 -1
  545. package/dist/sdk/networkInstrumentations.js.map +1 -1
  546. package/dist/sdk/resolveInitConfig.cjs +2 -1
  547. package/dist/sdk/resolveInitConfig.cjs.map +1 -1
  548. package/dist/sdk/resolveInitConfig.d.cts +4 -0
  549. package/dist/sdk/resolveInitConfig.d.cts.map +1 -1
  550. package/dist/sdk/resolveInitConfig.d.ts +4 -0
  551. package/dist/sdk/resolveInitConfig.d.ts.map +1 -1
  552. package/dist/sdk/resolveInitConfig.js +2 -1
  553. package/dist/sdk/resolveInitConfig.js.map +1 -1
  554. package/dist/sdk/setupDefaultInstrumentations.cjs +17 -1
  555. package/dist/sdk/setupDefaultInstrumentations.cjs.map +1 -1
  556. package/dist/sdk/setupDefaultInstrumentations.d.cts +2 -1
  557. package/dist/sdk/setupDefaultInstrumentations.d.cts.map +1 -1
  558. package/dist/sdk/setupDefaultInstrumentations.d.ts +2 -1
  559. package/dist/sdk/setupDefaultInstrumentations.d.ts.map +1 -1
  560. package/dist/sdk/setupDefaultInstrumentations.js +17 -1
  561. package/dist/sdk/setupDefaultInstrumentations.js.map +1 -1
  562. package/dist/sdk/types.d.cts +43 -2
  563. package/dist/sdk/types.d.cts.map +1 -1
  564. package/dist/sdk/types.d.ts +43 -2
  565. package/dist/sdk/types.d.ts.map +1 -1
  566. package/dist/transport/RetryingTransport/RetryingTransport.cjs +2 -2
  567. package/dist/transport/RetryingTransport/RetryingTransport.cjs.map +1 -1
  568. package/dist/transport/RetryingTransport/RetryingTransport.js +2 -2
  569. package/dist/transport/RetryingTransport/RetryingTransport.js.map +1 -1
  570. package/dist/utils/InMemoryStorage/InMemoryStorage.cjs +27 -0
  571. package/dist/utils/InMemoryStorage/InMemoryStorage.cjs.map +1 -0
  572. package/dist/utils/InMemoryStorage/InMemoryStorage.d.cts +13 -0
  573. package/dist/utils/InMemoryStorage/InMemoryStorage.d.cts.map +1 -0
  574. package/dist/utils/InMemoryStorage/InMemoryStorage.d.ts +13 -0
  575. package/dist/utils/InMemoryStorage/InMemoryStorage.d.ts.map +1 -0
  576. package/dist/utils/InMemoryStorage/InMemoryStorage.js +26 -0
  577. package/dist/utils/InMemoryStorage/InMemoryStorage.js.map +1 -0
  578. package/dist/utils/PerformanceManager/OTelPerformanceManager.cjs +71 -24
  579. package/dist/utils/PerformanceManager/OTelPerformanceManager.cjs.map +1 -1
  580. package/dist/utils/PerformanceManager/OTelPerformanceManager.d.cts +18 -19
  581. package/dist/utils/PerformanceManager/OTelPerformanceManager.d.cts.map +1 -1
  582. package/dist/utils/PerformanceManager/OTelPerformanceManager.d.ts +18 -19
  583. package/dist/utils/PerformanceManager/OTelPerformanceManager.d.ts.map +1 -1
  584. package/dist/utils/PerformanceManager/OTelPerformanceManager.js +70 -22
  585. package/dist/utils/PerformanceManager/OTelPerformanceManager.js.map +1 -1
  586. package/dist/utils/PerformanceManager/types.d.cts +28 -12
  587. package/dist/utils/PerformanceManager/types.d.cts.map +1 -1
  588. package/dist/utils/PerformanceManager/types.d.ts +28 -12
  589. package/dist/utils/PerformanceManager/types.d.ts.map +1 -1
  590. package/dist/utils/getWindowStorageOrInMemory.cjs +24 -0
  591. package/dist/utils/getWindowStorageOrInMemory.cjs.map +1 -0
  592. package/dist/utils/getWindowStorageOrInMemory.d.cts +13 -0
  593. package/dist/utils/getWindowStorageOrInMemory.d.cts.map +1 -0
  594. package/dist/utils/getWindowStorageOrInMemory.d.ts +13 -0
  595. package/dist/utils/getWindowStorageOrInMemory.d.ts.map +1 -0
  596. package/dist/utils/getWindowStorageOrInMemory.js +23 -0
  597. package/dist/utils/getWindowStorageOrInMemory.js.map +1 -0
  598. package/dist/utils/sdkLoadOriginOffset.cjs +12 -0
  599. package/dist/utils/sdkLoadOriginOffset.cjs.map +1 -0
  600. package/dist/utils/sdkLoadOriginOffset.d.cts +10 -0
  601. package/dist/utils/sdkLoadOriginOffset.d.cts.map +1 -0
  602. package/dist/utils/sdkLoadOriginOffset.d.ts +10 -0
  603. package/dist/utils/sdkLoadOriginOffset.d.ts.map +1 -0
  604. package/dist/utils/sdkLoadOriginOffset.js +11 -0
  605. package/dist/utils/sdkLoadOriginOffset.js.map +1 -0
  606. package/package.json +20 -22
@@ -8,9 +8,9 @@ const require_utils_getBfcacheNotRestoredReasons = require("../../../utils/getBf
8
8
  const require_utils_getSelector = require("../../../utils/getSelector.cjs");
9
9
  const require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes = require("./attributes.cjs");
10
10
  const require_instrumentations_web_vitals_WebVitalsInstrumentation_constants = require("./constants.cjs");
11
- let _opentelemetry_core = require("@opentelemetry/core");
12
- let _opentelemetry_api_logs = require("@opentelemetry/api-logs");
11
+ let _opentelemetry_api = require("@opentelemetry/api");
13
12
  let _opentelemetry_instrumentation = require("@opentelemetry/instrumentation");
13
+ let _opentelemetry_core = require("@opentelemetry/core");
14
14
  //#region src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts
15
15
  const roundClamp = (value) => Math.round(Math.max(0, value));
16
16
  const roundRect = (rect) => ({
@@ -143,7 +143,7 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
143
143
  _clsMetricId = void 0;
144
144
  _applyCustomLogRecordData;
145
145
  _listenersRegistered = false;
146
- constructor({ diag, perf, listeners = require_instrumentations_web_vitals_WebVitalsInstrumentation_constants.WEB_VITALS_ID_TO_LISTENER, urlDocument, urlAttribution = true, includeRawAttribution = true, reportSoftNavs = true, pageManager, applyCustomLogRecordData, ...config } = {}) {
146
+ constructor({ diag, perf, listeners, urlDocument, urlAttribution = true, includeRawAttribution = true, reportSoftNavs = true, pageManager, applyCustomLogRecordData, ...config } = {}) {
147
147
  super({
148
148
  config,
149
149
  diag,
@@ -151,19 +151,16 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
151
151
  instrumentationVersion: "1.0.0",
152
152
  perf
153
153
  });
154
- this._listeners = listeners;
154
+ this._listeners = listeners ?? {};
155
155
  this._urlDocument = urlDocument ?? window.document;
156
156
  this._urlAttribution = urlAttribution;
157
157
  this._includeRawAttribution = includeRawAttribution;
158
158
  this._softNavsActive = reportSoftNavs && require_utils_performanceObserver_performanceObserver.isEntryTypeSupported("soft-navigation");
159
159
  this._pageManager = pageManager ?? require_api_page_pageAPI.page.getPageManager();
160
160
  this._applyCustomLogRecordData = applyCustomLogRecordData;
161
- if (this._config.enabled !== false) this.enable();
162
- }
163
- enable() {
164
- if (typeof PerformanceObserver !== "undefined") super.enable();
165
- else this._diag.debug("PerformanceObserver not supported, web vitals will not be collected");
161
+ this._listenersProvided = listeners !== void 0;
166
162
  }
163
+ _listenersProvided;
167
164
  onDisable() {
168
165
  this._diag.debug("WebVitalsInstrumentation disabled, pausing emission");
169
166
  }
@@ -173,6 +170,17 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
173
170
  return;
174
171
  }
175
172
  this._listenersRegistered = true;
173
+ if (this._listenersProvided) {
174
+ this._registerListeners();
175
+ return;
176
+ }
177
+ require_instrumentations_web_vitals_WebVitalsInstrumentation_constants.loadWebVitalListeners().then((listeners) => {
178
+ if (!this._isEnabled) return;
179
+ this._listeners = listeners;
180
+ this._registerListeners();
181
+ });
182
+ }
183
+ _registerListeners() {
176
184
  require_instrumentations_web_vitals_WebVitalsInstrumentation_constants.ALL_WEB_VITALS.forEach((name) => {
177
185
  const reportSoftNavs = name !== "TTFB" && this._softNavsActive;
178
186
  if (this._urlAttribution) this._listeners[name]?.((metric) => {
@@ -208,15 +216,15 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
208
216
  };
209
217
  }
210
218
  _getTimeForMetric(metric) {
211
- if (metric.name === "INP" && metric.attribution.interactionTime !== void 0) return this.perf.epochMillisFromOriginOffset(metric.attribution.interactionTime);
219
+ if (metric.name === "INP" && metric.attribution.interactionTime !== void 0) return this.perf.offsetToAbsoluteTime(metric.attribution.interactionTime);
212
220
  if (metric.name === "CLS") {
213
221
  const windowStart = metric.entries.length > 0 ? Math.min(...metric.entries.map((entry) => entry.startTime)) : metric.attribution.largestShiftTime;
214
- if (windowStart !== void 0) return this.perf.epochMillisFromOriginOffset(windowStart);
222
+ if (windowStart !== void 0) return this.perf.offsetToAbsoluteTime(windowStart);
215
223
  }
216
224
  if (metric.name === "TTFB") return this.perf.getZeroTime();
217
225
  const metricStartTime = metric.entries[metric.entries.length - 1]?.startTime;
218
- if (metricStartTime !== void 0) return this.perf.epochMillisFromOriginOffset(metricStartTime);
219
- return this.perf.getNowMillis();
226
+ if (metricStartTime !== void 0) return this.perf.offsetToAbsoluteTime(metricStartTime);
227
+ return this.perf.getNow();
220
228
  }
221
229
  _emitWebVital(metric) {
222
230
  const attributedPage = this._attributedPage[metric.name];
@@ -232,7 +240,7 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
232
240
  [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,
233
241
  [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_ID]: metric.id,
234
242
  [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,
235
- ...metric.navigationId !== void 0 ? { [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId } : {},
243
+ [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId,
236
244
  ...metric.navigationInteractionId !== void 0 ? { [require_instrumentations_web_vitals_WebVitalsInstrumentation_attributes.KEY_BROWSER_WEB_VITAL_INTERACTION_ID]: metric.navigationInteractionId } : {},
237
245
  ...sessionPartId !== null ? { [require_constants_attributes.KEY_MXL_SESSION_PART_ID]: sessionPartId } : {},
238
246
  ...notRestoredReasons?.length ? { [require_constants_attributes.KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]: notRestoredReasons } : {},
@@ -248,9 +256,9 @@ var WebVitalsInstrumentation = class extends require_instrumentations_MXLInstrum
248
256
  ...metric.name === "CLS" ? clsLayoutShiftsAttribution(metric, this._diag) : {},
249
257
  ...metric.name === "LCP" ? lcpElementAttribution(metric, this._diag) : {}
250
258
  },
251
- body: this._includeRawAttribution && metric.attribution != null ? JSON.stringify(Object.fromEntries(Object.entries(metric.attribution).filter(([, v]) => isPrimitiveValue(v)))) : void 0,
259
+ body: this._includeRawAttribution ? JSON.stringify(Object.fromEntries(Object.entries(metric.attribution).filter(([, v]) => isPrimitiveValue(v)))) : void 0,
252
260
  eventName: require_instrumentations_web_vitals_WebVitalsInstrumentation_constants.WEB_VITAL_EVENT_NAME,
253
- severityNumber: _opentelemetry_api_logs.SeverityNumber.INFO,
261
+ severityNumber: _opentelemetry_api.SeverityNumber.INFO,
254
262
  timestamp: (0, _opentelemetry_core.millisToHrTime)(metricTimeMillis)
255
263
  };
256
264
  if (this._applyCustomLogRecordData) (0, _opentelemetry_instrumentation.safeExecuteInTheMiddle)(() => this._applyCustomLogRecordData?.(logRecord), (error) => {
@@ -1 +1 @@
1
- {"version":3,"file":"WebVitalsInstrumentation.cjs","names":["MAX_LOAF_SCRIPT_URL_LENGTH","KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX","getSelector","MXLInstrumentationBase","WEB_VITALS_ID_TO_LISTENER","isEntryTypeSupported","page","getBfcacheNotRestoredReasons","KEY_MXL_TYPE","KEY_BROWSER_WEB_VITAL_NAME","KEY_BROWSER_WEB_VITAL_VALUE","KEY_BROWSER_WEB_VITAL_DELTA","KEY_BROWSER_WEB_VITAL_RATING","KEY_BROWSER_WEB_VITAL_ID","KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE","KEY_BROWSER_WEB_VITAL_NAVIGATION_ID","KEY_BROWSER_WEB_VITAL_INTERACTION_ID","KEY_MXL_SESSION_PART_ID","KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS","KEY_BROWSER_URL_FULL","KEY_MXL_PAGE_PATH","KEY_MXL_PAGE_ID","KEY_APP_SURFACE_LABEL","WEB_VITAL_EVENT_NAME","SeverityNumber"],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"sourcesContent":["import type { Attributes, DiagLogger } from '@opentelemetry/api';\nimport type { LogRecord } from '@opentelemetry/api-logs';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport { millisToHrTime } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type {\n CLSMetricWithAttribution,\n INPAttribution,\n LCPAttribution,\n Metric,\n MetricWithAttribution,\n TTFBAttribution,\n} from 'web-vitals/attribution';\nimport type { PageManager } from '../../../api-page/manager/types';\nimport { page } from '../../../api-page/pageAPI';\nimport type { URLDocument } from '../../../common/types';\nimport {\n KEY_APP_SURFACE_LABEL,\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_BROWSER_URL_FULL,\n KEY_MXL_PAGE_ID,\n KEY_MXL_PAGE_PATH,\n KEY_MXL_SESSION_PART_ID,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { getBfcacheNotRestoredReasons } from '../../../utils/getBfcacheNotRestoredReasons';\nimport { getSelector } from '../../../utils/getSelector';\nimport { isEntryTypeSupported } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport {\n KEY_BROWSER_WEB_VITAL_DELTA,\n KEY_BROWSER_WEB_VITAL_ID,\n KEY_BROWSER_WEB_VITAL_INTERACTION_ID,\n KEY_BROWSER_WEB_VITAL_NAME,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_ID,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE,\n KEY_BROWSER_WEB_VITAL_RATING,\n KEY_BROWSER_WEB_VITAL_VALUE,\n KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX,\n} from './attributes';\nimport {\n ALL_WEB_VITALS,\n MAX_CLS_LAYOUT_SHIFTS,\n MAX_LOAF_SCRIPT_ENTRIES,\n MAX_LOAF_SCRIPT_URL_LENGTH,\n WEB_VITAL_EVENT_NAME,\n WEB_VITALS_ID_TO_LISTENER,\n} from './constants';\nimport type { WebVitalListeners, WebVitalsInstrumentationArgs } from './types';\n\ntype AttributedPage = {\n fullURL: string;\n path?: string;\n pageID?: string;\n label?: string;\n};\n\nconst roundClamp = (value: number): number => Math.round(Math.max(0, value));\n\nconst roundRect = (rect?: DOMRectReadOnly) => ({\n x: Math.round(rect?.x ?? 0),\n y: Math.round(rect?.y ?? 0),\n width: Math.round(rect?.width ?? 0),\n height: Math.round(rect?.height ?? 0),\n});\n\nconst isPrimitiveValue = (\n value: unknown,\n): value is string | number | boolean => {\n const type = typeof value;\n return type === 'number' || type === 'string' || type === 'boolean';\n};\n\nconst loafScriptsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as INPAttribution;\n\n try {\n // Suppress LoAF baseline errors\n /* eslint-disable baseline-js/use-baseline */\n if (attribution.longAnimationFrameEntries.length > 0) {\n const scripts = new Map<\n string,\n {\n totalDuration: number;\n styleAndLayoutDuration: number;\n count: number;\n }\n >();\n for (const entry of attribution.longAnimationFrameEntries) {\n for (const script of entry.scripts) {\n let url = script.sourceURL || '(inline)';\n if (url.length > MAX_LOAF_SCRIPT_URL_LENGTH) {\n url = `${url.substring(0, MAX_LOAF_SCRIPT_URL_LENGTH)}...`;\n }\n const existing = scripts.get(url);\n if (existing) {\n existing.totalDuration += script.duration;\n existing.styleAndLayoutDuration +=\n script.forcedStyleAndLayoutDuration;\n existing.count++;\n } else {\n scripts.set(url, {\n count: 1,\n styleAndLayoutDuration: script.forcedStyleAndLayoutDuration,\n totalDuration: script.duration,\n });\n }\n }\n }\n if (scripts.size > 0) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}loaf_scripts`] =\n JSON.stringify(\n Object.fromEntries(\n [...scripts]\n .sort((a, b) => b[1].totalDuration - a[1].totalDuration)\n .slice(0, MAX_LOAF_SCRIPT_ENTRIES)\n .map(([url, script]) => [\n url,\n {\n count: script.count,\n style_and_layout_duration: Math.round(\n script.styleAndLayoutDuration,\n ),\n total_duration: Math.round(script.totalDuration),\n },\n ]),\n ),\n );\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building loaf scripts for INP', error);\n }\n\n return attributes;\n};\n\nconst clsLayoutShiftsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const entries = metric.entries as LayoutShift[];\n\n if (entries.length > 0) {\n const shifts = entries.slice(0, MAX_CLS_LAYOUT_SHIFTS).map((entry) => {\n // web-vitals exposes sources sorted by impact area descending, so the\n // first source is the element that contributed most to the shift.\n const source = entry.sources[0];\n return {\n selector: getSelector(source?.node ?? null),\n startRect: roundRect(source?.previousRect),\n endRect: roundRect(source?.currentRect),\n };\n });\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}clsLayoutShifts`] = JSON.stringify(shifts);\n\n if (entries.length > MAX_CLS_LAYOUT_SHIFTS) {\n attributes[`${prefix}clsLayoutShiftsDroppedCount`] =\n entries.length - MAX_CLS_LAYOUT_SHIFTS;\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building CLS layout shifts', error);\n }\n\n return attributes;\n};\n\nconst inpAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const target = (metric.entries as PerformanceEventTiming[]).find(\n (entry) => entry.target,\n )?.target as Element | null | undefined;\n\n const tagName = target?.tagName?.toLowerCase();\n\n if (tagName) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}element_type`] =\n tagName;\n }\n\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building INP element type attribution', error);\n }\n\n return attributes;\n};\n\nconst ttfbSubPartsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as TTFBAttribution;\n const entry = attribution.navigationEntry as\n | PerformanceNavigationTiming\n | undefined;\n\n if (entry) {\n try {\n const redirect = roundClamp(entry.redirectEnd - entry.redirectStart);\n const domainLookup = roundClamp(\n entry.domainLookupEnd - entry.domainLookupStart,\n );\n const tcpConnection = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.secureConnectionStart - entry.connectStart\n : entry.connectEnd - entry.connectStart,\n );\n const tlsNegotiation = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.connectEnd - entry.secureConnectionStart\n : 0,\n );\n const effectiveResponseStart = Math.max(\n // @ts-expect-error 103 Early hints are not supported in all browsers\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/finalResponseHeadersStart\n entry.finalResponseHeadersStart ?? 0,\n entry.responseStart,\n );\n const serverResponse = roundClamp(\n effectiveResponseStart - entry.requestStart,\n );\n const total = Math.round(entry.responseEnd - entry.startTime);\n const unattributed = roundClamp(\n total -\n redirect -\n domainLookup -\n tcpConnection -\n tlsNegotiation -\n serverResponse,\n );\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}redirect`] = redirect;\n attributes[`${prefix}domainLookup`] = domainLookup;\n attributes[`${prefix}tcpConnection`] = tcpConnection;\n attributes[`${prefix}tlsNegotiation`] = tlsNegotiation;\n attributes[`${prefix}serverResponse`] = serverResponse;\n attributes[`${prefix}unattributed`] = unattributed;\n } catch (error) {\n diag.error('error computing TTFB timing breakdown', error);\n }\n } else {\n diag.debug('TTFB navigationEntry unavailable, skipping timing breakdown');\n }\n\n return attributes;\n};\n\nconst lcpElementAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n const attribution = metric.attribution as LCPAttribution;\n const element = attribution.lcpEntry?.element;\n\n if (element) {\n const elementType = element.tagName.toLowerCase();\n const elementBoundingRect = JSON.stringify(\n roundRect(element.getBoundingClientRect()),\n );\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}elementType`] = elementType;\n attributes[`${prefix}elementBoundingRect`] = elementBoundingRect;\n }\n } catch (error) {\n diag.error('error building LCP element attribution', error);\n }\n\n return attributes;\n};\n\nexport class WebVitalsInstrumentation extends MXLInstrumentationBase {\n private readonly _listeners: WebVitalListeners;\n private readonly _urlDocument: URLDocument;\n private readonly _urlAttribution: boolean;\n private readonly _includeRawAttribution: boolean;\n private readonly _softNavsActive: boolean;\n private readonly _pageManager: PageManager;\n private readonly _attributedPage: Record<\n Metric['name'],\n AttributedPage | undefined\n > = {\n CLS: undefined,\n FCP: undefined,\n INP: undefined,\n LCP: undefined,\n TTFB: undefined,\n };\n private _largestShiftTargetForCLS: string | undefined | null = null;\n private _clsMetricId: string | undefined = undefined;\n private _applyCustomLogRecordData?: (logRecord: LogRecord) => void;\n private _listenersRegistered = false;\n\n public constructor({\n diag,\n perf,\n listeners = WEB_VITALS_ID_TO_LISTENER,\n urlDocument,\n urlAttribution = true,\n includeRawAttribution = true,\n reportSoftNavs = true,\n pageManager,\n applyCustomLogRecordData,\n ...config\n }: WebVitalsInstrumentationArgs = {}) {\n super({\n config,\n diag,\n instrumentationName: 'WebVitalsInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n this._listeners = listeners;\n this._urlDocument = urlDocument ?? window.document;\n this._urlAttribution = urlAttribution;\n this._includeRawAttribution = includeRawAttribution;\n this._softNavsActive =\n reportSoftNavs && isEntryTypeSupported('soft-navigation');\n this._pageManager = pageManager ?? page.getPageManager();\n this._applyCustomLogRecordData = applyCustomLogRecordData;\n\n if (this._config.enabled !== false) {\n this.enable();\n }\n }\n\n public override enable(): void {\n if (typeof PerformanceObserver !== 'undefined') {\n super.enable();\n } else {\n this._diag.debug(\n 'PerformanceObserver not supported, web vitals will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n // web-vitals library doesn't support removing listeners, so we pause emission\n // https://github.com/GoogleChrome/web-vitals/issues/357#issuecomment-1593439036\n this._diag.debug('WebVitalsInstrumentation disabled, pausing emission');\n }\n\n protected override onEnable(): void {\n // web-vitals library doesn't support removing listeners, so only register once\n if (this._listenersRegistered) {\n this._diag.debug(\n 'WebVitalsInstrumentation listeners already registered, resuming emission',\n );\n return;\n }\n this._listenersRegistered = true;\n\n ALL_WEB_VITALS.forEach((name) => {\n // web-vitals reports a hardcoded dummy value of zero for TTFB on soft navigations. That\n // is not a real measurement and would skew the data, so TTFB listeners keep soft\n // navigation reporting off.\n const reportSoftNavs = name !== 'TTFB' && this._softNavsActive;\n\n if (this._urlAttribution) {\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n if (metric.name === 'CLS') {\n const clsMetric = metric as CLSMetricWithAttribution;\n const target = clsMetric.attribution.largestShiftTarget;\n\n if (this._clsMetricId !== clsMetric.id) {\n // A new metric ID means CLS has reset for a soft navigation.\n this._clsMetricId = clsMetric.id;\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n } else if (this._largestShiftTargetForCLS !== target) {\n // When the largest shift target changes, make sure the attributed page is updated\n // to reflect the page where that shift occurred.\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n }\n } else {\n this._attributedPage[metric.name] = this._currentAttributedPage();\n }\n },\n { reportAllChanges: true, reportSoftNavs },\n );\n }\n\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n this._emitWebVital(metric);\n },\n { reportSoftNavs },\n );\n });\n }\n\n private _currentAttributedPage(): AttributedPage {\n return {\n fullURL: this._urlDocument.URL,\n label: this._pageManager.getPageLabel() ?? undefined,\n pageID: this._pageManager.getCurrentPageId() ?? undefined,\n path: this._pageManager.getCurrentRoute()?.path,\n };\n }\n\n private _getTimeForMetric(metric: MetricWithAttribution): number {\n // For INP use interactionTime, which is the start time of the user's interaction\n if (\n metric.name === 'INP' &&\n metric.attribution.interactionTime !== undefined\n ) {\n return this.perf.epochMillisFromOriginOffset(\n metric.attribution.interactionTime,\n );\n }\n\n // For CLS use the first layout shift's startTime, which is the beginning of\n // the session window. Fall back to largestShiftTime if the entries aren't\n // available for some reason.\n if (metric.name === 'CLS') {\n const windowStart =\n metric.entries.length > 0\n ? Math.min(...metric.entries.map((entry) => entry.startTime))\n : metric.attribution.largestShiftTime;\n\n if (windowStart !== undefined) {\n return this.perf.epochMillisFromOriginOffset(windowStart);\n }\n }\n\n // For TTFB use the \"zero\" time of the current session part\n if (metric.name === 'TTFB') {\n return this.perf.getZeroTime();\n }\n\n // For other metrics, use the startTime of the last entry. In practice, web-vitals does\n // not emit multiple entries for metrics other than CLS. However to future-proof this code,\n // we are assuming that the last entry is the most relevant one.\n const metricStartTime =\n metric.entries[metric.entries.length - 1]?.startTime;\n\n if (metricStartTime !== undefined) {\n return this.perf.epochMillisFromOriginOffset(metricStartTime);\n }\n\n // Fall back to when the metric was reported\n return this.perf.getNowMillis();\n }\n\n private _emitWebVital(metric: MetricWithAttribution): void {\n const attributedPage = this._attributedPage[metric.name];\n // Resolve by the metric's own event time rather than reading the\n // currently active part: web-vitals can defer a metric's report well\n // past when its underlying entry occurred (e.g. INP/CLS finalize on\n // visibilitychange), by which point the part active at report time may\n // not be the one the entry happened in.\n const metricTimeMillis = this._getTimeForMetric(metric);\n const sessionPartId =\n this.userSessionManager.getSessionPartIdAt(metricTimeMillis);\n const notRestoredReasons = getBfcacheNotRestoredReasons();\n const logRecord: LogRecord = {\n attributes: {\n [KEY_MXL_TYPE]: MXL_TYPES.WebVital,\n [KEY_BROWSER_WEB_VITAL_NAME]: metric.name.toLowerCase(),\n [KEY_BROWSER_WEB_VITAL_VALUE]: metric.value,\n [KEY_BROWSER_WEB_VITAL_DELTA]: metric.delta,\n [KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,\n [KEY_BROWSER_WEB_VITAL_ID]: metric.id,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,\n ...(metric.navigationId !== undefined\n ? { [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId }\n : {}),\n ...(metric.navigationInteractionId !== undefined\n ? {\n [KEY_BROWSER_WEB_VITAL_INTERACTION_ID]:\n metric.navigationInteractionId,\n }\n : {}),\n ...(sessionPartId !== null\n ? { [KEY_MXL_SESSION_PART_ID]: sessionPartId }\n : {}),\n ...(notRestoredReasons?.length\n ? {\n [KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]:\n notRestoredReasons,\n }\n : {}),\n ...(attributedPage\n ? {\n // The navigationURL emitted by web-vitals is authoritative for which URL the metric\n // belongs to, since it was captured when the metric occurred. When soft navigations\n // are not supported, we fall back to the attributed page.\n [KEY_BROWSER_URL_FULL]:\n metric.navigationURL != null &&\n (metric.navigationType === 'soft-navigation' ||\n this._softNavsActive)\n ? metric.navigationURL\n : attributedPage.fullURL,\n [KEY_MXL_PAGE_PATH]: attributedPage.path,\n [KEY_MXL_PAGE_ID]: attributedPage.pageID,\n [KEY_APP_SURFACE_LABEL]: attributedPage.label,\n }\n : {}),\n ...(metric.name === 'INP'\n ? loafScriptsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'INP' ? inpAttribution(metric, this._diag) : {}),\n ...(metric.name === 'TTFB'\n ? ttfbSubPartsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'CLS'\n ? clsLayoutShiftsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'LCP'\n ? lcpElementAttribution(metric, this._diag)\n : {}),\n },\n body:\n this._includeRawAttribution && metric.attribution != null\n ? JSON.stringify(\n Object.fromEntries(\n Object.entries(metric.attribution).filter(([, v]) =>\n isPrimitiveValue(v),\n ),\n ),\n )\n : undefined,\n eventName: WEB_VITAL_EVENT_NAME,\n severityNumber: SeverityNumber.INFO,\n timestamp: millisToHrTime(metricTimeMillis),\n };\n\n if (this._applyCustomLogRecordData) {\n safeExecuteInTheMiddle(\n () => this._applyCustomLogRecordData?.(logRecord),\n (error) => {\n if (error) {\n this._diag.error('applyCustomLogRecordData hook failed', error);\n }\n },\n true,\n );\n }\n\n this.logger.emit(logRecord);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA0DA,MAAM,cAAc,UAA0B,KAAK,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;AAE5E,MAAM,aAAa,UAA4B;CAC7C,GAAG,KAAK,MAAM,MAAM,KAAK,EAAE;CAC3B,GAAG,KAAK,MAAM,MAAM,KAAK,EAAE;CAC3B,OAAO,KAAK,MAAM,MAAM,SAAS,EAAE;CACnC,QAAQ,KAAK,MAAM,MAAM,UAAU,EAAE;CACtC;AAED,MAAM,oBACJ,UACuC;CACvC,MAAM,OAAO,OAAO;AACpB,QAAO,SAAS,YAAY,SAAS,YAAY,SAAS;;AAG5D,MAAM,0BACJ,QACA,SACe;CACf,MAAM,aAAyB,EAAE;CACjC,MAAM,cAAc,OAAO;AAE3B,KAAI;AAGF,MAAI,YAAY,0BAA0B,SAAS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ACjCC,6BAAAA,wBAAwB,eAAe;KACzC,GACD,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,uBAAuB,QAAQ,KAAK,MAAM,GAC1C,EAAE;IACN,GAAI,OAAO,SAAS,QAAQ,eAAe,QAAQ,KAAK,MAAM,GAAG,EAAE;IACnE,GAAI,OAAO,SAAS,SAChB,wBAAwB,QAAQ,KAAK,MAAM,GAC3C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,2BAA2B,QAAQ,KAAK,MAAM,GAC9C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,sBAAsB,QAAQ,KAAK,MAAM,GACzC,EAAE;IACP;GACD,MACE,KAAK,0BAA0B,OAAO,eAAe,OACjD,KAAK,UACH,OAAO,YACL,OAAO,QAAQ,OAAO,YAAY,CAAC,QAAQ,GAAG,OAC5C,iBAAiB,EAAE,CACpB,CACF,CACF,GACD,KAAA;GACN,WAAWC,uEAAAA;GACX,gBAAgBC,wBAAAA,eAAe;GAC/B,YAAA,GAAA,oBAAA,gBAA0B,iBAAiB;GAC5C;AAED,MAAI,KAAK,0BACP,EAAA,GAAA,+BAAA,8BACQ,KAAK,4BAA4B,UAAU,GAChD,UAAU;AACT,OAAI,MACF,MAAK,MAAM,MAAM,wCAAwC,MAAM;KAGnE,KACD;AAGH,OAAK,OAAO,KAAK,UAAU"}
1
+ {"version":3,"file":"WebVitalsInstrumentation.cjs","names":["MAX_LOAF_SCRIPT_URL_LENGTH","KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX","getSelector","MXLInstrumentationBase","isEntryTypeSupported","page","loadWebVitalListeners","getBfcacheNotRestoredReasons","KEY_MXL_TYPE","KEY_BROWSER_WEB_VITAL_NAME","KEY_BROWSER_WEB_VITAL_VALUE","KEY_BROWSER_WEB_VITAL_DELTA","KEY_BROWSER_WEB_VITAL_RATING","KEY_BROWSER_WEB_VITAL_ID","KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE","KEY_BROWSER_WEB_VITAL_NAVIGATION_ID","KEY_BROWSER_WEB_VITAL_INTERACTION_ID","KEY_MXL_SESSION_PART_ID","KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS","KEY_BROWSER_URL_FULL","KEY_MXL_PAGE_PATH","KEY_MXL_PAGE_ID","KEY_APP_SURFACE_LABEL","WEB_VITAL_EVENT_NAME","SeverityNumber"],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"sourcesContent":["import type { Attributes, DiagLogger } from '@opentelemetry/api';\nimport type { LogRecord } from '@opentelemetry/api';\nimport { SeverityNumber } from '@opentelemetry/api';\nimport { millisToHrTime } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type {\n CLSMetricWithAttribution,\n INPAttribution,\n LCPAttribution,\n Metric,\n MetricWithAttribution,\n TTFBAttribution,\n} from 'web-vitals/attribution';\nimport type { PageManager } from '../../../api-page/manager/types';\nimport { page } from '../../../api-page/pageAPI';\nimport type { URLDocument } from '../../../common/types';\nimport {\n KEY_APP_SURFACE_LABEL,\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_BROWSER_URL_FULL,\n KEY_MXL_PAGE_ID,\n KEY_MXL_PAGE_PATH,\n KEY_MXL_SESSION_PART_ID,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { getBfcacheNotRestoredReasons } from '../../../utils/getBfcacheNotRestoredReasons';\nimport { getSelector } from '../../../utils/getSelector';\nimport { isEntryTypeSupported } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport {\n KEY_BROWSER_WEB_VITAL_DELTA,\n KEY_BROWSER_WEB_VITAL_ID,\n KEY_BROWSER_WEB_VITAL_INTERACTION_ID,\n KEY_BROWSER_WEB_VITAL_NAME,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_ID,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE,\n KEY_BROWSER_WEB_VITAL_RATING,\n KEY_BROWSER_WEB_VITAL_VALUE,\n KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX,\n} from './attributes';\nimport {\n ALL_WEB_VITALS,\n MAX_CLS_LAYOUT_SHIFTS,\n MAX_LOAF_SCRIPT_ENTRIES,\n MAX_LOAF_SCRIPT_URL_LENGTH,\n WEB_VITAL_EVENT_NAME,\n loadWebVitalListeners,\n} from './constants';\nimport type { WebVitalListeners, WebVitalsInstrumentationArgs } from './types';\n\ntype AttributedPage = {\n fullURL: string;\n path?: string;\n pageID?: string;\n label?: string;\n};\n\nconst roundClamp = (value: number): number => Math.round(Math.max(0, value));\n\nconst roundRect = (rect?: DOMRectReadOnly) => ({\n x: Math.round(rect?.x ?? 0),\n y: Math.round(rect?.y ?? 0),\n width: Math.round(rect?.width ?? 0),\n height: Math.round(rect?.height ?? 0),\n});\n\nconst isPrimitiveValue = (\n value: unknown,\n): value is string | number | boolean => {\n const type = typeof value;\n return type === 'number' || type === 'string' || type === 'boolean';\n};\n\nconst loafScriptsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as INPAttribution;\n\n try {\n // Suppress LoAF baseline errors\n /* eslint-disable baseline-js/use-baseline */\n if (attribution.longAnimationFrameEntries.length > 0) {\n const scripts = new Map<\n string,\n {\n totalDuration: number;\n styleAndLayoutDuration: number;\n count: number;\n }\n >();\n for (const entry of attribution.longAnimationFrameEntries) {\n for (const script of entry.scripts) {\n let url = script.sourceURL || '(inline)';\n if (url.length > MAX_LOAF_SCRIPT_URL_LENGTH) {\n url = `${url.substring(0, MAX_LOAF_SCRIPT_URL_LENGTH)}...`;\n }\n const existing = scripts.get(url);\n if (existing) {\n existing.totalDuration += script.duration;\n existing.styleAndLayoutDuration +=\n script.forcedStyleAndLayoutDuration;\n existing.count++;\n } else {\n scripts.set(url, {\n count: 1,\n styleAndLayoutDuration: script.forcedStyleAndLayoutDuration,\n totalDuration: script.duration,\n });\n }\n }\n }\n if (scripts.size > 0) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}loaf_scripts`] =\n JSON.stringify(\n Object.fromEntries(\n [...scripts]\n .sort((a, b) => b[1].totalDuration - a[1].totalDuration)\n .slice(0, MAX_LOAF_SCRIPT_ENTRIES)\n .map(([url, script]) => [\n url,\n {\n count: script.count,\n style_and_layout_duration: Math.round(\n script.styleAndLayoutDuration,\n ),\n total_duration: Math.round(script.totalDuration),\n },\n ]),\n ),\n );\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building loaf scripts for INP', error);\n }\n\n return attributes;\n};\n\nconst clsLayoutShiftsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const entries = metric.entries as LayoutShift[];\n\n if (entries.length > 0) {\n const shifts = entries.slice(0, MAX_CLS_LAYOUT_SHIFTS).map((entry) => {\n // web-vitals exposes sources sorted by impact area descending, so the\n // first source is the element that contributed most to the shift.\n const source = entry.sources[0];\n return {\n selector: getSelector(source?.node ?? null),\n startRect: roundRect(source?.previousRect),\n endRect: roundRect(source?.currentRect),\n };\n });\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}clsLayoutShifts`] = JSON.stringify(shifts);\n\n if (entries.length > MAX_CLS_LAYOUT_SHIFTS) {\n attributes[`${prefix}clsLayoutShiftsDroppedCount`] =\n entries.length - MAX_CLS_LAYOUT_SHIFTS;\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building CLS layout shifts', error);\n }\n\n return attributes;\n};\n\nconst inpAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const target = (metric.entries as PerformanceEventTiming[]).find(\n (entry) => entry.target,\n )?.target as Element | null | undefined;\n\n const tagName = target?.tagName?.toLowerCase();\n\n if (tagName) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}element_type`] =\n tagName;\n }\n\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building INP element type attribution', error);\n }\n\n return attributes;\n};\n\nconst ttfbSubPartsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as TTFBAttribution;\n const entry = attribution.navigationEntry as\n | PerformanceNavigationTiming\n | undefined;\n\n if (entry) {\n try {\n const redirect = roundClamp(entry.redirectEnd - entry.redirectStart);\n const domainLookup = roundClamp(\n entry.domainLookupEnd - entry.domainLookupStart,\n );\n const tcpConnection = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.secureConnectionStart - entry.connectStart\n : entry.connectEnd - entry.connectStart,\n );\n const tlsNegotiation = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.connectEnd - entry.secureConnectionStart\n : 0,\n );\n const effectiveResponseStart = Math.max(\n // @ts-expect-error 103 Early hints are not supported in all browsers\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/finalResponseHeadersStart\n entry.finalResponseHeadersStart ?? 0,\n entry.responseStart,\n );\n const serverResponse = roundClamp(\n effectiveResponseStart - entry.requestStart,\n );\n const total = Math.round(entry.responseEnd - entry.startTime);\n const unattributed = roundClamp(\n total -\n redirect -\n domainLookup -\n tcpConnection -\n tlsNegotiation -\n serverResponse,\n );\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}redirect`] = redirect;\n attributes[`${prefix}domainLookup`] = domainLookup;\n attributes[`${prefix}tcpConnection`] = tcpConnection;\n attributes[`${prefix}tlsNegotiation`] = tlsNegotiation;\n attributes[`${prefix}serverResponse`] = serverResponse;\n attributes[`${prefix}unattributed`] = unattributed;\n } catch (error) {\n diag.error('error computing TTFB timing breakdown', error);\n }\n } else {\n diag.debug('TTFB navigationEntry unavailable, skipping timing breakdown');\n }\n\n return attributes;\n};\n\nconst lcpElementAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n const attribution = metric.attribution as LCPAttribution;\n const element = attribution.lcpEntry?.element;\n\n if (element) {\n const elementType = element.tagName.toLowerCase();\n const elementBoundingRect = JSON.stringify(\n roundRect(element.getBoundingClientRect()),\n );\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}elementType`] = elementType;\n attributes[`${prefix}elementBoundingRect`] = elementBoundingRect;\n }\n } catch (error) {\n diag.error('error building LCP element attribution', error);\n }\n\n return attributes;\n};\n\nexport class WebVitalsInstrumentation extends MXLInstrumentationBase {\n private _listeners: WebVitalListeners;\n private readonly _urlDocument: URLDocument;\n private readonly _urlAttribution: boolean;\n private readonly _includeRawAttribution: boolean;\n private readonly _softNavsActive: boolean;\n private readonly _pageManager: PageManager;\n private readonly _attributedPage: Record<\n Metric['name'],\n AttributedPage | undefined\n > = {\n CLS: undefined,\n FCP: undefined,\n INP: undefined,\n LCP: undefined,\n TTFB: undefined,\n };\n private _largestShiftTargetForCLS: string | undefined | null = null;\n private _clsMetricId: string | undefined = undefined;\n private _applyCustomLogRecordData?: (logRecord: LogRecord) => void;\n private _listenersRegistered = false;\n\n public constructor({\n diag,\n perf,\n listeners,\n urlDocument,\n urlAttribution = true,\n includeRawAttribution = true,\n reportSoftNavs = true,\n pageManager,\n applyCustomLogRecordData,\n ...config\n }: WebVitalsInstrumentationArgs = {}) {\n super({\n config,\n diag,\n instrumentationName: 'WebVitalsInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n this._listeners = listeners ?? ({} as WebVitalListeners);\n this._urlDocument = urlDocument ?? window.document;\n this._urlAttribution = urlAttribution;\n this._includeRawAttribution = includeRawAttribution;\n this._softNavsActive =\n reportSoftNavs && isEntryTypeSupported('soft-navigation');\n this._pageManager = pageManager ?? page.getPageManager();\n this._applyCustomLogRecordData = applyCustomLogRecordData;\n this._listenersProvided = listeners !== undefined;\n }\n\n private readonly _listenersProvided: boolean;\n\n protected override onDisable(): void {\n // web-vitals library doesn't support removing listeners, so we pause emission\n // https://github.com/GoogleChrome/web-vitals/issues/357#issuecomment-1593439036\n this._diag.debug('WebVitalsInstrumentation disabled, pausing emission');\n }\n\n protected override onEnable(): void {\n // web-vitals library doesn't support removing listeners, so only register once\n if (this._listenersRegistered) {\n this._diag.debug(\n 'WebVitalsInstrumentation listeners already registered, resuming emission',\n );\n return;\n }\n this._listenersRegistered = true;\n\n if (this._listenersProvided) {\n this._registerListeners();\n return;\n }\n\n void loadWebVitalListeners().then((listeners) => {\n if (!this._isEnabled) {\n return;\n }\n this._listeners = listeners;\n this._registerListeners();\n });\n }\n\n private _registerListeners(): void {\n ALL_WEB_VITALS.forEach((name) => {\n // web-vitals reports a hardcoded dummy value of zero for TTFB on soft navigations. That\n // is not a real measurement and would skew the data, so TTFB listeners keep soft\n // navigation reporting off.\n const reportSoftNavs = name !== 'TTFB' && this._softNavsActive;\n\n if (this._urlAttribution) {\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n if (metric.name === 'CLS') {\n const clsMetric = metric as CLSMetricWithAttribution;\n const target = clsMetric.attribution.largestShiftTarget;\n\n if (this._clsMetricId !== clsMetric.id) {\n // A new metric ID means CLS has reset for a soft navigation.\n this._clsMetricId = clsMetric.id;\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n } else if (this._largestShiftTargetForCLS !== target) {\n // When the largest shift target changes, make sure the attributed page is updated\n // to reflect the page where that shift occurred.\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n }\n } else {\n this._attributedPage[metric.name] = this._currentAttributedPage();\n }\n },\n { reportAllChanges: true, reportSoftNavs },\n );\n }\n\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n this._emitWebVital(metric);\n },\n { reportSoftNavs },\n );\n });\n }\n\n private _currentAttributedPage(): AttributedPage {\n return {\n fullURL: this._urlDocument.URL,\n label: this._pageManager.getPageLabel() ?? undefined,\n pageID: this._pageManager.getCurrentPageId() ?? undefined,\n path: this._pageManager.getCurrentRoute()?.path,\n };\n }\n\n private _getTimeForMetric(metric: MetricWithAttribution): number {\n // For INP use interactionTime, which is the start time of the user's interaction\n if (\n metric.name === 'INP' &&\n metric.attribution.interactionTime !== undefined\n ) {\n return this.perf.offsetToAbsoluteTime(metric.attribution.interactionTime);\n }\n\n // For CLS use the first layout shift's startTime, which is the beginning of\n // the session window. Fall back to largestShiftTime if the entries aren't\n // available for some reason.\n if (metric.name === 'CLS') {\n const windowStart =\n metric.entries.length > 0\n ? Math.min(...metric.entries.map((entry) => entry.startTime))\n : metric.attribution.largestShiftTime;\n\n if (windowStart !== undefined) {\n return this.perf.offsetToAbsoluteTime(windowStart);\n }\n }\n\n // For TTFB use the \"zero\" time of the current session part\n if (metric.name === 'TTFB') {\n return this.perf.getZeroTime();\n }\n\n // For other metrics, use the startTime of the last entry. In practice, web-vitals does\n // not emit multiple entries for metrics other than CLS. However to future-proof this code,\n // we are assuming that the last entry is the most relevant one.\n const metricStartTime =\n metric.entries[metric.entries.length - 1]?.startTime;\n\n if (metricStartTime !== undefined) {\n return this.perf.offsetToAbsoluteTime(metricStartTime);\n }\n\n // Fall back to when the metric was reported\n return this.perf.getNow();\n }\n\n private _emitWebVital(metric: MetricWithAttribution): void {\n const attributedPage = this._attributedPage[metric.name];\n // Resolve by the metric's own event time rather than reading the\n // currently active part: web-vitals can defer a metric's report well\n // past when its underlying entry occurred (e.g. INP/CLS finalize on\n // visibilitychange), by which point the part active at report time may\n // not be the one the entry happened in.\n const metricTimeMillis = this._getTimeForMetric(metric);\n const sessionPartId =\n this.userSessionManager.getSessionPartIdAt(metricTimeMillis);\n const notRestoredReasons = getBfcacheNotRestoredReasons();\n const logRecord: LogRecord = {\n attributes: {\n [KEY_MXL_TYPE]: MXL_TYPES.WebVital,\n [KEY_BROWSER_WEB_VITAL_NAME]: metric.name.toLowerCase(),\n [KEY_BROWSER_WEB_VITAL_VALUE]: metric.value,\n [KEY_BROWSER_WEB_VITAL_DELTA]: metric.delta,\n [KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,\n [KEY_BROWSER_WEB_VITAL_ID]: metric.id,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId,\n ...(metric.navigationInteractionId !== undefined\n ? {\n [KEY_BROWSER_WEB_VITAL_INTERACTION_ID]:\n metric.navigationInteractionId,\n }\n : {}),\n ...(sessionPartId !== null\n ? { [KEY_MXL_SESSION_PART_ID]: sessionPartId }\n : {}),\n ...(notRestoredReasons?.length\n ? {\n [KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]:\n notRestoredReasons,\n }\n : {}),\n ...(attributedPage\n ? {\n // The navigationURL emitted by web-vitals is authoritative for which URL the metric\n // belongs to, since it was captured when the metric occurred. When soft navigations\n // are not supported, we fall back to the attributed page.\n [KEY_BROWSER_URL_FULL]:\n metric.navigationURL != null &&\n (metric.navigationType === 'soft-navigation' ||\n this._softNavsActive)\n ? metric.navigationURL\n : attributedPage.fullURL,\n [KEY_MXL_PAGE_PATH]: attributedPage.path,\n [KEY_MXL_PAGE_ID]: attributedPage.pageID,\n [KEY_APP_SURFACE_LABEL]: attributedPage.label,\n }\n : {}),\n ...(metric.name === 'INP'\n ? loafScriptsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'INP' ? inpAttribution(metric, this._diag) : {}),\n ...(metric.name === 'TTFB'\n ? ttfbSubPartsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'CLS'\n ? clsLayoutShiftsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'LCP'\n ? lcpElementAttribution(metric, this._diag)\n : {}),\n },\n body: this._includeRawAttribution\n ? JSON.stringify(\n Object.fromEntries(\n Object.entries(metric.attribution).filter(([, v]) =>\n isPrimitiveValue(v),\n ),\n ),\n )\n : undefined,\n eventName: WEB_VITAL_EVENT_NAME,\n severityNumber: SeverityNumber.INFO,\n timestamp: millisToHrTime(metricTimeMillis),\n };\n\n if (this._applyCustomLogRecordData) {\n safeExecuteInTheMiddle(\n () => this._applyCustomLogRecordData?.(logRecord),\n (error) => {\n if (error) {\n this._diag.error('applyCustomLogRecordData hook failed', error);\n }\n },\n true,\n );\n }\n\n this.logger.emit(logRecord);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA0DA,MAAM,cAAc,UAA0B,KAAK,MAAM,KAAK,IAAI,GAAG,MAAM,CAAC;AAE5E,MAAM,aAAa,UAA4B;CAC7C,GAAG,KAAK,MAAM,MAAM,KAAK,EAAE;CAC3B,GAAG,KAAK,MAAM,MAAM,KAAK,EAAE;CAC3B,OAAO,KAAK,MAAM,MAAM,SAAS,EAAE;CACnC,QAAQ,KAAK,MAAM,MAAM,UAAU,EAAE;CACtC;AAED,MAAM,oBACJ,UACuC;CACvC,MAAM,OAAO,OAAO;AACpB,QAAO,SAAS,YAAY,SAAS,YAAY,SAAS;;AAG5D,MAAM,0BACJ,QACA,SACe;CACf,MAAM,aAAyB,EAAE;CACjC,MAAM,cAAc,OAAO;AAE3B,KAAI;AAGF,MAAI,YAAY,0BAA0B,SAAS,GAAG;GACpD,MAAM,0BAAU,IAAI,KAOjB;AACH,QAAK,MAAM,SAAS,YAAY,0BAC9B,MAAK,MAAM,UAAU,MAAM,SAAS;IAClC,IAAI,MAAM,OAAO,aAAa;AAC9B,QAAI,IAAI,SAAA,KACN,OAAM,GAAG,IAAI,UAAU,GAAGA,uEAAAA,2BAA2B,CAAC;IAExD,MAAM,WAAW,QAAQ,IAAI,IAAI;AACjC,QAAI,UAAU;AACZ,cA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ACN,GAAI,OAAO,SAAS,QAChB,2BAA2B,QAAQ,KAAK,MAAM,GAC9C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,sBAAsB,QAAQ,KAAK,MAAM,GACzC,EAAE;IACP;GACD,MAAM,KAAK,yBACP,KAAK,UACH,OAAO,YACL,OAAO,QAAQ,OAAO,YAAY,CAAC,QAAQ,GAAG,OAC5C,iBAAiB,EAAE,CACpB,CACF,CACF,GACD,KAAA;GACJ,WAAWC,uEAAAA;GACX,gBAAgBC,mBAAAA,eAAe;GAC/B,YAAA,GAAA,oBAAA,gBAA0B,iBAAiB;GAC5C;AAED,MAAI,KAAK,0BACP,EAAA,GAAA,+BAAA,8BACQ,KAAK,4BAA4B,UAAU,GAChD,UAAU;AACT,OAAI,MACF,MAAK,MAAM,MAAM,wCAAwC,MAAM;KAGnE,KACD;AAGH,OAAK,OAAO,KAAK,UAAU"}
@@ -3,7 +3,7 @@ import { MXLInstrumentationBase } from "../../MXLInstrumentationBase/MXLInstrume
3
3
 
4
4
  //#region src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.ts
5
5
  declare class WebVitalsInstrumentation extends MXLInstrumentationBase {
6
- private readonly _listeners;
6
+ private _listeners;
7
7
  private readonly _urlDocument;
8
8
  private readonly _urlAttribution;
9
9
  private readonly _includeRawAttribution;
@@ -26,9 +26,10 @@ declare class WebVitalsInstrumentation extends MXLInstrumentationBase {
26
26
  applyCustomLogRecordData,
27
27
  ...config
28
28
  }?: WebVitalsInstrumentationArgs);
29
- enable(): void;
29
+ private readonly _listenersProvided;
30
30
  protected onDisable(): void;
31
31
  protected onEnable(): void;
32
+ private _registerListeners;
32
33
  private _currentAttributedPage;
33
34
  private _getTimeForMetric;
34
35
  private _emitWebVital;
@@ -1 +1 @@
1
- {"version":3,"file":"WebVitalsInstrumentation.d.cts","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"mappings":";;;;cAwSa,wBAAA,SAAiC,sBAAA;EAAA,iBAC3B,UAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,iBACA,sBAAA;EAAA,iBACA,eAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,QAUT,yBAAA;EAAA,QACA,YAAA;EAAA,QACA,yBAAA;EAAA,QACA,oBAAA;;IAGN,IAAA;IACA,IAAA;IACA,SAAA;IACA,WAAA;IACA,cAAA;IACA,qBAAA;IACA,cAAA;IACA,WAAA;IACA,wBAAA;IAAA,GACG;EAAA,IACF,4BAAA;EAsBa,MAAA,CAAA;EAAA,UAUG,SAAA,CAAA;EAAA,UAMA,QAAA,CAAA;EAAA,QAyDX,sBAAA;EAAA,QASA,iBAAA;EAAA,QA4CA,aAAA;AAAA"}
1
+ {"version":3,"file":"WebVitalsInstrumentation.d.cts","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"mappings":";;;;cAwSa,wBAAA,SAAiC,sBAAA;EAAA,QACpC,UAAA;EAAA,iBACS,YAAA;EAAA,iBACA,eAAA;EAAA,iBACA,sBAAA;EAAA,iBACA,eAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,QAUT,yBAAA;EAAA,QACA,YAAA;EAAA,QACA,yBAAA;EAAA,QACA,oBAAA;;IAGN,IAAA;IACA,IAAA;IACA,SAAA;IACA,WAAA;IACA,cAAA;IACA,qBAAA;IACA,cAAA;IACA,WAAA;IACA,wBAAA;IAAA,GACG;EAAA,IACF,4BAAA;EAAA,iBAmBc,kBAAA;EAAA,UAEE,SAAA,CAAA;EAAA,UAMA,QAAA,CAAA;EAAA,QAwBX,kBAAA;EAAA,QAgDA,sBAAA;EAAA,QASA,iBAAA;EAAA,QA0CA,aAAA;AAAA"}
@@ -3,7 +3,7 @@ import { MXLInstrumentationBase } from "../../MXLInstrumentationBase/MXLInstrume
3
3
 
4
4
  //#region src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.d.ts
5
5
  declare class WebVitalsInstrumentation extends MXLInstrumentationBase {
6
- private readonly _listeners;
6
+ private _listeners;
7
7
  private readonly _urlDocument;
8
8
  private readonly _urlAttribution;
9
9
  private readonly _includeRawAttribution;
@@ -26,9 +26,10 @@ declare class WebVitalsInstrumentation extends MXLInstrumentationBase {
26
26
  applyCustomLogRecordData,
27
27
  ...config
28
28
  }?: WebVitalsInstrumentationArgs);
29
- enable(): void;
29
+ private readonly _listenersProvided;
30
30
  protected onDisable(): void;
31
31
  protected onEnable(): void;
32
+ private _registerListeners;
32
33
  private _currentAttributedPage;
33
34
  private _getTimeForMetric;
34
35
  private _emitWebVital;
@@ -1 +1 @@
1
- {"version":3,"file":"WebVitalsInstrumentation.d.ts","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"mappings":";;;;cAwSa,wBAAA,SAAiC,sBAAA;EAAA,iBAC3B,UAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,iBACA,sBAAA;EAAA,iBACA,eAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,QAUT,yBAAA;EAAA,QACA,YAAA;EAAA,QACA,yBAAA;EAAA,QACA,oBAAA;;IAGN,IAAA;IACA,IAAA;IACA,SAAA;IACA,WAAA;IACA,cAAA;IACA,qBAAA;IACA,cAAA;IACA,WAAA;IACA,wBAAA;IAAA,GACG;EAAA,IACF,4BAAA;EAsBa,MAAA,CAAA;EAAA,UAUG,SAAA,CAAA;EAAA,UAMA,QAAA,CAAA;EAAA,QAyDX,sBAAA;EAAA,QASA,iBAAA;EAAA,QA4CA,aAAA;AAAA"}
1
+ {"version":3,"file":"WebVitalsInstrumentation.d.ts","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"mappings":";;;;cAwSa,wBAAA,SAAiC,sBAAA;EAAA,QACpC,UAAA;EAAA,iBACS,YAAA;EAAA,iBACA,eAAA;EAAA,iBACA,sBAAA;EAAA,iBACA,eAAA;EAAA,iBACA,YAAA;EAAA,iBACA,eAAA;EAAA,QAUT,yBAAA;EAAA,QACA,YAAA;EAAA,QACA,yBAAA;EAAA,QACA,oBAAA;;IAGN,IAAA;IACA,IAAA;IACA,SAAA;IACA,WAAA;IACA,cAAA;IACA,qBAAA;IACA,cAAA;IACA,WAAA;IACA,wBAAA;IAAA,GACG;EAAA,IACF,4BAAA;EAAA,iBAmBc,kBAAA;EAAA,UAEE,SAAA,CAAA;EAAA,UAMA,QAAA,CAAA;EAAA,QAwBX,kBAAA;EAAA,QAgDA,sBAAA;EAAA,QASA,iBAAA;EAAA,QA0CA,aAAA;AAAA"}
@@ -5,10 +5,10 @@ import { isEntryTypeSupported } from "../../../utils/performanceObserver/perform
5
5
  import { getBfcacheNotRestoredReasons } from "../../../utils/getBfcacheNotRestoredReasons.js";
6
6
  import { getSelector } from "../../../utils/getSelector.js";
7
7
  import { KEY_BROWSER_WEB_VITAL_DELTA, KEY_BROWSER_WEB_VITAL_ID, KEY_BROWSER_WEB_VITAL_INTERACTION_ID, KEY_BROWSER_WEB_VITAL_NAME, KEY_BROWSER_WEB_VITAL_NAVIGATION_ID, KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE, KEY_BROWSER_WEB_VITAL_RATING, KEY_BROWSER_WEB_VITAL_VALUE, KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX } from "./attributes.js";
8
- import { ALL_WEB_VITALS, MAX_LOAF_SCRIPT_URL_LENGTH, WEB_VITALS_ID_TO_LISTENER, WEB_VITAL_EVENT_NAME } from "./constants.js";
9
- import { millisToHrTime } from "@opentelemetry/core";
10
- import { SeverityNumber } from "@opentelemetry/api-logs";
8
+ import { ALL_WEB_VITALS, MAX_LOAF_SCRIPT_URL_LENGTH, WEB_VITAL_EVENT_NAME, loadWebVitalListeners } from "./constants.js";
9
+ import { SeverityNumber } from "@opentelemetry/api";
11
10
  import { safeExecuteInTheMiddle } from "@opentelemetry/instrumentation";
11
+ import { millisToHrTime } from "@opentelemetry/core";
12
12
  //#region src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts
13
13
  const roundClamp = (value) => Math.round(Math.max(0, value));
14
14
  const roundRect = (rect) => ({
@@ -141,7 +141,7 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
141
141
  _clsMetricId = void 0;
142
142
  _applyCustomLogRecordData;
143
143
  _listenersRegistered = false;
144
- constructor({ diag, perf, listeners = WEB_VITALS_ID_TO_LISTENER, urlDocument, urlAttribution = true, includeRawAttribution = true, reportSoftNavs = true, pageManager, applyCustomLogRecordData, ...config } = {}) {
144
+ constructor({ diag, perf, listeners, urlDocument, urlAttribution = true, includeRawAttribution = true, reportSoftNavs = true, pageManager, applyCustomLogRecordData, ...config } = {}) {
145
145
  super({
146
146
  config,
147
147
  diag,
@@ -149,19 +149,16 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
149
149
  instrumentationVersion: "1.0.0",
150
150
  perf
151
151
  });
152
- this._listeners = listeners;
152
+ this._listeners = listeners ?? {};
153
153
  this._urlDocument = urlDocument ?? window.document;
154
154
  this._urlAttribution = urlAttribution;
155
155
  this._includeRawAttribution = includeRawAttribution;
156
156
  this._softNavsActive = reportSoftNavs && isEntryTypeSupported("soft-navigation");
157
157
  this._pageManager = pageManager ?? page.getPageManager();
158
158
  this._applyCustomLogRecordData = applyCustomLogRecordData;
159
- if (this._config.enabled !== false) this.enable();
160
- }
161
- enable() {
162
- if (typeof PerformanceObserver !== "undefined") super.enable();
163
- else this._diag.debug("PerformanceObserver not supported, web vitals will not be collected");
159
+ this._listenersProvided = listeners !== void 0;
164
160
  }
161
+ _listenersProvided;
165
162
  onDisable() {
166
163
  this._diag.debug("WebVitalsInstrumentation disabled, pausing emission");
167
164
  }
@@ -171,6 +168,17 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
171
168
  return;
172
169
  }
173
170
  this._listenersRegistered = true;
171
+ if (this._listenersProvided) {
172
+ this._registerListeners();
173
+ return;
174
+ }
175
+ loadWebVitalListeners().then((listeners) => {
176
+ if (!this._isEnabled) return;
177
+ this._listeners = listeners;
178
+ this._registerListeners();
179
+ });
180
+ }
181
+ _registerListeners() {
174
182
  ALL_WEB_VITALS.forEach((name) => {
175
183
  const reportSoftNavs = name !== "TTFB" && this._softNavsActive;
176
184
  if (this._urlAttribution) this._listeners[name]?.((metric) => {
@@ -206,15 +214,15 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
206
214
  };
207
215
  }
208
216
  _getTimeForMetric(metric) {
209
- if (metric.name === "INP" && metric.attribution.interactionTime !== void 0) return this.perf.epochMillisFromOriginOffset(metric.attribution.interactionTime);
217
+ if (metric.name === "INP" && metric.attribution.interactionTime !== void 0) return this.perf.offsetToAbsoluteTime(metric.attribution.interactionTime);
210
218
  if (metric.name === "CLS") {
211
219
  const windowStart = metric.entries.length > 0 ? Math.min(...metric.entries.map((entry) => entry.startTime)) : metric.attribution.largestShiftTime;
212
- if (windowStart !== void 0) return this.perf.epochMillisFromOriginOffset(windowStart);
220
+ if (windowStart !== void 0) return this.perf.offsetToAbsoluteTime(windowStart);
213
221
  }
214
222
  if (metric.name === "TTFB") return this.perf.getZeroTime();
215
223
  const metricStartTime = metric.entries[metric.entries.length - 1]?.startTime;
216
- if (metricStartTime !== void 0) return this.perf.epochMillisFromOriginOffset(metricStartTime);
217
- return this.perf.getNowMillis();
224
+ if (metricStartTime !== void 0) return this.perf.offsetToAbsoluteTime(metricStartTime);
225
+ return this.perf.getNow();
218
226
  }
219
227
  _emitWebVital(metric) {
220
228
  const attributedPage = this._attributedPage[metric.name];
@@ -230,7 +238,7 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
230
238
  [KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,
231
239
  [KEY_BROWSER_WEB_VITAL_ID]: metric.id,
232
240
  [KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,
233
- ...metric.navigationId !== void 0 ? { [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId } : {},
241
+ [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId,
234
242
  ...metric.navigationInteractionId !== void 0 ? { [KEY_BROWSER_WEB_VITAL_INTERACTION_ID]: metric.navigationInteractionId } : {},
235
243
  ...sessionPartId !== null ? { [KEY_MXL_SESSION_PART_ID]: sessionPartId } : {},
236
244
  ...notRestoredReasons?.length ? { [KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]: notRestoredReasons } : {},
@@ -246,7 +254,7 @@ var WebVitalsInstrumentation = class extends MXLInstrumentationBase {
246
254
  ...metric.name === "CLS" ? clsLayoutShiftsAttribution(metric, this._diag) : {},
247
255
  ...metric.name === "LCP" ? lcpElementAttribution(metric, this._diag) : {}
248
256
  },
249
- body: this._includeRawAttribution && metric.attribution != null ? JSON.stringify(Object.fromEntries(Object.entries(metric.attribution).filter(([, v]) => isPrimitiveValue(v)))) : void 0,
257
+ body: this._includeRawAttribution ? JSON.stringify(Object.fromEntries(Object.entries(metric.attribution).filter(([, v]) => isPrimitiveValue(v)))) : void 0,
250
258
  eventName: WEB_VITAL_EVENT_NAME,
251
259
  severityNumber: SeverityNumber.INFO,
252
260
  timestamp: millisToHrTime(metricTimeMillis)
@@ -1 +1 @@
1
- {"version":3,"file":"WebVitalsInstrumentation.js","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"sourcesContent":["import type { Attributes, DiagLogger } from '@opentelemetry/api';\nimport type { LogRecord } from '@opentelemetry/api-logs';\nimport { SeverityNumber } from '@opentelemetry/api-logs';\nimport { millisToHrTime } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type {\n CLSMetricWithAttribution,\n INPAttribution,\n LCPAttribution,\n Metric,\n MetricWithAttribution,\n TTFBAttribution,\n} from 'web-vitals/attribution';\nimport type { PageManager } from '../../../api-page/manager/types';\nimport { page } from '../../../api-page/pageAPI';\nimport type { URLDocument } from '../../../common/types';\nimport {\n KEY_APP_SURFACE_LABEL,\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_BROWSER_URL_FULL,\n KEY_MXL_PAGE_ID,\n KEY_MXL_PAGE_PATH,\n KEY_MXL_SESSION_PART_ID,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { getBfcacheNotRestoredReasons } from '../../../utils/getBfcacheNotRestoredReasons';\nimport { getSelector } from '../../../utils/getSelector';\nimport { isEntryTypeSupported } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport {\n KEY_BROWSER_WEB_VITAL_DELTA,\n KEY_BROWSER_WEB_VITAL_ID,\n KEY_BROWSER_WEB_VITAL_INTERACTION_ID,\n KEY_BROWSER_WEB_VITAL_NAME,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_ID,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE,\n KEY_BROWSER_WEB_VITAL_RATING,\n KEY_BROWSER_WEB_VITAL_VALUE,\n KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX,\n} from './attributes';\nimport {\n ALL_WEB_VITALS,\n MAX_CLS_LAYOUT_SHIFTS,\n MAX_LOAF_SCRIPT_ENTRIES,\n MAX_LOAF_SCRIPT_URL_LENGTH,\n WEB_VITAL_EVENT_NAME,\n WEB_VITALS_ID_TO_LISTENER,\n} from './constants';\nimport type { WebVitalListeners, WebVitalsInstrumentationArgs } from './types';\n\ntype AttributedPage = {\n fullURL: string;\n path?: string;\n pageID?: string;\n label?: string;\n};\n\nconst roundClamp = (value: number): number => Math.round(Math.max(0, value));\n\nconst roundRect = (rect?: DOMRectReadOnly) => ({\n x: Math.round(rect?.x ?? 0),\n y: Math.round(rect?.y ?? 0),\n width: Math.round(rect?.width ?? 0),\n height: Math.round(rect?.height ?? 0),\n});\n\nconst isPrimitiveValue = (\n value: unknown,\n): value is string | number | boolean => {\n const type = typeof value;\n return type === 'number' || type === 'string' || type === 'boolean';\n};\n\nconst loafScriptsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as INPAttribution;\n\n try {\n // Suppress LoAF baseline errors\n /* eslint-disable baseline-js/use-baseline */\n if (attribution.longAnimationFrameEntries.length > 0) {\n const scripts = new Map<\n string,\n {\n totalDuration: number;\n styleAndLayoutDuration: number;\n count: number;\n }\n >();\n for (const entry of attribution.longAnimationFrameEntries) {\n for (const script of entry.scripts) {\n let url = script.sourceURL || '(inline)';\n if (url.length > MAX_LOAF_SCRIPT_URL_LENGTH) {\n url = `${url.substring(0, MAX_LOAF_SCRIPT_URL_LENGTH)}...`;\n }\n const existing = scripts.get(url);\n if (existing) {\n existing.totalDuration += script.duration;\n existing.styleAndLayoutDuration +=\n script.forcedStyleAndLayoutDuration;\n existing.count++;\n } else {\n scripts.set(url, {\n count: 1,\n styleAndLayoutDuration: script.forcedStyleAndLayoutDuration,\n totalDuration: script.duration,\n });\n }\n }\n }\n if (scripts.size > 0) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}loaf_scripts`] =\n JSON.stringify(\n Object.fromEntries(\n [...scripts]\n .sort((a, b) => b[1].totalDuration - a[1].totalDuration)\n .slice(0, MAX_LOAF_SCRIPT_ENTRIES)\n .map(([url, script]) => [\n url,\n {\n count: script.count,\n style_and_layout_duration: Math.round(\n script.styleAndLayoutDuration,\n ),\n total_duration: Math.round(script.totalDuration),\n },\n ]),\n ),\n );\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building loaf scripts for INP', error);\n }\n\n return attributes;\n};\n\nconst clsLayoutShiftsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const entries = metric.entries as LayoutShift[];\n\n if (entries.length > 0) {\n const shifts = entries.slice(0, MAX_CLS_LAYOUT_SHIFTS).map((entry) => {\n // web-vitals exposes sources sorted by impact area descending, so the\n // first source is the element that contributed most to the shift.\n const source = entry.sources[0];\n return {\n selector: getSelector(source?.node ?? null),\n startRect: roundRect(source?.previousRect),\n endRect: roundRect(source?.currentRect),\n };\n });\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}clsLayoutShifts`] = JSON.stringify(shifts);\n\n if (entries.length > MAX_CLS_LAYOUT_SHIFTS) {\n attributes[`${prefix}clsLayoutShiftsDroppedCount`] =\n entries.length - MAX_CLS_LAYOUT_SHIFTS;\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building CLS layout shifts', error);\n }\n\n return attributes;\n};\n\nconst inpAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const target = (metric.entries as PerformanceEventTiming[]).find(\n (entry) => entry.target,\n )?.target as Element | null | undefined;\n\n const tagName = target?.tagName?.toLowerCase();\n\n if (tagName) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}element_type`] =\n tagName;\n }\n\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building INP element type attribution', error);\n }\n\n return attributes;\n};\n\nconst ttfbSubPartsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as TTFBAttribution;\n const entry = attribution.navigationEntry as\n | PerformanceNavigationTiming\n | undefined;\n\n if (entry) {\n try {\n const redirect = roundClamp(entry.redirectEnd - entry.redirectStart);\n const domainLookup = roundClamp(\n entry.domainLookupEnd - entry.domainLookupStart,\n );\n const tcpConnection = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.secureConnectionStart - entry.connectStart\n : entry.connectEnd - entry.connectStart,\n );\n const tlsNegotiation = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.connectEnd - entry.secureConnectionStart\n : 0,\n );\n const effectiveResponseStart = Math.max(\n // @ts-expect-error 103 Early hints are not supported in all browsers\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/finalResponseHeadersStart\n entry.finalResponseHeadersStart ?? 0,\n entry.responseStart,\n );\n const serverResponse = roundClamp(\n effectiveResponseStart - entry.requestStart,\n );\n const total = Math.round(entry.responseEnd - entry.startTime);\n const unattributed = roundClamp(\n total -\n redirect -\n domainLookup -\n tcpConnection -\n tlsNegotiation -\n serverResponse,\n );\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}redirect`] = redirect;\n attributes[`${prefix}domainLookup`] = domainLookup;\n attributes[`${prefix}tcpConnection`] = tcpConnection;\n attributes[`${prefix}tlsNegotiation`] = tlsNegotiation;\n attributes[`${prefix}serverResponse`] = serverResponse;\n attributes[`${prefix}unattributed`] = unattributed;\n } catch (error) {\n diag.error('error computing TTFB timing breakdown', error);\n }\n } else {\n diag.debug('TTFB navigationEntry unavailable, skipping timing breakdown');\n }\n\n return attributes;\n};\n\nconst lcpElementAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n const attribution = metric.attribution as LCPAttribution;\n const element = attribution.lcpEntry?.element;\n\n if (element) {\n const elementType = element.tagName.toLowerCase();\n const elementBoundingRect = JSON.stringify(\n roundRect(element.getBoundingClientRect()),\n );\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}elementType`] = elementType;\n attributes[`${prefix}elementBoundingRect`] = elementBoundingRect;\n }\n } catch (error) {\n diag.error('error building LCP element attribution', error);\n }\n\n return attributes;\n};\n\nexport class WebVitalsInstrumentation extends MXLInstrumentationBase {\n private readonly _listeners: WebVitalListeners;\n private readonly _urlDocument: URLDocument;\n private readonly _urlAttribution: boolean;\n private readonly _includeRawAttribution: boolean;\n private readonly _softNavsActive: boolean;\n private readonly _pageManager: PageManager;\n private readonly _attributedPage: Record<\n Metric['name'],\n AttributedPage | undefined\n > = {\n CLS: undefined,\n FCP: undefined,\n INP: undefined,\n LCP: undefined,\n TTFB: undefined,\n };\n private _largestShiftTargetForCLS: string | undefined | null = null;\n private _clsMetricId: string | undefined = undefined;\n private _applyCustomLogRecordData?: (logRecord: LogRecord) => void;\n private _listenersRegistered = false;\n\n public constructor({\n diag,\n perf,\n listeners = WEB_VITALS_ID_TO_LISTENER,\n urlDocument,\n urlAttribution = true,\n includeRawAttribution = true,\n reportSoftNavs = true,\n pageManager,\n applyCustomLogRecordData,\n ...config\n }: WebVitalsInstrumentationArgs = {}) {\n super({\n config,\n diag,\n instrumentationName: 'WebVitalsInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n this._listeners = listeners;\n this._urlDocument = urlDocument ?? window.document;\n this._urlAttribution = urlAttribution;\n this._includeRawAttribution = includeRawAttribution;\n this._softNavsActive =\n reportSoftNavs && isEntryTypeSupported('soft-navigation');\n this._pageManager = pageManager ?? page.getPageManager();\n this._applyCustomLogRecordData = applyCustomLogRecordData;\n\n if (this._config.enabled !== false) {\n this.enable();\n }\n }\n\n public override enable(): void {\n if (typeof PerformanceObserver !== 'undefined') {\n super.enable();\n } else {\n this._diag.debug(\n 'PerformanceObserver not supported, web vitals will not be collected',\n );\n }\n }\n\n protected override onDisable(): void {\n // web-vitals library doesn't support removing listeners, so we pause emission\n // https://github.com/GoogleChrome/web-vitals/issues/357#issuecomment-1593439036\n this._diag.debug('WebVitalsInstrumentation disabled, pausing emission');\n }\n\n protected override onEnable(): void {\n // web-vitals library doesn't support removing listeners, so only register once\n if (this._listenersRegistered) {\n this._diag.debug(\n 'WebVitalsInstrumentation listeners already registered, resuming emission',\n );\n return;\n }\n this._listenersRegistered = true;\n\n ALL_WEB_VITALS.forEach((name) => {\n // web-vitals reports a hardcoded dummy value of zero for TTFB on soft navigations. That\n // is not a real measurement and would skew the data, so TTFB listeners keep soft\n // navigation reporting off.\n const reportSoftNavs = name !== 'TTFB' && this._softNavsActive;\n\n if (this._urlAttribution) {\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n if (metric.name === 'CLS') {\n const clsMetric = metric as CLSMetricWithAttribution;\n const target = clsMetric.attribution.largestShiftTarget;\n\n if (this._clsMetricId !== clsMetric.id) {\n // A new metric ID means CLS has reset for a soft navigation.\n this._clsMetricId = clsMetric.id;\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n } else if (this._largestShiftTargetForCLS !== target) {\n // When the largest shift target changes, make sure the attributed page is updated\n // to reflect the page where that shift occurred.\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n }\n } else {\n this._attributedPage[metric.name] = this._currentAttributedPage();\n }\n },\n { reportAllChanges: true, reportSoftNavs },\n );\n }\n\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n this._emitWebVital(metric);\n },\n { reportSoftNavs },\n );\n });\n }\n\n private _currentAttributedPage(): AttributedPage {\n return {\n fullURL: this._urlDocument.URL,\n label: this._pageManager.getPageLabel() ?? undefined,\n pageID: this._pageManager.getCurrentPageId() ?? undefined,\n path: this._pageManager.getCurrentRoute()?.path,\n };\n }\n\n private _getTimeForMetric(metric: MetricWithAttribution): number {\n // For INP use interactionTime, which is the start time of the user's interaction\n if (\n metric.name === 'INP' &&\n metric.attribution.interactionTime !== undefined\n ) {\n return this.perf.epochMillisFromOriginOffset(\n metric.attribution.interactionTime,\n );\n }\n\n // For CLS use the first layout shift's startTime, which is the beginning of\n // the session window. Fall back to largestShiftTime if the entries aren't\n // available for some reason.\n if (metric.name === 'CLS') {\n const windowStart =\n metric.entries.length > 0\n ? Math.min(...metric.entries.map((entry) => entry.startTime))\n : metric.attribution.largestShiftTime;\n\n if (windowStart !== undefined) {\n return this.perf.epochMillisFromOriginOffset(windowStart);\n }\n }\n\n // For TTFB use the \"zero\" time of the current session part\n if (metric.name === 'TTFB') {\n return this.perf.getZeroTime();\n }\n\n // For other metrics, use the startTime of the last entry. In practice, web-vitals does\n // not emit multiple entries for metrics other than CLS. However to future-proof this code,\n // we are assuming that the last entry is the most relevant one.\n const metricStartTime =\n metric.entries[metric.entries.length - 1]?.startTime;\n\n if (metricStartTime !== undefined) {\n return this.perf.epochMillisFromOriginOffset(metricStartTime);\n }\n\n // Fall back to when the metric was reported\n return this.perf.getNowMillis();\n }\n\n private _emitWebVital(metric: MetricWithAttribution): void {\n const attributedPage = this._attributedPage[metric.name];\n // Resolve by the metric's own event time rather than reading the\n // currently active part: web-vitals can defer a metric's report well\n // past when its underlying entry occurred (e.g. INP/CLS finalize on\n // visibilitychange), by which point the part active at report time may\n // not be the one the entry happened in.\n const metricTimeMillis = this._getTimeForMetric(metric);\n const sessionPartId =\n this.userSessionManager.getSessionPartIdAt(metricTimeMillis);\n const notRestoredReasons = getBfcacheNotRestoredReasons();\n const logRecord: LogRecord = {\n attributes: {\n [KEY_MXL_TYPE]: MXL_TYPES.WebVital,\n [KEY_BROWSER_WEB_VITAL_NAME]: metric.name.toLowerCase(),\n [KEY_BROWSER_WEB_VITAL_VALUE]: metric.value,\n [KEY_BROWSER_WEB_VITAL_DELTA]: metric.delta,\n [KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,\n [KEY_BROWSER_WEB_VITAL_ID]: metric.id,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,\n ...(metric.navigationId !== undefined\n ? { [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId }\n : {}),\n ...(metric.navigationInteractionId !== undefined\n ? {\n [KEY_BROWSER_WEB_VITAL_INTERACTION_ID]:\n metric.navigationInteractionId,\n }\n : {}),\n ...(sessionPartId !== null\n ? { [KEY_MXL_SESSION_PART_ID]: sessionPartId }\n : {}),\n ...(notRestoredReasons?.length\n ? {\n [KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]:\n notRestoredReasons,\n }\n : {}),\n ...(attributedPage\n ? {\n // The navigationURL emitted by web-vitals is authoritative for which URL the metric\n // belongs to, since it was captured when the metric occurred. When soft navigations\n // are not supported, we fall back to the attributed page.\n [KEY_BROWSER_URL_FULL]:\n metric.navigationURL != null &&\n (metric.navigationType === 'soft-navigation' ||\n this._softNavsActive)\n ? metric.navigationURL\n : attributedPage.fullURL,\n [KEY_MXL_PAGE_PATH]: attributedPage.path,\n [KEY_MXL_PAGE_ID]: attributedPage.pageID,\n [KEY_APP_SURFACE_LABEL]: attributedPage.label,\n }\n : {}),\n ...(metric.name === 'INP'\n ? loafScriptsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'INP' ? inpAttribution(metric, this._diag) : {}),\n ...(metric.name === 'TTFB'\n ? ttfbSubPartsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'CLS'\n ? clsLayoutShiftsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'LCP'\n ? lcpElementAttribution(metric, this._diag)\n : {}),\n },\n body:\n this._includeRawAttribution && metric.attribution != null\n ? JSON.stringify(\n Object.fromEntries(\n Object.entries(metric.attribution).filter(([, v]) =>\n isPrimitiveValue(v),\n ),\n ),\n )\n : undefined,\n eventName: WEB_VITAL_EVENT_NAME,\n severityNumber: SeverityNumber.INFO,\n timestamp: millisToHrTime(metricTimeMillis),\n };\n\n if (this._applyCustomLogRecordData) {\n safeExecuteInTheMiddle(\n () => this._applyCustomLogRecordData?.(logRecord),\n (error) => {\n if (error) {\n this._diag.error('applyCustomLogRecordData hook failed', error);\n }\n },\n true,\n );\n }\n\n this.logger.emit(logRecord);\n }\n}\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAM,cAAc,UAA0B,KAAK,MAAM,KAAK,IAAI,G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AAoB,SACpB,GACG,qDACC,oBACH,GACD,EAAE;IACN,GAAI,iBACA;MAIG,uBACC,OAAO,iBAAiB,SACvB,OAAO,mBAAmB,qBACzB,KAAK,mBACH,OAAO,gBACP,eAAe;MACpB,oBAAoB,eAAe;MACnC,kBAAkB,eAAe;MACjC,wBAAwB,eAAe;KACzC,GACD,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,uBAAuB,QAAQ,KAAK,MAAM,GAC1C,EAAE;IACN,GAAI,OAAO,SAAS,QAAQ,eAAe,QAAQ,KAAK,MAAM,GAAG,EAAE;IACnE,GAAI,OAAO,SAAS,SAChB,wBAAwB,QAAQ,KAAK,MAAM,GAC3C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,2BAA2B,QAAQ,KAAK,MAAM,GAC9C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,sBAAsB,QAAQ,KAAK,MAAM,GACzC,EAAE;IACP;GACD,MACE,KAAK,0BAA0B,OAAO,eAAe,OACjD,KAAK,UACH,OAAO,YACL,OAAO,QAAQ,OAAO,YAAY,CAAC,QAAQ,GAAG,OAC5C,iBAAiB,EAAE,CACpB,CACF,CACF,GACD,KAAA;GACN,WAAW;GACX,gBAAgB,eAAe;GAC/B,WAAW,eAAe,iBAAiB;GAC5C;AAED,MAAI,KAAK,0BACP,8BACQ,KAAK,4BAA4B,UAAU,GAChD,UAAU;AACT,OAAI,MACF,MAAK,MAAM,MAAM,wCAAwC,MAAM;KAGnE,KACD;AAGH,OAAK,OAAO,KAAK,UAAU"}
1
+ {"version":3,"file":"WebVitalsInstrumentation.js","names":[],"sources":["../../../../src/instrumentations/web-vitals/WebVitalsInstrumentation/WebVitalsInstrumentation.ts"],"sourcesContent":["import type { Attributes, DiagLogger } from '@opentelemetry/api';\nimport type { LogRecord } from '@opentelemetry/api';\nimport { SeverityNumber } from '@opentelemetry/api';\nimport { millisToHrTime } from '@opentelemetry/core';\nimport { safeExecuteInTheMiddle } from '@opentelemetry/instrumentation';\nimport type {\n CLSMetricWithAttribution,\n INPAttribution,\n LCPAttribution,\n Metric,\n MetricWithAttribution,\n TTFBAttribution,\n} from 'web-vitals/attribution';\nimport type { PageManager } from '../../../api-page/manager/types';\nimport { page } from '../../../api-page/pageAPI';\nimport type { URLDocument } from '../../../common/types';\nimport {\n KEY_APP_SURFACE_LABEL,\n KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS,\n KEY_BROWSER_URL_FULL,\n KEY_MXL_PAGE_ID,\n KEY_MXL_PAGE_PATH,\n KEY_MXL_SESSION_PART_ID,\n KEY_MXL_TYPE,\n MXL_TYPES,\n} from '../../../constants/attributes';\nimport { getBfcacheNotRestoredReasons } from '../../../utils/getBfcacheNotRestoredReasons';\nimport { getSelector } from '../../../utils/getSelector';\nimport { isEntryTypeSupported } from '../../../utils/performanceObserver/performanceObserver';\nimport { MXLInstrumentationBase } from '../../MXLInstrumentationBase/MXLInstrumentationBase';\nimport {\n KEY_BROWSER_WEB_VITAL_DELTA,\n KEY_BROWSER_WEB_VITAL_ID,\n KEY_BROWSER_WEB_VITAL_INTERACTION_ID,\n KEY_BROWSER_WEB_VITAL_NAME,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_ID,\n KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE,\n KEY_BROWSER_WEB_VITAL_RATING,\n KEY_BROWSER_WEB_VITAL_VALUE,\n KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX,\n} from './attributes';\nimport {\n ALL_WEB_VITALS,\n MAX_CLS_LAYOUT_SHIFTS,\n MAX_LOAF_SCRIPT_ENTRIES,\n MAX_LOAF_SCRIPT_URL_LENGTH,\n WEB_VITAL_EVENT_NAME,\n loadWebVitalListeners,\n} from './constants';\nimport type { WebVitalListeners, WebVitalsInstrumentationArgs } from './types';\n\ntype AttributedPage = {\n fullURL: string;\n path?: string;\n pageID?: string;\n label?: string;\n};\n\nconst roundClamp = (value: number): number => Math.round(Math.max(0, value));\n\nconst roundRect = (rect?: DOMRectReadOnly) => ({\n x: Math.round(rect?.x ?? 0),\n y: Math.round(rect?.y ?? 0),\n width: Math.round(rect?.width ?? 0),\n height: Math.round(rect?.height ?? 0),\n});\n\nconst isPrimitiveValue = (\n value: unknown,\n): value is string | number | boolean => {\n const type = typeof value;\n return type === 'number' || type === 'string' || type === 'boolean';\n};\n\nconst loafScriptsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as INPAttribution;\n\n try {\n // Suppress LoAF baseline errors\n /* eslint-disable baseline-js/use-baseline */\n if (attribution.longAnimationFrameEntries.length > 0) {\n const scripts = new Map<\n string,\n {\n totalDuration: number;\n styleAndLayoutDuration: number;\n count: number;\n }\n >();\n for (const entry of attribution.longAnimationFrameEntries) {\n for (const script of entry.scripts) {\n let url = script.sourceURL || '(inline)';\n if (url.length > MAX_LOAF_SCRIPT_URL_LENGTH) {\n url = `${url.substring(0, MAX_LOAF_SCRIPT_URL_LENGTH)}...`;\n }\n const existing = scripts.get(url);\n if (existing) {\n existing.totalDuration += script.duration;\n existing.styleAndLayoutDuration +=\n script.forcedStyleAndLayoutDuration;\n existing.count++;\n } else {\n scripts.set(url, {\n count: 1,\n styleAndLayoutDuration: script.forcedStyleAndLayoutDuration,\n totalDuration: script.duration,\n });\n }\n }\n }\n if (scripts.size > 0) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}loaf_scripts`] =\n JSON.stringify(\n Object.fromEntries(\n [...scripts]\n .sort((a, b) => b[1].totalDuration - a[1].totalDuration)\n .slice(0, MAX_LOAF_SCRIPT_ENTRIES)\n .map(([url, script]) => [\n url,\n {\n count: script.count,\n style_and_layout_duration: Math.round(\n script.styleAndLayoutDuration,\n ),\n total_duration: Math.round(script.totalDuration),\n },\n ]),\n ),\n );\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building loaf scripts for INP', error);\n }\n\n return attributes;\n};\n\nconst clsLayoutShiftsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const entries = metric.entries as LayoutShift[];\n\n if (entries.length > 0) {\n const shifts = entries.slice(0, MAX_CLS_LAYOUT_SHIFTS).map((entry) => {\n // web-vitals exposes sources sorted by impact area descending, so the\n // first source is the element that contributed most to the shift.\n const source = entry.sources[0];\n return {\n selector: getSelector(source?.node ?? null),\n startRect: roundRect(source?.previousRect),\n endRect: roundRect(source?.currentRect),\n };\n });\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}clsLayoutShifts`] = JSON.stringify(shifts);\n\n if (entries.length > MAX_CLS_LAYOUT_SHIFTS) {\n attributes[`${prefix}clsLayoutShiftsDroppedCount`] =\n entries.length - MAX_CLS_LAYOUT_SHIFTS;\n }\n }\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building CLS layout shifts', error);\n }\n\n return attributes;\n};\n\nconst inpAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n /* eslint-disable baseline-js/use-baseline */\n const target = (metric.entries as PerformanceEventTiming[]).find(\n (entry) => entry.target,\n )?.target as Element | null | undefined;\n\n const tagName = target?.tagName?.toLowerCase();\n\n if (tagName) {\n attributes[`${KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX}element_type`] =\n tagName;\n }\n\n /* eslint-enable baseline-js/use-baseline */\n } catch (error) {\n diag.error('error building INP element type attribution', error);\n }\n\n return attributes;\n};\n\nconst ttfbSubPartsAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n const attribution = metric.attribution as TTFBAttribution;\n const entry = attribution.navigationEntry as\n | PerformanceNavigationTiming\n | undefined;\n\n if (entry) {\n try {\n const redirect = roundClamp(entry.redirectEnd - entry.redirectStart);\n const domainLookup = roundClamp(\n entry.domainLookupEnd - entry.domainLookupStart,\n );\n const tcpConnection = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.secureConnectionStart - entry.connectStart\n : entry.connectEnd - entry.connectStart,\n );\n const tlsNegotiation = roundClamp(\n entry.secureConnectionStart > 0\n ? entry.connectEnd - entry.secureConnectionStart\n : 0,\n );\n const effectiveResponseStart = Math.max(\n // @ts-expect-error 103 Early hints are not supported in all browsers\n // https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/finalResponseHeadersStart\n entry.finalResponseHeadersStart ?? 0,\n entry.responseStart,\n );\n const serverResponse = roundClamp(\n effectiveResponseStart - entry.requestStart,\n );\n const total = Math.round(entry.responseEnd - entry.startTime);\n const unattributed = roundClamp(\n total -\n redirect -\n domainLookup -\n tcpConnection -\n tlsNegotiation -\n serverResponse,\n );\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}redirect`] = redirect;\n attributes[`${prefix}domainLookup`] = domainLookup;\n attributes[`${prefix}tcpConnection`] = tcpConnection;\n attributes[`${prefix}tlsNegotiation`] = tlsNegotiation;\n attributes[`${prefix}serverResponse`] = serverResponse;\n attributes[`${prefix}unattributed`] = unattributed;\n } catch (error) {\n diag.error('error computing TTFB timing breakdown', error);\n }\n } else {\n diag.debug('TTFB navigationEntry unavailable, skipping timing breakdown');\n }\n\n return attributes;\n};\n\nconst lcpElementAttribution = (\n metric: MetricWithAttribution,\n diag: DiagLogger,\n): Attributes => {\n const attributes: Attributes = {};\n\n try {\n const attribution = metric.attribution as LCPAttribution;\n const element = attribution.lcpEntry?.element;\n\n if (element) {\n const elementType = element.tagName.toLowerCase();\n const elementBoundingRect = JSON.stringify(\n roundRect(element.getBoundingClientRect()),\n );\n\n const prefix = KEY_MXL_WEB_VITAL_ATTRIBUTION_PREFIX;\n attributes[`${prefix}elementType`] = elementType;\n attributes[`${prefix}elementBoundingRect`] = elementBoundingRect;\n }\n } catch (error) {\n diag.error('error building LCP element attribution', error);\n }\n\n return attributes;\n};\n\nexport class WebVitalsInstrumentation extends MXLInstrumentationBase {\n private _listeners: WebVitalListeners;\n private readonly _urlDocument: URLDocument;\n private readonly _urlAttribution: boolean;\n private readonly _includeRawAttribution: boolean;\n private readonly _softNavsActive: boolean;\n private readonly _pageManager: PageManager;\n private readonly _attributedPage: Record<\n Metric['name'],\n AttributedPage | undefined\n > = {\n CLS: undefined,\n FCP: undefined,\n INP: undefined,\n LCP: undefined,\n TTFB: undefined,\n };\n private _largestShiftTargetForCLS: string | undefined | null = null;\n private _clsMetricId: string | undefined = undefined;\n private _applyCustomLogRecordData?: (logRecord: LogRecord) => void;\n private _listenersRegistered = false;\n\n public constructor({\n diag,\n perf,\n listeners,\n urlDocument,\n urlAttribution = true,\n includeRawAttribution = true,\n reportSoftNavs = true,\n pageManager,\n applyCustomLogRecordData,\n ...config\n }: WebVitalsInstrumentationArgs = {}) {\n super({\n config,\n diag,\n instrumentationName: 'WebVitalsInstrumentation',\n instrumentationVersion: '1.0.0',\n perf,\n });\n this._listeners = listeners ?? ({} as WebVitalListeners);\n this._urlDocument = urlDocument ?? window.document;\n this._urlAttribution = urlAttribution;\n this._includeRawAttribution = includeRawAttribution;\n this._softNavsActive =\n reportSoftNavs && isEntryTypeSupported('soft-navigation');\n this._pageManager = pageManager ?? page.getPageManager();\n this._applyCustomLogRecordData = applyCustomLogRecordData;\n this._listenersProvided = listeners !== undefined;\n }\n\n private readonly _listenersProvided: boolean;\n\n protected override onDisable(): void {\n // web-vitals library doesn't support removing listeners, so we pause emission\n // https://github.com/GoogleChrome/web-vitals/issues/357#issuecomment-1593439036\n this._diag.debug('WebVitalsInstrumentation disabled, pausing emission');\n }\n\n protected override onEnable(): void {\n // web-vitals library doesn't support removing listeners, so only register once\n if (this._listenersRegistered) {\n this._diag.debug(\n 'WebVitalsInstrumentation listeners already registered, resuming emission',\n );\n return;\n }\n this._listenersRegistered = true;\n\n if (this._listenersProvided) {\n this._registerListeners();\n return;\n }\n\n void loadWebVitalListeners().then((listeners) => {\n if (!this._isEnabled) {\n return;\n }\n this._listeners = listeners;\n this._registerListeners();\n });\n }\n\n private _registerListeners(): void {\n ALL_WEB_VITALS.forEach((name) => {\n // web-vitals reports a hardcoded dummy value of zero for TTFB on soft navigations. That\n // is not a real measurement and would skew the data, so TTFB listeners keep soft\n // navigation reporting off.\n const reportSoftNavs = name !== 'TTFB' && this._softNavsActive;\n\n if (this._urlAttribution) {\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n if (metric.name === 'CLS') {\n const clsMetric = metric as CLSMetricWithAttribution;\n const target = clsMetric.attribution.largestShiftTarget;\n\n if (this._clsMetricId !== clsMetric.id) {\n // A new metric ID means CLS has reset for a soft navigation.\n this._clsMetricId = clsMetric.id;\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n } else if (this._largestShiftTargetForCLS !== target) {\n // When the largest shift target changes, make sure the attributed page is updated\n // to reflect the page where that shift occurred.\n this._largestShiftTargetForCLS = target;\n this._attributedPage.CLS = this._currentAttributedPage();\n }\n } else {\n this._attributedPage[metric.name] = this._currentAttributedPage();\n }\n },\n { reportAllChanges: true, reportSoftNavs },\n );\n }\n\n this._listeners[name]?.(\n (metric) => {\n if (!this._isEnabled) {\n return;\n }\n this._emitWebVital(metric);\n },\n { reportSoftNavs },\n );\n });\n }\n\n private _currentAttributedPage(): AttributedPage {\n return {\n fullURL: this._urlDocument.URL,\n label: this._pageManager.getPageLabel() ?? undefined,\n pageID: this._pageManager.getCurrentPageId() ?? undefined,\n path: this._pageManager.getCurrentRoute()?.path,\n };\n }\n\n private _getTimeForMetric(metric: MetricWithAttribution): number {\n // For INP use interactionTime, which is the start time of the user's interaction\n if (\n metric.name === 'INP' &&\n metric.attribution.interactionTime !== undefined\n ) {\n return this.perf.offsetToAbsoluteTime(metric.attribution.interactionTime);\n }\n\n // For CLS use the first layout shift's startTime, which is the beginning of\n // the session window. Fall back to largestShiftTime if the entries aren't\n // available for some reason.\n if (metric.name === 'CLS') {\n const windowStart =\n metric.entries.length > 0\n ? Math.min(...metric.entries.map((entry) => entry.startTime))\n : metric.attribution.largestShiftTime;\n\n if (windowStart !== undefined) {\n return this.perf.offsetToAbsoluteTime(windowStart);\n }\n }\n\n // For TTFB use the \"zero\" time of the current session part\n if (metric.name === 'TTFB') {\n return this.perf.getZeroTime();\n }\n\n // For other metrics, use the startTime of the last entry. In practice, web-vitals does\n // not emit multiple entries for metrics other than CLS. However to future-proof this code,\n // we are assuming that the last entry is the most relevant one.\n const metricStartTime =\n metric.entries[metric.entries.length - 1]?.startTime;\n\n if (metricStartTime !== undefined) {\n return this.perf.offsetToAbsoluteTime(metricStartTime);\n }\n\n // Fall back to when the metric was reported\n return this.perf.getNow();\n }\n\n private _emitWebVital(metric: MetricWithAttribution): void {\n const attributedPage = this._attributedPage[metric.name];\n // Resolve by the metric's own event time rather than reading the\n // currently active part: web-vitals can defer a metric's report well\n // past when its underlying entry occurred (e.g. INP/CLS finalize on\n // visibilitychange), by which point the part active at report time may\n // not be the one the entry happened in.\n const metricTimeMillis = this._getTimeForMetric(metric);\n const sessionPartId =\n this.userSessionManager.getSessionPartIdAt(metricTimeMillis);\n const notRestoredReasons = getBfcacheNotRestoredReasons();\n const logRecord: LogRecord = {\n attributes: {\n [KEY_MXL_TYPE]: MXL_TYPES.WebVital,\n [KEY_BROWSER_WEB_VITAL_NAME]: metric.name.toLowerCase(),\n [KEY_BROWSER_WEB_VITAL_VALUE]: metric.value,\n [KEY_BROWSER_WEB_VITAL_DELTA]: metric.delta,\n [KEY_BROWSER_WEB_VITAL_RATING]: metric.rating,\n [KEY_BROWSER_WEB_VITAL_ID]: metric.id,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_TYPE]: metric.navigationType,\n [KEY_BROWSER_WEB_VITAL_NAVIGATION_ID]: metric.navigationId,\n ...(metric.navigationInteractionId !== undefined\n ? {\n [KEY_BROWSER_WEB_VITAL_INTERACTION_ID]:\n metric.navigationInteractionId,\n }\n : {}),\n ...(sessionPartId !== null\n ? { [KEY_MXL_SESSION_PART_ID]: sessionPartId }\n : {}),\n ...(notRestoredReasons?.length\n ? {\n [KEY_BROWSER_NAVIGATION_TIMING_NOT_RESTORED_REASONS]:\n notRestoredReasons,\n }\n : {}),\n ...(attributedPage\n ? {\n // The navigationURL emitted by web-vitals is authoritative for which URL the metric\n // belongs to, since it was captured when the metric occurred. When soft navigations\n // are not supported, we fall back to the attributed page.\n [KEY_BROWSER_URL_FULL]:\n metric.navigationURL != null &&\n (metric.navigationType === 'soft-navigation' ||\n this._softNavsActive)\n ? metric.navigationURL\n : attributedPage.fullURL,\n [KEY_MXL_PAGE_PATH]: attributedPage.path,\n [KEY_MXL_PAGE_ID]: attributedPage.pageID,\n [KEY_APP_SURFACE_LABEL]: attributedPage.label,\n }\n : {}),\n ...(metric.name === 'INP'\n ? loafScriptsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'INP' ? inpAttribution(metric, this._diag) : {}),\n ...(metric.name === 'TTFB'\n ? ttfbSubPartsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'CLS'\n ? clsLayoutShiftsAttribution(metric, this._diag)\n : {}),\n ...(metric.name === 'LCP'\n ? lcpElementAttribution(metric, this._diag)\n : {}),\n },\n body: this._includeRawAttribution\n ? JSON.stringify(\n Object.fromEntries(\n Object.entries(metric.attribution).filter(([, v]) =>\n isPrimitiveValue(v),\n ),\n ),\n )\n : undefined,\n eventName: WEB_VITAL_EVENT_NAME,\n severityNumber: SeverityNumber.INFO,\n timestamp: millisToHrTime(metricTimeMillis),\n };\n\n if (this._applyCustomLogRecordData) {\n safeExecuteInTheMiddle(\n () => this._applyCustomLogRecordData?.(logRecord),\n (error) => {\n if (error) {\n this._diag.error('applyCustomLogRecordData hook failed', error);\n }\n },\n true,\n );\n }\n\n this.logger.emit(logRecord);\n }\n}\n"],"mappings":";;;;;;;;;;;;AA0DA,MAAM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N,GAAI,kBAAkB,OAClB,GAAG,0BAA0B,eAAe,GAC5C,EAAE;IACN,GAAI,oBAAoB,SACpB,GACG,qDACC,oBACH,GACD,EAAE;IACN,GAAI,iBACA;MAIG,uBACC,OAAO,iBAAiB,SACvB,OAAO,mBAAmB,qBACzB,KAAK,mBACH,OAAO,gBACP,eAAe;MACpB,oBAAoB,eAAe;MACnC,kBAAkB,eAAe;MACjC,wBAAwB,eAAe;KACzC,GACD,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,uBAAuB,QAAQ,KAAK,MAAM,GAC1C,EAAE;IACN,GAAI,OAAO,SAAS,QAAQ,eAAe,QAAQ,KAAK,MAAM,GAAG,EAAE;IACnE,GAAI,OAAO,SAAS,SAChB,wBAAwB,QAAQ,KAAK,MAAM,GAC3C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,2BAA2B,QAAQ,KAAK,MAAM,GAC9C,EAAE;IACN,GAAI,OAAO,SAAS,QAChB,sBAAsB,QAAQ,KAAK,MAAM,GACzC,EAAE;IACP;GACD,MAAM,KAAK,yBACP,KAAK,UACH,OAAO,YACL,OAAO,QAAQ,OAAO,YAAY,CAAC,QAAQ,GAAG,OAC5C,iBAAiB,EAAE,CACpB,CACF,CACF,GACD,KAAA;GACJ,WAAW;GACX,gBAAgB,eAAe;GAC/B,WAAW,eAAe,iBAAiB;GAC5C;AAED,MAAI,KAAK,0BACP,8BACQ,KAAK,4BAA4B,UAAU,GAChD,UAAU;AACT,OAAI,MACF,MAAK,MAAM,MAAM,wCAAwC,MAAM;KAGnE,KACD;AAGH,OAAK,OAAO,KAAK,UAAU"}
@@ -1,6 +1,4 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("../../../_virtual/_rolldown/runtime.cjs");
3
- let web_vitals_attribution = require("web-vitals/attribution");
4
2
  //#region src/instrumentations/web-vitals/WebVitalsInstrumentation/constants.ts
5
3
  const WEB_VITAL_EVENT_NAME = "browser.web_vital";
6
4
  const MAX_LOAF_SCRIPT_URL_LENGTH = 2048;
@@ -13,73 +11,23 @@ const ALL_WEB_VITALS = [
13
11
  "FCP",
14
12
  "TTFB"
15
13
  ];
16
- const WEB_VITALS_ID_TO_LISTENER = {
17
- /**
18
- * Cumulative Layout Shift (CLS)
19
- * https://web.dev/articles/cls
20
- *
21
- * Measures _unexpected_ layout shifts throughout the lifespan of a page load. User-initiated shifts, e.g. showing
22
- * a loading indicator after a user clicked a button that triggered a network request, are excluded since these are
23
- * expected.
24
- *
25
- * onCLS is always called when the page's visibility state changes to hidden and may be called multiple times for
26
- * a single page load.
27
- *
28
- * SPA Note: Since this is cumulative it could be misleading in a SPA, e.g. you might cross the threshold from
29
- * good -> bad on Page 3 but the largest contributor to your score might have occurred on Page 1
30
- */
31
- CLS: web_vitals_attribution.onCLS,
32
- /**
33
- * First Contentful Paint (FCP)
34
- * https://web.dev/articles/fcp
35
- *
36
- * Measures from first hard page load to when the first "content" (text, image, svg elements, etc.) is rendered
37
- *
38
- * Only measured once per page load
39
- */
40
- FCP: web_vitals_attribution.onFCP,
41
- /**
42
- * Largest Contentful Paint (LCP)
43
- * https://web.dev/articles/lcp
44
- *
45
- * Uses heuristics to try and measure when the "main" content has been rendered on the page. Size is a factor, but
46
- * certain elements that likely represent backgrounds or splash screens are excluded.
47
- *
48
- * As the page loads the element considered the largest could change, once the user interacts with the page these
49
- * entries stop getting reported and the metric is ready
50
- *
51
- * Only measured once per page load
52
- */
53
- LCP: web_vitals_attribution.onLCP,
54
- /**
55
- * Interaction to Next Paint (INP)
56
- * https://web.dev/articles/inp
57
- *
58
- * Measures how long it takes from a user interaction until the next paint. The final INP value is the longest
59
- * interaction observed, ignoring outliers.
60
- *
61
- * onINP is always called when the page's visibility state changes to hidden and may be called multiple times for
62
- * a single page load.
63
- *
64
- * Each interaction is not reported even when setting reportAllChanges=true, just when an interaction causes an
65
- * increase to INP.
66
- */
67
- INP: web_vitals_attribution.onINP,
68
- /**
69
- * Time to First Byte (TTFB)
70
- * https://web.dev/articles/ttfb
71
- *
72
- * Measures the time between the request for a resource and when the first byte of a response begins to arrive.
73
- */
74
- TTFB: web_vitals_attribution.onTTFB,
75
- FID: void 0
14
+ const loadWebVitalListeners = async () => {
15
+ const { onCLS, onFCP, onINP, onLCP, onTTFB } = await import("web-vitals/attribution");
16
+ return {
17
+ CLS: onCLS,
18
+ FCP: onFCP,
19
+ LCP: onLCP,
20
+ INP: onINP,
21
+ TTFB: onTTFB,
22
+ FID: void 0
23
+ };
76
24
  };
77
25
  //#endregion
78
26
  exports.ALL_WEB_VITALS = ALL_WEB_VITALS;
79
27
  exports.MAX_CLS_LAYOUT_SHIFTS = MAX_CLS_LAYOUT_SHIFTS;
80
28
  exports.MAX_LOAF_SCRIPT_ENTRIES = MAX_LOAF_SCRIPT_ENTRIES;
81
29
  exports.MAX_LOAF_SCRIPT_URL_LENGTH = MAX_LOAF_SCRIPT_URL_LENGTH;
82
- exports.WEB_VITALS_ID_TO_LISTENER = WEB_VITALS_ID_TO_LISTENER;
83
30
  exports.WEB_VITAL_EVENT_NAME = WEB_VITAL_EVENT_NAME;
31
+ exports.loadWebVitalListeners = loadWebVitalListeners;
84
32
 
85
33
  //# sourceMappingURL=constants.cjs.map