@newrelic/browser-agent 1.236.0 → 1.237.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 (111) hide show
  1. package/dist/cjs/common/config/state/init.js +1 -0
  2. package/dist/cjs/common/config/state/runtime.js +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/deny-list/deny-list.js +14 -10
  6. package/dist/cjs/common/harvest/harvest.js +7 -20
  7. package/dist/cjs/common/util/submit-data.js +4 -36
  8. package/dist/cjs/common/wrap/wrap-jsonp.js +12 -6
  9. package/dist/cjs/features/ajax/aggregate/index.js +24 -27
  10. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  11. package/dist/cjs/features/jserrors/constants.js +2 -4
  12. package/dist/cjs/features/jserrors/instrument/index.js +79 -88
  13. package/dist/cjs/features/jserrors/instrument/uncaught-error.js +22 -0
  14. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +23 -19
  15. package/dist/cjs/features/session_replay/aggregate/index.js +65 -34
  16. package/dist/cjs/features/session_trace/aggregate/index.js +3 -4
  17. package/dist/cjs/features/utils/instrument-base.js +6 -8
  18. package/dist/cjs/loaders/agent-base.js +87 -0
  19. package/dist/cjs/loaders/agent.js +41 -1
  20. package/dist/cjs/loaders/api/api.js +1 -1
  21. package/dist/cjs/loaders/api/interaction-types.js +87 -0
  22. package/dist/cjs/loaders/configure/configure.js +2 -1
  23. package/dist/cjs/loaders/micro-agent.js +3 -1
  24. package/dist/esm/common/config/state/init.js +1 -0
  25. package/dist/esm/common/config/state/runtime.js +2 -1
  26. package/dist/esm/common/constants/env.cdn.js +1 -1
  27. package/dist/esm/common/constants/env.npm.js +1 -1
  28. package/dist/esm/common/deny-list/deny-list.js +14 -10
  29. package/dist/esm/common/harvest/harvest.js +6 -20
  30. package/dist/esm/common/util/submit-data.js +4 -35
  31. package/dist/esm/common/wrap/wrap-jsonp.js +12 -6
  32. package/dist/esm/features/ajax/aggregate/index.js +25 -28
  33. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  34. package/dist/esm/features/jserrors/constants.js +1 -2
  35. package/dist/esm/features/jserrors/instrument/index.js +78 -87
  36. package/dist/esm/features/jserrors/instrument/uncaught-error.js +15 -0
  37. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +23 -19
  38. package/dist/esm/features/session_replay/aggregate/index.js +65 -34
  39. package/dist/esm/features/session_trace/aggregate/index.js +3 -4
  40. package/dist/esm/features/utils/instrument-base.js +7 -9
  41. package/dist/esm/loaders/agent-base.js +80 -0
  42. package/dist/esm/loaders/agent.js +41 -1
  43. package/dist/esm/loaders/api/api.js +1 -1
  44. package/dist/esm/loaders/api/interaction-types.js +80 -0
  45. package/dist/esm/loaders/configure/configure.js +3 -2
  46. package/dist/esm/loaders/micro-agent.js +3 -1
  47. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  48. package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
  49. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  50. package/dist/types/common/session/session-entity.d.ts +6 -6
  51. package/dist/types/common/util/submit-data.d.ts +2 -20
  52. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  53. package/dist/types/common/window/nreum.d.ts +2 -2
  54. package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
  55. package/dist/types/features/ajax/aggregate/index.d.ts +5 -5
  56. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  57. package/dist/types/features/jserrors/constants.d.ts +0 -1
  58. package/dist/types/features/jserrors/constants.d.ts.map +1 -1
  59. package/dist/types/features/jserrors/instrument/index.d.ts +0 -13
  60. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  61. package/dist/types/features/jserrors/instrument/uncaught-error.d.ts +15 -0
  62. package/dist/types/features/jserrors/instrument/uncaught-error.d.ts.map +1 -0
  63. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +5 -5
  64. package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -1
  65. package/dist/types/features/session_replay/aggregate/index.d.ts +16 -30
  66. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  67. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  68. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  69. package/dist/types/loaders/agent-base.d.ts +59 -0
  70. package/dist/types/loaders/agent-base.d.ts.map +1 -0
  71. package/dist/types/loaders/agent.d.ts +35 -1
  72. package/dist/types/loaders/agent.d.ts.map +1 -1
  73. package/dist/types/loaders/api/interaction-types.d.ts +122 -0
  74. package/dist/types/loaders/api/interaction-types.d.ts.map +1 -0
  75. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  76. package/dist/types/loaders/features/features.d.ts +9 -9
  77. package/dist/types/loaders/micro-agent.d.ts +3 -2
  78. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  79. package/package.json +1 -1
  80. package/src/common/config/state/init.js +1 -1
  81. package/src/common/config/state/runtime.js +2 -1
  82. package/src/common/deny-list/deny-list.js +11 -11
  83. package/src/common/deny-list/deny-list.test.js +31 -0
  84. package/src/common/harvest/harvest.js +7 -16
  85. package/src/common/harvest/harvest.test.js +16 -36
  86. package/src/common/util/__mocks__/submit-data.js +0 -1
  87. package/src/common/util/submit-data.js +2 -24
  88. package/src/common/util/submit-data.test.js +0 -56
  89. package/src/common/wrap/wrap-jsonp.js +11 -6
  90. package/src/features/ajax/aggregate/index.js +25 -31
  91. package/src/features/jserrors/aggregate/compute-stack-trace.js +1 -1
  92. package/src/features/jserrors/constants.js +0 -1
  93. package/src/features/jserrors/instrument/index.js +91 -87
  94. package/src/features/jserrors/instrument/uncaught-error.js +15 -0
  95. package/src/features/page_view_event/aggregate/initialized-features.js +18 -14
  96. package/src/features/session_replay/aggregate/index.component-test.js +17 -56
  97. package/src/features/session_replay/aggregate/index.js +47 -28
  98. package/src/features/session_trace/aggregate/index.js +3 -4
  99. package/src/features/utils/instrument-base.js +6 -9
  100. package/src/features/utils/instrument-base.test.js +7 -0
  101. package/src/loaders/agent-base.js +81 -0
  102. package/src/loaders/agent.js +42 -1
  103. package/src/loaders/api/api.js +1 -1
  104. package/src/loaders/api/interaction-types.js +80 -0
  105. package/src/loaders/configure/configure.js +4 -3
  106. package/src/loaders/micro-agent.js +4 -1
  107. package/dist/cjs/features/jserrors/instrument/debug.js +0 -40
  108. package/dist/esm/features/jserrors/instrument/debug.js +0 -38
  109. package/dist/types/features/jserrors/instrument/debug.d.ts +0 -2
  110. package/dist/types/features/jserrors/instrument/debug.d.ts.map +0 -1
  111. package/src/features/jserrors/instrument/debug.js +0 -36
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getActivatedFeaturesFlags = getActivatedFeaturesFlags;
7
7
  var _features = require("../../../loaders/features/features");
8
+ var _nreum = require("../../../common/window/nreum");
8
9
  /**
9
10
  * Get an array of flags required by downstream (NR UI) based on the features initialized in this agent
10
11
  * (aka what is running on the page).
@@ -13,25 +14,28 @@ var _features = require("../../../loaders/features/features");
13
14
  */
14
15
  function getActivatedFeaturesFlags(agentId) {
15
16
  const flagArr = [];
16
- Object.keys(newrelic.initializedAgents[agentId].features).forEach(featName => {
17
- switch (featName) {
18
- case _features.FEATURE_NAMES.ajax:
19
- flagArr.push('xhr');
20
- break;
21
- case _features.FEATURE_NAMES.jserrors:
22
- flagArr.push('err');
23
- break;
24
- case _features.FEATURE_NAMES.pageAction:
25
- flagArr.push('ins');
26
- break;
27
- case _features.FEATURE_NAMES.sessionTrace:
28
- flagArr.push('stn');
29
- break;
30
- case _features.FEATURE_NAMES.spa:
31
- flagArr.push('spa');
32
- break;
33
- }
34
- });
17
+ const newrelic = (0, _nreum.gosNREUM)();
18
+ try {
19
+ Object.keys(newrelic.initializedAgents[agentId].features).forEach(featName => {
20
+ switch (featName) {
21
+ case _features.FEATURE_NAMES.ajax:
22
+ flagArr.push('xhr');
23
+ break;
24
+ case _features.FEATURE_NAMES.jserrors:
25
+ flagArr.push('err');
26
+ break;
27
+ case _features.FEATURE_NAMES.pageAction:
28
+ flagArr.push('ins');
29
+ break;
30
+ case _features.FEATURE_NAMES.sessionTrace:
31
+ flagArr.push('stn');
32
+ break;
33
+ case _features.FEATURE_NAMES.spa:
34
+ flagArr.push('spa');
35
+ break;
36
+ }
37
+ });
38
+ } catch (e) {}
35
39
  return flagArr;
36
40
  }
37
41
 
@@ -13,6 +13,7 @@ var _config = require("../../../common/config/config");
13
13
  var _sessionEntity = require("../../../common/session/session-entity");
14
14
  var _aggregateBase = require("../../utils/aggregate-base");
15
15
  var _sharedChannel = require("../../../common/constants/shared-channel");
16
+ var _encode = require("../../../common/url/encode");
16
17
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } /*
18
19
  * Copyright 2023 New Relic Corporation. All rights reserved.
@@ -36,9 +37,13 @@ const MAX_PAYLOAD_SIZE = 1000000;
36
37
  /** Unloading caps around 64kb */
37
38
  exports.MAX_PAYLOAD_SIZE = MAX_PAYLOAD_SIZE;
38
39
  const IDEAL_PAYLOAD_SIZE = 64000;
39
- /** Interval between forcing new full snapshots in "error" mode */
40
+ /** Interval between forcing new full snapshots -- 30 seconds in error mode, 5 minutes in full mode */
40
41
  exports.IDEAL_PAYLOAD_SIZE = IDEAL_PAYLOAD_SIZE;
41
- const CHECKOUT_MS = 30000;
42
+ const CHECKOUT_MS = {
43
+ [_sessionEntity.MODE.ERROR]: 30000,
44
+ [_sessionEntity.MODE.FULL]: 300000,
45
+ [_sessionEntity.MODE.OFF]: 0
46
+ };
42
47
  class Aggregate extends _aggregateBase.AggregateBase {
43
48
  static featureName = _constants.FEATURE_NAME;
44
49
  constructor(agentIdentifier, aggregator) {
@@ -70,6 +75,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
70
75
  /** Payload metadata -- Should indicate that the payload being sent contains an error. Used for query/filter purposes in UI */
71
76
  this.hasError = false;
72
77
 
78
+ /** Payload metadata -- Should indicate when a replay blob started recording. Resets each time a harvest occurs. */
79
+ this.timestamp = {
80
+ first: undefined,
81
+ last: undefined
82
+ };
83
+
73
84
  /** A value which increments with every new mutation node reported. Resets after a harvest is sent */
74
85
  this.payloadBytesEstimation = 0;
75
86
  const shouldSetup = (0, _config.getConfigurationValue)(agentIdentifier, 'privacy.cookies_enabled') === true && (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.enabled') === true;
@@ -93,7 +104,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
93
104
  });
94
105
 
95
106
  // Bespoke logic for new endpoint. This will change as downstream dependencies become solidified.
96
- this.scheduler = new _harvestScheduler.HarvestScheduler('blob', {
107
+ this.scheduler = new _harvestScheduler.HarvestScheduler('browser/blobs', {
97
108
  onFinished: this.onHarvestFinished.bind(this),
98
109
  retryDelay: this.harvestTimeSeconds,
99
110
  getPayload: this.prepareHarvest.bind(this),
@@ -113,10 +124,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
113
124
  this.stopRecording();
114
125
  this.startRecording();
115
126
  this.scheduler.startTimer(this.harvestTimeSeconds);
116
- const {
117
- session
118
- } = (0, _config.getRuntime)(this.agentIdentifier);
119
- session.state.sessionReplay = this.mode;
127
+ this.syncWithSessionManager({
128
+ sessionReplay: this.mode
129
+ });
120
130
  }
121
131
  }
122
132
  }, this.featureName, this.ee);
@@ -189,17 +199,18 @@ class Aggregate extends _aggregateBase.AggregateBase {
189
199
  }
190
200
  this.startRecording();
191
201
  this.isFirstChunk = !!session.isNew;
192
- session.state.sessionReplay = this.mode;
202
+ this.syncWithSessionManager({
203
+ sessionReplay: this.mode
204
+ });
193
205
  }
194
206
  prepareHarvest() {
195
- if (this.events.length === 0) return;
207
+ if (this.events.length === 0 || this.mode !== _sessionEntity.MODE.FULL && !this.blocked) return;
196
208
  const payload = this.getHarvestContents();
197
209
  if (this.shouldCompress) {
198
210
  payload.body = gzipper(u8((0, _stringify.stringify)(payload.body)));
199
211
  this.scheduler.opts.gzip = true;
200
212
  } else {
201
213
  this.scheduler.opts.gzip = false;
202
- delete payload.qs.content_encoding;
203
214
  }
204
215
  // TODO -- Gracefully handle the buffer for retries.
205
216
  this.clearBuffer();
@@ -210,25 +221,28 @@ class Aggregate extends _aggregateBase.AggregateBase {
210
221
  const info = (0, _config.getInfo)(this.agentIdentifier);
211
222
  return {
212
223
  qs: {
213
- protocol_version: '0',
214
- content_encoding: 'gzip',
215
- browser_monitoring_key: info.licenseKey
216
- },
217
- body: {
224
+ browser_monitoring_key: info.licenseKey,
218
225
  type: 'SessionReplay',
219
- appId: Number(info.applicationID),
220
- timestamp: Date.now(),
221
- blob: JSON.stringify(this.events),
222
- // this needs to be a stringified JSON array of rrweb nodes
223
- attributes: {
226
+ app_id: info.applicationID,
227
+ protocol_version: '0',
228
+ attributes: (0, _encode.obj)({
229
+ ...(this.shouldCompress && {
230
+ content_encoding: 'gzip'
231
+ }),
232
+ 'replay.firstTimestamp': this.timestamp.first,
233
+ 'replay.lastTimestamp': this.timestamp.last,
234
+ 'replay.durationMs': this.timestamp.last - this.timestamp.first,
235
+ agentVersion: agentRuntime.version,
224
236
  session: agentRuntime.session.state.value,
225
237
  hasSnapshot: this.hasSnapshot,
226
238
  hasError: this.hasError,
227
- agentVersion: agentRuntime.version,
228
239
  isFirstChunk: this.isFirstChunk,
240
+ decompressedBytes: this.payloadBytesEstimation,
229
241
  'nr.rrweb.version': RRWEB_VERSION
230
- }
231
- }
242
+ }, MAX_PAYLOAD_SIZE - this.payloadBytesEstimation).substring(1) // remove the leading '&'
243
+ },
244
+
245
+ body: this.events
232
246
  };
233
247
  }
234
248
  onHarvestFinished(result) {
@@ -246,6 +260,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
246
260
  this.hasSnapshot = false;
247
261
  this.hasError = false;
248
262
  this.payloadBytesEstimation = 0;
263
+ this.clearTimestamps();
249
264
  }
250
265
 
251
266
  /** Begin recording using configured recording lib */
@@ -254,6 +269,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
254
269
  warn('Recording library was never imported');
255
270
  return this.abort();
256
271
  }
272
+ this.recording = true;
257
273
  const {
258
274
  blockClass,
259
275
  ignoreClass,
@@ -263,7 +279,6 @@ class Aggregate extends _aggregateBase.AggregateBase {
263
279
  maskTextSelector,
264
280
  maskAllInputs
265
281
  } = (0, _config.getConfigurationValue)(this.agentIdentifier, 'session_replay');
266
- this.hasSnapshot = true;
267
282
  // set up rrweb configurations for maximum privacy --
268
283
  // https://newrelic.atlassian.net/wiki/spaces/O11Y/pages/2792293280/2023+02+28+Browser+-+Session+Replay#Configuration-options
269
284
  const stop = recorder({
@@ -275,11 +290,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
275
290
  maskInputOptions,
276
291
  maskTextSelector,
277
292
  maskAllInputs,
278
- ...(this.mode === _sessionEntity.MODE.ERROR && {
279
- checkoutEveryNms: CHECKOUT_MS
280
- })
293
+ checkoutEveryNms: CHECKOUT_MS[this.mode]
281
294
  });
282
- this.recording = true;
283
295
  this.stopRecording = () => {
284
296
  this.recording = false;
285
297
  stop();
@@ -304,12 +316,14 @@ class Aggregate extends _aggregateBase.AggregateBase {
304
316
  // we are still waiting for an error to throw, so keep wiping the buffer over time
305
317
  this.clearBuffer();
306
318
  }
319
+ this.setTimestamps(event);
320
+ if (event.type === 2) this.hasSnapshot = true;
307
321
  this.events.push(event);
308
322
  this.payloadBytesEstimation += eventBytes;
309
323
 
310
324
  // We are making an effort to try to keep payloads manageable for unloading. If they reach the unload limit before their interval,
311
325
  // it will send immediately. This often happens on the first snapshot, which can be significantly larger than the other payloads.
312
- if (payloadSize > IDEAL_PAYLOAD_SIZE) {
326
+ if (payloadSize > IDEAL_PAYLOAD_SIZE && this.mode !== _sessionEntity.MODE.ERROR) {
313
327
  // if we've made it to the ideal size of ~64kb before the interval timer, we should send early.
314
328
  this.scheduler.runHarvest();
315
329
  }
@@ -319,7 +333,17 @@ class Aggregate extends _aggregateBase.AggregateBase {
319
333
  takeFullSnapshot() {
320
334
  if (!recorder) return;
321
335
  recorder.takeFullSnapshot();
322
- this.hasSnapshot = true;
336
+ }
337
+ setTimestamps(rrwebEvent) {
338
+ if (!rrwebEvent) return;
339
+ if (!this.timestamp.first) this.timestamp.first = rrwebEvent.timestamp;
340
+ this.timestamp.last = rrwebEvent.timestamp;
341
+ }
342
+ clearTimestamps() {
343
+ this.timestamp = {
344
+ first: undefined,
345
+ last: undefined
346
+ };
323
347
  }
324
348
 
325
349
  /** Estimate the payload size */
@@ -334,11 +358,11 @@ class Aggregate extends _aggregateBase.AggregateBase {
334
358
  this.blocked = true;
335
359
  this.mode = _sessionEntity.MODE.OFF;
336
360
  this.stopRecording();
361
+ this.syncWithSessionManager({
362
+ sessionReplay: this.mode
363
+ });
364
+ this.clearTimestamps();
337
365
  this.ee.emit('REPLAY_ABORTED');
338
- const {
339
- session
340
- } = (0, _config.getRuntime)(this.agentIdentifier);
341
- session.state.sessionReplay = this.mode;
342
366
  }
343
367
 
344
368
  /** Extensive research has yielded about an 88% compression factor on these payloads.
@@ -349,5 +373,12 @@ class Aggregate extends _aggregateBase.AggregateBase {
349
373
  if (this.shouldCompress) return data * AVG_COMPRESSION;
350
374
  return data;
351
375
  }
376
+ syncWithSessionManager() {
377
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
378
+ const {
379
+ session
380
+ } = (0, _config.getRuntime)(this.agentIdentifier);
381
+ session.write(state);
382
+ }
352
383
  }
353
384
  exports.Aggregate = Aggregate;
@@ -116,8 +116,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
116
116
  sessionTraceMode: _sessionEntity.MODE.OFF
117
117
  });
118
118
  operationalGate.permanentlyDecide(false);
119
- this.#scheduler?.stopTimer(true);
120
119
  if (mostRecentModeKnown === _sessionEntity.MODE.FULL) this.#scheduler?.runHarvest(); // allow queued nodes (past opGate) to final harvest, unless they were buffered in other modes
120
+ this.#scheduler?.stopTimer(true); // the 'true' arg here will forcibly block any future call to runHarvest, so the last runHarvest above must be prior
121
121
  this.#scheduler = null;
122
122
  };
123
123
 
@@ -143,9 +143,8 @@ class Aggregate extends _aggregateBase.AggregateBase {
143
143
  this.ee.on(_sessionEntity.SESSION_EVENTS.PAUSE, () => mostRecentModeKnown = sessionEntity.state.sessionTraceMode);
144
144
  if (!sessionEntity.isNew) {
145
145
  // inherit the same mode as existing session's Trace
146
- const existingTraceMode = mostRecentModeKnown = sessionEntity.state.sessionTraceMode;
147
- if (existingTraceMode === _sessionEntity.MODE.OFF) this.isStandalone = true;
148
- controlTraceOp(existingTraceMode);
146
+ if (sessionEntity.state.sessionReplay === _sessionEntity.MODE.OFF) this.isStandalone = true;
147
+ controlTraceOp(mostRecentModeKnown = sessionEntity.state.sessionTraceMode);
149
148
  } else {
150
149
  // for new sessions, see the truth table associated with NEWRELIC-8662 wrt the new Trace behavior under session management
151
150
  const replayMode = await (0, _replayMode.getSessionReplayMode)(agentIdentifier);
@@ -61,7 +61,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
61
61
  let argsObjFromInstrument = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
62
62
  if (this.featAggregate || !this.auto) return;
63
63
  const enableSessionTracking = _runtime.isBrowserScope && (0, _config.getConfigurationValue)(this.agentIdentifier, 'privacy.cookies_enabled') === true;
64
- let loadedSuccessfully, loadFailed;
64
+ let loadedSuccessfully;
65
65
  this.onAggregateImported = new Promise(resolve => {
66
66
  loadedSuccessfully = resolve;
67
67
  });
@@ -86,6 +86,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
86
86
  try {
87
87
  if (!this.shouldImportAgg(this.featureName, session)) {
88
88
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
89
+ loadedSuccessfully(false); // aggregate module isn't loaded at all
89
90
  return;
90
91
  }
91
92
  const {
@@ -116,15 +117,12 @@ class InstrumentBase extends _featureBase.FeatureBase {
116
117
  * @returns
117
118
  */
118
119
  shouldImportAgg(featureName, session) {
119
- // if this isnt the FIRST load of a session AND
120
- // we are not actively recording SR... DO NOT run the aggregator
121
- // session replay samples can only be decided on the first load of a session
122
- // session replays can continue if in progress
123
120
  if (featureName === _features.FEATURE_NAMES.sessionReplay) {
124
- if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'session_trace.enabled') === false) return false;
125
- return !!session?.isNew || !!session?.state.sessionReplay;
121
+ if (!_config.originals.MO) return false; // Session Replay cannot work without Mutation Observer
122
+ if ((0, _config.getConfigurationValue)(this.agentIdentifier, 'session_trace.enabled') === false) return false; // Session Replay as of now is tightly coupled with Session Trace in the UI
123
+ return !!session?.isNew || !!session?.state.sessionReplay; // Session Replay should only try to run if already running from a previous page, or at the beginning of a session
126
124
  }
127
- // todo -- add case like above for session trace
125
+
128
126
  return true;
129
127
  }
130
128
  }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AgentBase = void 0;
7
+ var _console = require("../common/util/console");
8
+ class AgentBase {
9
+ /**
10
+ * Reports a browser PageAction event along with a name and optional attributes.
11
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction/}
12
+ * @param {string} name Name or category of the action. Reported as the actionName attribute.
13
+ * @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.
14
+ */
15
+ addPageAction(name, attributes) {
16
+ (0, _console.warn)('Call to agent api addPageAction failed. The session trace feature is not currently initialized.');
17
+ }
18
+
19
+ /**
20
+ * Groups page views to help URL structure or to capture the URL's routing information.
21
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
22
+ * @param {string} name The page name you want to use. Use alphanumeric characters.
23
+ * @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
24
+ */
25
+ setPageViewName(name, host) {
26
+ (0, _console.warn)('Call to agent api setPageViewName failed. The page view feature is not currently initialized.');
27
+ }
28
+
29
+ /**
30
+ * Adds a user-defined attribute name and value to subsequent events on the page.
31
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
32
+ * @param {string} name Name of the attribute. Appears as column in the PageView event. It will also appear as a column in the PageAction event if you are using it.
33
+ * @param {string|number|null} value Value of the attribute. Appears as the value in the named attribute column in the PageView event. It will appear as a column in the PageAction event if you are using it. Custom attribute values cannot be complex objects, only simple types such as Strings and Integers.
34
+ * @param {boolean} [persist] Default false. f set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
35
+ */
36
+ setCustomAttribute(name, value, persist) {
37
+ (0, _console.warn)('Call to agent api setCustomAttribute failed. The js errors feature is not currently initialized.');
38
+ }
39
+
40
+ /**
41
+ * Identifies a browser error without disrupting your app's operations.
42
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
43
+ * @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
44
+ * @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
45
+ */
46
+ noticeError(error, customAttributes) {
47
+ (0, _console.warn)('Call to agent api noticeError failed. The js errors feature is not currently initialized.');
48
+ }
49
+
50
+ /**
51
+ * Adds a user-defined identifier string to subsequent events on the page.
52
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
53
+ * @param {string|null} value A string identifier for the end-user, useful for tying all browser events to specific users. The value parameter does not have to be unique. If IDs should be unique, the caller is responsible for that validation. Passing a null value unsets any existing user ID.
54
+ */
55
+ setUserId(value) {
56
+ (0, _console.warn)('Call to agent api setUserId failed. The js errors feature is not currently initialized.');
57
+ }
58
+
59
+ /**
60
+ * Allows selective ignoring and grouping of known errors that the browser agent captures.
61
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
62
+ * @param {(error: Error|string) => boolean | { group: string }} callback When an error occurs, the callback is called with the error object as a parameter. The callback will be called with each error, so it is not specific to one error.
63
+ */
64
+ setErrorHandler(callback) {
65
+ (0, _console.warn)('Call to agent api setErrorHandler failed. The js errors feature is not currently initialized.');
66
+ }
67
+
68
+ /**
69
+ * Records an additional time point as "finished" in a session trace, and sends the event to New Relic.
70
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/finished/}
71
+ * @param {number} [timeStamp] Defaults to the current time of the call. If used, this marks the time that the page is "finished" according to your own criteria.
72
+ */
73
+ finished(timeStamp) {
74
+ (0, _console.warn)('Call to agent api finished failed. The page action feature is not currently initialized.');
75
+ }
76
+
77
+ /**
78
+ * Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
79
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
80
+ * @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
81
+ * @param {string} id The ID or version of this release; for example, a version number, build number from your CI environment, GitHub SHA, GUID, or a hash of the contents.
82
+ */
83
+ addRelease(name, id) {
84
+ (0, _console.warn)('Call to agent api addRelease failed. The agent is not currently initialized.');
85
+ }
86
+ }
87
+ exports.AgentBase = AgentBase;
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Agent = void 0;
7
+ var _agentBase = require("./agent-base");
7
8
  var _enabledFeatures = require("./features/enabled-features");
8
9
  var _configure = require("./configure/configure");
9
10
  var _featureDependencies = require("./features/featureDependencies");
@@ -22,13 +23,18 @@ var _runtime = require("../common/constants/runtime");
22
23
 
23
24
  // common files
24
25
 
26
+ /**
27
+ * @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
28
+ */
29
+
25
30
  /**
26
31
  * A flexible class that may be used to compose an agent from a select subset of feature modules. In applications
27
32
  * sensitive to network load, this may result in smaller builds with slightly lower performance impact.
28
33
  */
29
- class Agent {
34
+ class Agent extends _agentBase.AgentBase {
30
35
  constructor(options) {
31
36
  let agentIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _uniqueId.generateRandomHexString)(16);
37
+ super();
32
38
  if (!_runtime.globalScope) {
33
39
  // We could not determine the runtime environment. Short-circuite the agent here
34
40
  // to avoid possible exceptions later that may cause issues with customer's application.
@@ -89,5 +95,39 @@ class Agent {
89
95
  return false;
90
96
  }
91
97
  }
98
+
99
+ /* Below API methods are only available on a standard agent and not the micro agent */
100
+
101
+ /**
102
+ * Adds a JavaScript object with a custom name, start time, etc. to an in-progress session trace.
103
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addtotrace/}
104
+ * @param {{name: string, start: number, end?: number, origin?: string, type?: string}} customAttributes Supply a JavaScript object with these required and optional name/value pairs:
105
+ *
106
+ * - Required name/value pairs: name, start
107
+ * - Optional name/value pairs: end, origin, type
108
+ *
109
+ * If you are sending the same event object to New Relic as a PageAction, omit the TYPE attribute. (type is a string to describe what type of event you are marking inside of a session trace.) If included, it will override the event type and cause the PageAction event to be sent incorrectly. Instead, use the name attribute for event information.
110
+ */
111
+ addToTrace(customAttributes) {
112
+ (0, _console.warn)('Call to agent api addToTrace failed. The page action feature is not currently initialized.');
113
+ }
114
+
115
+ /**
116
+ * Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.
117
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcurrentroutename/}
118
+ * @param {string} name Current route name for the page.
119
+ */
120
+ setCurrentRouteName(name) {
121
+ (0, _console.warn)('Call to agent api setCurrentRouteName failed. The spa feature is not currently initialized.');
122
+ }
123
+
124
+ /**
125
+ * Returns a new API object that is bound to the current SPA interaction.
126
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction/}
127
+ * @returns {InteractionInstance} An API object that is bound to a specific BrowserInteraction event. Each time this method is called for the same BrowserInteraction, a new object is created, but it still references the same interaction.
128
+ */
129
+ interaction() {
130
+ (0, _console.warn)('Call to agent api interaction failed. The spa feature is not currently initialized.');
131
+ }
92
132
  }
93
133
  exports.Agent = Agent;
@@ -131,7 +131,7 @@ function setAPI(agentIdentifier, forceDrain) {
131
131
  try {
132
132
  return cb.apply(this, arguments);
133
133
  } catch (err) {
134
- tracerEE.emit('fn-err', [arguments, this, typeof err == 'string' ? new Error(err) : err], contextStore);
134
+ tracerEE.emit('fn-err', [arguments, this, err], contextStore);
135
135
  // the error came from outside the agent, so don't swallow
136
136
  throw err;
137
137
  } finally {
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.unused = void 0;
7
+ /**
8
+ * @typedef InteractionInstance
9
+ * @property {actionText} actionText
10
+ * @property {createTracer} createTracer
11
+ * @property {end} end
12
+ * @property {getContext} getContext
13
+ * @property {ignore} ignore
14
+ * @property {onEnd} onEnd
15
+ * @property {onEnd} save
16
+ * @property {setAttribute} setAttribute
17
+ * @property {setName} setName
18
+ */
19
+
20
+ /**
21
+ * Sets the text value of the HTML element that was clicked to start a browser interaction.
22
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/actiontext/}
23
+ * @callback actionText
24
+ * @param {string} value The text value of the HTML element that represents the action that started the interaction.
25
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
26
+ */
27
+
28
+ /**
29
+ * Times sub-components of a SPA interaction separately, including wait time and JS execution time.
30
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/createtracer/}
31
+ * @callback createTracer
32
+ * @param {string} name This will be used as the name of the tracer.
33
+ * @param {string} [callback] A callback that contains the synchronous work to run at the end of the async work. To execute this callback, call the wrapper function returned using createTracer().
34
+ * @returns {Function} Returns a method that wraps the original callback. When this method is invoked, it calls the original callback and ends the async timing.
35
+ */
36
+
37
+ /**
38
+ * Ends the SPA interaction at the current time.
39
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/end/}
40
+ * @callback end
41
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
42
+ */
43
+
44
+ /**
45
+ * Stores values for the current SPA interaction asynchronously in browser.
46
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/getcontext/}
47
+ * @callback getContext
48
+ * @param {(ctx: object) => void} callback This function is called when the interaction ends. It is called with one parameter, which is the interaction context.
49
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
50
+ */
51
+
52
+ /**
53
+ * Change the values associated with a SPA interaction before the interaction is saved.
54
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/onend/}
55
+ * @callback onEnd
56
+ * @param {(ctx: object) => void} callback This function is called when the interaction ends. It is called with one parameter, which is the interaction context.
57
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
58
+ */
59
+
60
+ /**
61
+ * Ensures a SPA browser interaction will be saved when it ends.
62
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/save/}
63
+ * @callback save
64
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
65
+ */
66
+
67
+ /**
68
+ * Adds a custom SPA attribute only to the current interaction in browser.
69
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setattribute/}
70
+ * @callback setAttribute
71
+ * @param {string} key Used as the attribute name on the BrowserInteraction event.
72
+ * @param {any} key Used as the attribute value on the BrowserInteraction event. This can be a string, number, boolean, or object. If it is an object, New Relic serializes it to a JSON string.
73
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
74
+ */
75
+
76
+ /**
77
+ * Sets the name and trigger of a SPA's browser interaction that is not a route change or URL change.
78
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setname/}
79
+ * @callback setName
80
+ * @param {string} name If null, the name will be set using the targetGroupedUrl attribute. If not null, this will set the browserInteractionName attribute in the BrowserInteraction event.
81
+ * @param {string} [trigger] If not null, this will set the TRIGGER attribute on the BrowserInteraction event.
82
+ * @returns {InteractionInstance} Returns the same interaction object allowing method chaining.
83
+ */
84
+
85
+ /* istanbul ignore next */
86
+ const unused = {};
87
+ exports.unused = unused;
@@ -30,13 +30,14 @@ function configure(agentIdentifier) {
30
30
  }
31
31
  (0, _config.setConfiguration)(agentIdentifier, init || {});
32
32
  (0, _config.setLoaderConfig)(agentIdentifier, loader_config || {});
33
- (0, _config.setRuntime)(agentIdentifier, runtime);
34
33
  info.jsAttributes ??= {};
35
34
  if (_runtime.isWorkerScope) {
36
35
  // add a default attr to all worker payloads
37
36
  info.jsAttributes.isWorker = true;
38
37
  }
39
38
  (0, _config.setInfo)(agentIdentifier, info);
39
+ runtime.denyList = init.ajax?.block_internal ? (init.ajax.deny_list || []).concat(info.beacon, info.errorBeacon) : init.ajax?.deny_list;
40
+ (0, _config.setRuntime)(agentIdentifier, runtime);
40
41
  (0, _api.setTopLevelCallers)();
41
42
  const api = (0, _api.setAPI)(agentIdentifier, forceDrain);
42
43
  (0, _nreum.gosNREUMInitializedAgents)(agentIdentifier, api, 'api');
@@ -14,6 +14,7 @@ var _config = require("../common/config/config");
14
14
  var _features = require("./features/features");
15
15
  var _console = require("../common/util/console");
16
16
  var _load = require("../common/window/load");
17
+ var _agentBase = require("./agent-base");
17
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } // loader files
19
20
  // core files
@@ -24,13 +25,14 @@ const nonAutoFeatures = [_features.FEATURE_NAMES.jserrors, _features.FEATURE_NAM
24
25
  * automatically instrument. Instead, each MicroAgent instance will lazy load the required features and can support loading multiple instances on one page.
25
26
  * Out of the box, it can manually handle and report Page View, Page Action, and Error events.
26
27
  */
27
- class MicroAgent {
28
+ class MicroAgent extends _agentBase.AgentBase {
28
29
  /**
29
30
  * @param {Object} options - Specifies features and runtime configuration,
30
31
  * @param {string=} agentIdentifier - The optional unique ID of the agent.
31
32
  */
32
33
  constructor(options) {
33
34
  let agentIdentifier = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _uniqueId.generateRandomHexString)(16);
35
+ super();
34
36
  this.agentIdentifier = agentIdentifier;
35
37
  this.sharedAggregator = new _aggregator.Aggregator({
36
38
  agentIdentifier: this.agentIdentifier
@@ -17,6 +17,7 @@ const model = () => {
17
17
  // *cli - per discussion, default should be true
18
18
  ajax: {
19
19
  deny_list: undefined,
20
+ block_internal: true,
20
21
  enabled: true,
21
22
  harvestTimeSeconds: 10
22
23
  },
@@ -23,7 +23,8 @@ const model = {
23
23
  releaseIds: {},
24
24
  session: undefined,
25
25
  xhrWrappable: typeof globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
26
- version: VERSION
26
+ version: VERSION,
27
+ denyList: undefined
27
28
  };
28
29
  const _cache = {};
29
30
  export function getRuntime(id) {