@newrelic/browser-agent 1.318.0-rc.8 → 1.318.0-rc.9

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.
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.318.0-rc.8";
20
+ const VERSION = exports.VERSION = "1.318.0-rc.9";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.318.0-rc.8";
20
+ const VERSION = exports.VERSION = "1.318.0-rc.9";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -107,7 +107,7 @@ function shouldDuplicate(target, aggregateInstance) {
107
107
  * @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
108
108
  */
109
109
  function findTargetsFromStackTrace(agentRef) {
110
- if (!agentRef?.init.api.register.enabled) return [undefined];
110
+ if (!agentRef?.init.api.register.enabled || !agentRef?.runtime?.registeredEntities?.length) return [undefined];
111
111
  const targets = [];
112
112
  try {
113
113
  var urls = (0, _scriptTracker.extractUrlsFromStack)((0, _scriptTracker.getDeepStackTrace)());
@@ -8,6 +8,7 @@ var _runtime = require("../constants/runtime");
8
8
  var _uniqueId = require("../ids/unique-id");
9
9
  var _now = require("../timing/now");
10
10
  var _cleanUrl = require("../url/clean-url");
11
+ var _utils = require("../v2/utils");
11
12
  var _nreum = require("../window/nreum");
12
13
  var _pageVisibility = require("../window/page-visibility");
13
14
  var _events = require("../constants/events");
@@ -19,7 +20,7 @@ var _events = require("../constants/events");
19
20
  const wrapped = {};
20
21
  const openWebSockets = new Set(); // track all instances to close out metrics on page unload
21
22
 
22
- function wrapWebSocket(sharedEE) {
23
+ function wrapWebSocket(sharedEE, agentRef) {
23
24
  const originals = (0, _nreum.gosNREUMOriginals)().o;
24
25
  if (!originals.WS) return sharedEE;
25
26
  const wsEE = sharedEE.get('websockets');
@@ -37,7 +38,7 @@ function wrapWebSocket(sharedEE) {
37
38
  if (ws.nrData.openedAt) {
38
39
  ws.nrData.connectedDuration = unloadTime - ws.nrData.openedAt;
39
40
  }
40
- wsEE.emit('ws', [ws.nrData], ws);
41
+ wsEE.emit('ws', [ws.nrData, ws.targets], ws);
41
42
  });
42
43
  });
43
44
  class WrappedWebSocket extends WebSocket {
@@ -65,6 +66,7 @@ function wrapWebSocket(sharedEE) {
65
66
  super(...args);
66
67
  /** @type {WebSocketData} */
67
68
  this.nrData = new WebSocketData(args[0], args[1]);
69
+ this.targets = (0, _utils.findTargetsFromStackTrace)(agentRef);
68
70
  this.addEventListener('open', () => {
69
71
  this.nrData.openedAt = (0, _now.now)();
70
72
  ['protocol', 'extensions', 'binaryType'].forEach(prop => {
@@ -93,7 +95,7 @@ function wrapWebSocket(sharedEE) {
93
95
  this.nrData.closeWasClean = event.wasClean;
94
96
  this.nrData.connectedDuration = this.nrData.closedAt - this.nrData.openedAt;
95
97
  openWebSockets.delete(this); // remove from tracking set since it's now closed
96
- wsEE.emit('ws', [this.nrData], this);
98
+ wsEE.emit('ws', [this.nrData, this.targets], this);
97
99
  });
98
100
  }
99
101
  addEventListener(type, listener, ...rest) {
@@ -262,19 +262,21 @@ class Aggregate extends _aggregateBase.AggregateBase {
262
262
  this.addEvent(event, target);
263
263
  }, this.featureName, this.ee);
264
264
  if (agentRef.init.feature_flags.includes('websockets') || agentRef.init.web_sockets?.enabled) {
265
- (0, _registerHandler.registerHandler)('ws-complete', nrData => {
266
- const event = {
267
- ...nrData,
268
- eventType: _events.EVENT_TYPES.WS,
269
- timestamp: this.#toEpoch(nrData.timestamp),
270
- openedAt: this.#toEpoch(nrData.openedAt),
271
- closedAt: this.#toEpoch(nrData.closedAt)
272
- };
265
+ (0, _registerHandler.registerHandler)('ws-complete', (nrData, targets = [undefined]) => {
266
+ targets.forEach(target => {
267
+ const event = {
268
+ ...nrData,
269
+ eventType: _events.EVENT_TYPES.WS,
270
+ timestamp: this.#toEpoch(nrData.timestamp),
271
+ openedAt: this.#toEpoch(nrData.openedAt),
272
+ closedAt: this.#toEpoch(nrData.closedAt)
273
+ };
273
274
 
274
- // Report supportability metrics for WebSocket completion
275
- this.reportSupportabilityMetric('WebSocket/Completed/Seen');
276
- this.reportSupportabilityMetric('WebSocket/Completed/Bytes', (0, _stringify.stringify)(event).length);
277
- this.addEvent(event);
275
+ // Report supportability metrics for WebSocket completion
276
+ this.reportSupportabilityMetric('WebSocket/Completed/Seen');
277
+ this.reportSupportabilityMetric('WebSocket/Completed/Bytes', (0, _stringify.stringify)(event).length);
278
+ this.addEvent(event, target);
279
+ });
278
280
  }, this.featureName, this.ee);
279
281
  }
280
282
  if (!agentRef.init.feature_flags.includes('no_spv')) {
@@ -50,9 +50,9 @@ class Instrument extends _instrumentBase.InstrumentBase {
50
50
  let historyEE;
51
51
  if (websocketsEnabled) {
52
52
  // this can apply outside browser scope such as in worker
53
- const websocketsEE = (0, _wrapWebsocket.wrapWebSocket)(this.ee);
54
- websocketsEE.on('ws', nrData => {
55
- (0, _handle.handle)('ws-complete', [nrData], undefined, this.featureName, this.ee);
53
+ const websocketsEE = (0, _wrapWebsocket.wrapWebSocket)(this.ee, agentRef);
54
+ websocketsEE.on('ws', (nrData, targets) => {
55
+ (0, _handle.handle)('ws-complete', [nrData, targets], undefined, this.featureName, this.ee);
56
56
  });
57
57
  }
58
58
  if (securityPolicyViolationEnabled) {
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.318.0-rc.8";
14
+ export const VERSION = "1.318.0-rc.9";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.318.0-rc.8";
14
+ export const VERSION = "1.318.0-rc.9";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -96,7 +96,7 @@ export function shouldDuplicate(target, aggregateInstance) {
96
96
  * @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
97
97
  */
98
98
  export function findTargetsFromStackTrace(agentRef) {
99
- if (!agentRef?.init.api.register.enabled) return [undefined];
99
+ if (!agentRef?.init.api.register.enabled || !agentRef?.runtime?.registeredEntities?.length) return [undefined];
100
100
  const targets = [];
101
101
  try {
102
102
  var urls = extractUrlsFromStack(getDeepStackTrace());
@@ -6,13 +6,14 @@ import { globalScope } from '../constants/runtime';
6
6
  import { generateRandomHexString } from '../ids/unique-id';
7
7
  import { now } from '../timing/now';
8
8
  import { cleanURL } from '../url/clean-url';
9
+ import { findTargetsFromStackTrace } from '../v2/utils';
9
10
  import { gosNREUMOriginals } from '../window/nreum';
10
11
  import { subscribeToPageUnload } from '../window/page-visibility';
11
12
  import { EVENT_TYPES } from '../constants/events';
12
13
  const wrapped = {};
13
14
  const openWebSockets = new Set(); // track all instances to close out metrics on page unload
14
15
 
15
- export function wrapWebSocket(sharedEE) {
16
+ export function wrapWebSocket(sharedEE, agentRef) {
16
17
  const originals = gosNREUMOriginals().o;
17
18
  if (!originals.WS) return sharedEE;
18
19
  const wsEE = sharedEE.get('websockets');
@@ -30,7 +31,7 @@ export function wrapWebSocket(sharedEE) {
30
31
  if (ws.nrData.openedAt) {
31
32
  ws.nrData.connectedDuration = unloadTime - ws.nrData.openedAt;
32
33
  }
33
- wsEE.emit('ws', [ws.nrData], ws);
34
+ wsEE.emit('ws', [ws.nrData, ws.targets], ws);
34
35
  });
35
36
  });
36
37
  class WrappedWebSocket extends WebSocket {
@@ -58,6 +59,7 @@ export function wrapWebSocket(sharedEE) {
58
59
  super(...args);
59
60
  /** @type {WebSocketData} */
60
61
  this.nrData = new WebSocketData(args[0], args[1]);
62
+ this.targets = findTargetsFromStackTrace(agentRef);
61
63
  this.addEventListener('open', () => {
62
64
  this.nrData.openedAt = now();
63
65
  ['protocol', 'extensions', 'binaryType'].forEach(prop => {
@@ -86,7 +88,7 @@ export function wrapWebSocket(sharedEE) {
86
88
  this.nrData.closeWasClean = event.wasClean;
87
89
  this.nrData.connectedDuration = this.nrData.closedAt - this.nrData.openedAt;
88
90
  openWebSockets.delete(this); // remove from tracking set since it's now closed
89
- wsEE.emit('ws', [this.nrData], this);
91
+ wsEE.emit('ws', [this.nrData, this.targets], this);
90
92
  });
91
93
  }
92
94
  addEventListener(type, listener, ...rest) {
@@ -255,19 +255,21 @@ export class Aggregate extends AggregateBase {
255
255
  this.addEvent(event, target);
256
256
  }, this.featureName, this.ee);
257
257
  if (agentRef.init.feature_flags.includes('websockets') || agentRef.init.web_sockets?.enabled) {
258
- registerHandler('ws-complete', nrData => {
259
- const event = {
260
- ...nrData,
261
- eventType: EVENT_TYPES.WS,
262
- timestamp: this.#toEpoch(nrData.timestamp),
263
- openedAt: this.#toEpoch(nrData.openedAt),
264
- closedAt: this.#toEpoch(nrData.closedAt)
265
- };
258
+ registerHandler('ws-complete', (nrData, targets = [undefined]) => {
259
+ targets.forEach(target => {
260
+ const event = {
261
+ ...nrData,
262
+ eventType: EVENT_TYPES.WS,
263
+ timestamp: this.#toEpoch(nrData.timestamp),
264
+ openedAt: this.#toEpoch(nrData.openedAt),
265
+ closedAt: this.#toEpoch(nrData.closedAt)
266
+ };
266
267
 
267
- // Report supportability metrics for WebSocket completion
268
- this.reportSupportabilityMetric('WebSocket/Completed/Seen');
269
- this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length);
270
- this.addEvent(event);
268
+ // Report supportability metrics for WebSocket completion
269
+ this.reportSupportabilityMetric('WebSocket/Completed/Seen');
270
+ this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length);
271
+ this.addEvent(event, target);
272
+ });
271
273
  }, this.featureName, this.ee);
272
274
  }
273
275
  if (!agentRef.init.feature_flags.includes('no_spv')) {
@@ -45,9 +45,9 @@ export class Instrument extends InstrumentBase {
45
45
  let historyEE;
46
46
  if (websocketsEnabled) {
47
47
  // this can apply outside browser scope such as in worker
48
- const websocketsEE = wrapWebSocket(this.ee);
49
- websocketsEE.on('ws', nrData => {
50
- handle('ws-complete', [nrData], undefined, this.featureName, this.ee);
48
+ const websocketsEE = wrapWebSocket(this.ee, agentRef);
49
+ websocketsEE.on('ws', (nrData, targets) => {
50
+ handle('ws-complete', [nrData, targets], undefined, this.featureName, this.ee);
51
51
  });
52
52
  }
53
53
  if (securityPolicyViolationEnabled) {
@@ -1,2 +1,2 @@
1
- export function wrapWebSocket(sharedEE: any): any;
1
+ export function wrapWebSocket(sharedEE: any, agentRef: any): any;
2
2
  //# sourceMappingURL=wrap-websocket.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wrap-websocket.d.ts","sourceRoot":"","sources":["../../../../src/common/wrap/wrap-websocket.js"],"names":[],"mappings":"AAeA,kDA2IC"}
1
+ {"version":3,"file":"wrap-websocket.d.ts","sourceRoot":"","sources":["../../../../src/common/wrap/wrap-websocket.js"],"names":[],"mappings":"AAgBA,iEA4IC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/generic_events/aggregate/index.js"],"names":[],"mappings":"AAmBA;IACE,2BAAiC;IAGjC,2BA6QC;IA3QC,gCAAkG;IAIlG,uBAA0C;IA0Q5C;;;;;;;;;;;;OAYG;IACH,eAJW,MAAM,YAAC,WACP,MAAM,YAAC,QAkCjB;IAED,6CAEC;IAED;;;MAEC;;CAsBF;8BAzW6B,4BAA4B;2BAI/B,gCAAgC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/generic_events/aggregate/index.js"],"names":[],"mappings":"AAmBA;IACE,2BAAiC;IAGjC,2BA+QC;IA7QC,gCAAkG;IAIlG,uBAA0C;IA4Q5C;;;;;;;;;;;;OAYG;IACH,eAJW,MAAM,YAAC,WACP,MAAM,YAAC,QAkCjB;IAED,6CAEC;IAED;;;MAEC;;CAsBF;8BA3W6B,4BAA4B;2BAI/B,gCAAgC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.318.0-rc.8",
3
+ "version": "1.318.0-rc.9",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -92,7 +92,7 @@ export function shouldDuplicate (target, aggregateInstance) {
92
92
  * @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
93
93
  */
94
94
  export function findTargetsFromStackTrace (agentRef) {
95
- if (!agentRef?.init.api.register.enabled) return [undefined]
95
+ if (!agentRef?.init.api.register.enabled || !agentRef?.runtime?.registeredEntities?.length) return [undefined]
96
96
 
97
97
  const targets = []
98
98
  try {
@@ -6,6 +6,7 @@ import { globalScope } from '../constants/runtime'
6
6
  import { generateRandomHexString } from '../ids/unique-id'
7
7
  import { now } from '../timing/now'
8
8
  import { cleanURL } from '../url/clean-url'
9
+ import { findTargetsFromStackTrace } from '../v2/utils'
9
10
  import { gosNREUMOriginals } from '../window/nreum'
10
11
  import { subscribeToPageUnload } from '../window/page-visibility'
11
12
  import { EVENT_TYPES } from '../constants/events'
@@ -13,7 +14,7 @@ import { EVENT_TYPES } from '../constants/events'
13
14
  const wrapped = {}
14
15
  const openWebSockets = new Set() // track all instances to close out metrics on page unload
15
16
 
16
- export function wrapWebSocket (sharedEE) {
17
+ export function wrapWebSocket (sharedEE, agentRef) {
17
18
  const originals = gosNREUMOriginals().o
18
19
  if (!originals.WS) return sharedEE
19
20
 
@@ -33,7 +34,7 @@ export function wrapWebSocket (sharedEE) {
33
34
  ws.nrData.connectedDuration = unloadTime - ws.nrData.openedAt
34
35
  }
35
36
 
36
- wsEE.emit('ws', [ws.nrData], ws)
37
+ wsEE.emit('ws', [ws.nrData, ws.targets], ws)
37
38
  })
38
39
  })
39
40
 
@@ -61,6 +62,7 @@ export function wrapWebSocket (sharedEE) {
61
62
  super(...args)
62
63
  /** @type {WebSocketData} */
63
64
  this.nrData = new WebSocketData(args[0], args[1])
65
+ this.targets = findTargetsFromStackTrace(agentRef)
64
66
 
65
67
  this.addEventListener('open', () => {
66
68
  this.nrData.openedAt = now()
@@ -90,7 +92,7 @@ export function wrapWebSocket (sharedEE) {
90
92
  this.nrData.connectedDuration = this.nrData.closedAt - this.nrData.openedAt
91
93
 
92
94
  openWebSockets.delete(this) // remove from tracking set since it's now closed
93
- wsEE.emit('ws', [this.nrData], this)
95
+ wsEE.emit('ws', [this.nrData, this.targets], this)
94
96
  })
95
97
  }
96
98
 
@@ -252,20 +252,22 @@ export class Aggregate extends AggregateBase {
252
252
  }, this.featureName, this.ee)
253
253
 
254
254
  if (agentRef.init.feature_flags.includes('websockets') || agentRef.init.web_sockets?.enabled) {
255
- registerHandler('ws-complete', (nrData) => {
256
- const event = {
257
- ...nrData,
258
- eventType: EVENT_TYPES.WS,
259
- timestamp: this.#toEpoch(nrData.timestamp),
260
- openedAt: this.#toEpoch(nrData.openedAt),
261
- closedAt: this.#toEpoch(nrData.closedAt)
262
- }
255
+ registerHandler('ws-complete', (nrData, targets = [undefined]) => {
256
+ targets.forEach(target => {
257
+ const event = {
258
+ ...nrData,
259
+ eventType: EVENT_TYPES.WS,
260
+ timestamp: this.#toEpoch(nrData.timestamp),
261
+ openedAt: this.#toEpoch(nrData.openedAt),
262
+ closedAt: this.#toEpoch(nrData.closedAt)
263
+ }
263
264
 
264
- // Report supportability metrics for WebSocket completion
265
- this.reportSupportabilityMetric('WebSocket/Completed/Seen')
266
- this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length)
265
+ // Report supportability metrics for WebSocket completion
266
+ this.reportSupportabilityMetric('WebSocket/Completed/Seen')
267
+ this.reportSupportabilityMetric('WebSocket/Completed/Bytes', stringify(event).length)
267
268
 
268
- this.addEvent(event)
269
+ this.addEvent(event, target)
270
+ })
269
271
  }, this.featureName, this.ee)
270
272
  }
271
273
  if (!agentRef.init.feature_flags.includes('no_spv')) {
@@ -55,9 +55,9 @@ export class Instrument extends InstrumentBase {
55
55
 
56
56
  let historyEE
57
57
  if (websocketsEnabled) { // this can apply outside browser scope such as in worker
58
- const websocketsEE = wrapWebSocket(this.ee)
59
- websocketsEE.on('ws', (nrData) => {
60
- handle('ws-complete', [nrData], undefined, this.featureName, this.ee)
58
+ const websocketsEE = wrapWebSocket(this.ee, agentRef)
59
+ websocketsEE.on('ws', (nrData, targets) => {
60
+ handle('ws-complete', [nrData, targets], undefined, this.featureName, this.ee)
61
61
  })
62
62
  }
63
63
  if (securityPolicyViolationEnabled) {