@newrelic/browser-agent 1.320.1-rc.1 → 1.320.1-rc.2

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 (74) hide show
  1. package/dist/cjs/common/config/runtime.js +2 -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/dom/selector-path.js +1 -1
  5. package/dist/cjs/common/session/session-entity.js +1 -1
  6. package/dist/cjs/common/v2/constants.js +21 -0
  7. package/dist/cjs/common/v2/utils.js +25 -23
  8. package/dist/cjs/common/wrap/wrap-events.js +4 -3
  9. package/dist/cjs/common/wrap/wrap-fetch.js +2 -2
  10. package/dist/cjs/common/wrap/wrap-function.js +1 -1
  11. package/dist/cjs/common/wrap/wrap-history.js +3 -2
  12. package/dist/cjs/common/wrap/wrap-xhr.js +2 -2
  13. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  14. package/dist/cjs/features/generic_events/aggregate/index.js +1 -1
  15. package/dist/cjs/features/generic_events/instrument/index.js +1 -1
  16. package/dist/cjs/features/jserrors/aggregate/index.js +5 -5
  17. package/dist/cjs/features/logging/instrument/index.js +1 -1
  18. package/dist/cjs/features/session_trace/instrument/index.js +3 -3
  19. package/dist/cjs/features/soft_navigations/instrument/index.js +2 -2
  20. package/dist/cjs/loaders/api/register.js +8 -8
  21. package/dist/cjs/loaders/configure/configure.js +14 -0
  22. package/dist/esm/common/config/runtime.js +2 -0
  23. package/dist/esm/common/constants/env.cdn.js +1 -1
  24. package/dist/esm/common/constants/env.npm.js +1 -1
  25. package/dist/esm/common/dom/selector-path.js +1 -1
  26. package/dist/esm/common/session/session-entity.js +1 -1
  27. package/dist/esm/common/v2/constants.js +15 -0
  28. package/dist/esm/common/v2/utils.js +24 -22
  29. package/dist/esm/common/wrap/wrap-events.js +4 -3
  30. package/dist/esm/common/wrap/wrap-fetch.js +2 -2
  31. package/dist/esm/common/wrap/wrap-function.js +1 -1
  32. package/dist/esm/common/wrap/wrap-history.js +3 -2
  33. package/dist/esm/common/wrap/wrap-xhr.js +2 -2
  34. package/dist/esm/features/ajax/aggregate/index.js +2 -2
  35. package/dist/esm/features/generic_events/aggregate/index.js +1 -1
  36. package/dist/esm/features/generic_events/instrument/index.js +1 -1
  37. package/dist/esm/features/jserrors/aggregate/index.js +6 -6
  38. package/dist/esm/features/logging/instrument/index.js +1 -1
  39. package/dist/esm/features/session_trace/instrument/index.js +3 -3
  40. package/dist/esm/features/soft_navigations/instrument/index.js +2 -2
  41. package/dist/esm/loaders/api/register.js +1 -1
  42. package/dist/esm/loaders/configure/configure.js +14 -0
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/dist/types/common/config/runtime.d.ts.map +1 -1
  45. package/dist/types/common/v2/constants.d.ts +9 -0
  46. package/dist/types/common/v2/constants.d.ts.map +1 -0
  47. package/dist/types/common/v2/utils.d.ts +36 -11
  48. package/dist/types/common/v2/utils.d.ts.map +1 -1
  49. package/dist/types/common/wrap/wrap-events.d.ts +2 -1
  50. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
  51. package/dist/types/common/wrap/wrap-history.d.ts +2 -1
  52. package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
  53. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  54. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  55. package/package.json +1 -1
  56. package/src/common/config/runtime.js +2 -0
  57. package/src/common/dom/selector-path.js +1 -1
  58. package/src/common/session/session-entity.js +1 -1
  59. package/src/common/v2/constants.js +15 -0
  60. package/src/common/v2/utils.js +23 -21
  61. package/src/common/wrap/wrap-events.js +4 -3
  62. package/src/common/wrap/wrap-fetch.js +2 -2
  63. package/src/common/wrap/wrap-function.js +1 -1
  64. package/src/common/wrap/wrap-history.js +3 -2
  65. package/src/common/wrap/wrap-xhr.js +2 -2
  66. package/src/features/ajax/aggregate/index.js +2 -2
  67. package/src/features/generic_events/aggregate/index.js +1 -1
  68. package/src/features/generic_events/instrument/index.js +1 -1
  69. package/src/features/jserrors/aggregate/index.js +6 -6
  70. package/src/features/logging/instrument/index.js +1 -1
  71. package/src/features/session_trace/instrument/index.js +3 -3
  72. package/src/features/soft_navigations/instrument/index.js +2 -2
  73. package/src/loaders/api/register.js +1 -1
  74. package/src/loaders/configure/configure.js +12 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
@@ -24,16 +24,17 @@ const flag = `nr@wrapped:${contextId}`
24
24
  * `document` (if in a browser scope). Adds custom events in context of a new emitter scoped only to these methods.
25
25
  * @param {Object} sharedEE - The shared event emitter on which a new scoped
26
26
  * event emitter will be based.
27
+ * @param {*} [agentRef] - The agent reference, used to attribute wrapped calls to the correct v2 target.
27
28
  * @returns {Object} Scoped event emitter with a debug ID of `events`.
28
29
  */
29
- export function wrapEvents (sharedEE) {
30
+ export function wrapEvents (sharedEE, agentRef) {
30
31
  var ee = scopedEE(sharedEE)
31
32
 
32
33
  // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
33
34
  // then we increment the count to track # of feats using this at runtime.
34
35
  if (wrapped[ee.debugId]++) return ee
35
36
  wrapped[ee.debugId] = 1 // otherwise, first feature to wrap events
36
- var wrapFn = wfn(ee, true)
37
+ var wrapFn = wfn(ee, true, agentRef)
37
38
 
38
39
  // Guard against instrumenting environments w/o necessary features
39
40
  if ('getPrototypeOf' in Object) {
@@ -47,8 +47,8 @@ export function wrapFetch (sharedEE, agentRef) {
47
47
 
48
48
  ee.on(prefix + 'end', function (err, res, targets) {
49
49
  var ctx = this
50
- // undefined target reports to container
51
- ctx.targets = targets || [undefined]
50
+ // default target reports to container
51
+ ctx.targets = targets || [agentRef.runtime.v2Target]
52
52
  if (res) {
53
53
  var size = res.headers.get('content-length')
54
54
  if (size !== null) {
@@ -88,7 +88,7 @@ export function createWrapperWithEmitter (emitter, always, agentRef) {
88
88
 
89
89
  // certain wrappers can inform the function wrapper to evaluate the stack of the executed wrapped function to find targets of the execution
90
90
  // (e.g. wrap-logger can inform this method to find try to find the MFE source of a console.log)
91
- targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [undefined] // undefined target always maps to the container agent
91
+ targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [agentRef?.runtime?.v2Target] // default target always maps to the container agent
92
92
 
93
93
  if (typeof getContext === 'function') {
94
94
  ctx = getContext(args, originalThis)
@@ -18,9 +18,10 @@ const HISTORY_FNS = ['pushState', 'replaceState']
18
18
  * Wraps the `pushState` and `replaceState` methods of `window.history` and returns a corresponding event emitter
19
19
  * scoped to the history object.
20
20
  * @param {Object} sharedEE - The shared event emitter on which a new scoped event emitter will be based.
21
+ * @param {*} [agentRef] - The agent reference, used to attribute wrapped calls to the correct v2 target.
21
22
  * @returns {Object} Scoped event emitter with a debug ID of `history`.
22
23
  */
23
- export function wrapHistory (sharedEE) {
24
+ export function wrapHistory (sharedEE, agentRef) {
24
25
  const ee = scopedEE(sharedEE)
25
26
 
26
27
  // Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
@@ -29,7 +30,7 @@ export function wrapHistory (sharedEE) {
29
30
  if (!isBrowserScope || wrapped[ee.debugId]++) return ee
30
31
  wrapped[ee.debugId] = 1 // otherwise, first feature to wrap history
31
32
 
32
- var wrapFn = wfn(ee)
33
+ var wrapFn = wfn(ee, undefined, agentRef)
33
34
  /*
34
35
  * For objects that will be instantiated more than once, we wrap the object's prototype methods. The history object
35
36
  * is instantiated only once, so we can wrap its methods directly--and we must wrap the history methods directly as
@@ -37,8 +37,8 @@ export function wrapXhr (sharedEE, agentRef) {
37
37
  if (wrapped[ee.debugId]++) return ee
38
38
  wrapped[ee.debugId] = 1 // otherwise, first feature to wrap XHR
39
39
 
40
- wrapEvents(baseEE) // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
41
- var wrapFn = wfn(ee)
40
+ wrapEvents(baseEE, agentRef) // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
41
+ var wrapFn = wfn(ee, undefined, agentRef)
42
42
 
43
43
  var OrigXHR = globalScope.XMLHttpRequest
44
44
  var MutationObserver = globalScope.MutationObserver
@@ -14,7 +14,7 @@ import { gosNREUMOriginals } from '../../../common/window/nreum'
14
14
  import { hasGQLErrors, parseGQL } from './gql'
15
15
  import { canCapturePayload, isLikelyHumanReadable, parseQueryString, createStringAdders } from '../../../common/payloads/payloads'
16
16
  import { Obfuscator } from '../../../common/util/obfuscate'
17
- import { getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate } from '../../../common/v2/utils'
17
+ import { getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate, isMfeTarget } from '../../../common/v2/utils'
18
18
  import { EVENT_TYPES } from '../../../common/constants/events'
19
19
  import { generateUuid } from '../../../common/ids/unique-id'
20
20
 
@@ -137,7 +137,7 @@ export class Aggregate extends AggregateBase {
137
137
  if (event.gql) this.reportSupportabilityMetric('Ajax/Events/GraphQL/Bytes-Added', stringify(event.gql).length)
138
138
 
139
139
  /** make a copy of the event for the MFE target if it exists */
140
- if (target) {
140
+ if (isMfeTarget(target)) {
141
141
  this.events.add({ ...event, targetAttributes: getVersion2Attributes(target, this) })
142
142
  if (shouldDuplicate(target, this)) this.reportContainerEvent({ ...event, targetAttributes: getVersion2DuplicationAttributes(target, this) }, ctx)
143
143
  } else {
@@ -252,7 +252,7 @@ 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, targets = [undefined]) => {
255
+ registerHandler('ws-complete', (nrData, targets = [agentRef.runtime.v2Target]) => {
256
256
  targets.forEach(target => {
257
257
  const event = {
258
258
  ...nrData,
@@ -68,7 +68,7 @@ export class Instrument extends InstrumentBase {
68
68
  if (isBrowserScope) {
69
69
  wrapFetch(this.ee, agentRef)
70
70
  wrapXhr(this.ee, agentRef)
71
- historyEE = wrapHistory(this.ee)
71
+ historyEE = wrapHistory(this.ee, agentRef)
72
72
 
73
73
  if (agentRef.init.user_actions.enabled) {
74
74
  OBSERVED_EVENTS.forEach(eventType =>
@@ -19,7 +19,7 @@ import { AggregateBase } from '../../utils/aggregate-base'
19
19
  import { now } from '../../../common/timing/now'
20
20
  import { Obfuscator } from '../../../common/util/obfuscate'
21
21
  import { evaluateInternalError } from './internal-errors'
22
- import { getRegisteredTargetsFromFilename, getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate } from '../../../common/v2/utils'
22
+ import { getRegisteredTargetsFromFilename, getVersion2Attributes, getVersion2DuplicationAttributes, shouldDuplicate, isMfeTarget } from '../../../common/v2/utils'
23
23
  import { buildCauseString } from './cause-string'
24
24
  import { ShortCircuit } from '../../../common/util/short-circuit'
25
25
  import { EVENT_TYPES } from '../../../common/constants/events'
@@ -209,7 +209,7 @@ export class Aggregate extends AggregateBase {
209
209
  if (targets.length) break
210
210
  }
211
211
  }
212
- if (!targets.length) targets.push(undefined)
212
+ if (!targets.length) targets.push(this.agentRef.runtime.v2Target)
213
213
  }
214
214
  return targets
215
215
  }
@@ -253,7 +253,7 @@ export class Aggregate extends AggregateBase {
253
253
  if (filterOutput?.group) params.errorGroup = filterOutput.group
254
254
 
255
255
  // Should only decorate "hasReplay" for the container agent, so check if the target matches the config
256
- if (hasReplay && !target) params.hasReplay = hasReplay
256
+ if (hasReplay && !isMfeTarget(target)) params.hasReplay = hasReplay
257
257
  /**
258
258
  * The bucketHash is different from the params.stackHash because the params.stackHash is based on the canonicalized
259
259
  * stack trace and is used downstream in NR1 to attempt to group the same errors across different browsers. However,
@@ -289,7 +289,7 @@ export class Aggregate extends AggregateBase {
289
289
 
290
290
  // Trace sends the error in its payload, and both trace & replay simply listens for any error to occur.
291
291
  const jsErrorEvent = [type, bucketHash, params, newMetrics, customAttributes]
292
- if (!target) handle('trace-jserror', jsErrorEvent, undefined, FEATURE_NAMES.sessionTrace, this.ee)
292
+ if (!isMfeTarget(target)) handle('trace-jserror', jsErrorEvent, undefined, FEATURE_NAMES.sessionTrace, this.ee)
293
293
  // still send EE events for other features such as above, but stop this one from aggregating internal data
294
294
  if (this.blocked) return
295
295
 
@@ -297,7 +297,7 @@ export class Aggregate extends AggregateBase {
297
297
  customAttributes.socketId = err.__newrelic.socketId
298
298
  }
299
299
 
300
- if (!target) {
300
+ if (!isMfeTarget(target)) {
301
301
  const softNavInUse = Boolean(this.agentRef.features?.[FEATURE_NAMES.softNav])
302
302
  if (softNavInUse) { // pass the error to soft nav for evaluation - it will return it via 'returnJserror' when interaction is resolved
303
303
  handle('jserror', [jsErrorEvent], undefined, FEATURE_NAMES.softNav, this.ee)
@@ -307,7 +307,7 @@ export class Aggregate extends AggregateBase {
307
307
  }
308
308
 
309
309
  // always add directly if scoped to a sub-entity, the other pathways above will be deterministic if the main agent should procede
310
- if (target) this.#storeJserrorForHarvest(jsErrorEvent, {}, target)
310
+ if (isMfeTarget(target)) this.#storeJserrorForHarvest(jsErrorEvent, {}, target)
311
311
  }
312
312
 
313
313
  /**
@@ -31,7 +31,7 @@ export class Instrument extends InstrumentBase {
31
31
  })
32
32
 
33
33
  /** emitted by wrap-logger function */
34
- this.ee.on('wrap-logger-end', function handleLog ([message], _, __, targets = []) {
34
+ this.ee.on('wrap-logger-end', function handleLog ([message], _, __, targets = [agentRef.runtime.v2Target]) {
35
35
  const { level, customAttributes, autoCaptured } = this
36
36
  targets.forEach(target => {
37
37
  bufferLog(instanceEE, message, customAttributes, level, autoCaptured, target)
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { handle } from '../../../common/event-emitter/handle'
@@ -33,8 +33,8 @@ export class Instrument extends InstrumentBase {
33
33
  }
34
34
 
35
35
  const thisInstrumentEE = this.ee
36
- wrapHistory(thisInstrumentEE)
37
- this.eventsEE = wrapEvents(thisInstrumentEE)
36
+ wrapHistory(thisInstrumentEE, agentRef)
37
+ this.eventsEE = wrapEvents(thisInstrumentEE, agentRef)
38
38
 
39
39
  this.eventsEE.on(FN_START, function (args, target) {
40
40
  this.bstStart = now()
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2020-2025 New Relic, Inc. All rights reserved.
2
+ * Copyright 2020-2026 New Relic, Inc. All rights reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { gosNREUMOriginals } from '../../../common/window/nreum'
@@ -30,7 +30,7 @@ export class Instrument extends InstrumentBase {
30
30
 
31
31
  if (!isBrowserScope || !gosNREUMOriginals().o.MO) return // soft navigations is not supported outside web env or browsers without the mutation observer API
32
32
 
33
- const historyEE = wrapHistory(this.ee)
33
+ const historyEE = wrapHistory(this.ee, agentRef)
34
34
  try {
35
35
  this.removeOnAbort = new AbortController()
36
36
  } catch (e) {}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { handle } from '../../common/event-emitter/handle'
6
6
  import { warn } from '../../common/util/console'
7
- import { V2_TYPES } from '../../common/v2/utils'
7
+ import { V2_TYPES } from '../../common/v2/constants'
8
8
  import { FEATURE_NAMES } from '../features/features'
9
9
  import { now } from '../../common/timing/now'
10
10
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
@@ -7,6 +7,7 @@ import { gosCDN } from '../../common/window/nreum'
7
7
  import { mergeInfo } from '../../common/config/info'
8
8
  import { mergeInit } from '../../common/config/init'
9
9
  import { mergeRuntime } from '../../common/config/runtime'
10
+ import { V2_TYPES } from '../../common/v2/constants'
10
11
  import { isWorkerScope, globalScope } from '../../common/constants/runtime'
11
12
  import { redefinePublicPath } from './public-path'
12
13
  import { ee } from '../../common/event-emitter/contextual-ee'
@@ -43,6 +44,17 @@ export function configure (agent, opts = {}, loaderType, forceDrain) {
43
44
  const updatedInit = agent.init
44
45
 
45
46
  agent.runtime ??= mergeRuntime(runtime)
47
+ agent.runtime.v2Target ??= {
48
+ type: V2_TYPES.BA,
49
+ instance: agent.agentIdentifier,
50
+ get id () { return agent.runtime.appMetadata?.agents?.[0]?.entityGuid },
51
+ get attributes () {
52
+ return {
53
+ 'entity.guid': this.id,
54
+ appId: agent.info.applicationID
55
+ }
56
+ }
57
+ }
46
58
 
47
59
  // Apply proxy settings whenever configure is called (supports late {init} setting)
48
60
  if (updatedInit.proxy.assets) {