@newrelic/browser-agent 1.267.0 → 1.269.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 (104) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +2 -1
  3. package/dist/cjs/common/config/init.js +3 -0
  4. package/dist/cjs/common/constants/env.cdn.js +1 -1
  5. package/dist/cjs/common/constants/env.npm.js +1 -1
  6. package/dist/cjs/common/dom/iframe.js +10 -0
  7. package/dist/cjs/common/dom/selector-path.js +48 -0
  8. package/dist/cjs/common/event-listener/event-listener-opts.js +4 -26
  9. package/dist/cjs/common/timing/time-keeper.js +9 -0
  10. package/dist/cjs/common/util/stringify.js +1 -1
  11. package/dist/cjs/features/generic_events/aggregate/index.js +80 -9
  12. package/dist/cjs/features/generic_events/aggregate/user-actions/aggregated-user-action.js +39 -0
  13. package/dist/cjs/features/generic_events/aggregate/user-actions/user-actions-aggregator.js +77 -0
  14. package/dist/cjs/features/generic_events/constants.js +6 -2
  15. package/dist/cjs/features/generic_events/instrument/index.js +12 -1
  16. package/dist/cjs/features/jserrors/aggregate/index.js +23 -3
  17. package/dist/cjs/features/jserrors/aggregate/internal-errors.js +42 -0
  18. package/dist/cjs/features/logging/aggregate/index.js +10 -2
  19. package/dist/cjs/features/metrics/aggregate/index.js +2 -1
  20. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -1
  21. package/dist/cjs/features/session_replay/aggregate/index.js +5 -3
  22. package/dist/cjs/features/session_trace/aggregate/index.js +11 -9
  23. package/dist/cjs/features/spa/instrument/index.js +4 -0
  24. package/dist/cjs/loaders/agent-base.js +1 -0
  25. package/dist/cjs/loaders/micro-agent.js +1 -1
  26. package/dist/esm/common/config/init.js +3 -0
  27. package/dist/esm/common/constants/env.cdn.js +1 -1
  28. package/dist/esm/common/constants/env.npm.js +1 -1
  29. package/dist/esm/common/dom/iframe.js +4 -0
  30. package/dist/esm/common/dom/selector-path.js +41 -0
  31. package/dist/esm/common/event-listener/event-listener-opts.js +4 -27
  32. package/dist/esm/common/timing/time-keeper.js +9 -0
  33. package/dist/esm/common/util/stringify.js +1 -1
  34. package/dist/esm/features/generic_events/aggregate/index.js +82 -11
  35. package/dist/esm/features/generic_events/aggregate/user-actions/aggregated-user-action.js +32 -0
  36. package/dist/esm/features/generic_events/aggregate/user-actions/user-actions-aggregator.js +70 -0
  37. package/dist/esm/features/generic_events/constants.js +5 -1
  38. package/dist/esm/features/generic_events/instrument/index.js +14 -3
  39. package/dist/esm/features/jserrors/aggregate/index.js +23 -3
  40. package/dist/esm/features/jserrors/aggregate/internal-errors.js +36 -0
  41. package/dist/esm/features/logging/aggregate/index.js +10 -2
  42. package/dist/esm/features/metrics/aggregate/index.js +2 -1
  43. package/dist/esm/features/page_view_event/aggregate/index.js +1 -1
  44. package/dist/esm/features/session_replay/aggregate/index.js +5 -3
  45. package/dist/esm/features/session_trace/aggregate/index.js +11 -9
  46. package/dist/esm/features/spa/instrument/index.js +4 -0
  47. package/dist/esm/loaders/agent-base.js +1 -0
  48. package/dist/esm/loaders/micro-agent.js +1 -1
  49. package/dist/types/common/config/init.d.ts.map +1 -1
  50. package/dist/types/common/dom/iframe.d.ts +2 -0
  51. package/dist/types/common/dom/iframe.d.ts.map +1 -0
  52. package/dist/types/common/dom/selector-path.d.ts +2 -0
  53. package/dist/types/common/dom/selector-path.d.ts.map +1 -0
  54. package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
  55. package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
  56. package/dist/types/common/timing/time-keeper.d.ts +6 -0
  57. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  58. package/dist/types/features/generic_events/aggregate/index.d.ts +16 -1
  59. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  60. package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts +22 -0
  61. package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts.map +1 -0
  62. package/dist/types/features/generic_events/aggregate/user-actions/user-actions-aggregator.d.ts +12 -0
  63. package/dist/types/features/generic_events/aggregate/user-actions/user-actions-aggregator.d.ts.map +1 -0
  64. package/dist/types/features/generic_events/constants.d.ts +4 -0
  65. package/dist/types/features/generic_events/constants.d.ts.map +1 -1
  66. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  67. package/dist/types/features/jserrors/aggregate/index.d.ts +10 -1
  68. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  69. package/dist/types/features/jserrors/aggregate/internal-errors.d.ts +7 -0
  70. package/dist/types/features/jserrors/aggregate/internal-errors.d.ts.map +1 -0
  71. package/dist/types/features/logging/aggregate/index.d.ts +3 -0
  72. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  73. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  74. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  75. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  76. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  77. package/dist/types/features/spa/instrument/index.d.ts +3 -0
  78. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  79. package/dist/types/loaders/agent-base.d.ts +1 -0
  80. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  81. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/common/config/init.js +1 -0
  84. package/src/common/dom/iframe.js +4 -0
  85. package/src/common/dom/selector-path.js +45 -0
  86. package/src/common/event-listener/event-listener-opts.js +5 -30
  87. package/src/common/timing/__mocks__/time-keeper.js +1 -0
  88. package/src/common/timing/time-keeper.js +9 -0
  89. package/src/common/util/stringify.js +1 -1
  90. package/src/features/generic_events/aggregate/index.js +74 -14
  91. package/src/features/generic_events/aggregate/user-actions/aggregated-user-action.js +33 -0
  92. package/src/features/generic_events/aggregate/user-actions/user-actions-aggregator.js +73 -0
  93. package/src/features/generic_events/constants.js +6 -0
  94. package/src/features/generic_events/instrument/index.js +19 -3
  95. package/src/features/jserrors/aggregate/index.js +21 -7
  96. package/src/features/jserrors/aggregate/internal-errors.js +33 -0
  97. package/src/features/logging/aggregate/index.js +9 -4
  98. package/src/features/metrics/aggregate/index.js +2 -1
  99. package/src/features/page_view_event/aggregate/index.js +1 -3
  100. package/src/features/session_replay/aggregate/index.js +5 -7
  101. package/src/features/session_trace/aggregate/index.js +12 -16
  102. package/src/features/spa/instrument/index.js +3 -0
  103. package/src/loaders/agent-base.js +1 -0
  104. package/src/loaders/micro-agent.js +2 -1
@@ -11,6 +11,7 @@ import { deregisterDrain } from '../../../common/drain/drain'
11
11
  import { globalScope } from '../../../common/constants/runtime'
12
12
  import { MODE, SESSION_EVENTS } from '../../../common/session/constants'
13
13
  import { applyFnToProps } from '../../../common/util/traverse'
14
+ import { cleanURL } from '../../../common/url/clean-url'
14
15
 
15
16
  const ERROR_MODE_SECONDS_WINDOW = 30 * 1000 // sliding window of nodes to track when simply monitoring (but not harvesting) in error mode
16
17
  /** Reserved room for query param attrs */
@@ -63,6 +64,12 @@ export class Aggregate extends AggregateBase {
63
64
  // if another page's session entity has expired, or another page has transitioned to off and this one hasn't... we can just abort straight away here
64
65
  if (this.sessionId !== sessionState.value || (eventType === 'cross-tab' && this.scheduler?.started && sessionState.sessionTraceMode === MODE.OFF)) this.abort(2)
65
66
  })
67
+
68
+ if (typeof PerformanceNavigationTiming !== 'undefined') {
69
+ this.traceStorage.storeTiming(globalScope.performance?.getEntriesByType?.('navigation')[0])
70
+ } else {
71
+ this.traceStorage.storeTiming(globalScope.performance?.timing, true)
72
+ }
66
73
  }
67
74
 
68
75
  /** ST/SR sampling flow in BCS - https://drive.google.com/file/d/19hwt2oft-8Hh4RrjpLqEXfpP_9wYBLcq/view?usp=sharing */
@@ -92,12 +99,6 @@ export class Aggregate extends AggregateBase {
92
99
  registerHandler('trace-jserror', (...args) => this.traceStorage.storeErrorAgg(...args), this.featureName, this.ee)
93
100
  registerHandler('pvtAdded', (...args) => this.traceStorage.processPVT(...args), this.featureName, this.ee)
94
101
 
95
- if (typeof PerformanceNavigationTiming !== 'undefined') {
96
- this.traceStorage.storeTiming(globalScope.performance?.getEntriesByType?.('navigation')[0])
97
- } else {
98
- this.traceStorage.storeTiming(globalScope.performance?.timing, true)
99
- }
100
-
101
102
  /** Only start actually harvesting if running in full mode at init time */
102
103
  if (this.mode === MODE.FULL) this.startHarvesting()
103
104
  else {
@@ -154,21 +155,15 @@ export class Aggregate extends AggregateBase {
154
155
  type: 'BrowserSessionChunk',
155
156
  app_id: this.agentInfo.applicationID,
156
157
  protocol_version: '0',
157
- timestamp: Math.floor(this.timeKeeper.correctAbsoluteTimestamp(
158
- this.timeKeeper.convertRelativeTimestamp(earliestTimeStamp)
159
- )),
158
+ timestamp: Math.floor(this.timeKeeper.correctRelativeTimestamp(earliestTimeStamp)),
160
159
  attributes: encodeObj({
161
160
  ...(agentMetadata.entityGuid && { entityGuid: agentMetadata.entityGuid }),
162
161
  harvestId: `${this.agentRuntime.session?.state.value}_${this.agentRuntime.ptid}_${this.agentRuntime.harvestCount}`,
163
162
  // this section of attributes must be controllable and stay below the query param padding limit -- see QUERY_PARAM_PADDING
164
163
  // if not, data could be lost to truncation at time of sending, potentially breaking parsing / API behavior in NR1
165
164
  // trace payload metadata
166
- 'trace.firstTimestamp': Math.floor(this.timeKeeper.correctAbsoluteTimestamp(
167
- this.timeKeeper.convertRelativeTimestamp(earliestTimeStamp)
168
- )),
169
- 'trace.lastTimestamp': Math.floor(this.timeKeeper.correctAbsoluteTimestamp(
170
- this.timeKeeper.convertRelativeTimestamp(latestTimeStamp)
171
- )),
165
+ 'trace.firstTimestamp': Math.floor(this.timeKeeper.correctRelativeTimestamp(earliestTimeStamp)),
166
+ 'trace.lastTimestamp': Math.floor(this.timeKeeper.correctRelativeTimestamp(latestTimeStamp)),
172
167
  'trace.nodes': stns.length,
173
168
  'trace.originTimestamp': this.timeKeeper.correctedOriginTime,
174
169
  // other payload metadata
@@ -178,7 +173,8 @@ export class Aggregate extends AggregateBase {
178
173
  ptid: `${this.ptid}`,
179
174
  session: `${this.sessionId}`,
180
175
  // customer-defined data should go last so that if it exceeds the query param padding limit it will be truncated instead of important attrs
181
- ...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) })
176
+ ...(endUserId && { 'enduser.id': this.obfuscator.obfuscateString(endUserId) }),
177
+ currentUrl: this.obfuscator.obfuscateString(cleanURL('' + location))
182
178
  // The Query Param is being arbitrarily limited in length here. It is also applied when estimating the size of the payload in getPayloadSize()
183
179
  }, QUERY_PARAM_PADDING).substring(1) // remove the leading '&'
184
180
  },
@@ -20,6 +20,9 @@ const {
20
20
  FEATURE_NAME, START, END, BODY, CB_END, JS_TIME, FETCH, FN_START, CB_START, FN_END
21
21
  } = CONSTANTS
22
22
 
23
+ /**
24
+ * @deprecated This feature has been deprecated, in favor of `soft_navigations`, which is in limited preview. Consider using/importing `SoftNavigations` instead. To gain access to the limited preview, please see https://docs.newrelic.com/docs/browser/single-page-app-monitoring/get-started/browser-spa-v2/ for more information. This feature will be removed in a future release.
25
+ */
23
26
  export class Instrument extends InstrumentBase {
24
27
  static featureName = FEATURE_NAME
25
28
  constructor (agentIdentifier, aggregator, auto = true) {
@@ -173,6 +173,7 @@ export class AgentBase {
173
173
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction/}
174
174
  * @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.
175
175
  * - Note: Does not apply to MicroAgent
176
+ * - Deprecation Notice: interaction.createTracer is deprecated. See https://docs.newrelic.com/eol/2024/04/eol-04-24-24-createtracer/ for more information.
176
177
  */
177
178
  interaction () {
178
179
  return this.#callMethod('interaction')
@@ -17,7 +17,8 @@ import { AgentBase } from './agent-base'
17
17
  const nonAutoFeatures = [
18
18
  FEATURE_NAMES.jserrors,
19
19
  FEATURE_NAMES.genericEvents,
20
- FEATURE_NAMES.metrics
20
+ FEATURE_NAMES.metrics,
21
+ FEATURE_NAMES.logging
21
22
  ]
22
23
 
23
24
  /**