@newrelic/browser-agent 1.282.0 → 1.283.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 (60) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +17 -0
  3. package/dist/cjs/common/config/info.js +21 -0
  4. package/dist/cjs/common/config/init.js +88 -20
  5. package/dist/cjs/common/constants/env.cdn.js +1 -1
  6. package/dist/cjs/common/constants/env.npm.js +1 -1
  7. package/dist/cjs/common/session/session-entity.js +2 -0
  8. package/dist/cjs/features/logging/aggregate/index.js +52 -3
  9. package/dist/cjs/features/logging/constants.js +9 -1
  10. package/dist/cjs/features/logging/instrument/index.js +20 -0
  11. package/dist/cjs/features/session_replay/aggregate/index.js +7 -3
  12. package/dist/cjs/features/utils/aggregate-base.js +3 -0
  13. package/dist/cjs/loaders/agent.js +12 -1
  14. package/dist/cjs/loaders/browser-agent.js +5 -2
  15. package/dist/cjs/loaders/micro-agent.js +1 -1
  16. package/dist/esm/common/config/info.js +22 -0
  17. package/dist/esm/common/config/init.js +86 -17
  18. package/dist/esm/common/constants/env.cdn.js +1 -1
  19. package/dist/esm/common/constants/env.npm.js +1 -1
  20. package/dist/esm/common/session/session-entity.js +2 -0
  21. package/dist/esm/features/logging/aggregate/index.js +53 -4
  22. package/dist/esm/features/logging/constants.js +8 -0
  23. package/dist/esm/features/logging/instrument/index.js +20 -0
  24. package/dist/esm/features/session_replay/aggregate/index.js +7 -3
  25. package/dist/esm/features/utils/aggregate-base.js +3 -0
  26. package/dist/esm/loaders/agent.js +12 -1
  27. package/dist/esm/loaders/browser-agent.js +5 -2
  28. package/dist/esm/loaders/micro-agent.js +1 -1
  29. package/dist/types/common/config/info.d.ts +31 -0
  30. package/dist/types/common/config/info.d.ts.map +1 -1
  31. package/dist/types/common/config/init.d.ts +262 -0
  32. package/dist/types/common/config/init.d.ts.map +1 -1
  33. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  34. package/dist/types/features/logging/aggregate/index.d.ts +7 -0
  35. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  36. package/dist/types/features/logging/constants.d.ts +13 -0
  37. package/dist/types/features/logging/constants.d.ts.map +1 -1
  38. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  39. package/dist/types/features/session_replay/aggregate/index.d.ts +3 -2
  40. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  41. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  42. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  43. package/dist/types/loaders/agent.d.ts +43 -3
  44. package/dist/types/loaders/agent.d.ts.map +1 -1
  45. package/dist/types/loaders/browser-agent.d.ts +0 -1
  46. package/dist/types/loaders/browser-agent.d.ts.map +1 -1
  47. package/dist/types/loaders/micro-agent.d.ts +2 -2
  48. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  49. package/package.json +1 -1
  50. package/src/common/config/info.js +22 -3
  51. package/src/common/config/init.js +95 -17
  52. package/src/common/session/session-entity.js +2 -0
  53. package/src/features/logging/aggregate/index.js +57 -4
  54. package/src/features/logging/constants.js +9 -0
  55. package/src/features/logging/instrument/index.js +8 -0
  56. package/src/features/session_replay/aggregate/index.js +8 -3
  57. package/src/features/utils/aggregate-base.js +4 -0
  58. package/src/loaders/agent.js +12 -1
  59. package/src/loaders/browser-agent.js +5 -3
  60. package/src/loaders/micro-agent.js +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.283.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.282.0...v1.283.0) (2025-02-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add auto-logging feature ([#1274](https://github.com/newrelic/newrelic-browser-agent/issues/1274)) ([91204ae](https://github.com/newrelic/newrelic-browser-agent/commit/91204ae0099508d13c944be06ed6c46dce901ce3))
12
+ * Add global custom attributes to log data ([#1343](https://github.com/newrelic/newrelic-browser-agent/issues/1343)) ([dc7d27c](https://github.com/newrelic/newrelic-browser-agent/commit/dc7d27c718c13a54bce5cc1fa6b0260b95008637))
13
+
6
14
  ## [1.282.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.281.0...v1.282.0) (2025-02-13)
7
15
 
8
16
 
package/README.md CHANGED
@@ -88,6 +88,23 @@ The following features may be disabled by adding `init` entries as shown above.
88
88
 
89
89
  See the [New Relic documentation site](https://docs.newrelic.com/docs/browser/browser-monitoring/getting-started/introduction-browser-monitoring/) for information on the above features.
90
90
 
91
+ ## Options Parameter
92
+
93
+ The `options` parameter used, or passed in, when instantiating the `BrowserAgent` class can include the following arguments:
94
+
95
+ | Argument | Type | Description |
96
+ |----------------|----------|-----------------------------------------------------------------------------|
97
+ | `info` | Object | Operational information for the agent. `applicationID` and `licenseKey` properties are strictly required to be defined inside of this. Some properties may be provided by APM-injection installation. See model object in [info.js](src/common/config/info.js). |
98
+ | `init` | Object | (Optional) Initialization settings for the agent, including feature toggles. This controls many parts of the agent's behavior and that of its features. It's recommended to understand each config being changed before doing so. See the object returned by `model()` in [init.js](src/common/config/init.js). |
99
+ | `loader_config`| Object | (Optional) Agent installed via APM-injection is provided this object by the APM agent. It's highly recommended to leave this alone. Defaults to model object in [loader-config.js](src/common/config/loader-config.js). |
100
+ | `runtime` | Object | (Optional) Used by the agent to store shared references or info at runtime. It's highly recommended to leave this alone. Defaults to model object in [runtime.js](src/common/config/runtime.js). |
101
+ | `exposed` | Boolean | (Optional) Affects whether the `newrelic` API includes or acts on this agent. If set to false, for example, `newrelic.setCustomAttribute()` would not affect this agent instance. Defaults to true. |
102
+
103
+ The underlying `Agent` class `options` parameter also includes the following _additional_ arguments, as shown in the next section:
104
+
105
+ | Argument | Type | Description |
106
+ |----------------|----------|-----------------------------------------------------------------------------|
107
+ | `features` | Array | List of feature classes to be used by the agent. This determines what features _can_ actually be enabled and affects your bundler build size of the agent. `PageViewEvent` is forcibly included, even if it's not in this array or an empty array is passed in. |
91
108
 
92
109
  ## Composing a custom agent with selected feature modules
93
110
 
@@ -13,6 +13,27 @@ var _configurable = require("./configurable");
13
13
  * SPDX-License-Identifier: Apache-2.0
14
14
  */
15
15
 
16
+ /**
17
+ * @typedef {Object} Info
18
+ * @property {string} [beacon]
19
+ * @property {string} [errorBeacon] - Base URL endpoint for all data harvested by the agent. Proxies should be defined in the init instead.
20
+ * @property {string} licenseKey - New Relic license key provided by the website in user account.
21
+ * @property {string} applicationID - New Relic application ID provided when creating a browser entity in the UI.
22
+ * @property {number} [sa]
23
+ * @property {number} [queueTime]
24
+ * @property {number} [applicationTime]
25
+ * @property {string} [ttGuid]
26
+ * @property {string} [user]
27
+ * @property {string} [account]
28
+ * @property {string} [product]
29
+ * @property {string} [extra]
30
+ * @property {Object} [jsAttributes] - Custom attributes that are added to majority of agent's payloads. The `setCustomAttribute` API method affects this.
31
+ * @property {string} [userAttributes]
32
+ * @property {string} [atts]
33
+ * @property {string} [transactionName]
34
+ * @property {string} [tNamePlain]
35
+ */
36
+
16
37
  const model = {
17
38
  // preset defaults
18
39
  beacon: _nreum.defaults.beacon,
@@ -7,9 +7,8 @@ exports.getConfiguration = getConfiguration;
7
7
  exports.getConfigurationValue = getConfigurationValue;
8
8
  exports.setConfiguration = setConfiguration;
9
9
  var _constants = require("../../features/generic_events/constants");
10
- var _constants2 = require("../../features/logging/constants");
11
10
  var _querySelector = require("../dom/query-selector");
12
- var _constants3 = require("../session/constants");
11
+ var _constants2 = require("../session/constants");
13
12
  var _console = require("../util/console");
14
13
  var _nreum = require("../window/nreum");
15
14
  var _configurable = require("./configurable");
@@ -18,6 +17,88 @@ var _configurable = require("./configurable");
18
17
  * SPDX-License-Identifier: Apache-2.0
19
18
  */
20
19
 
20
+ /**
21
+ * @typedef {Object} Init
22
+ * @property {Object} [ajax]
23
+ * @property {Array<string>} [ajax.deny_list] - List of domain URLs to be excluded from AjaxRequest collection.
24
+ * @property {boolean} [ajax.block_internal] - If true, agent requests going to harvest endpoint are treated as on deny list. In other words, agent will not self-report AJAX.
25
+ * @property {boolean} [ajax.enabled] - Turn on/off the ajax feature (on by default).
26
+ * @property {boolean} [ajax.autoStart] - If true, the agent will automatically start the ajax feature. Otherwise, it will be in a deferred state until the `start` API method is called.
27
+ * @property {Object} [distributed_tracing]
28
+ * @property {boolean} [distributed_tracing.enabled] - If true, distributed tracing headers will be added to outgoing requests. Requires ajax feature to be running.
29
+ * @property {boolean} [distributed_tracing.exclude_newrelic_header]
30
+ * @property {boolean} [distributed_tracing.cors_use_newrelic_header]
31
+ * @property {boolean} [distributed_tracing.cors_use_tracecontext_headers]
32
+ * @property {Array<string>} [distributed_tracing.allowed_origins]
33
+ * @property {Array<string>} [feature_flags] - An array of feature flags to enable experimental features.
34
+ * @property {Object} [generic_events]
35
+ * @property {boolean} [generic_events.enabled] - Turn on/off the generic events feature (on by default). This is required for `PageAction`, `UserAction`, and `BrowserPerformance` events.
36
+ * @property {boolean} [generic_events.autoStart] - If true, the agent will automatically start the generic events feature. Otherwise, it will be in a deferred state until the `start` API method is called.
37
+ * @property {Object} [harvest]
38
+ * @property {number} [harvest.interval] - The interval in seconds at which the agent will send out data. It's not recommended to change this value.
39
+ * @property {Object} [jserrors]
40
+ * @property {boolean} [jserrors.enabled] - Turn on/off the jserrors feature (on by default).
41
+ * @property {boolean} [jserrors.autoStart] - If true, the agent will automatically start the jserrors feature. Otherwise, it will be in a deferred state until the `start` API method is called.
42
+ * @property {Object} [logging]
43
+ * @property {boolean} [logging.enabled] - Turn on/off the logging feature (on by default).
44
+ * @property {boolean} [logging.autoStart] - If true, the agent will automatically start the logging feature. Otherwise, it will be in a deferred state until the `start` API method is called.
45
+ * @property {Object} [metrics]
46
+ * @property {boolean} [metrics.enabled] - Turn on/off the metrics feature (on by default).
47
+ * @property {boolean} [metrics.autoStart] - If true, the agent will automatically start the metrics feature. Otherwise, it will be in a deferred state until the `start` API method is called.
48
+ * @property {Array<Object>} [obfuscate] - Array of regexp and corresponding replacement patterns for obfuscating data.
49
+ * @property {Object} [page_action]
50
+ * @property {boolean} [page_action.enabled] - Must be true to allow PageAction events to be captured.
51
+ * @property {Object} [page_view_event]
52
+ * @property {boolean} [page_view_event.enabled] - This setting is ignored! PageViewEvent is always enabled by force.
53
+ * @property {boolean} [page_view_event.autoStart] - If true, the agent will automatically send the RUM request. Otherwise, it will be in a deferred state until the `start` API method is called.
54
+ * @property {Object} [page_view_timing]
55
+ * @property {boolean} [page_view_timing.enabled] - Turn on/off the page view timing feature (on by default).
56
+ * @property {boolean} [page_view_timing.autoStart] - If true, the agent will automatically start the page view timing feature. Otherwise, it will be in a deferred state until the `start` API method is called.
57
+ * @property {Object} [performance]
58
+ * @property {boolean} [performance.capture_marks] - If true, the agent will capture PerformanceMark events.
59
+ * @property {boolean} [performance.capture_measures] - If true, the agent will capture PerformanceMeasure events.
60
+ * @property {boolean} [performance.capture_detail] - If true, `BrowserPerformance` events from marks and measures will include, as attribute(s), the `detail` metadata provided to `markOptions` and `measureOptions`.
61
+ * @property {Object} [performance.resources]
62
+ * @property {boolean} [performance.resources.enabled] - If true, the agent will capture PerformanceResourceTiming entries.
63
+ * @property {Array<string>} [performance.resources.asset_types] - Array of `initiatorType` strings to filter the desired ResourceTiming entries. By default, all resource types are captured.
64
+ * @property {Array<string>} [performance.resources.first_party_domains] - Each resource URL will be checked against this list to determine if it should be labeled "first party" in the resulting `BrowserPerformance` event.
65
+ * @property {boolean} [performance.resources.ignore_newrelic] - When true (default), resource entries associated with New Relic domains will be ignored.
66
+ * @property {Object} [privacy]
67
+ * @property {boolean} [privacy.cookies_enabled] - If true (default), session tracking of users across page loads is enabled in the agent. This is required for session trace, replay, and session-related features.
68
+ * @property {Object} [proxy]
69
+ * @property {string} [proxy.assets] - Set value will be used to overwrite the webpack asset path used to fetch agent assets.
70
+ * @property {string} [proxy.beacon] - Set value will be used to overwrite the endpoint URL to which we send analytics.
71
+ * @property {Object} [session]
72
+ * @property {number} [session.expiresMs] - When session tracking is on, this determines how long a session will last before expiring. Modifying this value is not recommended.
73
+ * @property {number} [session.inactiveMs] - When session tracking is on, this determines how long a session will last without user activity before expiring. Modifying this value is not recommended.
74
+ * @property {Object} [session_replay]
75
+ * @property {boolean} [session_replay.autoStart] - If true, the agent will automatically start the session replay feature. Otherwise, it will be in a deferred state until the `start` API method is called.
76
+ * @property {boolean} [session_replay.enabled] - Turn on/off the session replay feature (off by default).
77
+ * @property {boolean} [session_replay.preload] - If true, allow the agent to run rrweb recorder immediately instead of waiting until after the window.load event, for new sessions. Existing sessions ignore this setting.
78
+ * @property {number} [session_replay.sampling_rate] - This setting is deprecated and ineffective. Sampling is controlled in New Relic by server-side configuration.
79
+ * @property {number} [session_replay.error_sampling_rate] - This setting is deprecated and ineffective.
80
+ * @property {boolean} [session_replay.collect_fonts] - When true, serialize fonts for collection without public asset url. This is currently broken -- https://github.com/rrweb-io/rrweb/issues/1304.
81
+ * @property {boolean} [session_replay.inline_images] - When true, serialize images for collection without public asset url. Not recommended for use. This is currently for TESTING as it easily generates payloads too large to be harvested.
82
+ * @property {boolean} [session_replay.fix_stylesheets] - When true, tries to fetch any missing stylesheets again to inline in replayer.
83
+ * @property {boolean} [session_replay.mask_all_inputs] - If true, all input content will be masked with asterisks.
84
+ * @property {string} [session_replay.mask_text_selector] - Set value should be in CSS selector syntax and is used to identify matching elements to mask.
85
+ * @property {string} [session_replay.block_selector] - Set value should be in CSS selector syntax and is used to identify matching elements to block.
86
+ * @property {Object} [session_replay.mask_input_options] - If mask_all_inputs is not true, this object will be used to select what input to mask. Passwords are forcibly always masked.
87
+ * @property {Object} [session_trace]
88
+ * @property {boolean} [session_trace.enabled] - Turn on/off the session trace feature (on by default).
89
+ * @property {boolean} [session_trace.autoStart] - If true, the agent will automatically start the session trace feature. Otherwise, it will be in a deferred state until the `start` API method is called.
90
+ * @property {Object} [soft_navigations]
91
+ * @property {boolean} [soft_navigations.enabled] - Turn on/off the soft navigations feature (on by default).
92
+ * @property {boolean} [soft_navigations.autoStart] - If true, the agent will automatically start the soft navigations feature. Otherwise, it will be in a deferred state until the `start` API method is called.
93
+ * @property {Object} [spa]
94
+ * @property {boolean} [spa.enabled] - Turn on/off the single page application feature (on by default). NOTE: the SPA feature is deprecated and under removal procedure.
95
+ * @property {boolean} [spa.autoStart] - If true, the agent will automatically start the single page application feature. Otherwise, it will be in a deferred state until the `start` API method is called.
96
+ * @property {boolean} [ssl] - If explicitly false, the agent will use HTTP instead of HTTPS. This setting should NOT be used.
97
+ * @property {Object} [user_actions]
98
+ * @property {boolean} [user_actions.enabled] - Must be true to allow UserAction events to be captured.
99
+ * @property {Array<string>} [user_actions.elementAttributes] - List of HTML Element properties to be captured with UserAction events' target elements. This may help to identify the source element being interacted with in the UI.
100
+ */
101
+
21
102
  const nrMask = '[data-nr-mask]';
22
103
  const model = () => {
23
104
  const hiddenState = {
@@ -82,8 +163,7 @@ const model = () => {
82
163
  },
83
164
  logging: {
84
165
  enabled: true,
85
- autoStart: true,
86
- level: _constants2.LOG_LEVELS.INFO
166
+ autoStart: true
87
167
  },
88
168
  metrics: {
89
169
  enabled: true,
@@ -116,7 +196,6 @@ const model = () => {
116
196
  },
117
197
  capture_detail: true,
118
198
  resources: {
119
- // whether to run this subfeature or not in the generic_events feature. false by default through experimental phase, but flipped to true once GA'd
120
199
  get enabled() {
121
200
  return hiddenState.feature_flags.includes(_constants.FEATURE_FLAGS.RESOURCES) || hiddenState.experimental.resources;
122
201
  },
@@ -124,41 +203,30 @@ const model = () => {
124
203
  hiddenState.experimental.resources = val;
125
204
  },
126
205
  asset_types: [],
127
- // MDN types to collect, empty array will collect all types
128
206
  first_party_domains: [],
129
- // when included, will decorate the resource as first party if matching
130
- ignore_newrelic: true // ignore capturing internal agent scripts and harvest calls
207
+ ignore_newrelic: true
131
208
  }
132
209
  },
133
210
  privacy: {
134
211
  cookies_enabled: true
135
212
  },
136
- // *cli - per discussion, default should be true
137
213
  proxy: {
138
214
  assets: undefined,
139
- // if this value is set, it will be used to overwrite the webpack asset path used to fetch assets
140
- beacon: undefined // likewise for the url to which we send analytics
215
+ beacon: undefined
141
216
  },
142
217
  session: {
143
- expiresMs: _constants3.DEFAULT_EXPIRES_MS,
144
- inactiveMs: _constants3.DEFAULT_INACTIVE_MS
218
+ expiresMs: _constants2.DEFAULT_EXPIRES_MS,
219
+ inactiveMs: _constants2.DEFAULT_INACTIVE_MS
145
220
  },
146
221
  session_replay: {
147
- // feature settings
148
222
  autoStart: true,
149
223
  enabled: false,
150
224
  preload: false,
151
- // if true, enables the agent to load rrweb immediately instead of waiting to do so after the window.load event
152
225
  sampling_rate: 10,
153
- // float from 0 - 100
154
226
  error_sampling_rate: 100,
155
- // float from 0 - 100
156
227
  collect_fonts: false,
157
- // serialize fonts for collection without public asset url, this is currently broken in RRWeb -- https://github.com/rrweb-io/rrweb/issues/1304. When fixed, revisit with test cases
158
228
  inline_images: false,
159
- // serialize images for collection without public asset url -- right now this is only useful for testing as it easily generates payloads too large to be harvested
160
229
  fix_stylesheets: true,
161
- // fetch missing stylesheet resources for inlining
162
230
  // recording config settings
163
231
  mask_all_inputs: true,
164
232
  // this has a getter/setter to facilitate validation of the selectors
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.282.0";
20
+ const VERSION = exports.VERSION = "1.283.0";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.282.0";
20
+ const VERSION = exports.VERSION = "1.283.0";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -18,6 +18,7 @@ var _handle = require("../event-emitter/handle");
18
18
  var _constants2 = require("../../features/metrics/constants");
19
19
  var _features = require("../../loaders/features/features");
20
20
  var _eventListenerOpts = require("../event-listener/event-listener-opts");
21
+ var _constants3 = require("../../features/logging/constants");
21
22
  /**
22
23
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
23
24
  * SPDX-License-Identifier: Apache-2.0
@@ -34,6 +35,7 @@ const model = {
34
35
  sessionReplaySentFirstChunk: false,
35
36
  sessionTraceMode: _constants.MODE.OFF,
36
37
  traceHarvestStarted: false,
38
+ loggingMode: _constants3.LOGGING_MODE.OFF,
37
39
  serverTimeDiff: null,
38
40
  // set by TimeKeeper; "undefined" value will not be stringified and stored but "null" will
39
41
  custom: {}
@@ -16,6 +16,9 @@ var _utils = require("../shared/utils");
16
16
  var _traverse = require("../../../common/util/traverse");
17
17
  var _agentConstants = require("../../../common/constants/agent-constants");
18
18
  var _features = require("../../../loaders/features/features");
19
+ var _constants3 = require("../../../common/session/constants");
20
+ var _constants4 = require("../../session_replay/constants");
21
+ var _featureGates = require("../../utils/feature-gates");
19
22
  /**
20
23
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
21
24
  * SPDX-License-Identifier: Apache-2.0
@@ -25,8 +28,30 @@ class Aggregate extends _aggregateBase.AggregateBase {
25
28
  static featureName = _constants2.FEATURE_NAME;
26
29
  constructor(agentRef) {
27
30
  super(agentRef, _constants2.FEATURE_NAME);
31
+ this.isSessionTrackingEnabled = (0, _featureGates.canEnableSessionTracking)(this.agentIdentifier) && this.agentRef.runtime.session;
32
+
33
+ // The SessionEntity class can emit a message indicating the session was cleared and reset (expiry, inactivity). This feature must abort and never resume if that occurs.
34
+ this.ee.on(_constants3.SESSION_EVENTS.RESET, () => {
35
+ this.abort(_constants4.ABORT_REASONS.RESET);
36
+ });
37
+ this.ee.on(_constants3.SESSION_EVENTS.UPDATE, (type, data) => {
38
+ if (this.blocked || type !== _constants3.SESSION_EVENT_TYPES.CROSS_TAB) return;
39
+ if (this.mode !== _constants2.LOGGING_MODE.OFF && data.loggingMode === _constants2.LOGGING_MODE.OFF) this.abort(_constants4.ABORT_REASONS.CROSS_TAB);else this.mode = data.loggingMode;
40
+ });
28
41
  this.harvestOpts.raw = true;
29
- this.waitForFlags([]).then(() => {
42
+ this.waitForFlags(['log']).then(([loggingMode]) => {
43
+ const session = this.agentRef.runtime.session ?? {};
44
+ if (this.loggingMode === _constants2.LOGGING_MODE.OFF || session.isNew && loggingMode === _constants2.LOGGING_MODE.OFF) {
45
+ this.blocked = true;
46
+ this.deregisterDrain();
47
+ return;
48
+ }
49
+ if (session.isNew || !this.isSessionTrackingEnabled) {
50
+ this.updateLoggingMode(loggingMode);
51
+ } else {
52
+ this.loggingMode = session.state.loggingMode;
53
+ }
54
+
30
55
  /** emitted by instrument class (wrapped loggers) or the api methods directly */
31
56
  (0, _registerHandler.registerHandler)(_constants2.LOGGING_EVENT_EMITTER_CHANNEL, this.handleLog.bind(this), this.featureName, this.ee);
32
57
  this.drain();
@@ -34,11 +59,18 @@ class Aggregate extends _aggregateBase.AggregateBase {
34
59
  agentRef.runtime.harvester.triggerHarvestFor(this);
35
60
  });
36
61
  }
62
+ updateLoggingMode(loggingMode) {
63
+ this.loggingMode = loggingMode;
64
+ this.syncWithSessionManager({
65
+ loggingMode: this.loggingMode
66
+ });
67
+ }
37
68
  handleLog(timestamp, message, attributes = {}, level = _constants2.LOG_LEVELS.INFO) {
38
- if (this.blocked) return;
69
+ if (this.blocked || !this.loggingMode) return;
39
70
  if (!attributes || typeof attributes !== 'object') attributes = {};
40
71
  if (typeof level === 'string') level = level.toUpperCase();
41
72
  if (!(0, _utils.isValidLogLevel)(level)) return (0, _console.warn)(30, level);
73
+ if (this.loggingMode < (_constants2.LOGGING_MODE[level] || Infinity)) return;
42
74
  try {
43
75
  if (typeof message !== 'string') {
44
76
  const stringified = (0, _stringify.stringify)(message);
@@ -100,7 +132,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
100
132
  // The following 3 attributes are evaluated and dropped at ingest processing time and do not get stored on NRDB:
101
133
  'instrumentation.provider': 'browser',
102
134
  'instrumentation.version': this.agentRef.runtime.version,
103
- 'instrumentation.name': this.agentRef.runtime.loaderType
135
+ 'instrumentation.name': this.agentRef.runtime.loaderType,
136
+ // Custom attributes
137
+ ...this.agentRef.info.jsAttributes
104
138
  }
105
139
  },
106
140
  /** logs section contains individual unique log entries */
@@ -112,5 +146,20 @@ class Aggregate extends _aggregateBase.AggregateBase {
112
146
  browser_monitoring_key: this.agentRef.info.licenseKey
113
147
  };
114
148
  }
149
+
150
+ /** Abort the feature, once aborted it will not resume */
151
+ abort(reason = {}) {
152
+ (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ["Logging/Abort/".concat(reason.sm)], undefined, _features.FEATURE_NAMES.logging, this.ee);
153
+ this.blocked = true;
154
+ this.events.clear();
155
+ this.events.clearSave();
156
+ this.updateLoggingMode(_constants2.LOGGING_MODE.OFF);
157
+ this.deregisterDrain();
158
+ }
159
+ syncWithSessionManager(state = {}) {
160
+ if (this.isSessionTrackingEnabled) {
161
+ this.agentRef.runtime.session.write(state);
162
+ }
163
+ }
115
164
  }
116
165
  exports.Aggregate = Aggregate;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.LOG_LEVELS = exports.LOGGING_EVENT_EMITTER_CHANNEL = exports.FEATURE_NAME = void 0;
6
+ exports.LOG_LEVELS = exports.LOGGING_MODE = exports.LOGGING_EVENT_EMITTER_CHANNEL = exports.FEATURE_NAME = void 0;
7
7
  var _features = require("../../loaders/features/features");
8
8
  /**
9
9
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
@@ -17,5 +17,13 @@ const LOG_LEVELS = exports.LOG_LEVELS = {
17
17
  DEBUG: 'DEBUG',
18
18
  TRACE: 'TRACE'
19
19
  };
20
+ const LOGGING_MODE = exports.LOGGING_MODE = {
21
+ OFF: 0,
22
+ ERROR: 1,
23
+ WARN: 2,
24
+ INFO: 3,
25
+ DEBUG: 4,
26
+ TRACE: 5
27
+ };
20
28
  const LOGGING_EVENT_EMITTER_CHANNEL = exports.LOGGING_EVENT_EMITTER_CHANNEL = 'log';
21
29
  const FEATURE_NAME = exports.FEATURE_NAME = _features.FEATURE_NAMES.logging;
@@ -7,6 +7,8 @@ exports.Logging = exports.Instrument = void 0;
7
7
  var _instrumentBase = require("../../utils/instrument-base");
8
8
  var _constants = require("../constants");
9
9
  var _utils = require("../shared/utils");
10
+ var _wrapLogger = require("../../../common/wrap/wrap-logger");
11
+ var _runtime = require("../../../common/constants/runtime");
10
12
  /**
11
13
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
12
14
  * SPDX-License-Identifier: Apache-2.0
@@ -17,6 +19,24 @@ class Instrument extends _instrumentBase.InstrumentBase {
17
19
  constructor(agentRef, auto = true) {
18
20
  super(agentRef, _constants.FEATURE_NAME, auto);
19
21
  const instanceEE = this.ee;
22
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'log', {
23
+ level: 'info'
24
+ });
25
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'error', {
26
+ level: 'error'
27
+ });
28
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'warn', {
29
+ level: 'warn'
30
+ });
31
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'info', {
32
+ level: 'info'
33
+ });
34
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'debug', {
35
+ level: 'debug'
36
+ });
37
+ (0, _wrapLogger.wrapLogger)(instanceEE, _runtime.globalScope.console, 'trace', {
38
+ level: 'trace'
39
+ });
20
40
  /** emitted by wrap-logger function */
21
41
  this.ee.on('wrap-logger-end', function handleLog([message]) {
22
42
  const {
@@ -22,6 +22,7 @@ var _now = require("../../../common/timing/now");
22
22
  var _utils = require("../shared/utils");
23
23
  var _agentConstants = require("../../../common/constants/agent-constants");
24
24
  var _cleanUrl = require("../../../common/url/clean-url");
25
+ var _featureGates = require("../../utils/feature-gates");
25
26
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
26
27
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
27
28
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
@@ -52,6 +53,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
52
53
  this.recorder = args?.recorder;
53
54
  this.errorNoticed = args?.errorNoticed || false;
54
55
  this.harvestOpts.raw = true;
56
+ this.isSessionTrackingEnabled = (0, _featureGates.canEnableSessionTracking)(this.agentIdentifier) && this.agentRef.runtime.session;
55
57
  (0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['Config/SessionReplay/Enabled'], undefined, _features.FEATURE_NAMES.metrics, this.ee);
56
58
 
57
59
  // The SessionEntity class can emit a message indicating the session was cleared and reset (expiry, inactivity). This feature must abort and never resume if that occurs.
@@ -74,7 +76,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
74
76
  this.ee.on(_constants3.SESSION_EVENTS.UPDATE, (type, data) => {
75
77
  if (!this.recorder || !this.initialized || this.blocked || type !== _constants3.SESSION_EVENT_TYPES.CROSS_TAB) return;
76
78
  if (this.mode !== _constants3.MODE.OFF && data.sessionReplayMode === _constants3.MODE.OFF) this.abort(_constants.ABORT_REASONS.CROSS_TAB);
77
- this.mode = data.sessionReplay;
79
+ this.mode = data.sessionReplayMode;
78
80
  });
79
81
  (0, _registerHandler.registerHandler)(_constants.SR_EVENT_EMITTER_TYPES.PAUSE, () => {
80
82
  this.forceStop(this.mode === _constants3.MODE.FULL);
@@ -148,7 +150,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
148
150
 
149
151
  /**
150
152
  * Evaluate entitlements and sampling before starting feature mechanics, importing and configuring recording library, and setting storage state
151
- * @param {boolean} entitlements - the true/false state of the "sr" flag from RUM response
153
+ * @param {boolean} srMode - the true/false state of the "sr" flag (aka. entitlements) from RUM response
152
154
  * @param {boolean} ignoreSession - whether to force the method to ignore the session state and use just the sample flags
153
155
  * @returns {void}
154
156
  */
@@ -396,7 +398,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
396
398
  while (this.recorder?.getEvents().events.length) this.recorder?.clearBuffer?.();
397
399
  }
398
400
  syncWithSessionManager(state = {}) {
399
- this.agentRef.runtime.session.write(state);
401
+ if (this.isSessionTrackingEnabled) {
402
+ this.agentRef.runtime.session.write(state);
403
+ }
400
404
  }
401
405
  }
402
406
  exports.Aggregate = Aggregate;
@@ -78,6 +78,9 @@ class AggregateBase extends _featureBase.FeatureBase {
78
78
  (0, _drain.drain)(this.agentIdentifier, this.featureName);
79
79
  this.drained = true;
80
80
  }
81
+ preHarvestChecks(opts) {
82
+ return !this.blocked;
83
+ }
81
84
 
82
85
  /**
83
86
  * Return harvest payload. A "serializer" function can be defined on a derived class to format the payload.
@@ -28,13 +28,24 @@ var _runtime = require("../common/constants/runtime");
28
28
 
29
29
  // common files
30
30
 
31
+ /**
32
+ * @typedef {Object} AgentOptions
33
+ * @property {import('../common/config/info').Info} info - An object containing operational info needed by the agent. It's strongly encouraged to define this.
34
+ * @property {import('../common/config/init').Init} [init] - An object containing initialization configurations for the agent.
35
+ * @property {Object} [loader_config] - An object containing configuration primarily passed by APM injection. This is not recommended for use if not already provided by installation.
36
+ * @property {Object} [runtime] - An object containing runtime references by the agent. This is not recommended for use.
37
+ * @property {Array<Object>} [features] - A list of feature modules to include in the agent. This is only necessary when using the `Agent` class strictly.
38
+ * @property {boolean} [exposed] - Whether the agent should expose its API to (be affected by) the global `newrelic` object.
39
+ * @property {string} [loaderType] - The type of loader that is initializing the agent. It's recommended to allow the default.
40
+ */
41
+
31
42
  /**
32
43
  * A flexible class that may be used to compose an agent from a select subset of feature modules. In applications
33
44
  * sensitive to network load, this may result in smaller builds with slightly lower performance impact.
34
45
  */
35
46
  class Agent extends _agentBase.AgentBase {
36
47
  /**
37
- * @param {Object} options Options to initialize agent with
48
+ * @param {AgentOptions} options
38
49
  */
39
50
  constructor(options) {
40
51
  super();
@@ -26,9 +26,12 @@ var _instrument11 = require("../features/soft_navigations/instrument");
26
26
  * The BrowserAgent class is the most convenient and reliable option for most use cases.
27
27
  */
28
28
  class BrowserAgent extends _agent.Agent {
29
- constructor(args) {
29
+ /**
30
+ * @param {import('./agent').AgentOptions} options
31
+ */
32
+ constructor(options) {
30
33
  super({
31
- ...args,
34
+ ...options,
32
35
  features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument3.Instrument, _instrument4.Instrument, _instrument7.Instrument, _instrument11.Instrument, _instrument8.Instrument, _instrument9.Instrument, _instrument10.Instrument],
33
36
  loaderType: 'browser-agent'
34
37
  });
@@ -26,7 +26,7 @@ const nonAutoFeatures = [_features.FEATURE_NAMES.jserrors, _features.FEATURE_NAM
26
26
  */
27
27
  class MicroAgent extends _microAgentBase.MicroAgentBase {
28
28
  /**
29
- * @param {Object} options - Specifies features and runtime configuration,
29
+ * @param {import('./agent').AgentOptions} options
30
30
  */
31
31
  constructor(options) {
32
32
  super();
@@ -4,6 +4,28 @@
4
4
  */
5
5
  import { defaults as nrDefaults, getNREUMInitializedAgent } from '../window/nreum';
6
6
  import { getModeledObject } from './configurable';
7
+
8
+ /**
9
+ * @typedef {Object} Info
10
+ * @property {string} [beacon]
11
+ * @property {string} [errorBeacon] - Base URL endpoint for all data harvested by the agent. Proxies should be defined in the init instead.
12
+ * @property {string} licenseKey - New Relic license key provided by the website in user account.
13
+ * @property {string} applicationID - New Relic application ID provided when creating a browser entity in the UI.
14
+ * @property {number} [sa]
15
+ * @property {number} [queueTime]
16
+ * @property {number} [applicationTime]
17
+ * @property {string} [ttGuid]
18
+ * @property {string} [user]
19
+ * @property {string} [account]
20
+ * @property {string} [product]
21
+ * @property {string} [extra]
22
+ * @property {Object} [jsAttributes] - Custom attributes that are added to majority of agent's payloads. The `setCustomAttribute` API method affects this.
23
+ * @property {string} [userAttributes]
24
+ * @property {string} [atts]
25
+ * @property {string} [transactionName]
26
+ * @property {string} [tNamePlain]
27
+ */
28
+
7
29
  const model = {
8
30
  // preset defaults
9
31
  beacon: nrDefaults.beacon,