@newrelic/browser-agent 1.252.0 → 1.253.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 (217) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +6 -6
  3. package/dist/cjs/cdn/experimental.js +6 -2
  4. package/dist/cjs/cdn/spa.js +5 -3
  5. package/dist/cjs/common/aggregate/aggregator.js +1 -8
  6. package/dist/cjs/common/config/state/init.js +7 -0
  7. package/dist/cjs/common/constants/env.cdn.js +1 -1
  8. package/dist/cjs/common/constants/env.npm.js +1 -1
  9. package/dist/cjs/common/context/observation-context-manager.js +56 -0
  10. package/dist/cjs/common/event-emitter/contextual-ee.js +12 -9
  11. package/dist/cjs/common/session/constants.js +2 -1
  12. package/dist/cjs/common/session/session-entity.js +3 -1
  13. package/dist/cjs/common/timing/nav-timing.js +8 -3
  14. package/dist/cjs/common/timing/now.js +1 -1
  15. package/dist/cjs/common/util/feature-flags.js +1 -1
  16. package/dist/cjs/common/wrap/index.js +0 -7
  17. package/dist/cjs/common/wrap/wrap-events.js +2 -2
  18. package/dist/cjs/common/wrap/wrap-fetch.js +2 -1
  19. package/dist/cjs/common/wrap/wrap-function.js +5 -7
  20. package/dist/cjs/common/wrap/wrap-promise.js +2 -1
  21. package/dist/cjs/features/ajax/aggregate/index.js +34 -16
  22. package/dist/cjs/features/jserrors/aggregate/index.js +77 -66
  23. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -1
  24. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -0
  25. package/dist/cjs/features/session_replay/aggregate/index.js +96 -94
  26. package/dist/cjs/features/session_replay/constants.js +5 -1
  27. package/dist/cjs/features/session_replay/instrument/index.js +24 -8
  28. package/dist/cjs/features/session_replay/shared/recorder.js +5 -4
  29. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +8 -7
  30. package/dist/cjs/features/session_replay/shared/utils.js +26 -0
  31. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +50 -0
  32. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +29 -0
  33. package/dist/cjs/features/soft_navigations/aggregate/index.js +263 -0
  34. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +62 -0
  35. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +146 -0
  36. package/dist/cjs/features/soft_navigations/constants.js +31 -0
  37. package/dist/cjs/features/soft_navigations/index.js +12 -0
  38. package/dist/cjs/features/soft_navigations/instrument/index.js +79 -0
  39. package/dist/cjs/features/spa/aggregate/index.js +4 -4
  40. package/dist/cjs/features/utils/agent-session.js +2 -1
  41. package/dist/cjs/features/utils/instrument-base.js +6 -9
  42. package/dist/cjs/features/utils/lazy-feature-loader.js +2 -0
  43. package/dist/cjs/loaders/agent-base.js +18 -3
  44. package/dist/cjs/loaders/agent.js +15 -18
  45. package/dist/cjs/loaders/api/api-methods.js +9 -0
  46. package/dist/cjs/loaders/api/api.js +17 -18
  47. package/dist/cjs/loaders/configure/configure.js +5 -2
  48. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  49. package/dist/cjs/loaders/features/features.js +3 -1
  50. package/dist/esm/cdn/experimental.js +5 -2
  51. package/dist/esm/cdn/spa.js +3 -1
  52. package/dist/esm/common/aggregate/aggregator.js +1 -8
  53. package/dist/esm/common/config/state/init.js +7 -0
  54. package/dist/esm/common/constants/env.cdn.js +1 -1
  55. package/dist/esm/common/constants/env.npm.js +1 -1
  56. package/dist/esm/common/context/observation-context-manager.js +49 -0
  57. package/dist/esm/common/event-emitter/contextual-ee.js +12 -9
  58. package/dist/esm/common/session/constants.js +1 -0
  59. package/dist/esm/common/session/session-entity.js +3 -1
  60. package/dist/esm/common/timing/nav-timing.js +8 -3
  61. package/dist/esm/common/timing/now.js +1 -1
  62. package/dist/esm/common/util/feature-flags.js +1 -1
  63. package/dist/esm/common/wrap/index.js +1 -2
  64. package/dist/esm/common/wrap/wrap-events.js +3 -3
  65. package/dist/esm/common/wrap/wrap-fetch.js +3 -2
  66. package/dist/esm/common/wrap/wrap-function.js +4 -5
  67. package/dist/esm/common/wrap/wrap-promise.js +3 -2
  68. package/dist/esm/features/ajax/aggregate/index.js +36 -18
  69. package/dist/esm/features/jserrors/aggregate/index.js +77 -66
  70. package/dist/esm/features/page_view_event/aggregate/index.js +1 -1
  71. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -0
  72. package/dist/esm/features/session_replay/aggregate/index.js +97 -95
  73. package/dist/esm/features/session_replay/constants.js +4 -0
  74. package/dist/esm/features/session_replay/instrument/index.js +25 -9
  75. package/dist/esm/features/session_replay/shared/recorder.js +5 -4
  76. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +8 -7
  77. package/dist/esm/features/session_replay/shared/utils.js +17 -0
  78. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +43 -0
  79. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +22 -0
  80. package/dist/esm/features/soft_navigations/aggregate/index.js +256 -0
  81. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +55 -0
  82. package/dist/esm/features/soft_navigations/aggregate/interaction.js +140 -0
  83. package/dist/esm/features/soft_navigations/constants.js +25 -0
  84. package/dist/esm/features/soft_navigations/index.js +1 -0
  85. package/dist/esm/features/soft_navigations/instrument/index.js +73 -0
  86. package/dist/esm/features/spa/aggregate/index.js +4 -4
  87. package/dist/esm/features/utils/agent-session.js +2 -1
  88. package/dist/esm/features/utils/instrument-base.js +7 -10
  89. package/dist/esm/features/utils/lazy-feature-loader.js +2 -0
  90. package/dist/esm/loaders/agent-base.js +18 -3
  91. package/dist/esm/loaders/agent.js +15 -18
  92. package/dist/esm/loaders/api/api-methods.js +3 -0
  93. package/dist/esm/loaders/api/api.js +17 -17
  94. package/dist/esm/loaders/configure/configure.js +5 -2
  95. package/dist/esm/loaders/features/enabled-features.js +1 -1
  96. package/dist/esm/loaders/features/features.js +3 -1
  97. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  98. package/dist/types/common/config/state/init.d.ts.map +1 -1
  99. package/dist/types/common/context/event-context.d.ts.map +1 -0
  100. package/dist/types/common/context/observation-context-manager.d.ts +28 -0
  101. package/dist/types/common/context/observation-context-manager.d.ts.map +1 -0
  102. package/dist/types/common/event-emitter/contextual-ee.d.ts +2 -2
  103. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
  104. package/dist/types/common/session/constants.d.ts +1 -0
  105. package/dist/types/common/session/constants.d.ts.map +1 -1
  106. package/dist/types/common/session/session-entity.d.ts +0 -1
  107. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  108. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  109. package/dist/types/common/wrap/index.d.ts +1 -2
  110. package/dist/types/common/wrap/index.d.ts.map +1 -1
  111. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  112. package/dist/types/common/wrap/wrap-function.d.ts +0 -1
  113. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  114. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  115. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  116. package/dist/types/features/jserrors/aggregate/index.d.ts +4 -3
  117. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  118. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
  119. package/dist/types/features/session_replay/aggregate/index.d.ts +1 -1
  120. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  121. package/dist/types/features/session_replay/constants.d.ts +4 -0
  122. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  123. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  124. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  125. package/dist/types/features/session_replay/shared/stylesheet-evaluator.d.ts.map +1 -1
  126. package/dist/types/features/session_replay/shared/utils.d.ts +4 -0
  127. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -0
  128. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts +19 -0
  129. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts.map +1 -0
  130. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts +16 -0
  131. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts.map +1 -0
  132. package/dist/types/features/soft_navigations/aggregate/index.d.ts +36 -0
  133. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -0
  134. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts +12 -0
  135. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts.map +1 -0
  136. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts +50 -0
  137. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts.map +1 -0
  138. package/dist/types/features/soft_navigations/constants.d.ts +20 -0
  139. package/dist/types/features/soft_navigations/constants.d.ts.map +1 -0
  140. package/dist/types/features/soft_navigations/index.d.ts +2 -0
  141. package/dist/types/features/soft_navigations/index.d.ts.map +1 -0
  142. package/dist/types/features/soft_navigations/instrument/index.d.ts +7 -0
  143. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -0
  144. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  145. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  146. package/dist/types/features/utils/instrument-base.d.ts +1 -7
  147. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  148. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -1
  149. package/dist/types/loaders/agent-base.d.ts +5 -1
  150. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  151. package/dist/types/loaders/agent.d.ts +2 -2
  152. package/dist/types/loaders/agent.d.ts.map +1 -1
  153. package/dist/types/loaders/api/api-methods.d.ts +3 -0
  154. package/dist/types/loaders/api/api-methods.d.ts.map +1 -0
  155. package/dist/types/loaders/api/api.d.ts +3 -6
  156. package/dist/types/loaders/api/api.d.ts.map +1 -1
  157. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  158. package/dist/types/loaders/features/features.d.ts +1 -0
  159. package/dist/types/loaders/features/features.d.ts.map +1 -1
  160. package/dist/types/loaders/micro-agent.d.ts +0 -1
  161. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  162. package/package.json +1 -1
  163. package/src/cdn/experimental.js +4 -2
  164. package/src/cdn/spa.js +3 -1
  165. package/src/common/aggregate/aggregator.js +2 -11
  166. package/src/common/config/state/init.js +3 -1
  167. package/src/common/context/observation-context-manager.js +55 -0
  168. package/src/common/event-emitter/contextual-ee.js +20 -10
  169. package/src/common/session/constants.js +1 -0
  170. package/src/common/session/session-entity.js +3 -1
  171. package/src/common/timing/nav-timing.js +7 -3
  172. package/src/common/timing/now.js +1 -1
  173. package/src/common/util/feature-flags.js +1 -1
  174. package/src/common/wrap/index.js +1 -2
  175. package/src/common/wrap/wrap-events.js +3 -3
  176. package/src/common/wrap/wrap-fetch.js +3 -2
  177. package/src/common/wrap/wrap-function.js +4 -6
  178. package/src/common/wrap/wrap-promise.js +3 -2
  179. package/src/features/ajax/aggregate/index.js +36 -18
  180. package/src/features/jserrors/aggregate/index.js +70 -73
  181. package/src/features/page_view_event/aggregate/index.js +1 -1
  182. package/src/features/page_view_event/aggregate/initialized-features.js +1 -0
  183. package/src/features/session_replay/aggregate/index.js +92 -95
  184. package/src/features/session_replay/constants.js +5 -0
  185. package/src/features/session_replay/instrument/index.js +24 -9
  186. package/src/features/session_replay/shared/recorder.js +5 -4
  187. package/src/features/session_replay/shared/stylesheet-evaluator.js +8 -7
  188. package/src/features/session_replay/shared/utils.js +19 -0
  189. package/src/features/soft_navigations/aggregate/ajax-node.js +57 -0
  190. package/src/features/soft_navigations/aggregate/bel-node.js +26 -0
  191. package/src/features/soft_navigations/aggregate/index.js +254 -0
  192. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +53 -0
  193. package/src/features/soft_navigations/aggregate/interaction.js +159 -0
  194. package/src/features/soft_navigations/constants.js +29 -0
  195. package/src/features/soft_navigations/index.js +1 -0
  196. package/src/features/soft_navigations/instrument/index.js +67 -0
  197. package/src/features/spa/aggregate/index.js +5 -4
  198. package/src/features/utils/agent-session.js +2 -1
  199. package/src/features/utils/instrument-base.js +7 -10
  200. package/src/features/utils/lazy-feature-loader.js +2 -0
  201. package/src/loaders/agent-base.js +18 -3
  202. package/src/loaders/agent.js +18 -17
  203. package/src/loaders/api/api-methods.js +12 -0
  204. package/src/loaders/api/api.js +17 -28
  205. package/src/loaders/configure/configure.js +4 -1
  206. package/src/loaders/features/enabled-features.js +1 -1
  207. package/src/loaders/features/features.js +3 -1
  208. package/dist/cjs/common/wrap/wrap-raf.js +0 -55
  209. package/dist/esm/common/wrap/wrap-raf.js +0 -48
  210. package/dist/types/common/event-emitter/event-context.d.ts.map +0 -1
  211. package/dist/types/common/wrap/wrap-raf.d.ts +0 -16
  212. package/dist/types/common/wrap/wrap-raf.d.ts.map +0 -1
  213. package/src/common/wrap/wrap-raf.js +0 -52
  214. /package/dist/cjs/common/{event-emitter → context}/event-context.js +0 -0
  215. /package/dist/esm/common/{event-emitter → context}/event-context.js +0 -0
  216. /package/dist/types/common/{event-emitter → context}/event-context.d.ts +0 -0
  217. /package/src/common/{event-emitter → context}/event-context.js +0 -0
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Instrument = void 0;
7
+ var _config = require("../../../common/config/config");
8
+ var _runtime = require("../../../common/constants/runtime");
9
+ var _handle = require("../../../common/event-emitter/handle");
10
+ var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
11
+ var _now = require("../../../common/timing/now");
12
+ var _invoke = require("../../../common/util/invoke");
13
+ var _wrap = require("../../../common/wrap");
14
+ var _instrumentBase = require("../../utils/instrument-base");
15
+ var _constants = require("../constants");
16
+ /** The minimal time after a UI event for which no further events will be processed - i.e. a throttling rate to reduce spam.
17
+ * This also give some time for the new interaction to complete without being discarded by a subsequent UI event and wrongly attributed.
18
+ * This value is still subject to change and critique, as it is derived from beyond worst case time to next frame of a page.
19
+ */
20
+ const UI_WAIT_INTERVAL = 1 / 10 * 1000; // assume 10 fps
21
+
22
+ class Instrument extends _instrumentBase.InstrumentBase {
23
+ static featureName = _constants.FEATURE_NAME;
24
+ constructor(agentIdentifier, aggregator) {
25
+ let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
26
+ super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
27
+ if (!_runtime.isBrowserScope || !_config.originals.MO) return; // soft navigations is not supported outside web env or browsers without the mutation observer API
28
+
29
+ const historyEE = (0, _wrap.wrapHistory)(this.ee);
30
+ const eventsEE = (0, _wrap.wrapEvents)(this.ee);
31
+ const trackURLChange = () => (0, _handle.handle)('newURL', [(0, _now.now)(), '' + window.location], undefined, this.featureName, this.ee);
32
+ historyEE.on('pushState-end', trackURLChange);
33
+ historyEE.on('replaceState-end', trackURLChange);
34
+ try {
35
+ this.removeOnAbort = new AbortController();
36
+ } catch (e) {}
37
+ const trackURLChangeEvent = evt => (0, _handle.handle)('newURL', [evt.timeStamp, '' + window.location], undefined, this.featureName, this.ee);
38
+ (0, _eventListenerOpts.windowAddEventListener)('popstate', trackURLChangeEvent, true, this.removeOnAbort?.signal);
39
+ let oncePerFrame = false; // attempt to reduce dom noice since the observer runs very frequently with below options
40
+ const domObserver = new _config.originals.MO((domChanges, observer) => {
41
+ if (oncePerFrame) return;
42
+ oncePerFrame = true;
43
+ requestAnimationFrame(() => {
44
+ // waiting for next frame to time when any visuals are supposedly updated
45
+ (0, _handle.handle)('newDom', [(0, _now.now)()], undefined, this.featureName, this.ee);
46
+ oncePerFrame = false;
47
+ });
48
+ });
49
+ const processUserInteraction = (0, _invoke.debounce)(event => {
50
+ (0, _handle.handle)('newUIEvent', [event], undefined, this.featureName, this.ee);
51
+ domObserver.observe(document.body, {
52
+ attributes: true,
53
+ childList: true,
54
+ subtree: true,
55
+ characterData: true
56
+ });
57
+ }, UI_WAIT_INTERVAL, {
58
+ leading: true
59
+ });
60
+ eventsEE.on('fn-start', _ref => {
61
+ let [evt] = _ref;
62
+ // set up a new user ixn before the callback for the triggering event executes
63
+ if (_constants.INTERACTION_TRIGGERS.includes(evt?.type)) {
64
+ processUserInteraction(evt);
65
+ }
66
+ });
67
+ for (let eventType of _constants.INTERACTION_TRIGGERS) document.addEventListener(eventType, () => {/* no-op, this ensures the UI events are monitored by our callback above */});
68
+ this.abortHandler = abort;
69
+ this.importAggregator({
70
+ domObserver
71
+ });
72
+ function abort() {
73
+ this.removeOnAbort?.abort();
74
+ domObserver.disconnect();
75
+ this.abortHandler = undefined; // weakly allow this abort op to run only once
76
+ }
77
+ }
78
+ }
79
+ exports.Instrument = Instrument;
@@ -656,7 +656,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
656
656
  }
657
657
  function saveInteraction(interaction) {
658
658
  if (interaction.ignored || !interaction.save && !interaction.routeChange) {
659
- baseEE.emit('interactionDiscarded', [interaction]);
659
+ baseEE.emit('interactionDone', [interaction, false]);
660
660
  return;
661
661
  }
662
662
  if (state.prevInteraction === interaction) {
@@ -672,10 +672,10 @@ class Aggregate extends _aggregateBase.AggregateBase {
672
672
  interaction.root.attrs.firstPaint = _firstPaint.firstPaint.current.value;
673
673
  interaction.root.attrs.firstContentfulPaint = _firstContentfulPaint.firstContentfulPaint.current.value;
674
674
  }
675
- baseEE.emit('interactionSaved', [interaction]);
675
+ baseEE.emit('interactionDone', [interaction, true]);
676
676
  state.interactionsToHarvest.push(interaction);
677
- let smCategory = 'RouteChange';
678
- if (interaction.root?.attrs?.trigger === 'initialPageLoad') smCategory = 'InitialPageLoad';else if (interaction.root?.attrs?.trigger === 'api') smCategory = 'Custom';
677
+ let smCategory;
678
+ if (interaction.root?.attrs?.trigger === 'initialPageLoad') smCategory = 'InitialPageLoad';else if (interaction.routeChange) smCategory = 'RouteChange';else smCategory = 'Custom';
679
679
  (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ["Spa/Interaction/".concat(smCategory, "/Duration/Ms"), Math.max((interaction.root?.end || 0) - (interaction.root?.start || 0), 0)], undefined, _features.FEATURE_NAMES.metrics, baseEE);
680
680
  scheduler.scheduleHarvest(0);
681
681
  }
@@ -11,6 +11,7 @@ var _registerHandler = require("../../common/event-emitter/register-handler");
11
11
  var _sessionEntity = require("../../common/session/session-entity");
12
12
  var _localStorage = require("../../common/storage/local-storage.js");
13
13
  var _firstPartyCookies = require("../../common/storage/first-party-cookies");
14
+ var _constants = require("../../common/session/constants");
14
15
  let ranOnce = 0;
15
16
  function setupAgentSession(agentIdentifier) {
16
17
  const agentRuntime = (0, _config.getRuntime)(agentIdentifier);
@@ -21,7 +22,7 @@ function setupAgentSession(agentIdentifier) {
21
22
  const storageTypeInst = sessionInit?.domain ? new _firstPartyCookies.FirstPartyCookies(sessionInit.domain) : new _localStorage.LocalStorage();
22
23
  agentRuntime.session = new _sessionEntity.SessionEntity({
23
24
  agentIdentifier,
24
- key: 'SESSION',
25
+ key: _constants.DEFAULT_KEY,
25
26
  storage: storageTypeInst,
26
27
  expiresMs: sessionInit?.expiresMs,
27
28
  inactiveMs: sessionInit?.inactiveMs
@@ -11,6 +11,7 @@ var _runtime = require("../../common/constants/runtime");
11
11
  var _console = require("../../common/util/console");
12
12
  var _features = require("../../loaders/features/features");
13
13
  var _config = require("../../common/config/config");
14
+ var _utils = require("../session_replay/shared/utils");
14
15
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
16
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
16
17
  * @file Defines `InstrumentBase` to be used as the super of the Instrument classes implemented by each feature.
@@ -78,7 +79,6 @@ class InstrumentBase extends _featureBase.FeatureBase {
78
79
  });
79
80
  return;
80
81
  }
81
- const enableSessionTracking = _runtime.isBrowserScope && (0, _config.getConfigurationValue)(this.agentIdentifier, 'privacy.cookies_enabled') === true;
82
82
  let loadedSuccessfully;
83
83
  this.onAggregateImported = new Promise(resolve => {
84
84
  loadedSuccessfully = resolve;
@@ -86,7 +86,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
86
86
  const importLater = async () => {
87
87
  let session;
88
88
  try {
89
- if (enableSessionTracking) {
89
+ if ((0, _utils.enableSessionTracking)(this.agentIdentifier)) {
90
90
  // would require some setup before certain features start
91
91
  const {
92
92
  setupAgentSession
@@ -95,6 +95,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
95
95
  }
96
96
  } catch (e) {
97
97
  (0, _console.warn)('A problem occurred when starting up session manager. This page will not start or extend any session.', e);
98
+ if (this.featureName === _features.FEATURE_NAMES.sessionReplay) this.abortHandler?.(); // SR should stop recording if session DNE
98
99
  }
99
100
 
100
101
  /**
@@ -102,7 +103,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
102
103
  * it's only responsible for aborting its one specific feature, rather than all.
103
104
  */
104
105
  try {
105
- if (!this.shouldImportAgg(this.featureName, session)) {
106
+ if (!this.#shouldImportAgg(this.featureName, session)) {
106
107
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
107
108
  loadedSuccessfully(false); // aggregate module isn't loaded at all
108
109
  return;
@@ -135,12 +136,8 @@ class InstrumentBase extends _featureBase.FeatureBase {
135
136
  * @param {import('../../common/session/session-entity').SessionEntity} session
136
137
  * @returns
137
138
  */
138
- shouldImportAgg(featureName, session) {
139
- if (featureName === _features.FEATURE_NAMES.sessionReplay) {
140
- if (!_config.originals.MO) return false; // Session Replay cannot work without Mutation Observer
141
- if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'session_trace.enabled') === false) return false; // Session Replay as of now is tightly coupled with Session Trace in the UI
142
- return !!session?.isNew || !!session?.state.sessionReplayMode; // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
143
- }
139
+ #shouldImportAgg(featureName, session) {
140
+ if (featureName === _features.FEATURE_NAMES.sessionReplay) return (0, _utils.canImportReplayAgg)(this.agentIdentifier, session);
144
141
  return true;
145
142
  }
146
143
  }
@@ -39,6 +39,8 @@ function lazyFeatureLoader(featureName, featurePart) {
39
39
  return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "session_trace-aggregate" */'../session_trace/aggregate')));
40
40
  case _features.FEATURE_NAMES.spa:
41
41
  return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "spa-aggregate" */'../spa/aggregate')));
42
+ case _features.FEATURE_NAMES.softNav:
43
+ return Promise.resolve().then(() => _interopRequireWildcard(require( /* webpackChunkName: "basic-spa-aggregate" */'../soft_navigations/aggregate')));
42
44
  default:
43
45
  throw new Error("Attempted to load unsupported agent feature: ".concat(featureName, " ").concat(featurePart));
44
46
  }
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.AgentBase = void 0;
7
7
  var _console = require("../common/util/console");
8
+ var _constants = require("../features/session_replay/constants");
9
+ var _observationContextManager = require("../common/context/observation-context-manager");
10
+ var _uniqueId = require("../common/ids/unique-id");
11
+ var _contextualEe = require("../common/event-emitter/contextual-ee");
8
12
  /* eslint-disable n/handle-callback-err */
9
13
 
10
14
  /**
@@ -12,6 +16,17 @@ var _console = require("../common/util/console");
12
16
  */
13
17
 
14
18
  class AgentBase {
19
+ agentIdentifier;
20
+ observationContext = new _observationContextManager.ObservationContextManager();
21
+ constructor() {
22
+ let agentIdentifier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _uniqueId.generateRandomHexString)(16);
23
+ this.agentIdentifier = agentIdentifier;
24
+
25
+ // Assign the observation context to the event emitter, so it knows how to create observation contexts
26
+ const eventEmitter = _contextualEe.ee.get(agentIdentifier);
27
+ eventEmitter.observationContext = this.observationContext;
28
+ }
29
+
15
30
  /**
16
31
  * Tries to execute the api and generates a generic warning message with the api name injected if unsuccessful
17
32
  * @param {string} methodName
@@ -129,17 +144,17 @@ class AgentBase {
129
144
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordReplay/}
130
145
  */
131
146
  recordReplay() {
132
- return this.#callMethod('recordReplay');
147
+ return this.#callMethod(_constants.SR_EVENT_EMITTER_TYPES.RECORD);
133
148
  }
134
149
 
135
150
  /**
136
151
  * Forces an active replay to pause recording. If a replay is already actively recording, this call will cause the recording to pause.
137
152
  * If a recording is not currently recording, this call will be ignored. This API will pause both manual and automatic replays that are in progress.
138
153
  * The only way to resume recording after manually pausing a replay is to manually record again using the recordReplay() API.
139
- * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordReplay/}
154
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/pauseReplay/}
140
155
  */
141
156
  pauseReplay() {
142
- return this.#callMethod('pauseReplay');
157
+ return this.#callMethod(_constants.SR_EVENT_EMITTER_TYPES.PAUSE);
143
158
  }
144
159
 
145
160
  /**
@@ -14,8 +14,6 @@ var _features = require("./features/features");
14
14
  var _instrument = require("../features/page_view_event/instrument");
15
15
  var _aggregator = require("../common/aggregate/aggregator");
16
16
  var _nreum = require("../common/window/nreum");
17
- var _uniqueId = require("../common/ids/unique-id");
18
- var _config = require("../common/config/config");
19
17
  var _console = require("../common/util/console");
20
18
  var _stringify = require("../common/util/stringify");
21
19
  var _runtime = require("../common/constants/runtime");
@@ -32,37 +30,36 @@ var _runtime = require("../common/constants/runtime");
32
30
  * sensitive to network load, this may result in smaller builds with slightly lower performance impact.
33
31
  */
34
32
  class Agent extends _agentBase.AgentBase {
35
- constructor(options) {
36
- let agentIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _uniqueId.generateRandomHexString)(16);
37
- super();
33
+ constructor(options, agentIdentifier) {
34
+ super(agentIdentifier);
38
35
  if (!_runtime.globalScope) {
39
36
  // We could not determine the runtime environment. Short-circuite the agent here
40
37
  // to avoid possible exceptions later that may cause issues with customer's application.
41
38
  (0, _console.warn)('Failed to initial the agent. Could not determine the runtime environment.');
42
39
  return;
43
40
  }
44
- this.agentIdentifier = agentIdentifier;
45
41
  this.sharedAggregator = new _aggregator.Aggregator({
46
42
  agentIdentifier: this.agentIdentifier
47
43
  });
48
44
  this.features = {};
49
- (0, _nreum.setNREUMInitializedAgent)(agentIdentifier, this); // append this agent onto the global NREUM.initializedAgents
45
+ (0, _nreum.setNREUMInitializedAgent)(this.agentIdentifier, this); // append this agent onto the global NREUM.initializedAgents
50
46
 
51
47
  this.desiredFeatures = new Set(options.features || []); // expected to be a list of static Instrument/InstrumentBase classes, see "spa.js" for example
52
48
  // For Now... ALL agents must make the rum call whether the page_view_event feature was enabled or not.
53
49
  // NR1 creates an index on the rum call, and if not seen for a few days, will remove the browser app!
54
50
  // Future work is being planned to evaluate removing this behavior from the backend, but for now we must ensure this call is made
55
51
  this.desiredFeatures.add(_instrument.Instrument);
52
+ this.runSoftNavOverSpa = [...this.desiredFeatures].some(instr => instr.featureName === _features.FEATURE_NAMES.softNav);
56
53
  (0, _configure.configure)(this, options, options.loaderType || 'agent'); // add api, exposed, and other config properties
57
54
 
58
55
  this.run();
59
56
  }
60
57
  get config() {
61
58
  return {
62
- info: (0, _config.getInfo)(this.agentIdentifier),
63
- init: (0, _config.getConfiguration)(this.agentIdentifier),
64
- loader_config: (0, _config.getLoaderConfig)(this.agentIdentifier),
65
- runtime: (0, _config.getRuntime)(this.agentIdentifier)
59
+ info: this.info,
60
+ init: this.init,
61
+ loader_config: this.loader_config,
62
+ runtime: this.runtime
66
63
  };
67
64
  }
68
65
  run() {
@@ -72,13 +69,13 @@ class Agent extends _agentBase.AgentBase {
72
69
  const featuresToStart = [...this.desiredFeatures];
73
70
  featuresToStart.sort((a, b) => _features.featurePriority[a.featureName] - _features.featurePriority[b.featureName]);
74
71
  featuresToStart.forEach(InstrumentCtor => {
75
- // pageViewEvent must be enabled because RUM calls are not optional. See comment in constructor and PR 428.
76
- if (enabledFeatures[InstrumentCtor.featureName] || InstrumentCtor.featureName === _features.FEATURE_NAMES.pageViewEvent) {
77
- const dependencies = (0, _featureDependencies.getFeatureDependencyNames)(InstrumentCtor.featureName);
78
- const hasAllDeps = dependencies.every(x => enabledFeatures[x]);
79
- if (!hasAllDeps) (0, _console.warn)("".concat(InstrumentCtor.featureName, " is enabled but one or more dependent features has been disabled (").concat((0, _stringify.stringify)(dependencies), "). This may cause unintended consequences or missing data..."));
80
- this.features[InstrumentCtor.featureName] = new InstrumentCtor(this.agentIdentifier, this.sharedAggregator);
81
- }
72
+ if (!enabledFeatures[InstrumentCtor.featureName] && InstrumentCtor.featureName !== _features.FEATURE_NAMES.pageViewEvent) return; // PVE is required to run even if it's marked disabled
73
+ if (this.runSoftNavOverSpa && InstrumentCtor.featureName === _features.FEATURE_NAMES.spa) return;
74
+ if (!this.runSoftNavOverSpa && InstrumentCtor.featureName === _features.FEATURE_NAMES.softNav) return;
75
+ const dependencies = (0, _featureDependencies.getFeatureDependencyNames)(InstrumentCtor.featureName);
76
+ const hasAllDeps = dependencies.every(featName => featName in this.features); // any other feature(s) this depends on should've been initialized on prior iterations by priority order
77
+ if (!hasAllDeps) (0, _console.warn)("".concat(InstrumentCtor.featureName, " is enabled but one or more dependent features has not been initialized (").concat((0, _stringify.stringify)(dependencies), "). This may cause unintended consequences or missing data..."));
78
+ this.features[InstrumentCtor.featureName] = new InstrumentCtor(this.agentIdentifier, this.sharedAggregator);
82
79
  });
83
80
  } catch (err) {
84
81
  (0, _console.warn)('Failed to initialize all enabled instrument classes (agent aborted) -', err);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.asyncApiMethods = exports.apiMethods = void 0;
7
+ var _constants = require("../../features/session_replay/constants");
8
+ const apiMethods = exports.apiMethods = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease', 'addPageAction', 'setCurrentRouteName', 'setPageViewName', 'setCustomAttribute', 'interaction', 'noticeError', 'setUserId', 'setApplicationVersion', 'start', 'recordReplay', 'pauseReplay', _constants.SR_EVENT_EMITTER_TYPES.RECORD, _constants.SR_EVENT_EMITTER_TYPES.PAUSE];
9
+ const asyncApiMethods = exports.asyncApiMethods = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease'];
@@ -3,7 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CUSTOM_ATTR_GROUP = void 0;
7
6
  exports.setAPI = setAPI;
8
7
  exports.setTopLevelCallers = setTopLevelCallers;
9
8
  var _features = require("../features/features");
@@ -17,17 +16,16 @@ var _runtime = require("../../common/constants/runtime");
17
16
  var _console = require("../../common/util/console");
18
17
  var _constants = require("../../features/metrics/constants");
19
18
  var _nreum = require("../../common/window/nreum");
19
+ var _apiMethods = require("./api-methods");
20
+ var _constants2 = require("../../features/session_replay/constants");
20
21
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
22
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /*
22
23
  * Copyright 2020 New Relic Corporation. All rights reserved.
23
24
  * SPDX-License-Identifier: Apache-2.0
24
25
  */
25
- const CUSTOM_ATTR_GROUP = exports.CUSTOM_ATTR_GROUP = 'CUSTOM/'; // the subgroup items should be stored under in storage API
26
-
27
26
  function setTopLevelCallers() {
28
27
  const nr = (0, _nreum.gosCDN)();
29
- const funcs = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease', 'addPageAction', 'setCurrentRouteName', 'setPageViewName', 'setCustomAttribute', 'interaction', 'noticeError', 'setUserId', 'setApplicationVersion', 'start', 'recordReplay', 'pauseReplay'];
30
- funcs.forEach(f => {
28
+ _apiMethods.apiMethods.forEach(f => {
31
29
  nr[f] = function () {
32
30
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
33
31
  args[_key] = arguments[_key];
@@ -49,20 +47,19 @@ function setTopLevelCallers() {
49
47
  }
50
48
  }
51
49
  function setAPI(agentIdentifier, forceDrain) {
50
+ let runSoftNavOverSpa = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
52
51
  if (!forceDrain) (0, _drain.registerDrain)(agentIdentifier, 'api');
53
52
  const apiInterface = {};
54
53
  var instanceEE = _contextualEe.ee.get(agentIdentifier);
55
54
  var tracerEE = instanceEE.get('tracer');
56
- var asyncApiFns = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease'];
57
55
  var prefix = 'api-';
58
56
  var spaPrefix = prefix + 'ixn-';
59
57
 
60
58
  // Setup stub functions that queue calls for later processing.
61
- asyncApiFns.forEach(fnName => {
59
+ _apiMethods.asyncApiMethods.forEach(fnName => {
62
60
  apiInterface[fnName] = apiCall(prefix, fnName, true, 'api');
63
61
  });
64
62
  apiInterface.addPageAction = apiCall(prefix, 'addPageAction', true, _features.FEATURE_NAMES.pageAction);
65
- apiInterface.setCurrentRouteName = apiCall(prefix, 'routeName', true, _features.FEATURE_NAMES.spa);
66
63
  apiInterface.setPageViewName = function (name, host) {
67
64
  if (typeof name !== 'string') return;
68
65
  if (name.charAt(0) !== '/') name = '/' + name;
@@ -147,25 +144,26 @@ function setAPI(agentIdentifier, forceDrain) {
147
144
  (0, _console.warn)('An unexpected issue occurred', err);
148
145
  }
149
146
  };
150
- apiInterface.recordReplay = function () {
147
+ apiInterface[_constants2.SR_EVENT_EMITTER_TYPES.RECORD] = function () {
151
148
  (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['API/recordReplay/called'], undefined, _features.FEATURE_NAMES.metrics, instanceEE);
152
- (0, _handle.handle)('recordReplay', [], undefined, _features.FEATURE_NAMES.sessionReplay, instanceEE);
149
+ (0, _handle.handle)(_constants2.SR_EVENT_EMITTER_TYPES.RECORD, [], undefined, _features.FEATURE_NAMES.sessionReplay, instanceEE);
153
150
  };
154
- apiInterface.pauseReplay = function () {
151
+ apiInterface[_constants2.SR_EVENT_EMITTER_TYPES.PAUSE] = function () {
155
152
  (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['API/pauseReplay/called'], undefined, _features.FEATURE_NAMES.metrics, instanceEE);
156
- (0, _handle.handle)('pauseReplay', [], undefined, _features.FEATURE_NAMES.sessionReplay, instanceEE);
153
+ (0, _handle.handle)(_constants2.SR_EVENT_EMITTER_TYPES.PAUSE, [], undefined, _features.FEATURE_NAMES.sessionReplay, instanceEE);
157
154
  };
158
- apiInterface.interaction = function () {
159
- return new InteractionHandle().get();
155
+ apiInterface.interaction = function (options) {
156
+ return new InteractionHandle().get(typeof options === 'object' ? options : {});
160
157
  };
161
158
  function InteractionHandle() {}
162
- var InteractionApiProto = InteractionHandle.prototype = {
159
+ const InteractionApiProto = InteractionHandle.prototype = {
163
160
  createTracer: function (name, cb) {
164
161
  var contextStore = {};
165
162
  var ixn = this;
166
163
  var hasCb = typeof cb === 'function';
167
164
  (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['API/createTracer/called'], undefined, _features.FEATURE_NAMES.metrics, instanceEE);
168
- (0, _handle.handle)(spaPrefix + 'tracer', [(0, _now.now)(), name, contextStore], ixn, _features.FEATURE_NAMES.spa, instanceEE);
165
+ // Soft navigations won't support Tracer nodes, but this fn should still work the same otherwise (e.g., run the orig cb).
166
+ if (!runSoftNavOverSpa) (0, _handle.handle)(spaPrefix + 'tracer', [(0, _now.now)(), name, contextStore], ixn, _features.FEATURE_NAMES.spa, instanceEE);
169
167
  return function () {
170
168
  tracerEE.emit((hasCb ? '' : 'no-') + 'fn-start', [(0, _now.now)(), ixn, hasCb], contextStore);
171
169
  if (hasCb) {
@@ -183,13 +181,14 @@ function setAPI(agentIdentifier, forceDrain) {
183
181
  }
184
182
  };
185
183
  ['actionText', 'setName', 'setAttribute', 'save', 'ignore', 'onEnd', 'getContext', 'end', 'get'].forEach(name => {
186
- InteractionApiProto[name] = apiCall(spaPrefix, name, undefined, _features.FEATURE_NAMES.spa);
184
+ InteractionApiProto[name] = apiCall(spaPrefix, name, undefined, runSoftNavOverSpa ? _features.FEATURE_NAMES.softNav : _features.FEATURE_NAMES.spa);
187
185
  });
186
+ apiInterface.setCurrentRouteName = runSoftNavOverSpa ? apiCall(spaPrefix, 'routeName', undefined, _features.FEATURE_NAMES.softNav) : apiCall(prefix, 'routeName', true, _features.FEATURE_NAMES.spa);
188
187
  function apiCall(prefix, name, notSpa, bufferGroup) {
189
188
  return function () {
190
189
  (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['API/' + name + '/called'], undefined, _features.FEATURE_NAMES.metrics, instanceEE);
191
190
  if (bufferGroup) (0, _handle.handle)(prefix + name, [(0, _now.now)(), ...arguments], notSpa ? null : this, bufferGroup, instanceEE); // no bufferGroup means only the SM is emitted
192
- return notSpa ? undefined : this;
191
+ return notSpa ? undefined : this; // returns the InteractionHandle which allows these methods to be chained
193
192
  };
194
193
  }
195
194
  apiInterface.noticeError = function (err, customAttributes) {
@@ -9,7 +9,7 @@ var _nreum = require("../../common/window/nreum");
9
9
  var _config = require("../../common/config/config");
10
10
  var _featureFlags = require("../../common/util/feature-flags");
11
11
  var _runtime = require("../../common/constants/runtime");
12
- var _publicPath = require("./public-path");
12
+ var _publicPath = require("./public-path.npm");
13
13
  let alreadySetOnce = false; // the configure() function can run multiple times in agent lifecycle
14
14
 
15
15
  /**
@@ -55,10 +55,13 @@ function configure(agent) {
55
55
  if (updatedInit.proxy.beacon) internalTrafficList.push(updatedInit.proxy.beacon);
56
56
  (0, _api.setTopLevelCallers)(); // no need to set global APIs on newrelic obj more than once
57
57
  (0, _nreum.addToNREUM)('activatedFeatures', _featureFlags.activatedFeatures);
58
+
59
+ // Update if soft_navigations is allowed to run AND part of this agent build, used to override old spa functions.
60
+ agent.runSoftNavOverSpa &&= updatedInit.soft_navigations.enabled === true && updatedInit.feature_flags.includes('soft_nav');
58
61
  }
59
62
  runtime.denyList = [...(updatedInit.ajax.deny_list || []), ...(updatedInit.ajax.block_internal ? internalTrafficList : [])];
60
63
  (0, _config.setRuntime)(agent.agentIdentifier, runtime);
61
- if (agent.api === undefined) agent.api = (0, _api.setAPI)(agent.agentIdentifier, forceDrain);
64
+ if (agent.api === undefined) agent.api = (0, _api.setAPI)(agent.agentIdentifier, forceDrain, agent.runSoftNavOverSpa);
62
65
  if (agent.exposed === undefined) agent.exposed = exposed;
63
66
  alreadySetOnce = true;
64
67
  }
@@ -8,7 +8,7 @@ var _features = require("./features");
8
8
  var _config = require("../../common/config/config");
9
9
  const featureNames = Object.values(_features.FEATURE_NAMES);
10
10
  function isEnabled(name, agentIdentifier) {
11
- return (0, _config.getConfigurationValue)(agentIdentifier, "".concat(name, ".enabled")) !== false;
11
+ return (0, _config.getConfigurationValue)(agentIdentifier, "".concat(name, ".enabled")) === true;
12
12
  }
13
13
  function getEnabledFeatures(agentIdentifier) {
14
14
  const enabledFeatures = {};
@@ -13,6 +13,7 @@ const FEATURE_NAMES = exports.FEATURE_NAMES = {
13
13
  pageViewTiming: 'page_view_timing',
14
14
  sessionReplay: 'session_replay',
15
15
  sessionTrace: 'session_trace',
16
+ softNav: 'soft_navigations',
16
17
  spa: 'spa'
17
18
  };
18
19
 
@@ -29,5 +30,6 @@ const featurePriority = exports.featurePriority = {
29
30
  [FEATURE_NAMES.sessionTrace]: 6,
30
31
  [FEATURE_NAMES.pageAction]: 7,
31
32
  [FEATURE_NAMES.spa]: 8,
32
- [FEATURE_NAMES.sessionReplay]: 9
33
+ [FEATURE_NAMES.softNav]: 9,
34
+ [FEATURE_NAMES.sessionReplay]: 10
33
35
  };
@@ -16,9 +16,12 @@ import { Instrument as InstrumentErrors } from '../features/jserrors/instrument'
16
16
  import { Instrument as InstrumentXhr } from '../features/ajax/instrument';
17
17
  import { Instrument as InstrumentSessionTrace } from '../features/session_trace/instrument';
18
18
  import { Instrument as InstrumentSessionReplay } from '../features/session_replay/instrument';
19
- import { Instrument as InstrumentSpa } from '../features/spa/instrument';
19
+ // import { Instrument as InstrumentSpa } from '../features/spa/instrument'
20
+ import { Instrument as InstrumentSoftNav } from '../features/soft_navigations/instrument';
20
21
  import { Instrument as InstrumentPageAction } from '../features/page_action/instrument';
21
22
  new Agent({
22
- features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentSessionReplay, InstrumentMetrics, InstrumentPageAction, InstrumentErrors, InstrumentSpa],
23
+ features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentSessionReplay, InstrumentMetrics, InstrumentPageAction, InstrumentErrors,
24
+ // InstrumentSpa,
25
+ InstrumentSoftNav],
23
26
  loaderType: 'experimental'
24
27
  });
@@ -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
  };
@@ -6,7 +6,7 @@
6
6
  /**
7
7
  * Exposes the version of the agent
8
8
  */
9
- export const VERSION = "1.252.0";
9
+ export const VERSION = "1.253.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.0";
9
+ export const VERSION = "1.253.0";
10
10
 
11
11
  /**
12
12
  * Exposes the build type of the agent
@@ -0,0 +1,49 @@
1
+ import { gosNREUM } from '../window/nreum';
2
+ import { bundleId } from '../ids/bundle-id';
3
+ import { EventContext } from './event-context';
4
+ export class ObservationContextManager {
5
+ // These IDs are provided for backwards compatibility until the agent is fully updated
6
+ // use the observation context class.
7
+
8
+ static contextId = "nr@context:".concat(bundleId);
9
+ static contextOriginalId = "nr@original:".concat(bundleId);
10
+ static contextWrappedId = "nr@wrapped:".concat(ObservationContextManager.contextId);
11
+ static getObservationContextByAgentIdentifier(agentIdentifier) {
12
+ const nr = gosNREUM();
13
+ return Object.keys(nr?.initializedAgents || {}).indexOf(agentIdentifier) > -1 ? nr.initializedAgents[agentIdentifier].observationContext : undefined;
14
+ }
15
+
16
+ /**
17
+ * @type {WeakMap<WeakKey, {[key: string]: unknown}>}
18
+ */
19
+ #observationContext = new WeakMap();
20
+
21
+ /**
22
+ * Returns the observation context tied to the supplied construct. If there has been
23
+ * no observation construct created, an empty object is created and stored as the current
24
+ * context.
25
+ * @param key {unknown} The construct being observed such as an XHR instance
26
+ * @return {EventContext} An object of key:value pairs to track as
27
+ * part of the observation
28
+ */
29
+ getCreateContext(key) {
30
+ if (!this.#observationContext.has(key)) {
31
+ this.#observationContext.set(key, new EventContext());
32
+ }
33
+ return this.#observationContext.get(key);
34
+ }
35
+
36
+ /**
37
+ * Set the observation context for an observed construct. If values of the context
38
+ * need to be updated, they should be done so directly on the context. This function
39
+ * is only for the setting of a whole context.
40
+ * @param key {unknown} The construct being observed such as an XHR instance
41
+ * @param value {EventContext} An object of key:value pairs to track as
42
+ * part of the observation
43
+ * @return {EventContext} The updated observation context
44
+ */
45
+ setContext(key, value) {
46
+ this.#observationContext.set(key, value);
47
+ return this.#observationContext.get(key);
48
+ }
49
+ }