@newrelic/browser-agent 1.234.0 → 1.236.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/README.md +42 -2
  2. package/dist/cjs/common/config/state/init.js +3 -0
  3. package/dist/cjs/common/config/state/runtime.js +4 -4
  4. package/dist/cjs/common/constants/env.cdn.js +2 -2
  5. package/dist/cjs/common/constants/env.npm.js +1 -1
  6. package/dist/cjs/common/constants/runtime.js +52 -0
  7. package/dist/cjs/common/constants/shared-channel.js +19 -0
  8. package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
  9. package/dist/cjs/common/harvest/harvest-scheduler.js +35 -16
  10. package/dist/cjs/common/harvest/harvest.js +163 -144
  11. package/dist/cjs/common/harvest/types.js +54 -0
  12. package/dist/cjs/common/ids/id.js +2 -2
  13. package/dist/cjs/common/ids/unique-id.js +3 -3
  14. package/dist/cjs/common/session/session-entity.js +21 -13
  15. package/dist/cjs/common/timer/interaction-timer.js +3 -3
  16. package/dist/cjs/common/unload/eol.js +10 -11
  17. package/dist/cjs/common/url/canonicalize-url.js +2 -2
  18. package/dist/cjs/common/url/parse-url.js +3 -3
  19. package/dist/cjs/common/url/protocol.js +2 -2
  20. package/dist/cjs/common/util/feature-flags.js +23 -12
  21. package/dist/cjs/common/util/obfuscate.js +2 -2
  22. package/dist/cjs/common/util/submit-data.js +61 -79
  23. package/dist/cjs/common/window/nreum.js +14 -14
  24. package/dist/cjs/common/wrap/wrap-events.js +3 -3
  25. package/dist/cjs/common/wrap/wrap-fetch.js +5 -5
  26. package/dist/cjs/common/wrap/wrap-history.js +2 -2
  27. package/dist/cjs/common/wrap/wrap-jsonp.js +2 -2
  28. package/dist/cjs/common/wrap/wrap-mutation.js +2 -2
  29. package/dist/cjs/common/wrap/wrap-promise.js +2 -2
  30. package/dist/cjs/common/wrap/wrap-raf.js +3 -3
  31. package/dist/cjs/common/wrap/wrap-timer.js +5 -5
  32. package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
  33. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  34. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +2 -2
  35. package/dist/cjs/features/ajax/instrument/index.js +6 -7
  36. package/dist/cjs/features/jserrors/aggregate/index.js +11 -4
  37. package/dist/cjs/features/jserrors/instrument/index.js +6 -19
  38. package/dist/cjs/features/metrics/aggregate/framework-detection.js +2 -2
  39. package/dist/cjs/features/metrics/aggregate/index.js +3 -3
  40. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  41. package/dist/cjs/features/page_view_event/aggregate/index.js +10 -11
  42. package/dist/cjs/features/page_view_event/instrument/index.js +2 -2
  43. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -5
  44. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -2
  45. package/dist/cjs/features/session_replay/aggregate/index.js +99 -82
  46. package/dist/cjs/features/session_replay/replay-mode.js +28 -0
  47. package/dist/cjs/features/session_trace/aggregate/index.js +222 -99
  48. package/dist/cjs/features/session_trace/constants.js +1 -3
  49. package/dist/cjs/features/session_trace/instrument/index.js +2 -18
  50. package/dist/cjs/features/spa/aggregate/index.js +1 -1
  51. package/dist/cjs/features/spa/constants.js +0 -1
  52. package/dist/cjs/features/spa/instrument/index.js +2 -2
  53. package/dist/cjs/features/utils/agent-session.js +20 -36
  54. package/dist/cjs/features/utils/aggregate-base.js +7 -12
  55. package/dist/cjs/features/utils/handler-cache.js +28 -23
  56. package/dist/cjs/features/utils/instrument-base.js +58 -40
  57. package/dist/cjs/index.js +7 -0
  58. package/dist/cjs/loaders/agent.js +7 -1
  59. package/dist/cjs/loaders/api/api.js +2 -2
  60. package/dist/cjs/loaders/api/apiAsync.js +6 -4
  61. package/dist/cjs/loaders/configure/configure.js +2 -2
  62. package/dist/cjs/loaders/features/featureDependencies.js +2 -0
  63. package/dist/cjs/loaders/micro-agent.js +29 -38
  64. package/dist/esm/common/config/state/init.js +3 -0
  65. package/dist/esm/common/config/state/runtime.js +1 -1
  66. package/dist/esm/common/constants/env.cdn.js +2 -2
  67. package/dist/esm/common/constants/env.npm.js +1 -1
  68. package/dist/esm/common/constants/runtime.js +38 -0
  69. package/dist/esm/common/constants/shared-channel.js +12 -0
  70. package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
  71. package/dist/esm/common/harvest/harvest-scheduler.js +34 -17
  72. package/dist/esm/common/harvest/harvest.js +160 -142
  73. package/dist/esm/common/harvest/types.js +47 -0
  74. package/dist/esm/common/ids/id.js +1 -1
  75. package/dist/esm/common/ids/unique-id.js +1 -1
  76. package/dist/esm/common/session/session-entity.js +18 -12
  77. package/dist/esm/common/timer/interaction-timer.js +2 -2
  78. package/dist/esm/common/unload/eol.js +1 -2
  79. package/dist/esm/common/url/canonicalize-url.js +1 -1
  80. package/dist/esm/common/url/parse-url.js +1 -1
  81. package/dist/esm/common/url/protocol.js +1 -1
  82. package/dist/esm/common/util/feature-flags.js +23 -12
  83. package/dist/esm/common/util/obfuscate.js +2 -2
  84. package/dist/esm/common/util/submit-data.js +58 -76
  85. package/dist/esm/common/window/nreum.js +1 -1
  86. package/dist/esm/common/wrap/wrap-events.js +1 -1
  87. package/dist/esm/common/wrap/wrap-fetch.js +1 -1
  88. package/dist/esm/common/wrap/wrap-history.js +1 -1
  89. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  90. package/dist/esm/common/wrap/wrap-mutation.js +1 -1
  91. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  92. package/dist/esm/common/wrap/wrap-raf.js +2 -2
  93. package/dist/esm/common/wrap/wrap-timer.js +2 -2
  94. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  95. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  96. package/dist/esm/features/ajax/instrument/distributed-tracing.js +1 -1
  97. package/dist/esm/features/ajax/instrument/index.js +1 -2
  98. package/dist/esm/features/jserrors/aggregate/index.js +10 -3
  99. package/dist/esm/features/jserrors/instrument/index.js +3 -16
  100. package/dist/esm/features/metrics/aggregate/framework-detection.js +1 -1
  101. package/dist/esm/features/metrics/aggregate/index.js +1 -1
  102. package/dist/esm/features/page_action/aggregate/index.js +1 -1
  103. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  104. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -4
  106. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  107. package/dist/esm/features/session_replay/aggregate/index.js +92 -78
  108. package/dist/esm/features/session_replay/replay-mode.js +23 -0
  109. package/dist/esm/features/session_trace/aggregate/index.js +223 -100
  110. package/dist/esm/features/session_trace/constants.js +0 -1
  111. package/dist/esm/features/session_trace/instrument/index.js +2 -18
  112. package/dist/esm/features/spa/aggregate/index.js +1 -1
  113. package/dist/esm/features/spa/constants.js +0 -1
  114. package/dist/esm/features/spa/instrument/index.js +1 -1
  115. package/dist/esm/features/utils/agent-session.js +21 -37
  116. package/dist/esm/features/utils/aggregate-base.js +7 -12
  117. package/dist/esm/features/utils/handler-cache.js +28 -23
  118. package/dist/esm/features/utils/instrument-base.js +57 -39
  119. package/dist/esm/index.js +1 -4
  120. package/dist/esm/loaders/agent.js +7 -1
  121. package/dist/esm/loaders/api/api.js +2 -2
  122. package/dist/esm/loaders/api/apiAsync.js +3 -3
  123. package/dist/esm/loaders/configure/configure.js +1 -1
  124. package/dist/esm/loaders/features/featureDependencies.js +2 -0
  125. package/dist/esm/loaders/micro-agent.js +29 -38
  126. package/dist/types/common/config/state/init.d.ts.map +1 -1
  127. package/dist/types/common/constants/runtime.d.ts +29 -0
  128. package/dist/types/common/constants/runtime.d.ts.map +1 -0
  129. package/dist/types/common/constants/shared-channel.d.ts +5 -0
  130. package/dist/types/common/constants/shared-channel.d.ts.map +1 -0
  131. package/dist/types/common/harvest/harvest-scheduler.d.ts +5 -1
  132. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  133. package/dist/types/common/harvest/harvest.d.ts +49 -38
  134. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  135. package/dist/types/common/harvest/types.d.ts +100 -0
  136. package/dist/types/common/harvest/types.d.ts.map +1 -0
  137. package/dist/types/common/session/session-entity.d.ts +9 -5
  138. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  139. package/dist/types/common/unload/eol.d.ts.map +1 -1
  140. package/dist/types/common/util/feature-flags.d.ts +1 -0
  141. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  142. package/dist/types/common/util/submit-data.d.ts +62 -64
  143. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  144. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  145. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -1
  146. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  147. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  148. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  149. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  150. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  151. package/dist/types/features/session_replay/aggregate/index.d.ts +14 -5
  152. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  153. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  154. package/dist/types/features/session_replay/replay-mode.d.ts +9 -0
  155. package/dist/types/features/session_replay/replay-mode.d.ts.map +1 -0
  156. package/dist/types/features/session_trace/aggregate/index.d.ts +21 -3
  157. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  158. package/dist/types/features/session_trace/constants.d.ts +0 -1
  159. package/dist/types/features/session_trace/constants.d.ts.map +1 -1
  160. package/dist/types/features/session_trace/instrument/index.d.ts +0 -2
  161. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  162. package/dist/types/features/spa/constants.d.ts.map +1 -1
  163. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  164. package/dist/types/features/utils/aggregate-base.d.ts +6 -1
  165. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  166. package/dist/types/features/utils/handler-cache.d.ts +12 -11
  167. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  168. package/dist/types/features/utils/instrument-base.d.ts +17 -1
  169. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  170. package/dist/types/index.d.ts +1 -0
  171. package/dist/types/loaders/agent.d.ts +4 -4
  172. package/dist/types/loaders/agent.d.ts.map +1 -1
  173. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
  174. package/dist/types/loaders/micro-agent.d.ts +3 -4
  175. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  176. package/package.json +14 -7
  177. package/src/common/config/__mocks__/config.js +11 -0
  178. package/src/common/config/state/init.js +1 -0
  179. package/src/common/config/state/runtime.js +1 -1
  180. package/src/common/constants/__mocks__/env.js +3 -0
  181. package/src/common/constants/__mocks__/runtime.js +8 -0
  182. package/src/common/constants/env.cdn.test.js +7 -0
  183. package/src/common/constants/env.npm.test.js +7 -0
  184. package/src/common/constants/env.test.js +7 -0
  185. package/src/common/constants/runtime.js +71 -0
  186. package/src/common/constants/runtime.test.js +168 -0
  187. package/src/common/constants/shared-channel.js +13 -0
  188. package/src/common/context/__mocks__/shared-context.js +8 -0
  189. package/src/common/event-listener/__mocks__/event-listener-opts.js +7 -0
  190. package/src/common/event-listener/event-listener-opts.js +1 -1
  191. package/src/common/harvest/__mocks__/harvest.js +13 -0
  192. package/src/common/harvest/harvest-scheduler.js +31 -19
  193. package/src/common/harvest/harvest-scheduler.test.js +491 -20
  194. package/src/common/harvest/harvest.js +147 -130
  195. package/src/common/harvest/harvest.test.js +788 -139
  196. package/src/common/harvest/types.js +47 -0
  197. package/src/common/ids/id.js +1 -1
  198. package/src/common/ids/unique-id.js +1 -1
  199. package/src/common/session/__mocks__/session-entity.js +25 -0
  200. package/src/common/session/{session-entity.test.js → session-entity.component-test.js} +71 -48
  201. package/src/common/session/session-entity.js +16 -13
  202. package/src/common/timer/interaction-timer.js +2 -2
  203. package/src/common/timing/__mocks__/now.js +1 -0
  204. package/src/common/unload/__mocks__/eol.js +1 -0
  205. package/src/common/unload/eol.js +1 -2
  206. package/src/common/url/__mocks__/clean-url.js +1 -0
  207. package/src/common/url/__mocks__/encode.js +7 -0
  208. package/src/common/url/__mocks__/location.js +1 -0
  209. package/src/common/url/canonicalize-url.js +1 -1
  210. package/src/common/url/canonicalize-url.test.js +32 -21
  211. package/src/common/url/parse-url.js +1 -1
  212. package/src/common/url/parse-url.test.js +3 -3
  213. package/src/common/url/protocol.js +1 -1
  214. package/src/common/util/__mocks__/obfuscate.js +10 -0
  215. package/src/common/util/__mocks__/stringify.js +1 -0
  216. package/src/common/util/__mocks__/submit-data.js +6 -0
  217. package/src/common/util/__mocks__/traverse.js +1 -0
  218. package/src/common/util/data-size.test.js +27 -20
  219. package/src/common/util/feature-flags.js +24 -12
  220. package/src/common/util/feature-flags.test.js +98 -0
  221. package/src/common/util/obfuscate.component-test.js +173 -0
  222. package/src/common/util/obfuscate.js +2 -2
  223. package/src/common/util/submit-data.js +42 -56
  224. package/src/common/util/submit-data.test.js +158 -137
  225. package/src/common/window/nreum.js +1 -1
  226. package/src/common/wrap/wrap-events.js +1 -1
  227. package/src/common/wrap/wrap-fetch.js +1 -1
  228. package/src/common/wrap/wrap-history.js +1 -1
  229. package/src/common/wrap/wrap-jsonp.js +1 -1
  230. package/src/common/wrap/wrap-mutation.js +1 -1
  231. package/src/common/wrap/wrap-promise.js +1 -1
  232. package/src/common/wrap/wrap-promise.test.js +2 -2
  233. package/src/common/wrap/wrap-raf.js +2 -2
  234. package/src/common/wrap/wrap-timer.js +2 -2
  235. package/src/common/wrap/wrap-xhr.js +1 -1
  236. package/src/features/ajax/aggregate/index.js +1 -1
  237. package/src/features/ajax/instrument/distributed-tracing.js +1 -1
  238. package/src/features/ajax/instrument/index.js +1 -2
  239. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  240. package/src/features/jserrors/aggregate/index.js +12 -3
  241. package/src/features/jserrors/instrument/index.js +3 -16
  242. package/src/features/metrics/aggregate/framework-detection.js +1 -1
  243. package/src/features/metrics/aggregate/framework-detection.test.js +2 -2
  244. package/src/features/metrics/aggregate/index.js +1 -1
  245. package/src/features/page_action/aggregate/index.js +1 -1
  246. package/src/features/page_view_event/aggregate/index.js +1 -2
  247. package/src/features/page_view_event/instrument/index.js +1 -1
  248. package/src/features/page_view_timing/aggregate/index.js +2 -4
  249. package/src/features/page_view_timing/instrument/index.js +1 -1
  250. package/src/features/session_replay/aggregate/index.component-test.js +368 -0
  251. package/src/features/session_replay/aggregate/index.js +96 -71
  252. package/src/features/session_replay/instrument/index.js +0 -1
  253. package/src/features/session_replay/replay-mode.js +23 -0
  254. package/src/features/session_trace/aggregate/index.js +198 -79
  255. package/src/features/session_trace/constants.js +0 -1
  256. package/src/features/session_trace/instrument/index.js +3 -20
  257. package/src/features/spa/aggregate/index.js +1 -1
  258. package/src/features/spa/constants.js +0 -1
  259. package/src/features/spa/instrument/index.js +1 -1
  260. package/src/features/utils/agent-session.js +22 -34
  261. package/src/features/utils/agent-session.test.js +194 -0
  262. package/src/features/utils/aggregate-base.js +12 -9
  263. package/src/features/utils/aggregate-base.test.js +122 -0
  264. package/src/features/utils/feature-base.test.js +45 -0
  265. package/src/features/utils/handler-cache.js +29 -23
  266. package/src/features/utils/handler-cache.test.js +72 -0
  267. package/src/features/utils/instrument-base.js +45 -29
  268. package/src/features/utils/instrument-base.test.js +209 -0
  269. package/src/features/utils/lazy-feature-loader.test.js +37 -0
  270. package/src/index.js +1 -3
  271. package/src/loaders/agent.js +8 -1
  272. package/src/loaders/api/api.js +2 -2
  273. package/src/loaders/api/apiAsync.js +3 -3
  274. package/src/loaders/configure/configure.js +1 -1
  275. package/src/loaders/features/featureDependencies.js +2 -0
  276. package/src/loaders/micro-agent.js +26 -30
  277. package/dist/cjs/common/browser-version/firefox-version.js +0 -17
  278. package/dist/cjs/common/browser-version/ios-version.js +0 -19
  279. package/dist/cjs/common/event-emitter/contextual-ee.test.js +0 -282
  280. package/dist/cjs/common/event-emitter/handle.test.js +0 -58
  281. package/dist/cjs/common/event-emitter/register-handler.test.js +0 -55
  282. package/dist/cjs/common/harvest/harvest-scheduler.test.js +0 -39
  283. package/dist/cjs/common/harvest/harvest.test.js +0 -224
  284. package/dist/cjs/common/ids/id.test.js +0 -85
  285. package/dist/cjs/common/ids/unique-id.test.js +0 -49
  286. package/dist/cjs/common/session/session-entity.test.js +0 -460
  287. package/dist/cjs/common/storage/local-memory.js +0 -35
  288. package/dist/cjs/common/storage/local-memory.test.js +0 -20
  289. package/dist/cjs/common/storage/local-storage.test.js +0 -14
  290. package/dist/cjs/common/timer/interaction-timer.test.js +0 -216
  291. package/dist/cjs/common/timer/timer.test.js +0 -105
  292. package/dist/cjs/common/timing/nav-timing.test.js +0 -192
  293. package/dist/cjs/common/url/canonicalize-url.test.js +0 -42
  294. package/dist/cjs/common/url/clean-url.test.js +0 -9
  295. package/dist/cjs/common/url/encode.test.js +0 -74
  296. package/dist/cjs/common/url/location.test.js +0 -13
  297. package/dist/cjs/common/url/parse-url.test.js +0 -111
  298. package/dist/cjs/common/url/protocol.test.js +0 -15
  299. package/dist/cjs/common/util/console.test.js +0 -30
  300. package/dist/cjs/common/util/data-size.test.js +0 -47
  301. package/dist/cjs/common/util/get-or-set.test.js +0 -47
  302. package/dist/cjs/common/util/global-scope.js +0 -58
  303. package/dist/cjs/common/util/invoke.test.js +0 -49
  304. package/dist/cjs/common/util/map-own.test.js +0 -49
  305. package/dist/cjs/common/util/stringify.test.js +0 -48
  306. package/dist/cjs/common/util/submit-data.test.js +0 -221
  307. package/dist/cjs/common/util/traverse.test.js +0 -44
  308. package/dist/cjs/common/wrap/wrap-promise.test.js +0 -119
  309. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +0 -31
  310. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +0 -383
  311. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +0 -40
  312. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +0 -27
  313. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +0 -137
  314. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -17
  315. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +0 -165
  316. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
  317. package/dist/esm/common/browser-version/firefox-version.js +0 -10
  318. package/dist/esm/common/browser-version/ios-version.js +0 -11
  319. package/dist/esm/common/event-emitter/contextual-ee.test.js +0 -278
  320. package/dist/esm/common/event-emitter/handle.test.js +0 -54
  321. package/dist/esm/common/event-emitter/register-handler.test.js +0 -51
  322. package/dist/esm/common/harvest/harvest-scheduler.test.js +0 -37
  323. package/dist/esm/common/harvest/harvest.test.js +0 -222
  324. package/dist/esm/common/ids/id.test.js +0 -81
  325. package/dist/esm/common/ids/unique-id.test.js +0 -44
  326. package/dist/esm/common/session/session-entity.test.js +0 -458
  327. package/dist/esm/common/storage/local-memory.js +0 -28
  328. package/dist/esm/common/storage/local-memory.test.js +0 -18
  329. package/dist/esm/common/storage/local-storage.test.js +0 -12
  330. package/dist/esm/common/timer/interaction-timer.test.js +0 -214
  331. package/dist/esm/common/timer/timer.test.js +0 -103
  332. package/dist/esm/common/timing/nav-timing.test.js +0 -190
  333. package/dist/esm/common/url/canonicalize-url.test.js +0 -38
  334. package/dist/esm/common/url/clean-url.test.js +0 -7
  335. package/dist/esm/common/url/encode.test.js +0 -70
  336. package/dist/esm/common/url/location.test.js +0 -11
  337. package/dist/esm/common/url/parse-url.test.js +0 -107
  338. package/dist/esm/common/url/protocol.test.js +0 -13
  339. package/dist/esm/common/util/console.test.js +0 -28
  340. package/dist/esm/common/util/data-size.test.js +0 -45
  341. package/dist/esm/common/util/get-or-set.test.js +0 -45
  342. package/dist/esm/common/util/global-scope.js +0 -45
  343. package/dist/esm/common/util/invoke.test.js +0 -47
  344. package/dist/esm/common/util/map-own.test.js +0 -47
  345. package/dist/esm/common/util/stringify.test.js +0 -46
  346. package/dist/esm/common/util/submit-data.test.js +0 -219
  347. package/dist/esm/common/util/traverse.test.js +0 -42
  348. package/dist/esm/common/wrap/wrap-promise.test.js +0 -115
  349. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +0 -29
  350. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +0 -379
  351. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +0 -38
  352. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +0 -25
  353. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +0 -133
  354. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -15
  355. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  356. package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
  357. package/dist/types/common/browser-version/firefox-version.d.ts +0 -2
  358. package/dist/types/common/browser-version/firefox-version.d.ts.map +0 -1
  359. package/dist/types/common/browser-version/ios-version.d.ts +0 -3
  360. package/dist/types/common/browser-version/ios-version.d.ts.map +0 -1
  361. package/dist/types/common/storage/local-memory.d.ts +0 -8
  362. package/dist/types/common/storage/local-memory.d.ts.map +0 -1
  363. package/dist/types/common/util/global-scope.d.ts +0 -14
  364. package/dist/types/common/util/global-scope.d.ts.map +0 -1
  365. package/src/common/browser-version/firefox-version.js +0 -10
  366. package/src/common/browser-version/ios-version.js +0 -11
  367. package/src/common/storage/local-memory.js +0 -30
  368. package/src/common/storage/local-memory.test.js +0 -19
  369. package/src/common/util/global-scope.js +0 -49
  370. /package/src/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
  371. /package/src/common/url/{encode.test.js → encode.component-test.js} +0 -0
  372. /package/src/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
@@ -11,7 +11,7 @@ import './debug'
11
11
  import { InstrumentBase } from '../../utils/instrument-base'
12
12
  import { FEATURE_NAME, NR_ERR_PROP } from '../constants'
13
13
  import { FEATURE_NAMES } from '../../../loaders/features/features'
14
- import { globalScope } from '../../../common/util/global-scope'
14
+ import { globalScope } from '../../../common/constants/runtime'
15
15
  import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
16
16
  import { getRuntime } from '../../../common/config/config'
17
17
  import { stringify } from '../../../common/util/stringify'
@@ -38,7 +38,7 @@ export class Instrument extends InstrumentBase {
38
38
  return true
39
39
  })
40
40
  this.thrown = true
41
- notice(err, undefined, thisInstrument.ee)
41
+ handle('err', [err, now()], undefined, FEATURE_NAMES.jserrors, thisInstrument.ee)
42
42
  }
43
43
  })
44
44
  thisInstrument.ee.on('fn-end', function () {
@@ -89,7 +89,7 @@ export class Instrument extends InstrumentBase {
89
89
 
90
90
  try {
91
91
  if (this.skipNext) this.skipNext -= 1
92
- else notice(errorObj || new UncaughtException(message, filename, lineno), true, this.ee)
92
+ else handle('err', [errorObj || new UncaughtException(message, filename, lineno), now()], undefined, FEATURE_NAMES.jserrors, this.ee)
93
93
  } catch (e) {
94
94
  try {
95
95
  handle('ierr', [e, now(), true], undefined, FEATURE_NAMES.jserrors, this.ee)
@@ -113,19 +113,6 @@ function UncaughtException (message, filename, lineno) {
113
113
  this.line = lineno
114
114
  }
115
115
 
116
- /**
117
- * Adds a timestamp and emits the 'err' event, which the error aggregator listens for
118
- * @param {Error} err
119
- * @param {boolean} doNotStamp
120
- * @param {ContextualEE} ee
121
- */
122
- function notice (err, doNotStamp, ee) {
123
- // by default add timestamp, unless specifically told not to
124
- // this is to preserve existing behavior
125
- var time = (!doNotStamp) ? now() : null
126
- handle('err', [err, time], undefined, FEATURE_NAMES.jserrors, ee)
127
- }
128
-
129
116
  /**
130
117
  * Attempts to cast an unhandledPromiseRejection reason (reject(...)) to an Error object
131
118
  * @param {*} reason - The reason property from an unhandled promise rejection
@@ -1,4 +1,4 @@
1
- import { isBrowserScope } from '../../../common/util/global-scope'
1
+ import { isBrowserScope } from '../../../common/constants/runtime'
2
2
 
3
3
  const FRAMEWORKS = {
4
4
  REACT: 'React',
@@ -1,7 +1,7 @@
1
1
  import { faker } from '@faker-js/faker'
2
2
  import { getFrameworks } from './framework-detection'
3
3
 
4
- jest.mock('../../../common/util/global-scope', () => ({
4
+ jest.mock('../../../common/constants/runtime', () => ({
5
5
  isBrowserScope: true
6
6
  }))
7
7
 
@@ -13,7 +13,7 @@ test('framework detection should not happen in non-browser scope', async () => {
13
13
  global.React = {}
14
14
 
15
15
  jest.resetModules()
16
- jest.doMock('../../../common/util/global-scope', () => ({
16
+ jest.doMock('../../../common/constants/runtime', () => ({
17
17
  isBrowserScope: false
18
18
  }))
19
19
  const frameworkDetector = await import('./framework-detection')
@@ -10,7 +10,7 @@ import { getRules, validateRules } from '../../../common/util/obfuscate'
10
10
  import { VERSION } from '../../../common/constants/env'
11
11
  import { onDOMContentLoaded } from '../../../common/window/load'
12
12
  import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
13
- import { isBrowserScope } from '../../../common/util/global-scope'
13
+ import { isBrowserScope } from '../../../common/constants/runtime'
14
14
  import { AggregateBase } from '../../utils/aggregate-base'
15
15
  import { stringify } from '../../../common/util/stringify'
16
16
  import { endpointMap } from './endpoint-map'
@@ -11,7 +11,7 @@ import { cleanURL } from '../../../common/url/clean-url'
11
11
  import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
12
12
  import { FEATURE_NAME } from '../constants'
13
13
  import { drain } from '../../../common/drain/drain'
14
- import { isBrowserScope } from '../../../common/util/global-scope'
14
+ import { isBrowserScope } from '../../../common/constants/runtime'
15
15
  import { AggregateBase } from '../../utils/aggregate-base'
16
16
 
17
17
  export class Aggregate extends AggregateBase {
@@ -1,6 +1,6 @@
1
1
  import { handle } from '../../../common/event-emitter/handle'
2
2
  import { FEATURE_NAMES } from '../../../loaders/features/features'
3
- import { isiOS } from '../../../common/browser-version/ios-version'
3
+ import { isiOS, globalScope, isBrowserScope } from '../../../common/constants/runtime'
4
4
  import { onTTFB } from 'web-vitals'
5
5
  import { addPT, addPN } from '../../../common/timing/nav-timing'
6
6
  import { stringify } from '../../../common/util/stringify'
@@ -9,7 +9,6 @@ import { getConfigurationValue, getInfo, getRuntime } from '../../../common/conf
9
9
  import { Harvest } from '../../../common/harvest/harvest'
10
10
  import * as CONSTANTS from '../constants'
11
11
  import { getActivatedFeaturesFlags } from './initialized-features'
12
- import { globalScope, isBrowserScope } from '../../../common/util/global-scope'
13
12
  import { drain } from '../../../common/drain/drain'
14
13
  import { activateFeatures } from '../../../common/util/feature-flags'
15
14
  import { warn } from '../../../common/util/console'
@@ -1,5 +1,5 @@
1
1
  import { handle } from '../../../common/event-emitter/handle'
2
- import { isiOS } from '../../../common/browser-version/ios-version'
2
+ import { isiOS } from '../../../common/constants/runtime'
3
3
  import { InstrumentBase } from '../../utils/instrument-base'
4
4
  import * as CONSTANTS from '../constants'
5
5
  import { FEATURE_NAMES } from '../../../loaders/features/features'
@@ -6,7 +6,7 @@
6
6
  import { onFCP, onFID, onLCP, onCLS, onINP } from 'web-vitals'
7
7
  import { onFirstPaint } from '../first-paint'
8
8
  import { onLongTask } from '../long-tasks'
9
- import { iOS_below16 } from '../../../common/browser-version/ios-version'
9
+ import { iOS_below16 } from '../../../common/constants/runtime'
10
10
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
11
11
  import { mapOwn } from '../../../common/util/map-own'
12
12
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
@@ -195,9 +195,7 @@ export class Aggregate extends AggregateBase {
195
195
 
196
196
  onHarvestFinished (result) {
197
197
  if (result.retry && this.timingsSent.length > 0) {
198
- for (var i = 0; i < this.timingsSent.length; i++) {
199
- this.timings.push(this.timingsSent[i])
200
- }
198
+ this.timings.unshift(...this.timingsSent)
201
199
  this.timingsSent = []
202
200
  }
203
201
  }
@@ -9,7 +9,7 @@ import { windowAddEventListener } from '../../../common/event-listener/event-lis
9
9
  import { now } from '../../../common/timing/now'
10
10
  import { InstrumentBase } from '../../utils/instrument-base'
11
11
  import { FEATURE_NAME } from '../constants'
12
- import { isBrowserScope } from '../../../common/util/global-scope'
12
+ import { isBrowserScope } from '../../../common/constants/runtime'
13
13
 
14
14
  export class Instrument extends InstrumentBase {
15
15
  static featureName = FEATURE_NAME
@@ -0,0 +1,368 @@
1
+ import { Aggregate as SessionReplayAgg, AVG_COMPRESSION, MAX_PAYLOAD_SIZE, IDEAL_PAYLOAD_SIZE } from '.'
2
+ import { Aggregator } from '../../../common/aggregate/aggregator'
3
+ import { SESSION_EVENTS, SessionEntity, MODE } from '../../../common/session/session-entity'
4
+ import { setConfiguration } from '../../../common/config/config'
5
+ import { configure } from '../../../loaders/configure/configure'
6
+
7
+ class LocalMemory {
8
+ constructor (initialState = {}) {
9
+ this.state = initialState
10
+ }
11
+
12
+ get (key) {
13
+ try {
14
+ return this.state[key]
15
+ } catch (err) {
16
+ return ''
17
+ }
18
+ }
19
+
20
+ set (key, value) {
21
+ try {
22
+ if (value === undefined || value === null) return this.remove(key)
23
+ this.state[key] = value
24
+ } catch (err) {
25
+ return
26
+ }
27
+ }
28
+
29
+ remove (key) {
30
+ try {
31
+ delete this.state[key]
32
+ } catch (err) {
33
+ return
34
+ }
35
+ }
36
+ }
37
+
38
+ let sr, session
39
+ const agentIdentifier = 'abcd'
40
+ const info = { licenseKey: 1234, applicationID: 9876 }
41
+ const init = { session_replay: { enabled: true, sampleRate: 1, errorSampleRate: 0 } }
42
+
43
+ describe('Session Replay', () => {
44
+ beforeEach(async () => {
45
+ primeSessionAndReplay()
46
+ })
47
+ afterEach(async () => {
48
+ sr.abort()
49
+ jest.clearAllMocks()
50
+ })
51
+
52
+ describe('Session Replay Session Behavior', () => {
53
+ test('When Session Ends', async () => {
54
+ const xhrMockClass = () => ({
55
+ open: jest.fn(),
56
+ send: jest.fn(),
57
+ setRequestHeader: jest.fn(),
58
+ addEventListener: jest.fn()
59
+ })
60
+ global.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
61
+
62
+ setConfiguration(agentIdentifier, { ...init })
63
+ sr.ee.emit('rumresp-sr', [true])
64
+ await wait(1)
65
+ expect(sr.initialized).toBeTruthy()
66
+ expect(sr.recording).toBeTruthy()
67
+ sr.ee.emit(SESSION_EVENTS.RESET)
68
+ expect(global.XMLHttpRequest).toHaveBeenCalled()
69
+ expect(sr.recording).toBeFalsy()
70
+ expect(sr.blocked).toBeTruthy()
71
+ })
72
+
73
+ test('When Session Is Paused/Resumed', async () => {
74
+ setConfiguration(agentIdentifier, { ...init })
75
+ sr.ee.emit('rumresp-sr', [true])
76
+ await wait(1)
77
+ expect(sr.initialized).toBeTruthy()
78
+ expect(sr.recording).toBeTruthy()
79
+ sr.ee.emit(SESSION_EVENTS.PAUSE)
80
+ expect(sr.recording).toBeFalsy()
81
+ sr.ee.emit(SESSION_EVENTS.RESUME)
82
+ expect(sr.recording).toBeTruthy()
83
+ })
84
+
85
+ test('Session SR mode matches SR mode -- FULL', async () => {
86
+ setConfiguration(agentIdentifier, { ...init })
87
+ sr.ee.emit('rumresp-sr', [true])
88
+ await wait(1)
89
+ expect(session.state.sessionReplay).toEqual(sr.mode)
90
+ })
91
+
92
+ test('Session SR mode matches SR mode -- ERROR', async () => {
93
+ setConfiguration(agentIdentifier, { session_replay: { sampleRate: 0, errorSampleRate: 1 } })
94
+ sr.ee.emit('rumresp-sr', [true])
95
+ await wait(1)
96
+ expect(session.state.sessionReplay).toEqual(sr.mode)
97
+ return
98
+ })
99
+
100
+ test('Session SR mode matches SR mode -- OFF', async () => {
101
+ setConfiguration(agentIdentifier, { session_replay: { sampleRate: 0, errorSampleRate: 0 } })
102
+ sr.ee.emit('rumresp-sr', [true])
103
+ await wait(1)
104
+ expect(session.state.sessionReplay).toEqual(sr.mode)
105
+ return
106
+ })
107
+ })
108
+
109
+ describe('Session Replay Initialization Behavior', () => {
110
+ test('Waits for SR', async () => {
111
+ setConfiguration(agentIdentifier, { ...init })
112
+ // do not emit sr flag
113
+ await wait(1000)
114
+ expect(sr.initialized).toEqual(false)
115
+ expect(sr.recording).toEqual(false)
116
+
117
+ // emit a false flag
118
+ sr.ee.emit('rumresp-sr', [false])
119
+ await wait(1)
120
+ expect(sr.initialized).toEqual(true)
121
+ expect(sr.recording).toEqual(false)
122
+ return
123
+ })
124
+
125
+ test('Does not run if cookies_enabled is false', async () => {
126
+ setConfiguration(agentIdentifier, { ...init, privacy: { cookies_enabled: false } })
127
+ sr = new SessionReplayAgg(agentIdentifier, new Aggregator({}))
128
+ sr.ee.emit('rumresp-sr', [true])
129
+ await wait(1)
130
+ expect(sr.initialized).toEqual(false)
131
+ expect(sr.recording).toEqual(false)
132
+ return
133
+ })
134
+
135
+ test('Does not run if session_trace is disabled', async () => {
136
+ setConfiguration(agentIdentifier, { ...init, session_trace: { enabled: false } })
137
+ sr = new SessionReplayAgg(agentIdentifier, new Aggregator({}))
138
+ sr.ee.emit('rumresp-sr', [true])
139
+ await wait(1)
140
+ expect(sr.initialized).toEqual(false)
141
+ expect(sr.recording).toEqual(false)
142
+ return
143
+ })
144
+ })
145
+
146
+ describe('Session Replay Sample -> Mode Behaviors', () => {
147
+ test('New Session -- Full 1 Error 1 === FULL', async () => {
148
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 1, sampleRate: 1 } })
149
+ sr.ee.emit('rumresp-sr', [true])
150
+ await wait(1)
151
+ expect(sr.mode).toEqual(MODE.FULL)
152
+ return
153
+ })
154
+
155
+ test('New Session -- Full 1 Error 0 === FULL', async () => {
156
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 0, sampleRate: 1 } })
157
+ sr.ee.emit('rumresp-sr', [true])
158
+ await wait(1)
159
+ expect(sr.mode).toEqual(MODE.FULL)
160
+ return
161
+ })
162
+
163
+ test('New Session -- Full 0 Error 1 === ERROR', async () => {
164
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 1, sampleRate: 0 } })
165
+ sr.ee.emit('rumresp-sr', [true])
166
+ await wait(1)
167
+ expect(sr.mode).toEqual(MODE.ERROR)
168
+ return
169
+ })
170
+
171
+ test('New Session -- Full 0 Error 0 === OFF', async () => {
172
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 0, sampleRate: 0 } })
173
+ sr.ee.emit('rumresp-sr', [true])
174
+ await wait(1)
175
+ expect(sr.mode).toEqual(MODE.OFF)
176
+ return
177
+ })
178
+
179
+ test('Existing Session -- Should inherit mode from session entity and ignore samples', async () => {
180
+ const storage = new LocalMemory({ NRBA_SESSION: { value: 'abcdefghijklmnop', expiresAt: Date.now() + 10000, inactiveAt: Date.now() + 10000, updatedAt: Date.now(), sessionReplay: MODE.FULL, sessionTraceMode: MODE.FULL, custom: {} } })
181
+ session = new SessionEntity({ agentIdentifier, key: 'SESSION', storage })
182
+ expect(session.isNew).toBeFalsy()
183
+ primeSessionAndReplay(session)
184
+ // configure to get "error" sample ---> but should inherit FULL from session manager
185
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 1, sampleRate: 0 } })
186
+ sr.ee.emit('rumresp-sr', [true])
187
+ await wait(1)
188
+ expect(sr.mode).toEqual(MODE.FULL)
189
+ return
190
+ })
191
+ })
192
+
193
+ describe('Session Replay Error Mode Behaviors', () => {
194
+ test('An error BEFORE rrweb import starts running in FULL from beginning', async () => {
195
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 1, sampleRate: 0 } })
196
+ sr.ee.emit('errorAgg')
197
+ sr.ee.emit('rumresp-sr', [true])
198
+ await wait(1)
199
+ expect(sr.mode).toEqual(MODE.FULL)
200
+ expect(sr.scheduler.started).toEqual(true)
201
+ return
202
+ })
203
+
204
+ test('An error AFTER rrweb import changes mode and starts harvester', async () => {
205
+ setConfiguration(agentIdentifier, { session_replay: { errorSampleRate: 1, sampleRate: 0 } })
206
+ sr.ee.emit('rumresp-sr', [true])
207
+ await wait(1)
208
+ expect(sr.mode).toEqual(MODE.ERROR)
209
+ expect(sr.scheduler.started).toEqual(false)
210
+ sr.ee.emit('errorAgg')
211
+ expect(sr.mode).toEqual(MODE.FULL)
212
+ expect(sr.scheduler.started).toEqual(true)
213
+ return
214
+ })
215
+ })
216
+
217
+ describe('Session Replay Payload Validation', () => {
218
+ test('Payload', async () => {
219
+ setConfiguration(agentIdentifier, { ...init })
220
+ sr.ee.emit('rumresp-sr', [true])
221
+ await wait(1)
222
+ const harvestContents = sr.getHarvestContents()
223
+ // query attrs
224
+ expect(harvestContents.qs).toMatchObject({
225
+ protocol_version: '0',
226
+ content_encoding: 'gzip',
227
+ browser_monitoring_key: info.licenseKey
228
+ })
229
+
230
+ expect(harvestContents.body).toMatchObject({
231
+ type: 'SessionReplay',
232
+ appId: info.applicationID,
233
+ timestamp: expect.any(Number),
234
+ blob: expect.any(String),
235
+ attributes: {
236
+ session: session.state.value,
237
+ hasSnapshot: expect.any(Boolean),
238
+ hasError: expect.any(Boolean),
239
+ agentVersion: expect.any(String),
240
+ isFirstChunk: expect.any(Boolean),
241
+ 'nr.rrweb.version': expect.any(String)
242
+ }
243
+ })
244
+
245
+ expect(JSON.parse(harvestContents.body.blob).length).toBeGreaterThan(0)
246
+ })
247
+ })
248
+
249
+ describe('Session Replay Harvest Behaviors', () => {
250
+ test('Compressed payload is provided to harvester', async () => {
251
+ const { gunzipSync, strFromU8 } = await import('fflate')
252
+ setConfiguration(agentIdentifier, { ...init })
253
+ sr.ee.emit('rumresp-sr', [true])
254
+ await wait(1)
255
+ const [harvestContents] = sr.prepareHarvest()
256
+ expect(harvestContents.qs).toMatchObject({
257
+ protocol_version: '0',
258
+ content_encoding: 'gzip',
259
+ browser_monitoring_key: info.licenseKey
260
+ })
261
+ expect(harvestContents.body).toEqual(expect.any(Uint8Array))
262
+ expect(JSON.parse(strFromU8(gunzipSync(harvestContents.body)))).toMatchObject({
263
+ type: 'SessionReplay',
264
+ appId: info.applicationID,
265
+ timestamp: expect.any(Number),
266
+ blob: expect.any(String),
267
+ attributes: {
268
+ session: session.state.value,
269
+ hasSnapshot: expect.any(Boolean),
270
+ hasError: expect.any(Boolean),
271
+ agentVersion: expect.any(String),
272
+ isFirstChunk: expect.any(Boolean),
273
+ 'nr.rrweb.version': expect.any(String)
274
+ }
275
+ })
276
+ })
277
+
278
+ test('Uncompressed payload is provided to harvester', async () => {
279
+ jest.doMock('fflate', () => ({
280
+ __esModule: true,
281
+ gzipSync: jest.fn().mockImplementation(() => { throw new Error() })
282
+ }))
283
+
284
+ setConfiguration(agentIdentifier, { ...init })
285
+ sr.shouldCompress = false
286
+ sr.ee.emit('rumresp-sr', [true])
287
+ await wait(1)
288
+
289
+ const [harvestContents] = sr.prepareHarvest()
290
+ expect(harvestContents.qs).toMatchObject({
291
+ protocol_version: '0',
292
+ // content_encoding is omitted when the payload is not compressed
293
+ browser_monitoring_key: info.licenseKey
294
+ })
295
+ expect(harvestContents.qs.content_encoding).toBeUndefined()
296
+ expect(harvestContents.body).toMatchObject({
297
+ type: 'SessionReplay',
298
+ appId: info.applicationID,
299
+ timestamp: expect.any(Number),
300
+ blob: expect.any(String),
301
+ attributes: {
302
+ session: session.state.value,
303
+ hasSnapshot: expect.any(Boolean),
304
+ hasError: expect.any(Boolean),
305
+ agentVersion: expect.any(String),
306
+ isFirstChunk: expect.any(Boolean),
307
+ 'nr.rrweb.version': expect.any(String)
308
+ }
309
+ })
310
+ })
311
+
312
+ test('Clears the event buffer when staged for harvesting', async () => {
313
+ setConfiguration(agentIdentifier, { ...init })
314
+ sr.shouldCompress = false
315
+ sr.ee.emit('rumresp-sr', [true])
316
+ await wait(1)
317
+
318
+ sr.prepareHarvest()
319
+ expect(sr.events.length).toEqual(0)
320
+ })
321
+
322
+ test('Harvests early if exceeds limit', async () => {
323
+ let after = 0
324
+ const spy = jest.spyOn(sr.scheduler, 'runHarvest').mockImplementation(() => { after = Date.now() })
325
+ setConfiguration(agentIdentifier, { ...init })
326
+ sr.payloadBytesEstimation = IDEAL_PAYLOAD_SIZE / AVG_COMPRESSION
327
+ const before = Date.now()
328
+ sr.ee.emit('rumresp-sr', [true])
329
+ await wait(1)
330
+ expect(spy).toHaveBeenCalled()
331
+ expect(after - before).toBeLessThan(sr.harvestTimeSeconds * 1000)
332
+ })
333
+
334
+ test('Aborts if exceeds total limit', async () => {
335
+ const spy = jest.spyOn(sr.scheduler, 'runHarvest')
336
+ setConfiguration(agentIdentifier, { ...init })
337
+ sr.payloadBytesEstimation = (MAX_PAYLOAD_SIZE + 1) / AVG_COMPRESSION
338
+ const before = Date.now()
339
+ sr.ee.emit('rumresp-sr', [true])
340
+ await wait(1)
341
+ expect(spy).not.toHaveBeenCalled()
342
+ expect(sr.blocked).toEqual(true)
343
+ expect(sr.mode).toEqual(MODE.OFF)
344
+ })
345
+
346
+ test('Aborts if 429 response', async () => {
347
+ setConfiguration(agentIdentifier, { ...init })
348
+ sr.ee.emit('rumresp-sr', [true])
349
+ await wait(1)
350
+ expect(sr.mode).toEqual(MODE.FULL)
351
+ sr.onHarvestFinished({ status: 429 })
352
+ expect(sr.blocked).toEqual(true)
353
+ expect(sr.mode).toEqual(MODE.OFF)
354
+ })
355
+ })
356
+ })
357
+
358
+ function wait (ms = 0) {
359
+ return new Promise((resolve) => {
360
+ setTimeout(resolve, ms)
361
+ })
362
+ }
363
+
364
+ function primeSessionAndReplay (sess = new SessionEntity({ agentIdentifier, key: 'SESSION', storage: new LocalMemory() })) {
365
+ session = sess
366
+ configure(agentIdentifier, { info, runtime: { session } }, 'test', true)
367
+ sr = new SessionReplayAgg(agentIdentifier, new Aggregator({}))
368
+ }