@newrelic/browser-agent 1.312.1-rc.0 → 1.312.1-rc.2
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/dist/cjs/common/config/init-types.js +3 -2
- package/dist/cjs/common/config/init.js +10 -8
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/util/v2.js +4 -4
- package/dist/cjs/interfaces/registered-entity.js +7 -20
- package/dist/cjs/loaders/api/register-api-types.js +3 -5
- package/dist/cjs/loaders/api/register.js +4 -18
- package/dist/esm/common/config/init-types.js +3 -2
- package/dist/esm/common/config/init.js +10 -8
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/util/v2.js +4 -4
- package/dist/esm/interfaces/registered-entity.js +7 -20
- package/dist/esm/loaders/api/register-api-types.js +3 -5
- package/dist/esm/loaders/api/register.js +4 -18
- package/dist/types/common/config/init-types.d.ts +10 -8
- package/dist/types/common/config/init-types.d.ts.map +1 -1
- package/dist/types/common/config/init.d.ts.map +1 -1
- package/dist/types/interfaces/registered-entity.d.ts +0 -10
- package/dist/types/interfaces/registered-entity.d.ts.map +1 -1
- package/dist/types/loaders/api/register-api-types.d.ts +4 -12
- package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/config/init-types.js +3 -2
- package/src/common/config/init.js +6 -4
- package/src/common/util/v2.js +4 -4
- package/src/interfaces/registered-entity.js +8 -20
- package/src/loaders/api/register-api-types.js +3 -5
- package/src/loaders/api/register.js +4 -14
|
@@ -17,8 +17,9 @@ exports.default = void 0;
|
|
|
17
17
|
* @property {boolean} [ajax.enabled] - Turn on/off the ajax feature (on by default).
|
|
18
18
|
* @property {boolean} [ajax.autoStart] - If true, the agent will automatically start the ajax feature. Otherwise, it will be in a deferred state until the `start` API method is called.
|
|
19
19
|
* @property {Object} [api]
|
|
20
|
-
* @property {
|
|
21
|
-
* @property {boolean} [api.
|
|
20
|
+
* @property {Object} [api.register]
|
|
21
|
+
* @property {boolean} [api.register.enabled] - If true, the agent will allow registered children to be sent to the server.
|
|
22
|
+
* @property {boolean} [api.register.duplicate_data_to_container] - If true, the agent will capture registered child data to the main agent as well as the registered child.
|
|
22
23
|
* @property {Object} [distributed_tracing]
|
|
23
24
|
* @property {boolean} [distributed_tracing.enabled] - If true, distributed tracing headers will be added to outgoing requests. Requires ajax feature to be running.
|
|
24
25
|
* @property {boolean} [distributed_tracing.exclude_newrelic_header]
|
|
@@ -27,7 +27,7 @@ const InitModelFn = () => {
|
|
|
27
27
|
const hiddenState = {
|
|
28
28
|
feature_flags: [],
|
|
29
29
|
experimental: {
|
|
30
|
-
|
|
30
|
+
register: false,
|
|
31
31
|
resources: false
|
|
32
32
|
},
|
|
33
33
|
mask_selector: '*',
|
|
@@ -60,13 +60,15 @@ const InitModelFn = () => {
|
|
|
60
60
|
autoStart: true
|
|
61
61
|
},
|
|
62
62
|
api: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
register: {
|
|
64
|
+
get enabled() {
|
|
65
|
+
return hiddenState.feature_flags.includes(_constants.FEATURE_FLAGS.REGISTER) || hiddenState.experimental.register;
|
|
66
|
+
},
|
|
67
|
+
set enabled(val) {
|
|
68
|
+
hiddenState.experimental.register = val;
|
|
69
|
+
},
|
|
70
|
+
duplicate_data_to_container: false
|
|
71
|
+
}
|
|
70
72
|
},
|
|
71
73
|
browser_consent_mode: {
|
|
72
74
|
enabled: false
|
|
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the version of the agent
|
|
19
19
|
*/
|
|
20
|
-
const VERSION = exports.VERSION = "1.312.1-rc.
|
|
20
|
+
const VERSION = exports.VERSION = "1.312.1-rc.2";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Exposes the build type of the agent
|
|
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the version of the agent
|
|
19
19
|
*/
|
|
20
|
-
const VERSION = exports.VERSION = "1.312.1-rc.
|
|
20
|
+
const VERSION = exports.VERSION = "1.312.1-rc.2";
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Exposes the build type of the agent
|
|
@@ -34,7 +34,7 @@ const V2_TYPES = exports.V2_TYPES = {
|
|
|
34
34
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
35
35
|
*/
|
|
36
36
|
function getRegisteredTargetsFromId(id, agentRef) {
|
|
37
|
-
if (!id || !agentRef?.init.api.
|
|
37
|
+
if (!id || !agentRef?.init.api.register.enabled) return [];
|
|
38
38
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
39
39
|
return registeredEntities?.filter(entity => String(entity.metadata.target.id) === String(id)).map(entity => entity.metadata.target) || [];
|
|
40
40
|
}
|
|
@@ -46,7 +46,7 @@ function getRegisteredTargetsFromId(id, agentRef) {
|
|
|
46
46
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
47
47
|
*/
|
|
48
48
|
function getRegisteredTargetsFromFilename(filename, agentRef) {
|
|
49
|
-
if (!filename || !agentRef?.init.api.
|
|
49
|
+
if (!filename || !agentRef?.init.api.register.enabled) return [];
|
|
50
50
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
51
51
|
return registeredEntities?.filter(entity => entity.metadata.timings?.asset?.endsWith(filename)).map(entity => entity.metadata.target) || [];
|
|
52
52
|
}
|
|
@@ -98,7 +98,7 @@ function getVersion2DuplicationAttributes(target, aggregateInstance) {
|
|
|
98
98
|
* @returns {boolean} returns true if the event should be duplicated for the target, false otherwise
|
|
99
99
|
*/
|
|
100
100
|
function shouldDuplicate(target, aggregateInstance) {
|
|
101
|
-
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.
|
|
101
|
+
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/**
|
|
@@ -107,7 +107,7 @@ function shouldDuplicate(target, aggregateInstance) {
|
|
|
107
107
|
* @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
|
|
108
108
|
*/
|
|
109
109
|
function findTargetsFromStackTrace(agentRef) {
|
|
110
|
-
if (!agentRef?.init.api.
|
|
110
|
+
if (!agentRef?.init.api.register.enabled) return [undefined];
|
|
111
111
|
const targets = [];
|
|
112
112
|
try {
|
|
113
113
|
var urls = (0, _scriptTracker.extractUrlsFromStack)((0, _scriptTracker.getDeepStackTrace)());
|
|
@@ -24,18 +24,18 @@ var _console = require("../common/util/console");
|
|
|
24
24
|
* An interface for registering an external caller to report through the base agent to a different target than the base agent.
|
|
25
25
|
*/
|
|
26
26
|
class RegisteredEntity {
|
|
27
|
-
/** @type {RegisterAPIMetadata} */
|
|
28
|
-
metadata = {
|
|
29
|
-
target: {},
|
|
30
|
-
timings: {},
|
|
31
|
-
customAttributes: {}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
27
|
/**
|
|
35
28
|
*
|
|
36
29
|
* @param {RegisterAPIConstructor} opts The options for setting up the registered entity.
|
|
37
30
|
*/
|
|
38
31
|
constructor(opts) {
|
|
32
|
+
// Initialize metadata as an own property to ensure it exists even when agent is missing
|
|
33
|
+
/** @type {RegisterAPIMetadata} */
|
|
34
|
+
this.metadata = {
|
|
35
|
+
target: (/** @type {import('../loaders/api/register-api-types').RegisterAPITarget} */{}),
|
|
36
|
+
timings: (/** @type {import('../loaders/api/register-api-types').RegisterAPITimings} */{}),
|
|
37
|
+
customAttributes: {}
|
|
38
|
+
};
|
|
39
39
|
try {
|
|
40
40
|
if (!window?.newrelic) return (0, _console.warn)(51);
|
|
41
41
|
Object.assign(this, window?.newrelic?.register(opts) || {});
|
|
@@ -55,19 +55,6 @@ class RegisteredEntity {
|
|
|
55
55
|
(0, _console.warn)(35, 'addPageAction');
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* @experimental
|
|
60
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
61
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
62
|
-
*
|
|
63
|
-
* Registers an external caller to report through the base agent to a different target than the base agent. Will be related to this registered entity when called through this access point.
|
|
64
|
-
* @param {import('../loaders/api/register-api-types').RegisterAPIConstructor} target the target object to report data to
|
|
65
|
-
@returns {import('../loaders/api/register-api-types').RegisterAPI} 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.
|
|
66
|
-
*/
|
|
67
|
-
register(target) {
|
|
68
|
-
(0, _console.warn)(35, 'register');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
58
|
/**
|
|
72
59
|
* @experimental
|
|
73
60
|
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
@@ -13,7 +13,6 @@ exports.default = void 0;
|
|
|
13
13
|
* @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
|
|
14
14
|
* @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
|
|
15
15
|
* @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
|
|
16
|
-
* @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
|
|
17
16
|
* @property {() => void} deregister - Deregister the registered entity, which blocks its use and captures end of life timings.
|
|
18
17
|
* @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
|
|
19
18
|
* @property {(eventType: string, options?: {start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}) => ({start: number, end: number, duration: number, customAttributes: object})} measure - Measures a task that is recorded as a BrowserPerformance event.
|
|
@@ -27,14 +26,14 @@ exports.default = void 0;
|
|
|
27
26
|
* @property {string} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
|
|
28
27
|
* @property {string} name - The readable name for the registered entity. This will be assigned to any synthesized entities.
|
|
29
28
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs. This will be assigned to any synthesized entities. Tags are converted to source.* attributes (e.g., {environment: 'production'} becomes source.environment: 'production').
|
|
30
|
-
* @property {
|
|
29
|
+
* @property {RegisterAPITarget} [parent] - The parent target for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
31
30
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
32
31
|
*/
|
|
33
32
|
/**
|
|
34
33
|
* @typedef {Object} RegisterAPIMetadata
|
|
35
34
|
* @property {Object} customAttributes - The custom attributes for the registered entity.
|
|
36
|
-
* @property {RegisterAPITimings} timings - The timing metrics for the registered entity.
|
|
37
|
-
* @property {RegisterAPITarget} target - The options for the registered entity.
|
|
35
|
+
* @property {Partial<RegisterAPITimings>} timings - The timing metrics for the registered entity.
|
|
36
|
+
* @property {Partial<RegisterAPITarget>} target - The options for the registered entity.
|
|
38
37
|
*/
|
|
39
38
|
/**
|
|
40
39
|
* @typedef {Object} RegisterAPITarget
|
|
@@ -42,7 +41,6 @@ exports.default = void 0;
|
|
|
42
41
|
* @property {string} name - The name returned for the registered entity.
|
|
43
42
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs.
|
|
44
43
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
45
|
-
* @property {boolean} [isolated] - When true, each registration creates an isolated instance. When false, multiple registrations with the same id and isolated: false will share a single instance, including all custom attributes, ids, names, and metadata. Calling deregister on a shared instance will deregister it for all entities using the instance. Defaults to true.
|
|
46
44
|
*/
|
|
47
45
|
/**
|
|
48
46
|
* @typedef {Object} RegisterAPITimings
|
|
@@ -48,10 +48,9 @@ function setupRegisterAPI(agent) {
|
|
|
48
48
|
* Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
|
|
49
49
|
* @param {Object} agentRef the reference to the base agent instance
|
|
50
50
|
* @param {import('./register-api-types').RegisterAPIConstructor} target
|
|
51
|
-
* @param {import('./register-api-types').RegisterAPIConstructor} [parent]
|
|
52
51
|
* @returns {RegisterAPI} the api object to be returned from the register api method
|
|
53
52
|
*/
|
|
54
|
-
function register(agentRef, target
|
|
53
|
+
function register(agentRef, target) {
|
|
55
54
|
(0, _console.warn)(54, 'newrelic.register');
|
|
56
55
|
target ||= {};
|
|
57
56
|
target.instance = (0, _uniqueId.generateRandomHexString)(8);
|
|
@@ -59,7 +58,7 @@ function register(agentRef, target, parent) {
|
|
|
59
58
|
target.licenseKey ||= agentRef.info.licenseKey; // will inherit the license key from the container agent if not provided for brevity. A future state may dictate that we need different license keys to do different things.
|
|
60
59
|
target.blocked = false;
|
|
61
60
|
if (typeof target.tags !== 'object' || target.tags === null || Array.isArray(target.tags)) target.tags = {};
|
|
62
|
-
target.parent
|
|
61
|
+
target.parent ??= {
|
|
63
62
|
get id() {
|
|
64
63
|
return agentRef.runtime.appMetadata.agents[0].entityGuid;
|
|
65
64
|
},
|
|
@@ -87,23 +86,11 @@ function register(agentRef, target, parent) {
|
|
|
87
86
|
attrs["source.".concat(key)] = value;
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
|
-
target.isolated ??= true;
|
|
91
89
|
|
|
92
90
|
/** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
|
|
93
91
|
let invalidApiResponse = () => {};
|
|
94
92
|
/** @type {Array} the array of registered target APIs */
|
|
95
93
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
96
|
-
if (!target.isolated) {
|
|
97
|
-
/** if we have already registered this non-isolated target, go ahead and re-use it */
|
|
98
|
-
const sharedEntity = registeredEntities.find(({
|
|
99
|
-
metadata: {
|
|
100
|
-
target: {
|
|
101
|
-
id
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}) => id === target.id && !target.isolated);
|
|
105
|
-
if (sharedEntity) return sharedEntity;
|
|
106
|
-
}
|
|
107
94
|
|
|
108
95
|
/**
|
|
109
96
|
* Block the API, and supply a warning function to display a message to end users
|
|
@@ -118,7 +105,7 @@ function register(agentRef, target, parent) {
|
|
|
118
105
|
}
|
|
119
106
|
|
|
120
107
|
/** primary cases that can block the register API from working at init time */
|
|
121
|
-
if (!agentRef.init.api.
|
|
108
|
+
if (!agentRef.init.api.register.enabled) block((0, _invoke.single)(() => (0, _console.warn)(55)));
|
|
122
109
|
if (!hasValidValue(target.id) || !hasValidValue(target.name)) block((0, _invoke.single)(() => (0, _console.warn)(48, target)));
|
|
123
110
|
|
|
124
111
|
/** @type {RegisterAPI} */
|
|
@@ -150,7 +137,6 @@ function register(agentRef, target, parent) {
|
|
|
150
137
|
...attrs,
|
|
151
138
|
...attributes
|
|
152
139
|
}, agentRef], target),
|
|
153
|
-
register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
|
|
154
140
|
recordCustomEvent: (eventType, attributes = {}) => report(_recordCustomEvent.recordCustomEvent, [eventType, {
|
|
155
141
|
...attrs,
|
|
156
142
|
...attributes
|
|
@@ -222,7 +208,7 @@ function register(agentRef, target, parent) {
|
|
|
222
208
|
|
|
223
209
|
/**
|
|
224
210
|
* The reporter method that will be used to report the data to the container agent's API method. If invalid, will log a warning and not execute.
|
|
225
|
-
* If the api.
|
|
211
|
+
* If the api.register.duplicate_data_to_container configuration value is set to true, the data will be reported to BOTH the container and the external target
|
|
226
212
|
* @param {*} methodToCall the container agent's API method to call
|
|
227
213
|
* @param {*} args the arguments to supply to the container agent's API method
|
|
228
214
|
* @param {string} target the target to report the data to. If undefined, will report to the container agent's target.
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
* @property {boolean} [ajax.enabled] - Turn on/off the ajax feature (on by default).
|
|
13
13
|
* @property {boolean} [ajax.autoStart] - If true, the agent will automatically start the ajax feature. Otherwise, it will be in a deferred state until the `start` API method is called.
|
|
14
14
|
* @property {Object} [api]
|
|
15
|
-
* @property {
|
|
16
|
-
* @property {boolean} [api.
|
|
15
|
+
* @property {Object} [api.register]
|
|
16
|
+
* @property {boolean} [api.register.enabled] - If true, the agent will allow registered children to be sent to the server.
|
|
17
|
+
* @property {boolean} [api.register.duplicate_data_to_container] - If true, the agent will capture registered child data to the main agent as well as the registered child.
|
|
17
18
|
* @property {Object} [distributed_tracing]
|
|
18
19
|
* @property {boolean} [distributed_tracing.enabled] - If true, distributed tracing headers will be added to outgoing requests. Requires ajax feature to be running.
|
|
19
20
|
* @property {boolean} [distributed_tracing.exclude_newrelic_header]
|
|
@@ -21,7 +21,7 @@ const InitModelFn = () => {
|
|
|
21
21
|
const hiddenState = {
|
|
22
22
|
feature_flags: [],
|
|
23
23
|
experimental: {
|
|
24
|
-
|
|
24
|
+
register: false,
|
|
25
25
|
resources: false
|
|
26
26
|
},
|
|
27
27
|
mask_selector: '*',
|
|
@@ -54,13 +54,15 @@ const InitModelFn = () => {
|
|
|
54
54
|
autoStart: true
|
|
55
55
|
},
|
|
56
56
|
api: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
register: {
|
|
58
|
+
get enabled() {
|
|
59
|
+
return hiddenState.feature_flags.includes(FEATURE_FLAGS.REGISTER) || hiddenState.experimental.register;
|
|
60
|
+
},
|
|
61
|
+
set enabled(val) {
|
|
62
|
+
hiddenState.experimental.register = val;
|
|
63
|
+
},
|
|
64
|
+
duplicate_data_to_container: false
|
|
65
|
+
}
|
|
64
66
|
},
|
|
65
67
|
browser_consent_mode: {
|
|
66
68
|
enabled: false
|
|
@@ -23,7 +23,7 @@ export const V2_TYPES = {
|
|
|
23
23
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
24
24
|
*/
|
|
25
25
|
export function getRegisteredTargetsFromId(id, agentRef) {
|
|
26
|
-
if (!id || !agentRef?.init.api.
|
|
26
|
+
if (!id || !agentRef?.init.api.register.enabled) return [];
|
|
27
27
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
28
28
|
return registeredEntities?.filter(entity => String(entity.metadata.target.id) === String(id)).map(entity => entity.metadata.target) || [];
|
|
29
29
|
}
|
|
@@ -35,7 +35,7 @@ export function getRegisteredTargetsFromId(id, agentRef) {
|
|
|
35
35
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
36
36
|
*/
|
|
37
37
|
export function getRegisteredTargetsFromFilename(filename, agentRef) {
|
|
38
|
-
if (!filename || !agentRef?.init.api.
|
|
38
|
+
if (!filename || !agentRef?.init.api.register.enabled) return [];
|
|
39
39
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
40
40
|
return registeredEntities?.filter(entity => entity.metadata.timings?.asset?.endsWith(filename)).map(entity => entity.metadata.target) || [];
|
|
41
41
|
}
|
|
@@ -87,7 +87,7 @@ export function getVersion2DuplicationAttributes(target, aggregateInstance) {
|
|
|
87
87
|
* @returns {boolean} returns true if the event should be duplicated for the target, false otherwise
|
|
88
88
|
*/
|
|
89
89
|
export function shouldDuplicate(target, aggregateInstance) {
|
|
90
|
-
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.
|
|
90
|
+
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
@@ -96,7 +96,7 @@ export function shouldDuplicate(target, aggregateInstance) {
|
|
|
96
96
|
* @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
|
|
97
97
|
*/
|
|
98
98
|
export function findTargetsFromStackTrace(agentRef) {
|
|
99
|
-
if (!agentRef?.init.api.
|
|
99
|
+
if (!agentRef?.init.api.register.enabled) return [undefined];
|
|
100
100
|
const targets = [];
|
|
101
101
|
try {
|
|
102
102
|
var urls = extractUrlsFromStack(getDeepStackTrace());
|
|
@@ -18,18 +18,18 @@ import { warn } from '../common/util/console';
|
|
|
18
18
|
* An interface for registering an external caller to report through the base agent to a different target than the base agent.
|
|
19
19
|
*/
|
|
20
20
|
export class RegisteredEntity {
|
|
21
|
-
/** @type {RegisterAPIMetadata} */
|
|
22
|
-
metadata = {
|
|
23
|
-
target: {},
|
|
24
|
-
timings: {},
|
|
25
|
-
customAttributes: {}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
21
|
/**
|
|
29
22
|
*
|
|
30
23
|
* @param {RegisterAPIConstructor} opts The options for setting up the registered entity.
|
|
31
24
|
*/
|
|
32
25
|
constructor(opts) {
|
|
26
|
+
// Initialize metadata as an own property to ensure it exists even when agent is missing
|
|
27
|
+
/** @type {RegisterAPIMetadata} */
|
|
28
|
+
this.metadata = {
|
|
29
|
+
target: (/** @type {import('../loaders/api/register-api-types').RegisterAPITarget} */{}),
|
|
30
|
+
timings: (/** @type {import('../loaders/api/register-api-types').RegisterAPITimings} */{}),
|
|
31
|
+
customAttributes: {}
|
|
32
|
+
};
|
|
33
33
|
try {
|
|
34
34
|
if (!window?.newrelic) return warn(51);
|
|
35
35
|
Object.assign(this, window?.newrelic?.register(opts) || {});
|
|
@@ -49,19 +49,6 @@ export class RegisteredEntity {
|
|
|
49
49
|
warn(35, 'addPageAction');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
/**
|
|
53
|
-
* @experimental
|
|
54
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
55
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
56
|
-
*
|
|
57
|
-
* Registers an external caller to report through the base agent to a different target than the base agent. Will be related to this registered entity when called through this access point.
|
|
58
|
-
* @param {import('../loaders/api/register-api-types').RegisterAPIConstructor} target the target object to report data to
|
|
59
|
-
@returns {import('../loaders/api/register-api-types').RegisterAPI} 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.
|
|
60
|
-
*/
|
|
61
|
-
register(target) {
|
|
62
|
-
warn(35, 'register');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
52
|
/**
|
|
66
53
|
* @experimental
|
|
67
54
|
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
|
|
9
9
|
* @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
|
|
10
10
|
* @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
|
|
11
|
-
* @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
|
|
12
11
|
* @property {() => void} deregister - Deregister the registered entity, which blocks its use and captures end of life timings.
|
|
13
12
|
* @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
|
|
14
13
|
* @property {(eventType: string, options?: {start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}) => ({start: number, end: number, duration: number, customAttributes: object})} measure - Measures a task that is recorded as a BrowserPerformance event.
|
|
@@ -23,15 +22,15 @@
|
|
|
23
22
|
* @property {string} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
|
|
24
23
|
* @property {string} name - The readable name for the registered entity. This will be assigned to any synthesized entities.
|
|
25
24
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs. This will be assigned to any synthesized entities. Tags are converted to source.* attributes (e.g., {environment: 'production'} becomes source.environment: 'production').
|
|
26
|
-
* @property {
|
|
25
|
+
* @property {RegisterAPITarget} [parent] - The parent target for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
27
26
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* @typedef {Object} RegisterAPIMetadata
|
|
32
31
|
* @property {Object} customAttributes - The custom attributes for the registered entity.
|
|
33
|
-
* @property {RegisterAPITimings} timings - The timing metrics for the registered entity.
|
|
34
|
-
* @property {RegisterAPITarget} target - The options for the registered entity.
|
|
32
|
+
* @property {Partial<RegisterAPITimings>} timings - The timing metrics for the registered entity.
|
|
33
|
+
* @property {Partial<RegisterAPITarget>} target - The options for the registered entity.
|
|
35
34
|
*/
|
|
36
35
|
|
|
37
36
|
/**
|
|
@@ -40,7 +39,6 @@
|
|
|
40
39
|
* @property {string} name - The name returned for the registered entity.
|
|
41
40
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs.
|
|
42
41
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
43
|
-
* @property {boolean} [isolated] - When true, each registration creates an isolated instance. When false, multiple registrations with the same id and isolated: false will share a single instance, including all custom attributes, ids, names, and metadata. Calling deregister on a shared instance will deregister it for all entities using the instance. Defaults to true.
|
|
44
42
|
*/
|
|
45
43
|
|
|
46
44
|
/**
|
|
@@ -42,10 +42,9 @@ export function setupRegisterAPI(agent) {
|
|
|
42
42
|
* Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
|
|
43
43
|
* @param {Object} agentRef the reference to the base agent instance
|
|
44
44
|
* @param {import('./register-api-types').RegisterAPIConstructor} target
|
|
45
|
-
* @param {import('./register-api-types').RegisterAPIConstructor} [parent]
|
|
46
45
|
* @returns {RegisterAPI} the api object to be returned from the register api method
|
|
47
46
|
*/
|
|
48
|
-
function register(agentRef, target
|
|
47
|
+
function register(agentRef, target) {
|
|
49
48
|
warn(54, 'newrelic.register');
|
|
50
49
|
target ||= {};
|
|
51
50
|
target.instance = generateRandomHexString(8);
|
|
@@ -53,7 +52,7 @@ function register(agentRef, target, parent) {
|
|
|
53
52
|
target.licenseKey ||= agentRef.info.licenseKey; // will inherit the license key from the container agent if not provided for brevity. A future state may dictate that we need different license keys to do different things.
|
|
54
53
|
target.blocked = false;
|
|
55
54
|
if (typeof target.tags !== 'object' || target.tags === null || Array.isArray(target.tags)) target.tags = {};
|
|
56
|
-
target.parent
|
|
55
|
+
target.parent ??= {
|
|
57
56
|
get id() {
|
|
58
57
|
return agentRef.runtime.appMetadata.agents[0].entityGuid;
|
|
59
58
|
},
|
|
@@ -81,23 +80,11 @@ function register(agentRef, target, parent) {
|
|
|
81
80
|
attrs["source.".concat(key)] = value;
|
|
82
81
|
}
|
|
83
82
|
});
|
|
84
|
-
target.isolated ??= true;
|
|
85
83
|
|
|
86
84
|
/** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
|
|
87
85
|
let invalidApiResponse = () => {};
|
|
88
86
|
/** @type {Array} the array of registered target APIs */
|
|
89
87
|
const registeredEntities = agentRef.runtime.registeredEntities;
|
|
90
|
-
if (!target.isolated) {
|
|
91
|
-
/** if we have already registered this non-isolated target, go ahead and re-use it */
|
|
92
|
-
const sharedEntity = registeredEntities.find(({
|
|
93
|
-
metadata: {
|
|
94
|
-
target: {
|
|
95
|
-
id
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}) => id === target.id && !target.isolated);
|
|
99
|
-
if (sharedEntity) return sharedEntity;
|
|
100
|
-
}
|
|
101
88
|
|
|
102
89
|
/**
|
|
103
90
|
* Block the API, and supply a warning function to display a message to end users
|
|
@@ -112,7 +99,7 @@ function register(agentRef, target, parent) {
|
|
|
112
99
|
}
|
|
113
100
|
|
|
114
101
|
/** primary cases that can block the register API from working at init time */
|
|
115
|
-
if (!agentRef.init.api.
|
|
102
|
+
if (!agentRef.init.api.register.enabled) block(single(() => warn(55)));
|
|
116
103
|
if (!hasValidValue(target.id) || !hasValidValue(target.name)) block(single(() => warn(48, target)));
|
|
117
104
|
|
|
118
105
|
/** @type {RegisterAPI} */
|
|
@@ -144,7 +131,6 @@ function register(agentRef, target, parent) {
|
|
|
144
131
|
...attrs,
|
|
145
132
|
...attributes
|
|
146
133
|
}, agentRef], target),
|
|
147
|
-
register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
|
|
148
134
|
recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, {
|
|
149
135
|
...attrs,
|
|
150
136
|
...attributes
|
|
@@ -216,7 +202,7 @@ function register(agentRef, target, parent) {
|
|
|
216
202
|
|
|
217
203
|
/**
|
|
218
204
|
* The reporter method that will be used to report the data to the container agent's API method. If invalid, will log a warning and not execute.
|
|
219
|
-
* If the api.
|
|
205
|
+
* If the api.register.duplicate_data_to_container configuration value is set to true, the data will be reported to BOTH the container and the external target
|
|
220
206
|
* @param {*} methodToCall the container agent's API method to call
|
|
221
207
|
* @param {*} args the arguments to supply to the container agent's API method
|
|
222
208
|
* @param {string} target the target to report the data to. If undefined, will report to the container agent's target.
|
|
@@ -20,14 +20,16 @@ export type Init = {
|
|
|
20
20
|
autoStart?: boolean | undefined;
|
|
21
21
|
} | undefined;
|
|
22
22
|
api?: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
register?: {
|
|
24
|
+
/**
|
|
25
|
+
* - If true, the agent will allow registered children to be sent to the server.
|
|
26
|
+
*/
|
|
27
|
+
enabled?: boolean | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* - If true, the agent will capture registered child data to the main agent as well as the registered child.
|
|
30
|
+
*/
|
|
31
|
+
duplicate_data_to_container?: boolean | undefined;
|
|
32
|
+
} | undefined;
|
|
31
33
|
} | undefined;
|
|
32
34
|
distributed_tracing?: {
|
|
33
35
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-types.d.ts","sourceRoot":"","sources":["../../../../src/common/config/init-types.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init-types.d.ts","sourceRoot":"","sources":["../../../../src/common/config/init-types.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAsCsB,MAAM,GAAG,MAAM;qBAAe,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/config/init.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../../src/common/config/init.js"],"names":[],"mappings":"AA+IO,0CAEN;mBAtIY,OAAO,cAAc,EAAE,IAAI"}
|
|
@@ -25,16 +25,6 @@ export class RegisteredEntity {
|
|
|
25
25
|
* @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.
|
|
26
26
|
*/
|
|
27
27
|
addPageAction(name: string, attributes?: object): void;
|
|
28
|
-
/**
|
|
29
|
-
* @experimental
|
|
30
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
31
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
32
|
-
*
|
|
33
|
-
* Registers an external caller to report through the base agent to a different target than the base agent. Will be related to this registered entity when called through this access point.
|
|
34
|
-
* @param {import('../loaders/api/register-api-types').RegisterAPIConstructor} target the target object to report data to
|
|
35
|
-
@returns {import('../loaders/api/register-api-types').RegisterAPI} 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.
|
|
36
|
-
*/
|
|
37
|
-
register(target: import("../loaders/api/register-api-types").RegisterAPIConstructor): import("../loaders/api/register-api-types").RegisterAPI;
|
|
38
28
|
/**
|
|
39
29
|
* @experimental
|
|
40
30
|
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registered-entity.d.ts","sourceRoot":"","sources":["../../../src/interfaces/registered-entity.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH;;;;;;GAMG;AACH;
|
|
1
|
+
{"version":3,"file":"registered-entity.d.ts","sourceRoot":"","sources":["../../../src/interfaces/registered-entity.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH;;;;;;GAMG;AACH;IACE;;;OAGG;IACH,kBAFW,sBAAsB,EAiBhC;IAbC,kCAAkC;IAClC,UADW,mBAAmB,CAK7B;IAUH;;;;;OAKG;IACH,oBAHW,MAAM,eACN,MAAM,QAKhB;IAED;;;;;;;OAOG;IACH,cAFa,IAAI,CAIhB;IAED;;;;;SAKK;IACL,6BAHa,MAAM,eACN,MAAM,QAIlB;IAED;;;;;;OAMG;IACH,cAJW,MAAM,YACN;QAAC,KAAK,CAAC,EAAE,MAAM,GAAC,eAAe,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAC,eAAe,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAC,GACvF;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,CAIpF;IAED;;;;;;OAMG;IACH,yBAJW,MAAM,SACN,MAAM,GAAC,MAAM,GAAC,OAAO,GAAC,IAAI,YAC1B,OAAO,QAKjB;IAED;;;;;OAKG;IACH,mBAHW,KAAK,GAAC,MAAM,qBACZ,MAAM,QAKhB;IAED;;;;;OAKG;IACH,iBAHW,MAAM,GAAC,IAAI,iBACX,OAAO,QAKjB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,IAAI,QAOrB;IAED;;;;;MAKE;IACF,aAHW,MAAM,YACN;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,MAAM,GAAC,MAAM,CAAA;KAAC,QAKpF;CACF;0BAvIY,OAAO,mCAAmC,EAAE,WAAW;kCACvD,OAAO,mCAAmC,EAAE,mBAAmB;qCAC/D,OAAO,mCAAmC,EAAE,sBAAsB"}
|
|
@@ -16,10 +16,6 @@ export type RegisterAPI = {
|
|
|
16
16
|
* - Notice an error for the registered entity.
|
|
17
17
|
*/
|
|
18
18
|
noticeError: (error: Error | string, customAttributes?: object) => void;
|
|
19
|
-
/**
|
|
20
|
-
* - Record a custom event for the registered entity.
|
|
21
|
-
*/
|
|
22
|
-
register: (target: RegisterAPIConstructor) => RegisterAPI;
|
|
23
19
|
/**
|
|
24
20
|
* - Deregister the registered entity, which blocks its use and captures end of life timings.
|
|
25
21
|
*/
|
|
@@ -74,9 +70,9 @@ export type RegisterAPIConstructor = {
|
|
|
74
70
|
[key: string]: any;
|
|
75
71
|
} | undefined;
|
|
76
72
|
/**
|
|
77
|
-
* -
|
|
73
|
+
* - The parent target for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
78
74
|
*/
|
|
79
|
-
|
|
75
|
+
parent?: RegisterAPITarget | undefined;
|
|
80
76
|
/**
|
|
81
77
|
* - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
82
78
|
*/
|
|
@@ -90,11 +86,11 @@ export type RegisterAPIMetadata = {
|
|
|
90
86
|
/**
|
|
91
87
|
* - The timing metrics for the registered entity.
|
|
92
88
|
*/
|
|
93
|
-
timings: RegisterAPITimings
|
|
89
|
+
timings: Partial<RegisterAPITimings>;
|
|
94
90
|
/**
|
|
95
91
|
* - The options for the registered entity.
|
|
96
92
|
*/
|
|
97
|
-
target: RegisterAPITarget
|
|
93
|
+
target: Partial<RegisterAPITarget>;
|
|
98
94
|
};
|
|
99
95
|
export type RegisterAPITarget = {
|
|
100
96
|
/**
|
|
@@ -115,10 +111,6 @@ export type RegisterAPITarget = {
|
|
|
115
111
|
* - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
116
112
|
*/
|
|
117
113
|
parentId?: string | undefined;
|
|
118
|
-
/**
|
|
119
|
-
* - When true, each registration creates an isolated instance. When false, multiple registrations with the same id and isolated: false will share a single instance, including all custom attributes, ids, names, and metadata. Calling deregister on a shared instance will deregister it for all entities using the instance. Defaults to true.
|
|
120
|
-
*/
|
|
121
|
-
isolated?: boolean | undefined;
|
|
122
114
|
};
|
|
123
115
|
export type RegisterAPITimings = {
|
|
124
116
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-api-types.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api-types.js"],"names":[],"mappings":";;;;;;mBAOc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;SAC3C,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;KAAC,KAAK,IAAI;;;;iBACxH,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,KAAK,IAAI;;;;
|
|
1
|
+
{"version":3,"file":"register-api-types.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api-types.js"],"names":[],"mappings":";;;;;;mBAOc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;SAC3C,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;KAAC,KAAK,IAAI;;;;iBACxH,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,KAAK,IAAI;;;;gBAC1D,MAAM,IAAI;;;;uBACV,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;aAChD,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,CAAC,EAAE,MAAM,GAAC,eAAe,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,GAAC,eAAe,CAAC;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;KAAC,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,CAAC;;;;2BACtM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;wBAC9B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI;;;;eAClF,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,YAAY,CAAC,EAAE,OAAO,KAAK,IAAI;;;;cACtD,mBAAmB;;;;;;QAKnB,MAAM;;;;UACN,MAAM;;;;;;;;;;;;;;;;;;;;sBAQN,MAAM;;;;aACN,OAAO,CAAC,kBAAkB,CAAC;;;;YAC3B,OAAO,CAAC,iBAAiB,CAAC;;;;;;QAK1B,MAAM;;;;UACN,MAAM;;;;;;;;;;;;;;;;kBAON,MAAM;;;;;;;;gBAEN,MAAM;;;;cACN,MAAM;;;;;;;;UAEN,MAAM"}
|
package/package.json
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
* @property {boolean} [ajax.enabled] - Turn on/off the ajax feature (on by default).
|
|
13
13
|
* @property {boolean} [ajax.autoStart] - If true, the agent will automatically start the ajax feature. Otherwise, it will be in a deferred state until the `start` API method is called.
|
|
14
14
|
* @property {Object} [api]
|
|
15
|
-
* @property {
|
|
16
|
-
* @property {boolean} [api.
|
|
15
|
+
* @property {Object} [api.register]
|
|
16
|
+
* @property {boolean} [api.register.enabled] - If true, the agent will allow registered children to be sent to the server.
|
|
17
|
+
* @property {boolean} [api.register.duplicate_data_to_container] - If true, the agent will capture registered child data to the main agent as well as the registered child.
|
|
17
18
|
* @property {Object} [distributed_tracing]
|
|
18
19
|
* @property {boolean} [distributed_tracing.enabled] - If true, distributed tracing headers will be added to outgoing requests. Requires ajax feature to be running.
|
|
19
20
|
* @property {boolean} [distributed_tracing.exclude_newrelic_header]
|
|
@@ -21,7 +21,7 @@ const InitModelFn = () => {
|
|
|
21
21
|
const hiddenState = {
|
|
22
22
|
feature_flags: [],
|
|
23
23
|
experimental: {
|
|
24
|
-
|
|
24
|
+
register: false,
|
|
25
25
|
resources: false
|
|
26
26
|
},
|
|
27
27
|
mask_selector: '*',
|
|
@@ -49,9 +49,11 @@ const InitModelFn = () => {
|
|
|
49
49
|
return {
|
|
50
50
|
ajax: { deny_list: undefined, block_internal: true, enabled: true, autoStart: true },
|
|
51
51
|
api: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
register: {
|
|
53
|
+
get enabled () { return hiddenState.feature_flags.includes(FEATURE_FLAGS.REGISTER) || hiddenState.experimental.register },
|
|
54
|
+
set enabled (val) { hiddenState.experimental.register = val },
|
|
55
|
+
duplicate_data_to_container: false
|
|
56
|
+
}
|
|
55
57
|
},
|
|
56
58
|
browser_consent_mode: { enabled: false },
|
|
57
59
|
distributed_tracing: {
|
package/src/common/util/v2.js
CHANGED
|
@@ -23,7 +23,7 @@ export const V2_TYPES = {
|
|
|
23
23
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
24
24
|
*/
|
|
25
25
|
export function getRegisteredTargetsFromId (id, agentRef) {
|
|
26
|
-
if (!id || !agentRef?.init.api.
|
|
26
|
+
if (!id || !agentRef?.init.api.register.enabled) return []
|
|
27
27
|
const registeredEntities = agentRef.runtime.registeredEntities
|
|
28
28
|
return registeredEntities?.filter(entity => String(entity.metadata.target.id) === String(id)).map(entity => entity.metadata.target) || []
|
|
29
29
|
}
|
|
@@ -35,7 +35,7 @@ export function getRegisteredTargetsFromId (id, agentRef) {
|
|
|
35
35
|
* @returns {import("../../interfaces/registered-entity").RegisterAPIMetadataTarget[]}
|
|
36
36
|
*/
|
|
37
37
|
export function getRegisteredTargetsFromFilename (filename, agentRef) {
|
|
38
|
-
if (!filename || !agentRef?.init.api.
|
|
38
|
+
if (!filename || !agentRef?.init.api.register.enabled) return []
|
|
39
39
|
const registeredEntities = agentRef.runtime.registeredEntities
|
|
40
40
|
return registeredEntities?.filter(entity => entity.metadata.timings?.asset?.endsWith(filename)).map(entity => entity.metadata.target) || []
|
|
41
41
|
}
|
|
@@ -83,7 +83,7 @@ export function getVersion2DuplicationAttributes (target, aggregateInstance) {
|
|
|
83
83
|
* @returns {boolean} returns true if the event should be duplicated for the target, false otherwise
|
|
84
84
|
*/
|
|
85
85
|
export function shouldDuplicate (target, aggregateInstance) {
|
|
86
|
-
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.
|
|
86
|
+
return !!target && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
@@ -92,7 +92,7 @@ export function shouldDuplicate (target, aggregateInstance) {
|
|
|
92
92
|
* @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array with undefined.
|
|
93
93
|
*/
|
|
94
94
|
export function findTargetsFromStackTrace (agentRef) {
|
|
95
|
-
if (!agentRef?.init.api.
|
|
95
|
+
if (!agentRef?.init.api.register.enabled) return [undefined]
|
|
96
96
|
|
|
97
97
|
const targets = []
|
|
98
98
|
try {
|
|
@@ -18,18 +18,19 @@ import { warn } from '../common/util/console'
|
|
|
18
18
|
* An interface for registering an external caller to report through the base agent to a different target than the base agent.
|
|
19
19
|
*/
|
|
20
20
|
export class RegisteredEntity {
|
|
21
|
-
/** @type {RegisterAPIMetadata} */
|
|
22
|
-
metadata = {
|
|
23
|
-
target: {},
|
|
24
|
-
timings: {},
|
|
25
|
-
customAttributes: {}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
21
|
/**
|
|
29
22
|
*
|
|
30
23
|
* @param {RegisterAPIConstructor} opts The options for setting up the registered entity.
|
|
31
24
|
*/
|
|
32
25
|
constructor (opts) {
|
|
26
|
+
// Initialize metadata as an own property to ensure it exists even when agent is missing
|
|
27
|
+
/** @type {RegisterAPIMetadata} */
|
|
28
|
+
this.metadata = {
|
|
29
|
+
target: /** @type {import('../loaders/api/register-api-types').RegisterAPITarget} */ ({}),
|
|
30
|
+
timings: /** @type {import('../loaders/api/register-api-types').RegisterAPITimings} */ ({}),
|
|
31
|
+
customAttributes: {}
|
|
32
|
+
}
|
|
33
|
+
|
|
33
34
|
try {
|
|
34
35
|
if (!window?.newrelic) return warn(51)
|
|
35
36
|
Object.assign(this, window?.newrelic?.register(opts) || {})
|
|
@@ -49,19 +50,6 @@ export class RegisteredEntity {
|
|
|
49
50
|
warn(35, 'addPageAction')
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
/**
|
|
53
|
-
* @experimental
|
|
54
|
-
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
55
|
-
* It is not recommended for use in production environments and will not receive support for issues.
|
|
56
|
-
*
|
|
57
|
-
* Registers an external caller to report through the base agent to a different target than the base agent. Will be related to this registered entity when called through this access point.
|
|
58
|
-
* @param {import('../loaders/api/register-api-types').RegisterAPIConstructor} target the target object to report data to
|
|
59
|
-
@returns {import('../loaders/api/register-api-types').RegisterAPI} 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.
|
|
60
|
-
*/
|
|
61
|
-
register (target) {
|
|
62
|
-
warn(35, 'register')
|
|
63
|
-
}
|
|
64
|
-
|
|
65
53
|
/**
|
|
66
54
|
* @experimental
|
|
67
55
|
* IMPORTANT: This feature is being developed for use internally and is not in a public-facing production-ready state.
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
* @property {(name: string, attributes?: object) => void} addPageAction - Add a page action for the registered entity.
|
|
9
9
|
* @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
|
|
10
10
|
* @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
|
|
11
|
-
* @property {(target: RegisterAPIConstructor) => RegisterAPI} register - Record a custom event for the registered entity.
|
|
12
11
|
* @property {() => void} deregister - Deregister the registered entity, which blocks its use and captures end of life timings.
|
|
13
12
|
* @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
|
|
14
13
|
* @property {(eventType: string, options?: {start?: number|PerformanceMark, end?: number|PerformanceMark, customAttributes?: object}) => ({start: number, end: number, duration: number, customAttributes: object})} measure - Measures a task that is recorded as a BrowserPerformance event.
|
|
@@ -23,15 +22,15 @@
|
|
|
23
22
|
* @property {string} id - The unique id for the registered entity. This will be assigned to any synthesized entities.
|
|
24
23
|
* @property {string} name - The readable name for the registered entity. This will be assigned to any synthesized entities.
|
|
25
24
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs. This will be assigned to any synthesized entities. Tags are converted to source.* attributes (e.g., {environment: 'production'} becomes source.environment: 'production').
|
|
26
|
-
* @property {
|
|
25
|
+
* @property {RegisterAPITarget} [parent] - The parent target for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
27
26
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
29
|
/**
|
|
31
30
|
* @typedef {Object} RegisterAPIMetadata
|
|
32
31
|
* @property {Object} customAttributes - The custom attributes for the registered entity.
|
|
33
|
-
* @property {RegisterAPITimings} timings - The timing metrics for the registered entity.
|
|
34
|
-
* @property {RegisterAPITarget} target - The options for the registered entity.
|
|
32
|
+
* @property {Partial<RegisterAPITimings>} timings - The timing metrics for the registered entity.
|
|
33
|
+
* @property {Partial<RegisterAPITarget>} target - The options for the registered entity.
|
|
35
34
|
*/
|
|
36
35
|
|
|
37
36
|
/**
|
|
@@ -40,7 +39,6 @@
|
|
|
40
39
|
* @property {string} name - The name returned for the registered entity.
|
|
41
40
|
* @property {{[key: string]: any}} [tags] - The tags for the registered entity as key-value pairs.
|
|
42
41
|
* @property {string} [parentId] - The parentId for the registered entity. If none was supplied, it will assume the entity guid from the main agent.
|
|
43
|
-
* @property {boolean} [isolated] - When true, each registration creates an isolated instance. When false, multiple registrations with the same id and isolated: false will share a single instance, including all custom attributes, ids, names, and metadata. Calling deregister on a shared instance will deregister it for all entities using the instance. Defaults to true.
|
|
44
42
|
*/
|
|
45
43
|
|
|
46
44
|
/**
|
|
@@ -42,10 +42,9 @@ export function setupRegisterAPI (agent) {
|
|
|
42
42
|
* Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
|
|
43
43
|
* @param {Object} agentRef the reference to the base agent instance
|
|
44
44
|
* @param {import('./register-api-types').RegisterAPIConstructor} target
|
|
45
|
-
* @param {import('./register-api-types').RegisterAPIConstructor} [parent]
|
|
46
45
|
* @returns {RegisterAPI} the api object to be returned from the register api method
|
|
47
46
|
*/
|
|
48
|
-
function register (agentRef, target
|
|
47
|
+
function register (agentRef, target) {
|
|
49
48
|
warn(54, 'newrelic.register')
|
|
50
49
|
|
|
51
50
|
target ||= {}
|
|
@@ -54,7 +53,7 @@ function register (agentRef, target, parent) {
|
|
|
54
53
|
target.licenseKey ||= agentRef.info.licenseKey // will inherit the license key from the container agent if not provided for brevity. A future state may dictate that we need different license keys to do different things.
|
|
55
54
|
target.blocked = false
|
|
56
55
|
if (typeof target.tags !== 'object' || target.tags === null || Array.isArray(target.tags)) target.tags = {}
|
|
57
|
-
target.parent
|
|
56
|
+
target.parent ??= {
|
|
58
57
|
get id () { return agentRef.runtime.appMetadata.agents[0].entityGuid }, // getter because this is asyncronously set
|
|
59
58
|
type: V2_TYPES.BA
|
|
60
59
|
}
|
|
@@ -82,19 +81,11 @@ function register (agentRef, target, parent) {
|
|
|
82
81
|
}
|
|
83
82
|
})
|
|
84
83
|
|
|
85
|
-
target.isolated ??= true
|
|
86
|
-
|
|
87
84
|
/** @type {Function} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
|
|
88
85
|
let invalidApiResponse = () => {}
|
|
89
86
|
/** @type {Array} the array of registered target APIs */
|
|
90
87
|
const registeredEntities = agentRef.runtime.registeredEntities
|
|
91
88
|
|
|
92
|
-
if (!target.isolated) {
|
|
93
|
-
/** if we have already registered this non-isolated target, go ahead and re-use it */
|
|
94
|
-
const sharedEntity = registeredEntities.find(({ metadata: { target: { id } } }) => id === target.id && !target.isolated)
|
|
95
|
-
if (sharedEntity) return sharedEntity
|
|
96
|
-
}
|
|
97
|
-
|
|
98
89
|
/**
|
|
99
90
|
* Block the API, and supply a warning function to display a message to end users
|
|
100
91
|
* @param {Function} warning
|
|
@@ -109,7 +100,7 @@ function register (agentRef, target, parent) {
|
|
|
109
100
|
}
|
|
110
101
|
|
|
111
102
|
/** primary cases that can block the register API from working at init time */
|
|
112
|
-
if (!agentRef.init.api.
|
|
103
|
+
if (!agentRef.init.api.register.enabled) block(single(() => warn(55)))
|
|
113
104
|
if (!hasValidValue(target.id) || !hasValidValue(target.name)) block(single(() => warn(48, target)))
|
|
114
105
|
|
|
115
106
|
/** @type {RegisterAPI} */
|
|
@@ -123,7 +114,6 @@ function register (agentRef, target, parent) {
|
|
|
123
114
|
log: (message, options = {}) => report(log, [message, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
|
|
124
115
|
measure: (name, options = {}) => report(measure, [name, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
|
|
125
116
|
noticeError: (error, attributes = {}) => report(noticeError, [error, { ...attrs, ...attributes }, agentRef], target),
|
|
126
|
-
register: (target = {}) => report(register, [agentRef, target], api.metadata.target),
|
|
127
117
|
recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, { ...attrs, ...attributes }, agentRef], target),
|
|
128
118
|
setApplicationVersion: (value) => setLocalValue('application.version', value),
|
|
129
119
|
setCustomAttribute: (key, value) => setLocalValue(key, value),
|
|
@@ -184,7 +174,7 @@ function register (agentRef, target, parent) {
|
|
|
184
174
|
|
|
185
175
|
/**
|
|
186
176
|
* The reporter method that will be used to report the data to the container agent's API method. If invalid, will log a warning and not execute.
|
|
187
|
-
* If the api.
|
|
177
|
+
* If the api.register.duplicate_data_to_container configuration value is set to true, the data will be reported to BOTH the container and the external target
|
|
188
178
|
* @param {*} methodToCall the container agent's API method to call
|
|
189
179
|
* @param {*} args the arguments to supply to the container agent's API method
|
|
190
180
|
* @param {string} target the target to report the data to. If undefined, will report to the container agent's target.
|