@newrelic/browser-agent 1.252.1 → 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 (203) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +1 -1
  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/timing/nav-timing.js +8 -3
  13. package/dist/cjs/common/timing/now.js +1 -1
  14. package/dist/cjs/common/util/feature-flags.js +1 -1
  15. package/dist/cjs/common/wrap/index.js +0 -7
  16. package/dist/cjs/common/wrap/wrap-events.js +2 -2
  17. package/dist/cjs/common/wrap/wrap-fetch.js +2 -1
  18. package/dist/cjs/common/wrap/wrap-function.js +5 -7
  19. package/dist/cjs/common/wrap/wrap-promise.js +2 -1
  20. package/dist/cjs/features/ajax/aggregate/index.js +34 -16
  21. package/dist/cjs/features/jserrors/aggregate/index.js +77 -66
  22. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -1
  23. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -0
  24. package/dist/cjs/features/session_replay/aggregate/index.js +96 -94
  25. package/dist/cjs/features/session_replay/constants.js +5 -1
  26. package/dist/cjs/features/session_replay/instrument/index.js +24 -8
  27. package/dist/cjs/features/session_replay/shared/utils.js +26 -0
  28. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +50 -0
  29. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +29 -0
  30. package/dist/cjs/features/soft_navigations/aggregate/index.js +263 -0
  31. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +62 -0
  32. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +146 -0
  33. package/dist/cjs/features/soft_navigations/constants.js +31 -0
  34. package/dist/cjs/features/soft_navigations/index.js +12 -0
  35. package/dist/cjs/features/soft_navigations/instrument/index.js +79 -0
  36. package/dist/cjs/features/spa/aggregate/index.js +4 -4
  37. package/dist/cjs/features/utils/agent-session.js +2 -1
  38. package/dist/cjs/features/utils/instrument-base.js +6 -9
  39. package/dist/cjs/features/utils/lazy-feature-loader.js +2 -0
  40. package/dist/cjs/loaders/agent-base.js +18 -3
  41. package/dist/cjs/loaders/agent.js +15 -18
  42. package/dist/cjs/loaders/api/api-methods.js +2 -1
  43. package/dist/cjs/loaders/api/api.js +14 -11
  44. package/dist/cjs/loaders/configure/configure.js +4 -1
  45. package/dist/cjs/loaders/features/enabled-features.js +1 -1
  46. package/dist/cjs/loaders/features/features.js +3 -1
  47. package/dist/esm/cdn/experimental.js +5 -2
  48. package/dist/esm/cdn/spa.js +3 -1
  49. package/dist/esm/common/aggregate/aggregator.js +1 -8
  50. package/dist/esm/common/config/state/init.js +7 -0
  51. package/dist/esm/common/constants/env.cdn.js +1 -1
  52. package/dist/esm/common/constants/env.npm.js +1 -1
  53. package/dist/esm/common/context/observation-context-manager.js +49 -0
  54. package/dist/esm/common/event-emitter/contextual-ee.js +12 -9
  55. package/dist/esm/common/session/constants.js +1 -0
  56. package/dist/esm/common/timing/nav-timing.js +8 -3
  57. package/dist/esm/common/timing/now.js +1 -1
  58. package/dist/esm/common/util/feature-flags.js +1 -1
  59. package/dist/esm/common/wrap/index.js +1 -2
  60. package/dist/esm/common/wrap/wrap-events.js +3 -3
  61. package/dist/esm/common/wrap/wrap-fetch.js +3 -2
  62. package/dist/esm/common/wrap/wrap-function.js +4 -5
  63. package/dist/esm/common/wrap/wrap-promise.js +3 -2
  64. package/dist/esm/features/ajax/aggregate/index.js +36 -18
  65. package/dist/esm/features/jserrors/aggregate/index.js +77 -66
  66. package/dist/esm/features/page_view_event/aggregate/index.js +1 -1
  67. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -0
  68. package/dist/esm/features/session_replay/aggregate/index.js +97 -95
  69. package/dist/esm/features/session_replay/constants.js +4 -0
  70. package/dist/esm/features/session_replay/instrument/index.js +25 -9
  71. package/dist/esm/features/session_replay/shared/utils.js +17 -0
  72. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +43 -0
  73. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +22 -0
  74. package/dist/esm/features/soft_navigations/aggregate/index.js +256 -0
  75. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +55 -0
  76. package/dist/esm/features/soft_navigations/aggregate/interaction.js +140 -0
  77. package/dist/esm/features/soft_navigations/constants.js +25 -0
  78. package/dist/esm/features/soft_navigations/index.js +1 -0
  79. package/dist/esm/features/soft_navigations/instrument/index.js +73 -0
  80. package/dist/esm/features/spa/aggregate/index.js +4 -4
  81. package/dist/esm/features/utils/agent-session.js +2 -1
  82. package/dist/esm/features/utils/instrument-base.js +7 -10
  83. package/dist/esm/features/utils/lazy-feature-loader.js +2 -0
  84. package/dist/esm/loaders/agent-base.js +18 -3
  85. package/dist/esm/loaders/agent.js +15 -18
  86. package/dist/esm/loaders/api/api-methods.js +2 -1
  87. package/dist/esm/loaders/api/api.js +14 -11
  88. package/dist/esm/loaders/configure/configure.js +4 -1
  89. package/dist/esm/loaders/features/enabled-features.js +1 -1
  90. package/dist/esm/loaders/features/features.js +3 -1
  91. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  92. package/dist/types/common/config/state/init.d.ts.map +1 -1
  93. package/dist/types/common/context/event-context.d.ts.map +1 -0
  94. package/dist/types/common/context/observation-context-manager.d.ts +28 -0
  95. package/dist/types/common/context/observation-context-manager.d.ts.map +1 -0
  96. package/dist/types/common/event-emitter/contextual-ee.d.ts +2 -2
  97. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
  98. package/dist/types/common/session/constants.d.ts +1 -0
  99. package/dist/types/common/session/constants.d.ts.map +1 -1
  100. package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
  101. package/dist/types/common/wrap/index.d.ts +1 -2
  102. package/dist/types/common/wrap/index.d.ts.map +1 -1
  103. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  104. package/dist/types/common/wrap/wrap-function.d.ts +0 -1
  105. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  106. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  107. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  108. package/dist/types/features/jserrors/aggregate/index.d.ts +4 -3
  109. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  110. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
  111. package/dist/types/features/session_replay/aggregate/index.d.ts +1 -1
  112. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  113. package/dist/types/features/session_replay/constants.d.ts +4 -0
  114. package/dist/types/features/session_replay/constants.d.ts.map +1 -1
  115. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  116. package/dist/types/features/session_replay/shared/utils.d.ts +4 -0
  117. package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -0
  118. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts +19 -0
  119. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts.map +1 -0
  120. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts +16 -0
  121. package/dist/types/features/soft_navigations/aggregate/bel-node.d.ts.map +1 -0
  122. package/dist/types/features/soft_navigations/aggregate/index.d.ts +36 -0
  123. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -0
  124. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts +12 -0
  125. package/dist/types/features/soft_navigations/aggregate/initial-page-load-interaction.d.ts.map +1 -0
  126. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts +50 -0
  127. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts.map +1 -0
  128. package/dist/types/features/soft_navigations/constants.d.ts +20 -0
  129. package/dist/types/features/soft_navigations/constants.d.ts.map +1 -0
  130. package/dist/types/features/soft_navigations/index.d.ts +2 -0
  131. package/dist/types/features/soft_navigations/index.d.ts.map +1 -0
  132. package/dist/types/features/soft_navigations/instrument/index.d.ts +7 -0
  133. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -0
  134. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  135. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  136. package/dist/types/features/utils/instrument-base.d.ts +1 -7
  137. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  138. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -1
  139. package/dist/types/loaders/agent-base.d.ts +5 -1
  140. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  141. package/dist/types/loaders/agent.d.ts +2 -2
  142. package/dist/types/loaders/agent.d.ts.map +1 -1
  143. package/dist/types/loaders/api/api-methods.d.ts.map +1 -1
  144. package/dist/types/loaders/api/api.d.ts +3 -5
  145. package/dist/types/loaders/api/api.d.ts.map +1 -1
  146. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  147. package/dist/types/loaders/features/features.d.ts +1 -0
  148. package/dist/types/loaders/features/features.d.ts.map +1 -1
  149. package/dist/types/loaders/micro-agent.d.ts +0 -1
  150. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  151. package/package.json +1 -1
  152. package/src/cdn/experimental.js +4 -2
  153. package/src/cdn/spa.js +3 -1
  154. package/src/common/aggregate/aggregator.js +2 -11
  155. package/src/common/config/state/init.js +3 -1
  156. package/src/common/context/observation-context-manager.js +55 -0
  157. package/src/common/event-emitter/contextual-ee.js +20 -10
  158. package/src/common/session/constants.js +1 -0
  159. package/src/common/timing/nav-timing.js +7 -3
  160. package/src/common/timing/now.js +1 -1
  161. package/src/common/util/feature-flags.js +1 -1
  162. package/src/common/wrap/index.js +1 -2
  163. package/src/common/wrap/wrap-events.js +3 -3
  164. package/src/common/wrap/wrap-fetch.js +3 -2
  165. package/src/common/wrap/wrap-function.js +4 -6
  166. package/src/common/wrap/wrap-promise.js +3 -2
  167. package/src/features/ajax/aggregate/index.js +36 -18
  168. package/src/features/jserrors/aggregate/index.js +70 -73
  169. package/src/features/page_view_event/aggregate/index.js +1 -1
  170. package/src/features/page_view_event/aggregate/initialized-features.js +1 -0
  171. package/src/features/session_replay/aggregate/index.js +92 -95
  172. package/src/features/session_replay/constants.js +5 -0
  173. package/src/features/session_replay/instrument/index.js +24 -9
  174. package/src/features/session_replay/shared/utils.js +19 -0
  175. package/src/features/soft_navigations/aggregate/ajax-node.js +57 -0
  176. package/src/features/soft_navigations/aggregate/bel-node.js +26 -0
  177. package/src/features/soft_navigations/aggregate/index.js +254 -0
  178. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +53 -0
  179. package/src/features/soft_navigations/aggregate/interaction.js +159 -0
  180. package/src/features/soft_navigations/constants.js +29 -0
  181. package/src/features/soft_navigations/index.js +1 -0
  182. package/src/features/soft_navigations/instrument/index.js +67 -0
  183. package/src/features/spa/aggregate/index.js +5 -4
  184. package/src/features/utils/agent-session.js +2 -1
  185. package/src/features/utils/instrument-base.js +7 -10
  186. package/src/features/utils/lazy-feature-loader.js +2 -0
  187. package/src/loaders/agent-base.js +18 -3
  188. package/src/loaders/agent.js +18 -17
  189. package/src/loaders/api/api-methods.js +4 -1
  190. package/src/loaders/api/api.js +14 -12
  191. package/src/loaders/configure/configure.js +4 -1
  192. package/src/loaders/features/enabled-features.js +1 -1
  193. package/src/loaders/features/features.js +3 -1
  194. package/dist/cjs/common/wrap/wrap-raf.js +0 -55
  195. package/dist/esm/common/wrap/wrap-raf.js +0 -48
  196. package/dist/types/common/event-emitter/event-context.d.ts.map +0 -1
  197. package/dist/types/common/wrap/wrap-raf.d.ts +0 -16
  198. package/dist/types/common/wrap/wrap-raf.d.ts.map +0 -1
  199. package/src/common/wrap/wrap-raf.js +0 -52
  200. /package/dist/cjs/common/{event-emitter → context}/event-context.js +0 -0
  201. /package/dist/esm/common/{event-emitter → context}/event-context.js +0 -0
  202. /package/dist/types/common/{event-emitter → context}/event-context.d.ts +0 -0
  203. /package/src/common/{event-emitter → context}/event-context.js +0 -0
package/CHANGELOG.md CHANGED
@@ -3,6 +3,16 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.253.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.252.1...v1.253.0) (2024-03-13)
7
+
8
+
9
+ ### Features
10
+
11
+ * Apply deny list to ajax metrics ([#898](https://github.com/newrelic/newrelic-browser-agent/issues/898)) ([a5c2adc](https://github.com/newrelic/newrelic-browser-agent/commit/a5c2adc0ecbe322ea9a9dcdf1ed3b072c1212415))
12
+ * Isolate observation context per agent ([#903](https://github.com/newrelic/newrelic-browser-agent/issues/903)) ([85887c8](https://github.com/newrelic/newrelic-browser-agent/commit/85887c8e7f4241076daeeda75077e6ee710a3d00))
13
+ * Preload the Session Replay recorder when properly configured ([#893](https://github.com/newrelic/newrelic-browser-agent/issues/893)) ([bc5ebb5](https://github.com/newrelic/newrelic-browser-agent/commit/bc5ebb5cb255fda7f2c30d5053b5a980a423c2b1))
14
+ * Soft Navigations trial ([#808](https://github.com/newrelic/newrelic-browser-agent/issues/808)) ([7fcb627](https://github.com/newrelic/newrelic-browser-agent/commit/7fcb62791ad932cbd3b9f16a72277b42bca9a75f))
15
+
6
16
  ## [1.252.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.252.0...v1.252.1) (2024-02-29)
7
17
 
8
18
 
package/README.md CHANGED
@@ -33,7 +33,7 @@ Before instrumenting your app using the NPM package, a Browser App should be con
33
33
  - Select the *Browser monitoring* data source.
34
34
  - Choose the *APM* or *Copy/Paste* method.
35
35
  - Select or name your app and click *Enable*.
36
- 2. From the navigation panel, select *Browser* to view brower apps.
36
+ 2. From the navigation panel, select *Browser* to view browser apps.
37
37
  3. Select the desired app and navigate to the *Application settings* page.
38
38
  4. From the *Copy/Paste JavaScript* box, copy the configuration values assigned to the `NREUM` object (`init`, `info`, and `loader_config`). You will use these configuration values when instantiating the agent using the NPM package.
39
39
 
@@ -8,7 +8,7 @@ var _instrument4 = require("../features/jserrors/instrument");
8
8
  var _instrument5 = require("../features/ajax/instrument");
9
9
  var _instrument6 = require("../features/session_trace/instrument");
10
10
  var _instrument7 = require("../features/session_replay/instrument");
11
- var _instrument8 = require("../features/spa/instrument");
11
+ var _instrument8 = require("../features/soft_navigations/instrument");
12
12
  var _instrument9 = require("../features/page_action/instrument");
13
13
  /*
14
14
  * Copyright 2023 New Relic Corporation. All rights reserved.
@@ -21,7 +21,11 @@ var _instrument9 = require("../features/page_action/instrument");
21
21
  * It is not production ready, and is not intended to be imported or implemented in any build of the browser agent
22
22
  */
23
23
 
24
+ // import { Instrument as InstrumentSpa } from '../features/spa/instrument'
25
+
24
26
  new _agent.Agent({
25
- features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument7.Instrument, _instrument3.Instrument, _instrument9.Instrument, _instrument4.Instrument, _instrument8.Instrument],
27
+ features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument7.Instrument, _instrument3.Instrument, _instrument9.Instrument, _instrument4.Instrument,
28
+ // InstrumentSpa,
29
+ _instrument8.Instrument],
26
30
  loaderType: 'experimental'
27
31
  });
@@ -8,13 +8,15 @@ var _instrument4 = require("../features/jserrors/instrument");
8
8
  var _instrument5 = require("../features/ajax/instrument");
9
9
  var _instrument6 = require("../features/session_trace/instrument");
10
10
  var _instrument7 = require("../features/session_replay/instrument");
11
- var _instrument8 = require("../features/spa/instrument");
12
- var _instrument9 = require("../features/page_action/instrument");
11
+ var _instrument8 = require("../features/soft_navigations/instrument");
12
+ var _instrument9 = require("../features/spa/instrument");
13
+ var _instrument10 = require("../features/page_action/instrument");
13
14
  /**
14
15
  * @file Creates a "SPA" agent loader bundle composed of the core agent and all available feature modules.
15
16
  */
16
17
 
17
18
  new _agent.Agent({
18
- features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument7.Instrument, _instrument3.Instrument, _instrument9.Instrument, _instrument4.Instrument, _instrument8.Instrument],
19
+ features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument7.Instrument, _instrument3.Instrument, _instrument10.Instrument, _instrument4.Instrument, _instrument8.Instrument, _instrument9.Instrument // 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
20
+ ],
19
21
  loaderType: 'spa'
20
22
  });
@@ -83,7 +83,7 @@ class Aggregator extends _sharedContext.SharedContext {
83
83
  var hasData = false;
84
84
  for (var i = 0; i < types.length; i++) {
85
85
  type = types[i];
86
- results[type] = toArray(this.aggregatedData[type]);
86
+ results[type] = Object.values(this.aggregatedData[type] || {});
87
87
  if (results[type].length) hasData = true;
88
88
  delete this.aggregatedData[type];
89
89
  }
@@ -158,11 +158,4 @@ function createMetricObject(value) {
158
158
  sos: value * value,
159
159
  c: 1
160
160
  };
161
- }
162
- function toArray(obj) {
163
- if (typeof obj !== 'object') return [];
164
- return (0, _mapOwn.mapOwn)(obj, getValue);
165
- }
166
- function getValue(key, value) {
167
- return value;
168
161
  }
@@ -106,6 +106,8 @@ const model = () => {
106
106
  autoStart: true,
107
107
  enabled: false,
108
108
  harvestTimeSeconds: 60,
109
+ preload: false,
110
+ // if true, enables the agent to load rrweb immediately instead of waiting to do so after the window.load event
109
111
  sampling_rate: 10,
110
112
  // float from 0 - 100
111
113
  error_sampling_rate: 100,
@@ -158,6 +160,11 @@ const model = () => {
158
160
  enabled: true,
159
161
  harvestTimeSeconds: 10,
160
162
  autoStart: true
163
+ },
164
+ soft_navigations: {
165
+ enabled: true,
166
+ harvestTimeSeconds: 10,
167
+ autoStart: true
161
168
  }
162
169
  };
163
170
  };
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.252.1";
15
+ const VERSION = exports.VERSION = "1.253.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
12
12
  /**
13
13
  * Exposes the version of the agent
14
14
  */
15
- const VERSION = exports.VERSION = "1.252.1";
15
+ const VERSION = exports.VERSION = "1.253.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ObservationContextManager = void 0;
7
+ var _nreum = require("../window/nreum");
8
+ var _bundleId = require("../ids/bundle-id");
9
+ var _eventContext = require("./event-context");
10
+ class ObservationContextManager {
11
+ // These IDs are provided for backwards compatibility until the agent is fully updated
12
+ // use the observation context class.
13
+
14
+ static contextId = "nr@context:".concat(_bundleId.bundleId);
15
+ static contextOriginalId = "nr@original:".concat(_bundleId.bundleId);
16
+ static contextWrappedId = "nr@wrapped:".concat(ObservationContextManager.contextId);
17
+ static getObservationContextByAgentIdentifier(agentIdentifier) {
18
+ const nr = (0, _nreum.gosNREUM)();
19
+ return Object.keys(nr?.initializedAgents || {}).indexOf(agentIdentifier) > -1 ? nr.initializedAgents[agentIdentifier].observationContext : undefined;
20
+ }
21
+
22
+ /**
23
+ * @type {WeakMap<WeakKey, {[key: string]: unknown}>}
24
+ */
25
+ #observationContext = new WeakMap();
26
+
27
+ /**
28
+ * Returns the observation context tied to the supplied construct. If there has been
29
+ * no observation construct created, an empty object is created and stored as the current
30
+ * context.
31
+ * @param key {unknown} The construct being observed such as an XHR instance
32
+ * @return {EventContext} An object of key:value pairs to track as
33
+ * part of the observation
34
+ */
35
+ getCreateContext(key) {
36
+ if (!this.#observationContext.has(key)) {
37
+ this.#observationContext.set(key, new _eventContext.EventContext());
38
+ }
39
+ return this.#observationContext.get(key);
40
+ }
41
+
42
+ /**
43
+ * Set the observation context for an observed construct. If values of the context
44
+ * need to be updated, they should be done so directly on the context. This function
45
+ * is only for the setting of a whole context.
46
+ * @param key {unknown} The construct being observed such as an XHR instance
47
+ * @param value {EventContext} An object of key:value pairs to track as
48
+ * part of the observation
49
+ * @return {EventContext} The updated observation context
50
+ */
51
+ setContext(key, value) {
52
+ this.#observationContext.set(key, value);
53
+ return this.#observationContext.get(key);
54
+ }
55
+ }
56
+ exports.ObservationContextManager = ObservationContextManager;
@@ -3,19 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ee = exports.contextId = void 0;
6
+ exports.ee = void 0;
7
7
  var _nreum = require("../window/nreum");
8
8
  var _getOrSet = require("../util/get-or-set");
9
9
  var _config = require("../config/config");
10
- var _eventContext = require("./event-context");
11
- var _bundleId = require("../ids/bundle-id");
10
+ var _eventContext = require("../context/event-context");
11
+ var _observationContextManager = require("../context/observation-context-manager");
12
12
  /*
13
13
  * Copyright 2020 New Relic Corporation. All rights reserved.
14
14
  * SPDX-License-Identifier: Apache-2.0
15
15
  */
16
16
 
17
- // create a unique id to store event context data for the current agent bundle
18
- const contextId = exports.contextId = "nr@context:".concat(_bundleId.bundleId);
19
17
  // create global emitter instance that can be shared among bundles
20
18
  const globalInstance = exports.ee = ee(undefined, 'globalEE');
21
19
 
@@ -53,16 +51,17 @@ function ee(old, debugId) {
53
51
  aborted: false,
54
52
  isBuffering,
55
53
  debugId,
56
- backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
54
+ backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {},
55
+ observationContextManager: null
57
56
  };
58
57
  return emitter;
59
58
  function context(contextOrStore) {
60
59
  if (contextOrStore && contextOrStore instanceof _eventContext.EventContext) {
61
60
  return contextOrStore;
62
61
  } else if (contextOrStore) {
63
- return (0, _getOrSet.getOrSet)(contextOrStore, contextId, () => new _eventContext.EventContext(contextId));
62
+ return (0, _getOrSet.getOrSet)(contextOrStore, _observationContextManager.ObservationContextManager.contextId, () => emitter.observationContextManager ? emitter.observationContextManager.getCreateContext(contextOrStore) : new _eventContext.EventContext(_observationContextManager.ObservationContextManager.contextId));
64
63
  } else {
65
- return new _eventContext.EventContext(contextId);
64
+ return emitter.observationContextManager ? emitter.observationContextManager.getCreateContext({}) : new _eventContext.EventContext(_observationContextManager.ObservationContextManager.contextId);
66
65
  }
67
66
  }
68
67
  function emit(type, args, contextOrStore, force, bubble) {
@@ -106,7 +105,11 @@ function ee(old, debugId) {
106
105
  return handlers[type] || [];
107
106
  }
108
107
  function getOrCreate(name) {
109
- return emitters[name] = emitters[name] || ee(emitter, name);
108
+ const newEventEmitter = emitters[name] = emitters[name] || ee(emitter, name);
109
+ if (!newEventEmitter.observationContextManager && emitter.observationContextManager) {
110
+ newEventEmitter.observationContextManager = emitter.observationContextManager;
111
+ }
112
+ return newEventEmitter;
110
113
  }
111
114
  function bufferEventsByGroup(types, group) {
112
115
  const eventBuffer = getBuffer();
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SESSION_EVENT_TYPES = exports.SESSION_EVENTS = exports.PREFIX = exports.MODE = exports.DEFAULT_INACTIVE_MS = exports.DEFAULT_EXPIRES_MS = void 0;
6
+ exports.SESSION_EVENT_TYPES = exports.SESSION_EVENTS = exports.PREFIX = exports.MODE = exports.DEFAULT_KEY = exports.DEFAULT_INACTIVE_MS = exports.DEFAULT_EXPIRES_MS = void 0;
7
7
  const PREFIX = exports.PREFIX = 'NRBA';
8
+ const DEFAULT_KEY = exports.DEFAULT_KEY = 'SESSION';
8
9
  const DEFAULT_EXPIRES_MS = exports.DEFAULT_EXPIRES_MS = 14400000;
9
10
  const DEFAULT_INACTIVE_MS = exports.DEFAULT_INACTIVE_MS = 1800000;
10
11
  const SESSION_EVENTS = exports.SESSION_EVENTS = {
@@ -32,7 +32,7 @@ var REQUEST = 'request';
32
32
  var RESPONSE = 'response';
33
33
  var LOAD_EVENT = 'loadEvent';
34
34
  var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
35
- var navTimingValues = exports.navTimingValues = [];
35
+ const navTimingValues = exports.navTimingValues = [];
36
36
  function getPntType(type) {
37
37
  if (typeof type === 'number') return type;
38
38
  const types = {
@@ -78,6 +78,11 @@ function addPN(pn, v) {
78
78
  handleValue(pn.redirectCount, v, 'rc');
79
79
  return v;
80
80
  }
81
+
82
+ /**
83
+ * By side effect, this modifies 'obj' with a mapping of the 'prop' provided to a 'value', and invalid values are not added.
84
+ * On the other hand, the local navTimingValues array gets the value appended if valid and 'undefined' appended if invalid, regardless.
85
+ */
81
86
  function handleValue(value, obj, prop, isOldApi) {
82
87
  /*
83
88
  For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
@@ -92,6 +97,6 @@ function handleValue(value, obj, prop, isOldApi) {
92
97
  }
93
98
  value = Math.round(value);
94
99
  obj[prop] = value;
95
- }
96
- navTimingValues.push(value);
100
+ navTimingValues.push(value);
101
+ } else navTimingValues.push(undefined);
97
102
  }
@@ -11,5 +11,5 @@ exports.now = now;
11
11
 
12
12
  // 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.
13
13
  function now() {
14
- return Math.round(performance.now());
14
+ return Math.floor(performance.now());
15
15
  }
@@ -18,7 +18,7 @@ const bucketMap = {
18
18
  stn: [_features.FEATURE_NAMES.sessionTrace],
19
19
  err: [_features.FEATURE_NAMES.jserrors, _features.FEATURE_NAMES.metrics],
20
20
  ins: [_features.FEATURE_NAMES.pageAction],
21
- spa: [_features.FEATURE_NAMES.spa],
21
+ spa: [_features.FEATURE_NAMES.spa, _features.FEATURE_NAMES.softNav],
22
22
  sr: [_features.FEATURE_NAMES.sessionReplay, _features.FEATURE_NAMES.sessionTrace]
23
23
  };
24
24
  const sentIds = new Set();
@@ -39,12 +39,6 @@ Object.defineProperty(exports, "wrapPromise", {
39
39
  return _wrapPromise.wrapPromise;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "wrapRaf", {
43
- enumerable: true,
44
- get: function () {
45
- return _wrapRaf.wrapRaf;
46
- }
47
- });
48
42
  Object.defineProperty(exports, "wrapTimer", {
49
43
  enumerable: true,
50
44
  get: function () {
@@ -63,6 +57,5 @@ var _wrapHistory = require("./wrap-history");
63
57
  var _wrapJsonp = require("./wrap-jsonp");
64
58
  var _wrapMutation = require("./wrap-mutation");
65
59
  var _wrapPromise = require("./wrap-promise");
66
- var _wrapRaf = require("./wrap-raf");
67
60
  var _wrapTimer = require("./wrap-timer");
68
61
  var _wrapXhr = require("./wrap-xhr");
@@ -9,6 +9,7 @@ var _contextualEe = require("../event-emitter/contextual-ee");
9
9
  var _wrapFunction = require("./wrap-function");
10
10
  var _getOrSet = require("../util/get-or-set");
11
11
  var _runtime = require("../constants/runtime");
12
+ var _observationContextManager = require("../context/observation-context-manager");
12
13
  /*
13
14
  * Copyright 2020 New Relic Corporation. All rights reserved.
14
15
  * SPDX-License-Identifier: Apache-2.0
@@ -23,7 +24,6 @@ const wrapped = {};
23
24
  const XHR = _runtime.globalScope.XMLHttpRequest;
24
25
  const ADD_EVENT_LISTENER = 'addEventListener';
25
26
  const REMOVE_EVENT_LISTENER = 'removeEventListener';
26
- const flag = "nr@wrapped:".concat(_contextualEe.contextId);
27
27
 
28
28
  /**
29
29
  * Wraps `addEventListener` and `removeEventListener` on: global scope; the prototype of `XMLHttpRequest`, and
@@ -52,7 +52,7 @@ function wrapEvents(sharedEE) {
52
52
  if (originalListener === null || typeof originalListener !== 'function' && typeof originalListener !== 'object') {
53
53
  return;
54
54
  }
55
- var wrapped = (0, _getOrSet.getOrSet)(originalListener, flag, function () {
55
+ var wrapped = (0, _getOrSet.getOrSet)(originalListener, _observationContextManager.ObservationContextManager.contextWrappedId, function () {
56
56
  var listener = {
57
57
  object: wrapHandleEvent,
58
58
  function: originalListener
@@ -7,6 +7,7 @@ exports.scopedEE = scopedEE;
7
7
  exports.wrapFetch = wrapFetch;
8
8
  var _contextualEe = require("../event-emitter/contextual-ee");
9
9
  var _runtime = require("../constants/runtime");
10
+ var _observationContextManager = require("../context/observation-context-manager");
10
11
  /*
11
12
  * Copyright 2020 New Relic Corporation. All rights reserved.
12
13
  * SPDX-License-Identifier: Apache-2.0
@@ -78,7 +79,7 @@ function wrapFetch(sharedEE) {
78
79
  // we are wrapping args in an array so we can preserve the reference
79
80
  ee.emit(prefix + 'before-start', [args], ctx);
80
81
  var dtPayload;
81
- if (ctx[_contextualEe.contextId] && ctx[_contextualEe.contextId].dt) dtPayload = ctx[_contextualEe.contextId].dt;
82
+ if (ctx[_observationContextManager.ObservationContextManager.contextId] && ctx[_observationContextManager.ObservationContextManager.contextId].dt) dtPayload = ctx[_observationContextManager.ObservationContextManager.contextId].dt;
82
83
  var origPromiseFromFetch = fn.apply(this, args);
83
84
  ee.emit(prefix + 'start', [args, dtPayload], origPromiseFromFetch);
84
85
 
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createWrapperWithEmitter = createWrapperWithEmitter;
7
- exports.flag = exports.default = void 0;
7
+ exports.default = void 0;
8
8
  var _contextualEe = require("../event-emitter/contextual-ee");
9
- var _bundleId = require("../ids/bundle-id");
9
+ var _observationContextManager = require("../context/observation-context-manager");
10
10
  /*
11
11
  * Copyright 2020 New Relic Corporation. All rights reserved.
12
12
  * SPDX-License-Identifier: Apache-2.0
@@ -15,8 +15,6 @@ var _bundleId = require("../ids/bundle-id");
15
15
  * @file Provides helper functions for wrapping functions in various scenarios.
16
16
  */
17
17
 
18
- const flag = exports.flag = "nr@original:".concat(_bundleId.bundleId);
19
-
20
18
  /**
21
19
  * A convenience alias of `hasOwnProperty`.
22
20
  * @type {function}
@@ -46,7 +44,7 @@ function createWrapperWithEmitter(emitter, always) {
46
44
  * As a property on a wrapped function, contains the original function.
47
45
  * @type {string}
48
46
  */
49
- wrapFn.flag = flag;
47
+ wrapFn.flag = _observationContextManager.ObservationContextManager.contextOriginalId;
50
48
  return wrapFn;
51
49
 
52
50
  /**
@@ -62,7 +60,7 @@ function createWrapperWithEmitter(emitter, always) {
62
60
  // Unless fn is both wrappable and unwrapped, return it unchanged.
63
61
  if (notWrappable(fn)) return fn;
64
62
  if (!prefix) prefix = '';
65
- nrWrapper[flag] = fn;
63
+ nrWrapper[_observationContextManager.ObservationContextManager.contextOriginalId] = fn;
66
64
  copy(fn, nrWrapper, emitter);
67
65
  return nrWrapper;
68
66
 
@@ -216,5 +214,5 @@ function copy(from, to, emitter) {
216
214
  * @returns {boolean} Whether the passed function is ineligible to be wrapped.
217
215
  */
218
216
  function notWrappable(fn) {
219
- return !(fn && typeof fn === 'function' && fn.apply && !fn[flag]);
217
+ return !(fn && typeof fn === 'function' && fn.apply && !fn[_observationContextManager.ObservationContextManager.contextOriginalId]);
220
218
  }
@@ -8,6 +8,7 @@ exports.wrapPromise = wrapPromise;
8
8
  var _wrapFunction = require("./wrap-function");
9
9
  var _contextualEe = require("../event-emitter/contextual-ee");
10
10
  var _runtime = require("../constants/runtime");
11
+ var _observationContextManager = require("../context/observation-context-manager");
11
12
  /*
12
13
  * Copyright 2020 New Relic Corporation. All rights reserved.
13
14
  * SPDX-License-Identifier: Apache-2.0
@@ -125,7 +126,7 @@ function wrapPromise(sharedEE) {
125
126
  promiseEE.emit('propagate', [originalThis, true], origFnCallWithThis, false, false);
126
127
  return origFnCallWithThis;
127
128
  };
128
- prevPromiseObj.prototype.then[_wrapFunction.flag] = prevPromiseOrigThen;
129
+ prevPromiseObj.prototype.then[_observationContextManager.ObservationContextManager.contextOriginalId] = prevPromiseOrigThen;
129
130
  promiseEE.on('executor-start', function (args) {
130
131
  args[0] = promiseWrapper(args[0], 'resolve-', this, null, false);
131
132
  args[1] = promiseWrapper(args[1], 'resolve-', this, null, false);
@@ -16,6 +16,7 @@ var _features = require("../../../loaders/features/features");
16
16
  var _constants2 = require("../../metrics/constants");
17
17
  var _aggregateBase = require("../../utils/aggregate-base");
18
18
  var _gql = require("./gql");
19
+ var _nreum = require("../../../common/window/nreum");
19
20
  /*
20
21
  * Copyright 2020 New Relic Corporation. All rights reserved.
21
22
  * SPDX-License-Identifier: Apache-2.0
@@ -50,19 +51,23 @@ class Aggregate extends _aggregateBase.AggregateBase {
50
51
  spaAjaxEvents
51
52
  };
52
53
  };
53
- ee.on('interactionSaved', interaction => {
54
- if (!spaAjaxEvents[interaction.id]) return;
55
- // remove from the spaAjaxEvents buffer, and let spa harvest it
56
- delete spaAjaxEvents[interaction.id];
57
- });
58
- ee.on('interactionDiscarded', interaction => {
54
+
55
+ // --- v Used by old spa feature
56
+ ee.on('interactionDone', (interaction, wasSaved) => {
59
57
  if (!spaAjaxEvents[interaction.id]) return;
60
- spaAjaxEvents[interaction.id].forEach(function (item) {
61
- // move it from the spaAjaxEvents buffer to the ajaxEvents buffer for harvesting here
62
- ajaxEvents.push(item);
63
- });
58
+ if (!wasSaved) {
59
+ // 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
60
+ spaAjaxEvents[interaction.id].forEach(function (item) {
61
+ ajaxEvents.push(item);
62
+ });
63
+ }
64
64
  delete spaAjaxEvents[interaction.id];
65
65
  });
66
+ // --- ^
67
+ // --- v Used by new soft nav
68
+ (0, _registerHandler.registerHandler)('returnAjax', event => ajaxEvents.push(event), this.featureName, this.ee);
69
+ // --- ^
70
+
66
71
  const scheduler = new _harvestScheduler.HarvestScheduler('events', {
67
72
  onFinished: onEventsHarvestFinished,
68
73
  getPayload: prepareHarvest
@@ -83,16 +88,26 @@ class Aggregate extends _aggregateBase.AggregateBase {
83
88
  } else {
84
89
  hash = (0, _stringify.stringify)([params.status, params.host, params.pathname]);
85
90
  }
91
+ const shouldCollect = (0, _denyList.shouldCollectEvent)(params);
92
+ const ajaxMetricDenyListEnabled = agentInit.feature_flags?.includes('ajax_metrics_deny_list');
86
93
 
87
94
  // store as metric
88
- aggregator.store('xhr', hash, params, metrics);
95
+ if (shouldCollect || !ajaxMetricDenyListEnabled) {
96
+ aggregator.store('xhr', hash, params, metrics);
97
+ }
89
98
  if (!allAjaxIsEnabled) return;
90
- if (!(0, _denyList.shouldCollectEvent)(params)) {
99
+ if (!shouldCollect) {
91
100
  if (params.hostname === beacon || proxyBeacon && params.hostname === proxyBeacon) {
92
101
  // This doesn't make a distinction if the same-domain request is going to a different port or path...
93
102
  (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/Agent'], undefined, _features.FEATURE_NAMES.metrics, ee);
103
+ if (ajaxMetricDenyListEnabled) {
104
+ (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/Agent'], undefined, _features.FEATURE_NAMES.metrics, ee);
105
+ }
94
106
  } else {
95
107
  (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/App'], undefined, _features.FEATURE_NAMES.metrics, ee);
108
+ if (ajaxMetricDenyListEnabled) {
109
+ (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/App'], undefined, _features.FEATURE_NAMES.metrics, ee);
110
+ }
96
111
  }
97
112
  return;
98
113
  }
@@ -122,10 +137,13 @@ class Aggregate extends _aggregateBase.AggregateBase {
122
137
  query: this?.parsedOrigin?.search
123
138
  });
124
139
  if (event.gql) (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/GraphQL/Bytes-Added', (0, _stringify.stringify)(event.gql).length], undefined, _features.FEATURE_NAMES.metrics, ee);
125
-
126
- // if the ajax happened inside an interaction, hold it until the interaction finishes
127
- if (this.spaNode) {
128
- var interactionId = this.spaNode.interaction.id;
140
+ const softNavInUse = Boolean((0, _nreum.getNREUMInitializedAgent)(agentIdentifier)?.features?.[_features.FEATURE_NAMES.softNav]);
141
+ if (softNavInUse) {
142
+ // For newer soft nav (when running), pass the event to it for evaluation -- either part of an interaction or is given back
143
+ (0, _handle.handle)('ajax', [event], undefined, _features.FEATURE_NAMES.softNav, ee);
144
+ } else if (this.spaNode) {
145
+ // For old spa (when running), if the ajax happened inside an interaction, hold it until the interaction finishes
146
+ const interactionId = this.spaNode.interaction.id;
129
147
  spaAjaxEvents[interactionId] = spaAjaxEvents[interactionId] || [];
130
148
  spaAjaxEvents[interactionId].push(event);
131
149
  } else {