@newrelic/browser-agent 1.301.0 → 1.302.0-alpha.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 +13 -0
- package/dist/cjs/common/config/init-types.js +1 -1
- package/dist/cjs/common/config/init.js +7 -1
- package/dist/cjs/common/config/runtime.js +1 -1
- package/dist/cjs/common/constants/agent-constants.js +11 -2
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/drain/drain.js +1 -1
- package/dist/cjs/common/harvest/harvester.js +30 -39
- package/dist/cjs/common/util/mfe.js +45 -0
- package/dist/cjs/features/ajax/aggregate/index.js +5 -1
- package/dist/cjs/features/generic_events/aggregate/index.js +9 -8
- package/dist/cjs/features/generic_events/constants.js +3 -1
- package/dist/cjs/features/generic_events/instrument/index.js +38 -32
- package/dist/cjs/features/jserrors/aggregate/index.js +18 -17
- package/dist/cjs/features/logging/aggregate/index.js +19 -15
- package/dist/cjs/features/logging/shared/utils.js +3 -3
- package/dist/cjs/features/page_view_event/aggregate/index.js +3 -33
- package/dist/cjs/features/session_replay/aggregate/index.js +13 -13
- package/dist/cjs/features/session_replay/shared/recorder.js +3 -2
- package/dist/cjs/features/session_trace/aggregate/index.js +0 -2
- package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -2
- package/dist/cjs/features/utils/aggregate-base.js +45 -47
- package/dist/cjs/loaders/api/addPageAction.js +2 -2
- package/dist/cjs/loaders/api/log.js +2 -2
- package/dist/cjs/loaders/api/noticeError.js +2 -2
- package/dist/cjs/loaders/api/register-api-types.js +5 -5
- package/dist/cjs/loaders/api/register.js +80 -97
- package/dist/esm/common/config/init-types.js +1 -1
- package/dist/esm/common/config/init.js +7 -1
- package/dist/esm/common/config/runtime.js +1 -1
- package/dist/esm/common/constants/agent-constants.js +9 -1
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/drain/drain.js +1 -1
- package/dist/esm/common/harvest/harvester.js +30 -39
- package/dist/esm/common/util/mfe.js +38 -0
- package/dist/esm/features/ajax/aggregate/index.js +5 -1
- package/dist/esm/features/generic_events/aggregate/index.js +9 -8
- package/dist/esm/features/generic_events/constants.js +3 -1
- package/dist/esm/features/generic_events/instrument/index.js +38 -32
- package/dist/esm/features/jserrors/aggregate/index.js +18 -17
- package/dist/esm/features/logging/aggregate/index.js +19 -15
- package/dist/esm/features/logging/shared/utils.js +3 -3
- package/dist/esm/features/page_view_event/aggregate/index.js +3 -33
- package/dist/esm/features/session_replay/aggregate/index.js +13 -13
- package/dist/esm/features/session_replay/shared/recorder.js +3 -2
- package/dist/esm/features/session_trace/aggregate/index.js +0 -2
- package/dist/esm/features/soft_navigations/aggregate/index.js +1 -2
- package/dist/esm/features/utils/aggregate-base.js +46 -48
- package/dist/esm/loaders/api/addPageAction.js +2 -2
- package/dist/esm/loaders/api/log.js +2 -2
- package/dist/esm/loaders/api/noticeError.js +2 -2
- package/dist/esm/loaders/api/register-api-types.js +5 -5
- package/dist/esm/loaders/api/register.js +80 -97
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/config/init-types.d.ts +4 -1
- 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/common/constants/agent-constants.d.ts +7 -4
- package/dist/types/common/constants/agent-constants.d.ts.map +1 -1
- package/dist/types/common/harvest/harvester.d.ts +2 -2
- package/dist/types/common/harvest/harvester.d.ts.map +1 -1
- package/dist/types/common/util/mfe.d.ts +20 -0
- package/dist/types/common/util/mfe.d.ts.map +1 -0
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/generic_events/aggregate/index.d.ts +2 -2
- package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/generic_events/constants.d.ts +1 -0
- package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +3 -3
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/logging/aggregate/index.d.ts +3 -3
- package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/logging/shared/utils.d.ts +2 -2
- package/dist/types/features/logging/shared/utils.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -4
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts +13 -4
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/shared/recorder.d.ts +1 -0
- package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +13 -5
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/loaders/api/addPageAction.d.ts +1 -1
- package/dist/types/loaders/api/addPageAction.d.ts.map +1 -1
- package/dist/types/loaders/api/log.d.ts +1 -1
- package/dist/types/loaders/api/log.d.ts.map +1 -1
- package/dist/types/loaders/api/noticeError.d.ts +1 -1
- package/dist/types/loaders/api/noticeError.d.ts.map +1 -1
- package/dist/types/loaders/api/register-api-types.d.ts +4 -4
- package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
- package/dist/types/loaders/api/register.d.ts +8 -1
- package/dist/types/loaders/api/register.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/common/config/init-types.js +1 -1
- package/src/common/config/init.js +3 -1
- package/src/common/config/runtime.js +1 -1
- package/src/common/constants/agent-constants.js +10 -0
- package/src/common/drain/drain.js +1 -1
- package/src/common/harvest/harvester.js +27 -32
- package/src/common/util/mfe.js +35 -0
- package/src/features/ajax/aggregate/index.js +7 -1
- package/src/features/generic_events/aggregate/index.js +9 -8
- package/src/features/generic_events/constants.js +3 -1
- package/src/features/generic_events/instrument/index.js +44 -35
- package/src/features/jserrors/aggregate/index.js +17 -17
- package/src/features/logging/aggregate/index.js +20 -13
- package/src/features/logging/shared/utils.js +3 -3
- package/src/features/page_view_event/aggregate/index.js +3 -28
- package/src/features/session_replay/aggregate/index.js +12 -10
- package/src/features/session_replay/shared/recorder.js +3 -2
- package/src/features/session_trace/aggregate/index.js +0 -2
- package/src/features/soft_navigations/aggregate/index.js +1 -2
- package/src/features/utils/aggregate-base.js +47 -42
- package/src/loaders/api/addPageAction.js +2 -2
- package/src/loaders/api/log.js +2 -2
- package/src/loaders/api/noticeError.js +2 -2
- package/src/loaders/api/register-api-types.js +5 -5
- package/src/loaders/api/register.js +62 -89
- package/dist/cjs/common/util/target.js +0 -34
- package/dist/cjs/features/utils/entity-manager.js +0 -46
- package/dist/cjs/features/utils/event-store-manager.js +0 -174
- package/dist/cjs/loaders/api/register-api.js +0 -165
- package/dist/esm/common/util/target.js +0 -27
- package/dist/esm/features/utils/entity-manager.js +0 -39
- package/dist/esm/features/utils/event-store-manager.js +0 -166
- package/dist/esm/loaders/api/register-api.js +0 -159
- package/dist/types/common/util/target.d.ts +0 -18
- package/dist/types/common/util/target.d.ts.map +0 -1
- package/dist/types/features/utils/entity-manager.d.ts +0 -11
- package/dist/types/features/utils/entity-manager.d.ts.map +0 -1
- package/dist/types/features/utils/event-store-manager.d.ts +0 -85
- package/dist/types/features/utils/event-store-manager.d.ts.map +0 -1
- package/dist/types/loaders/api/register-api.d.ts +0 -14
- package/dist/types/loaders/api/register-api.d.ts.map +0 -1
- package/src/common/util/target.js +0 -27
- package/src/features/utils/entity-manager.js +0 -45
- package/src/features/utils/event-store-manager.js +0 -165
- package/src/loaders/api/register-api.js +0 -152
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020-2025 New Relic, Inc. All rights reserved.
|
|
3
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
*/
|
|
5
|
-
import { handle } from '../../common/event-emitter/handle'
|
|
6
|
-
import { warn } from '../../common/util/console'
|
|
7
|
-
import { isContainerAgentTarget, isValidTarget } from '../../common/util/target'
|
|
8
|
-
import { FEATURE_NAMES } from '../features/features'
|
|
9
|
-
import { now } from '../../common/timing/now'
|
|
10
|
-
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Builds the api object that will be returned from the register api method.
|
|
18
|
-
* Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
|
|
19
|
-
* @param {Object} agentRef the reference to the base agent instance
|
|
20
|
-
* @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
|
|
21
|
-
* @param {Object} target the target information to be used by the external target's API to send data to the correct location
|
|
22
|
-
* @returns {RegisterAPI} the api object to be returned from the register api method
|
|
23
|
-
*/
|
|
24
|
-
export function buildRegisterApi (agentRef, handlers, target) {
|
|
25
|
-
const attrs = {}
|
|
26
|
-
warn(54, 'newrelic.register')
|
|
27
|
-
|
|
28
|
-
/** @type {Function|undefined} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
|
|
29
|
-
let invalidApiResponse
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A promise that indicates when all needed connections for the registered child to be ready to report data
|
|
33
|
-
* 1. The main agent to be ready (made a RUM call and got its entity guid)
|
|
34
|
-
* 2. The child to be registered with the main agent (made its own RUM call and got its entity guid)
|
|
35
|
-
* @type {Promise<RegisterAPI>}
|
|
36
|
-
*/
|
|
37
|
-
let _connected
|
|
38
|
-
if (!agentRef.init.api.allow_registered_children) invalidApiResponse = () => warn(55)
|
|
39
|
-
if (!target || !isValidTarget(target)) invalidApiResponse = () => warn(48, target)
|
|
40
|
-
|
|
41
|
-
/** @type {RegisterAPI} */
|
|
42
|
-
const api = {
|
|
43
|
-
addPageAction: (name, attributes = {}) => {
|
|
44
|
-
report(handlers.addPageAction, [name, { ...attrs, ...attributes }], target)
|
|
45
|
-
},
|
|
46
|
-
log: (message, options = {}) => {
|
|
47
|
-
report(handlers.log, [message, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }], target)
|
|
48
|
-
},
|
|
49
|
-
noticeError: (error, attributes = {}) => {
|
|
50
|
-
report(handlers.noticeError, [error, { ...attrs, ...attributes }], target)
|
|
51
|
-
},
|
|
52
|
-
setApplicationVersion: (value) => {
|
|
53
|
-
attrs['application.version'] = value
|
|
54
|
-
},
|
|
55
|
-
setCustomAttribute: (key, value) => {
|
|
56
|
-
attrs[key] = value
|
|
57
|
-
},
|
|
58
|
-
setUserId: (value) => {
|
|
59
|
-
attrs['enduser.id'] = value
|
|
60
|
-
},
|
|
61
|
-
/** metadata */
|
|
62
|
-
metadata: {
|
|
63
|
-
customAttributes: attrs,
|
|
64
|
-
target,
|
|
65
|
-
/** set in a getter so that later access of the Promise is not polluted before customer is allowed to set a catch block */
|
|
66
|
-
get connected () {
|
|
67
|
-
return _connected || Promise.reject(new Error('Failed to connect'))
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (invalidApiResponse) {
|
|
73
|
-
invalidApiResponse()
|
|
74
|
-
} else {
|
|
75
|
-
_connected = new Promise((resolve, reject) => {
|
|
76
|
-
try {
|
|
77
|
-
const entityManager = agentRef.runtime?.entityManager
|
|
78
|
-
/** check if main agent already has main agent entity guid */
|
|
79
|
-
let mainAgentReady = !!entityManager?.get().entityGuid
|
|
80
|
-
/** check if registered target already has entity guid */
|
|
81
|
-
let registeredEntityGuid = entityManager?.getEntityGuidFor(target.licenseKey, target.applicationID)
|
|
82
|
-
let registrationReady = !!registeredEntityGuid
|
|
83
|
-
|
|
84
|
-
/** check if we can just resolve immediately without making another connect call */
|
|
85
|
-
if (mainAgentReady && registrationReady) {
|
|
86
|
-
target.entityGuid = registeredEntityGuid
|
|
87
|
-
resolve(api)
|
|
88
|
-
} else {
|
|
89
|
-
/** we need to make a new connection call since we dont already have a registered entity for this call */
|
|
90
|
-
|
|
91
|
-
/** if the connect callback doesnt resolve in 15 seconds... reject */
|
|
92
|
-
const timeout = setTimeout(() => reject(new Error('Failed to connect - Timeout')), 15000)
|
|
93
|
-
|
|
94
|
-
// tell the main agent to send a rum call for this target
|
|
95
|
-
// when the rum call resolves, it will emit an "entity-added" event, see below
|
|
96
|
-
agentRef.ee.emit('api-send-rum', [attrs, target])
|
|
97
|
-
|
|
98
|
-
// wait for entity events to emit to see when main agent and/or API registration is ready
|
|
99
|
-
agentRef.ee.on('entity-added', entityEventHandler)
|
|
100
|
-
|
|
101
|
-
function entityEventHandler (entity) {
|
|
102
|
-
if (isContainerAgentTarget(entity, agentRef)) mainAgentReady ||= true
|
|
103
|
-
else {
|
|
104
|
-
if (target.licenseKey === entity.licenseKey && target.applicationID === entity.applicationID) {
|
|
105
|
-
registrationReady = true
|
|
106
|
-
target.entityGuid = entity.entityGuid
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (mainAgentReady && registrationReady) {
|
|
111
|
-
clearTimeout(timeout)
|
|
112
|
-
// unsubscribe from the event emitter
|
|
113
|
-
agentRef.ee.removeEventListener('entity-added', entityEventHandler)
|
|
114
|
-
resolve(api)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} catch (err) {
|
|
119
|
-
reject(err)
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 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.
|
|
126
|
-
* If the api.duplicate_registered_data configuration value is set to true, the data will be reported to BOTH the container and the external target
|
|
127
|
-
* @param {*} methodToCall the container agent's API method to call
|
|
128
|
-
* @param {*} args the arguments to supply to the container agent's API method
|
|
129
|
-
* @param {string} targetEntityGuid the target entity guid, which looks up the target to report the data to from the entity manager. If undefined, will report to the container agent's target.
|
|
130
|
-
* @returns
|
|
131
|
-
*/
|
|
132
|
-
const report = async (methodToCall, args, target) => {
|
|
133
|
-
if (invalidApiResponse) return invalidApiResponse()
|
|
134
|
-
/** set the timestamp before the async part of waiting for the rum response for better accuracy */
|
|
135
|
-
const timestamp = now()
|
|
136
|
-
handle(SUPPORTABILITY_METRIC_CHANNEL, [`API/register/${methodToCall.name}/called`], undefined, FEATURE_NAMES.metrics, agentRef.ee)
|
|
137
|
-
try {
|
|
138
|
-
await _connected
|
|
139
|
-
// target should be decorated with entityGuid by the rum resp at this point
|
|
140
|
-
const shouldDuplicate = agentRef.init.api.duplicate_registered_data
|
|
141
|
-
if (shouldDuplicate === true || (Array.isArray(shouldDuplicate) && shouldDuplicate.includes(target.entityGuid))) {
|
|
142
|
-
// also report to container by providing undefined target
|
|
143
|
-
methodToCall(...args, undefined, timestamp)
|
|
144
|
-
}
|
|
145
|
-
methodToCall(...args, target.entityGuid, timestamp) // always report to target
|
|
146
|
-
} catch (err) {
|
|
147
|
-
warn(50, err)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return api
|
|
152
|
-
}
|