@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
@@ -3,12 +3,94 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { FEATURE_FLAGS } from '../../features/generic_events/constants';
6
- import { LOG_LEVELS } from '../../features/logging/constants';
7
6
  import { isValidSelector } from '../dom/query-selector';
8
7
  import { DEFAULT_EXPIRES_MS, DEFAULT_INACTIVE_MS } from '../session/constants';
9
8
  import { warn } from '../util/console';
10
9
  import { getNREUMInitializedAgent } from '../window/nreum';
11
10
  import { getModeledObject } from './configurable';
11
+
12
+ /**
13
+ * @typedef {Object} Init
14
+ * @property {Object} [ajax]
15
+ * @property {Array<string>} [ajax.deny_list] - List of domain URLs to be excluded from AjaxRequest collection.
16
+ * @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.
17
+ * @property {boolean} [ajax.enabled] - Turn on/off the ajax feature (on by default).
18
+ * @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.
19
+ * @property {Object} [distributed_tracing]
20
+ * @property {boolean} [distributed_tracing.enabled] - If true, distributed tracing headers will be added to outgoing requests. Requires ajax feature to be running.
21
+ * @property {boolean} [distributed_tracing.exclude_newrelic_header]
22
+ * @property {boolean} [distributed_tracing.cors_use_newrelic_header]
23
+ * @property {boolean} [distributed_tracing.cors_use_tracecontext_headers]
24
+ * @property {Array<string>} [distributed_tracing.allowed_origins]
25
+ * @property {Array<string>} [feature_flags] - An array of feature flags to enable experimental features.
26
+ * @property {Object} [generic_events]
27
+ * @property {boolean} [generic_events.enabled] - Turn on/off the generic events feature (on by default). This is required for `PageAction`, `UserAction`, and `BrowserPerformance` events.
28
+ * @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.
29
+ * @property {Object} [harvest]
30
+ * @property {number} [harvest.interval] - The interval in seconds at which the agent will send out data. It's not recommended to change this value.
31
+ * @property {Object} [jserrors]
32
+ * @property {boolean} [jserrors.enabled] - Turn on/off the jserrors feature (on by default).
33
+ * @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.
34
+ * @property {Object} [logging]
35
+ * @property {boolean} [logging.enabled] - Turn on/off the logging feature (on by default).
36
+ * @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.
37
+ * @property {Object} [metrics]
38
+ * @property {boolean} [metrics.enabled] - Turn on/off the metrics feature (on by default).
39
+ * @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.
40
+ * @property {Array<Object>} [obfuscate] - Array of regexp and corresponding replacement patterns for obfuscating data.
41
+ * @property {Object} [page_action]
42
+ * @property {boolean} [page_action.enabled] - Must be true to allow PageAction events to be captured.
43
+ * @property {Object} [page_view_event]
44
+ * @property {boolean} [page_view_event.enabled] - This setting is ignored! PageViewEvent is always enabled by force.
45
+ * @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.
46
+ * @property {Object} [page_view_timing]
47
+ * @property {boolean} [page_view_timing.enabled] - Turn on/off the page view timing feature (on by default).
48
+ * @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.
49
+ * @property {Object} [performance]
50
+ * @property {boolean} [performance.capture_marks] - If true, the agent will capture PerformanceMark events.
51
+ * @property {boolean} [performance.capture_measures] - If true, the agent will capture PerformanceMeasure events.
52
+ * @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`.
53
+ * @property {Object} [performance.resources]
54
+ * @property {boolean} [performance.resources.enabled] - If true, the agent will capture PerformanceResourceTiming entries.
55
+ * @property {Array<string>} [performance.resources.asset_types] - Array of `initiatorType` strings to filter the desired ResourceTiming entries. By default, all resource types are captured.
56
+ * @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.
57
+ * @property {boolean} [performance.resources.ignore_newrelic] - When true (default), resource entries associated with New Relic domains will be ignored.
58
+ * @property {Object} [privacy]
59
+ * @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.
60
+ * @property {Object} [proxy]
61
+ * @property {string} [proxy.assets] - Set value will be used to overwrite the webpack asset path used to fetch agent assets.
62
+ * @property {string} [proxy.beacon] - Set value will be used to overwrite the endpoint URL to which we send analytics.
63
+ * @property {Object} [session]
64
+ * @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.
65
+ * @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.
66
+ * @property {Object} [session_replay]
67
+ * @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.
68
+ * @property {boolean} [session_replay.enabled] - Turn on/off the session replay feature (off by default).
69
+ * @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.
70
+ * @property {number} [session_replay.sampling_rate] - This setting is deprecated and ineffective. Sampling is controlled in New Relic by server-side configuration.
71
+ * @property {number} [session_replay.error_sampling_rate] - This setting is deprecated and ineffective.
72
+ * @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.
73
+ * @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.
74
+ * @property {boolean} [session_replay.fix_stylesheets] - When true, tries to fetch any missing stylesheets again to inline in replayer.
75
+ * @property {boolean} [session_replay.mask_all_inputs] - If true, all input content will be masked with asterisks.
76
+ * @property {string} [session_replay.mask_text_selector] - Set value should be in CSS selector syntax and is used to identify matching elements to mask.
77
+ * @property {string} [session_replay.block_selector] - Set value should be in CSS selector syntax and is used to identify matching elements to block.
78
+ * @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.
79
+ * @property {Object} [session_trace]
80
+ * @property {boolean} [session_trace.enabled] - Turn on/off the session trace feature (on by default).
81
+ * @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.
82
+ * @property {Object} [soft_navigations]
83
+ * @property {boolean} [soft_navigations.enabled] - Turn on/off the soft navigations feature (on by default).
84
+ * @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.
85
+ * @property {Object} [spa]
86
+ * @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.
87
+ * @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.
88
+ * @property {boolean} [ssl] - If explicitly false, the agent will use HTTP instead of HTTPS. This setting should NOT be used.
89
+ * @property {Object} [user_actions]
90
+ * @property {boolean} [user_actions.enabled] - Must be true to allow UserAction events to be captured.
91
+ * @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.
92
+ */
93
+
12
94
  const nrMask = '[data-nr-mask]';
13
95
  const model = () => {
14
96
  const hiddenState = {
@@ -73,8 +155,7 @@ const model = () => {
73
155
  },
74
156
  logging: {
75
157
  enabled: true,
76
- autoStart: true,
77
- level: LOG_LEVELS.INFO
158
+ autoStart: true
78
159
  },
79
160
  metrics: {
80
161
  enabled: true,
@@ -107,7 +188,6 @@ const model = () => {
107
188
  },
108
189
  capture_detail: true,
109
190
  resources: {
110
- // 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
111
191
  get enabled() {
112
192
  return hiddenState.feature_flags.includes(FEATURE_FLAGS.RESOURCES) || hiddenState.experimental.resources;
113
193
  },
@@ -115,41 +195,30 @@ const model = () => {
115
195
  hiddenState.experimental.resources = val;
116
196
  },
117
197
  asset_types: [],
118
- // MDN types to collect, empty array will collect all types
119
198
  first_party_domains: [],
120
- // when included, will decorate the resource as first party if matching
121
- ignore_newrelic: true // ignore capturing internal agent scripts and harvest calls
199
+ ignore_newrelic: true
122
200
  }
123
201
  },
124
202
  privacy: {
125
203
  cookies_enabled: true
126
204
  },
127
- // *cli - per discussion, default should be true
128
205
  proxy: {
129
206
  assets: undefined,
130
- // if this value is set, it will be used to overwrite the webpack asset path used to fetch assets
131
- beacon: undefined // likewise for the url to which we send analytics
207
+ beacon: undefined
132
208
  },
133
209
  session: {
134
210
  expiresMs: DEFAULT_EXPIRES_MS,
135
211
  inactiveMs: DEFAULT_INACTIVE_MS
136
212
  },
137
213
  session_replay: {
138
- // feature settings
139
214
  autoStart: true,
140
215
  enabled: false,
141
216
  preload: false,
142
- // if true, enables the agent to load rrweb immediately instead of waiting to do so after the window.load event
143
217
  sampling_rate: 10,
144
- // float from 0 - 100
145
218
  error_sampling_rate: 100,
146
- // float from 0 - 100
147
219
  collect_fonts: false,
148
- // 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
149
220
  inline_images: false,
150
- // 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
151
221
  fix_stylesheets: true,
152
- // fetch missing stylesheet resources for inlining
153
222
  // recording config settings
154
223
  mask_all_inputs: true,
155
224
  // this has a getter/setter to facilitate validation of the selectors
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.282.0";
14
+ export const VERSION = "1.283.0";
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.282.0";
14
+ export const VERSION = "1.283.0";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -16,6 +16,7 @@ import { handle } from '../event-emitter/handle';
16
16
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants';
17
17
  import { FEATURE_NAMES } from '../../loaders/features/features';
18
18
  import { windowAddEventListener } from '../event-listener/event-listener-opts';
19
+ import { LOGGING_MODE } from '../../features/logging/constants';
19
20
 
20
21
  // this is what can be stored in local storage (not enforced but probably should be)
21
22
  // these values should sync between local storage and the parent class props
@@ -28,6 +29,7 @@ const model = {
28
29
  sessionReplaySentFirstChunk: false,
29
30
  sessionTraceMode: MODE.OFF,
30
31
  traceHarvestStarted: false,
32
+ loggingMode: LOGGING_MODE.OFF,
31
33
  serverTimeDiff: null,
32
34
  // set by TimeKeeper; "undefined" value will not be stringified and stored but "null" will
33
35
  custom: {}
@@ -8,18 +8,43 @@ import { warn } from '../../../common/util/console';
8
8
  import { stringify } from '../../../common/util/stringify';
9
9
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants';
10
10
  import { AggregateBase } from '../../utils/aggregate-base';
11
- import { FEATURE_NAME, LOGGING_EVENT_EMITTER_CHANNEL, LOG_LEVELS } from '../constants';
11
+ import { FEATURE_NAME, LOGGING_EVENT_EMITTER_CHANNEL, LOG_LEVELS, LOGGING_MODE } from '../constants';
12
12
  import { Log } from '../shared/log';
13
13
  import { isValidLogLevel } from '../shared/utils';
14
14
  import { applyFnToProps } from '../../../common/util/traverse';
15
15
  import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants';
16
16
  import { FEATURE_NAMES } from '../../../loaders/features/features';
17
+ import { SESSION_EVENT_TYPES, SESSION_EVENTS } from '../../../common/session/constants';
18
+ import { ABORT_REASONS } from '../../session_replay/constants';
19
+ import { canEnableSessionTracking } from '../../utils/feature-gates';
17
20
  export class Aggregate extends AggregateBase {
18
21
  static featureName = FEATURE_NAME;
19
22
  constructor(agentRef) {
20
23
  super(agentRef, FEATURE_NAME);
24
+ this.isSessionTrackingEnabled = canEnableSessionTracking(this.agentIdentifier) && this.agentRef.runtime.session;
25
+
26
+ // 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.
27
+ this.ee.on(SESSION_EVENTS.RESET, () => {
28
+ this.abort(ABORT_REASONS.RESET);
29
+ });
30
+ this.ee.on(SESSION_EVENTS.UPDATE, (type, data) => {
31
+ if (this.blocked || type !== SESSION_EVENT_TYPES.CROSS_TAB) return;
32
+ if (this.mode !== LOGGING_MODE.OFF && data.loggingMode === LOGGING_MODE.OFF) this.abort(ABORT_REASONS.CROSS_TAB);else this.mode = data.loggingMode;
33
+ });
21
34
  this.harvestOpts.raw = true;
22
- this.waitForFlags([]).then(() => {
35
+ this.waitForFlags(['log']).then(([loggingMode]) => {
36
+ const session = this.agentRef.runtime.session ?? {};
37
+ if (this.loggingMode === LOGGING_MODE.OFF || session.isNew && loggingMode === LOGGING_MODE.OFF) {
38
+ this.blocked = true;
39
+ this.deregisterDrain();
40
+ return;
41
+ }
42
+ if (session.isNew || !this.isSessionTrackingEnabled) {
43
+ this.updateLoggingMode(loggingMode);
44
+ } else {
45
+ this.loggingMode = session.state.loggingMode;
46
+ }
47
+
23
48
  /** emitted by instrument class (wrapped loggers) or the api methods directly */
24
49
  registerHandler(LOGGING_EVENT_EMITTER_CHANNEL, this.handleLog.bind(this), this.featureName, this.ee);
25
50
  this.drain();
@@ -27,11 +52,18 @@ export class Aggregate extends AggregateBase {
27
52
  agentRef.runtime.harvester.triggerHarvestFor(this);
28
53
  });
29
54
  }
55
+ updateLoggingMode(loggingMode) {
56
+ this.loggingMode = loggingMode;
57
+ this.syncWithSessionManager({
58
+ loggingMode: this.loggingMode
59
+ });
60
+ }
30
61
  handleLog(timestamp, message, attributes = {}, level = LOG_LEVELS.INFO) {
31
- if (this.blocked) return;
62
+ if (this.blocked || !this.loggingMode) return;
32
63
  if (!attributes || typeof attributes !== 'object') attributes = {};
33
64
  if (typeof level === 'string') level = level.toUpperCase();
34
65
  if (!isValidLogLevel(level)) return warn(30, level);
66
+ if (this.loggingMode < (LOGGING_MODE[level] || Infinity)) return;
35
67
  try {
36
68
  if (typeof message !== 'string') {
37
69
  const stringified = stringify(message);
@@ -93,7 +125,9 @@ export class Aggregate extends AggregateBase {
93
125
  // The following 3 attributes are evaluated and dropped at ingest processing time and do not get stored on NRDB:
94
126
  'instrumentation.provider': 'browser',
95
127
  'instrumentation.version': this.agentRef.runtime.version,
96
- 'instrumentation.name': this.agentRef.runtime.loaderType
128
+ 'instrumentation.name': this.agentRef.runtime.loaderType,
129
+ // Custom attributes
130
+ ...this.agentRef.info.jsAttributes
97
131
  }
98
132
  },
99
133
  /** logs section contains individual unique log entries */
@@ -105,4 +139,19 @@ export class Aggregate extends AggregateBase {
105
139
  browser_monitoring_key: this.agentRef.info.licenseKey
106
140
  };
107
141
  }
142
+
143
+ /** Abort the feature, once aborted it will not resume */
144
+ abort(reason = {}) {
145
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ["Logging/Abort/".concat(reason.sm)], undefined, FEATURE_NAMES.logging, this.ee);
146
+ this.blocked = true;
147
+ this.events.clear();
148
+ this.events.clearSave();
149
+ this.updateLoggingMode(LOGGING_MODE.OFF);
150
+ this.deregisterDrain();
151
+ }
152
+ syncWithSessionManager(state = {}) {
153
+ if (this.isSessionTrackingEnabled) {
154
+ this.agentRef.runtime.session.write(state);
155
+ }
156
+ }
108
157
  }
@@ -10,5 +10,13 @@ export const LOG_LEVELS = {
10
10
  DEBUG: 'DEBUG',
11
11
  TRACE: 'TRACE'
12
12
  };
13
+ export const LOGGING_MODE = {
14
+ OFF: 0,
15
+ ERROR: 1,
16
+ WARN: 2,
17
+ INFO: 3,
18
+ DEBUG: 4,
19
+ TRACE: 5
20
+ };
13
21
  export const LOGGING_EVENT_EMITTER_CHANNEL = 'log';
14
22
  export const FEATURE_NAME = FEATURE_NAMES.logging;
@@ -5,11 +5,31 @@
5
5
  import { InstrumentBase } from '../../utils/instrument-base';
6
6
  import { FEATURE_NAME } from '../constants';
7
7
  import { bufferLog } from '../shared/utils';
8
+ import { wrapLogger } from '../../../common/wrap/wrap-logger';
9
+ import { globalScope } from '../../../common/constants/runtime';
8
10
  export class Instrument extends InstrumentBase {
9
11
  static featureName = FEATURE_NAME;
10
12
  constructor(agentRef, auto = true) {
11
13
  super(agentRef, FEATURE_NAME, auto);
12
14
  const instanceEE = this.ee;
15
+ wrapLogger(instanceEE, globalScope.console, 'log', {
16
+ level: 'info'
17
+ });
18
+ wrapLogger(instanceEE, globalScope.console, 'error', {
19
+ level: 'error'
20
+ });
21
+ wrapLogger(instanceEE, globalScope.console, 'warn', {
22
+ level: 'warn'
23
+ });
24
+ wrapLogger(instanceEE, globalScope.console, 'info', {
25
+ level: 'info'
26
+ });
27
+ wrapLogger(instanceEE, globalScope.console, 'debug', {
28
+ level: 'debug'
29
+ });
30
+ wrapLogger(instanceEE, globalScope.console, 'trace', {
31
+ level: 'trace'
32
+ });
13
33
  /** emitted by wrap-logger function */
14
34
  this.ee.on('wrap-logger-end', function handleLog([message]) {
15
35
  const {
@@ -24,6 +24,7 @@ import { now } from '../../../common/timing/now';
24
24
  import { buildNRMetaNode } from '../shared/utils';
25
25
  import { MAX_PAYLOAD_SIZE } from '../../../common/constants/agent-constants';
26
26
  import { cleanURL } from '../../../common/url/clean-url';
27
+ import { canEnableSessionTracking } from '../../utils/feature-gates';
27
28
  export class Aggregate extends AggregateBase {
28
29
  static featureName = FEATURE_NAME;
29
30
  mode = MODE.OFF;
@@ -47,6 +48,7 @@ export class Aggregate extends AggregateBase {
47
48
  this.recorder = args?.recorder;
48
49
  this.errorNoticed = args?.errorNoticed || false;
49
50
  this.harvestOpts.raw = true;
51
+ this.isSessionTrackingEnabled = canEnableSessionTracking(this.agentIdentifier) && this.agentRef.runtime.session;
50
52
  handle(SUPPORTABILITY_METRIC_CHANNEL, ['Config/SessionReplay/Enabled'], undefined, FEATURE_NAMES.metrics, this.ee);
51
53
 
52
54
  // 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.
@@ -69,7 +71,7 @@ export class Aggregate extends AggregateBase {
69
71
  this.ee.on(SESSION_EVENTS.UPDATE, (type, data) => {
70
72
  if (!this.recorder || !this.initialized || this.blocked || type !== SESSION_EVENT_TYPES.CROSS_TAB) return;
71
73
  if (this.mode !== MODE.OFF && data.sessionReplayMode === MODE.OFF) this.abort(ABORT_REASONS.CROSS_TAB);
72
- this.mode = data.sessionReplay;
74
+ this.mode = data.sessionReplayMode;
73
75
  });
74
76
  registerHandler(SR_EVENT_EMITTER_TYPES.PAUSE, () => {
75
77
  this.forceStop(this.mode === MODE.FULL);
@@ -143,7 +145,7 @@ export class Aggregate extends AggregateBase {
143
145
 
144
146
  /**
145
147
  * Evaluate entitlements and sampling before starting feature mechanics, importing and configuring recording library, and setting storage state
146
- * @param {boolean} entitlements - the true/false state of the "sr" flag from RUM response
148
+ * @param {boolean} srMode - the true/false state of the "sr" flag (aka. entitlements) from RUM response
147
149
  * @param {boolean} ignoreSession - whether to force the method to ignore the session state and use just the sample flags
148
150
  * @returns {void}
149
151
  */
@@ -391,6 +393,8 @@ export class Aggregate extends AggregateBase {
391
393
  while (this.recorder?.getEvents().events.length) this.recorder?.clearBuffer?.();
392
394
  }
393
395
  syncWithSessionManager(state = {}) {
394
- this.agentRef.runtime.session.write(state);
396
+ if (this.isSessionTrackingEnabled) {
397
+ this.agentRef.runtime.session.write(state);
398
+ }
395
399
  }
396
400
  }
@@ -71,6 +71,9 @@ export class AggregateBase extends FeatureBase {
71
71
  drain(this.agentIdentifier, this.featureName);
72
72
  this.drained = true;
73
73
  }
74
+ preHarvestChecks(opts) {
75
+ return !this.blocked;
76
+ }
74
77
 
75
78
  /**
76
79
  * Return harvest payload. A "serializer" function can be defined on a derived class to format the payload.
@@ -19,13 +19,24 @@ import { gosNREUM, setNREUMInitializedAgent } from '../common/window/nreum';
19
19
  import { warn } from '../common/util/console';
20
20
  import { globalScope } from '../common/constants/runtime';
21
21
 
22
+ /**
23
+ * @typedef {Object} AgentOptions
24
+ * @property {import('../common/config/info').Info} info - An object containing operational info needed by the agent. It's strongly encouraged to define this.
25
+ * @property {import('../common/config/init').Init} [init] - An object containing initialization configurations for the agent.
26
+ * @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.
27
+ * @property {Object} [runtime] - An object containing runtime references by the agent. This is not recommended for use.
28
+ * @property {Array<Object>} [features] - A list of feature modules to include in the agent. This is only necessary when using the `Agent` class strictly.
29
+ * @property {boolean} [exposed] - Whether the agent should expose its API to (be affected by) the global `newrelic` object.
30
+ * @property {string} [loaderType] - The type of loader that is initializing the agent. It's recommended to allow the default.
31
+ */
32
+
22
33
  /**
23
34
  * A flexible class that may be used to compose an agent from a select subset of feature modules. In applications
24
35
  * sensitive to network load, this may result in smaller builds with slightly lower performance impact.
25
36
  */
26
37
  export class Agent extends AgentBase {
27
38
  /**
28
- * @param {Object} options Options to initialize agent with
39
+ * @param {AgentOptions} options
29
40
  */
30
41
  constructor(options) {
31
42
  super();
@@ -20,9 +20,12 @@ import { Instrument as InstrumentSoftNav } from '../features/soft_navigations/in
20
20
  * The BrowserAgent class is the most convenient and reliable option for most use cases.
21
21
  */
22
22
  export class BrowserAgent extends Agent {
23
- constructor(args) {
23
+ /**
24
+ * @param {import('./agent').AgentOptions} options
25
+ */
26
+ constructor(options) {
24
27
  super({
25
- ...args,
28
+ ...options,
26
29
  features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentMetrics, InstrumentErrors, InstrumentSpa, InstrumentSoftNav, InstrumentSessionReplay, InstrumentGenericEvents, InstrumentLogs],
27
30
  loaderType: 'browser-agent'
28
31
  });
@@ -21,7 +21,7 @@ const nonAutoFeatures = [FEATURE_NAMES.jserrors, FEATURE_NAMES.genericEvents, FE
21
21
  */
22
22
  export class MicroAgent extends MicroAgentBase {
23
23
  /**
24
- * @param {Object} options - Specifies features and runtime configuration,
24
+ * @param {import('./agent').AgentOptions} options
25
25
  */
26
26
  constructor(options) {
27
27
  super();
@@ -1,4 +1,35 @@
1
1
  export function isValid(id: any): boolean;
2
2
  export function getInfo(id: any): any;
3
3
  export function setInfo(id: any, obj: any): void;
4
+ export type Info = {
5
+ beacon?: string | undefined;
6
+ /**
7
+ * - Base URL endpoint for all data harvested by the agent. Proxies should be defined in the init instead.
8
+ */
9
+ errorBeacon?: string | undefined;
10
+ /**
11
+ * - New Relic license key provided by the website in user account.
12
+ */
13
+ licenseKey: string;
14
+ /**
15
+ * - New Relic application ID provided when creating a browser entity in the UI.
16
+ */
17
+ applicationID: string;
18
+ sa?: number | undefined;
19
+ queueTime?: number | undefined;
20
+ applicationTime?: number | undefined;
21
+ ttGuid?: string | undefined;
22
+ user?: string | undefined;
23
+ account?: string | undefined;
24
+ product?: string | undefined;
25
+ extra?: string | undefined;
26
+ /**
27
+ * - Custom attributes that are added to majority of agent's payloads. The `setCustomAttribute` API method affects this.
28
+ */
29
+ jsAttributes?: Object | undefined;
30
+ userAttributes?: string | undefined;
31
+ atts?: string | undefined;
32
+ transactionName?: string | undefined;
33
+ tNamePlain?: string | undefined;
34
+ };
4
35
  //# sourceMappingURL=info.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../../src/common/config/info.js"],"names":[],"mappings":"AAiCA,0CAOC;AAED,sCAIC;AAED,iDAKC"}
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../../src/common/config/info.js"],"names":[],"mappings":"AAoDA,0CAOC;AAED,sCAIC;AAED,iDAKC;;;;;;;;;;gBA7Da,MAAM;;;;mBACN,MAAM"}