@newrelic/browser-agent 1.252.1 → 1.254.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 (252) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/cdn/experimental.js +6 -2
  4. package/dist/cjs/cdn/polyfills.js +2 -1
  5. package/dist/cjs/cdn/spa.js +5 -3
  6. package/dist/cjs/common/aggregate/aggregator.js +1 -8
  7. package/dist/cjs/common/config/state/init.js +7 -0
  8. package/dist/cjs/common/config/state/runtime.js +4 -1
  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/drain/drain.js +41 -27
  12. package/dist/cjs/common/event-emitter/contextual-ee.js +17 -12
  13. package/dist/cjs/common/harvest/harvest.js +5 -1
  14. package/dist/cjs/common/session/constants.js +2 -1
  15. package/dist/cjs/common/timing/nav-timing.js +8 -3
  16. package/dist/cjs/common/timing/now.js +1 -1
  17. package/dist/cjs/common/timing/time-keeper.js +94 -0
  18. package/dist/cjs/common/util/feature-flags.js +14 -31
  19. package/dist/cjs/common/wrap/index.js +0 -7
  20. package/dist/cjs/features/ajax/aggregate/index.js +41 -29
  21. package/dist/cjs/features/jserrors/aggregate/index.js +96 -84
  22. package/dist/cjs/features/metrics/aggregate/index.js +25 -24
  23. package/dist/cjs/features/page_action/aggregate/index.js +6 -4
  24. package/dist/cjs/features/page_view_event/aggregate/index.js +23 -3
  25. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -0
  26. package/dist/cjs/features/page_view_timing/aggregate/index.js +15 -16
  27. package/dist/cjs/features/session_replay/aggregate/index.js +102 -92
  28. package/dist/cjs/features/session_replay/constants.js +5 -1
  29. package/dist/cjs/features/session_replay/instrument/index.js +24 -8
  30. package/dist/cjs/features/session_replay/shared/utils.js +26 -0
  31. package/dist/cjs/features/session_trace/aggregate/index.js +11 -8
  32. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +50 -0
  33. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +29 -0
  34. package/dist/cjs/features/soft_navigations/aggregate/index.js +268 -0
  35. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +62 -0
  36. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +146 -0
  37. package/dist/cjs/features/soft_navigations/constants.js +31 -0
  38. package/dist/cjs/features/soft_navigations/index.js +12 -0
  39. package/dist/cjs/features/soft_navigations/instrument/index.js +79 -0
  40. package/dist/cjs/features/spa/aggregate/index.js +23 -18
  41. package/dist/cjs/features/utils/agent-session.js +2 -1
  42. package/dist/cjs/features/utils/aggregate-base.js +18 -5
  43. package/dist/cjs/features/utils/feature-base.js +2 -0
  44. package/dist/cjs/features/utils/instrument-base.js +7 -9
  45. package/dist/cjs/features/utils/lazy-feature-loader.js +2 -0
  46. package/dist/cjs/loaders/agent-base.js +13 -3
  47. package/dist/cjs/loaders/agent.js +19 -22
  48. package/dist/cjs/loaders/api/api-methods.js +2 -1
  49. package/dist/cjs/loaders/api/api.js +15 -12
  50. package/dist/cjs/loaders/configure/configure.js +5 -2
  51. package/dist/cjs/loaders/configure/nonce.cdn.js +13 -0
  52. package/dist/cjs/loaders/configure/nonce.js +2 -13
  53. package/dist/cjs/loaders/configure/public-path.cdn.js +16 -0
  54. package/dist/cjs/loaders/configure/public-path.js +2 -8
  55. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  56. package/dist/cjs/loaders/features/features.js +3 -1
  57. package/dist/esm/cdn/experimental.js +5 -2
  58. package/dist/esm/cdn/polyfills.js +2 -1
  59. package/dist/esm/cdn/spa.js +3 -1
  60. package/dist/esm/common/aggregate/aggregator.js +1 -8
  61. package/dist/esm/common/config/state/init.js +7 -0
  62. package/dist/esm/common/config/state/runtime.js +4 -1
  63. package/dist/esm/common/constants/env.cdn.js +1 -1
  64. package/dist/esm/common/constants/env.npm.js +1 -1
  65. package/dist/esm/common/drain/drain.js +40 -27
  66. package/dist/esm/common/event-emitter/contextual-ee.js +17 -12
  67. package/dist/esm/common/harvest/harvest.js +5 -1
  68. package/dist/esm/common/session/constants.js +1 -0
  69. package/dist/esm/common/timing/nav-timing.js +8 -3
  70. package/dist/esm/common/timing/now.js +1 -1
  71. package/dist/esm/common/timing/time-keeper.js +88 -0
  72. package/dist/esm/common/util/feature-flags.js +14 -31
  73. package/dist/esm/common/wrap/index.js +1 -2
  74. package/dist/esm/features/ajax/aggregate/index.js +43 -31
  75. package/dist/esm/features/jserrors/aggregate/index.js +96 -84
  76. package/dist/esm/features/metrics/aggregate/index.js +25 -24
  77. package/dist/esm/features/page_action/aggregate/index.js +6 -4
  78. package/dist/esm/features/page_view_event/aggregate/index.js +23 -3
  79. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -0
  80. package/dist/esm/features/page_view_timing/aggregate/index.js +15 -16
  81. package/dist/esm/features/session_replay/aggregate/index.js +103 -93
  82. package/dist/esm/features/session_replay/constants.js +4 -0
  83. package/dist/esm/features/session_replay/instrument/index.js +25 -9
  84. package/dist/esm/features/session_replay/shared/utils.js +17 -0
  85. package/dist/esm/features/session_trace/aggregate/index.js +11 -8
  86. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +43 -0
  87. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +22 -0
  88. package/dist/esm/features/soft_navigations/aggregate/index.js +261 -0
  89. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +55 -0
  90. package/dist/esm/features/soft_navigations/aggregate/interaction.js +140 -0
  91. package/dist/esm/features/soft_navigations/constants.js +25 -0
  92. package/dist/esm/features/soft_navigations/index.js +1 -0
  93. package/dist/esm/features/soft_navigations/instrument/index.js +73 -0
  94. package/dist/esm/features/spa/aggregate/index.js +23 -18
  95. package/dist/esm/features/utils/agent-session.js +2 -1
  96. package/dist/esm/features/utils/aggregate-base.js +18 -5
  97. package/dist/esm/features/utils/feature-base.js +2 -0
  98. package/dist/esm/features/utils/instrument-base.js +8 -10
  99. package/dist/esm/features/utils/lazy-feature-loader.js +2 -0
  100. package/dist/esm/loaders/agent-base.js +13 -3
  101. package/dist/esm/loaders/agent.js +19 -22
  102. package/dist/esm/loaders/api/api-methods.js +2 -1
  103. package/dist/esm/loaders/api/api.js +15 -12
  104. package/dist/esm/loaders/configure/configure.js +5 -2
  105. package/dist/esm/loaders/configure/nonce.cdn.js +11 -0
  106. package/dist/esm/loaders/configure/nonce.js +1 -11
  107. package/dist/esm/loaders/configure/public-path.cdn.js +9 -0
  108. package/dist/esm/loaders/configure/public-path.js +2 -8
  109. package/dist/esm/loaders/features/enabled-features.js +1 -1
  110. package/dist/esm/loaders/features/features.js +3 -1
  111. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  112. package/dist/types/common/config/state/init.d.ts.map +1 -1
  113. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  114. package/dist/types/common/drain/drain.d.ts +6 -0
  115. package/dist/types/common/drain/drain.d.ts.map +1 -1
  116. package/dist/types/common/event-emitter/contextual-ee.d.ts +2 -1
  117. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
  118. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  119. package/dist/types/common/session/constants.d.ts +1 -0
  120. package/dist/types/common/session/constants.d.ts.map +1 -1
  121. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  122. package/dist/types/common/timing/time-keeper.d.ts +31 -0
  123. package/dist/types/common/timing/time-keeper.d.ts.map +1 -0
  124. package/dist/types/common/util/feature-flags.d.ts +11 -2
  125. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  126. package/dist/types/common/wrap/index.d.ts +1 -2
  127. package/dist/types/common/wrap/index.d.ts.map +1 -1
  128. package/dist/types/features/ajax/aggregate/index.d.ts +5 -5
  129. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  130. package/dist/types/features/jserrors/aggregate/index.d.ts +4 -3
  131. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  132. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  133. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  134. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  135. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
  136. package/dist/types/features/page_view_timing/aggregate/index.d.ts +0 -2
  137. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  138. package/dist/types/features/session_replay/aggregate/index.d.ts +1 -1
  139. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  140. package/dist/types/features/session_replay/constants.d.ts +4 -0
  141. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  142. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  143. package/dist/types/features/session_replay/shared/utils.d.ts +4 -0
  144. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -0
  145. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts +19 -0
  146. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts.map +1 -0
  147. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts +16 -0
  148. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts.map +1 -0
  149. package/dist/types/features/soft_navigations/aggregate/index.d.ts +34 -0
  150. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -0
  151. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts +12 -0
  152. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts.map +1 -0
  153. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts +50 -0
  154. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts.map +1 -0
  155. package/dist/types/features/soft_navigations/constants.d.ts +20 -0
  156. package/dist/types/features/soft_navigations/constants.d.ts.map +1 -0
  157. package/dist/types/features/soft_navigations/index.d.ts +2 -0
  158. package/dist/types/features/soft_navigations/index.d.ts.map +1 -0
  159. package/dist/types/features/soft_navigations/instrument/index.d.ts +7 -0
  160. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -0
  161. package/dist/types/features/spa/aggregate/index.d.ts +2 -0
  162. package/dist/types/features/spa/aggregate/index.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 +2 -2
  165. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  166. package/dist/types/features/utils/feature-base.d.ts +1 -0
  167. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  168. package/dist/types/features/utils/instrument-base.d.ts +1 -7
  169. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  170. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -1
  171. package/dist/types/loaders/agent-base.d.ts +5 -1
  172. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  173. package/dist/types/loaders/agent.d.ts +2 -2
  174. package/dist/types/loaders/agent.d.ts.map +1 -1
  175. package/dist/types/loaders/api/api-methods.d.ts.map +1 -1
  176. package/dist/types/loaders/api/api.d.ts +3 -5
  177. package/dist/types/loaders/api/api.d.ts.map +1 -1
  178. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  179. package/dist/types/loaders/configure/public-path.d.ts +1 -1
  180. package/dist/types/loaders/configure/public-path.d.ts.map +1 -1
  181. package/dist/types/loaders/features/features.d.ts +1 -0
  182. package/dist/types/loaders/features/features.d.ts.map +1 -1
  183. package/dist/types/loaders/micro-agent.d.ts +0 -1
  184. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  185. package/package.json +1 -1
  186. package/src/cdn/experimental.js +4 -2
  187. package/src/cdn/polyfills.js +1 -0
  188. package/src/cdn/spa.js +3 -1
  189. package/src/common/aggregate/aggregator.js +2 -11
  190. package/src/common/config/state/init.js +3 -1
  191. package/src/common/config/state/runtime.js +4 -1
  192. package/src/common/drain/drain.js +41 -28
  193. package/src/common/event-emitter/contextual-ee.js +21 -13
  194. package/src/common/harvest/harvest.js +4 -1
  195. package/src/common/session/constants.js +1 -0
  196. package/src/common/timing/nav-timing.js +7 -3
  197. package/src/common/timing/now.js +1 -1
  198. package/src/common/timing/time-keeper.js +96 -0
  199. package/src/common/util/feature-flags.js +13 -31
  200. package/src/common/wrap/index.js +1 -2
  201. package/src/features/ajax/aggregate/index.js +43 -33
  202. package/src/features/jserrors/aggregate/index.js +82 -87
  203. package/src/features/metrics/aggregate/index.js +18 -17
  204. package/src/features/page_action/aggregate/index.js +6 -5
  205. package/src/features/page_view_event/aggregate/index.js +19 -3
  206. package/src/features/page_view_event/aggregate/initialized-features.js +1 -0
  207. package/src/features/page_view_timing/aggregate/index.js +15 -15
  208. package/src/features/session_replay/aggregate/index.js +95 -92
  209. package/src/features/session_replay/constants.js +5 -0
  210. package/src/features/session_replay/instrument/index.js +24 -9
  211. package/src/features/session_replay/shared/utils.js +19 -0
  212. package/src/features/session_trace/aggregate/index.js +2 -2
  213. package/src/features/soft_navigations/aggregate/ajax-node.js +57 -0
  214. package/src/features/soft_navigations/aggregate/bel-node.js +26 -0
  215. package/src/features/soft_navigations/aggregate/index.js +256 -0
  216. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +53 -0
  217. package/src/features/soft_navigations/aggregate/interaction.js +159 -0
  218. package/src/features/soft_navigations/constants.js +29 -0
  219. package/src/features/soft_navigations/index.js +1 -0
  220. package/src/features/soft_navigations/instrument/index.js +67 -0
  221. package/src/features/spa/aggregate/index.js +20 -17
  222. package/src/features/utils/agent-session.js +2 -1
  223. package/src/features/utils/aggregate-base.js +16 -8
  224. package/src/features/utils/feature-base.js +3 -0
  225. package/src/features/utils/instrument-base.js +8 -10
  226. package/src/features/utils/lazy-feature-loader.js +2 -0
  227. package/src/loaders/agent-base.js +13 -3
  228. package/src/loaders/agent.js +20 -19
  229. package/src/loaders/api/api-methods.js +4 -1
  230. package/src/loaders/api/api.js +15 -13
  231. package/src/loaders/configure/configure.js +4 -1
  232. package/src/loaders/configure/nonce.cdn.js +12 -0
  233. package/src/loaders/configure/nonce.js +1 -12
  234. package/src/loaders/configure/public-path.cdn.js +9 -0
  235. package/src/loaders/configure/public-path.js +2 -8
  236. package/src/loaders/features/enabled-features.js +1 -1
  237. package/src/loaders/features/features.js +3 -1
  238. package/dist/cjs/common/wrap/wrap-raf.js +0 -55
  239. package/dist/cjs/loaders/configure/nonce.npm.js +0 -2
  240. package/dist/cjs/loaders/configure/public-path.npm.js +0 -10
  241. package/dist/esm/common/wrap/wrap-raf.js +0 -48
  242. package/dist/esm/loaders/configure/nonce.npm.js +0 -1
  243. package/dist/esm/loaders/configure/public-path.npm.js +0 -3
  244. package/dist/types/common/wrap/wrap-raf.d.ts +0 -16
  245. package/dist/types/common/wrap/wrap-raf.d.ts.map +0 -1
  246. package/dist/types/loaders/configure/nonce.npm.d.ts +0 -1
  247. package/dist/types/loaders/configure/nonce.npm.d.ts.map +0 -1
  248. package/dist/types/loaders/configure/public-path.npm.d.ts +0 -2
  249. package/dist/types/loaders/configure/public-path.npm.d.ts.map +0 -1
  250. package/src/common/wrap/wrap-raf.js +0 -52
  251. package/src/loaders/configure/nonce.npm.js +0 -1
  252. package/src/loaders/configure/public-path.npm.js +0 -3
@@ -10,9 +10,11 @@ import { Instrument as InstrumentErrors } from '../features/jserrors/instrument'
10
10
  import { Instrument as InstrumentXhr } from '../features/ajax/instrument';
11
11
  import { Instrument as InstrumentSessionTrace } from '../features/session_trace/instrument';
12
12
  import { Instrument as InstrumentSessionReplay } from '../features/session_replay/instrument';
13
+ import { Instrument as InstrumentSoftNav } from '../features/soft_navigations/instrument';
13
14
  import { Instrument as InstrumentSpa } from '../features/spa/instrument';
14
15
  import { Instrument as InstrumentPageAction } from '../features/page_action/instrument';
15
16
  new Agent({
16
- features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentSessionReplay, InstrumentMetrics, InstrumentPageAction, InstrumentErrors, InstrumentSpa],
17
+ features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentSessionReplay, InstrumentMetrics, InstrumentPageAction, InstrumentErrors, InstrumentSoftNav, InstrumentSpa // either the softnav or the old spa will be used (not both), but we still need to pack both to avoid dynamic import for instrument files
18
+ ],
17
19
  loaderType: 'spa'
18
20
  });
@@ -77,7 +77,7 @@ export class Aggregator extends SharedContext {
77
77
  var hasData = false;
78
78
  for (var i = 0; i < types.length; i++) {
79
79
  type = types[i];
80
- results[type] = toArray(this.aggregatedData[type]);
80
+ results[type] = Object.values(this.aggregatedData[type] || {});
81
81
  if (results[type].length) hasData = true;
82
82
  delete this.aggregatedData[type];
83
83
  }
@@ -151,11 +151,4 @@ function createMetricObject(value) {
151
151
  sos: value * value,
152
152
  c: 1
153
153
  };
154
- }
155
- function toArray(obj) {
156
- if (typeof obj !== 'object') return [];
157
- return mapOwn(obj, getValue);
158
- }
159
- function getValue(key, value) {
160
- return value;
161
154
  }
@@ -98,6 +98,8 @@ const model = () => {
98
98
  autoStart: true,
99
99
  enabled: false,
100
100
  harvestTimeSeconds: 60,
101
+ preload: false,
102
+ // if true, enables the agent to load rrweb immediately instead of waiting to do so after the window.load event
101
103
  sampling_rate: 10,
102
104
  // float from 0 - 100
103
105
  error_sampling_rate: 100,
@@ -150,6 +152,11 @@ const model = () => {
150
152
  enabled: true,
151
153
  harvestTimeSeconds: 10,
152
154
  autoStart: true
155
+ },
156
+ soft_navigations: {
157
+ enabled: true,
158
+ harvestTimeSeconds: 10,
159
+ autoStart: true
153
160
  }
154
161
  };
155
162
  };
@@ -17,10 +17,13 @@ const model = {
17
17
  origin: '' + globalScope.location,
18
18
  ptid: undefined,
19
19
  releaseIds: {},
20
+ /** Agent-specific metadata found in the RUM call response. ex. entityGuid */
21
+ appMetadata: {},
20
22
  session: undefined,
21
23
  xhrWrappable: typeof globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
22
24
  version: VERSION,
23
- denyList: undefined
25
+ denyList: undefined,
26
+ harvestCount: 0
24
27
  };
25
28
  const _cache = {};
26
29
  export function getRuntime(id) {
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * Exposes the version of the agent
8
8
  */
9
- export const VERSION = "1.252.1";
9
+ export const VERSION = "1.254.0";
10
10
 
11
11
  /**
12
12
  * Exposes the build type of the agent
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * Exposes the version of the agent
8
8
  */
9
- export const VERSION = "1.252.1";
9
+ export const VERSION = "1.254.0";
10
10
 
11
11
  /**
12
12
  * Exposes the build type of the agent
@@ -28,13 +28,24 @@ export function registerDrain(agentIdentifier, group) {
28
28
  if (!registry[agentIdentifier].get(group)) registry[agentIdentifier].set(group, item);
29
29
  }
30
30
 
31
+ /**
32
+ * Removes an item from the registry and immediately re-checks if the registry is ready to "drain all"
33
+ * @param {*} agentIdentifier - A 16 character string uniquely identifying the agent.
34
+ * @param {*} group - The named "bucket" to be removed from the registry
35
+ */
36
+ export function deregisterDrain(agentIdentifier, group) {
37
+ curateRegistry(agentIdentifier);
38
+ if (registry[agentIdentifier].get(group)) registry[agentIdentifier].delete(group);
39
+ if (registry[agentIdentifier].size) checkCanDrainAll(agentIdentifier);
40
+ }
41
+
31
42
  /**
32
43
  * Registers the specified agent with the centralized event buffer registry if it is not already registered.
33
44
  * Agents without an identifier (as in the case of some tests) will be excluded from the registry.
34
45
  * @param {string} agentIdentifier - A 16 character string uniquely identifying an agent.
35
46
  */
36
47
  function curateRegistry(agentIdentifier) {
37
- if (!agentIdentifier) return;
48
+ if (!agentIdentifier) throw new Error('agentIdentifier required');
38
49
  if (!registry[agentIdentifier]) registry[agentIdentifier] = new Map();
39
50
  }
40
51
 
@@ -53,11 +64,15 @@ export function drain() {
53
64
  // If the feature for the specified agent is not in the registry, that means the instrument file was bypassed.
54
65
  // This could happen in tests, or loaders that directly import the aggregator. In these cases it is safe to
55
66
  // drain the feature group immediately rather than waiting to drain all at once.
56
- if (!agentIdentifier || !registry[agentIdentifier].get(featureName) || force) return drainGroup(featureName);
67
+ if (!agentIdentifier || !registry[agentIdentifier].get(featureName) || force) return drainGroup(agentIdentifier, featureName);
57
68
 
58
69
  // When `drain` is called, this feature is ready to drain (staged).
59
70
  registry[agentIdentifier].get(featureName).staged = true;
71
+ checkCanDrainAll(agentIdentifier);
72
+ }
60
73
 
74
+ /** Checks all items in the registry to see if they have been "staged". If ALL items are staged, it will drain all registry items (drainGroup). It not, nothing will happen */
75
+ function checkCanDrainAll(agentIdentifier) {
61
76
  // Only when the event-groups for all features are ready to drain (staged) do we execute the drain. This has the effect
62
77
  // that the last feature to call drain triggers drain for all features.
63
78
  const items = [...registry[agentIdentifier]];
@@ -69,40 +84,38 @@ export function drain() {
69
84
  items.forEach(_ref2 => {
70
85
  let [group] = _ref2;
71
86
  registry[agentIdentifier].delete(group);
72
- drainGroup(group);
87
+ drainGroup(agentIdentifier, group);
73
88
  });
74
89
  }
90
+ }
75
91
 
76
- /**
92
+ /**
77
93
  * Drains all the buffered (backlog) events for a particular feature's event-group by emitting each event to each of
78
94
  * the subscribed handlers for the group.
79
95
  * @param {*} group - The name of a particular feature's event "bucket".
80
96
  */
81
- function drainGroup(group) {
82
- const baseEE = agentIdentifier ? ee.get(agentIdentifier) : ee;
83
- const handlers = defaultRegister.handlers;
84
- if (!baseEE.backlog || !handlers) return;
85
- var bufferedEventsInGroup = baseEE.backlog[group];
86
- var groupHandlers = handlers[group];
87
- if (groupHandlers) {
88
- // We don't cache the length of the buffer while looping because events might still be added while processing.
89
- for (var i = 0; bufferedEventsInGroup && i < bufferedEventsInGroup.length; ++i) {
90
- // eslint-disable-line no-unmodified-loop-condition
91
- emitEvent(bufferedEventsInGroup[i], groupHandlers);
92
- }
93
- mapOwn(groupHandlers, function (eventType, handlerRegistrationList) {
94
- mapOwn(handlerRegistrationList, function (i, registration) {
95
- // registration is an array of: [targetEE, eventHandler]
96
- registration[0].on(eventType, registration[1]);
97
- });
98
- });
97
+ function drainGroup(agentIdentifier, group) {
98
+ const baseEE = agentIdentifier ? ee.get(agentIdentifier) : ee;
99
+ const handlers = defaultRegister.handlers; // other storage in registerHandler
100
+ if (!baseEE.backlog || !handlers) return;
101
+ var bufferedEventsInGroup = baseEE.backlog[group];
102
+ var groupHandlers = handlers[group]; // each group in the registerHandler storage
103
+ if (groupHandlers) {
104
+ // We don't cache the length of the buffer while looping because events might still be added while processing.
105
+ for (var i = 0; bufferedEventsInGroup && i < bufferedEventsInGroup.length; ++i) {
106
+ // eslint-disable-line no-unmodified-loop-condition
107
+ emitEvent(bufferedEventsInGroup[i], groupHandlers);
99
108
  }
100
- delete handlers[group];
101
-
102
- // Keep the feature's event-group as a property of the event emitter so we know it was already created and drained.
103
- baseEE.backlog[group] = null;
104
- baseEE.emit('drain-' + group, []);
109
+ mapOwn(groupHandlers, function (eventType, handlerRegistrationList) {
110
+ mapOwn(handlerRegistrationList, function (i, registration) {
111
+ // registration is an array of: [targetEE, eventHandler]
112
+ registration[0].on(eventType, registration[1]);
113
+ });
114
+ });
105
115
  }
116
+ if (!baseEE.isolatedBacklog) delete handlers[group];
117
+ baseEE.backlog[group] = null;
118
+ baseEE.emit('drain-' + group, []);
106
119
  }
107
120
 
108
121
  /**
@@ -46,11 +46,26 @@ function ee(old, debugId) {
46
46
  context,
47
47
  buffer: bufferEventsByGroup,
48
48
  abort,
49
- aborted: false,
50
49
  isBuffering,
51
50
  debugId,
52
- backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
51
+ backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {},
52
+ isolatedBacklog
53
53
  };
54
+ function abort() {
55
+ emitter._aborted = true;
56
+ Object.keys(emitter.backlog).forEach(key => {
57
+ delete emitter.backlog[key];
58
+ });
59
+ }
60
+ Object.defineProperty(emitter, 'aborted', {
61
+ get: () => {
62
+ let aborted = emitter._aborted || false;
63
+ if (aborted) return aborted;else if (old) {
64
+ aborted = old.aborted;
65
+ }
66
+ return aborted;
67
+ }
68
+ });
54
69
  return emitter;
55
70
  function context(contextOrStore) {
56
71
  if (contextOrStore && contextOrStore instanceof EventContext) {
@@ -128,14 +143,4 @@ function ee(old, debugId) {
128
143
  function getBuffer() {
129
144
  return emitter.backlog;
130
145
  }
131
- }
132
- function abort() {
133
- globalInstance.aborted = true;
134
- // The global backlog can be referenced directly by other emitters,
135
- // so we need to delete its contents as opposed to replacing it.
136
- // Otherwise, these references to the old backlog would still exist
137
- // and the keys will not be garbage collected.
138
- Object.keys(globalInstance.backlog).forEach(key => {
139
- delete globalInstance.backlog[key];
140
- });
141
146
  }
@@ -177,7 +177,9 @@ export class Harvest extends SharedContext {
177
177
  // status 0 refers to a local error, such as CORS or network failure, or a blocked request by the browser (e.g. adblocker)
178
178
  const cbResult = {
179
179
  sent: this.status !== 0,
180
- status: this.status
180
+ status: this.status,
181
+ xhr: this,
182
+ fullUrl
181
183
  };
182
184
  if (this.status === 429) {
183
185
  cbResult.retry = true;
@@ -191,6 +193,8 @@ export class Harvest extends SharedContext {
191
193
  cbFinished(cbResult);
192
194
  }, eventListenerOpts(false));
193
195
  }
196
+ const runtime = getRuntime(this.sharedContext.agentIdentifier);
197
+ runtime.harvestCount++;
194
198
  return result;
195
199
  }
196
200
 
@@ -1,4 +1,5 @@
1
1
  export const PREFIX = 'NRBA';
2
+ export const DEFAULT_KEY = 'SESSION';
2
3
  export const DEFAULT_EXPIRES_MS = 14400000;
3
4
  export const DEFAULT_INACTIVE_MS = 1800000;
4
5
  export const SESSION_EVENTS = {
@@ -24,7 +24,7 @@ var REQUEST = 'request';
24
24
  var RESPONSE = 'response';
25
25
  var LOAD_EVENT = 'loadEvent';
26
26
  var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
27
- export var navTimingValues = [];
27
+ export const navTimingValues = [];
28
28
  function getPntType(type) {
29
29
  if (typeof type === 'number') return type;
30
30
  const types = {
@@ -70,6 +70,11 @@ export function addPN(pn, v) {
70
70
  handleValue(pn.redirectCount, v, 'rc');
71
71
  return v;
72
72
  }
73
+
74
+ /**
75
+ * By side effect, this modifies 'obj' with a mapping of the 'prop' provided to a 'value', and invalid values are not added.
76
+ * On the other hand, the local navTimingValues array gets the value appended if valid and 'undefined' appended if invalid, regardless.
77
+ */
73
78
  function handleValue(value, obj, prop, isOldApi) {
74
79
  /*
75
80
  For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
@@ -84,6 +89,6 @@ function handleValue(value, obj, prop, isOldApi) {
84
89
  }
85
90
  value = Math.round(value);
86
91
  obj[prop] = value;
87
- }
88
- navTimingValues.push(value);
92
+ navTimingValues.push(value);
93
+ } else navTimingValues.push(undefined);
89
94
  }
@@ -5,5 +5,5 @@
5
5
 
6
6
  // This is our own layer around performance.now. It's not strictly necessary, but we keep it in case of future mod-ing of the value for refactor purpose.
7
7
  export function now() {
8
- return Math.round(performance.now());
8
+ return Math.floor(performance.now());
9
9
  }
@@ -0,0 +1,88 @@
1
+ import { gosNREUM } from '../window/nreum';
2
+ import { globalScope } from '../constants/runtime';
3
+ import { getRuntime } from '../config/config';
4
+
5
+ /**
6
+ * Class used to adjust the timestamp of harvested data to New Relic server time. This
7
+ * is done by tracking the performance timings of the RUM call and applying a calculation
8
+ * to the harvested data event offset time.
9
+ */
10
+ export class TimeKeeper {
11
+ #agent;
12
+
13
+ /**
14
+ * Represents the browser origin time corrected to NR server time.
15
+ * @type {number}
16
+ */
17
+ #correctedOriginTime;
18
+
19
+ /**
20
+ * Represents the difference in milliseconds between the calculated NR server time and
21
+ * the local time.
22
+ * @type {number}
23
+ */
24
+ #localTimeDiff;
25
+ constructor(agent) {
26
+ this.#agent = agent;
27
+ }
28
+ static getTimeKeeperByAgentIdentifier(agentIdentifier) {
29
+ const nr = gosNREUM();
30
+ return Object.keys(nr?.initializedAgents || {}).indexOf(agentIdentifier) > -1 ? nr.initializedAgents[agentIdentifier].timeKeeper : undefined;
31
+ }
32
+ get correctedPageOriginTime() {
33
+ return this.#correctedOriginTime;
34
+ }
35
+
36
+ /**
37
+ * Process a rum request to calculate NR server time.
38
+ * @param rumRequest {XMLHttpRequest} The xhr for the rum request
39
+ * @param rumRequestUrl {string} The full url of the rum request
40
+ */
41
+ processRumRequest(rumRequest, rumRequestUrl) {
42
+ const responseDateHeader = rumRequest.getResponseHeader('Date');
43
+ if (!responseDateHeader) {
44
+ throw new Error('Missing date header on rum response.');
45
+ }
46
+ const resourceEntries = globalScope.performance.getEntriesByName(rumRequestUrl, 'resource');
47
+ if (!Array.isArray(resourceEntries) || resourceEntries.length === 0) {
48
+ throw new Error('Missing rum request performance entry.');
49
+ }
50
+ let medianRumOffset = 0;
51
+ let serverOffset = 0;
52
+ if (typeof resourceEntries[0].responseStart === 'number' && resourceEntries[0].responseStart !== 0) {
53
+ // Cors is enabled and we can make a more accurate calculation of NR server time
54
+ medianRumOffset = (resourceEntries[0].responseStart - resourceEntries[0].requestStart) / 2;
55
+ serverOffset = Math.floor(resourceEntries[0].requestStart + medianRumOffset);
56
+ } else {
57
+ // Cors is disabled or erred, we need to use a less accurate calculation
58
+ medianRumOffset = (resourceEntries[0].responseEnd - resourceEntries[0].fetchStart) / 2;
59
+ serverOffset = Math.floor(resourceEntries[0].fetchStart + medianRumOffset);
60
+ }
61
+
62
+ // Corrected page origin time
63
+ this.#correctedOriginTime = Math.floor(Date.parse(responseDateHeader) - serverOffset);
64
+ this.#localTimeDiff = getRuntime(this.#agent.agentIdentifier).offset - this.#correctedOriginTime;
65
+ if (Number.isNaN(this.#correctedOriginTime)) {
66
+ throw new Error('Date header invalid format.');
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Converts a page origin relative time to an absolute timestamp
72
+ * corrected to NR server time.
73
+ * @param relativeTime {number} The relative time of the event in milliseconds
74
+ * @returns {number} The correct timestamp as a unix/epoch timestamp value
75
+ */
76
+ convertRelativeTimestamp(relativeTime) {
77
+ return this.#correctedOriginTime + relativeTime;
78
+ }
79
+
80
+ /**
81
+ * Corrects an event timestamp to NR server time.
82
+ * @param timestamp {number} The unix/epoch timestamp of the event with milliseconds
83
+ * @return {number} Corrected unix/epoch timestamp
84
+ */
85
+ correctAbsoluteTimestamp(timestamp) {
86
+ return Math.floor(timestamp - this.#localTimeDiff);
87
+ }
88
+ }
@@ -3,47 +3,30 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { ee } from '../event-emitter/contextual-ee';
6
- import { handle } from '../event-emitter/handle';
7
- import { FEATURE_NAMES } from '../../loaders/features/features';
8
6
  import { dispatchGlobalEvent } from '../dispatch/global-event';
9
- const bucketMap = {
10
- stn: [FEATURE_NAMES.sessionTrace],
11
- err: [FEATURE_NAMES.jserrors, FEATURE_NAMES.metrics],
12
- ins: [FEATURE_NAMES.pageAction],
13
- spa: [FEATURE_NAMES.spa],
14
- sr: [FEATURE_NAMES.sessionReplay, FEATURE_NAMES.sessionTrace]
15
- };
16
7
  const sentIds = new Set();
17
8
 
18
- /** Note that this function only processes each unique flag ONCE, with the first occurrence of each flag and numeric value determining its switch on/off setting. */
9
+ /** A map of feature flags and their values as provided by the rum call -- scoped by agent ID */
10
+ export const activatedFeatures = {};
11
+
12
+ /**
13
+ * Sets the activatedFeatures object, dispatches the global loaded event,
14
+ * and emits the rumresp flag to features
15
+ * @param {{[key:string]:number}} flags key-val pair of flag names and numeric
16
+ * @param {string} agentIdentifier agent instance identifier
17
+ * @returns {void}
18
+ */
19
19
  export function activateFeatures(flags, agentIdentifier) {
20
20
  const sharedEE = ee.get(agentIdentifier);
21
+ activatedFeatures[agentIdentifier] ??= {};
21
22
  if (!(flags && typeof flags === 'object')) return;
22
23
  if (sentIds.has(agentIdentifier)) return;
23
- Object.entries(flags).forEach(_ref => {
24
- let [flag, num] = _ref;
25
- if (bucketMap[flag]) {
26
- bucketMap[flag].forEach(feat => {
27
- if (!num) handle('block-' + flag, [], undefined, feat, sharedEE);else handle('feat-' + flag, [], undefined, feat, sharedEE);
28
- handle('rumresp-' + flag, [Boolean(num)], undefined, feat, sharedEE); // this is a duplicate of feat-/block- but makes awaiting for 1 event easier than 2
29
- });
30
- } else if (num) handle('feat-' + flag, [], undefined, undefined, sharedEE); // not sure what other flags are overlooked, but there's a test for ones not in the map --
31
- activatedFeatures[flag] = Boolean(num);
32
- });
33
-
34
- // Let the features waiting on their respective flags know that RUM response was received and that any missing flags are interpreted as bad entitlement / "off".
35
- // Hence, those features will not be hanging forever if their flags aren't included in the response.
36
- Object.keys(bucketMap).forEach(flag => {
37
- if (activatedFeatures[flag] === undefined) {
38
- bucketMap[flag]?.forEach(feat => handle('rumresp-' + flag, [false], undefined, feat, sharedEE));
39
- activatedFeatures[flag] = false;
40
- }
41
- });
24
+ sharedEE.emit('rumresp', [flags]);
25
+ activatedFeatures[agentIdentifier] = flags;
42
26
  sentIds.add(agentIdentifier);
43
27
 
44
28
  // let any window level subscribers know that the agent is running
45
29
  dispatchGlobalEvent({
46
30
  loaded: true
47
31
  });
48
- }
49
- export const activatedFeatures = {};
32
+ }
@@ -8,7 +8,6 @@ import { wrapHistory } from './wrap-history';
8
8
  import { wrapJsonP } from './wrap-jsonp';
9
9
  import { wrapMutation } from './wrap-mutation';
10
10
  import { wrapPromise } from './wrap-promise';
11
- import { wrapRaf } from './wrap-raf';
12
11
  import { wrapTimer } from './wrap-timer';
13
12
  import { wrapXhr } from './wrap-xhr';
14
- export { wrapEvents, wrapFetch, wrapHistory, wrapJsonP, wrapMutation, wrapPromise, wrapRaf, wrapTimer, wrapXhr };
13
+ export { wrapEvents, wrapFetch, wrapHistory, wrapJsonP, wrapMutation, wrapPromise, wrapTimer, wrapXhr };
@@ -2,7 +2,7 @@
2
2
  * Copyright 2020 New Relic Corporation. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { registerHandler as register } from '../../../common/event-emitter/register-handler';
5
+ import { registerHandler } from '../../../common/event-emitter/register-handler';
6
6
  import { stringify } from '../../../common/util/stringify';
7
7
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer';
8
8
  import { handle } from '../../../common/event-emitter/handle';
@@ -14,17 +14,21 @@ import { FEATURE_NAMES } from '../../../loaders/features/features';
14
14
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants';
15
15
  import { AggregateBase } from '../../utils/aggregate-base';
16
16
  import { parseGQL } from './gql';
17
+ import { getNREUMInitializedAgent } from '../../../common/window/nreum';
17
18
  export class Aggregate extends AggregateBase {
18
19
  static featureName = FEATURE_NAME;
19
20
  constructor(agentIdentifier, aggregator) {
20
21
  super(agentIdentifier, aggregator, FEATURE_NAME);
21
22
  const agentInit = getConfiguration(agentIdentifier);
22
- const allAjaxIsEnabled = agentInit.ajax.enabled !== false;
23
- register('xhr', storeXhr, this.featureName, this.ee);
24
- if (!allAjaxIsEnabled) {
23
+ registerHandler('xhr', storeXhr, this.featureName, this.ee);
24
+ this.waitForFlags([]).then(() => {
25
+ const scheduler = new HarvestScheduler('events', {
26
+ onFinished: onEventsHarvestFinished,
27
+ getPayload: prepareHarvest
28
+ }, this);
29
+ scheduler.startTimer(harvestTimeSeconds);
25
30
  this.drain();
26
- return; // feature will only collect timeslice metrics & ajax trace nodes if it's not fully enabled
27
- }
31
+ });
28
32
  const denyList = getRuntime(agentIdentifier).denyList;
29
33
  setDenyList(denyList);
30
34
  let ajaxEvents = [];
@@ -43,27 +47,23 @@ export class Aggregate extends AggregateBase {
43
47
  spaAjaxEvents
44
48
  };
45
49
  };
46
- ee.on('interactionSaved', interaction => {
47
- if (!spaAjaxEvents[interaction.id]) return;
48
- // remove from the spaAjaxEvents buffer, and let spa harvest it
49
- delete spaAjaxEvents[interaction.id];
50
- });
51
- ee.on('interactionDiscarded', interaction => {
50
+
51
+ // --- v Used by old spa feature
52
+ ee.on('interactionDone', (interaction, wasSaved) => {
52
53
  if (!spaAjaxEvents[interaction.id]) return;
53
- spaAjaxEvents[interaction.id].forEach(function (item) {
54
- // move it from the spaAjaxEvents buffer to the ajaxEvents buffer for harvesting here
55
- ajaxEvents.push(item);
56
- });
54
+ if (!wasSaved) {
55
+ // 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
56
+ spaAjaxEvents[interaction.id].forEach(function (item) {
57
+ ajaxEvents.push(item);
58
+ });
59
+ }
57
60
  delete spaAjaxEvents[interaction.id];
58
61
  });
59
- const scheduler = new HarvestScheduler('events', {
60
- onFinished: onEventsHarvestFinished,
61
- getPayload: prepareHarvest
62
- }, this);
63
- ee.on("drain-".concat(this.featureName), () => {
64
- scheduler.startTimer(harvestTimeSeconds);
65
- });
66
- this.drain();
62
+ // --- ^
63
+ // --- v Used by new soft nav
64
+ registerHandler('returnAjax', event => ajaxEvents.push(event), this.featureName, this.ee);
65
+ // --- ^
66
+
67
67
  const beacon = getInfo(agentIdentifier).errorBeacon;
68
68
  const proxyBeacon = agentInit.proxy.beacon;
69
69
  function storeXhr(params, metrics, startTime, endTime, type) {
@@ -76,16 +76,25 @@ export class Aggregate extends AggregateBase {
76
76
  } else {
77
77
  hash = stringify([params.status, params.host, params.pathname]);
78
78
  }
79
+ const shouldCollect = shouldCollectEvent(params);
80
+ const ajaxMetricDenyListEnabled = agentInit.feature_flags?.includes('ajax_metrics_deny_list');
79
81
 
80
82
  // store as metric
81
- aggregator.store('xhr', hash, params, metrics);
82
- if (!allAjaxIsEnabled) return;
83
- if (!shouldCollectEvent(params)) {
83
+ if (shouldCollect || !ajaxMetricDenyListEnabled) {
84
+ aggregator.store('xhr', hash, params, metrics);
85
+ }
86
+ if (!shouldCollect) {
84
87
  if (params.hostname === beacon || proxyBeacon && params.hostname === proxyBeacon) {
85
88
  // This doesn't make a distinction if the same-domain request is going to a different port or path...
86
89
  handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/Agent'], undefined, FEATURE_NAMES.metrics, ee);
90
+ if (ajaxMetricDenyListEnabled) {
91
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/Agent'], undefined, FEATURE_NAMES.metrics, ee);
92
+ }
87
93
  } else {
88
94
  handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/App'], undefined, FEATURE_NAMES.metrics, ee);
95
+ if (ajaxMetricDenyListEnabled) {
96
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/App'], undefined, FEATURE_NAMES.metrics, ee);
97
+ }
89
98
  }
90
99
  return;
91
100
  }
@@ -115,10 +124,13 @@ export class Aggregate extends AggregateBase {
115
124
  query: this?.parsedOrigin?.search
116
125
  });
117
126
  if (event.gql) handle(SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/GraphQL/Bytes-Added', stringify(event.gql).length], undefined, FEATURE_NAMES.metrics, ee);
118
-
119
- // if the ajax happened inside an interaction, hold it until the interaction finishes
120
- if (this.spaNode) {
121
- var interactionId = this.spaNode.interaction.id;
127
+ const softNavInUse = Boolean(getNREUMInitializedAgent(agentIdentifier)?.features?.[FEATURE_NAMES.softNav]);
128
+ if (softNavInUse) {
129
+ // For newer soft nav (when running), pass the event to it for evaluation -- either part of an interaction or is given back
130
+ handle('ajax', [event], undefined, FEATURE_NAMES.softNav, ee);
131
+ } else if (this.spaNode) {
132
+ // For old spa (when running), if the ajax happened inside an interaction, hold it until the interaction finishes
133
+ const interactionId = this.spaNode.interaction.id;
122
134
  spaAjaxEvents[interactionId] = spaAjaxEvents[interactionId] || [];
123
135
  spaAjaxEvents[interactionId].push(event);
124
136
  } else {