@newrelic/browser-agent 1.264.0 → 1.265.1

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 (406) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/cjs/common/aggregate/aggregator.js +1 -2
  3. package/dist/cjs/common/config/{state/configurable.js → configurable.js} +1 -1
  4. package/dist/cjs/common/config/{state/info.js → info.js} +1 -1
  5. package/dist/cjs/common/config/{state/init.js → init.js} +5 -5
  6. package/dist/cjs/common/config/{state/loader-config.js → loader-config.js} +1 -1
  7. package/dist/cjs/common/config/{state/runtime.js → runtime.js} +16 -5
  8. package/dist/cjs/common/constants/agent-constants.js +8 -0
  9. package/dist/cjs/common/constants/env.cdn.js +1 -1
  10. package/dist/cjs/common/constants/env.npm.js +1 -1
  11. package/dist/cjs/common/context/shared-context.js +1 -2
  12. package/dist/cjs/common/dispatch/global-event.js +1 -2
  13. package/dist/cjs/common/drain/drain.js +10 -16
  14. package/dist/cjs/common/event-emitter/contextual-ee.js +3 -4
  15. package/dist/cjs/common/event-listener/event-listener-opts.js +2 -6
  16. package/dist/cjs/common/harvest/harvest-scheduler.js +1 -2
  17. package/dist/cjs/common/harvest/harvest.js +29 -56
  18. package/dist/cjs/common/serialize/bel-serializer.js +6 -11
  19. package/dist/cjs/common/session/session-entity.js +9 -12
  20. package/dist/cjs/common/timing/nav-timing.js +1 -3
  21. package/dist/cjs/common/timing/time-keeper.js +16 -6
  22. package/dist/cjs/common/url/encode.js +2 -4
  23. package/dist/cjs/common/util/console.js +2 -0
  24. package/dist/cjs/common/util/invoke.js +6 -16
  25. package/dist/cjs/common/util/obfuscate.js +97 -53
  26. package/dist/cjs/common/util/submit-data.js +17 -20
  27. package/dist/cjs/common/util/text.js +9 -0
  28. package/dist/cjs/common/util/traverse.js +1 -3
  29. package/dist/cjs/common/vitals/cumulative-layout-shift.js +5 -6
  30. package/dist/cjs/common/vitals/first-contentful-paint.js +4 -5
  31. package/dist/cjs/common/vitals/first-input-delay.js +4 -5
  32. package/dist/cjs/common/vitals/interaction-to-next-paint.js +5 -6
  33. package/dist/cjs/common/vitals/largest-contentful-paint.js +4 -5
  34. package/dist/cjs/common/vitals/time-to-first-byte.js +4 -5
  35. package/dist/cjs/common/vitals/vital-metric.js +6 -8
  36. package/dist/cjs/common/window/nreum.js +2 -1
  37. package/dist/cjs/common/window/page-visibility.js +1 -4
  38. package/dist/cjs/common/wrap/wrap-events.js +1 -4
  39. package/dist/cjs/common/wrap/wrap-promise.js +1 -4
  40. package/dist/cjs/common/wrap/wrap-websocket.js +74 -0
  41. package/dist/cjs/features/ajax/aggregate/chunk.js +4 -3
  42. package/dist/cjs/features/ajax/aggregate/gql.js +4 -5
  43. package/dist/cjs/features/ajax/aggregate/index.js +20 -23
  44. package/dist/cjs/features/ajax/constants.js +2 -3
  45. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +9 -8
  46. package/dist/cjs/features/ajax/instrument/index.js +15 -13
  47. package/dist/cjs/features/generic_events/aggregate/index.js +49 -58
  48. package/dist/cjs/features/generic_events/constants.js +4 -2
  49. package/dist/cjs/features/generic_events/instrument/index.js +7 -7
  50. package/dist/cjs/features/jserrors/aggregate/index.js +24 -44
  51. package/dist/cjs/features/jserrors/instrument/index.js +5 -5
  52. package/dist/cjs/features/logging/aggregate/index.js +34 -37
  53. package/dist/cjs/features/logging/constants.js +2 -3
  54. package/dist/cjs/features/logging/instrument/index.js +6 -7
  55. package/dist/cjs/features/logging/shared/log.js +1 -3
  56. package/dist/cjs/features/logging/shared/utils.js +2 -4
  57. package/dist/cjs/features/metrics/aggregate/index.js +37 -18
  58. package/dist/cjs/features/metrics/aggregate/websocket-detection.js +34 -0
  59. package/dist/cjs/features/metrics/constants.js +5 -1
  60. package/dist/cjs/features/metrics/instrument/index.js +16 -5
  61. package/dist/cjs/features/page_action/instrument/index.js +8 -4
  62. package/dist/cjs/features/page_view_event/aggregate/index.js +20 -40
  63. package/dist/cjs/features/page_view_event/instrument/index.js +5 -5
  64. package/dist/cjs/features/page_view_timing/aggregate/index.js +24 -40
  65. package/dist/cjs/features/page_view_timing/instrument/index.js +5 -5
  66. package/dist/cjs/features/session_replay/aggregate/index.js +37 -44
  67. package/dist/cjs/features/session_replay/constants.js +1 -5
  68. package/dist/cjs/features/session_replay/instrument/index.js +6 -10
  69. package/dist/cjs/features/session_replay/shared/recorder-events.js +25 -20
  70. package/dist/cjs/features/session_replay/shared/recorder.js +17 -13
  71. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +3 -3
  72. package/dist/cjs/features/session_replay/shared/utils.js +5 -4
  73. package/dist/cjs/features/session_trace/aggregate/index.js +26 -43
  74. package/dist/cjs/features/session_trace/aggregate/trace/storage.js +7 -5
  75. package/dist/cjs/features/session_trace/instrument/index.js +9 -8
  76. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +1 -1
  77. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +1 -1
  78. package/dist/cjs/features/soft_navigations/aggregate/index.js +23 -31
  79. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +2 -2
  80. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +9 -10
  81. package/dist/cjs/features/soft_navigations/instrument/index.js +15 -14
  82. package/dist/cjs/features/spa/aggregate/index.js +17 -27
  83. package/dist/cjs/features/spa/aggregate/interaction.js +7 -6
  84. package/dist/cjs/features/spa/aggregate/serializer.js +3 -3
  85. package/dist/cjs/features/spa/constants.js +2 -2
  86. package/dist/cjs/features/spa/instrument/index.js +21 -20
  87. package/dist/cjs/features/utils/agent-session.js +6 -4
  88. package/dist/cjs/features/utils/aggregate-base.js +15 -10
  89. package/dist/cjs/features/utils/event-buffer.js +132 -0
  90. package/dist/cjs/features/utils/feature-gates.js +2 -2
  91. package/dist/cjs/features/utils/instrument-base.js +7 -8
  92. package/dist/cjs/features/utils/lazy-feature-loader.js +11 -11
  93. package/dist/cjs/features/utils/nr1-debugger.js +1 -3
  94. package/dist/cjs/loaders/agent-base.js +4 -8
  95. package/dist/cjs/loaders/agent.js +7 -2
  96. package/dist/cjs/loaders/api/api.js +22 -34
  97. package/dist/cjs/loaders/api/apiAsync.js +9 -12
  98. package/dist/cjs/loaders/configure/configure.js +12 -12
  99. package/dist/cjs/loaders/features/enabled-features.js +2 -2
  100. package/dist/cjs/loaders/micro-agent.js +15 -14
  101. package/dist/esm/common/aggregate/aggregator.js +1 -2
  102. package/dist/esm/common/config/{state/configurable.js → configurable.js} +1 -1
  103. package/dist/esm/common/config/{state/info.js → info.js} +1 -1
  104. package/dist/esm/common/config/{state/init.js → init.js} +5 -5
  105. package/dist/esm/common/config/{state/loader-config.js → loader-config.js} +1 -1
  106. package/dist/esm/common/config/{state/runtime.js → runtime.js} +17 -5
  107. package/dist/esm/common/constants/agent-constants.js +2 -0
  108. package/dist/esm/common/constants/env.cdn.js +1 -1
  109. package/dist/esm/common/constants/env.npm.js +1 -1
  110. package/dist/esm/common/context/shared-context.js +1 -2
  111. package/dist/esm/common/dispatch/global-event.js +1 -2
  112. package/dist/esm/common/drain/drain.js +10 -16
  113. package/dist/esm/common/event-emitter/contextual-ee.js +2 -3
  114. package/dist/esm/common/event-listener/event-listener-opts.js +2 -6
  115. package/dist/esm/common/harvest/harvest-scheduler.js +1 -2
  116. package/dist/esm/common/harvest/harvest.js +21 -48
  117. package/dist/esm/common/serialize/bel-serializer.js +6 -11
  118. package/dist/esm/common/session/session-entity.js +8 -11
  119. package/dist/esm/common/timing/nav-timing.js +1 -3
  120. package/dist/esm/common/timing/time-keeper.js +15 -5
  121. package/dist/esm/common/url/encode.js +2 -4
  122. package/dist/esm/common/util/console.js +2 -0
  123. package/dist/esm/common/util/invoke.js +6 -16
  124. package/dist/esm/common/util/obfuscate.js +96 -49
  125. package/dist/esm/common/util/submit-data.js +17 -20
  126. package/dist/esm/common/util/text.js +3 -0
  127. package/dist/esm/common/util/traverse.js +1 -3
  128. package/dist/esm/common/vitals/cumulative-layout-shift.js +5 -6
  129. package/dist/esm/common/vitals/first-contentful-paint.js +4 -5
  130. package/dist/esm/common/vitals/first-input-delay.js +4 -5
  131. package/dist/esm/common/vitals/interaction-to-next-paint.js +5 -6
  132. package/dist/esm/common/vitals/largest-contentful-paint.js +4 -5
  133. package/dist/esm/common/vitals/time-to-first-byte.js +4 -5
  134. package/dist/esm/common/vitals/vital-metric.js +6 -8
  135. package/dist/esm/common/window/nreum.js +2 -1
  136. package/dist/esm/common/window/page-visibility.js +1 -4
  137. package/dist/esm/common/wrap/wrap-events.js +1 -4
  138. package/dist/esm/common/wrap/wrap-promise.js +1 -4
  139. package/dist/esm/common/wrap/wrap-websocket.js +67 -0
  140. package/dist/esm/features/ajax/aggregate/chunk.js +3 -2
  141. package/dist/esm/features/ajax/aggregate/gql.js +4 -5
  142. package/dist/esm/features/ajax/aggregate/index.js +17 -20
  143. package/dist/esm/features/ajax/constants.js +1 -2
  144. package/dist/esm/features/ajax/instrument/distributed-tracing.js +2 -1
  145. package/dist/esm/features/ajax/instrument/index.js +11 -9
  146. package/dist/esm/features/generic_events/aggregate/index.js +41 -50
  147. package/dist/esm/features/generic_events/constants.js +3 -1
  148. package/dist/esm/features/generic_events/instrument/index.js +5 -5
  149. package/dist/esm/features/jserrors/aggregate/index.js +19 -39
  150. package/dist/esm/features/jserrors/instrument/index.js +4 -4
  151. package/dist/esm/features/logging/aggregate/index.js +32 -35
  152. package/dist/esm/features/logging/constants.js +1 -2
  153. package/dist/esm/features/logging/instrument/index.js +5 -6
  154. package/dist/esm/features/logging/shared/log.js +1 -3
  155. package/dist/esm/features/logging/shared/utils.js +2 -4
  156. package/dist/esm/features/metrics/aggregate/index.js +31 -12
  157. package/dist/esm/features/metrics/aggregate/websocket-detection.js +29 -0
  158. package/dist/esm/features/metrics/constants.js +4 -1
  159. package/dist/esm/features/metrics/instrument/index.js +15 -5
  160. package/dist/esm/features/page_action/instrument/index.js +7 -3
  161. package/dist/esm/features/page_view_event/aggregate/index.js +18 -38
  162. package/dist/esm/features/page_view_event/instrument/index.js +4 -4
  163. package/dist/esm/features/page_view_timing/aggregate/index.js +21 -37
  164. package/dist/esm/features/page_view_timing/instrument/index.js +4 -4
  165. package/dist/esm/features/session_replay/aggregate/index.js +27 -34
  166. package/dist/esm/features/session_replay/constants.js +0 -4
  167. package/dist/esm/features/session_replay/index.js +1 -7
  168. package/dist/esm/features/session_replay/instrument/index.js +6 -9
  169. package/dist/esm/features/session_replay/shared/recorder-events.js +25 -20
  170. package/dist/esm/features/session_replay/shared/recorder.js +14 -10
  171. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +3 -3
  172. package/dist/esm/features/session_replay/shared/utils.js +3 -2
  173. package/dist/esm/features/session_trace/aggregate/index.js +21 -38
  174. package/dist/esm/features/session_trace/aggregate/trace/storage.js +7 -5
  175. package/dist/esm/features/session_trace/instrument/index.js +6 -5
  176. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +1 -1
  177. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +1 -1
  178. package/dist/esm/features/soft_navigations/aggregate/index.js +22 -30
  179. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  180. package/dist/esm/features/soft_navigations/aggregate/interaction.js +7 -8
  181. package/dist/esm/features/soft_navigations/instrument/index.js +12 -11
  182. package/dist/esm/features/spa/aggregate/index.js +11 -21
  183. package/dist/esm/features/spa/aggregate/interaction.js +6 -5
  184. package/dist/esm/features/spa/aggregate/serializer.js +1 -1
  185. package/dist/esm/features/spa/constants.js +2 -2
  186. package/dist/esm/features/spa/instrument/index.js +13 -12
  187. package/dist/esm/features/utils/agent-session.js +3 -1
  188. package/dist/esm/features/utils/aggregate-base.js +13 -8
  189. package/dist/esm/features/utils/event-buffer.js +126 -0
  190. package/dist/esm/features/utils/feature-gates.js +1 -1
  191. package/dist/esm/features/utils/instrument-base.js +6 -7
  192. package/dist/esm/features/utils/lazy-feature-loader.js +11 -11
  193. package/dist/esm/features/utils/nr1-debugger.js +1 -3
  194. package/dist/esm/loaders/agent-base.js +4 -8
  195. package/dist/esm/loaders/agent.js +7 -2
  196. package/dist/esm/loaders/api/api.js +17 -29
  197. package/dist/esm/loaders/api/apiAsync.js +2 -5
  198. package/dist/esm/loaders/configure/configure.js +5 -5
  199. package/dist/esm/loaders/features/enabled-features.js +1 -1
  200. package/dist/esm/loaders/micro-agent.js +10 -9
  201. package/dist/types/common/config/configurable.d.ts.map +1 -0
  202. package/dist/types/common/config/info.d.ts.map +1 -0
  203. package/dist/types/common/config/init.d.ts.map +1 -0
  204. package/dist/types/common/config/loader-config.d.ts.map +1 -0
  205. package/dist/types/common/config/runtime.d.ts.map +1 -0
  206. package/dist/types/common/constants/agent-constants.d.ts +3 -0
  207. package/dist/types/common/constants/agent-constants.d.ts.map +1 -0
  208. package/dist/types/common/drain/drain.d.ts.map +1 -1
  209. package/dist/types/common/harvest/harvest.d.ts +1 -7
  210. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  211. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  212. package/dist/types/common/timing/time-keeper.d.ts +9 -2
  213. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  214. package/dist/types/common/util/console.d.ts.map +1 -1
  215. package/dist/types/common/util/obfuscate.d.ts +78 -6
  216. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  217. package/dist/types/common/util/text.d.ts +2 -0
  218. package/dist/types/common/util/text.d.ts.map +1 -0
  219. package/dist/types/common/window/nreum.d.ts.map +1 -1
  220. package/dist/types/common/wrap/wrap-websocket.d.ts +4 -0
  221. package/dist/types/common/wrap/wrap-websocket.d.ts.map +1 -0
  222. package/dist/types/features/ajax/aggregate/chunk.d.ts.map +1 -1
  223. package/dist/types/features/ajax/aggregate/index.d.ts +2 -3
  224. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  225. package/dist/types/features/ajax/constants.d.ts +0 -1
  226. package/dist/types/features/ajax/constants.d.ts.map +1 -1
  227. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
  228. package/dist/types/features/ajax/instrument/index.d.ts +1 -0
  229. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  230. package/dist/types/features/generic_events/aggregate/index.d.ts +6 -8
  231. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  232. package/dist/types/features/generic_events/constants.d.ts +2 -0
  233. package/dist/types/features/generic_events/constants.d.ts.map +1 -1
  234. package/dist/types/features/generic_events/instrument/index.d.ts +1 -0
  235. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  236. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
  237. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  238. package/dist/types/features/jserrors/instrument/index.d.ts +1 -0
  239. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  240. package/dist/types/features/logging/aggregate/index.d.ts +4 -7
  241. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  242. package/dist/types/features/logging/constants.d.ts +0 -1
  243. package/dist/types/features/logging/constants.d.ts.map +1 -1
  244. package/dist/types/features/logging/instrument/index.d.ts +1 -0
  245. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  246. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  247. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts +12 -0
  248. package/dist/types/features/metrics/aggregate/websocket-detection.d.ts.map +1 -0
  249. package/dist/types/features/metrics/constants.d.ts.map +1 -1
  250. package/dist/types/features/metrics/instrument/index.d.ts +1 -0
  251. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  252. package/dist/types/features/page_action/instrument/index.d.ts +4 -0
  253. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  254. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  255. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -0
  256. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  257. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -2
  258. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  259. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -0
  260. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  261. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  262. package/dist/types/features/session_replay/constants.d.ts +0 -4
  263. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  264. package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
  265. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  266. package/dist/types/features/session_replay/shared/recorder-events.d.ts +6 -6
  267. package/dist/types/features/session_replay/shared/recorder-events.d.ts.map +1 -1
  268. package/dist/types/features/session_replay/shared/recorder.d.ts +2 -2
  269. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  270. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
  271. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -2
  272. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  273. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts +1 -1
  274. package/dist/types/features/session_trace/aggregate/trace/storage.d.ts.map +1 -1
  275. package/dist/types/features/session_trace/instrument/index.d.ts +1 -0
  276. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  277. package/dist/types/features/soft_navigations/aggregate/index.d.ts +3 -3
  278. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  279. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -0
  280. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  281. package/dist/types/features/spa/aggregate/index.d.ts +2 -2
  282. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  283. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  284. package/dist/types/features/spa/constants.d.ts.map +1 -1
  285. package/dist/types/features/spa/instrument/index.d.ts +1 -0
  286. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  287. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  288. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  289. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  290. package/dist/types/features/utils/event-buffer.d.ts +72 -0
  291. package/dist/types/features/utils/event-buffer.d.ts.map +1 -0
  292. package/dist/types/features/utils/instrument-base.d.ts +1 -0
  293. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  294. package/dist/types/loaders/agent-base.d.ts +1 -1
  295. package/dist/types/loaders/agent.d.ts.map +1 -1
  296. package/dist/types/loaders/api/api.d.ts.map +1 -1
  297. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  298. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  299. package/package.json +55 -59
  300. package/src/common/config/__mocks__/info.js +3 -0
  301. package/src/common/config/__mocks__/init.js +3 -0
  302. package/src/common/config/__mocks__/loader-config.js +2 -0
  303. package/src/common/config/__mocks__/runtime.js +2 -0
  304. package/src/common/config/{state/configurable.js → configurable.js} +1 -1
  305. package/src/common/config/{state/info.js → info.js} +1 -1
  306. package/src/common/config/{state/init.js → init.js} +5 -5
  307. package/src/common/config/{state/loader-config.js → loader-config.js} +1 -1
  308. package/src/common/config/{state/runtime.js → runtime.js} +19 -5
  309. package/src/common/constants/agent-constants.js +2 -0
  310. package/src/common/drain/drain.js +5 -2
  311. package/src/common/event-emitter/contextual-ee.js +1 -1
  312. package/src/common/harvest/harvest.js +7 -21
  313. package/src/common/serialize/bel-serializer.js +5 -7
  314. package/src/common/session/session-entity.js +2 -2
  315. package/src/common/timing/__mocks__/time-keeper.js +6 -2
  316. package/src/common/timing/time-keeper.js +15 -5
  317. package/src/common/util/__mocks__/console.js +1 -0
  318. package/src/common/util/__mocks__/obfuscate.js +5 -8
  319. package/src/common/util/console.js +2 -0
  320. package/src/common/util/obfuscate.js +94 -50
  321. package/src/common/util/text.js +6 -0
  322. package/src/common/window/__mocks__/nreum.js +1 -1
  323. package/src/common/window/nreum.js +2 -1
  324. package/src/common/wrap/wrap-websocket.js +73 -0
  325. package/src/features/ajax/aggregate/chunk.js +3 -2
  326. package/src/features/ajax/aggregate/index.js +20 -19
  327. package/src/features/ajax/constants.js +0 -2
  328. package/src/features/ajax/instrument/distributed-tracing.js +2 -1
  329. package/src/features/ajax/instrument/index.js +9 -5
  330. package/src/features/generic_events/aggregate/index.js +43 -37
  331. package/src/features/generic_events/constants.js +2 -0
  332. package/src/features/generic_events/instrument/index.js +3 -1
  333. package/src/features/jserrors/aggregate/index.js +14 -4
  334. package/src/features/jserrors/instrument/index.js +2 -0
  335. package/src/features/logging/aggregate/index.js +39 -31
  336. package/src/features/logging/constants.js +0 -2
  337. package/src/features/logging/instrument/index.js +2 -0
  338. package/src/features/logging/shared/utils.js +1 -1
  339. package/src/features/metrics/aggregate/index.js +24 -9
  340. package/src/features/metrics/aggregate/websocket-detection.js +31 -0
  341. package/src/features/metrics/constants.js +3 -0
  342. package/src/features/metrics/instrument/index.js +13 -1
  343. package/src/features/page_action/instrument/index.js +5 -0
  344. package/src/features/page_view_event/aggregate/index.js +8 -23
  345. package/src/features/page_view_event/instrument/index.js +2 -0
  346. package/src/features/page_view_timing/aggregate/index.js +14 -16
  347. package/src/features/page_view_timing/instrument/index.js +2 -0
  348. package/src/features/session_replay/aggregate/index.js +13 -9
  349. package/src/features/session_replay/constants.js +0 -4
  350. package/src/features/session_replay/index.js +1 -7
  351. package/src/features/session_replay/instrument/index.js +3 -4
  352. package/src/features/session_replay/shared/recorder-events.js +27 -20
  353. package/src/features/session_replay/shared/recorder.js +13 -6
  354. package/src/features/session_replay/shared/stylesheet-evaluator.js +2 -2
  355. package/src/features/session_replay/shared/utils.js +3 -2
  356. package/src/features/session_trace/aggregate/index.js +16 -7
  357. package/src/features/session_trace/aggregate/trace/storage.js +6 -1
  358. package/src/features/session_trace/instrument/index.js +4 -1
  359. package/src/features/soft_navigations/aggregate/ajax-node.js +1 -1
  360. package/src/features/soft_navigations/aggregate/index.js +13 -15
  361. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  362. package/src/features/soft_navigations/aggregate/interaction.js +1 -1
  363. package/src/features/soft_navigations/instrument/index.js +9 -5
  364. package/src/features/spa/aggregate/index.js +11 -18
  365. package/src/features/spa/aggregate/interaction.js +5 -3
  366. package/src/features/spa/aggregate/serializer.js +1 -1
  367. package/src/features/spa/constants.js +2 -2
  368. package/src/features/spa/instrument/index.js +9 -3
  369. package/src/features/utils/agent-session.js +3 -1
  370. package/src/features/utils/aggregate-base.js +10 -2
  371. package/src/features/utils/event-buffer.js +126 -0
  372. package/src/features/utils/feature-gates.js +1 -1
  373. package/src/features/utils/instrument-base.js +2 -1
  374. package/src/loaders/agent-base.js +2 -2
  375. package/src/loaders/agent.js +7 -2
  376. package/src/loaders/api/api.js +2 -1
  377. package/src/loaders/api/apiAsync.js +1 -1
  378. package/src/loaders/configure/configure.js +4 -1
  379. package/src/loaders/features/enabled-features.js +1 -1
  380. package/src/loaders/micro-agent.js +4 -1
  381. package/dist/cjs/common/config/config.js +0 -76
  382. package/dist/cjs/common/config/state/originals.js +0 -8
  383. package/dist/cjs/common/wrap/index.js +0 -61
  384. package/dist/esm/common/config/config.js +0 -11
  385. package/dist/esm/common/config/state/originals.js +0 -2
  386. package/dist/esm/common/wrap/index.js +0 -13
  387. package/dist/types/common/config/config.d.ts +0 -13
  388. package/dist/types/common/config/config.d.ts.map +0 -1
  389. package/dist/types/common/config/state/configurable.d.ts.map +0 -1
  390. package/dist/types/common/config/state/info.d.ts.map +0 -1
  391. package/dist/types/common/config/state/init.d.ts.map +0 -1
  392. package/dist/types/common/config/state/loader-config.d.ts.map +0 -1
  393. package/dist/types/common/config/state/originals.d.ts +0 -2
  394. package/dist/types/common/config/state/originals.d.ts.map +0 -1
  395. package/dist/types/common/config/state/runtime.d.ts.map +0 -1
  396. package/dist/types/common/wrap/index.d.ts +0 -10
  397. package/dist/types/common/wrap/index.d.ts.map +0 -1
  398. package/src/common/config/__mocks__/config.js +0 -11
  399. package/src/common/config/config.js +0 -12
  400. package/src/common/config/state/originals.js +0 -3
  401. package/src/common/wrap/index.js +0 -16
  402. /package/dist/types/common/config/{state/configurable.d.ts → configurable.d.ts} +0 -0
  403. /package/dist/types/common/config/{state/info.d.ts → info.d.ts} +0 -0
  404. /package/dist/types/common/config/{state/init.d.ts → init.d.ts} +0 -0
  405. /package/dist/types/common/config/{state/loader-config.d.ts → loader-config.d.ts} +0 -0
  406. /package/dist/types/common/config/{state/runtime.d.ts → runtime.d.ts} +0 -0
@@ -5,11 +5,10 @@ import { initiallyHidden, isBrowserScope } from '../constants/runtime';
5
5
  import { cleanURL } from '../url/clean-url';
6
6
  export const largestContentfulPaint = new VitalMetric(VITAL_NAMES.LARGEST_CONTENTFUL_PAINT);
7
7
  if (isBrowserScope) {
8
- onLCP(_ref => {
9
- let {
10
- value,
11
- attribution
12
- } = _ref;
8
+ onLCP(({
9
+ value,
10
+ attribution
11
+ }) => {
13
12
  /* Largest Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
14
13
  if (initiallyHidden || largestContentfulPaint.isValid) return;
15
14
  let attrs;
@@ -12,11 +12,10 @@ export const timeToFirstByte = new VitalMetric(VITAL_NAMES.TIME_TO_FIRST_BYTE);
12
12
  * - cross-origin iframes specifically in firefox and safari
13
13
  */
14
14
  if (isBrowserScope && typeof PerformanceNavigationTiming !== 'undefined' && !isiOS && window === window.parent) {
15
- onTTFB(_ref => {
16
- let {
17
- value,
18
- attribution
19
- } = _ref;
15
+ onTTFB(({
16
+ value,
17
+ attribution
18
+ }) => {
20
19
  if (timeToFirstByte.isValid) return;
21
20
  timeToFirstByte.update({
22
21
  value,
@@ -1,16 +1,15 @@
1
1
  export class VitalMetric {
2
- #subscribers = (() => new Set())();
2
+ #subscribers = new Set();
3
3
  history = [];
4
4
  constructor(name, roundingMethod) {
5
5
  this.name = name;
6
6
  this.attrs = {};
7
7
  this.roundingMethod = typeof roundingMethod === 'function' ? roundingMethod : Math.floor;
8
8
  }
9
- update(_ref) {
10
- let {
11
- value,
12
- attrs = {}
13
- } = _ref;
9
+ update({
10
+ value,
11
+ attrs = {}
12
+ }) {
14
13
  if (value === undefined || value === null || value < 0) return;
15
14
  const state = {
16
15
  value: this.roundingMethod(value),
@@ -36,8 +35,7 @@ export class VitalMetric {
36
35
  get isValid() {
37
36
  return this.current.value >= 0;
38
37
  }
39
- subscribe(callback) {
40
- let buffered = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
38
+ subscribe(callback, buffered = true) {
41
39
  if (typeof callback !== 'function') return;
42
40
  this.#subscribers.add(callback);
43
41
  // emit full history on subscription ("buffered" behavior)
@@ -50,7 +50,8 @@ export function gosNREUMOriginals() {
50
50
  PR: globalScope.Promise,
51
51
  MO: globalScope.MutationObserver,
52
52
  // this'll be undefined if not in a web window
53
- FETCH: globalScope.fetch
53
+ FETCH: globalScope.fetch,
54
+ WS: globalScope.WebSocket
54
55
  };
55
56
  }
56
57
  return nr;
@@ -10,10 +10,7 @@ import { documentAddEventListener } from '../event-listener/event-listener-opts'
10
10
  * @param {boolean} [toHiddenOnly=false] - only execute the 'cb' when the vis is changing to the hidden state; no arg is passed to 'cb' if used
11
11
  * @returns void
12
12
  */
13
- export function subscribeToVisibilityChange(cb) {
14
- let toHiddenOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
15
- let capture = arguments.length > 2 ? arguments[2] : undefined;
16
- let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
13
+ export function subscribeToVisibilityChange(cb, toHiddenOnly = false, capture, abortSignal) {
17
14
  documentAddEventListener('visibilitychange', handleVisibilityChange, capture, abortSignal);
18
15
  function handleVisibilityChange() {
19
16
  if (toHiddenOnly) {
@@ -75,14 +75,11 @@ export function wrapEvents(sharedEE) {
75
75
  * @param {Function} cb - the function to run on the ancestral object once found, accepts an object as a arg
76
76
  * @param {Array} rest - [optional] any additional arguments to pass to the cb
77
77
  */
78
- function findEventListenerProtoAndCb(object, cb) {
78
+ function findEventListenerProtoAndCb(object, cb, ...rest) {
79
79
  let step = object;
80
80
  while (typeof step === 'object' && !Object.prototype.hasOwnProperty.call(step, ADD_EVENT_LISTENER)) {
81
81
  step = Object.getPrototypeOf(step);
82
82
  }
83
- for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
84
- rest[_key - 2] = arguments[_key];
85
- }
86
83
  if (step) cb(step, ...rest);
87
84
  }
88
85
 
@@ -104,13 +104,10 @@ export function wrapPromise(sharedEE) {
104
104
 
105
105
  // Note that this wrapping affects the same originals.PR (prototype) object.
106
106
  const prevPromiseOrigThen = prevPromiseObj.prototype.then;
107
- prevPromiseObj.prototype.then = function wrappedThen() {
107
+ prevPromiseObj.prototype.then = function wrappedThen(...args) {
108
108
  var originalThis = this;
109
109
  var ctx = getContext(originalThis);
110
110
  ctx.promise = originalThis;
111
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
112
- args[_key] = arguments[_key];
113
- }
114
111
  args[0] = promiseWrapper(args[0], 'cb-', ctx, null, false);
115
112
  args[1] = promiseWrapper(args[1], 'cb-', ctx, null, false);
116
113
  const origFnCallWithThis = prevPromiseOrigThen.apply(this, args);
@@ -0,0 +1,67 @@
1
+ import { globalScope } from '../constants/runtime';
2
+ import { now } from '../timing/now';
3
+ import { checkState } from '../window/load';
4
+ import { generateRandomHexString } from '../ids/unique-id';
5
+ import { gosNREUMOriginals } from '../window/nreum';
6
+ export const WEBSOCKET_TAG = 'websocket-';
7
+ export const ADD_EVENT_LISTENER_TAG = 'addEventListener';
8
+ const wrapped = {};
9
+ export function wrapWebSocket(sharedEE) {
10
+ if (wrapped[sharedEE.debugId]++) return sharedEE;
11
+ const originals = gosNREUMOriginals().o;
12
+ if (!originals.WS) return sharedEE;
13
+ function reporter(socketId) {
14
+ const createdAt = now();
15
+ return function (message, ...data) {
16
+ const timestamp = data[0]?.timeStamp || now();
17
+ const isLoaded = checkState();
18
+ sharedEE.emit(WEBSOCKET_TAG + message, [timestamp, timestamp - createdAt, isLoaded, socketId, ...data]);
19
+ };
20
+ }
21
+ Object.defineProperty(WrappedWebSocket, 'name', {
22
+ value: 'WebSocket'
23
+ });
24
+ function WrappedWebSocket() {
25
+ const ws = new originals.WS(...arguments);
26
+ const socketId = generateRandomHexString(6);
27
+ const report = reporter(socketId);
28
+ report('new');
29
+ const events = ['message', 'error', 'open', 'close'];
30
+ /** add event listeners */
31
+ events.forEach(evt => {
32
+ ws.addEventListener(evt, function (e) {
33
+ report(ADD_EVENT_LISTENER_TAG, {
34
+ eventType: evt,
35
+ event: e
36
+ });
37
+ });
38
+ })
39
+
40
+ /** could also observe the on-events for runtime processing, but not implemented yet */
41
+
42
+ /** observe the static method send, but noteably not close, as that is currently observed with the event listener */;
43
+ ['send'].forEach(wrapStaticProperty);
44
+ function wrapStaticProperty(prop) {
45
+ const originalProp = ws[prop];
46
+ if (originalProp) {
47
+ Object.defineProperty(proxiedProp, 'name', {
48
+ value: prop
49
+ });
50
+ function proxiedProp() {
51
+ report(prop, ...arguments);
52
+ try {
53
+ return originalProp.apply(this, arguments);
54
+ } catch (err) {
55
+ report(prop + '-err', ...arguments);
56
+ // rethrow error so we don't effect execution by observing.
57
+ throw err;
58
+ }
59
+ }
60
+ ws[prop] = proxiedProp;
61
+ }
62
+ }
63
+ return ws;
64
+ }
65
+ globalScope.WebSocket = WrappedWebSocket;
66
+ return sharedEE;
67
+ }
@@ -1,5 +1,6 @@
1
1
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer';
2
- import { getInfo } from '../../../common/config/config';
2
+ import { getInfo } from '../../../common/config/info';
3
+ import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants';
3
4
  export default class Chunk {
4
5
  constructor(events, aggregateInstance) {
5
6
  this.addString = getAddStringContext(aggregateInstance.agentIdentifier); // pass agentIdentifier here
@@ -38,6 +39,6 @@ export default class Chunk {
38
39
  if (i + 1 < events.length) insert += ';';
39
40
  this.payload += insert;
40
41
  }
41
- this.tooBig = this.payload.length * 2 > aggregateInstance.MAX_PAYLOAD_SIZE;
42
+ this.tooBig = this.payload.length * 2 > MAX_PAYLOAD_SIZE;
42
43
  }
43
44
  }
@@ -14,11 +14,10 @@ import { isPureObject } from '../../../common/util/type-check';
14
14
  * @param {string} query Ajax request query param string
15
15
  * @returns {GQLMetadata | undefined}
16
16
  */
17
- export function parseGQL() {
18
- let {
19
- body,
20
- query
21
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
+ export function parseGQL({
18
+ body,
19
+ query
20
+ } = {}) {
22
21
  if (!body && !query) return;
23
22
  try {
24
23
  const gqlBody = parseBatchGQL(parseGQLContents(body));
@@ -5,7 +5,9 @@
5
5
  import { registerHandler } from '../../../common/event-emitter/register-handler';
6
6
  import { stringify } from '../../../common/util/stringify';
7
7
  import { handle } from '../../../common/event-emitter/handle';
8
- import { getConfiguration, getInfo, getRuntime } from '../../../common/config/config';
8
+ import { getInfo } from '../../../common/config/info';
9
+ import { getConfiguration } from '../../../common/config/init';
10
+ import { getRuntime } from '../../../common/config/runtime';
9
11
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler';
10
12
  import { setDenyList, shouldCollectEvent } from '../../../common/deny-list/deny-list';
11
13
  import { FEATURE_NAME } from '../constants';
@@ -15,8 +17,9 @@ import { AggregateBase } from '../../utils/aggregate-base';
15
17
  import { parseGQL } from './gql';
16
18
  import { getNREUMInitializedAgent } from '../../../common/window/nreum';
17
19
  import Chunk from './chunk';
20
+ import { EventBuffer } from '../../utils/event-buffer';
18
21
  export class Aggregate extends AggregateBase {
19
- static featureName = (() => FEATURE_NAME)();
22
+ static featureName = FEATURE_NAME;
20
23
  #agentInfo;
21
24
  #agentRuntime;
22
25
  #agentInit;
@@ -26,25 +29,23 @@ export class Aggregate extends AggregateBase {
26
29
  this.#agentRuntime = getRuntime(agentIdentifier);
27
30
  this.#agentInit = getConfiguration(agentIdentifier);
28
31
  const harvestTimeSeconds = this.#agentInit.ajax.harvestTimeSeconds || 10;
29
- this.MAX_PAYLOAD_SIZE = this.#agentInit.ajax.maxPayloadSize || 1000000;
30
32
  setDenyList(this.#agentRuntime.denyList);
31
- this.ajaxEvents = [];
33
+ this.ajaxEvents = new EventBuffer();
32
34
  this.spaAjaxEvents = {};
33
- this.sentAjaxEvents = [];
34
35
  const classThis = this;
35
36
 
36
37
  // --- v Used by old spa feature
37
38
  this.ee.on('interactionDone', (interaction, wasSaved) => {
38
- if (!this.spaAjaxEvents[interaction.id]) return;
39
+ if (!this.spaAjaxEvents[interaction.id]?.hasData) return;
39
40
  if (!wasSaved) {
40
41
  // if the ixn was saved, then its ajax reqs are part of the payload whereas if it was discarded, it should still be harvested in the ajax feature itself
41
- this.spaAjaxEvents[interaction.id].forEach(item => this.ajaxEvents.push(item));
42
+ this.ajaxEvents.merge(this.spaAjaxEvents[interaction.id]);
42
43
  }
43
44
  delete this.spaAjaxEvents[interaction.id];
44
45
  });
45
46
  // --- ^
46
47
  // --- v Used by new soft nav
47
- registerHandler('returnAjax', event => this.ajaxEvents.push(event), this.featureName, this.ee);
48
+ registerHandler('returnAjax', event => this.ajaxEvents.add(event), this.featureName, this.ee);
48
49
  // --- ^
49
50
  registerHandler('xhr', function () {
50
51
  // the EE-drain system not only switches "this" but also passes a new EventContext with info. Should consider platform refactor to another system which passes a mutable context around separately and predictably to avoid problems like this.
@@ -104,7 +105,7 @@ export class Aggregate extends AggregateBase {
104
105
  if (ctx.dt) {
105
106
  event.spanId = ctx.dt.spanId;
106
107
  event.traceId = ctx.dt.traceId;
107
- event.spanTimestamp = this.#agentRuntime.timeKeeper.correctAbsoluteTimestamp(ctx.dt.timestamp);
108
+ event.spanTimestamp = Math.floor(this.#agentRuntime.timeKeeper.correctAbsoluteTimestamp(ctx.dt.timestamp));
108
109
  }
109
110
 
110
111
  // parsed from the AJAX body, looking for operationName param & parsing query for operationType
@@ -120,31 +121,27 @@ export class Aggregate extends AggregateBase {
120
121
  } else if (ctx.spaNode) {
121
122
  // For old spa (when running), if the ajax happened inside an interaction, hold it until the interaction finishes
122
123
  const interactionId = ctx.spaNode.interaction.id;
123
- this.spaAjaxEvents[interactionId] = this.spaAjaxEvents[interactionId] || [];
124
- this.spaAjaxEvents[interactionId].push(event);
124
+ this.spaAjaxEvents[interactionId] ??= new EventBuffer();
125
+ this.spaAjaxEvents[interactionId].add(event);
125
126
  } else {
126
- this.ajaxEvents.push(event);
127
+ this.ajaxEvents.add(event);
127
128
  }
128
129
  }
129
130
  prepareHarvest(options) {
130
131
  options = options || {};
131
- if (this.ajaxEvents.length === 0) return null;
132
- const payload = this.#getPayload(this.ajaxEvents);
132
+ if (this.ajaxEvents.buffer.length === 0) return null;
133
+ const payload = this.#getPayload(this.ajaxEvents.buffer);
133
134
  const payloadObjs = [];
134
135
  for (let i = 0; i < payload.length; i++) payloadObjs.push({
135
136
  body: {
136
137
  e: payload[i]
137
138
  }
138
139
  });
139
- if (options.retry) this.sentAjaxEvents = this.ajaxEvents;
140
- this.ajaxEvents = [];
140
+ if (options.retry) this.ajaxEvents.hold();else this.ajaxEvents.clear();
141
141
  return payloadObjs;
142
142
  }
143
143
  onEventsHarvestFinished(result) {
144
- if (result.retry && this.sentAjaxEvents.length > 0) {
145
- this.ajaxEvents.unshift(...this.sentAjaxEvents);
146
- this.sentAjaxEvents = [];
147
- }
144
+ if (result.retry && this.ajaxEvents.held.hasData) this.ajaxEvents.unhold();else this.ajaxEvents.held.clear();
148
145
  }
149
146
  #getPayload(events, numberOfChunks) {
150
147
  numberOfChunks = numberOfChunks || 1;
@@ -1,3 +1,2 @@
1
1
  import { FEATURE_NAMES } from '../../loaders/features/features';
2
- export const FEATURE_NAME = FEATURE_NAMES.ajax;
3
- export const MAX_PAYLOAD_SIZE = 1000000;
2
+ export const FEATURE_NAME = FEATURE_NAMES.ajax;
@@ -2,7 +2,8 @@
2
2
  * Copyright 2020 New Relic Corporation. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { getConfiguration, getConfigurationValue, getLoaderConfig } from '../../../common/config/config';
5
+ import { getConfiguration, getConfigurationValue } from '../../../common/config/init';
6
+ import { getLoaderConfig } from '../../../common/config/loader-config';
6
7
  import { generateSpanId, generateTraceId } from '../../../common/ids/unique-id';
7
8
  import { parseUrl } from '../../../common/url/parse-url';
8
9
  import { globalScope } from '../../../common/constants/runtime';
@@ -2,13 +2,15 @@
2
2
  * Copyright 2020 New Relic Corporation. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { originals, getLoaderConfig } from '../../../common/config/config';
5
+ import { gosNREUMOriginals } from '../../../common/window/nreum';
6
+ import { getLoaderConfig } from '../../../common/config/loader-config';
6
7
  import { handle } from '../../../common/event-emitter/handle';
7
8
  import { id } from '../../../common/ids/id';
8
9
  import { ffVersion, globalScope, isBrowserScope } from '../../../common/constants/runtime';
9
10
  import { dataSize } from '../../../common/util/data-size';
10
11
  import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts';
11
- import { wrapFetch, wrapXhr } from '../../../common/wrap';
12
+ import { wrapXhr } from '../../../common/wrap/wrap-xhr';
13
+ import { wrapFetch } from '../../../common/wrap/wrap-fetch';
12
14
  import { parseUrl } from '../../../common/url/parse-url';
13
15
  import { DT } from './distributed-tracing';
14
16
  import { responseSizeFromXhr } from './response-size';
@@ -20,12 +22,11 @@ import { now } from '../../../common/timing/now';
20
22
  import { hasUndefinedHostname } from '../../../common/deny-list/deny-list';
21
23
  var handlers = ['load', 'error', 'abort', 'timeout'];
22
24
  var handlersLen = handlers.length;
23
- var origRequest = originals.REQ;
24
- var origXHR = originals.XHR;
25
+ var origRequest = gosNREUMOriginals().o.REQ;
26
+ var origXHR = gosNREUMOriginals().o.XHR;
25
27
  export class Instrument extends InstrumentBase {
26
- static featureName = (() => FEATURE_NAME)();
27
- constructor(agentIdentifier, aggregator) {
28
- let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
28
+ static featureName = FEATURE_NAME;
29
+ constructor(agentIdentifier, aggregator, auto = true) {
29
30
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
30
31
  this.dt = new DT(agentIdentifier);
31
32
  this.handler = (type, args, ctx, group) => handle(type, args, ctx, group, this.ee);
@@ -339,7 +340,7 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
339
340
  if (hasUndefinedHostname(params)) return; // don't bother with XHR of url with no hostname
340
341
 
341
342
  metrics.duration = now() - this.startTime;
342
- if (!this.loadCaptureCalled && xhr.readyState === 4) {
343
+ if (!this.loadCazptureCalled && xhr.readyState === 4) {
343
344
  captureXhrData(this, xhr);
344
345
  } else if (params.status == null) {
345
346
  params.status = 0;
@@ -373,4 +374,5 @@ function addUrl(ctx, url) {
373
374
  params.pathname = parsed.pathname;
374
375
  ctx.parsedOrigin = parsed;
375
376
  ctx.sameOrigin = parsed.sameOrigin;
376
- }
377
+ }
378
+ export const Ajax = Instrument;
@@ -5,7 +5,9 @@
5
5
  import { stringify } from '../../../common/util/stringify';
6
6
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler';
7
7
  import { cleanURL } from '../../../common/url/clean-url';
8
- import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config';
8
+ import { getInfo } from '../../../common/config/info';
9
+ import { getConfigurationValue } from '../../../common/config/init';
10
+ import { getRuntime } from '../../../common/config/runtime';
9
11
  import { FEATURE_NAME } from '../constants';
10
12
  import { isBrowserScope } from '../../../common/constants/runtime';
11
13
  import { AggregateBase } from '../../utils/aggregate-base';
@@ -14,22 +16,20 @@ import { now } from '../../../common/timing/now';
14
16
  import { registerHandler } from '../../../common/event-emitter/register-handler';
15
17
  import { deregisterDrain } from '../../../common/drain/drain';
16
18
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants';
19
+ import { EventBuffer } from '../../utils/event-buffer';
20
+ import { applyFnToProps } from '../../../common/util/traverse';
21
+ import { IDEAL_PAYLOAD_SIZE } from '../../../common/constants/agent-constants';
17
22
  export class Aggregate extends AggregateBase {
18
23
  #agentRuntime;
19
- static featureName = (() => FEATURE_NAME)();
24
+ static featureName = FEATURE_NAME;
20
25
  constructor(agentIdentifier, aggregator) {
21
- var _this;
22
26
  super(agentIdentifier, aggregator, FEATURE_NAME);
23
- _this = this;
24
27
  this.eventsPerHarvest = 1000;
25
28
  this.harvestTimeSeconds = getConfigurationValue(this.agentIdentifier, 'generic_events.harvestTimeSeconds');
26
29
  this.referrerUrl = isBrowserScope && document.referrer ? cleanURL(document.referrer) : undefined;
27
- this.currentEvents = [];
28
- this.events = [];
29
- this.overflow = [];
30
+ this.events = new EventBuffer();
30
31
  this.#agentRuntime = getRuntime(this.agentIdentifier);
31
- this.waitForFlags(['ins']).then(_ref => {
32
- let [ins] = _ref;
32
+ this.waitForFlags(['ins']).then(([ins]) => {
33
33
  if (!ins) {
34
34
  this.blocked = true;
35
35
  deregisterDrain(this.agentIdentifier, this.featureName);
@@ -40,7 +40,7 @@ export class Aggregate extends AggregateBase {
40
40
  this.addEvent({
41
41
  ...attributes,
42
42
  eventType: 'PageAction',
43
- timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(timestamp),
43
+ timestamp: Math.floor(this.#agentRuntime.timeKeeper.correctAbsoluteTimestamp(this.#agentRuntime.timeKeeper.convertRelativeTimestamp(timestamp))),
44
44
  timeSinceLoad: timestamp / 1000,
45
45
  actionName: name,
46
46
  referrerUrl: this.referrerUrl,
@@ -53,47 +53,16 @@ export class Aggregate extends AggregateBase {
53
53
  }, this.featureName, this.ee);
54
54
  }
55
55
  this.harvestScheduler = new HarvestScheduler('ins', {
56
- onFinished: function () {
57
- return _this.onHarvestFinished(...arguments);
58
- }
56
+ onFinished: (...args) => this.onHarvestFinished(...args)
59
57
  }, this);
60
- this.harvestScheduler.harvest.on('ins', function () {
61
- return _this.onHarvestStarted(...arguments);
62
- });
58
+ this.harvestScheduler.harvest.on('ins', (...args) => this.onHarvestStarted(...args));
63
59
  this.harvestScheduler.startTimer(this.harvestTimeSeconds, 0);
64
60
  this.drain();
65
61
  });
66
62
  }
67
- onHarvestStarted(options) {
68
- const {
69
- userAttributes,
70
- atts
71
- } = getInfo(this.agentIdentifier);
72
- const harvestEvents = this.overflow.length ? this.overflow.splice(0, Infinity) : this.events.splice(0, Infinity);
73
- var payload = {
74
- qs: {
75
- ua: userAttributes,
76
- at: atts
77
- },
78
- body: {
79
- ins: harvestEvents
80
- }
81
- };
82
- if (options.retry) {
83
- this.currentEvents = harvestEvents;
84
- }
85
- return payload;
86
- }
87
- onHarvestFinished(result) {
88
- if (result && result.sent && result.retry && this.currentEvents.length) {
89
- this.events = this.currentEvents.concat(this.events);
90
- this.currentEvents = [];
91
- }
92
- }
93
63
 
94
64
  // WARNING: Insights times are in seconds. EXCEPT timestamp, which is in ms.
95
- addEvent() {
96
- let obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
65
+ addEvent(obj = {}) {
97
66
  if (!obj || !Object.keys(obj).length) return;
98
67
  if (!obj.eventType) {
99
68
  warn(44);
@@ -105,7 +74,7 @@ export class Aggregate extends AggregateBase {
105
74
  }
106
75
  const defaultEventAttributes = {
107
76
  /** should be overridden by the event-specific attributes, but just in case -- set it to now() */
108
- timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(now()),
77
+ timestamp: Math.floor(this.#agentRuntime.timeKeeper.correctAbsoluteTimestamp(this.#agentRuntime.timeKeeper.convertRelativeTimestamp(now()))),
109
78
  /** all generic events require a pageUrl */
110
79
  pageUrl: cleanURL(getRuntime(this.agentIdentifier).origin)
111
80
  };
@@ -117,12 +86,34 @@ export class Aggregate extends AggregateBase {
117
86
  /** Event-specific attributes take precedence over agent-level custom attributes and fallbacks */
118
87
  ...obj
119
88
  };
120
- this.events.push(eventAttributes);
121
-
122
- // check if we've reached the harvest limit...
123
- if (this.events.length >= this.eventsPerHarvest) {
89
+ this.events.add(eventAttributes);
90
+ this.checkEventLimits();
91
+ }
92
+ onHarvestStarted(options) {
93
+ const {
94
+ userAttributes,
95
+ atts
96
+ } = getInfo(this.agentIdentifier);
97
+ if (!this.events.hasData) return;
98
+ var payload = {
99
+ qs: {
100
+ ua: userAttributes,
101
+ at: atts
102
+ },
103
+ body: applyFnToProps({
104
+ ins: this.events.buffer
105
+ }, this.obfuscator.obfuscateString.bind(this.obfuscator), 'string')
106
+ };
107
+ if (options.retry) this.events.hold();
108
+ return payload;
109
+ }
110
+ onHarvestFinished(result) {
111
+ if (result && result?.sent && result?.retry && this.events.held.hasData) this.events.unhold();else this.events.held.clear();
112
+ }
113
+ checkEventLimits() {
114
+ // check if we've reached any harvest limits...
115
+ if (this.events.bytes > IDEAL_PAYLOAD_SIZE) {
124
116
  this.ee.emit(SUPPORTABILITY_METRIC_CHANNEL, ['GenericEvents/Harvest/Max/Seen']);
125
- this.overflow = [...this.overflow, ...this.events.splice(0, Infinity)];
126
117
  this.harvestScheduler.runHarvest();
127
118
  }
128
119
  }
@@ -1,2 +1,4 @@
1
1
  import { FEATURE_NAMES } from '../../loaders/features/features';
2
- export const FEATURE_NAME = FEATURE_NAMES.genericEvents;
2
+ export const FEATURE_NAME = FEATURE_NAMES.genericEvents;
3
+ export const IDEAL_PAYLOAD_SIZE = 64000;
4
+ export const MAX_PAYLOAD_SIZE = 1000000;
@@ -2,14 +2,13 @@
2
2
  * SPDX-License-Identifier: Apache-2.0
3
3
  */
4
4
 
5
- import { getConfigurationValue } from '../../../common/config/config';
5
+ import { getConfigurationValue } from '../../../common/config/init';
6
6
  import { deregisterDrain } from '../../../common/drain/drain';
7
7
  import { InstrumentBase } from '../../utils/instrument-base';
8
8
  import { FEATURE_NAME } from '../constants';
9
9
  export class Instrument extends InstrumentBase {
10
- static featureName = (() => FEATURE_NAME)();
11
- constructor(agentIdentifier, aggregator) {
12
- let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
10
+ static featureName = FEATURE_NAME;
11
+ constructor(agentIdentifier, aggregator, auto = true) {
13
12
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
14
13
  const genericEventSourceConfigs = [getConfigurationValue(this.agentIdentifier, 'page_action.enabled')
15
14
  // other future generic event source configs to go here, like M&Ms, PageResouce, etc.
@@ -17,4 +16,5 @@ export class Instrument extends InstrumentBase {
17
16
  /** If any of the sources are active, import the aggregator. otherwise deregister */
18
17
  if (genericEventSourceConfigs.some(x => x)) this.importAggregator();else deregisterDrain(this.agentIdentifier, this.featureName);
19
18
  }
20
- }
19
+ }
20
+ export const GenericEvents = Instrument;