@newrelic/browser-agent 1.289.0 → 1.290.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.
- package/CHANGELOG.md +10 -0
- package/README.md +32 -0
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/features/ajax/instrument/index.js +5 -5
- package/dist/cjs/features/generic_events/aggregate/index.js +1 -0
- package/dist/cjs/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
- package/dist/cjs/features/generic_events/instrument/index.js +15 -5
- package/dist/cjs/features/jserrors/instrument/index.js +15 -5
- package/dist/cjs/features/logging/instrument/index.js +13 -5
- package/dist/cjs/features/metrics/instrument/index.js +5 -5
- package/dist/cjs/features/page_action/instrument/index.js +1 -5
- package/dist/cjs/features/page_view_event/instrument/index.js +8 -6
- package/dist/cjs/features/page_view_timing/instrument/index.js +5 -5
- package/dist/cjs/features/session_replay/instrument/index.js +10 -4
- package/dist/cjs/features/session_trace/instrument/index.js +10 -6
- package/dist/cjs/features/soft_navigations/instrument/index.js +9 -5
- package/dist/cjs/features/spa/instrument/index.js +8 -6
- package/dist/cjs/features/utils/instrument-base.js +27 -23
- package/dist/cjs/loaders/agent-base.js +4 -95
- package/dist/cjs/loaders/agent.js +11 -0
- package/dist/cjs/loaders/api/addPageAction.js +23 -0
- package/dist/cjs/loaders/api/addRelease.js +20 -0
- package/dist/cjs/loaders/api/addToTrace.js +29 -0
- package/dist/cjs/loaders/api/constants.js +32 -0
- package/dist/cjs/loaders/api/finished.js +31 -0
- package/dist/cjs/loaders/api/interaction.js +58 -0
- package/dist/cjs/loaders/api/log.js +26 -0
- package/dist/cjs/loaders/api/noticeError.js +30 -0
- package/dist/cjs/loaders/api/pauseReplay.js +20 -0
- package/dist/cjs/loaders/api/recordCustomEvent.js +21 -0
- package/dist/cjs/loaders/api/recordReplay.js +20 -0
- package/dist/cjs/loaders/api/register.js +182 -0
- package/dist/cjs/loaders/api/setApplicationVersion.js +28 -0
- package/dist/cjs/loaders/api/setCustomAttribute.js +27 -0
- package/dist/cjs/loaders/api/setErrorHandler.js +18 -0
- package/dist/cjs/loaders/api/setPageViewName.js +23 -0
- package/dist/cjs/loaders/api/setUserId.js +28 -0
- package/dist/cjs/loaders/api/sharedHandlers.js +76 -0
- package/dist/cjs/loaders/api/start.js +18 -0
- package/dist/cjs/loaders/api/topLevelCallers.js +29 -0
- package/dist/cjs/loaders/api/wrapLogger.js +26 -0
- package/dist/cjs/loaders/api-base.js +224 -0
- package/dist/cjs/loaders/configure/configure.js +2 -4
- package/dist/cjs/loaders/micro-agent-base.js +3 -134
- package/dist/cjs/loaders/micro-agent.js +34 -6
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/features/ajax/instrument/index.js +3 -3
- package/dist/esm/features/generic_events/aggregate/index.js +1 -0
- package/dist/esm/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
- package/dist/esm/features/generic_events/instrument/index.js +13 -3
- package/dist/esm/features/jserrors/instrument/index.js +13 -3
- package/dist/esm/features/logging/instrument/index.js +11 -3
- package/dist/esm/features/metrics/instrument/index.js +3 -3
- package/dist/esm/features/page_action/instrument/index.js +1 -5
- package/dist/esm/features/page_view_event/instrument/index.js +7 -3
- package/dist/esm/features/page_view_timing/instrument/index.js +3 -3
- package/dist/esm/features/session_replay/instrument/index.js +10 -4
- package/dist/esm/features/session_trace/instrument/index.js +9 -3
- package/dist/esm/features/soft_navigations/instrument/index.js +7 -3
- package/dist/esm/features/spa/instrument/index.js +7 -3
- package/dist/esm/features/utils/instrument-base.js +27 -23
- package/dist/esm/loaders/agent-base.js +4 -95
- package/dist/esm/loaders/agent.js +10 -0
- package/dist/esm/loaders/api/addPageAction.js +15 -0
- package/dist/esm/loaders/api/addRelease.js +13 -0
- package/dist/esm/loaders/api/addToTrace.js +22 -0
- package/dist/esm/loaders/api/constants.js +26 -0
- package/dist/esm/loaders/api/finished.js +24 -0
- package/dist/esm/loaders/api/interaction.js +52 -0
- package/dist/esm/loaders/api/log.js +19 -0
- package/dist/esm/loaders/api/noticeError.js +22 -0
- package/dist/esm/loaders/api/pauseReplay.js +13 -0
- package/dist/esm/loaders/api/recordCustomEvent.js +14 -0
- package/dist/esm/loaders/api/recordReplay.js +13 -0
- package/dist/esm/loaders/api/register.js +175 -0
- package/dist/esm/loaders/api/setApplicationVersion.js +21 -0
- package/dist/esm/loaders/api/setCustomAttribute.js +20 -0
- package/dist/esm/loaders/api/setErrorHandler.js +11 -0
- package/dist/esm/loaders/api/setPageViewName.js +16 -0
- package/dist/esm/loaders/api/setUserId.js +21 -0
- package/dist/esm/loaders/api/sharedHandlers.js +69 -0
- package/dist/esm/loaders/api/start.js +11 -0
- package/dist/esm/loaders/api/topLevelCallers.js +22 -0
- package/dist/esm/loaders/api/wrapLogger.js +19 -0
- package/dist/esm/loaders/api-base.js +217 -0
- package/dist/esm/loaders/configure/configure.js +2 -4
- package/dist/esm/loaders/micro-agent-base.js +3 -134
- package/dist/esm/loaders/micro-agent.js +34 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/features/ajax/instrument/index.d.ts +1 -1
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
- package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts +1 -0
- package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts.map +1 -1
- package/dist/types/features/generic_events/instrument/index.d.ts +1 -1
- package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/logging/instrument/index.d.ts +1 -1
- package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_action/instrument/index.d.ts +0 -1
- package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/instrument/index.d.ts +1 -1
- package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -1
- package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/instrument/index.d.ts +1 -1
- package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -1
- package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/instrument/index.d.ts +1 -1
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts +9 -7
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/agent-base.d.ts +3 -71
- package/dist/types/loaders/agent-base.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/addPageAction.d.ts +3 -0
- package/dist/types/loaders/api/addPageAction.d.ts.map +1 -0
- package/dist/types/loaders/api/addRelease.d.ts +2 -0
- package/dist/types/loaders/api/addRelease.d.ts.map +1 -0
- package/dist/types/loaders/api/addToTrace.d.ts +2 -0
- package/dist/types/loaders/api/addToTrace.d.ts.map +1 -0
- package/dist/types/loaders/api/constants.d.ts +27 -0
- package/dist/types/loaders/api/constants.d.ts.map +1 -0
- package/dist/types/loaders/api/finished.d.ts +2 -0
- package/dist/types/loaders/api/finished.d.ts.map +1 -0
- package/dist/types/loaders/api/interaction.d.ts +2 -0
- package/dist/types/loaders/api/interaction.d.ts.map +1 -0
- package/dist/types/loaders/api/log.d.ts +6 -0
- package/dist/types/loaders/api/log.d.ts.map +1 -0
- package/dist/types/loaders/api/noticeError.d.ts +3 -0
- package/dist/types/loaders/api/noticeError.d.ts.map +1 -0
- package/dist/types/loaders/api/pauseReplay.d.ts +2 -0
- package/dist/types/loaders/api/pauseReplay.d.ts.map +1 -0
- package/dist/types/loaders/api/recordCustomEvent.d.ts +2 -0
- package/dist/types/loaders/api/recordCustomEvent.d.ts.map +1 -0
- package/dist/types/loaders/api/recordReplay.d.ts +2 -0
- package/dist/types/loaders/api/recordReplay.d.ts.map +1 -0
- package/dist/types/loaders/api/register.d.ts +20 -0
- package/dist/types/loaders/api/register.d.ts.map +1 -0
- package/dist/types/loaders/api/setApplicationVersion.d.ts +2 -0
- package/dist/types/loaders/api/setApplicationVersion.d.ts.map +1 -0
- package/dist/types/loaders/api/setCustomAttribute.d.ts +2 -0
- package/dist/types/loaders/api/setCustomAttribute.d.ts.map +1 -0
- package/dist/types/loaders/api/setErrorHandler.d.ts +2 -0
- package/dist/types/loaders/api/setErrorHandler.d.ts.map +1 -0
- package/dist/types/loaders/api/setPageViewName.d.ts +2 -0
- package/dist/types/loaders/api/setPageViewName.d.ts.map +1 -0
- package/dist/types/loaders/api/setUserId.d.ts +2 -0
- package/dist/types/loaders/api/setUserId.d.ts.map +1 -0
- package/dist/types/loaders/api/sharedHandlers.d.ts +20 -0
- package/dist/types/loaders/api/sharedHandlers.d.ts.map +1 -0
- package/dist/types/loaders/api/start.d.ts +2 -0
- package/dist/types/loaders/api/start.d.ts.map +1 -0
- package/dist/types/loaders/api/topLevelCallers.d.ts +2 -0
- package/dist/types/loaders/api/topLevelCallers.d.ts.map +1 -0
- package/dist/types/loaders/api/wrapLogger.d.ts +2 -0
- package/dist/types/loaders/api/wrapLogger.d.ts.map +1 -0
- package/dist/types/loaders/api-base.d.ts +169 -0
- package/dist/types/loaders/api-base.d.ts.map +1 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/micro-agent-base.d.ts +2 -95
- package/dist/types/loaders/micro-agent-base.d.ts.map +1 -1
- package/dist/types/loaders/micro-agent.d.ts +1 -1
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/features/ajax/instrument/index.js +3 -3
- package/src/features/generic_events/aggregate/index.js +1 -0
- package/src/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
- package/src/features/generic_events/instrument/index.js +13 -3
- package/src/features/jserrors/instrument/index.js +13 -3
- package/src/features/logging/instrument/index.js +11 -3
- package/src/features/metrics/instrument/index.js +3 -3
- package/src/features/page_action/instrument/index.js +1 -3
- package/src/features/page_view_event/instrument/index.js +7 -3
- package/src/features/page_view_timing/instrument/index.js +3 -3
- package/src/features/session_replay/instrument/index.js +11 -4
- package/src/features/session_trace/instrument/index.js +10 -3
- package/src/features/soft_navigations/instrument/index.js +8 -3
- package/src/features/spa/instrument/index.js +8 -3
- package/src/features/utils/instrument-base.js +27 -20
- package/src/loaders/agent-base.js +4 -96
- package/src/loaders/agent.js +11 -0
- package/src/loaders/api/addPageAction.js +17 -0
- package/src/loaders/api/addRelease.js +14 -0
- package/src/loaders/api/addToTrace.js +25 -0
- package/src/loaders/api/constants.js +28 -0
- package/src/loaders/api/finished.js +19 -0
- package/src/loaders/api/interaction.js +59 -0
- package/src/loaders/api/log.js +18 -0
- package/src/loaders/api/noticeError.js +26 -0
- package/src/loaders/api/pauseReplay.js +14 -0
- package/src/loaders/api/recordCustomEvent.js +15 -0
- package/src/loaders/api/recordReplay.js +14 -0
- package/src/loaders/api/register.js +168 -0
- package/src/loaders/api/setApplicationVersion.js +22 -0
- package/src/loaders/api/setCustomAttribute.js +21 -0
- package/src/loaders/api/setErrorHandler.js +12 -0
- package/src/loaders/api/setPageViewName.js +17 -0
- package/src/loaders/api/setUserId.js +22 -0
- package/src/loaders/api/sharedHandlers.js +63 -0
- package/src/loaders/api/start.js +12 -0
- package/src/loaders/api/topLevelCallers.js +24 -0
- package/src/loaders/api/wrapLogger.js +14 -0
- package/src/loaders/api-base.js +218 -0
- package/src/loaders/configure/configure.js +2 -3
- package/src/loaders/micro-agent-base.js +3 -136
- package/src/loaders/micro-agent.js +34 -4
- package/tools/bundler-tools/bundler-tools.js +27 -0
- package/tools/bundler-tools/bundler-tools.mjs +23 -0
- package/dist/cjs/features/utils/lazy-feature-loader.js +0 -53
- package/dist/cjs/loaders/api/api-methods.js +0 -14
- package/dist/cjs/loaders/api/api.js +0 -259
- package/dist/cjs/loaders/api/apiAsync.js +0 -63
- package/dist/esm/features/utils/lazy-feature-loader.js +0 -47
- package/dist/esm/loaders/api/api-methods.js +0 -7
- package/dist/esm/loaders/api/api.js +0 -251
- package/dist/esm/loaders/api/apiAsync.js +0 -56
- package/dist/types/features/utils/lazy-feature-loader.d.ts +0 -13
- package/dist/types/features/utils/lazy-feature-loader.d.ts.map +0 -1
- package/dist/types/loaders/api/api-methods.d.ts +0 -3
- package/dist/types/loaders/api/api-methods.d.ts.map +0 -1
- package/dist/types/loaders/api/api.d.ts +0 -3
- package/dist/types/loaders/api/api.d.ts.map +0 -1
- package/dist/types/loaders/api/apiAsync.d.ts +0 -2
- package/dist/types/loaders/api/apiAsync.d.ts.map +0 -1
- package/src/features/utils/lazy-feature-loader.js +0 -47
- package/src/loaders/api/api-methods.js +0 -16
- package/src/loaders/api/api.js +0 -264
- package/src/loaders/api/apiAsync.js +0 -56
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { warn } from '../common/util/console'
|
|
6
|
+
import { ADD_PAGE_ACTION, ADD_RELEASE, ADD_TO_TRACE, FINISHED, INTERACTION, LOG, NOTICE_ERROR, PAUSE_REPLAY, RECORD_CUSTOM_EVENT, RECORD_REPLAY, REGISTER, SET_APPLICATION_VERSION, SET_CURRENT_ROUTE_NAME, SET_CUSTOM_ATTRIBUTE, SET_ERROR_HANDLER, SET_PAGE_VIEW_NAME, SET_USER_ID, START, WRAP_LOGGER } from './api/constants'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
|
|
10
|
+
*/
|
|
11
|
+
export class ApiBase {
|
|
12
|
+
#callMethod (methodName, ...args) {
|
|
13
|
+
if (this[methodName] === ApiBase.prototype[methodName]) warn(35, methodName)
|
|
14
|
+
else return this[methodName](...args)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// MicroAgent class custom defines its own start
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Reports a browser PageAction event along with a name and optional attributes.
|
|
21
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction/}
|
|
22
|
+
* @param {string} name Name or category of the action. Reported as the actionName attribute.
|
|
23
|
+
* @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.
|
|
24
|
+
*/
|
|
25
|
+
addPageAction (name, attributes) {
|
|
26
|
+
return this.#callMethod(ADD_PAGE_ACTION, name, attributes)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @experimental
|
|
31
|
+
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
32
|
+
* It is not recommended for use in production environments and will not receive support for issues.
|
|
33
|
+
*
|
|
34
|
+
* Registers an external caller to report through the base agent to a different target than the base agent.
|
|
35
|
+
* @param {object} target the target object to report data to
|
|
36
|
+
* @param {string} target.licenseKey The licenseKey to report data to
|
|
37
|
+
* @param {string} target.applicationID The applicationID to report data to
|
|
38
|
+
* @param {string=} target.entityGuid The entityGuid to report data to
|
|
39
|
+
* @returns {object} Returns an object that contains the available API methods and configurations to use with the external caller. See loaders/api/api.js for more information.
|
|
40
|
+
*/
|
|
41
|
+
register (target) {
|
|
42
|
+
return this.#callMethod(REGISTER, target)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Records a custom event with a specified eventType and attributes.
|
|
47
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordCustomEvent/}
|
|
48
|
+
* @param {string} eventType The eventType to store the event as.
|
|
49
|
+
* @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}.
|
|
50
|
+
*/
|
|
51
|
+
recordCustomEvent (eventType, attributes) {
|
|
52
|
+
return this.#callMethod(RECORD_CUSTOM_EVENT, eventType, attributes)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Groups page views to help URL structure or to capture the URL's routing information.
|
|
57
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
|
|
58
|
+
* @param {string} name The page name you want to use. Use alphanumeric characters.
|
|
59
|
+
* @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
|
|
60
|
+
*/
|
|
61
|
+
setPageViewName (name, host) {
|
|
62
|
+
return this.#callMethod(SET_PAGE_VIEW_NAME, name, host)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Adds a user-defined attribute name and value to subsequent events on the page.
|
|
67
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
|
|
68
|
+
* @param {string} name Name of the attribute. Appears as column in the PageView event. It will also appear as a column in the PageAction event if you are using it.
|
|
69
|
+
* @param {string|number|boolean|null} value Value of the attribute. Appears as the value in the named attribute column in the PageView event. It will appear as a column in the PageAction event if you are using it. Custom attribute values cannot be complex objects, only simple types such as Strings, Integers and Booleans. Passing a null value unsets any existing attribute of the same name.
|
|
70
|
+
* @param {boolean} [persist] Default false. If set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
|
|
71
|
+
*/
|
|
72
|
+
setCustomAttribute (name, value, persist) {
|
|
73
|
+
return this.#callMethod(SET_CUSTOM_ATTRIBUTE, name, value, persist)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Identifies a browser error without disrupting your app's operations.
|
|
78
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
|
|
79
|
+
* @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
|
|
80
|
+
* @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
|
|
81
|
+
*/
|
|
82
|
+
noticeError (error, customAttributes) {
|
|
83
|
+
return this.#callMethod(NOTICE_ERROR, error, customAttributes)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Adds a user-defined identifier string to subsequent events on the page.
|
|
88
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
|
|
89
|
+
* @param {string|null} value A string identifier for the end-user, useful for tying all browser events to specific users. The value parameter does not have to be unique. If IDs should be unique, the caller is responsible for that validation. Passing a null value unsets any existing user ID.
|
|
90
|
+
*/
|
|
91
|
+
setUserId (value) {
|
|
92
|
+
return this.#callMethod(SET_USER_ID, value)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Adds a user-defined application version string to subsequent events on the page.
|
|
97
|
+
* This decorates all payloads with an attribute of `application.version` which is queryable in NR1.
|
|
98
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setapplicationversion/}
|
|
99
|
+
* @param {string|null} value A string identifier for the application version, useful for
|
|
100
|
+
* tying all browser events to a specific release tag. The value parameter does not
|
|
101
|
+
* have to be unique. Passing a null value unsets any existing value.
|
|
102
|
+
*/
|
|
103
|
+
setApplicationVersion (value) {
|
|
104
|
+
return this.#callMethod(SET_APPLICATION_VERSION, value)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Allows selective ignoring and grouping of known errors that the browser agent captures.
|
|
109
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
|
|
110
|
+
* @param {(error: Error|string) => boolean | { group: string }} callback When an error occurs, the callback is called with the error object as a parameter. The callback will be called with each error, so it is not specific to one error.
|
|
111
|
+
*/
|
|
112
|
+
setErrorHandler (callback) {
|
|
113
|
+
return this.#callMethod(SET_ERROR_HANDLER, callback)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
|
|
118
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
|
|
119
|
+
* @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
|
|
120
|
+
* @param {string} id The ID or version of this release; for example, a version number, build number from your CI environment, GitHub SHA, GUID, or a hash of the contents.
|
|
121
|
+
*/
|
|
122
|
+
addRelease (name, id) {
|
|
123
|
+
return this.#callMethod(ADD_RELEASE, name, id)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Capture a single log.
|
|
128
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log/}
|
|
129
|
+
* @param {string} message String to be captured as log message
|
|
130
|
+
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
|
|
131
|
+
*/
|
|
132
|
+
log (message, options) {
|
|
133
|
+
return this.#callMethod(LOG, message, options)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Starts any and all features that are not running yet in "autoStart" mode
|
|
138
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
|
|
139
|
+
*/
|
|
140
|
+
start () {
|
|
141
|
+
return this.#callMethod(START)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Records an additional time point as "finished" in a session trace and adds a page action.
|
|
146
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/finished/}
|
|
147
|
+
* @param {number} [timeStamp] Defaults to the current time of the call. If used, this marks the time that the page is "finished" according to your own criteria.
|
|
148
|
+
*/
|
|
149
|
+
finished (timeStamp) {
|
|
150
|
+
return this.#callMethod(FINISHED, timeStamp)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Forces a replay to record. If a replay is already actively recording, this call will be ignored.
|
|
155
|
+
* If a recording has not been started, a new one will be created. If a recording has been started, but is currently not recording, it will resume recording.
|
|
156
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordReplay/}
|
|
157
|
+
*/
|
|
158
|
+
recordReplay () {
|
|
159
|
+
return this.#callMethod(RECORD_REPLAY)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Forces an active replay to pause recording. If a replay is already actively recording, this call will cause the recording to pause.
|
|
164
|
+
* If a recording is not currently recording, this call will be ignored. This API will pause both manual and automatic replays that are in progress.
|
|
165
|
+
* The only way to resume recording after manually pausing a replay is to manually record again using the recordReplay() API.
|
|
166
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/pauseReplay/}
|
|
167
|
+
*/
|
|
168
|
+
pauseReplay () {
|
|
169
|
+
return this.#callMethod(PAUSE_REPLAY)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Adds a JavaScript object with a custom name, start time, etc. to an in-progress session trace.
|
|
174
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addtotrace/}
|
|
175
|
+
* @param {{name: string, start: number, end?: number, origin?: string, type?: string}} customAttributes Supply a JavaScript object with these required and optional name/value pairs:
|
|
176
|
+
*
|
|
177
|
+
* - Required name/value pairs: name, start
|
|
178
|
+
* - Optional name/value pairs: end, origin, type
|
|
179
|
+
* - Note: Does not apply to MicroAgent
|
|
180
|
+
*
|
|
181
|
+
* If you are sending the same event object to New Relic as a PageAction, omit the TYPE attribute. (type is a string to describe what type of event you are marking inside of a session trace.) If included, it will override the event type and cause the PageAction event to be sent incorrectly. Instead, use the name attribute for event information.
|
|
182
|
+
*/
|
|
183
|
+
addToTrace (customAttributes) {
|
|
184
|
+
return this.#callMethod(ADD_TO_TRACE, customAttributes)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Gives SPA routes more accurate names than default names. Monitors specific routes rather than by default grouping.
|
|
189
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcurrentroutename/}
|
|
190
|
+
* @param {string} name Current route name for the page.
|
|
191
|
+
* - Note: Does not apply to MicroAgent
|
|
192
|
+
*/
|
|
193
|
+
setCurrentRouteName (name) {
|
|
194
|
+
return this.#callMethod(SET_CURRENT_ROUTE_NAME, name)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Returns a new API object that is bound to the current SPA interaction.
|
|
199
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/interaction/}
|
|
200
|
+
* @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.
|
|
201
|
+
* - Note: Does not apply to MicroAgent
|
|
202
|
+
* - Deprecation Notice: interaction.createTracer is deprecated. See https://docs.newrelic.com/eol/2024/04/eol-04-24-24-createtracer/ for more information.
|
|
203
|
+
*/
|
|
204
|
+
interaction () {
|
|
205
|
+
return this.#callMethod(INTERACTION)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Wrap a logger function to capture a log each time the function is invoked with the message and arguments passed
|
|
210
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/wraplogger/}
|
|
211
|
+
* @param {object} parent The parent object containing the logger method
|
|
212
|
+
* @param {string} functionName The property name of the function in the parent object to be wrapped
|
|
213
|
+
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
|
|
214
|
+
*/
|
|
215
|
+
wrapLogger (parent, functionName, options) {
|
|
216
|
+
return this.#callMethod(WRAP_LOGGER, parent, functionName, options)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { setTopLevelCallers } from '../api/topLevelCallers'
|
|
6
6
|
import { addToNREUM, gosCDN } from '../../common/window/nreum'
|
|
7
7
|
import { mergeInfo } from '../../common/config/info'
|
|
8
8
|
import { mergeInit } from '../../common/config/init'
|
|
@@ -51,7 +51,7 @@ export function configure (agent, opts = {}, loaderType, forceDrain) {
|
|
|
51
51
|
}
|
|
52
52
|
if (updatedInit.proxy.beacon) internalTrafficList.push(updatedInit.proxy.beacon)
|
|
53
53
|
|
|
54
|
-
setTopLevelCallers() // no need to set global APIs on newrelic obj more than once
|
|
54
|
+
setTopLevelCallers(agent) // no need to set global APIs on newrelic obj more than once
|
|
55
55
|
addToNREUM('activatedFeatures', activatedFeatures)
|
|
56
56
|
|
|
57
57
|
// Update if soft_navigations is allowed to run AND part of this agent build, used to override old spa functions.
|
|
@@ -69,7 +69,6 @@ export function configure (agent, opts = {}, loaderType, forceDrain) {
|
|
|
69
69
|
if (!alreadySetOnce.has(agent.agentIdentifier)) {
|
|
70
70
|
agent.ee = ee.get(agent.agentIdentifier)
|
|
71
71
|
agent.exposed = exposed
|
|
72
|
-
setAPI(agent, forceDrain) // assign our API functions to the agent instance
|
|
73
72
|
|
|
74
73
|
dispatchGlobalEvent({
|
|
75
74
|
agentIdentifier: agent.agentIdentifier,
|
|
@@ -2,142 +2,9 @@
|
|
|
2
2
|
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { warn } from '../common/util/console'
|
|
6
5
|
import { generateRandomHexString } from '../common/ids/unique-id'
|
|
6
|
+
import { ApiBase } from './api-base'
|
|
7
7
|
|
|
8
|
-
export class MicroAgentBase {
|
|
9
|
-
agentIdentifier
|
|
10
|
-
|
|
11
|
-
constructor () {
|
|
12
|
-
this.agentIdentifier = generateRandomHexString(16)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Tries to execute the api and generates a generic warning message with the api name injected if unsuccessful
|
|
17
|
-
* @param {string} methodName
|
|
18
|
-
* @param {...any} args
|
|
19
|
-
*/
|
|
20
|
-
#callMethod (methodName, ...args) {
|
|
21
|
-
if (this[methodName] === MicroAgentBase.prototype[methodName]) warn(35, methodName)
|
|
22
|
-
else return this[methodName](...args)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// MicroAgent class custom defines its own start
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Reports a browser PageAction event along with a name and optional attributes.
|
|
29
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction/}
|
|
30
|
-
* @param {string} name Name or category of the action. Reported as the actionName attribute.
|
|
31
|
-
* @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}. The key is reported as its own PageAction attribute with the specified values.
|
|
32
|
-
*/
|
|
33
|
-
addPageAction (name, attributes) {
|
|
34
|
-
return this.#callMethod('addPageAction', name, attributes)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @experimental
|
|
39
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
40
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
41
|
-
*
|
|
42
|
-
* Registers an external caller to report through the base agent to a different target than the base agent.
|
|
43
|
-
* @param {object} target the target object to report data to
|
|
44
|
-
* @param {string} target.licenseKey The licenseKey to report data to
|
|
45
|
-
* @param {string} target.applicationID The applicationID to report data to
|
|
46
|
-
* @param {string=} target.entityGuid The entityGuid to report data to
|
|
47
|
-
* @returns {object} Returns an object that contains the available API methods and configurations to use with the external caller. See loaders/api/api.js for more information.
|
|
48
|
-
*/
|
|
49
|
-
register (target) {
|
|
50
|
-
return this.#callMethod('register', target)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Records a custom event with a specified eventType and attributes.
|
|
55
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/recordCustomEvent/}
|
|
56
|
-
* @param {string} eventType The eventType to store the event as.
|
|
57
|
-
* @param {object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}.
|
|
58
|
-
*/
|
|
59
|
-
recordCustomEvent (eventType, attributes) {
|
|
60
|
-
return this.#callMethod('recordCustomEvent', eventType, attributes)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Groups page views to help URL structure or to capture the URL's routing information.
|
|
65
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
|
|
66
|
-
* @param {string} name The page name you want to use. Use alphanumeric characters.
|
|
67
|
-
* @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
|
|
68
|
-
*/
|
|
69
|
-
setPageViewName (name, host) {
|
|
70
|
-
return this.#callMethod('setPageViewName', name, host)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Adds a user-defined attribute name and value to subsequent events on the page.
|
|
75
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
|
|
76
|
-
* @param {string} name Name of the attribute. Appears as column in the PageView event. It will also appear as a column in the PageAction event if you are using it.
|
|
77
|
-
* @param {string|number|boolean|null} value Value of the attribute. Appears as the value in the named attribute column in the PageView event. It will appear as a column in the PageAction event if you are using it. Custom attribute values cannot be complex objects, only simple types such as Strings, Integers and Booleans. Passing a null value unsets any existing attribute of the same name.
|
|
78
|
-
* @param {boolean} [persist] Default false. If set to true, the name-value pair will also be set into the browser's storage API. Then on the following instrumented pages that load within the same session, the pair will be re-applied as a custom attribute.
|
|
79
|
-
*/
|
|
80
|
-
setCustomAttribute (name, value, persist) {
|
|
81
|
-
return this.#callMethod('setCustomAttribute', name, value, persist)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Identifies a browser error without disrupting your app's operations.
|
|
86
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
|
|
87
|
-
* @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
|
|
88
|
-
* @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
|
|
89
|
-
*/
|
|
90
|
-
noticeError (error, customAttributes) {
|
|
91
|
-
return this.#callMethod('noticeError', error, customAttributes)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Adds a user-defined identifier string to subsequent events on the page.
|
|
96
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
|
|
97
|
-
* @param {string|null} value A string identifier for the end-user, useful for tying all browser events to specific users. The value parameter does not have to be unique. If IDs should be unique, the caller is responsible for that validation. Passing a null value unsets any existing user ID.
|
|
98
|
-
*/
|
|
99
|
-
setUserId (value) {
|
|
100
|
-
return this.#callMethod('setUserId', value)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Adds a user-defined application version string to subsequent events on the page.
|
|
105
|
-
* This decorates all payloads with an attribute of `application.version` which is queryable in NR1.
|
|
106
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setapplicationversion/}
|
|
107
|
-
* @param {string|null} value A string identifier for the application version, useful for
|
|
108
|
-
* tying all browser events to a specific release tag. The value parameter does not
|
|
109
|
-
* have to be unique. Passing a null value unsets any existing value.
|
|
110
|
-
*/
|
|
111
|
-
setApplicationVersion (value) {
|
|
112
|
-
return this.#callMethod('setApplicationVersion', value)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Allows selective ignoring and grouping of known errors that the browser agent captures.
|
|
117
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
|
|
118
|
-
* @param {(error: Error|string) => boolean | { group: string }} callback When an error occurs, the callback is called with the error object as a parameter. The callback will be called with each error, so it is not specific to one error.
|
|
119
|
-
*/
|
|
120
|
-
setErrorHandler (callback) {
|
|
121
|
-
return this.#callMethod('setErrorHandler', callback)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
|
|
126
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
|
|
127
|
-
* @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
|
|
128
|
-
* @param {string} id The ID or version of this release; for example, a version number, build number from your CI environment, GitHub SHA, GUID, or a hash of the contents.
|
|
129
|
-
*/
|
|
130
|
-
addRelease (name, id) {
|
|
131
|
-
return this.#callMethod('addRelease', name, id)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Capture a single log.
|
|
136
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log/}
|
|
137
|
-
* @param {string} message String to be captured as log message
|
|
138
|
-
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
|
|
139
|
-
*/
|
|
140
|
-
log (message, options) {
|
|
141
|
-
return this.#callMethod('log', message, options)
|
|
142
|
-
}
|
|
8
|
+
export class MicroAgentBase extends ApiBase {
|
|
9
|
+
agentIdentifier = generateRandomHexString(16)
|
|
143
10
|
}
|
|
@@ -12,6 +12,19 @@ import { setNREUMInitializedAgent } from '../common/window/nreum'
|
|
|
12
12
|
import { FEATURE_NAMES } from './features/features'
|
|
13
13
|
import { warn } from '../common/util/console'
|
|
14
14
|
import { MicroAgentBase } from './micro-agent-base'
|
|
15
|
+
// api files that are not auto-instrumented
|
|
16
|
+
import { setupSetCustomAttributeAPI } from './api/setCustomAttribute'
|
|
17
|
+
import { setupSetUserIdAPI } from './api/setUserId'
|
|
18
|
+
import { setupSetApplicationVersionAPI } from './api/setApplicationVersion'
|
|
19
|
+
import { setupStartAPI } from './api/start'
|
|
20
|
+
import { setupNoticeErrorAPI } from './api/noticeError'
|
|
21
|
+
import { setupSetErrorHandlerAPI } from './api/setErrorHandler'
|
|
22
|
+
import { setupAddReleaseAPI } from './api/addRelease'
|
|
23
|
+
import { setupAddPageActionAPI } from './api/addPageAction'
|
|
24
|
+
import { setupRecordCustomEventAPI } from './api/recordCustomEvent'
|
|
25
|
+
import { setupFinishedAPI } from './api/finished'
|
|
26
|
+
import { setupLogAPI } from './api/log'
|
|
27
|
+
import { setupWrapLoggerAPI } from './api/wrapLogger'
|
|
15
28
|
|
|
16
29
|
const nonAutoFeatures = [
|
|
17
30
|
FEATURE_NAMES.jserrors,
|
|
@@ -22,7 +35,7 @@ const nonAutoFeatures = [
|
|
|
22
35
|
|
|
23
36
|
/**
|
|
24
37
|
* @deprecated This feature has been deprecated and will be removed in a future release. A future product centralizing around a single agent instance will be released as a replacement, at which time this loader will be removed.
|
|
25
|
-
* A minimal agent class designed to only respond to manual user input. As such, this class does not
|
|
38
|
+
* --- A minimal agent class designed to only respond to manual user input. As such, this class does not
|
|
26
39
|
* automatically instrument. Instead, each MicroAgent instance will lazy load the required features and can support loading multiple instances on one page.
|
|
27
40
|
* Out of the box, it can manually handle and report Page View, Page Action, and Error events.
|
|
28
41
|
*/
|
|
@@ -38,6 +51,25 @@ export class MicroAgent extends MicroAgentBase {
|
|
|
38
51
|
|
|
39
52
|
configure(this, { ...options, runtime: { isolatedBacklog: true } }, options.loaderType || 'micro-agent')
|
|
40
53
|
|
|
54
|
+
/** assign base agent-level API definitions */
|
|
55
|
+
setupSetCustomAttributeAPI(this)
|
|
56
|
+
setupSetUserIdAPI(this)
|
|
57
|
+
setupSetApplicationVersionAPI(this)
|
|
58
|
+
setupStartAPI(this)
|
|
59
|
+
|
|
60
|
+
/** feature APIs that wont get set up automatically for the micro agent since it skips the inst file */
|
|
61
|
+
/** jserrors */
|
|
62
|
+
setupNoticeErrorAPI(this)
|
|
63
|
+
setupSetErrorHandlerAPI(this)
|
|
64
|
+
setupAddReleaseAPI(this)
|
|
65
|
+
/** generic events */
|
|
66
|
+
setupAddPageActionAPI(this)
|
|
67
|
+
setupRecordCustomEventAPI(this)
|
|
68
|
+
setupFinishedAPI(this)
|
|
69
|
+
/** logging */
|
|
70
|
+
setupLogAPI(this)
|
|
71
|
+
setupWrapLoggerAPI(this)
|
|
72
|
+
|
|
41
73
|
/**
|
|
42
74
|
* Starts a set of agent features if not running in "autoStart" mode
|
|
43
75
|
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
|
|
@@ -64,9 +96,7 @@ export class MicroAgent extends MicroAgentBase {
|
|
|
64
96
|
so as to avoid the race condition of things like session and sharedAggregator not being ready by features that uses them right away. */
|
|
65
97
|
nonAutoFeatures.forEach(f => {
|
|
66
98
|
if (enabledFeatures[f] && featureNames.includes(f)) {
|
|
67
|
-
import(
|
|
68
|
-
return lazyFeatureLoader(f, 'aggregate')
|
|
69
|
-
}).then(({ Aggregate }) => {
|
|
99
|
+
import(`../features/${f}/aggregate`).then(({ Aggregate }) => {
|
|
70
100
|
this.features[f] = new Aggregate(this)
|
|
71
101
|
this.runtime.harvester.initializedAggregates.push(this.features[f]) // so that harvester will poll this feature agg on interval
|
|
72
102
|
}).catch(err => warn(25, err))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const webpackCacheGroup = (asyncChunkName = 'new-relic-browser-agent', matcher) => {
|
|
2
|
+
if (!matcher) {
|
|
3
|
+
matcher = (module, { chunkGraph }) => {
|
|
4
|
+
if (!module.resource) return false
|
|
5
|
+
if (!module.resource.match(/node_modules[\\/](@newrelic[\\/]browser-agent|web-vitals)[\\/]/)) return false
|
|
6
|
+
return chunkGraph.getModuleChunks(module).filter(chunk => {
|
|
7
|
+
return !['recorder', 'compressor'].includes(chunk.name)
|
|
8
|
+
}).length > 0
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
[asyncChunkName]: {
|
|
14
|
+
name: asyncChunkName,
|
|
15
|
+
enforce: true,
|
|
16
|
+
reuseExistingChunk: true,
|
|
17
|
+
test: matcher,
|
|
18
|
+
chunks: 'async'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
webpackCacheGroup
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// roll-up, vite, esbuild etc.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const webpackCacheGroup = (asyncChunkName = 'new-relic-browser-agent', matcher) => {
|
|
2
|
+
if (!matcher) {
|
|
3
|
+
matcher = (module, { chunkGraph }) => {
|
|
4
|
+
if (!module.resource) return false
|
|
5
|
+
if (!module.resource.match(/node_modules[\\/](@newrelic[\\/]browser-agent|web-vitals)[\\/]/)) return false
|
|
6
|
+
return chunkGraph.getModuleChunks(module).filter(chunk => {
|
|
7
|
+
return !['recorder', 'compressor'].includes(chunk.name)
|
|
8
|
+
}).length > 0
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
[asyncChunkName]: {
|
|
14
|
+
name: asyncChunkName,
|
|
15
|
+
enforce: true,
|
|
16
|
+
reuseExistingChunk: true,
|
|
17
|
+
test: matcher,
|
|
18
|
+
chunks: 'async'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// roll-up, vite, esbuild etc.
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.lazyFeatureLoader = lazyFeatureLoader;
|
|
7
|
-
var _features = require("../../loaders/features/features");
|
|
8
|
-
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); }
|
|
9
|
-
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; } /**
|
|
10
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
11
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Centralizes the lazy loading of agent feature aggregate and instrument sources.
|
|
15
|
-
*
|
|
16
|
-
* This function uses two defined switch cases to allow us to easily name our chunks and re-use these
|
|
17
|
-
* chunks for different agent types. We do not use template strings or string concatenation here because
|
|
18
|
-
* doing so makes it much more difficult to name the chunks and forces Webpack to "guess" what the chunks
|
|
19
|
-
* should be.
|
|
20
|
-
* @param featureName Name of the feature to import such as ajax or session_trace
|
|
21
|
-
* @param featurePart Name of the feature part to load; should be either instrument or aggregate
|
|
22
|
-
* @returns {Promise<InstrumentBase|FeatureBase|null>}
|
|
23
|
-
*/
|
|
24
|
-
function lazyFeatureLoader(featureName, featurePart) {
|
|
25
|
-
if (featurePart === 'aggregate') {
|
|
26
|
-
switch (featureName) {
|
|
27
|
-
case _features.FEATURE_NAMES.ajax:
|
|
28
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "ajax-aggregate" */'../ajax/aggregate')));
|
|
29
|
-
case _features.FEATURE_NAMES.jserrors:
|
|
30
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "jserrors-aggregate" */'../jserrors/aggregate')));
|
|
31
|
-
case _features.FEATURE_NAMES.genericEvents:
|
|
32
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "generic_events-aggregate" */'../generic_events/aggregate')));
|
|
33
|
-
case _features.FEATURE_NAMES.logging:
|
|
34
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "logging-aggregate" */'../logging/aggregate')));
|
|
35
|
-
case _features.FEATURE_NAMES.metrics:
|
|
36
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "metrics-aggregate" */'../metrics/aggregate')));
|
|
37
|
-
case _features.FEATURE_NAMES.pageViewEvent:
|
|
38
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "page_view_event-aggregate" */'../page_view_event/aggregate')));
|
|
39
|
-
case _features.FEATURE_NAMES.pageViewTiming:
|
|
40
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "page_view_timing-aggregate" */'../page_view_timing/aggregate')));
|
|
41
|
-
case _features.FEATURE_NAMES.sessionReplay:
|
|
42
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "session_replay-aggregate" */'../session_replay/aggregate')));
|
|
43
|
-
case _features.FEATURE_NAMES.sessionTrace:
|
|
44
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "session_trace-aggregate" */'../session_trace/aggregate')));
|
|
45
|
-
case _features.FEATURE_NAMES.spa:
|
|
46
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "spa-aggregate" */'../spa/aggregate')));
|
|
47
|
-
case _features.FEATURE_NAMES.softNav:
|
|
48
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "basic-spa-aggregate" */'../soft_navigations/aggregate')));
|
|
49
|
-
default:
|
|
50
|
-
throw new Error("Attempted to load unsupported agent feature: ".concat(featureName, " ").concat(featurePart));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.asyncApiMethods = exports.apiMethods = void 0;
|
|
7
|
-
var _constants = require("../../features/session_replay/constants");
|
|
8
|
-
/**
|
|
9
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
10
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const apiMethods = exports.apiMethods = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease', 'recordCustomEvent', 'addPageAction', 'setCurrentRouteName', 'setPageViewName', 'setCustomAttribute', 'interaction', 'noticeError', 'setUserId', 'setApplicationVersion', 'start', _constants.SR_EVENT_EMITTER_TYPES.RECORD, _constants.SR_EVENT_EMITTER_TYPES.PAUSE, 'log', 'wrapLogger', 'register'];
|
|
14
|
-
const asyncApiMethods = exports.asyncApiMethods = ['setErrorHandler', 'finished', 'addToTrace', 'addRelease'];
|