@newrelic/browser-agent 1.316.0 → 1.317.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 (140) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/common/config/init-types.js +1 -0
  3. package/dist/cjs/common/config/init.js +6 -4
  4. package/dist/cjs/common/constants/env.cdn.js +2 -2
  5. package/dist/cjs/common/constants/env.npm.js +2 -2
  6. package/dist/cjs/common/constants/events.js +26 -0
  7. package/dist/cjs/common/harvest/harvester.js +12 -4
  8. package/dist/cjs/common/payloads/payloads.js +127 -0
  9. package/dist/cjs/common/serialize/bel-serializer.js +4 -3
  10. package/dist/cjs/common/util/data-size.js +2 -2
  11. package/dist/cjs/common/util/obfuscate.js +147 -3
  12. package/dist/cjs/common/wrap/wrap-websocket.js +2 -1
  13. package/dist/cjs/common/wrap/wrap-xhr.js +1 -1
  14. package/dist/cjs/features/ajax/aggregate/gql.js +40 -1
  15. package/dist/cjs/features/ajax/aggregate/index.js +51 -13
  16. package/dist/cjs/features/ajax/constants.js +6 -1
  17. package/dist/cjs/features/ajax/instrument/index.js +105 -17
  18. package/dist/cjs/features/generic_events/aggregate/index.js +15 -10
  19. package/dist/cjs/features/generic_events/constants.js +3 -2
  20. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.js +2 -2
  21. package/dist/cjs/features/jserrors/aggregate/index.js +12 -3
  22. package/dist/cjs/features/logging/aggregate/index.js +7 -3
  23. package/dist/cjs/features/metrics/aggregate/index.js +5 -1
  24. package/dist/cjs/features/page_view_event/aggregate/index.js +7 -3
  25. package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -1
  26. package/dist/cjs/features/session_replay/aggregate/index.js +7 -1
  27. package/dist/cjs/features/session_trace/aggregate/index.js +6 -2
  28. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +36 -5
  29. package/dist/cjs/features/soft_navigations/aggregate/index.js +7 -1
  30. package/dist/cjs/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  31. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +6 -4
  32. package/dist/cjs/features/utils/aggregate-base.js +2 -3
  33. package/dist/esm/common/config/init-types.js +1 -0
  34. package/dist/esm/common/config/init.js +3 -1
  35. package/dist/esm/common/constants/env.cdn.js +2 -2
  36. package/dist/esm/common/constants/env.npm.js +2 -2
  37. package/dist/esm/common/constants/events.js +20 -0
  38. package/dist/esm/common/harvest/harvester.js +12 -4
  39. package/dist/esm/common/payloads/payloads.js +118 -0
  40. package/dist/esm/common/serialize/bel-serializer.js +4 -3
  41. package/dist/esm/common/util/data-size.js +2 -2
  42. package/dist/esm/common/util/obfuscate.js +147 -3
  43. package/dist/esm/common/wrap/wrap-websocket.js +2 -1
  44. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  45. package/dist/esm/features/ajax/aggregate/gql.js +39 -1
  46. package/dist/esm/features/ajax/aggregate/index.js +52 -14
  47. package/dist/esm/features/ajax/constants.js +5 -0
  48. package/dist/esm/features/ajax/instrument/index.js +106 -18
  49. package/dist/esm/features/generic_events/aggregate/index.js +15 -10
  50. package/dist/esm/features/generic_events/constants.js +3 -2
  51. package/dist/esm/features/jserrors/aggregate/format-stack-trace.js +2 -2
  52. package/dist/esm/features/jserrors/aggregate/index.js +12 -3
  53. package/dist/esm/features/logging/aggregate/index.js +7 -3
  54. package/dist/esm/features/metrics/aggregate/index.js +5 -1
  55. package/dist/esm/features/page_view_event/aggregate/index.js +7 -3
  56. package/dist/esm/features/page_view_timing/aggregate/index.js +6 -1
  57. package/dist/esm/features/session_replay/aggregate/index.js +7 -1
  58. package/dist/esm/features/session_trace/aggregate/index.js +6 -2
  59. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +36 -5
  60. package/dist/esm/features/soft_navigations/aggregate/index.js +7 -1
  61. package/dist/esm/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  62. package/dist/esm/features/soft_navigations/aggregate/interaction.js +6 -4
  63. package/dist/esm/features/utils/aggregate-base.js +2 -3
  64. package/dist/tsconfig.tsbuildinfo +1 -1
  65. package/dist/types/common/config/init-types.d.ts +4 -0
  66. package/dist/types/common/config/init-types.d.ts.map +1 -1
  67. package/dist/types/common/config/init.d.ts.map +1 -1
  68. package/dist/types/common/constants/events.d.ts +16 -0
  69. package/dist/types/common/constants/events.d.ts.map +1 -0
  70. package/dist/types/common/harvest/harvester.d.ts +4 -1
  71. package/dist/types/common/harvest/harvester.d.ts.map +1 -1
  72. package/dist/types/common/payloads/payloads.d.ts +42 -0
  73. package/dist/types/common/payloads/payloads.d.ts.map +1 -0
  74. package/dist/types/common/serialize/bel-serializer.d.ts +1 -1
  75. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  76. package/dist/types/common/util/obfuscate.d.ts +23 -2
  77. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  78. package/dist/types/common/wrap/wrap-websocket.d.ts.map +1 -1
  79. package/dist/types/features/ajax/aggregate/gql.d.ts +8 -0
  80. package/dist/types/features/ajax/aggregate/gql.d.ts.map +1 -1
  81. package/dist/types/features/ajax/aggregate/index.d.ts +2 -0
  82. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  83. package/dist/types/features/ajax/constants.d.ts +5 -0
  84. package/dist/types/features/ajax/constants.d.ts.map +1 -1
  85. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  86. package/dist/types/features/generic_events/aggregate/index.d.ts +3 -1
  87. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  88. package/dist/types/features/generic_events/constants.d.ts.map +1 -1
  89. package/dist/types/features/jserrors/aggregate/index.d.ts +8 -1
  90. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  91. package/dist/types/features/logging/aggregate/index.d.ts +3 -1
  92. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  93. package/dist/types/features/metrics/aggregate/index.d.ts +2 -0
  94. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  95. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -0
  96. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  97. package/dist/types/features/page_view_timing/aggregate/index.d.ts +2 -0
  98. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  99. package/dist/types/features/session_replay/aggregate/index.d.ts +2 -0
  100. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  101. package/dist/types/features/session_trace/aggregate/index.d.ts +2 -0
  102. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  103. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts +6 -1
  104. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts.map +1 -1
  105. package/dist/types/features/soft_navigations/aggregate/index.d.ts +3 -0
  106. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  107. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts +3 -1
  108. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts.map +1 -1
  109. package/dist/types/features/utils/aggregate-base.d.ts +0 -1
  110. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  111. package/package.json +2 -2
  112. package/src/common/config/init-types.js +1 -0
  113. package/src/common/config/init.js +2 -1
  114. package/src/common/constants/events.js +20 -0
  115. package/src/common/harvest/harvester.js +11 -4
  116. package/src/common/payloads/payloads.js +135 -0
  117. package/src/common/serialize/bel-serializer.js +4 -3
  118. package/src/common/util/data-size.js +2 -2
  119. package/src/common/util/obfuscate.js +154 -3
  120. package/src/common/wrap/wrap-websocket.js +2 -1
  121. package/src/common/wrap/wrap-xhr.js +1 -1
  122. package/src/features/ajax/aggregate/gql.js +42 -1
  123. package/src/features/ajax/aggregate/index.js +43 -13
  124. package/src/features/ajax/constants.js +5 -1
  125. package/src/features/ajax/instrument/index.js +114 -18
  126. package/src/features/generic_events/aggregate/index.js +14 -9
  127. package/src/features/generic_events/constants.js +3 -2
  128. package/src/features/jserrors/aggregate/format-stack-trace.js +3 -3
  129. package/src/features/jserrors/aggregate/index.js +12 -3
  130. package/src/features/logging/aggregate/index.js +7 -6
  131. package/src/features/metrics/aggregate/index.js +5 -1
  132. package/src/features/page_view_event/aggregate/index.js +6 -2
  133. package/src/features/page_view_timing/aggregate/index.js +6 -1
  134. package/src/features/session_replay/aggregate/index.js +7 -1
  135. package/src/features/session_trace/aggregate/index.js +6 -2
  136. package/src/features/soft_navigations/aggregate/ajax-node.js +26 -5
  137. package/src/features/soft_navigations/aggregate/index.js +7 -1
  138. package/src/features/soft_navigations/aggregate/initial-page-load-interaction.js +1 -1
  139. package/src/features/soft_navigations/aggregate/interaction.js +6 -4
  140. package/src/features/utils/aggregate-base.js +1 -3
@@ -3,6 +3,7 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { addCustomAttributes, getAddStringContext, nullable, numeric } from '../../../common/serialize/bel-serializer'
6
+ import { createStringAdders } from '../../../common/payloads/payloads'
6
7
  import { AJAX_ID } from '../../ajax/constants'
7
8
  import { NODE_TYPE } from '../constants'
8
9
  import { BelNode } from './bel-node'
@@ -25,6 +26,13 @@ export class AjaxNode extends BelNode {
25
26
  this.targetAttributes = ajaxEvent.targetAttributes
26
27
  this[AJAX_ID] = ajaxEvent[AJAX_ID] // all AjaxRequest events should have a unique identifier to allow for easier grouping and analysis in the UI
27
28
 
29
+ // optional payload metadata attributes
30
+ this.requestBody = ajaxEvent.requestBody
31
+ this.requestHeaders = ajaxEvent.requestHeaders
32
+ this.requestQuery = ajaxEvent.requestQuery
33
+ this.responseBody = ajaxEvent.responseBody
34
+ this.responseHeaders = ajaxEvent.responseHeaders
35
+
28
36
  this.start = ajaxEvent.startTime
29
37
  this.end = ajaxEvent.endTime
30
38
  if (ajaxContext?.latestLongtaskEnd) {
@@ -33,8 +41,9 @@ export class AjaxNode extends BelNode {
33
41
  } else this.callbackEnd = this.end // if no long task was observed, callbackEnd is the same as end
34
42
  }
35
43
 
36
- serialize (parentStartTimestamp, agentRef) {
37
- const addString = getAddStringContext(agentRef.runtime.obfuscator)
44
+ serialize (parentStartTimestamp, agentRef, ajaxObfuscator) {
45
+ const { addString, addStringWithTruncation } = createStringAdders(getAddStringContext, ajaxObfuscator)
46
+
38
47
  const nodeList = []
39
48
 
40
49
  // IMPORTANT: The order in which addString is called matters and correlates to the order in which string shows up in the harvest payload. Do not re-order the following code.
@@ -55,11 +64,23 @@ export class AjaxNode extends BelNode {
55
64
  addString(this.nodeId),
56
65
  nullable(this.spanId, addString, true) + nullable(this.traceId, addString, true) + nullable(this.spanTimestamp, numeric)
57
66
  ]
58
- let allAttachedNodes = addCustomAttributes({
59
- ...(this.gql || {}),
67
+ // Regular attributes: obfuscate only
68
+ const regularAttrs = addCustomAttributes({
69
+ [AJAX_ID]: this[AJAX_ID],
60
70
  ...(this.targetAttributes || {}),
61
- [AJAX_ID]: this[AJAX_ID]
71
+ ...(this.gql || {})
62
72
  }, addString)
73
+
74
+ // Payload attributes: obfuscate then truncate
75
+ const payloadAttrs = addCustomAttributes({
76
+ ...(this.requestBody ? { requestBody: this.requestBody } : {}),
77
+ ...(this.requestHeaders ? { requestHeaders: this.requestHeaders } : {}),
78
+ ...(this.requestQuery ? { requestQuery: this.requestQuery } : {}),
79
+ ...(this.responseBody ? { responseBody: this.responseBody } : {}),
80
+ ...(this.responseHeaders ? { responseHeaders: this.responseHeaders } : {})
81
+ }, addStringWithTruncation)
82
+
83
+ let allAttachedNodes = [...regularAttrs, ...payloadAttrs]
63
84
  this.children.forEach(node => allAttachedNodes.push(node.serialize())) // no children is expected under ajax nodes at this time
64
85
 
65
86
  fields[1] = numeric(allAttachedNodes.length)
@@ -8,10 +8,12 @@ import { webdriverDetected } from '../../../common/util/webdriver-detection'
8
8
  import { loadTime } from '../../../common/vitals/load-time'
9
9
  import { FEATURE_NAMES } from '../../../loaders/features/features'
10
10
  import { AggregateBase } from '../../utils/aggregate-base'
11
+ import { Obfuscator } from '../../../common/util/obfuscate'
11
12
  import { API_TRIGGER_NAME, FEATURE_NAME, INTERACTION_STATUS, INTERACTION_TRIGGERS, IPL_TRIGGER_NAME, NO_LONG_TASK_WINDOW, POPSTATE_MERGE_WINDOW, POPSTATE_TRIGGER } from '../constants'
12
13
  import { AjaxNode } from './ajax-node'
13
14
  import { InitialPageLoadInteraction } from './initial-page-load-interaction'
14
15
  import { Interaction } from './interaction'
16
+ import { EVENT_TYPES } from '../../../common/constants/events'
15
17
 
16
18
  export class Aggregate extends AggregateBase {
17
19
  static featureName = FEATURE_NAME
@@ -20,6 +22,10 @@ export class Aggregate extends AggregateBase {
20
22
 
21
23
  super.customAttributesAreSeparate = true
22
24
 
25
+ // Create obfuscators for browser interactions and nested AJAX requests
26
+ this.interactionObfuscator = new Obfuscator(agentRef, EVENT_TYPES.BI)
27
+ this.ajaxObfuscator = new Obfuscator(agentRef, EVENT_TYPES.AJAX)
28
+
23
29
  this.interactionsToHarvest = this.events
24
30
  this.domObserver = domObserver
25
31
 
@@ -86,7 +92,7 @@ export class Aggregate extends AggregateBase {
86
92
  let firstIxnStartTime
87
93
  const serializedIxnList = []
88
94
  for (const interaction of eventBuffer) {
89
- serializedIxnList.push(interaction.serialize(firstIxnStartTime, this.agentRef))
95
+ serializedIxnList.push(interaction.serialize(firstIxnStartTime, this.agentRef, this.interactionObfuscator, this.ajaxObfuscator))
90
96
  if (firstIxnStartTime === undefined) firstIxnStartTime = Math.floor(interaction.start) // careful not to match or overwrite on 0 value!
91
97
  }
92
98
  return `bel.7;${serializedIxnList.join(';')}`
@@ -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 { navTimingValues } from '../../../common/timing/nav-timing'
@@ -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 { globalScope, initialLocation } from '../../../common/constants/runtime'
@@ -133,11 +133,13 @@ export class Interaction extends BelNode {
133
133
  * Serializes (BEL) the interaction data for transmission.
134
134
  * @param {Number} firstStartTimeOfPayload timestamp
135
135
  * @param {Agent} agentRef Pass in the agent reference directly so that the event itself doesnt need to store the pointers and ruin the evaluation of the event size by including unused object references.
136
+ * @param {Obfuscator} interactionObfuscator Obfuscator for BrowserInteraction event type
137
+ * @param {Obfuscator} ajaxObfuscator Obfuscator for AjaxRequest event type (passed to child AjaxNodes)
136
138
  * @returns {String} A string that is the serialized representation of this interaction.
137
139
  */
138
- serialize (firstStartTimeOfPayload, agentRef) {
140
+ serialize (firstStartTimeOfPayload, agentRef, interactionObfuscator, ajaxObfuscator) {
139
141
  const isFirstIxnOfPayload = firstStartTimeOfPayload === undefined
140
- const addString = getAddStringContext(agentRef.runtime.obfuscator)
142
+ const addString = getAddStringContext(interactionObfuscator)
141
143
  const nodeList = []
142
144
  let ixnType
143
145
  if (this.trigger === IPL_TRIGGER_NAME) ixnType = INTERACTION_TYPE.INITIAL_PAGE_LOAD
@@ -170,7 +172,7 @@ export class Interaction extends BelNode {
170
172
  /* Querypack encoder+decoder quirkiness:
171
173
  - If first ixn node of payload is being processed, its children's start time must be offset by this node's start. (firstStartTime should be undefined.)
172
174
  - Else for subsequent ixns in the same payload, we go back to using that first ixn node's start to offset their children's start. */
173
- this.children.forEach(node => allAttachedNodes.push(node.serialize(isFirstIxnOfPayload ? this.start : firstStartTimeOfPayload, agentRef))) // recursively add the serialized string of every child of this (ixn) bel node
175
+ this.children.forEach(node => allAttachedNodes.push(node.serialize(isFirstIxnOfPayload ? this.start : firstStartTimeOfPayload, agentRef, ajaxObfuscator))) // recursively add the serialized string of every child of this (ixn) bel node
174
176
 
175
177
  fields[1] = numeric(allAttachedNodes.length)
176
178
  nodeList.push(fields)
@@ -4,7 +4,6 @@
4
4
  */
5
5
  import { FeatureBase } from './feature-base'
6
6
  import { drain } from '../../common/drain/drain'
7
- import { Obfuscator } from '../../common/util/obfuscate'
8
7
  import { FEATURE_NAMES } from '../../loaders/features/features'
9
8
  import { Harvester } from '../../common/harvest/harvester'
10
9
  import { EventBuffer } from './event-buffer'
@@ -182,8 +181,7 @@ export class AggregateBase extends FeatureBase {
182
181
  * This method should run after checkConfiguration, which may reset the agent's info/runtime object that is used here.
183
182
  */
184
183
  doOnceForAllAggregate (agentRef) {
185
- if (!agentRef.runtime.obfuscator) agentRef.runtime.obfuscator = new Obfuscator(agentRef)
186
- this.obfuscator = agentRef.runtime.obfuscator
184
+ // Note: obfuscator is now created per-feature for their specific event types
187
185
 
188
186
  if (!agentRef.runtime.harvester) agentRef.runtime.harvester = new Harvester(agentRef)
189
187
  }