@newrelic/browser-agent 1.269.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 (162) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/common/constants/env.cdn.js +1 -1
  3. package/dist/cjs/common/constants/env.npm.js +1 -1
  4. package/dist/cjs/common/constants/runtime.js +1 -2
  5. package/dist/cjs/common/harvest/harvest-scheduler.js +3 -4
  6. package/dist/cjs/common/unload/eol.js +2 -5
  7. package/dist/cjs/common/util/submit-data.js +1 -1
  8. package/dist/cjs/features/ajax/aggregate/index.js +8 -17
  9. package/dist/cjs/features/ajax/instrument/index.js +8 -10
  10. package/dist/cjs/features/generic_events/aggregate/index.js +15 -22
  11. package/dist/cjs/features/generic_events/instrument/index.js +5 -8
  12. package/dist/cjs/features/jserrors/aggregate/index.js +17 -22
  13. package/dist/cjs/features/jserrors/instrument/index.js +3 -3
  14. package/dist/cjs/features/logging/aggregate/index.js +16 -23
  15. package/dist/cjs/features/logging/instrument/index.js +3 -3
  16. package/dist/cjs/features/metrics/aggregate/index.js +13 -16
  17. package/dist/cjs/features/metrics/instrument/index.js +3 -3
  18. package/dist/cjs/features/page_view_event/aggregate/index.js +15 -29
  19. package/dist/cjs/features/page_view_event/instrument/index.js +3 -3
  20. package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -23
  21. package/dist/cjs/features/page_view_timing/instrument/index.js +3 -3
  22. package/dist/cjs/features/session_replay/aggregate/index.js +15 -29
  23. package/dist/cjs/features/session_replay/instrument/index.js +7 -5
  24. package/dist/cjs/features/session_trace/aggregate/index.js +25 -31
  25. package/dist/cjs/features/session_trace/instrument/index.js +4 -5
  26. package/dist/cjs/features/soft_navigations/aggregate/index.js +6 -11
  27. package/dist/cjs/features/soft_navigations/instrument/index.js +3 -3
  28. package/dist/cjs/features/spa/aggregate/index.js +19 -30
  29. package/dist/cjs/features/spa/instrument/index.js +4 -4
  30. package/dist/cjs/features/utils/aggregate-base.js +11 -12
  31. package/dist/cjs/features/utils/feature-base.js +5 -3
  32. package/dist/cjs/features/utils/instrument-base.js +18 -10
  33. package/dist/cjs/loaders/agent.js +1 -5
  34. package/dist/cjs/loaders/micro-agent.js +6 -9
  35. package/dist/esm/common/constants/env.cdn.js +1 -1
  36. package/dist/esm/common/constants/env.npm.js +1 -1
  37. package/dist/esm/common/constants/runtime.js +0 -1
  38. package/dist/esm/common/harvest/harvest-scheduler.js +3 -4
  39. package/dist/esm/common/unload/eol.js +2 -5
  40. package/dist/esm/common/util/submit-data.js +2 -2
  41. package/dist/esm/features/ajax/aggregate/index.js +8 -17
  42. package/dist/esm/features/ajax/instrument/index.js +8 -10
  43. package/dist/esm/features/generic_events/aggregate/index.js +11 -18
  44. package/dist/esm/features/generic_events/instrument/index.js +5 -8
  45. package/dist/esm/features/jserrors/aggregate/index.js +15 -20
  46. package/dist/esm/features/jserrors/instrument/index.js +3 -3
  47. package/dist/esm/features/logging/aggregate/index.js +16 -23
  48. package/dist/esm/features/logging/instrument/index.js +3 -3
  49. package/dist/esm/features/metrics/aggregate/index.js +8 -11
  50. package/dist/esm/features/metrics/instrument/index.js +3 -3
  51. package/dist/esm/features/page_view_event/aggregate/index.js +16 -30
  52. package/dist/esm/features/page_view_event/instrument/index.js +3 -3
  53. package/dist/esm/features/page_view_timing/aggregate/index.js +6 -23
  54. package/dist/esm/features/page_view_timing/instrument/index.js +3 -3
  55. package/dist/esm/features/session_replay/aggregate/index.js +13 -27
  56. package/dist/esm/features/session_replay/instrument/index.js +7 -5
  57. package/dist/esm/features/session_trace/aggregate/index.js +22 -28
  58. package/dist/esm/features/session_trace/instrument/index.js +4 -5
  59. package/dist/esm/features/soft_navigations/aggregate/index.js +6 -11
  60. package/dist/esm/features/soft_navigations/instrument/index.js +3 -3
  61. package/dist/esm/features/spa/aggregate/index.js +17 -28
  62. package/dist/esm/features/spa/instrument/index.js +4 -4
  63. package/dist/esm/features/utils/aggregate-base.js +13 -14
  64. package/dist/esm/features/utils/feature-base.js +5 -3
  65. package/dist/esm/features/utils/instrument-base.js +18 -10
  66. package/dist/esm/loaders/agent.js +1 -5
  67. package/dist/esm/loaders/micro-agent.js +6 -9
  68. package/dist/types/common/constants/runtime.d.ts +0 -1
  69. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  70. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  71. package/dist/types/common/unload/eol.d.ts +1 -1
  72. package/dist/types/common/unload/eol.d.ts.map +1 -1
  73. package/dist/types/features/ajax/aggregate/index.d.ts +1 -1
  74. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  75. package/dist/types/features/ajax/instrument/index.d.ts +1 -1
  76. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  77. package/dist/types/features/generic_events/aggregate/index.d.ts +1 -2
  78. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  79. package/dist/types/features/generic_events/instrument/index.d.ts +1 -1
  80. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  81. package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
  82. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  83. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  84. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  85. package/dist/types/features/logging/aggregate/index.d.ts +1 -2
  86. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  87. package/dist/types/features/logging/instrument/index.d.ts +1 -1
  88. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  89. package/dist/types/features/metrics/aggregate/index.d.ts +1 -1
  90. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  91. package/dist/types/features/metrics/instrument/index.d.ts +1 -1
  92. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  93. package/dist/types/features/page_action/instrument/index.d.ts +1 -0
  94. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  95. package/dist/types/features/page_view_event/aggregate/index.d.ts +1 -1
  96. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  97. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -1
  98. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  99. package/dist/types/features/page_view_timing/aggregate/index.d.ts +1 -5
  100. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  101. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -1
  102. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  103. package/dist/types/features/session_replay/aggregate/index.d.ts +0 -1
  104. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  105. package/dist/types/features/session_replay/instrument/index.d.ts +1 -1
  106. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  107. package/dist/types/features/session_trace/aggregate/index.d.ts +1 -3
  108. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  109. package/dist/types/features/session_trace/instrument/index.d.ts +1 -1
  110. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  111. package/dist/types/features/soft_navigations/aggregate/index.d.ts +1 -1
  112. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  113. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -1
  114. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  115. package/dist/types/features/spa/aggregate/index.d.ts +1 -1
  116. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  117. package/dist/types/features/spa/instrument/index.d.ts +1 -1
  118. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  119. package/dist/types/features/utils/aggregate-base.d.ts +2 -2
  120. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  121. package/dist/types/features/utils/feature-base.d.ts +2 -3
  122. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  123. package/dist/types/features/utils/instrument-base.d.ts +3 -3
  124. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  125. package/dist/types/loaders/agent.d.ts +0 -2
  126. package/dist/types/loaders/agent.d.ts.map +1 -1
  127. package/dist/types/loaders/micro-agent.d.ts +0 -2
  128. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  129. package/package.json +1 -1
  130. package/src/common/constants/__mocks__/runtime.js +0 -1
  131. package/src/common/constants/runtime.js +0 -2
  132. package/src/common/harvest/harvest-scheduler.js +3 -4
  133. package/src/common/unload/eol.js +2 -5
  134. package/src/common/util/submit-data.js +2 -2
  135. package/src/features/ajax/aggregate/index.js +8 -18
  136. package/src/features/ajax/instrument/index.js +8 -10
  137. package/src/features/generic_events/aggregate/index.js +11 -20
  138. package/src/features/generic_events/instrument/index.js +7 -10
  139. package/src/features/jserrors/aggregate/index.js +15 -20
  140. package/src/features/jserrors/instrument/index.js +3 -4
  141. package/src/features/logging/aggregate/index.js +15 -23
  142. package/src/features/logging/instrument/index.js +3 -3
  143. package/src/features/metrics/aggregate/index.js +8 -11
  144. package/src/features/metrics/instrument/index.js +3 -3
  145. package/src/features/page_view_event/aggregate/index.js +16 -22
  146. package/src/features/page_view_event/instrument/index.js +3 -3
  147. package/src/features/page_view_timing/aggregate/index.js +6 -23
  148. package/src/features/page_view_timing/instrument/index.js +3 -3
  149. package/src/features/session_replay/aggregate/index.js +13 -21
  150. package/src/features/session_replay/instrument/index.js +7 -5
  151. package/src/features/session_trace/aggregate/index.js +22 -28
  152. package/src/features/session_trace/instrument/index.js +4 -5
  153. package/src/features/soft_navigations/aggregate/index.js +6 -8
  154. package/src/features/soft_navigations/instrument/index.js +3 -3
  155. package/src/features/spa/aggregate/index.js +17 -26
  156. package/src/features/spa/instrument/index.js +4 -4
  157. package/src/features/utils/__mocks__/feature-base.js +1 -2
  158. package/src/features/utils/aggregate-base.js +13 -14
  159. package/src/features/utils/feature-base.js +6 -3
  160. package/src/features/utils/instrument-base.js +16 -10
  161. package/src/loaders/agent.js +1 -3
  162. package/src/loaders/micro-agent.js +7 -9
@@ -6,15 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Aggregate = void 0;
7
7
  var _registerHandler = require("../../../common/event-emitter/register-handler");
8
8
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
9
- var _info = require("../../../common/config/info");
10
- var _init = require("../../../common/config/init");
11
- var _runtime = require("../../../common/config/runtime");
12
9
  var _constants = require("../constants");
13
10
  var _aggregateBase = require("../../utils/aggregate-base");
14
11
  var _storage = require("./trace/storage");
15
12
  var _encode = require("../../../common/url/encode");
16
- var _drain = require("../../../common/drain/drain");
17
- var _runtime2 = require("../../../common/constants/runtime");
13
+ var _runtime = require("../../../common/constants/runtime");
18
14
  var _constants2 = require("../../../common/session/constants");
19
15
  var _traverse = require("../../../common/util/traverse");
20
16
  var _cleanUrl = require("../../../common/url/clean-url");
@@ -23,14 +19,12 @@ const ERROR_MODE_SECONDS_WINDOW = 30 * 1000; // sliding window of nodes to track
23
19
  const QUERY_PARAM_PADDING = 5000;
24
20
  class Aggregate extends _aggregateBase.AggregateBase {
25
21
  static featureName = _constants.FEATURE_NAME;
26
- constructor(agentIdentifier, aggregator) {
27
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
28
- this.agentRuntime = (0, _runtime.getRuntime)(agentIdentifier);
29
- this.agentInfo = (0, _info.getInfo)(agentIdentifier);
22
+ constructor(agentRef) {
23
+ super(agentRef, _constants.FEATURE_NAME);
30
24
 
31
25
  /** A buffer to hold on to harvested traces in the case that a retry must be made later */
32
26
  this.sentTrace = null;
33
- this.harvestTimeSeconds = (0, _init.getConfigurationValue)(agentIdentifier, 'session_trace.harvestTimeSeconds') || 30;
27
+ this.harvestTimeSeconds = agentRef.init.session_trace.harvestTimeSeconds || 30;
34
28
  /** Tied to the entitlement flag response from BCS. Will short circuit operations of the agg if false */
35
29
  this.entitled = undefined;
36
30
  /** A flag used to decide if the 30 node threshold should be ignored on the first harvest to ensure sending on the first payload */
@@ -46,12 +40,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
46
40
  /** Sets up event listeners, and initializes this module to run in the correct "mode". Can be triggered from a few places, but makes an effort to only set up listeners once */
47
41
  initialize(stMode, stEntitled, ignoreSession) {
48
42
  this.entitled ??= stEntitled;
49
- if (this.blocked || !this.entitled) return (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
43
+ if (this.blocked || !this.entitled) return this.deregisterDrain();
50
44
  if (!this.initialized) {
51
45
  this.initialized = true;
52
46
  /** Store session identifiers at initialization time to be cross-checked later at harvest time for session changes that are subject to race conditions */
53
- this.ptid = this.agentRuntime.ptid;
54
- this.sessionId = this.agentRuntime.session?.state.value;
47
+ this.ptid = this.agentRef.runtime.ptid;
48
+ this.sessionId = this.agentRef.runtime.session?.state.value;
55
49
  // The SessionEntity class can emit a message indicating the session was cleared and reset (expiry, inactivity). This feature must abort and never resume if that occurs.
56
50
  this.ee.on(_constants2.SESSION_EVENTS.RESET, () => {
57
51
  if (this.blocked) return;
@@ -67,20 +61,20 @@ class Aggregate extends _aggregateBase.AggregateBase {
67
61
  if (this.sessionId !== sessionState.value || eventType === 'cross-tab' && this.scheduler?.started && sessionState.sessionTraceMode === _constants2.MODE.OFF) this.abort(2);
68
62
  });
69
63
  if (typeof PerformanceNavigationTiming !== 'undefined') {
70
- this.traceStorage.storeTiming(_runtime2.globalScope.performance?.getEntriesByType?.('navigation')[0]);
64
+ this.traceStorage.storeTiming(_runtime.globalScope.performance?.getEntriesByType?.('navigation')[0]);
71
65
  } else {
72
- this.traceStorage.storeTiming(_runtime2.globalScope.performance?.timing, true);
66
+ this.traceStorage.storeTiming(_runtime.globalScope.performance?.timing, true);
73
67
  }
74
68
  }
75
69
 
76
70
  /** ST/SR sampling flow in BCS - https://drive.google.com/file/d/19hwt2oft-8Hh4RrjpLqEXfpP_9wYBLcq/view?usp=sharing */
77
71
  /** ST will run in the mode provided by BCS if the session IS NEW. If not... it will use the state of the session entity to determine what mode to run in */
78
- if (!this.agentRuntime.session.isNew && !ignoreSession) this.mode = this.agentRuntime.session.state.sessionTraceMode;else this.mode = stMode;
72
+ if (!this.agentRef.runtime.session.isNew && !ignoreSession) this.mode = this.agentRef.runtime.session.state.sessionTraceMode;else this.mode = stMode;
79
73
 
80
74
  /** If the mode is off, we do not want to hold up draining for other features, so we deregister the feature for now.
81
75
  * If it drains later (due to a mode change), data and handlers will instantly drain instead of waiting for the registry. */
82
- if (this.mode === _constants2.MODE.OFF) return (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
83
- this.timeKeeper ??= this.agentRuntime.timeKeeper;
76
+ if (this.mode === _constants2.MODE.OFF) return this.deregisterDrain();
77
+ this.timeKeeper ??= this.agentRef.runtime.timeKeeper;
84
78
  this.scheduler = new _harvestScheduler.HarvestScheduler('browser/blobs', {
85
79
  onFinished: this.onHarvestFinished.bind(this),
86
80
  retryDelay: this.harvestTimeSeconds,
@@ -104,7 +98,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
104
98
  if (this.mode === _constants2.MODE.ERROR) this.switchToFull();
105
99
  }, this.featureName, this.ee);
106
100
  }
107
- this.agentRuntime.session.write({
101
+ this.agentRef.runtime.session.write({
108
102
  sessionTraceMode: this.mode
109
103
  });
110
104
  this.drain();
@@ -122,7 +116,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
122
116
  this.traceStorage.prevStoredEvents.clear(); // release references to past events for GC
123
117
  if (!this.timeKeeper?.ready) return; // this should likely never happen, but just to be safe, we should never harvest if we cant correct time
124
118
  if (this.blocked || this.mode !== _constants2.MODE.FULL || this.traceStorage.nodeCount === 0) return;
125
- if (this.sessionId !== this.agentRuntime.session?.state.value || this.ptid !== this.agentRuntime.ptid) return this.abort(3); // if something unexpected happened and we somehow still got to the point of harvesting after a session identifier changed, we should force-exit instead of harvesting
119
+ if (this.sessionId !== this.agentRef.runtime.session?.state.value || this.ptid !== this.agentRef.runtime.ptid) return this.abort(3); // if something unexpected happened and we somehow still got to the point of harvesting after a session identifier changed, we should force-exit instead of harvesting
126
120
  /** Get the ST nodes from the traceStorage buffer. This also returns helpful metadata about the payload. */
127
121
  const {
128
122
  stns,
@@ -133,12 +127,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
133
127
  if (options.retry) {
134
128
  this.sentTrace = stns;
135
129
  }
136
- const firstSessionHarvest = !this.agentRuntime.session.state.traceHarvestStarted;
137
- if (firstSessionHarvest) this.agentRuntime.session.write({
130
+ const firstSessionHarvest = !this.agentRef.runtime.session.state.traceHarvestStarted;
131
+ if (firstSessionHarvest) this.agentRef.runtime.session.write({
138
132
  traceHarvestStarted: true
139
133
  });
140
- const hasReplay = this.agentRuntime.session?.state.sessionReplayMode === 1;
141
- const endUserId = this.agentInfo?.jsAttributes?.['enduser.id'];
134
+ const hasReplay = this.agentRef.runtime.session?.state.sessionReplayMode === 1;
135
+ const endUserId = this.agentRef.info?.jsAttributes?.['enduser.id'];
142
136
  this.everHarvested = true;
143
137
 
144
138
  /** The blob consumer expects the following and will reject if not supplied:
@@ -150,19 +144,19 @@ class Aggregate extends _aggregateBase.AggregateBase {
150
144
  *
151
145
  * For data that does not fit the schema of the above, it should be url-encoded and placed into `attributes`
152
146
  */
153
- const agentMetadata = this.agentRuntime.appMetadata?.agents?.[0] || {};
147
+ const agentMetadata = this.agentRef.runtime.appMetadata?.agents?.[0] || {};
154
148
  return {
155
149
  qs: {
156
- browser_monitoring_key: this.agentInfo.licenseKey,
150
+ browser_monitoring_key: this.agentRef.info.licenseKey,
157
151
  type: 'BrowserSessionChunk',
158
- app_id: this.agentInfo.applicationID,
152
+ app_id: this.agentRef.info.applicationID,
159
153
  protocol_version: '0',
160
154
  timestamp: Math.floor(this.timeKeeper.correctRelativeTimestamp(earliestTimeStamp)),
161
155
  attributes: (0, _encode.obj)({
162
156
  ...(agentMetadata.entityGuid && {
163
157
  entityGuid: agentMetadata.entityGuid
164
158
  }),
165
- harvestId: "".concat(this.agentRuntime.session?.state.value, "_").concat(this.agentRuntime.ptid, "_").concat(this.agentRuntime.harvestCount),
159
+ harvestId: "".concat(this.agentRef.runtime.session?.state.value, "_").concat(this.agentRef.runtime.ptid, "_").concat(this.agentRef.runtime.harvestCount),
166
160
  // this section of attributes must be controllable and stay below the query param padding limit -- see QUERY_PARAM_PADDING
167
161
  // if not, data could be lost to truncation at time of sending, potentially breaking parsing / API behavior in NR1
168
162
  // trace payload metadata
@@ -171,7 +165,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
171
165
  'trace.nodes': stns.length,
172
166
  'trace.originTimestamp': this.timeKeeper.correctedOriginTime,
173
167
  // other payload metadata
174
- agentVersion: this.agentRuntime.version,
168
+ agentVersion: this.agentRef.runtime.version,
175
169
  ...(firstSessionHarvest && {
176
170
  firstSessionHarvest
177
171
  }),
@@ -210,7 +204,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
210
204
  if (this.mode === _constants2.MODE.FULL || !this.entitled || this.blocked) return;
211
205
  const prevMode = this.mode;
212
206
  this.mode = _constants2.MODE.FULL;
213
- this.agentRuntime.session.write({
207
+ this.agentRef.runtime.session.write({
214
208
  sessionTraceMode: this.mode
215
209
  });
216
210
  if (prevMode === _constants2.MODE.OFF || !this.initialized) return this.initialize(this.mode, this.entitled);
@@ -224,7 +218,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
224
218
  abort(reason) {
225
219
  this.blocked = true;
226
220
  this.mode = _constants2.MODE.OFF;
227
- this.agentRuntime.session.write({
221
+ this.agentRef.runtime.session.write({
228
222
  sessionTraceMode: this.mode
229
223
  });
230
224
  this.scheduler?.stopTimer();
@@ -10,7 +10,6 @@ var _wrapEvents = require("../../../common/wrap/wrap-events");
10
10
  var _instrumentBase = require("../../utils/instrument-base");
11
11
  var CONSTANTS = _interopRequireWildcard(require("../constants"));
12
12
  var _features = require("../../../loaders/features/features");
13
- var _drain = require("../../../common/drain/drain");
14
13
  var _featureGates = require("../../utils/feature-gates");
15
14
  var _now = require("../../../common/timing/now");
16
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); }
@@ -32,11 +31,11 @@ const {
32
31
  } = CONSTANTS;
33
32
  class Instrument extends _instrumentBase.InstrumentBase {
34
33
  static featureName = FEATURE_NAME;
35
- constructor(agentIdentifier, aggregator, auto = true) {
36
- super(agentIdentifier, aggregator, FEATURE_NAME, auto);
34
+ constructor(agentRef, auto = true) {
35
+ super(agentRef, FEATURE_NAME, auto);
37
36
  const canTrackSession = (0, _featureGates.canEnableSessionTracking)(this.agentIdentifier);
38
37
  if (!canTrackSession) {
39
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
38
+ this.deregisterDrain();
40
39
  return;
41
40
  }
42
41
  const thisInstrumentEE = this.ee;
@@ -72,7 +71,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
72
71
  } catch (e) {
73
72
  // Per NEWRELIC-8525, we don't have a fallback for capturing resources for older versions that don't support PO at this time.
74
73
  }
75
- this.importAggregator({
74
+ this.importAggregator(agentRef, {
76
75
  resourceObserver: observer
77
76
  });
78
77
  }
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Aggregate = void 0;
7
- var _init = require("../../../common/config/init");
8
- var _drain = require("../../../common/drain/drain");
9
7
  var _handle = require("../../../common/event-emitter/handle");
10
8
  var _registerHandler = require("../../../common/event-emitter/register-handler");
11
9
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
@@ -21,14 +19,14 @@ var _initialPageLoadInteraction = require("./initial-page-load-interaction");
21
19
  var _interaction = require("./interaction");
22
20
  class Aggregate extends _aggregateBase.AggregateBase {
23
21
  static featureName = _constants2.FEATURE_NAME;
24
- constructor(agentIdentifier, aggregator, {
22
+ constructor(agentRef, {
25
23
  domObserver
26
24
  }) {
27
- super(agentIdentifier, aggregator, _constants2.FEATURE_NAME);
28
- const harvestTimeSeconds = (0, _init.getConfigurationValue)(agentIdentifier, 'soft_navigations.harvestTimeSeconds') || 10;
25
+ super(agentRef, _constants2.FEATURE_NAME);
26
+ const harvestTimeSeconds = agentRef.init.soft_navigations.harvestTimeSeconds || 10;
29
27
  this.interactionsToHarvest = new _eventBuffer.EventBuffer();
30
28
  this.domObserver = domObserver;
31
- this.initialPageLoadInteraction = new _initialPageLoadInteraction.InitialPageLoadInteraction(agentIdentifier);
29
+ this.initialPageLoadInteraction = new _initialPageLoadInteraction.InitialPageLoadInteraction(agentRef.agentIdentifier);
32
30
  _timeToFirstByte.timeToFirstByte.subscribe(({
33
31
  attrs
34
32
  }) => {
@@ -51,15 +49,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
51
49
  onFinished: this.onHarvestFinished.bind(this),
52
50
  retryDelay: harvestTimeSeconds,
53
51
  onUnload: () => this.interactionInProgress?.done() // return any held ajax or jserr events so they can be sent with EoL harvest
54
- }, {
55
- agentIdentifier,
56
- ee: this.ee
57
- });
52
+ }, this);
58
53
  scheduler.harvest.on('events', this.onHarvestStarted.bind(this));
59
54
  scheduler.startTimer(harvestTimeSeconds, 0);
60
55
  } else {
61
56
  this.blocked = true; // if rum response determines that customer lacks entitlements for spa endpoint, this feature shouldn't harvest
62
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
57
+ this.deregisterDrain();
63
58
  }
64
59
  });
65
60
 
@@ -23,8 +23,8 @@ const UI_WAIT_INTERVAL = 1 / 10 * 1000; // assume 10 fps
23
23
 
24
24
  class Instrument extends _instrumentBase.InstrumentBase {
25
25
  static featureName = _constants.FEATURE_NAME;
26
- constructor(agentIdentifier, aggregator, auto = true) {
27
- super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
26
+ constructor(agentRef, auto = true) {
27
+ super(agentRef, _constants.FEATURE_NAME, auto);
28
28
  if (!_runtime.isBrowserScope || !(0, _nreum.gosNREUMOriginals)().o.MO) return; // soft navigations is not supported outside web env or browsers without the mutation observer API
29
29
 
30
30
  const historyEE = (0, _wrapHistory.wrapHistory)(this.ee);
@@ -66,7 +66,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
66
66
  });
67
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
68
  this.abortHandler = abort;
69
- this.importAggregator({
69
+ this.importAggregator(agentRef, {
70
70
  domObserver
71
71
  });
72
72
  function abort() {
@@ -10,8 +10,6 @@ var _denyList = require("../../../common/deny-list/deny-list");
10
10
  var _navTiming = require("../../../common/timing/nav-timing");
11
11
  var _uniqueId = require("../../../common/ids/unique-id");
12
12
  var _interaction = require("./interaction");
13
- var _init = require("../../../common/config/init");
14
- var _runtime = require("../../../common/config/runtime");
15
13
  var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
16
14
  var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
17
15
  var _serializer = require("./serializer");
@@ -22,10 +20,9 @@ var _aggregateBase = require("../../utils/aggregate-base");
22
20
  var _firstContentfulPaint = require("../../../common/vitals/first-contentful-paint");
23
21
  var _firstPaint = require("../../../common/vitals/first-paint");
24
22
  var _bundleId = require("../../../common/ids/bundle-id");
25
- var _runtime2 = require("../../../common/constants/runtime");
23
+ var _runtime = require("../../../common/constants/runtime");
26
24
  var _handle = require("../../../common/event-emitter/handle");
27
25
  var _constants2 = require("../../metrics/constants");
28
- var _drain = require("../../../common/drain/drain");
29
26
  var _console = require("../../../common/util/console");
30
27
  var _eventBuffer = require("../../utils/event-buffer");
31
28
  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); }
@@ -56,12 +53,11 @@ const {
56
53
  } = CONSTANTS;
57
54
  class Aggregate extends _aggregateBase.AggregateBase {
58
55
  static featureName = FEATURE_NAME;
59
- constructor(agentIdentifier, aggregator) {
60
- super(agentIdentifier, aggregator, FEATURE_NAME);
61
- const agentRuntime = (0, _runtime.getRuntime)(agentIdentifier);
56
+ constructor(agentRef) {
57
+ super(agentRef, FEATURE_NAME);
62
58
  this.state = {
63
- initialPageURL: agentRuntime.origin,
64
- lastSeenUrl: agentRuntime.origin,
59
+ initialPageURL: agentRef.runtime.origin,
60
+ lastSeenUrl: agentRef.runtime.origin,
65
61
  lastSeenRouteName: null,
66
62
  timerMap: {},
67
63
  timerBudget: MAX_TIMER_BUDGET,
@@ -72,10 +68,10 @@ class Aggregate extends _aggregateBase.AggregateBase {
72
68
  pageLoaded: false,
73
69
  childTime: 0,
74
70
  depth: 0,
75
- harvestTimeSeconds: (0, _init.getConfigurationValue)(agentIdentifier, 'spa.harvestTimeSeconds') || 10,
71
+ harvestTimeSeconds: agentRef.init.spa.harvestTimeSeconds || 10,
76
72
  interactionsToHarvest: new _eventBuffer.EventBuffer(),
77
73
  // The below feature flag is used to disable the SPA ajax fix for specific customers, see https://new-relic.atlassian.net/browse/NR-172169
78
- disableSpaFix: ((0, _init.getConfigurationValue)(agentIdentifier, 'feature_flags') || []).indexOf('disable-spa-fix') > -1
74
+ disableSpaFix: (agentRef.init.feature_flags || []).indexOf('disable-spa-fix') > -1
79
75
  };
80
76
  let scheduler;
81
77
  this.serializer = new _serializer.Serializer(this);
@@ -83,7 +79,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
83
79
  state,
84
80
  serializer
85
81
  } = this;
86
- const baseEE = _contextualEe.ee.get(agentIdentifier); // <-- parent baseEE
82
+ const baseEE = _contextualEe.ee.get(agentRef.agentIdentifier); // <-- parent baseEE
87
83
  const mutationEE = baseEE.get('mutation');
88
84
  const promiseEE = baseEE.get('promise');
89
85
  const historyEE = baseEE.get('history');
@@ -131,19 +127,16 @@ class Aggregate extends _aggregateBase.AggregateBase {
131
127
  scheduler = new _harvestScheduler.HarvestScheduler('events', {
132
128
  onFinished: onHarvestFinished,
133
129
  retryDelay: state.harvestTimeSeconds
134
- }, {
135
- agentIdentifier,
136
- ee: baseEE
137
- });
130
+ }, this);
138
131
  scheduler.harvest.on('events', onHarvestStarted);
139
132
  this.drain();
140
133
  } else {
141
134
  this.blocked = true;
142
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
135
+ this.deregisterDrain();
143
136
  }
144
137
  });
145
- if (!isEnabled()) return;
146
- state.initialPageLoad = new _interaction.Interaction('initialPageLoad', 0, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier);
138
+ if (agentRef.init.spa.enabled !== true) return;
139
+ state.initialPageLoad = new _interaction.Interaction('initialPageLoad', 0, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentRef.agentIdentifier);
147
140
  state.initialPageLoad.save = true;
148
141
  state.prevInteraction = state.initialPageLoad;
149
142
  state.currentNode = state.initialPageLoad.root; // hint
@@ -193,7 +186,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
193
186
  var ev = args[0];
194
187
  var evName = ev.type;
195
188
  var eventNode = ev["__nrNode:".concat(_bundleId.bundleId)];
196
- if (!state.pageLoaded && (evName === 'load' && eventSource === window || _runtime2.loadedAsDeferredBrowserScript)) {
189
+ if (!state.pageLoaded && (evName === 'load' && eventSource === window || _runtime.loadedAsDeferredBrowserScript)) {
197
190
  state.pageLoaded = true;
198
191
  // set to null so prevNode is set correctly
199
192
  this.prevNode = state.currentNode = null;
@@ -224,7 +217,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
224
217
  // Otherwise, if no interaction is currently active, create a new node ID,
225
218
  // and let the aggregator know that we entered a new event handler callback
226
219
  // so that it has a chance to possibly start an interaction.
227
- var ixn = new _interaction.Interaction(evName, this[FN_START], state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier);
220
+ var ixn = new _interaction.Interaction(evName, this[FN_START], state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentRef.agentIdentifier);
228
221
 
229
222
  // Store the interaction as prevInteraction in case it is prematurely discarded
230
223
  state.prevInteraction = ixn;
@@ -315,7 +308,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
315
308
  this.sent = true;
316
309
  node.dt = this.dt;
317
310
  if (node.dt?.timestamp) {
318
- node.dt.timestamp = agentRuntime.timeKeeper.correctAbsoluteTimestamp(node.dt.timestamp);
311
+ node.dt.timestamp = agentRef.runtime.timeKeeper.correctAbsoluteTimestamp(node.dt.timestamp);
319
312
  }
320
313
  node.jsEnd = node.start = this.startTime;
321
314
  node[INTERACTION][REMAINING]++;
@@ -404,7 +397,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
404
397
  if (dtPayload && this[SPA_NODE]) {
405
398
  this[SPA_NODE].dt = dtPayload;
406
399
  if (this[SPA_NODE].dt?.timestamp) {
407
- this[SPA_NODE].dt.timestamp = agentRuntime.timeKeeper.correctAbsoluteTimestamp(this[SPA_NODE].dt.timestamp);
400
+ this[SPA_NODE].dt.timestamp = agentRef.runtime.timeKeeper.correctAbsoluteTimestamp(this[SPA_NODE].dt.timestamp);
408
401
  }
409
402
  }
410
403
  }
@@ -522,7 +515,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
522
515
  }, this.featureName, promiseEE);
523
516
  (0, _registerHandler.registerHandler)(INTERACTION_API + 'get', function (t) {
524
517
  var interaction;
525
- if (state?.currentNode?.[INTERACTION]) interaction = this.ixn = state.currentNode[INTERACTION];else if (state?.prevNode?.end === null && state?.prevNode?.[INTERACTION]?.root?.[INTERACTION]?.eventName !== 'initialPageLoad') interaction = this.ixn = state.prevNode[INTERACTION];else interaction = this.ixn = new _interaction.Interaction('api', t, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentIdentifier);
518
+ if (state?.currentNode?.[INTERACTION]) interaction = this.ixn = state.currentNode[INTERACTION];else if (state?.prevNode?.end === null && state?.prevNode?.[INTERACTION]?.root?.[INTERACTION]?.eventName !== 'initialPageLoad') interaction = this.ixn = state.prevNode[INTERACTION];else interaction = this.ixn = new _interaction.Interaction('api', t, state.lastSeenUrl, state.lastSeenRouteName, onInteractionFinished, agentRef.agentIdentifier);
526
519
  if (!state.currentNode) {
527
520
  interaction.checkFinish();
528
521
  if (state.depth) setCurrentNode(interaction.root);
@@ -651,11 +644,11 @@ class Aggregate extends _aggregateBase.AggregateBase {
651
644
  (0, _registerHandler.registerHandler)('function-err', function (args, obj, error) {
652
645
  if (!state.currentNode) return;
653
646
  error.__newrelic ??= {};
654
- error.__newrelic[agentIdentifier] = {
647
+ error.__newrelic[agentRef.agentIdentifier] = {
655
648
  interactionId: state.currentNode.interaction.id
656
649
  };
657
650
  if (state.currentNode.type && state.currentNode.type !== 'interaction') {
658
- error.__newrelic[agentIdentifier].interactionNodeId = state.currentNode.id;
651
+ error.__newrelic[agentRef.agentIdentifier].interactionNodeId = state.currentNode.id;
659
652
  }
660
653
  }, this.featureName, baseEE);
661
654
  baseEE.on('interaction', saveInteraction);
@@ -693,10 +686,6 @@ class Aggregate extends _aggregateBase.AggregateBase {
693
686
  scheduler?.scheduleHarvest(0);
694
687
  if (!scheduler) (0, _console.warn)(19);
695
688
  }
696
- function isEnabled() {
697
- var enabled = (0, _init.getConfigurationValue)(agentIdentifier, 'spa.enabled');
698
- return enabled !== false;
699
- }
700
689
  }
701
690
  }
702
691
  exports.Aggregate = Aggregate;
@@ -42,8 +42,8 @@ const {
42
42
  */
43
43
  class Instrument extends _instrumentBase.InstrumentBase {
44
44
  static featureName = FEATURE_NAME;
45
- constructor(agentIdentifier, aggregator, auto = true) {
46
- super(agentIdentifier, aggregator, FEATURE_NAME, auto);
45
+ constructor(agentRef, auto = true) {
46
+ super(agentRef, FEATURE_NAME, auto);
47
47
  if (!_runtime.isBrowserScope) return; // SPA not supported outside web env
48
48
 
49
49
  try {
@@ -67,7 +67,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
67
67
  promiseEE.on(CB_END, endTimestamp);
68
68
  jsonpEE.on(CB_END, endTimestamp);
69
69
  this.ee.on('fn-err', (...args) => {
70
- if (!args[2]?.__newrelic?.[agentIdentifier]) (0, _handle.handle)('function-err', [...args], undefined, this.featureName, this.ee);
70
+ if (!args[2]?.__newrelic?.[agentRef.agentIdentifier]) (0, _handle.handle)('function-err', [...args], undefined, this.featureName, this.ee);
71
71
  });
72
72
  this.ee.buffer([FN_START, FN_END, 'xhr-resolved'], this.featureName);
73
73
  eventsEE.buffer([FN_START], this.featureName);
@@ -114,7 +114,7 @@ class Instrument extends _instrumentBase.InstrumentBase {
114
114
  });
115
115
  }
116
116
  this.abortHandler = this.#abort;
117
- this.importAggregator();
117
+ this.importAggregator(agentRef);
118
118
  }
119
119
 
120
120
  /** Restoration and resource release tasks to be done if SPA loader is being aborted. Unwind changes to globals and subscription to DOM events. */
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.AggregateBase = void 0;
7
7
  var _featureBase = require("./feature-base");
8
8
  var _info = require("../../common/config/info");
9
- var _runtime = require("../../common/config/runtime");
10
9
  var _configure = require("../../loaders/configure/configure");
11
10
  var _nreum = require("../../common/window/nreum");
12
11
  var _drain = require("../../common/drain/drain");
13
12
  var _featureFlags = require("../../common/util/feature-flags");
14
13
  var _obfuscate = require("../../common/util/obfuscate");
15
14
  class AggregateBase extends _featureBase.FeatureBase {
16
- constructor(...args) {
17
- super(...args);
18
- this.checkConfiguration();
19
- this.obfuscator = (0, _runtime.getRuntime)(this.agentIdentifier).obfuscator;
15
+ constructor(agentRef, featureName) {
16
+ super(agentRef.agentIdentifier, featureName);
17
+ this.agentRef = agentRef;
18
+ this.checkConfiguration(agentRef);
19
+ this.obfuscator = agentRef.runtime.obfuscator;
20
20
  }
21
21
 
22
22
  /**
@@ -43,7 +43,7 @@ class AggregateBase extends _featureBase.FeatureBase {
43
43
  return flagsPromise.catch(err => {
44
44
  this.ee.emit('internal-error', [err]);
45
45
  this.blocked = true;
46
- (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
46
+ this.deregisterDrain();
47
47
  });
48
48
  }
49
49
  drain() {
@@ -55,7 +55,7 @@ class AggregateBase extends _featureBase.FeatureBase {
55
55
  * Checks for additional `jsAttributes` items to support backward compatibility with implementations of the agent where
56
56
  * loader configurations may appear after the loader code is executed.
57
57
  */
58
- checkConfiguration() {
58
+ checkConfiguration(existingAgent) {
59
59
  // NOTE: This check has to happen at aggregator load time
60
60
  if (!(0, _info.isValid)(this.agentIdentifier)) {
61
61
  const cdn = (0, _nreum.gosCDN)();
@@ -65,7 +65,7 @@ class AggregateBase extends _featureBase.FeatureBase {
65
65
  try {
66
66
  jsAttributes = {
67
67
  ...jsAttributes,
68
- ...(0, _info.getInfo)(this.agentIdentifier)?.jsAttributes
68
+ ...existingAgent.info?.jsAttributes
69
69
  };
70
70
  } catch (err) {
71
71
  // do nothing
@@ -78,12 +78,11 @@ class AggregateBase extends _featureBase.FeatureBase {
78
78
  ...cdn.info,
79
79
  jsAttributes
80
80
  },
81
- runtime: (0, _runtime.getRuntime)(this.agentIdentifier)
81
+ runtime: existingAgent.runtime
82
82
  });
83
83
  }
84
- const runtime = (0, _runtime.getRuntime)(this.agentIdentifier);
85
- if (!runtime.obfuscator) {
86
- runtime.obfuscator = new _obfuscate.Obfuscator(this.agentIdentifier);
84
+ if (!existingAgent.runtime.obfuscator) {
85
+ existingAgent.runtime.obfuscator = new _obfuscate.Obfuscator(this.agentIdentifier);
87
86
  }
88
87
  }
89
88
  }
@@ -5,12 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.FeatureBase = void 0;
7
7
  var _contextualEe = require("../../common/event-emitter/contextual-ee");
8
+ var _drain = require("../../common/drain/drain");
8
9
  class FeatureBase {
9
- constructor(agentIdentifier, aggregator, featureName) {
10
+ constructor(agentIdentifier, featureName) {
10
11
  /** @type {string} */
11
12
  this.agentIdentifier = agentIdentifier;
12
- /** @type {import('../../common/aggregate/aggregator').Aggregator} */
13
- this.aggregator = aggregator;
14
13
  /** @type {import('../../common/event-emitter/contextual-ee').ee} */
15
14
  this.ee = _contextualEe.ee.get(agentIdentifier);
16
15
  /** @type {string} */
@@ -22,5 +21,8 @@ class FeatureBase {
22
21
  */
23
22
  this.blocked = false;
24
23
  }
24
+ deregisterDrain() {
25
+ (0, _drain.deregisterDrain)(this.agentIdentifier, this.featureName);
26
+ }
25
27
  }
26
28
  exports.FeatureBase = FeatureBase;
@@ -10,7 +10,6 @@ var _load = require("../../common/window/load");
10
10
  var _runtime = require("../../common/constants/runtime");
11
11
  var _console = require("../../common/util/console");
12
12
  var _features = require("../../loaders/features/features");
13
- var _init = require("../../common/config/init");
14
13
  var _utils = require("../session_replay/shared/utils");
15
14
  var _featureGates = require("./feature-gates");
16
15
  var _invoke = require("../../common/util/invoke");
@@ -28,14 +27,13 @@ class InstrumentBase extends _featureBase.FeatureBase {
28
27
  /**
29
28
  * Instantiate InstrumentBase.
30
29
  * @param {string} agentIdentifier - The unique ID of the instantiated agent (relative to global scope).
31
- * @param {import('../../common/aggregate/aggregator').Aggregator} aggregator - The shared Aggregator that will handle batching and reporting of data.
32
30
  * @param {string} featureName - The name of the feature module (used to construct file path).
33
31
  * @param {boolean} [auto=true] - Determines whether the feature should automatically register to have the draining
34
32
  * of its pooled instrumentation data handled by the agent's centralized drain functionality, rather than draining
35
33
  * immediately. Primarily useful for fine-grained control in tests.
36
34
  */
37
- constructor(agentIdentifier, aggregator, featureName, auto = true) {
38
- super(agentIdentifier, aggregator, featureName);
35
+ constructor(agentRef, featureName, auto = true) {
36
+ super(agentRef.agentIdentifier, featureName);
39
37
  this.auto = auto;
40
38
 
41
39
  /** @type {Function | undefined} This should be set by any derived Instrument class if it has things to do when feature fails or is killed. */
@@ -55,15 +53,15 @@ class InstrumentBase extends _featureBase.FeatureBase {
55
53
  this.onAggregateImported = undefined;
56
54
 
57
55
  /** used in conjunction with newrelic.start() to defer harvesting in features */
58
- if ((0, _init.getConfigurationValue)(this.agentIdentifier, "".concat(this.featureName, ".autoStart")) === false) this.auto = false;
56
+ if (agentRef.init[this.featureName].autoStart === false) this.auto = false;
59
57
  /** if the feature requires opt-in (!auto-start), it will get registered once the api has been called */
60
- if (this.auto) (0, _drain.registerDrain)(agentIdentifier, featureName);else {
58
+ if (this.auto) (0, _drain.registerDrain)(agentRef.agentIdentifier, featureName);else {
61
59
  this.ee.on('manual-start-all', (0, _invoke.single)(() => {
62
60
  // register the feature to drain only once the API has been called, it will drain when importAggregator finishes for all the features
63
61
  // called by the api in that cycle
64
- (0, _drain.registerDrain)(this.agentIdentifier, this.featureName);
62
+ (0, _drain.registerDrain)(agentRef.agentIdentifier, this.featureName);
65
63
  this.auto = true;
66
- this.importAggregator();
64
+ this.importAggregator(agentRef);
67
65
  }));
68
66
  }
69
67
  }
@@ -71,10 +69,11 @@ class InstrumentBase extends _featureBase.FeatureBase {
71
69
  /**
72
70
  * Lazy-load the latter part of the feature: its aggregator. This method is called by the first part of the feature
73
71
  * (the instrumentation) when instrumentation is complete.
72
+ * @param agentRef - reference to the base agent ancestor that this feature belongs to
74
73
  * @param {Object} [argsObjFromInstrument] - any values or references to pass down to aggregate
75
74
  * @returns void
76
75
  */
77
- importAggregator(argsObjFromInstrument = {}) {
76
+ importAggregator(agentRef, argsObjFromInstrument = {}) {
78
77
  if (this.featAggregate || !this.auto) return;
79
78
  let loadedSuccessfully;
80
79
  this.onAggregateImported = new Promise(resolve => {
@@ -96,6 +95,15 @@ class InstrumentBase extends _featureBase.FeatureBase {
96
95
  if (this.featureName === _features.FEATURE_NAMES.sessionReplay) this.abortHandler?.(); // SR should stop recording if session DNE
97
96
  }
98
97
 
98
+ // Create a single Aggregator for this agent if DNE yet; to be used by jserror endpoint features.
99
+ if (!agentRef.sharedAggregator) {
100
+ agentRef.sharedAggregator = Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "shared-aggregator" */'../../common/aggregate/aggregator')));
101
+ const {
102
+ Aggregator
103
+ } = await agentRef.sharedAggregator;
104
+ agentRef.sharedAggregator = new Aggregator();
105
+ } else await agentRef.sharedAggregator; // if another feature is already importing the aggregator, wait for it to finish
106
+
99
107
  /**
100
108
  * Note this try-catch differs from the one in Agent.run() in that it's placed later in a page's lifecycle and
101
109
  * it's only responsible for aborting its one specific feature, rather than all.
@@ -112,7 +120,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
112
120
  const {
113
121
  Aggregate
114
122
  } = await lazyFeatureLoader(this.featureName, 'aggregate');
115
- this.featAggregate = new Aggregate(this.agentIdentifier, this.aggregator, argsObjFromInstrument);
123
+ this.featAggregate = new Aggregate(agentRef, argsObjFromInstrument);
116
124
  loadedSuccessfully(true);
117
125
  } catch (e) {
118
126
  (0, _console.warn)(34, e);
@@ -12,7 +12,6 @@ var _configure = require("./configure/configure");
12
12
  var _featureDependencies = require("./features/featureDependencies");
13
13
  var _features = require("./features/features");
14
14
  var _instrument = require("../features/page_view_event/instrument");
15
- var _aggregator = require("../common/aggregate/aggregator");
16
15
  var _nreum = require("../common/window/nreum");
17
16
  var _console = require("../common/util/console");
18
17
  var _runtime = require("../common/constants/runtime");
@@ -41,9 +40,6 @@ class Agent extends _agentBase.AgentBase {
41
40
  (0, _console.warn)(21);
42
41
  return;
43
42
  }
44
- this.sharedAggregator = new _aggregator.Aggregator({
45
- agentIdentifier: this.agentIdentifier
46
- });
47
43
  this.features = {};
48
44
  (0, _nreum.setNREUMInitializedAgent)(this.agentIdentifier, this); // append this agent onto the global NREUM.initializedAgents
49
45
 
@@ -83,7 +79,7 @@ class Agent extends _agentBase.AgentBase {
83
79
  missingDependencies
84
80
  });
85
81
  }
86
- this.features[InstrumentCtor.featureName] = new InstrumentCtor(this.agentIdentifier, this.sharedAggregator);
82
+ this.features[InstrumentCtor.featureName] = new InstrumentCtor(this);
87
83
  });
88
84
  } catch (err) {
89
85
  (0, _console.warn)(22, err);