@newrelic/browser-agent 1.273.0 → 1.273.1
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 +7 -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/utils/agent-session.js +14 -19
- package/dist/cjs/features/utils/instrument-base.js +1 -1
- package/dist/cjs/loaders/agent-base.js +6 -103
- package/dist/cjs/loaders/micro-agent-base.js +117 -0
- package/dist/cjs/loaders/micro-agent.js +43 -56
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/features/utils/agent-session.js +14 -19
- package/dist/esm/features/utils/instrument-base.js +1 -1
- package/dist/esm/loaders/agent-base.js +6 -103
- package/dist/esm/loaders/micro-agent-base.js +110 -0
- package/dist/esm/loaders/micro-agent.js +43 -56
- package/dist/types/features/utils/agent-session.d.ts +1 -1
- package/dist/types/features/utils/agent-session.d.ts.map +1 -1
- package/dist/types/loaders/agent-base.d.ts +5 -76
- package/dist/types/loaders/agent-base.d.ts.map +1 -1
- package/dist/types/loaders/micro-agent-base.d.ts +75 -0
- package/dist/types/loaders/micro-agent-base.d.ts.map +1 -0
- package/dist/types/loaders/micro-agent.d.ts +4 -5
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/features/utils/agent-session.js +12 -18
- package/src/features/utils/instrument-base.js +1 -1
- package/src/loaders/agent-base.js +6 -104
- package/src/loaders/micro-agent-base.js +113 -0
- package/src/loaders/micro-agent.js +42 -55
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.273.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.273.0...v1.273.1) (2024-11-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Multiple MicroAgent undefined session and limit available API ([#1252](https://github.com/newrelic/newrelic-browser-agent/issues/1252)) ([19cbb63](https://github.com/newrelic/newrelic-browser-agent/commit/19cbb634b5016e3e8ce0c40a6bf1ee59156c78eb))
|
|
12
|
+
|
|
6
13
|
## [1.273.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.272.0...v1.273.0) (2024-11-11)
|
|
7
14
|
|
|
8
15
|
|
|
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
|
|
|
12
12
|
/**
|
|
13
13
|
* Exposes the version of the agent
|
|
14
14
|
*/
|
|
15
|
-
const VERSION = exports.VERSION = "1.273.
|
|
15
|
+
const VERSION = exports.VERSION = "1.273.1";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the build type of the agent
|
|
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
|
|
|
12
12
|
/**
|
|
13
13
|
* Exposes the version of the agent
|
|
14
14
|
*/
|
|
15
|
-
const VERSION = exports.VERSION = "1.273.
|
|
15
|
+
const VERSION = exports.VERSION = "1.273.1";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the build type of the agent
|
|
@@ -4,22 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setupAgentSession = setupAgentSession;
|
|
7
|
-
var _info = require("../../common/config/info");
|
|
8
|
-
var _init = require("../../common/config/init");
|
|
9
|
-
var _runtime = require("../../common/config/runtime");
|
|
10
7
|
var _drain = require("../../common/drain/drain");
|
|
11
8
|
var _contextualEe = require("../../common/event-emitter/contextual-ee");
|
|
12
9
|
var _registerHandler = require("../../common/event-emitter/register-handler");
|
|
13
10
|
var _sessionEntity = require("../../common/session/session-entity");
|
|
14
11
|
var _localStorage = require("../../common/storage/local-storage.js");
|
|
15
12
|
var _constants = require("../../common/session/constants");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
agentIdentifier,
|
|
13
|
+
function setupAgentSession(agentRef) {
|
|
14
|
+
if (agentRef.runtime.session) return agentRef.runtime.session; // already setup
|
|
15
|
+
|
|
16
|
+
const sessionInit = agentRef.init.session;
|
|
17
|
+
agentRef.runtime.session = new _sessionEntity.SessionEntity({
|
|
18
|
+
agentIdentifier: agentRef.agentIdentifier,
|
|
23
19
|
key: _constants.DEFAULT_KEY,
|
|
24
20
|
storage: new _localStorage.LocalStorage(),
|
|
25
21
|
expiresMs: sessionInit?.expiresMs,
|
|
@@ -27,29 +23,28 @@ function setupAgentSession(agentIdentifier) {
|
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
// Retrieve & re-add all of the persisted setCustomAttribute|setUserId k-v from previous page load(s), if any was stored.
|
|
30
|
-
const customSessionData =
|
|
31
|
-
const agentInfo = (0, _info.getInfo)(agentIdentifier);
|
|
26
|
+
const customSessionData = agentRef.runtime.session.state.custom;
|
|
32
27
|
if (customSessionData) {
|
|
33
|
-
|
|
34
|
-
...
|
|
28
|
+
agentRef.info.jsAttributes = {
|
|
29
|
+
...agentRef.info.jsAttributes,
|
|
35
30
|
...customSessionData
|
|
36
31
|
};
|
|
37
32
|
}
|
|
38
|
-
const sharedEE = _contextualEe.ee.get(agentIdentifier);
|
|
33
|
+
const sharedEE = _contextualEe.ee.get(agentRef.agentIdentifier);
|
|
39
34
|
|
|
40
35
|
// any calls to newrelic.setCustomAttribute(<persisted>) will need to be added to:
|
|
41
36
|
// local info.jsAttributes {}
|
|
42
37
|
// the session's storage API
|
|
43
38
|
(0, _registerHandler.registerHandler)('api-setCustomAttribute', (time, key, value) => {
|
|
44
|
-
|
|
39
|
+
agentRef.runtime.session.syncCustomAttribute(key, value);
|
|
45
40
|
}, 'session', sharedEE);
|
|
46
41
|
|
|
47
42
|
// any calls to newrelic.setUserId(...) will need to be added to:
|
|
48
43
|
// local info.jsAttributes {}
|
|
49
44
|
// the session's storage API
|
|
50
45
|
(0, _registerHandler.registerHandler)('api-setUserId', (time, key, value) => {
|
|
51
|
-
|
|
46
|
+
agentRef.runtime.session.syncCustomAttribute(key, value);
|
|
52
47
|
}, 'session', sharedEE);
|
|
53
|
-
(0, _drain.drain)(agentIdentifier, 'session');
|
|
54
|
-
return
|
|
48
|
+
(0, _drain.drain)(agentRef.agentIdentifier, 'session');
|
|
49
|
+
return agentRef.runtime.session;
|
|
55
50
|
}
|
|
@@ -87,7 +87,7 @@ class InstrumentBase extends _featureBase.FeatureBase {
|
|
|
87
87
|
const {
|
|
88
88
|
setupAgentSession
|
|
89
89
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "session-manager" */'./agent-session')));
|
|
90
|
-
session = setupAgentSession(
|
|
90
|
+
session = setupAgentSession(agentRef);
|
|
91
91
|
}
|
|
92
92
|
} catch (e) {
|
|
93
93
|
(0, _console.warn)(20, e);
|
|
@@ -6,19 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.AgentBase = void 0;
|
|
7
7
|
var _console = require("../common/util/console");
|
|
8
8
|
var _constants = require("../features/session_replay/constants");
|
|
9
|
-
var
|
|
9
|
+
var _microAgentBase = require("./micro-agent-base");
|
|
10
10
|
/* eslint-disable n/handle-callback-err */
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
class AgentBase {
|
|
17
|
-
agentIdentifier;
|
|
18
|
-
constructor(agentIdentifier = (0, _uniqueId.generateRandomHexString)(16)) {
|
|
19
|
-
this.agentIdentifier = agentIdentifier;
|
|
20
|
-
}
|
|
21
|
-
|
|
16
|
+
class AgentBase extends _microAgentBase.MicroAgentBase {
|
|
22
17
|
/**
|
|
23
18
|
* Tries to execute the api and generates a generic warning message with the api name injected if unsuccessful
|
|
24
19
|
* @param {string} methodName
|
|
@@ -29,74 +24,11 @@ class AgentBase {
|
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
/**
|
|
32
|
-
*
|
|
33
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/
|
|
34
|
-
* @param {string} name Name or category of the action. Reported as the actionName attribute.
|
|
35
|
-
* @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.
|
|
36
|
-
*/
|
|
37
|
-
addPageAction(name, attributes) {
|
|
38
|
-
return this.#callMethod('addPageAction', name, attributes);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Groups page views to help URL structure or to capture the URL's routing information.
|
|
43
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
|
|
44
|
-
* @param {string} name The page name you want to use. Use alphanumeric characters.
|
|
45
|
-
* @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
|
|
46
|
-
*/
|
|
47
|
-
setPageViewName(name, host) {
|
|
48
|
-
return this.#callMethod('setPageViewName', name, host);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Adds a user-defined attribute name and value to subsequent events on the page.
|
|
53
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
|
|
54
|
-
* @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.
|
|
55
|
-
* @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.
|
|
56
|
-
* @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.
|
|
57
|
-
*/
|
|
58
|
-
setCustomAttribute(name, value, persist) {
|
|
59
|
-
return this.#callMethod('setCustomAttribute', name, value, persist);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Identifies a browser error without disrupting your app's operations.
|
|
64
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
|
|
65
|
-
* @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
|
|
66
|
-
* @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
|
|
67
|
-
*/
|
|
68
|
-
noticeError(error, customAttributes) {
|
|
69
|
-
return this.#callMethod('noticeError', error, customAttributes);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Adds a user-defined identifier string to subsequent events on the page.
|
|
74
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
|
|
75
|
-
* @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.
|
|
76
|
-
*/
|
|
77
|
-
setUserId(value) {
|
|
78
|
-
return this.#callMethod('setUserId', value);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Adds a user-defined application version string to subsequent events on the page.
|
|
83
|
-
* This decorates all payloads with an attribute of `application.version` which is queryable in NR1.
|
|
84
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setapplicationversion/}
|
|
85
|
-
* @param {string|null} value A string identifier for the application version, useful for
|
|
86
|
-
* tying all browser events to a specific release tag. The value parameter does not
|
|
87
|
-
* have to be unique. Passing a null value unsets any existing value.
|
|
88
|
-
*/
|
|
89
|
-
setApplicationVersion(value) {
|
|
90
|
-
return this.#callMethod('setApplicationVersion', value);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Allows selective ignoring and grouping of known errors that the browser agent captures.
|
|
95
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
|
|
96
|
-
* @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.
|
|
27
|
+
* Starts any and all features that are not running yet in "autoStart" mode
|
|
28
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
|
|
97
29
|
*/
|
|
98
|
-
|
|
99
|
-
return this.#callMethod('
|
|
30
|
+
start() {
|
|
31
|
+
return this.#callMethod('start');
|
|
100
32
|
}
|
|
101
33
|
|
|
102
34
|
/**
|
|
@@ -108,25 +40,6 @@ class AgentBase {
|
|
|
108
40
|
return this.#callMethod('finished', timeStamp);
|
|
109
41
|
}
|
|
110
42
|
|
|
111
|
-
/**
|
|
112
|
-
* Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
|
|
113
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
|
|
114
|
-
* @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
|
|
115
|
-
* @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.
|
|
116
|
-
*/
|
|
117
|
-
addRelease(name, id) {
|
|
118
|
-
return this.#callMethod('addRelease', name, id);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Starts a set of agent features if not running in "autoStart" mode
|
|
123
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
|
|
124
|
-
* @param {string|string[]} [featureNames] The name(s) of the features to start. If no name(s) are passed, all features will be started
|
|
125
|
-
*/
|
|
126
|
-
start(featureNames) {
|
|
127
|
-
return this.#callMethod('start', featureNames);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
43
|
/**
|
|
131
44
|
* Forces a replay to record. If a replay is already actively recording, this call will be ignored.
|
|
132
45
|
* 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.
|
|
@@ -182,16 +95,6 @@ class AgentBase {
|
|
|
182
95
|
return this.#callMethod('interaction');
|
|
183
96
|
}
|
|
184
97
|
|
|
185
|
-
/**
|
|
186
|
-
* Capture a single log.
|
|
187
|
-
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log/}
|
|
188
|
-
* @param {string} message String to be captured as log message
|
|
189
|
-
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
|
|
190
|
-
*/
|
|
191
|
-
log(message, options) {
|
|
192
|
-
return this.#callMethod('log', message, options);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
98
|
/**
|
|
196
99
|
* Wrap a logger function to capture a log each time the function is invoked with the message and arguments passed
|
|
197
100
|
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/wraplogger/}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MicroAgentBase = void 0;
|
|
7
|
+
var _console = require("../common/util/console");
|
|
8
|
+
var _uniqueId = require("../common/ids/unique-id");
|
|
9
|
+
class MicroAgentBase {
|
|
10
|
+
agentIdentifier;
|
|
11
|
+
constructor(agentIdentifier = (0, _uniqueId.generateRandomHexString)(16)) {
|
|
12
|
+
this.agentIdentifier = agentIdentifier;
|
|
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 (typeof this.api?.[methodName] !== 'function') (0, _console.warn)(35, methodName);else return this.api[methodName](...args);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// MicroAgent class custom defines its own start
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Reports a browser PageAction event along with a name and optional attributes.
|
|
28
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addpageaction/}
|
|
29
|
+
* @param {string} name Name or category of the action. Reported as the actionName attribute.
|
|
30
|
+
* @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.
|
|
31
|
+
*/
|
|
32
|
+
addPageAction(name, attributes) {
|
|
33
|
+
return this.#callMethod('addPageAction', name, attributes);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Groups page views to help URL structure or to capture the URL's routing information.
|
|
38
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setpageviewname/}
|
|
39
|
+
* @param {string} name The page name you want to use. Use alphanumeric characters.
|
|
40
|
+
* @param {string} [host] Default is http://custom.transaction. Typically set host to your site's domain URI.
|
|
41
|
+
*/
|
|
42
|
+
setPageViewName(name, host) {
|
|
43
|
+
return this.#callMethod('setPageViewName', name, host);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Adds a user-defined attribute name and value to subsequent events on the page.
|
|
48
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
|
|
49
|
+
* @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.
|
|
50
|
+
* @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.
|
|
51
|
+
* @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.
|
|
52
|
+
*/
|
|
53
|
+
setCustomAttribute(name, value, persist) {
|
|
54
|
+
return this.#callMethod('setCustomAttribute', name, value, persist);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Identifies a browser error without disrupting your app's operations.
|
|
59
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/noticeerror/}
|
|
60
|
+
* @param {Error|string} error Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page.
|
|
61
|
+
* @param {object} [customAttributes] An object containing name/value pairs representing custom attributes.
|
|
62
|
+
*/
|
|
63
|
+
noticeError(error, customAttributes) {
|
|
64
|
+
return this.#callMethod('noticeError', error, customAttributes);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Adds a user-defined identifier string to subsequent events on the page.
|
|
69
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setuserid/}
|
|
70
|
+
* @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.
|
|
71
|
+
*/
|
|
72
|
+
setUserId(value) {
|
|
73
|
+
return this.#callMethod('setUserId', value);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Adds a user-defined application version string to subsequent events on the page.
|
|
78
|
+
* This decorates all payloads with an attribute of `application.version` which is queryable in NR1.
|
|
79
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setapplicationversion/}
|
|
80
|
+
* @param {string|null} value A string identifier for the application version, useful for
|
|
81
|
+
* tying all browser events to a specific release tag. The value parameter does not
|
|
82
|
+
* have to be unique. Passing a null value unsets any existing value.
|
|
83
|
+
*/
|
|
84
|
+
setApplicationVersion(value) {
|
|
85
|
+
return this.#callMethod('setApplicationVersion', value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Allows selective ignoring and grouping of known errors that the browser agent captures.
|
|
90
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/seterrorhandler/}
|
|
91
|
+
* @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.
|
|
92
|
+
*/
|
|
93
|
+
setErrorHandler(callback) {
|
|
94
|
+
return this.#callMethod('setErrorHandler', callback);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Adds a unique name and ID to identify releases with multiple JavaScript bundles on the same page.
|
|
99
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/addrelease/}
|
|
100
|
+
* @param {string} name A short description of the component; for example, the name of a project, application, file, or library.
|
|
101
|
+
* @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.
|
|
102
|
+
*/
|
|
103
|
+
addRelease(name, id) {
|
|
104
|
+
return this.#callMethod('addRelease', name, id);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Capture a single log.
|
|
109
|
+
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/log/}
|
|
110
|
+
* @param {string} message String to be captured as log message
|
|
111
|
+
* @param {{customAttributes?: object, level?: 'ERROR'|'TRACE'|'DEBUG'|'INFO'|'WARN'}} [options] customAttributes defaults to `{}` if not assigned, level defaults to `info` if not assigned.
|
|
112
|
+
*/
|
|
113
|
+
log(message, options) {
|
|
114
|
+
return this.#callMethod('log', message, options);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.MicroAgentBase = MicroAgentBase;
|
|
@@ -8,13 +8,9 @@ var _instrument = require("../features/page_view_event/instrument");
|
|
|
8
8
|
var _enabledFeatures = require("./features/enabled-features");
|
|
9
9
|
var _configure = require("./configure/configure");
|
|
10
10
|
var _nreum = require("../common/window/nreum");
|
|
11
|
-
var _info = require("../common/config/info");
|
|
12
|
-
var _init = require("../common/config/init");
|
|
13
|
-
var _loaderConfig = require("../common/config/loader-config");
|
|
14
|
-
var _runtime = require("../common/config/runtime");
|
|
15
11
|
var _features = require("./features/features");
|
|
16
12
|
var _console = require("../common/util/console");
|
|
17
|
-
var
|
|
13
|
+
var _microAgentBase = require("./micro-agent-base");
|
|
18
14
|
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); }
|
|
19
15
|
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; } // loader files
|
|
20
16
|
// core files
|
|
@@ -25,7 +21,7 @@ const nonAutoFeatures = [_features.FEATURE_NAMES.jserrors, _features.FEATURE_NAM
|
|
|
25
21
|
* automatically instrument. Instead, each MicroAgent instance will lazy load the required features and can support loading multiple instances on one page.
|
|
26
22
|
* Out of the box, it can manually handle and report Page View, Page Action, and Error events.
|
|
27
23
|
*/
|
|
28
|
-
class MicroAgent extends
|
|
24
|
+
class MicroAgent extends _microAgentBase.MicroAgentBase {
|
|
29
25
|
/**
|
|
30
26
|
* @param {Object} options - Specifies features and runtime configuration,
|
|
31
27
|
* @param {string=} agentIdentifier - The optional unique ID of the agent.
|
|
@@ -45,61 +41,52 @@ class MicroAgent extends _agentBase.AgentBase {
|
|
|
45
41
|
/**
|
|
46
42
|
* Starts a set of agent features if not running in "autoStart" mode
|
|
47
43
|
* {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/start/}
|
|
48
|
-
* @param {string|string[]
|
|
44
|
+
* @param {string|string[]} [featureNames] The feature name(s) to start. If no name(s) are passed, all features will be started
|
|
49
45
|
*/
|
|
50
|
-
this.start =
|
|
51
|
-
|
|
46
|
+
this.start = featureNames => {
|
|
47
|
+
try {
|
|
48
|
+
if (featureNames === undefined || Array.isArray(featureNames) && featureNames.length === 0) featureNames = nonAutoFeatures;else if (typeof featureNames === 'string') featureNames = [featureNames];
|
|
49
|
+
if (featureNames.some(f => !nonAutoFeatures.includes(f))) (0, _console.warn)(37, nonAutoFeatures);
|
|
50
|
+
const enabledFeatures = (0, _enabledFeatures.getEnabledFeatures)(this.agentIdentifier);
|
|
51
|
+
try {
|
|
52
|
+
// a biproduct of doing this is that the "session manager" is automatically handled through importing this feature
|
|
53
|
+
this.features.page_view_event = new _instrument.Instrument(this);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
(0, _console.warn)(24, err);
|
|
56
|
+
}
|
|
57
|
+
this.features.page_view_event.onAggregateImported.then(() => {
|
|
58
|
+
/* The following features do not import an "instrument" file, meaning they are only hooked up to the API.
|
|
59
|
+
Since the missing instrument-base class handles drain-gating (racing behavior) and PVE handles some setup, these are chained until after PVE has finished initializing
|
|
60
|
+
so as to avoid the race condition of things like session and sharedAggregator not being ready by features that uses them right away. */
|
|
61
|
+
nonAutoFeatures.forEach(f => {
|
|
62
|
+
if (enabledFeatures[f] && featureNames.includes(f)) {
|
|
63
|
+
Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "lazy-feature-loader" */'../features/utils/lazy-feature-loader'))).then(({
|
|
64
|
+
lazyFeatureLoader
|
|
65
|
+
}) => {
|
|
66
|
+
return lazyFeatureLoader(f, 'aggregate');
|
|
67
|
+
}).then(({
|
|
68
|
+
Aggregate
|
|
69
|
+
}) => {
|
|
70
|
+
this.features[f] = new Aggregate(this);
|
|
71
|
+
}).catch(err => (0, _console.warn)(25, err));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return true;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
(0, _console.warn)(26, err);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
this.start(nonAutoFeatures.filter(featureName => !!this.init[featureName].autoStart));
|
|
52
82
|
}
|
|
53
83
|
get config() {
|
|
54
84
|
return {
|
|
55
|
-
info:
|
|
56
|
-
init:
|
|
57
|
-
loader_config:
|
|
58
|
-
runtime:
|
|
85
|
+
info: this.info,
|
|
86
|
+
init: this.init,
|
|
87
|
+
loader_config: this.loader_config,
|
|
88
|
+
runtime: this.runtime
|
|
59
89
|
};
|
|
60
90
|
}
|
|
61
|
-
run(features) {
|
|
62
|
-
try {
|
|
63
|
-
const featNames = nonAutoFeatures;
|
|
64
|
-
if (features === undefined) features = featNames;else {
|
|
65
|
-
features = Array.isArray(features) && features.length ? features : [features];
|
|
66
|
-
if (features.some(f => !featNames.includes(f))) return (0, _console.warn)(37, featNames);
|
|
67
|
-
if (!features.includes(_features.FEATURE_NAMES.pageViewEvent)) features.push(_features.FEATURE_NAMES.pageViewEvent);
|
|
68
|
-
}
|
|
69
|
-
} catch (err) {
|
|
70
|
-
(0, _console.warn)(23, err);
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
const enabledFeatures = (0, _enabledFeatures.getEnabledFeatures)(this.agentIdentifier);
|
|
74
|
-
try {
|
|
75
|
-
// a biproduct of doing this is that the "session manager" is automatically handled through importing this feature
|
|
76
|
-
this.features.page_view_event = new _instrument.Instrument(this);
|
|
77
|
-
} catch (err) {
|
|
78
|
-
(0, _console.warn)(24, err);
|
|
79
|
-
}
|
|
80
|
-
this.features.page_view_event.onAggregateImported.then(() => {
|
|
81
|
-
/* The following features do not import an "instrument" file, meaning they are only hooked up to the API.
|
|
82
|
-
Since the missing instrument-base class handles drain-gating (racing behavior) and PVE handles some setup, these are chained until after PVE has finished initializing
|
|
83
|
-
so as to avoid the race condition of things like session and sharedAggregator not being ready by features that uses them right away. */
|
|
84
|
-
nonAutoFeatures.forEach(f => {
|
|
85
|
-
if (enabledFeatures[f] && features.includes(f)) {
|
|
86
|
-
Promise.resolve().then(() => _interopRequireWildcard(require(/* webpackChunkName: "lazy-feature-loader" */'../features/utils/lazy-feature-loader'))).then(({
|
|
87
|
-
lazyFeatureLoader
|
|
88
|
-
}) => {
|
|
89
|
-
return lazyFeatureLoader(f, 'aggregate');
|
|
90
|
-
}).then(({
|
|
91
|
-
Aggregate
|
|
92
|
-
}) => {
|
|
93
|
-
this.features[f] = new Aggregate(this);
|
|
94
|
-
}).catch(err => (0, _console.warn)(25, err));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
return true;
|
|
99
|
-
} catch (err) {
|
|
100
|
-
(0, _console.warn)(26, err);
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
91
|
}
|
|
105
92
|
exports.MicroAgent = MicroAgent;
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { getInfo } from '../../common/config/info';
|
|
2
|
-
import { getConfiguration } from '../../common/config/init';
|
|
3
|
-
import { getRuntime } from '../../common/config/runtime';
|
|
4
1
|
import { drain } from '../../common/drain/drain';
|
|
5
2
|
import { ee } from '../../common/event-emitter/contextual-ee';
|
|
6
3
|
import { registerHandler } from '../../common/event-emitter/register-handler';
|
|
7
4
|
import { SessionEntity } from '../../common/session/session-entity';
|
|
8
5
|
import { LocalStorage } from '../../common/storage/local-storage.js';
|
|
9
6
|
import { DEFAULT_KEY } from '../../common/session/constants';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
agentIdentifier,
|
|
7
|
+
export function setupAgentSession(agentRef) {
|
|
8
|
+
if (agentRef.runtime.session) return agentRef.runtime.session; // already setup
|
|
9
|
+
|
|
10
|
+
const sessionInit = agentRef.init.session;
|
|
11
|
+
agentRef.runtime.session = new SessionEntity({
|
|
12
|
+
agentIdentifier: agentRef.agentIdentifier,
|
|
17
13
|
key: DEFAULT_KEY,
|
|
18
14
|
storage: new LocalStorage(),
|
|
19
15
|
expiresMs: sessionInit?.expiresMs,
|
|
@@ -21,29 +17,28 @@ export function setupAgentSession(agentIdentifier) {
|
|
|
21
17
|
});
|
|
22
18
|
|
|
23
19
|
// Retrieve & re-add all of the persisted setCustomAttribute|setUserId k-v from previous page load(s), if any was stored.
|
|
24
|
-
const customSessionData =
|
|
25
|
-
const agentInfo = getInfo(agentIdentifier);
|
|
20
|
+
const customSessionData = agentRef.runtime.session.state.custom;
|
|
26
21
|
if (customSessionData) {
|
|
27
|
-
|
|
28
|
-
...
|
|
22
|
+
agentRef.info.jsAttributes = {
|
|
23
|
+
...agentRef.info.jsAttributes,
|
|
29
24
|
...customSessionData
|
|
30
25
|
};
|
|
31
26
|
}
|
|
32
|
-
const sharedEE = ee.get(agentIdentifier);
|
|
27
|
+
const sharedEE = ee.get(agentRef.agentIdentifier);
|
|
33
28
|
|
|
34
29
|
// any calls to newrelic.setCustomAttribute(<persisted>) will need to be added to:
|
|
35
30
|
// local info.jsAttributes {}
|
|
36
31
|
// the session's storage API
|
|
37
32
|
registerHandler('api-setCustomAttribute', (time, key, value) => {
|
|
38
|
-
|
|
33
|
+
agentRef.runtime.session.syncCustomAttribute(key, value);
|
|
39
34
|
}, 'session', sharedEE);
|
|
40
35
|
|
|
41
36
|
// any calls to newrelic.setUserId(...) will need to be added to:
|
|
42
37
|
// local info.jsAttributes {}
|
|
43
38
|
// the session's storage API
|
|
44
39
|
registerHandler('api-setUserId', (time, key, value) => {
|
|
45
|
-
|
|
40
|
+
agentRef.runtime.session.syncCustomAttribute(key, value);
|
|
46
41
|
}, 'session', sharedEE);
|
|
47
|
-
drain(agentIdentifier, 'session');
|
|
48
|
-
return
|
|
42
|
+
drain(agentRef.agentIdentifier, 'session');
|
|
43
|
+
return agentRef.runtime.session;
|
|
49
44
|
}
|
|
@@ -82,7 +82,7 @@ export class InstrumentBase extends FeatureBase {
|
|
|
82
82
|
const {
|
|
83
83
|
setupAgentSession
|
|
84
84
|
} = await import(/* webpackChunkName: "session-manager" */'./agent-session');
|
|
85
|
-
session = setupAgentSession(
|
|
85
|
+
session = setupAgentSession(agentRef);
|
|
86
86
|
}
|
|
87
87
|
} catch (e) {
|
|
88
88
|
warn(20, e);
|