@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
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { FEATURE_NAMES } from '../features/features';
|
|
6
|
-
import { handle } from '../../common/event-emitter/handle';
|
|
7
|
-
import { registerHandler } from '../../common/event-emitter/register-handler';
|
|
8
|
-
import { single } from '../../common/util/invoke';
|
|
9
|
-
import { CUSTOM_METRIC_CHANNEL } from '../../features/metrics/constants';
|
|
10
|
-
import { originTime } from '../../common/constants/runtime';
|
|
11
|
-
export function setAsyncAPI(agent) {
|
|
12
|
-
const api = {
|
|
13
|
-
finished: single(finished),
|
|
14
|
-
setErrorHandler,
|
|
15
|
-
addToTrace,
|
|
16
|
-
addRelease
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// Hook all of the api functions up to the queues/stubs created in loader/api.js
|
|
20
|
-
Object.entries(api).forEach(([fnName, fnCall]) => registerHandler('api-' + fnName, fnCall, 'api', agent.ee));
|
|
21
|
-
|
|
22
|
-
// All API functions get passed the time they were called as their
|
|
23
|
-
// first parameter. These functions can be called asynchronously.
|
|
24
|
-
|
|
25
|
-
function finished(t, providedTime) {
|
|
26
|
-
const time = providedTime ? providedTime - originTime : t;
|
|
27
|
-
handle(CUSTOM_METRIC_CHANNEL, ['finished', {
|
|
28
|
-
time
|
|
29
|
-
}], undefined, FEATURE_NAMES.metrics, agent.ee);
|
|
30
|
-
addToTrace(t, {
|
|
31
|
-
name: 'finished',
|
|
32
|
-
start: time + originTime,
|
|
33
|
-
origin: 'nr'
|
|
34
|
-
});
|
|
35
|
-
handle('api-addPageAction', [time, 'finished'], undefined, FEATURE_NAMES.genericEvents, agent.ee);
|
|
36
|
-
}
|
|
37
|
-
function addToTrace(_, evt) {
|
|
38
|
-
if (!(evt && typeof evt === 'object' && evt.name && evt.start)) return;
|
|
39
|
-
const report = {
|
|
40
|
-
n: evt.name,
|
|
41
|
-
s: evt.start - originTime,
|
|
42
|
-
e: (evt.end || evt.start) - originTime,
|
|
43
|
-
o: evt.origin || '',
|
|
44
|
-
t: 'api'
|
|
45
|
-
};
|
|
46
|
-
handle('bstApi', [report], undefined, FEATURE_NAMES.sessionTrace, agent.ee);
|
|
47
|
-
}
|
|
48
|
-
function setErrorHandler(_, handler) {
|
|
49
|
-
agent.runtime.onerror = handler;
|
|
50
|
-
}
|
|
51
|
-
let releaseCount = 0;
|
|
52
|
-
function addRelease(_, name, id) {
|
|
53
|
-
if (++releaseCount > 10) return;
|
|
54
|
-
agent.runtime.releaseIds[name.slice(-200)] = ('' + id).slice(-200);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralizes the lazy loading of agent feature aggregate and instrument sources.
|
|
3
|
-
*
|
|
4
|
-
* This function uses two defined switch cases to allow us to easily name our chunks and re-use these
|
|
5
|
-
* chunks for different agent types. We do not use template strings or string concatenation here because
|
|
6
|
-
* doing so makes it much more difficult to name the chunks and forces Webpack to "guess" what the chunks
|
|
7
|
-
* should be.
|
|
8
|
-
* @param featureName Name of the feature to import such as ajax or session_trace
|
|
9
|
-
* @param featurePart Name of the feature part to load; should be either instrument or aggregate
|
|
10
|
-
* @returns {Promise<InstrumentBase|FeatureBase|null>}
|
|
11
|
-
*/
|
|
12
|
-
export function lazyFeatureLoader(featureName: any, featurePart: any): Promise<InstrumentBase | FeatureBase | null>;
|
|
13
|
-
//# sourceMappingURL=lazy-feature-loader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-feature-loader.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/lazy-feature-loader.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,uEAFa,OAAO,CAAC,cAAc,GAAC,WAAW,GAAC,IAAI,CAAC,CA+BpD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-methods.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/api-methods.js"],"names":[],"mappings":"AAMA,kCAKC;AAED,uCAEC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/api.js"],"names":[],"mappings":"AAuBA,2CAiBC;AAID,6DA2NC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apiAsync.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/apiAsync.js"],"names":[],"mappings":"AAWA,8CA4CC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { FEATURE_NAMES } from '../../loaders/features/features'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Centralizes the lazy loading of agent feature aggregate and instrument sources.
|
|
9
|
-
*
|
|
10
|
-
* This function uses two defined switch cases to allow us to easily name our chunks and re-use these
|
|
11
|
-
* chunks for different agent types. We do not use template strings or string concatenation here because
|
|
12
|
-
* doing so makes it much more difficult to name the chunks and forces Webpack to "guess" what the chunks
|
|
13
|
-
* should be.
|
|
14
|
-
* @param featureName Name of the feature to import such as ajax or session_trace
|
|
15
|
-
* @param featurePart Name of the feature part to load; should be either instrument or aggregate
|
|
16
|
-
* @returns {Promise<InstrumentBase|FeatureBase|null>}
|
|
17
|
-
*/
|
|
18
|
-
export function lazyFeatureLoader (featureName, featurePart) {
|
|
19
|
-
if (featurePart === 'aggregate') {
|
|
20
|
-
switch (featureName) {
|
|
21
|
-
case FEATURE_NAMES.ajax:
|
|
22
|
-
return import(/* webpackChunkName: "ajax-aggregate" */ '../ajax/aggregate')
|
|
23
|
-
case FEATURE_NAMES.jserrors:
|
|
24
|
-
return import(/* webpackChunkName: "jserrors-aggregate" */ '../jserrors/aggregate')
|
|
25
|
-
case FEATURE_NAMES.genericEvents:
|
|
26
|
-
return import(/* webpackChunkName: "generic_events-aggregate" */ '../generic_events/aggregate')
|
|
27
|
-
case FEATURE_NAMES.logging:
|
|
28
|
-
return import(/* webpackChunkName: "logging-aggregate" */ '../logging/aggregate')
|
|
29
|
-
case FEATURE_NAMES.metrics:
|
|
30
|
-
return import(/* webpackChunkName: "metrics-aggregate" */ '../metrics/aggregate')
|
|
31
|
-
case FEATURE_NAMES.pageViewEvent:
|
|
32
|
-
return import(/* webpackChunkName: "page_view_event-aggregate" */ '../page_view_event/aggregate')
|
|
33
|
-
case FEATURE_NAMES.pageViewTiming:
|
|
34
|
-
return import(/* webpackChunkName: "page_view_timing-aggregate" */ '../page_view_timing/aggregate')
|
|
35
|
-
case FEATURE_NAMES.sessionReplay:
|
|
36
|
-
return import(/* webpackChunkName: "session_replay-aggregate" */ '../session_replay/aggregate')
|
|
37
|
-
case FEATURE_NAMES.sessionTrace:
|
|
38
|
-
return import(/* webpackChunkName: "session_trace-aggregate" */ '../session_trace/aggregate')
|
|
39
|
-
case FEATURE_NAMES.spa:
|
|
40
|
-
return import(/* webpackChunkName: "spa-aggregate" */ '../spa/aggregate')
|
|
41
|
-
case FEATURE_NAMES.softNav:
|
|
42
|
-
return import(/* webpackChunkName: "basic-spa-aggregate" */ '../soft_navigations/aggregate')
|
|
43
|
-
default:
|
|
44
|
-
throw new Error(`Attempted to load unsupported agent feature: ${featureName} ${featurePart}`)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { SR_EVENT_EMITTER_TYPES } from '../../features/session_replay/constants'
|
|
6
|
-
|
|
7
|
-
export const apiMethods = [
|
|
8
|
-
'setErrorHandler', 'finished', 'addToTrace', 'addRelease', 'recordCustomEvent',
|
|
9
|
-
'addPageAction', 'setCurrentRouteName', 'setPageViewName', 'setCustomAttribute',
|
|
10
|
-
'interaction', 'noticeError', 'setUserId', 'setApplicationVersion', 'start',
|
|
11
|
-
SR_EVENT_EMITTER_TYPES.RECORD, SR_EVENT_EMITTER_TYPES.PAUSE, 'log', 'wrapLogger', 'register'
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
export const asyncApiMethods = [
|
|
15
|
-
'setErrorHandler', 'finished', 'addToTrace', 'addRelease'
|
|
16
|
-
]
|
package/src/loaders/api/api.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { FEATURE_NAMES } from '../features/features'
|
|
6
|
-
import { handle } from '../../common/event-emitter/handle'
|
|
7
|
-
import { drain, registerDrain } from '../../common/drain/drain'
|
|
8
|
-
import { onWindowLoad } from '../../common/window/load'
|
|
9
|
-
import { isBrowserScope } from '../../common/constants/runtime'
|
|
10
|
-
import { warn } from '../../common/util/console'
|
|
11
|
-
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
12
|
-
import { gosCDN } from '../../common/window/nreum'
|
|
13
|
-
import { apiMethods, asyncApiMethods } from './api-methods'
|
|
14
|
-
import { SR_EVENT_EMITTER_TYPES } from '../../features/session_replay/constants'
|
|
15
|
-
import { now } from '../../common/timing/now'
|
|
16
|
-
import { MODE } from '../../common/session/constants'
|
|
17
|
-
import { LOG_LEVELS } from '../../features/logging/constants'
|
|
18
|
-
import { bufferLog } from '../../features/logging/shared/utils'
|
|
19
|
-
import { wrapLogger } from '../../common/wrap/wrap-logger'
|
|
20
|
-
import { buildRegisterApi } from './register-api'
|
|
21
|
-
import { dispatchGlobalEvent } from '../../common/dispatch/global-event'
|
|
22
|
-
import { activatedFeatures } from '../../common/util/feature-flags'
|
|
23
|
-
|
|
24
|
-
export function setTopLevelCallers () {
|
|
25
|
-
const nr = gosCDN()
|
|
26
|
-
apiMethods.forEach(f => {
|
|
27
|
-
nr[f] = (...args) => caller(f, ...args)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
function caller (fnName, ...args) {
|
|
31
|
-
let returnVals = []
|
|
32
|
-
Object.values(nr.initializedAgents).forEach(agt => {
|
|
33
|
-
if (!agt || !agt.runtime) {
|
|
34
|
-
warn(38, fnName)
|
|
35
|
-
} else if (agt.exposed && agt[fnName] && agt.runtime.loaderType !== 'micro-agent') {
|
|
36
|
-
returnVals.push(agt[fnName](...args))
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
return returnVals[0]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const replayRunning = {}
|
|
44
|
-
|
|
45
|
-
export function setAPI (agent, forceDrain) {
|
|
46
|
-
if (!forceDrain) registerDrain(agent.agentIdentifier, 'api')
|
|
47
|
-
const tracerEE = agent.ee.get('tracer')
|
|
48
|
-
|
|
49
|
-
replayRunning[agent.agentIdentifier] = MODE.OFF
|
|
50
|
-
|
|
51
|
-
agent.ee.on(SR_EVENT_EMITTER_TYPES.REPLAY_RUNNING, (isRunning) => {
|
|
52
|
-
replayRunning[agent.agentIdentifier] = isRunning
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const prefix = 'api-'
|
|
56
|
-
const spaPrefix = prefix + 'ixn-'
|
|
57
|
-
|
|
58
|
-
/** Shared handlers are used by both the base agent instance as well as "registered" entities
|
|
59
|
-
* We isolate them like this so that the public interface methods are unchanged and still dont require
|
|
60
|
-
* a target, but the register APIs `can` supply a target.
|
|
61
|
-
*/
|
|
62
|
-
const sharedHandlers = {
|
|
63
|
-
addPageAction: function (name, attributes, targetEntityGuid, timestamp = now()) {
|
|
64
|
-
apiCall(prefix, 'addPageAction', true, FEATURE_NAMES.genericEvents, timestamp)(name, attributes, targetEntityGuid)
|
|
65
|
-
},
|
|
66
|
-
log: function (message, { customAttributes = {}, level = LOG_LEVELS.INFO } = {}, targetEntityGuid, timestamp = now()) {
|
|
67
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/log/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
68
|
-
bufferLog(agent.ee, message, customAttributes, level, targetEntityGuid, timestamp)
|
|
69
|
-
},
|
|
70
|
-
noticeError: function (err, customAttributes, targetEntityGuid, timestamp = now()) {
|
|
71
|
-
if (typeof err === 'string') err = new Error(err)
|
|
72
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/noticeError/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
73
|
-
handle('err', [err, timestamp, false, customAttributes, !!replayRunning[agent.agentIdentifier], undefined, targetEntityGuid], undefined, FEATURE_NAMES.jserrors, agent.ee)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @experimental
|
|
79
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
80
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
81
|
-
*/
|
|
82
|
-
agent.register = function (target) {
|
|
83
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/register/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
84
|
-
return buildRegisterApi(agent, sharedHandlers, target)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
agent.log = function (message, options) {
|
|
88
|
-
sharedHandlers.log(message, options)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
agent.wrapLogger = (parent, functionName, { customAttributes = {}, level = LOG_LEVELS.INFO } = {}) => {
|
|
92
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/wrapLogger/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
93
|
-
wrapLogger(agent.ee, parent, functionName, { customAttributes, level })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Setup stub functions that queue calls for later processing.
|
|
97
|
-
asyncApiMethods.forEach(fnName => { agent[fnName] = apiCall(prefix, fnName, true, 'api') })
|
|
98
|
-
|
|
99
|
-
agent.addPageAction = function (name, attributes) {
|
|
100
|
-
sharedHandlers.addPageAction(name, attributes)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
agent.recordCustomEvent = apiCall(prefix, 'recordCustomEvent', true, FEATURE_NAMES.genericEvents)
|
|
104
|
-
|
|
105
|
-
agent.setPageViewName = function (name, host) {
|
|
106
|
-
if (typeof name !== 'string') return
|
|
107
|
-
if (name.charAt(0) !== '/') name = '/' + name
|
|
108
|
-
agent.runtime.customTransaction = (host || 'http://custom.transaction') + name
|
|
109
|
-
return apiCall(prefix, 'setPageViewName', true)()
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Attach the key-value attribute onto agent payloads. All browser events in NR will be affected.
|
|
114
|
-
* @param {string} key
|
|
115
|
-
* @param {string|number|boolean|null} value - null indicates the key should be removed or erased
|
|
116
|
-
* @param {string} apiName
|
|
117
|
-
* @param {boolean} addToBrowserStorage - whether this attribute should be stored in browser storage API and retrieved by the next agent context or initialization
|
|
118
|
-
* @returns @see apiCall
|
|
119
|
-
*/
|
|
120
|
-
function appendJsAttribute (key, value, apiName, addToBrowserStorage) {
|
|
121
|
-
const currentInfo = agent.info
|
|
122
|
-
if (value === null) delete currentInfo.jsAttributes[key]
|
|
123
|
-
else currentInfo.jsAttributes[key] = value
|
|
124
|
-
|
|
125
|
-
return apiCall(prefix, apiName, true, (!!addToBrowserStorage || value === null) ? 'session' : undefined)(key, value)
|
|
126
|
-
}
|
|
127
|
-
agent.setCustomAttribute = function (name, value, persistAttribute = false) {
|
|
128
|
-
if (typeof name !== 'string') {
|
|
129
|
-
warn(39, typeof name)
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
if (!(['string', 'number', 'boolean'].includes(typeof value) || value === null)) {
|
|
133
|
-
warn(40, typeof value)
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
return appendJsAttribute(name, value, 'setCustomAttribute', persistAttribute)
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Attach the 'enduser.id' attribute onto agent payloads. This may be used in NR queries to group all browser events by specific users.
|
|
140
|
-
* @param {string} value - unique user identifier; a null user id suggests none should exist
|
|
141
|
-
* @returns @see apiCall
|
|
142
|
-
*/
|
|
143
|
-
agent.setUserId = function (value) {
|
|
144
|
-
if (!(typeof value === 'string' || value === null)) {
|
|
145
|
-
warn(41, typeof value)
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
return appendJsAttribute('enduser.id', value, 'setUserId', true)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Attach the 'applcation.version' attribute onto agent payloads. This may be used in NR queries to group all browser events by a specific customer-defined release.
|
|
153
|
-
* @param {string|null} value - Application version -- if null, will "unset" the value
|
|
154
|
-
* @returns @see apiCall
|
|
155
|
-
*/
|
|
156
|
-
agent.setApplicationVersion = function (value) {
|
|
157
|
-
if (!(typeof value === 'string' || value === null)) {
|
|
158
|
-
warn(42, typeof value)
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
|
-
return appendJsAttribute('application.version', value, 'setApplicationVersion', false)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
agent.start = () => {
|
|
165
|
-
try {
|
|
166
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/start/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
167
|
-
agent.ee.emit('manual-start-all')
|
|
168
|
-
} catch (err) {
|
|
169
|
-
warn(23, err)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
agent[SR_EVENT_EMITTER_TYPES.RECORD] = function () {
|
|
174
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/recordReplay/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
175
|
-
handle(SR_EVENT_EMITTER_TYPES.RECORD, [], undefined, FEATURE_NAMES.sessionReplay, agent.ee)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
agent[SR_EVENT_EMITTER_TYPES.PAUSE] = function () {
|
|
179
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/pauseReplay/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
180
|
-
handle(SR_EVENT_EMITTER_TYPES.PAUSE, [], undefined, FEATURE_NAMES.sessionReplay, agent.ee)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
agent.interaction = function (options) {
|
|
184
|
-
return new InteractionHandle().get(typeof options === 'object' ? options : {})
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function InteractionHandle () { }
|
|
188
|
-
|
|
189
|
-
const InteractionApiProto = InteractionHandle.prototype = {
|
|
190
|
-
createTracer: function (name, cb) {
|
|
191
|
-
var contextStore = {}
|
|
192
|
-
var ixn = this
|
|
193
|
-
var hasCb = typeof cb === 'function'
|
|
194
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/createTracer/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
195
|
-
// Soft navigations won't support Tracer nodes, but this fn should still work the same otherwise (e.g., run the orig cb).
|
|
196
|
-
if (!agent.runSoftNavOverSpa) handle(spaPrefix + 'tracer', [now(), name, contextStore], ixn, FEATURE_NAMES.spa, agent.ee)
|
|
197
|
-
return function () {
|
|
198
|
-
tracerEE.emit((hasCb ? '' : 'no-') + 'fn-start', [now(), ixn, hasCb], contextStore)
|
|
199
|
-
if (hasCb) {
|
|
200
|
-
try {
|
|
201
|
-
return cb.apply(this, arguments)
|
|
202
|
-
} catch (err) {
|
|
203
|
-
const error = typeof err === 'string' ? new Error(err) : err
|
|
204
|
-
tracerEE.emit('fn-err', [arguments, this, error], contextStore)
|
|
205
|
-
// the error came from outside the agent, so don't swallow
|
|
206
|
-
throw error
|
|
207
|
-
} finally {
|
|
208
|
-
tracerEE.emit('fn-end', [now()], contextStore)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
;['actionText', 'setName', 'setAttribute', 'save', 'ignore', 'onEnd', 'getContext', 'end', 'get'].forEach(name => {
|
|
216
|
-
InteractionApiProto[name] = function () {
|
|
217
|
-
return apiCall
|
|
218
|
-
.apply(this, [spaPrefix, name, undefined, agent.runSoftNavOverSpa ? FEATURE_NAMES.softNav : FEATURE_NAMES.spa])
|
|
219
|
-
.apply(this, arguments)
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
agent.setCurrentRouteName = function () {
|
|
223
|
-
return agent.runSoftNavOverSpa
|
|
224
|
-
? apiCall(spaPrefix, 'routeName', undefined, FEATURE_NAMES.softNav)(...arguments)
|
|
225
|
-
: apiCall(prefix, 'routeName', true, FEATURE_NAMES.spa)(...arguments)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function apiCall (prefix, name, notSpa, bufferGroup, timestamp = now()) {
|
|
229
|
-
return function () {
|
|
230
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/' + name + '/called'], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
231
|
-
dispatchGlobalEvent({
|
|
232
|
-
agentIdentifier: agent.agentIdentifier,
|
|
233
|
-
drained: !!activatedFeatures?.[agent.agentIdentifier],
|
|
234
|
-
type: 'data',
|
|
235
|
-
name: 'api',
|
|
236
|
-
feature: prefix + name,
|
|
237
|
-
data: { notSpa, bufferGroup }
|
|
238
|
-
})
|
|
239
|
-
if (bufferGroup) handle(prefix + name, [timestamp, ...arguments], notSpa ? null : this, bufferGroup, agent.ee) // no bufferGroup means only the SM is emitted
|
|
240
|
-
return notSpa ? undefined : this // returns the InteractionHandle which allows these methods to be chained
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
agent.noticeError = function (err, customAttributes) {
|
|
245
|
-
sharedHandlers.noticeError(err, customAttributes)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// theres no window.load event on non-browser scopes, lazy load immediately
|
|
249
|
-
if (!isBrowserScope) lazyLoad()
|
|
250
|
-
// try to stay out of the way of the window.load event, lazy load once that has finished.
|
|
251
|
-
else onWindowLoad(() => lazyLoad(), true)
|
|
252
|
-
|
|
253
|
-
function lazyLoad () {
|
|
254
|
-
import(/* webpackChunkName: "async-api" */'./apiAsync').then(({ setAsyncAPI }) => {
|
|
255
|
-
setAsyncAPI(agent)
|
|
256
|
-
drain(agent.agentIdentifier, 'api')
|
|
257
|
-
}).catch((err) => {
|
|
258
|
-
warn(27, err)
|
|
259
|
-
agent.ee.abort()
|
|
260
|
-
})
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return true
|
|
264
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { FEATURE_NAMES } from '../features/features'
|
|
6
|
-
import { handle } from '../../common/event-emitter/handle'
|
|
7
|
-
import { registerHandler } from '../../common/event-emitter/register-handler'
|
|
8
|
-
import { single } from '../../common/util/invoke'
|
|
9
|
-
import { CUSTOM_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
10
|
-
import { originTime } from '../../common/constants/runtime'
|
|
11
|
-
|
|
12
|
-
export function setAsyncAPI (agent) {
|
|
13
|
-
const api = {
|
|
14
|
-
finished: single(finished),
|
|
15
|
-
setErrorHandler,
|
|
16
|
-
addToTrace,
|
|
17
|
-
addRelease
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Hook all of the api functions up to the queues/stubs created in loader/api.js
|
|
21
|
-
Object.entries(api).forEach(([fnName, fnCall]) => registerHandler('api-' + fnName, fnCall, 'api', agent.ee))
|
|
22
|
-
|
|
23
|
-
// All API functions get passed the time they were called as their
|
|
24
|
-
// first parameter. These functions can be called asynchronously.
|
|
25
|
-
|
|
26
|
-
function finished (t, providedTime) {
|
|
27
|
-
const time = providedTime ? providedTime - originTime : t
|
|
28
|
-
handle(CUSTOM_METRIC_CHANNEL, ['finished', { time }], undefined, FEATURE_NAMES.metrics, agent.ee)
|
|
29
|
-
addToTrace(t, { name: 'finished', start: time + originTime, origin: 'nr' })
|
|
30
|
-
handle('api-addPageAction', [time, 'finished'], undefined, FEATURE_NAMES.genericEvents, agent.ee)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function addToTrace (_, evt) {
|
|
34
|
-
if (!(evt && typeof evt === 'object' && evt.name && evt.start)) return
|
|
35
|
-
|
|
36
|
-
const report = {
|
|
37
|
-
n: evt.name,
|
|
38
|
-
s: evt.start - originTime,
|
|
39
|
-
e: (evt.end || evt.start) - originTime,
|
|
40
|
-
o: evt.origin || '',
|
|
41
|
-
t: 'api'
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
handle('bstApi', [report], undefined, FEATURE_NAMES.sessionTrace, agent.ee)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function setErrorHandler (_, handler) {
|
|
48
|
-
agent.runtime.onerror = handler
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let releaseCount = 0
|
|
52
|
-
function addRelease (_, name, id) {
|
|
53
|
-
if (++releaseCount > 10) return
|
|
54
|
-
agent.runtime.releaseIds[name.slice(-200)] = ('' + id).slice(-200)
|
|
55
|
-
}
|
|
56
|
-
}
|