@newrelic/browser-agent 1.268.0 → 1.270.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 (173) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +2 -1
  3. package/dist/cjs/common/constants/env.cdn.js +1 -1
  4. package/dist/cjs/common/constants/env.npm.js +1 -1
  5. package/dist/cjs/common/constants/runtime.js +1 -2
  6. package/dist/cjs/common/harvest/harvest-scheduler.js +3 -4
  7. package/dist/cjs/common/unload/eol.js +2 -5
  8. package/dist/cjs/common/util/submit-data.js +1 -1
  9. package/dist/cjs/features/ajax/aggregate/index.js +8 -17
  10. package/dist/cjs/features/ajax/instrument/index.js +8 -10
  11. package/dist/cjs/features/generic_events/aggregate/index.js +15 -22
  12. package/dist/cjs/features/generic_events/instrument/index.js +5 -8
  13. package/dist/cjs/features/jserrors/aggregate/index.js +38 -23
  14. package/dist/cjs/features/jserrors/aggregate/internal-errors.js +42 -0
  15. package/dist/cjs/features/jserrors/instrument/index.js +3 -3
  16. package/dist/cjs/features/logging/aggregate/index.js +21 -20
  17. package/dist/cjs/features/logging/instrument/index.js +3 -3
  18. package/dist/cjs/features/metrics/aggregate/index.js +13 -16
  19. package/dist/cjs/features/metrics/instrument/index.js +3 -3
  20. package/dist/cjs/features/page_view_event/aggregate/index.js +15 -29
  21. package/dist/cjs/features/page_view_event/instrument/index.js +3 -3
  22. package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -23
  23. package/dist/cjs/features/page_view_timing/instrument/index.js +3 -3
  24. package/dist/cjs/features/session_replay/aggregate/index.js +15 -29
  25. package/dist/cjs/features/session_replay/instrument/index.js +7 -5
  26. package/dist/cjs/features/session_trace/aggregate/index.js +28 -34
  27. package/dist/cjs/features/session_trace/instrument/index.js +4 -5
  28. package/dist/cjs/features/soft_navigations/aggregate/index.js +6 -11
  29. package/dist/cjs/features/soft_navigations/instrument/index.js +3 -3
  30. package/dist/cjs/features/spa/aggregate/index.js +19 -30
  31. package/dist/cjs/features/spa/instrument/index.js +8 -4
  32. package/dist/cjs/features/utils/aggregate-base.js +11 -12
  33. package/dist/cjs/features/utils/feature-base.js +5 -3
  34. package/dist/cjs/features/utils/instrument-base.js +18 -10
  35. package/dist/cjs/loaders/agent-base.js +1 -0
  36. package/dist/cjs/loaders/agent.js +1 -5
  37. package/dist/cjs/loaders/micro-agent.js +7 -10
  38. package/dist/esm/common/constants/env.cdn.js +1 -1
  39. package/dist/esm/common/constants/env.npm.js +1 -1
  40. package/dist/esm/common/constants/runtime.js +0 -1
  41. package/dist/esm/common/harvest/harvest-scheduler.js +3 -4
  42. package/dist/esm/common/unload/eol.js +2 -5
  43. package/dist/esm/common/util/submit-data.js +2 -2
  44. package/dist/esm/features/ajax/aggregate/index.js +8 -17
  45. package/dist/esm/features/ajax/instrument/index.js +8 -10
  46. package/dist/esm/features/generic_events/aggregate/index.js +11 -18
  47. package/dist/esm/features/generic_events/instrument/index.js +5 -8
  48. package/dist/esm/features/jserrors/aggregate/index.js +36 -21
  49. package/dist/esm/features/jserrors/aggregate/internal-errors.js +36 -0
  50. package/dist/esm/features/jserrors/instrument/index.js +3 -3
  51. package/dist/esm/features/logging/aggregate/index.js +21 -20
  52. package/dist/esm/features/logging/instrument/index.js +3 -3
  53. package/dist/esm/features/metrics/aggregate/index.js +8 -11
  54. package/dist/esm/features/metrics/instrument/index.js +3 -3
  55. package/dist/esm/features/page_view_event/aggregate/index.js +16 -30
  56. package/dist/esm/features/page_view_event/instrument/index.js +3 -3
  57. package/dist/esm/features/page_view_timing/aggregate/index.js +6 -23
  58. package/dist/esm/features/page_view_timing/instrument/index.js +3 -3
  59. package/dist/esm/features/session_replay/aggregate/index.js +13 -27
  60. package/dist/esm/features/session_replay/instrument/index.js +7 -5
  61. package/dist/esm/features/session_trace/aggregate/index.js +27 -33
  62. package/dist/esm/features/session_trace/instrument/index.js +4 -5
  63. package/dist/esm/features/soft_navigations/aggregate/index.js +6 -11
  64. package/dist/esm/features/soft_navigations/instrument/index.js +3 -3
  65. package/dist/esm/features/spa/aggregate/index.js +17 -28
  66. package/dist/esm/features/spa/instrument/index.js +8 -4
  67. package/dist/esm/features/utils/aggregate-base.js +13 -14
  68. package/dist/esm/features/utils/feature-base.js +5 -3
  69. package/dist/esm/features/utils/instrument-base.js +18 -10
  70. package/dist/esm/loaders/agent-base.js +1 -0
  71. package/dist/esm/loaders/agent.js +1 -5
  72. package/dist/esm/loaders/micro-agent.js +7 -10
  73. package/dist/types/common/constants/runtime.d.ts +0 -1
  74. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  75. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  76. package/dist/types/common/unload/eol.d.ts +1 -1
  77. package/dist/types/common/unload/eol.d.ts.map +1 -1
  78. package/dist/types/features/ajax/aggregate/index.d.ts +1 -1
  79. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  80. package/dist/types/features/ajax/instrument/index.d.ts +1 -1
  81. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  82. package/dist/types/features/generic_events/aggregate/index.d.ts +1 -2
  83. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  84. package/dist/types/features/generic_events/instrument/index.d.ts +1 -1
  85. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  86. package/dist/types/features/jserrors/aggregate/index.d.ts +11 -2
  87. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  88. package/dist/types/features/jserrors/aggregate/internal-errors.d.ts +7 -0
  89. package/dist/types/features/jserrors/aggregate/internal-errors.d.ts.map +1 -0
  90. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  91. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  92. package/dist/types/features/logging/aggregate/index.d.ts +4 -2
  93. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  94. package/dist/types/features/logging/instrument/index.d.ts +1 -1
  95. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  96. package/dist/types/features/metrics/aggregate/index.d.ts +1 -1
  97. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  98. package/dist/types/features/metrics/instrument/index.d.ts +1 -1
  99. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  100. package/dist/types/features/page_action/instrument/index.d.ts +1 -0
  101. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  102. package/dist/types/features/page_view_event/aggregate/index.d.ts +1 -1
  103. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  104. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -1
  105. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  106. package/dist/types/features/page_view_timing/aggregate/index.d.ts +1 -5
  107. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  108. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -1
  109. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  110. package/dist/types/features/session_replay/aggregate/index.d.ts +0 -1
  111. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  112. package/dist/types/features/session_replay/instrument/index.d.ts +1 -1
  113. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  114. package/dist/types/features/session_trace/aggregate/index.d.ts +1 -3
  115. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  116. package/dist/types/features/session_trace/instrument/index.d.ts +1 -1
  117. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  118. package/dist/types/features/soft_navigations/aggregate/index.d.ts +1 -1
  119. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  120. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -1
  121. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  122. package/dist/types/features/spa/aggregate/index.d.ts +1 -1
  123. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  124. package/dist/types/features/spa/instrument/index.d.ts +4 -1
  125. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  126. package/dist/types/features/utils/aggregate-base.d.ts +2 -2
  127. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  128. package/dist/types/features/utils/feature-base.d.ts +2 -3
  129. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  130. package/dist/types/features/utils/instrument-base.d.ts +3 -3
  131. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  132. package/dist/types/loaders/agent-base.d.ts +1 -0
  133. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  134. package/dist/types/loaders/agent.d.ts +0 -2
  135. package/dist/types/loaders/agent.d.ts.map +1 -1
  136. package/dist/types/loaders/micro-agent.d.ts +0 -2
  137. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  138. package/package.json +1 -1
  139. package/src/common/constants/__mocks__/runtime.js +0 -1
  140. package/src/common/constants/runtime.js +0 -2
  141. package/src/common/harvest/harvest-scheduler.js +3 -4
  142. package/src/common/unload/eol.js +2 -5
  143. package/src/common/util/submit-data.js +2 -2
  144. package/src/features/ajax/aggregate/index.js +8 -18
  145. package/src/features/ajax/instrument/index.js +8 -10
  146. package/src/features/generic_events/aggregate/index.js +11 -20
  147. package/src/features/generic_events/instrument/index.js +7 -10
  148. package/src/features/jserrors/aggregate/index.js +34 -21
  149. package/src/features/jserrors/aggregate/internal-errors.js +33 -0
  150. package/src/features/jserrors/instrument/index.js +3 -4
  151. package/src/features/logging/aggregate/index.js +20 -21
  152. package/src/features/logging/instrument/index.js +3 -3
  153. package/src/features/metrics/aggregate/index.js +8 -11
  154. package/src/features/metrics/instrument/index.js +3 -3
  155. package/src/features/page_view_event/aggregate/index.js +16 -22
  156. package/src/features/page_view_event/instrument/index.js +3 -3
  157. package/src/features/page_view_timing/aggregate/index.js +6 -23
  158. package/src/features/page_view_timing/instrument/index.js +3 -3
  159. package/src/features/session_replay/aggregate/index.js +13 -21
  160. package/src/features/session_replay/instrument/index.js +7 -5
  161. package/src/features/session_trace/aggregate/index.js +28 -34
  162. package/src/features/session_trace/instrument/index.js +4 -5
  163. package/src/features/soft_navigations/aggregate/index.js +6 -8
  164. package/src/features/soft_navigations/instrument/index.js +3 -3
  165. package/src/features/spa/aggregate/index.js +17 -26
  166. package/src/features/spa/instrument/index.js +7 -4
  167. package/src/features/utils/__mocks__/feature-base.js +1 -2
  168. package/src/features/utils/aggregate-base.js +13 -14
  169. package/src/features/utils/feature-base.js +6 -3
  170. package/src/features/utils/instrument-base.js +16 -10
  171. package/src/loaders/agent-base.js +1 -0
  172. package/src/loaders/agent.js +1 -3
  173. package/src/loaders/micro-agent.js +9 -10
package/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
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.270.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.269.0...v1.270.0) (2024-10-22)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add Firefox to LCP test matcher ([#1223](https://github.com/newrelic/newrelic-browser-agent/issues/1223)) ([c6a20e1](https://github.com/newrelic/newrelic-browser-agent/commit/c6a20e11b694fcf721ce27b02be1df76caed1a3e))
12
+ * Move deregisterDrain method to feature-base ([#1220](https://github.com/newrelic/newrelic-browser-agent/issues/1220)) ([5fdea14](https://github.com/newrelic/newrelic-browser-agent/commit/5fdea14097d415d7c6f3f98bfe87848e118ec62e))
13
+ * Relocate aggregator from loader and improve agent internals ([#1216](https://github.com/newrelic/newrelic-browser-agent/issues/1216)) ([789df5a](https://github.com/newrelic/newrelic-browser-agent/commit/789df5a0d5574acb02ac0db2aea98150a9c8786e))
14
+ * Remove 'pageHide' from page end-of-lifecycle listener ([#1219](https://github.com/newrelic/newrelic-browser-agent/issues/1219)) ([daf349e](https://github.com/newrelic/newrelic-browser-agent/commit/daf349e632902597c232c3392cc5d188f2995f25))
15
+ * Remove supportsSendBeacon runtime property ([#1224](https://github.com/newrelic/newrelic-browser-agent/issues/1224)) ([a5996be](https://github.com/newrelic/newrelic-browser-agent/commit/a5996bec25f7c4038ce87f2ad72eb61d637f5994))
16
+
17
+ ## [1.269.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.268.0...v1.269.0) (2024-10-16)
18
+
19
+
20
+ ### Features
21
+
22
+ * Add instrumentation metadata to logging ([#1208](https://github.com/newrelic/newrelic-browser-agent/issues/1208)) ([6926474](https://github.com/newrelic/newrelic-browser-agent/commit/6926474fe2530475e10daab2bb6bad745bb547e1))
23
+ * Include logging feature in micro agent loader ([#1210](https://github.com/newrelic/newrelic-browser-agent/issues/1210)) ([1b24484](https://github.com/newrelic/newrelic-browser-agent/commit/1b2448498cf285f36530f2107cb0403401958b1f))
24
+
25
+
26
+ ### Bug Fixes
27
+
28
+ * Handle Session Replay Security Policy Errors ([#1215](https://github.com/newrelic/newrelic-browser-agent/issues/1215)) ([f14b0fe](https://github.com/newrelic/newrelic-browser-agent/commit/f14b0fec81d7d21b418b6be6c5d415bdd813eca9))
29
+ * Only ever allow session traces to capture page load timings once ([#1212](https://github.com/newrelic/newrelic-browser-agent/issues/1212)) ([d189686](https://github.com/newrelic/newrelic-browser-agent/commit/d1896869858eca3320144113e168f17f524f3119))
30
+
6
31
  ## [1.268.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.267.0...v1.268.0) (2024-10-08)
7
32
 
8
33
 
package/README.md CHANGED
@@ -238,7 +238,8 @@ A lot of new frameworks support the concept of server-side rendering the pages o
238
238
 
239
239
  ## Disclaimers
240
240
 
241
- The session replay library shipping as part of the browser agent is not turned on by default. For information on the use of this feature, see [Session Replay](#session-replay)
241
+ * The session replay feature is not turned on by default. For information on the use of this feature, see [Session Replay](#session-replay)
242
+ * As part of the improvement efforts around our SPA capabilities, the `createTracer` API has been [deprecated](https://docs.newrelic.com/eol/2024/04/eol-04-24-24-createtracer/). Please engage in removing usage of that library. If tracking task duration, we recommend utilizing the generic browser performance mark and measure APIs, which will gain native detection support from the agent in a future update.
242
243
 
243
244
  ## Support
244
245
 
@@ -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.268.0";
15
+ const VERSION = exports.VERSION = "1.270.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.268.0";
15
+ const VERSION = exports.VERSION = "1.270.0";
16
16
 
17
17
  /**
18
18
  * Exposes the build type of the agent
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.supportsSendBeacon = exports.originTime = exports.loadedAsDeferredBrowserScript = exports.isiOS = exports.isWorkerScope = exports.isBrowserScope = exports.initiallyHidden = exports.initialLocation = exports.iOSBelow16 = exports.globalScope = exports.ffVersion = void 0;
6
+ exports.originTime = exports.loadedAsDeferredBrowserScript = exports.isiOS = exports.isWorkerScope = exports.isBrowserScope = exports.initiallyHidden = exports.initialLocation = exports.iOSBelow16 = exports.globalScope = exports.ffVersion = void 0;
7
7
  var _now = require("../timing/now");
8
8
  /**
9
9
  * @file Contains constants about the environment the agent is running
@@ -42,7 +42,6 @@ const ffVersion = exports.ffVersion = (() => {
42
42
  }
43
43
  return 0;
44
44
  })();
45
- const supportsSendBeacon = exports.supportsSendBeacon = !!globalScope.navigator?.sendBeacon;
46
45
 
47
46
  /**
48
47
  * Represents the absolute timestamp in milliseconds that the page was loaded
@@ -41,8 +41,9 @@ class HarvestScheduler extends _sharedContext.SharedContext {
41
41
  this.harvesting = false;
42
42
  this.harvest = new _harvest.Harvest(this.sharedContext);
43
43
 
44
- // unload if EOL mechanism fires
45
- (0, _eol.subscribeToEOL)(this.unload.bind(this));
44
+ // If a feature specifies stuff to be done on page unload, those are frontrunned (via capture phase) before ANY feature final harvests.
45
+ if (typeof this.opts.onUnload === 'function') (0, _eol.subscribeToEOL)(this.opts.onUnload, true);
46
+ (0, _eol.subscribeToEOL)(this.unload.bind(this)); // this should consist only of sending final harvest
46
47
 
47
48
  /* Flush all buffered data if session resets and give up retries. This should be synchronous to ensure that the correct `session` value is sent.
48
49
  Since session-reset generates a new session ID and the ID is grabbed at send-time, any delays or retries would cause the payload to be sent under
@@ -58,8 +59,6 @@ class HarvestScheduler extends _sharedContext.SharedContext {
58
59
  */
59
60
  unload() {
60
61
  if (this.aborted) return;
61
- // If opts.onUnload is defined, these are special actions to execute before attempting to send the final payload.
62
- if (this.opts.onUnload) this.opts.onUnload();
63
62
  this.runHarvest({
64
63
  unload: true
65
64
  });
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.subscribeToEOL = subscribeToEOL;
7
- var _eventListenerOpts = require("../event-listener/event-listener-opts");
8
7
  var _runtime = require("../constants/runtime");
9
8
  var _pageVisibility = require("../window/page-visibility");
10
9
  /*
@@ -30,11 +29,9 @@ if (_runtime.isWorkerScope) {
30
29
  * This is used, for example, to submit a final harvest and send all remaining data on best-effort.
31
30
  * @param {function} cb - func to run before or during the last reliable event or time of an env's life span
32
31
  */
33
- function subscribeToEOL(cb) {
32
+ function subscribeToEOL(cb, capturePhase) {
34
33
  if (_runtime.isBrowserScope) {
35
- (0, _pageVisibility.subscribeToVisibilityChange)(cb, true); // when user switches tab or hides window, esp. mobile scenario
36
- (0, _eventListenerOpts.windowAddEventListener)('pagehide', cb); // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
37
- // --this ought to be removed once support for version below 14.5 phases out
34
+ (0, _pageVisibility.subscribeToVisibilityChange)(cb, true, capturePhase); // when user switches tab or hides window, esp. mobile scenario
38
35
  } else if (_runtime.isWorkerScope) {
39
36
  _runtime.globalScope.cleanupTasks.push(cb); // close() should run these tasks before quitting thread
40
37
  }
@@ -26,7 +26,7 @@ var _runtime = require("../constants/runtime");
26
26
  function getSubmitMethod({
27
27
  isFinalHarvest = false
28
28
  } = {}) {
29
- return isFinalHarvest && _runtime.isBrowserScope && _runtime.supportsSendBeacon
29
+ return isFinalHarvest && _runtime.isBrowserScope
30
30
  // Use sendBeacon for final harvest
31
31
  ? beacon
32
32
  // If not final harvest, or not browserScope, always use xhr post
@@ -7,9 +7,6 @@ exports.Aggregate = void 0;
7
7
  var _registerHandler = require("../../../common/event-emitter/register-handler");
8
8
  var _stringify = require("../../../common/util/stringify");
9
9
  var _handle = require("../../../common/event-emitter/handle");
10
- var _info = require("../../../common/config/info");
11
- var _init = require("../../../common/config/init");
12
- var _runtime = require("../../../common/config/runtime");
13
10
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
14
11
  var _denyList = require("../../../common/deny-list/deny-list");
15
12
  var _constants = require("../constants");
@@ -28,16 +25,10 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
28
25
 
29
26
  class Aggregate extends _aggregateBase.AggregateBase {
30
27
  static featureName = _constants.FEATURE_NAME;
31
- #agentInfo;
32
- #agentRuntime;
33
- #agentInit;
34
- constructor(agentIdentifier, aggregator) {
35
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
36
- this.#agentInfo = (0, _info.getInfo)(agentIdentifier);
37
- this.#agentRuntime = (0, _runtime.getRuntime)(agentIdentifier);
38
- this.#agentInit = (0, _init.getConfiguration)(agentIdentifier);
39
- const harvestTimeSeconds = this.#agentInit.ajax.harvestTimeSeconds || 10;
40
- (0, _denyList.setDenyList)(this.#agentRuntime.denyList);
28
+ constructor(agentRef) {
29
+ super(agentRef, _constants.FEATURE_NAME);
30
+ const harvestTimeSeconds = agentRef.init.ajax.harvestTimeSeconds || 10;
31
+ (0, _denyList.setDenyList)(agentRef.runtime.denyList);
41
32
  this.ajaxEvents = new _eventBuffer.EventBuffer();
42
33
  this.spaAjaxEvents = {};
43
34
  const classThis = this;
@@ -79,14 +70,14 @@ class Aggregate extends _aggregateBase.AggregateBase {
79
70
  hash = (0, _stringify.stringify)([params.status, params.host, params.pathname]);
80
71
  }
81
72
  const shouldCollect = (0, _denyList.shouldCollectEvent)(params);
82
- const shouldOmitAjaxMetrics = this.#agentInit.feature_flags?.includes('ajax_metrics_deny_list');
73
+ const shouldOmitAjaxMetrics = this.agentRef.init.feature_flags?.includes('ajax_metrics_deny_list');
83
74
 
84
75
  // store for timeslice metric (harvested by jserrors feature)
85
76
  if (shouldCollect || !shouldOmitAjaxMetrics) {
86
- this.aggregator.store('xhr', hash, params, metrics);
77
+ this.agentRef.sharedAggregator.store('xhr', hash, params, metrics);
87
78
  }
88
79
  if (!shouldCollect) {
89
- if (params.hostname === this.#agentInfo.errorBeacon || this.#agentInit.proxy?.beacon && params.hostname === this.#agentInit.proxy.beacon) {
80
+ if (params.hostname === this.agentRef.info.errorBeacon || this.agentRef.init.proxy?.beacon && params.hostname === this.agentRef.init.proxy.beacon) {
90
81
  // This doesn't make a distinction if the same-domain request is going to a different port or path...
91
82
  (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Events/Excluded/Agent'], undefined, _features.FEATURE_NAMES.metrics, this.ee);
92
83
  if (shouldOmitAjaxMetrics) (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Ajax/Metrics/Excluded/Agent'], undefined, _features.FEATURE_NAMES.metrics, this.ee);
@@ -113,7 +104,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
113
104
  if (ctx.dt) {
114
105
  event.spanId = ctx.dt.spanId;
115
106
  event.traceId = ctx.dt.traceId;
116
- event.spanTimestamp = Math.floor(this.#agentRuntime.timeKeeper.correctAbsoluteTimestamp(ctx.dt.timestamp));
107
+ event.spanTimestamp = Math.floor(this.agentRef.runtime.timeKeeper.correctAbsoluteTimestamp(ctx.dt.timestamp));
117
108
  }
118
109
 
119
110
  // parsed from the AJAX body, looking for operationName param & parsing query for operationType
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Instrument = exports.Ajax = void 0;
7
7
  var _nreum = require("../../../common/window/nreum");
8
- var _loaderConfig = require("../../../common/config/loader-config");
9
8
  var _handle = require("../../../common/event-emitter/handle");
10
9
  var _id = require("../../../common/ids/id");
11
10
  var _runtime = require("../../../common/constants/runtime");
@@ -33,9 +32,9 @@ var origRequest = (0, _nreum.gosNREUMOriginals)().o.REQ;
33
32
  var origXHR = (0, _nreum.gosNREUMOriginals)().o.XHR;
34
33
  class Instrument extends _instrumentBase.InstrumentBase {
35
34
  static featureName = _constants.FEATURE_NAME;
36
- constructor(agentIdentifier, aggregator, auto = true) {
37
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
38
- this.dt = new _distributedTracing.DT(agentIdentifier);
35
+ constructor(agentRef, auto = true) {
36
+ super(agentRef, _constants.FEATURE_NAME, auto);
37
+ this.dt = new _distributedTracing.DT(agentRef.agentIdentifier);
39
38
  this.handler = (type, args, ctx, group) => (0, _handle.handle)(type, args, ctx, group, this.ee);
40
39
 
41
40
  // this is a best (but imperfect) effort at capturing AJAX calls that may have fired before the agent was instantiated
@@ -71,12 +70,12 @@ class Instrument extends _instrumentBase.InstrumentBase {
71
70
  }
72
71
  (0, _wrapFetch.wrapFetch)(this.ee);
73
72
  (0, _wrapXhr.wrapXhr)(this.ee);
74
- subscribeToEvents(agentIdentifier, this.ee, this.handler, this.dt);
75
- this.importAggregator();
73
+ subscribeToEvents(agentRef, this.ee, this.handler, this.dt);
74
+ this.importAggregator(agentRef);
76
75
  }
77
76
  }
78
77
  exports.Instrument = Instrument;
79
- function subscribeToEvents(agentIdentifier, ee, handler, dt) {
78
+ function subscribeToEvents(agentRef, ee, handler, dt) {
80
79
  ee.on('new-xhr', onNewXhr);
81
80
  ee.on('open-xhr-start', onOpenXhrStart);
82
81
  ee.on('open-xhr-end', onOpenXhrEnd);
@@ -129,9 +128,8 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
129
128
  this.metrics = {};
130
129
  }
131
130
  function onOpenXhrEnd(args, xhr) {
132
- var loaderConfig = (0, _loaderConfig.getLoaderConfig)(agentIdentifier);
133
- if (loaderConfig.xpid && this.sameOrigin) {
134
- xhr.setRequestHeader('X-NewRelic-ID', loaderConfig.xpid);
131
+ if (agentRef.loader_config.xpid && this.sameOrigin) {
132
+ xhr.setRequestHeader('X-NewRelic-ID', agentRef.loader_config.xpid);
135
133
  }
136
134
  var payload = dt.generateTracePayload(this.parsedOrigin);
137
135
  if (payload) {
@@ -7,16 +7,12 @@ exports.Aggregate = void 0;
7
7
  var _stringify = require("../../../common/util/stringify");
8
8
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
9
9
  var _cleanUrl = require("../../../common/url/clean-url");
10
- var _info = require("../../../common/config/info");
11
- var _init = require("../../../common/config/init");
12
- var _runtime = require("../../../common/config/runtime");
13
10
  var _constants = require("../constants");
14
- var _runtime2 = require("../../../common/constants/runtime");
11
+ var _runtime = require("../../../common/constants/runtime");
15
12
  var _aggregateBase = require("../../utils/aggregate-base");
16
13
  var _console = require("../../../common/util/console");
17
14
  var _now = require("../../../common/timing/now");
18
15
  var _registerHandler = require("../../../common/event-emitter/register-handler");
19
- var _drain = require("../../../common/drain/drain");
20
16
  var _constants2 = require("../../metrics/constants");
21
17
  var _eventBuffer = require("../../utils/event-buffer");
22
18
  var _traverse = require("../../../common/util/traverse");
@@ -29,40 +25,37 @@ var _iframe = require("../../../common/dom/iframe");
29
25
  */
30
26
 
31
27
  class Aggregate extends _aggregateBase.AggregateBase {
32
- #agentRuntime;
33
28
  static featureName = _constants.FEATURE_NAME;
34
- constructor(agentIdentifier, aggregator) {
35
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
36
- const agentInit = (0, _init.getConfiguration)(this.agentIdentifier);
29
+ constructor(agentRef) {
30
+ super(agentRef, _constants.FEATURE_NAME);
37
31
  this.eventsPerHarvest = 1000;
38
- this.harvestTimeSeconds = agentInit.generic_events.harvestTimeSeconds;
39
- this.referrerUrl = _runtime2.isBrowserScope && document.referrer ? (0, _cleanUrl.cleanURL)(document.referrer) : undefined;
32
+ this.harvestTimeSeconds = agentRef.init.generic_events.harvestTimeSeconds;
33
+ this.referrerUrl = _runtime.isBrowserScope && document.referrer ? (0, _cleanUrl.cleanURL)(document.referrer) : undefined;
40
34
  this.events = new _eventBuffer.EventBuffer();
41
- this.#agentRuntime = (0, _runtime.getRuntime)(this.agentIdentifier);
42
35
  this.waitForFlags(['ins']).then(([ins]) => {
43
36
  if (!ins) {
44
37
  this.blocked = true;
45
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
38
+ this.deregisterDrain();
46
39
  return;
47
40
  }
48
41
  const preHarvestMethods = [];
49
- if (agentInit.page_action.enabled) {
42
+ if (agentRef.init.page_action.enabled) {
50
43
  (0, _registerHandler.registerHandler)('api-addPageAction', (timestamp, name, attributes) => {
51
44
  this.addEvent({
52
45
  ...attributes,
53
46
  eventType: 'PageAction',
54
- timestamp: Math.floor(this.#agentRuntime.timeKeeper.correctRelativeTimestamp(timestamp)),
47
+ timestamp: Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(timestamp)),
55
48
  timeSinceLoad: timestamp / 1000,
56
49
  actionName: name,
57
50
  referrerUrl: this.referrerUrl,
58
- ...(_runtime2.isBrowserScope && {
51
+ ...(_runtime.isBrowserScope && {
59
52
  browserWidth: window.document.documentElement?.clientWidth,
60
53
  browserHeight: window.document.documentElement?.clientHeight
61
54
  })
62
55
  });
63
56
  }, this.featureName, this.ee);
64
57
  }
65
- if (_runtime2.isBrowserScope && agentInit.user_actions.enabled) {
58
+ if (_runtime.isBrowserScope && agentRef.init.user_actions.enabled) {
66
59
  this.userActionAggregator = new _userActionsAggregator.UserActionsAggregator();
67
60
  this.addUserAction = aggregatedUserAction => {
68
61
  try {
@@ -76,7 +69,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
76
69
  } = aggregatedUserAction.event;
77
70
  this.addEvent({
78
71
  eventType: 'UserAction',
79
- timestamp: Math.floor(this.#agentRuntime.timeKeeper.correctRelativeTimestamp(timeStamp)),
72
+ timestamp: Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(timeStamp)),
80
73
  action: type,
81
74
  actionCount: aggregatedUserAction.count,
82
75
  actionDuration: aggregatedUserAction.relativeMs[aggregatedUserAction.relativeMs.length - 1],
@@ -151,14 +144,14 @@ class Aggregate extends _aggregateBase.AggregateBase {
151
144
  }
152
145
  const defaultEventAttributes = {
153
146
  /** should be overridden by the event-specific attributes, but just in case -- set it to now() */
154
- timestamp: Math.floor(this.#agentRuntime.timeKeeper.correctRelativeTimestamp((0, _now.now)())),
147
+ timestamp: Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp((0, _now.now)())),
155
148
  /** all generic events require pageUrl(s) */
156
- pageUrl: (0, _cleanUrl.cleanURL)('' + _runtime2.initialLocation),
149
+ pageUrl: (0, _cleanUrl.cleanURL)('' + _runtime.initialLocation),
157
150
  currentUrl: (0, _cleanUrl.cleanURL)('' + location)
158
151
  };
159
152
  const eventAttributes = {
160
153
  /** Agent-level custom attributes */
161
- ...((0, _info.getInfo)(this.agentIdentifier).jsAttributes || {}),
154
+ ...(this.agentRef.info.jsAttributes || {}),
162
155
  /** Fallbacks for required properties in-case the event did not supply them, should take precedence over agent-level custom attrs */
163
156
  ...defaultEventAttributes,
164
157
  /** Event-specific attributes take precedence over agent-level custom attributes and fallbacks */
@@ -171,7 +164,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
171
164
  const {
172
165
  userAttributes,
173
166
  atts
174
- } = (0, _info.getInfo)(this.agentIdentifier);
167
+ } = this.agentRef.info;
175
168
  if (!this.events.hasData) return;
176
169
  var payload = {
177
170
  qs: {
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Instrument = exports.GenericEvents = void 0;
7
- var _init = require("../../../common/config/init");
8
7
  var _runtime = require("../../../common/constants/runtime");
9
- var _drain = require("../../../common/drain/drain");
10
8
  var _handle = require("../../../common/event-emitter/handle");
11
9
  var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
12
10
  var _instrumentBase = require("../../utils/instrument-base");
@@ -17,13 +15,12 @@ var _constants = require("../constants");
17
15
 
18
16
  class Instrument extends _instrumentBase.InstrumentBase {
19
17
  static featureName = _constants.FEATURE_NAME;
20
- constructor(agentIdentifier, aggregator, auto = true) {
21
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
22
- const agentInit = (0, _init.getConfiguration)(this.agentIdentifier);
23
- const genericEventSourceConfigs = [agentInit.page_action.enabled, agentInit.user_actions.enabled
18
+ constructor(agentRef, auto = true) {
19
+ super(agentRef, _constants.FEATURE_NAME, auto);
20
+ const genericEventSourceConfigs = [agentRef.init.page_action.enabled, agentRef.init.user_actions.enabled
24
21
  // other future generic event source configs to go here, like M&Ms, PageResouce, etc.
25
22
  ];
26
- if (_runtime.isBrowserScope && agentInit.user_actions.enabled) {
23
+ if (_runtime.isBrowserScope && agentRef.init.user_actions.enabled) {
27
24
  _constants.OBSERVED_EVENTS.forEach(eventType => (0, _eventListenerOpts.windowAddEventListener)(eventType, evt => (0, _handle.handle)('ua', [evt], undefined, this.featureName, this.ee), true));
28
25
  _constants.OBSERVED_WINDOW_EVENTS.forEach(eventType => (0, _eventListenerOpts.windowAddEventListener)(eventType, evt => (0, _handle.handle)('ua', [evt], undefined, this.featureName, this.ee))
29
26
  // Capture is not used here so that we don't get element focus/blur events, only the window's as they do not bubble. They are also not cancellable, so no worries about being front of line.
@@ -31,7 +28,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
31
28
  }
32
29
 
33
30
  /** If any of the sources are active, import the aggregator. otherwise deregister */
34
- if (genericEventSourceConfigs.some(x => x)) this.importAggregator();else (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
31
+ if (genericEventSourceConfigs.some(x => x)) this.importAggregator(agentRef);else this.deregisterDrain();
35
32
  }
36
33
  }
37
34
  exports.Instrument = Instrument;
@@ -12,17 +12,15 @@ var _registerHandler = require("../../../common/event-emitter/register-handler")
12
12
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
13
13
  var _stringify = require("../../../common/util/stringify");
14
14
  var _handle = require("../../../common/event-emitter/handle");
15
- var _info = require("../../../common/config/info");
16
- var _init = require("../../../common/config/init");
17
- var _runtime = require("../../../common/config/runtime");
18
- var _runtime2 = require("../../../common/constants/runtime");
15
+ var _runtime = require("../../../common/constants/runtime");
19
16
  var _constants = require("../constants");
20
17
  var _features = require("../../../loaders/features/features");
21
18
  var _aggregateBase = require("../../utils/aggregate-base");
22
19
  var _nreum = require("../../../common/window/nreum");
23
- var _drain = require("../../../common/drain/drain");
24
20
  var _now = require("../../../common/timing/now");
25
21
  var _traverse = require("../../../common/util/traverse");
22
+ var _internalErrors = require("./internal-errors");
23
+ var _constants2 = require("../../metrics/constants");
26
24
  /*
27
25
  * Copyright 2020 New Relic Corporation. All rights reserved.
28
26
  * SPDX-License-Identifier: Apache-2.0
@@ -34,8 +32,8 @@ var _traverse = require("../../../common/util/traverse");
34
32
 
35
33
  class Aggregate extends _aggregateBase.AggregateBase {
36
34
  static featureName = _constants.FEATURE_NAME;
37
- constructor(agentIdentifier, aggregator) {
38
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
35
+ constructor(agentRef) {
36
+ super(agentRef, _constants.FEATURE_NAME);
39
37
  this.stackReported = {};
40
38
  this.observedAt = {};
41
39
  this.pageviewReported = {};
@@ -49,7 +47,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
49
47
  (0, _registerHandler.registerHandler)('ierr', (...args) => this.storeError(...args), this.featureName, this.ee);
50
48
  (0, _registerHandler.registerHandler)('softNavFlush', (interactionId, wasFinished, softNavAttrs) => this.onSoftNavNotification(interactionId, wasFinished, softNavAttrs), this.featureName, this.ee); // when an ixn is done or cancelled
51
49
 
52
- const harvestTimeSeconds = (0, _init.getConfigurationValue)(this.agentIdentifier, 'jserrors.harvestTimeSeconds') || 10;
50
+ const harvestTimeSeconds = agentRef.init.jserrors.harvestTimeSeconds || 10;
53
51
 
54
52
  // 0 == off, 1 == on
55
53
  this.waitForFlags(['err']).then(([errFlag]) => {
@@ -62,13 +60,13 @@ class Aggregate extends _aggregateBase.AggregateBase {
62
60
  this.drain();
63
61
  } else {
64
62
  this.blocked = true; // if rum response determines that customer lacks entitlements for spa endpoint, this feature shouldn't harvest
65
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
63
+ this.deregisterDrain();
66
64
  }
67
65
  });
68
66
  }
69
67
  onHarvestStarted(options) {
70
68
  // this gets rid of dependency in AJAX module
71
- var body = (0, _traverse.applyFnToProps)(this.aggregator.take(['err', 'ierr', 'xhr']), this.obfuscator.obfuscateString.bind(this.obfuscator), 'string');
69
+ var body = (0, _traverse.applyFnToProps)(this.agentRef.sharedAggregator.take(['err', 'ierr', 'xhr']), this.obfuscator.obfuscateString.bind(this.obfuscator), 'string');
72
70
  if (options.retry) {
73
71
  this.currentBody = body;
74
72
  }
@@ -76,7 +74,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
76
74
  body,
77
75
  qs: {}
78
76
  };
79
- var releaseIds = (0, _stringify.stringify)((0, _runtime.getRuntime)(this.agentIdentifier).releaseIds);
77
+ var releaseIds = (0, _stringify.stringify)(this.agentRef.runtime.releaseIds);
80
78
  if (releaseIds !== '{}') {
81
79
  payload.qs.ri = releaseIds;
82
80
  }
@@ -95,7 +93,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
95
93
  for (var i = 0; i < value.length; i++) {
96
94
  var bucket = value[i];
97
95
  var name = this.getBucketName(key, bucket.params, bucket.custom);
98
- this.aggregator.merge(key, name, bucket.metrics, bucket.params, bucket.custom);
96
+ this.agentRef.sharedAggregator.merge(key, name, bucket.metrics, bucket.params, bucket.custom);
99
97
  }
100
98
  });
101
99
  this.currentBody = null;
@@ -130,14 +128,23 @@ class Aggregate extends _aggregateBase.AggregateBase {
130
128
  }
131
129
  return canonicalStackString;
132
130
  }
131
+
132
+ /**
133
+ *
134
+ * @param {Error|UncaughtError} err The error instance to be processed
135
+ * @param {number} time the relative ms (to origin) timestamp of occurence
136
+ * @param {boolean=} internal if the error was "caught" and deemed "internal" before reporting to the jserrors feature
137
+ * @param {object=} customAttributes any custom attributes to be included in the error payload
138
+ * @param {boolean=} hasReplay a flag indicating if the error occurred during a replay session
139
+ * @returns
140
+ */
133
141
  storeError(err, time, internal, customAttributes, hasReplay) {
134
142
  if (!err) return;
135
143
  // are we in an interaction
136
144
  time = time || (0, _now.now)();
137
- const agentRuntime = (0, _runtime.getRuntime)(this.agentIdentifier);
138
145
  let filterOutput;
139
- if (!internal && agentRuntime.onerror) {
140
- filterOutput = agentRuntime.onerror(err);
146
+ if (!internal && this.agentRef.runtime.onerror) {
147
+ filterOutput = this.agentRef.runtime.onerror(err);
141
148
  if (filterOutput && !(typeof filterOutput.group === 'string' && filterOutput.group.length)) {
142
149
  // All truthy values mean don't report (store) the error, per backwards-compatible usage,
143
150
  // - EXCEPT if a fingerprinting label is returned, via an object with key of 'group' and value of non-empty string
@@ -146,11 +153,19 @@ class Aggregate extends _aggregateBase.AggregateBase {
146
153
  // Again as with previous usage, all falsey values would include the error.
147
154
  }
148
155
  var stackInfo = (0, _computeStackTrace.computeStackTrace)(err);
156
+ const {
157
+ shouldSwallow,
158
+ reason
159
+ } = (0, _internalErrors.evaluateInternalError)(stackInfo, internal);
160
+ if (shouldSwallow) {
161
+ (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Internal/Error/' + reason], undefined, _features.FEATURE_NAMES.metrics, this.ee);
162
+ return;
163
+ }
149
164
  var canonicalStackString = this.buildCanonicalStackString(stackInfo);
150
165
  const params = {
151
166
  stackHash: (0, _stringHashCode.stringHashCode)(canonicalStackString),
152
167
  exceptionClass: stackInfo.name,
153
- request_uri: _runtime2.globalScope?.location.pathname
168
+ request_uri: _runtime.globalScope?.location.pathname
154
169
  };
155
170
  if (stackInfo.message) params.message = '' + stackInfo.message;
156
171
  // Notice if filterOutput isn't false|undefined OR our specified object, this func would've returned already (so it's unnecessary to req-check group).
@@ -167,11 +182,11 @@ class Aggregate extends _aggregateBase.AggregateBase {
167
182
  if (!this.stackReported[bucketHash]) {
168
183
  this.stackReported[bucketHash] = true;
169
184
  params.stack_trace = (0, _formatStackTrace.truncateSize)(stackInfo.stackString);
170
- this.observedAt[bucketHash] = Math.floor(agentRuntime.timeKeeper.correctRelativeTimestamp(time));
185
+ this.observedAt[bucketHash] = Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(time));
171
186
  } else {
172
187
  params.browser_stack_hash = (0, _stringHashCode.stringHashCode)(stackInfo.stackString);
173
188
  }
174
- params.releaseIds = (0, _stringify.stringify)(agentRuntime.releaseIds);
189
+ params.releaseIds = (0, _stringify.stringify)(this.agentRef.runtime.releaseIds);
175
190
 
176
191
  // When debugging stack canonicalization/hashing, uncomment these lines for
177
192
  // more output in the test logs
@@ -183,8 +198,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
183
198
  this.pageviewReported[bucketHash] = true;
184
199
  }
185
200
  params.firstOccurrenceTimestamp = this.observedAt[bucketHash];
186
- params.timestamp = Math.floor(agentRuntime.timeKeeper.correctRelativeTimestamp(time));
187
- var type = internal ? 'ierr' : 'err';
201
+ params.timestamp = Math.floor(this.agentRef.runtime.timeKeeper.correctRelativeTimestamp(time));
202
+ var type = 'err';
188
203
  var newMetrics = {
189
204
  time
190
205
  };
@@ -226,14 +241,14 @@ class Aggregate extends _aggregateBase.AggregateBase {
226
241
  delete params._softNavFinished;
227
242
  } else {
228
243
  // interaction was cancelled -> error should not be associated OR there was no interaction
229
- Object.entries((0, _info.getInfo)(this.agentIdentifier).jsAttributes).forEach(([k, v]) => setCustom(k, v));
244
+ Object.entries(this.agentRef.info.jsAttributes).forEach(([k, v]) => setCustom(k, v));
230
245
  delete params.browserInteractionId;
231
246
  }
232
247
  if (localAttrs) Object.entries(localAttrs).forEach(([k, v]) => setCustom(k, v)); // local custom attrs are applied in either case with the highest precedence
233
248
 
234
249
  const jsAttributesHash = (0, _stringHashCode.stringHashCode)((0, _stringify.stringify)(allCustomAttrs));
235
250
  const aggregateHash = bucketHash + ':' + jsAttributesHash;
236
- this.aggregator.store(type, aggregateHash, params, newMetrics, allCustomAttrs);
251
+ this.agentRef.sharedAggregator.store(type, aggregateHash, params, newMetrics, allCustomAttrs);
237
252
  function setCustom(key, val) {
238
253
  allCustomAttrs[key] = val && typeof val === 'object' ? (0, _stringify.stringify)(val) : val;
239
254
  }
@@ -257,7 +272,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
257
272
  var hash = wasSaved ? item[1] + interaction.root.attrs.id : item[1];
258
273
  var jsAttributesHash = (0, _stringHashCode.stringHashCode)((0, _stringify.stringify)(allCustomAttrs));
259
274
  var aggregateHash = hash + ':' + jsAttributesHash;
260
- this.aggregator.store(item[0], aggregateHash, params, item[3], allCustomAttrs);
275
+ this.agentRef.sharedAggregator.store(item[0], aggregateHash, params, item[3], allCustomAttrs);
261
276
  function setCustom([key, val]) {
262
277
  allCustomAttrs[key] = val && typeof val === 'object' ? (0, _stringify.stringify)(val) : val;
263
278
  }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.evaluateInternalError = evaluateInternalError;
7
+ const REASON_RRWEB = 'Rrweb';
8
+ const REASON_SECURITY_POLICY = 'Security-Policy';
9
+ /**
10
+ * This function is responsible for determining if an error should be swallowed or not.
11
+ * @param {Object} stackInfo - The error stack information.
12
+ * @returns {boolean} - Whether the error should be swallowed or not.
13
+ */
14
+ function evaluateInternalError(stackInfo, internal) {
15
+ const output = {
16
+ shouldSwallow: internal || false,
17
+ reason: 'Other'
18
+ };
19
+ const leadingFrame = stackInfo.frames?.[0];
20
+ /** If we cant otherwise determine from the frames and message, the default of internal + reason will be the fallback */
21
+ if (!leadingFrame || typeof stackInfo?.message !== 'string') return output;
22
+
23
+ // check if the error happened in expected modules or if messages match known patterns
24
+ const isNrRecorder = leadingFrame?.url?.match(/nr-(.*)-recorder.min.js/);
25
+ const isRrweb = leadingFrame?.url?.match(/rrweb/);
26
+ const isMaybeNrRecorder = leadingFrame?.url?.match(/recorder/);
27
+ const isSecurityPolicyAPIError = stackInfo.message.toLowerCase().match(/an attempt was made to break through the security policy of the user agent/);
28
+
29
+ // check if modules and patterns above fit known swallow cases
30
+ if (!!isNrRecorder || !!isRrweb) {
31
+ /** We know -for sure- that the error came from our recorder module or rrweb directly if these are true, so swallow it */
32
+ output.shouldSwallow = true;
33
+ output.reason = REASON_RRWEB;
34
+ if (isSecurityPolicyAPIError) output.reason += '-' + REASON_SECURITY_POLICY;
35
+ } else if (!!isMaybeNrRecorder && isSecurityPolicyAPIError) {
36
+ /** We -suspect- that the error came from NR, so if it matches the exact case we know about, swallow it */
37
+ output.shouldSwallow = true;
38
+ output.reason = REASON_RRWEB + '-' + REASON_SECURITY_POLICY;
39
+ }
40
+ // other swallow conditions could also be added here
41
+ return output;
42
+ }
@@ -20,8 +20,8 @@ var _castError = require("../shared/cast-error");
20
20
  class Instrument extends _instrumentBase.InstrumentBase {
21
21
  static featureName = _constants.FEATURE_NAME;
22
22
  #replayRunning = false;
23
- constructor(agentIdentifier, aggregator, auto = true) {
24
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
23
+ constructor(agentRef, auto = true) {
24
+ super(agentRef, _constants.FEATURE_NAME, auto);
25
25
  try {
26
26
  // this try-catch can be removed when IE11 is completely unsupported & gone
27
27
  this.removeOnAbort = new AbortController();
@@ -44,7 +44,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
44
44
  (0, _handle.handle)('err', [(0, _castError.castErrorEvent)(errorEvent), (0, _now.now)(), false, {}, this.#replayRunning], undefined, this.featureName, this.ee);
45
45
  }, (0, _eventListenerOpts.eventListenerOpts)(false, this.removeOnAbort?.signal));
46
46
  this.abortHandler = this.#abort; // we also use this as a flag to denote that the feature is active or on and handling errors
47
- this.importAggregator();
47
+ this.importAggregator(agentRef);
48
48
  }
49
49
 
50
50
  /** Restoration and resource release tasks to be done if JS error loader is being aborted. Unwind changes to globals. */