@newrelic/browser-agent 1.289.0 → 1.290.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +32 -0
  3. package/dist/cjs/common/constants/env.cdn.js +1 -1
  4. package/dist/cjs/common/constants/env.npm.js +1 -1
  5. package/dist/cjs/features/ajax/instrument/index.js +5 -5
  6. package/dist/cjs/features/generic_events/aggregate/index.js +1 -0
  7. package/dist/cjs/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
  8. package/dist/cjs/features/generic_events/instrument/index.js +15 -5
  9. package/dist/cjs/features/jserrors/instrument/index.js +15 -5
  10. package/dist/cjs/features/logging/instrument/index.js +13 -5
  11. package/dist/cjs/features/metrics/instrument/index.js +5 -5
  12. package/dist/cjs/features/page_action/instrument/index.js +1 -5
  13. package/dist/cjs/features/page_view_event/instrument/index.js +8 -6
  14. package/dist/cjs/features/page_view_timing/instrument/index.js +5 -5
  15. package/dist/cjs/features/session_replay/instrument/index.js +10 -4
  16. package/dist/cjs/features/session_trace/instrument/index.js +10 -6
  17. package/dist/cjs/features/soft_navigations/instrument/index.js +9 -5
  18. package/dist/cjs/features/spa/instrument/index.js +8 -6
  19. package/dist/cjs/features/utils/instrument-base.js +27 -23
  20. package/dist/cjs/loaders/agent-base.js +4 -95
  21. package/dist/cjs/loaders/agent.js +11 -0
  22. package/dist/cjs/loaders/api/addPageAction.js +23 -0
  23. package/dist/cjs/loaders/api/addRelease.js +20 -0
  24. package/dist/cjs/loaders/api/addToTrace.js +29 -0
  25. package/dist/cjs/loaders/api/constants.js +32 -0
  26. package/dist/cjs/loaders/api/finished.js +31 -0
  27. package/dist/cjs/loaders/api/interaction.js +58 -0
  28. package/dist/cjs/loaders/api/log.js +26 -0
  29. package/dist/cjs/loaders/api/noticeError.js +30 -0
  30. package/dist/cjs/loaders/api/pauseReplay.js +20 -0
  31. package/dist/cjs/loaders/api/recordCustomEvent.js +21 -0
  32. package/dist/cjs/loaders/api/recordReplay.js +20 -0
  33. package/dist/cjs/loaders/api/register.js +182 -0
  34. package/dist/cjs/loaders/api/setApplicationVersion.js +28 -0
  35. package/dist/cjs/loaders/api/setCustomAttribute.js +27 -0
  36. package/dist/cjs/loaders/api/setErrorHandler.js +18 -0
  37. package/dist/cjs/loaders/api/setPageViewName.js +23 -0
  38. package/dist/cjs/loaders/api/setUserId.js +28 -0
  39. package/dist/cjs/loaders/api/sharedHandlers.js +76 -0
  40. package/dist/cjs/loaders/api/start.js +18 -0
  41. package/dist/cjs/loaders/api/topLevelCallers.js +29 -0
  42. package/dist/cjs/loaders/api/wrapLogger.js +26 -0
  43. package/dist/cjs/loaders/api-base.js +224 -0
  44. package/dist/cjs/loaders/configure/configure.js +2 -4
  45. package/dist/cjs/loaders/micro-agent-base.js +3 -134
  46. package/dist/cjs/loaders/micro-agent.js +34 -6
  47. package/dist/esm/common/constants/env.cdn.js +1 -1
  48. package/dist/esm/common/constants/env.npm.js +1 -1
  49. package/dist/esm/features/ajax/instrument/index.js +3 -3
  50. package/dist/esm/features/generic_events/aggregate/index.js +1 -0
  51. package/dist/esm/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
  52. package/dist/esm/features/generic_events/instrument/index.js +13 -3
  53. package/dist/esm/features/jserrors/instrument/index.js +13 -3
  54. package/dist/esm/features/logging/instrument/index.js +11 -3
  55. package/dist/esm/features/metrics/instrument/index.js +3 -3
  56. package/dist/esm/features/page_action/instrument/index.js +1 -5
  57. package/dist/esm/features/page_view_event/instrument/index.js +7 -3
  58. package/dist/esm/features/page_view_timing/instrument/index.js +3 -3
  59. package/dist/esm/features/session_replay/instrument/index.js +10 -4
  60. package/dist/esm/features/session_trace/instrument/index.js +9 -3
  61. package/dist/esm/features/soft_navigations/instrument/index.js +7 -3
  62. package/dist/esm/features/spa/instrument/index.js +7 -3
  63. package/dist/esm/features/utils/instrument-base.js +27 -23
  64. package/dist/esm/loaders/agent-base.js +4 -95
  65. package/dist/esm/loaders/agent.js +10 -0
  66. package/dist/esm/loaders/api/addPageAction.js +15 -0
  67. package/dist/esm/loaders/api/addRelease.js +13 -0
  68. package/dist/esm/loaders/api/addToTrace.js +22 -0
  69. package/dist/esm/loaders/api/constants.js +26 -0
  70. package/dist/esm/loaders/api/finished.js +24 -0
  71. package/dist/esm/loaders/api/interaction.js +52 -0
  72. package/dist/esm/loaders/api/log.js +19 -0
  73. package/dist/esm/loaders/api/noticeError.js +22 -0
  74. package/dist/esm/loaders/api/pauseReplay.js +13 -0
  75. package/dist/esm/loaders/api/recordCustomEvent.js +14 -0
  76. package/dist/esm/loaders/api/recordReplay.js +13 -0
  77. package/dist/esm/loaders/api/register.js +175 -0
  78. package/dist/esm/loaders/api/setApplicationVersion.js +21 -0
  79. package/dist/esm/loaders/api/setCustomAttribute.js +20 -0
  80. package/dist/esm/loaders/api/setErrorHandler.js +11 -0
  81. package/dist/esm/loaders/api/setPageViewName.js +16 -0
  82. package/dist/esm/loaders/api/setUserId.js +21 -0
  83. package/dist/esm/loaders/api/sharedHandlers.js +69 -0
  84. package/dist/esm/loaders/api/start.js +11 -0
  85. package/dist/esm/loaders/api/topLevelCallers.js +22 -0
  86. package/dist/esm/loaders/api/wrapLogger.js +19 -0
  87. package/dist/esm/loaders/api-base.js +217 -0
  88. package/dist/esm/loaders/configure/configure.js +2 -4
  89. package/dist/esm/loaders/micro-agent-base.js +3 -134
  90. package/dist/esm/loaders/micro-agent.js +34 -6
  91. package/dist/tsconfig.tsbuildinfo +1 -1
  92. package/dist/types/features/ajax/instrument/index.d.ts +1 -1
  93. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  94. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  95. package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts +1 -0
  96. package/dist/types/features/generic_events/aggregate/user-actions/aggregated-user-action.d.ts.map +1 -1
  97. package/dist/types/features/generic_events/instrument/index.d.ts +1 -1
  98. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  99. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  100. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  101. package/dist/types/features/logging/instrument/index.d.ts +1 -1
  102. package/dist/types/features/logging/instrument/index.d.ts.map +1 -1
  103. package/dist/types/features/metrics/instrument/index.d.ts +1 -1
  104. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  105. package/dist/types/features/page_action/instrument/index.d.ts +0 -1
  106. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  107. package/dist/types/features/page_view_event/instrument/index.d.ts +1 -1
  108. package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
  109. package/dist/types/features/page_view_timing/instrument/index.d.ts +1 -1
  110. package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -1
  111. package/dist/types/features/session_replay/instrument/index.d.ts +1 -1
  112. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  113. package/dist/types/features/session_trace/instrument/index.d.ts +1 -1
  114. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  115. package/dist/types/features/soft_navigations/instrument/index.d.ts +1 -1
  116. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  117. package/dist/types/features/spa/instrument/index.d.ts +1 -1
  118. package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
  119. package/dist/types/features/utils/instrument-base.d.ts +9 -7
  120. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  121. package/dist/types/loaders/agent-base.d.ts +3 -71
  122. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  123. package/dist/types/loaders/agent.d.ts.map +1 -1
  124. package/dist/types/loaders/api/addPageAction.d.ts +3 -0
  125. package/dist/types/loaders/api/addPageAction.d.ts.map +1 -0
  126. package/dist/types/loaders/api/addRelease.d.ts +2 -0
  127. package/dist/types/loaders/api/addRelease.d.ts.map +1 -0
  128. package/dist/types/loaders/api/addToTrace.d.ts +2 -0
  129. package/dist/types/loaders/api/addToTrace.d.ts.map +1 -0
  130. package/dist/types/loaders/api/constants.d.ts +27 -0
  131. package/dist/types/loaders/api/constants.d.ts.map +1 -0
  132. package/dist/types/loaders/api/finished.d.ts +2 -0
  133. package/dist/types/loaders/api/finished.d.ts.map +1 -0
  134. package/dist/types/loaders/api/interaction.d.ts +2 -0
  135. package/dist/types/loaders/api/interaction.d.ts.map +1 -0
  136. package/dist/types/loaders/api/log.d.ts +6 -0
  137. package/dist/types/loaders/api/log.d.ts.map +1 -0
  138. package/dist/types/loaders/api/noticeError.d.ts +3 -0
  139. package/dist/types/loaders/api/noticeError.d.ts.map +1 -0
  140. package/dist/types/loaders/api/pauseReplay.d.ts +2 -0
  141. package/dist/types/loaders/api/pauseReplay.d.ts.map +1 -0
  142. package/dist/types/loaders/api/recordCustomEvent.d.ts +2 -0
  143. package/dist/types/loaders/api/recordCustomEvent.d.ts.map +1 -0
  144. package/dist/types/loaders/api/recordReplay.d.ts +2 -0
  145. package/dist/types/loaders/api/recordReplay.d.ts.map +1 -0
  146. package/dist/types/loaders/api/register.d.ts +20 -0
  147. package/dist/types/loaders/api/register.d.ts.map +1 -0
  148. package/dist/types/loaders/api/setApplicationVersion.d.ts +2 -0
  149. package/dist/types/loaders/api/setApplicationVersion.d.ts.map +1 -0
  150. package/dist/types/loaders/api/setCustomAttribute.d.ts +2 -0
  151. package/dist/types/loaders/api/setCustomAttribute.d.ts.map +1 -0
  152. package/dist/types/loaders/api/setErrorHandler.d.ts +2 -0
  153. package/dist/types/loaders/api/setErrorHandler.d.ts.map +1 -0
  154. package/dist/types/loaders/api/setPageViewName.d.ts +2 -0
  155. package/dist/types/loaders/api/setPageViewName.d.ts.map +1 -0
  156. package/dist/types/loaders/api/setUserId.d.ts +2 -0
  157. package/dist/types/loaders/api/setUserId.d.ts.map +1 -0
  158. package/dist/types/loaders/api/sharedHandlers.d.ts +20 -0
  159. package/dist/types/loaders/api/sharedHandlers.d.ts.map +1 -0
  160. package/dist/types/loaders/api/start.d.ts +2 -0
  161. package/dist/types/loaders/api/start.d.ts.map +1 -0
  162. package/dist/types/loaders/api/topLevelCallers.d.ts +2 -0
  163. package/dist/types/loaders/api/topLevelCallers.d.ts.map +1 -0
  164. package/dist/types/loaders/api/wrapLogger.d.ts +2 -0
  165. package/dist/types/loaders/api/wrapLogger.d.ts.map +1 -0
  166. package/dist/types/loaders/api-base.d.ts +169 -0
  167. package/dist/types/loaders/api-base.d.ts.map +1 -0
  168. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  169. package/dist/types/loaders/micro-agent-base.d.ts +2 -95
  170. package/dist/types/loaders/micro-agent-base.d.ts.map +1 -1
  171. package/dist/types/loaders/micro-agent.d.ts +1 -1
  172. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  173. package/package.json +6 -1
  174. package/src/features/ajax/instrument/index.js +3 -3
  175. package/src/features/generic_events/aggregate/index.js +1 -0
  176. package/src/features/generic_events/aggregate/user-actions/aggregated-user-action.js +2 -0
  177. package/src/features/generic_events/instrument/index.js +13 -3
  178. package/src/features/jserrors/instrument/index.js +13 -3
  179. package/src/features/logging/instrument/index.js +11 -3
  180. package/src/features/metrics/instrument/index.js +3 -3
  181. package/src/features/page_action/instrument/index.js +1 -3
  182. package/src/features/page_view_event/instrument/index.js +7 -3
  183. package/src/features/page_view_timing/instrument/index.js +3 -3
  184. package/src/features/session_replay/instrument/index.js +11 -4
  185. package/src/features/session_trace/instrument/index.js +10 -3
  186. package/src/features/soft_navigations/instrument/index.js +8 -3
  187. package/src/features/spa/instrument/index.js +8 -3
  188. package/src/features/utils/instrument-base.js +27 -20
  189. package/src/loaders/agent-base.js +4 -96
  190. package/src/loaders/agent.js +11 -0
  191. package/src/loaders/api/addPageAction.js +17 -0
  192. package/src/loaders/api/addRelease.js +14 -0
  193. package/src/loaders/api/addToTrace.js +25 -0
  194. package/src/loaders/api/constants.js +28 -0
  195. package/src/loaders/api/finished.js +19 -0
  196. package/src/loaders/api/interaction.js +59 -0
  197. package/src/loaders/api/log.js +18 -0
  198. package/src/loaders/api/noticeError.js +26 -0
  199. package/src/loaders/api/pauseReplay.js +14 -0
  200. package/src/loaders/api/recordCustomEvent.js +15 -0
  201. package/src/loaders/api/recordReplay.js +14 -0
  202. package/src/loaders/api/register.js +168 -0
  203. package/src/loaders/api/setApplicationVersion.js +22 -0
  204. package/src/loaders/api/setCustomAttribute.js +21 -0
  205. package/src/loaders/api/setErrorHandler.js +12 -0
  206. package/src/loaders/api/setPageViewName.js +17 -0
  207. package/src/loaders/api/setUserId.js +22 -0
  208. package/src/loaders/api/sharedHandlers.js +63 -0
  209. package/src/loaders/api/start.js +12 -0
  210. package/src/loaders/api/topLevelCallers.js +24 -0
  211. package/src/loaders/api/wrapLogger.js +14 -0
  212. package/src/loaders/api-base.js +218 -0
  213. package/src/loaders/configure/configure.js +2 -3
  214. package/src/loaders/micro-agent-base.js +3 -136
  215. package/src/loaders/micro-agent.js +34 -4
  216. package/tools/bundler-tools/bundler-tools.js +27 -0
  217. package/tools/bundler-tools/bundler-tools.mjs +23 -0
  218. package/dist/cjs/features/utils/lazy-feature-loader.js +0 -53
  219. package/dist/cjs/loaders/api/api-methods.js +0 -14
  220. package/dist/cjs/loaders/api/api.js +0 -259
  221. package/dist/cjs/loaders/api/apiAsync.js +0 -63
  222. package/dist/esm/features/utils/lazy-feature-loader.js +0 -47
  223. package/dist/esm/loaders/api/api-methods.js +0 -7
  224. package/dist/esm/loaders/api/api.js +0 -251
  225. package/dist/esm/loaders/api/apiAsync.js +0 -56
  226. package/dist/types/features/utils/lazy-feature-loader.d.ts +0 -13
  227. package/dist/types/features/utils/lazy-feature-loader.d.ts.map +0 -1
  228. package/dist/types/loaders/api/api-methods.d.ts +0 -3
  229. package/dist/types/loaders/api/api-methods.d.ts.map +0 -1
  230. package/dist/types/loaders/api/api.d.ts +0 -3
  231. package/dist/types/loaders/api/api.d.ts.map +0 -1
  232. package/dist/types/loaders/api/apiAsync.d.ts +0 -2
  233. package/dist/types/loaders/api/apiAsync.d.ts.map +0 -1
  234. package/src/features/utils/lazy-feature-loader.js +0 -47
  235. package/src/loaders/api/api-methods.js +0 -16
  236. package/src/loaders/api/api.js +0 -264
  237. package/src/loaders/api/apiAsync.js +0 -56
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.buildRegisterApi = buildRegisterApi;
7
+ exports.setupRegisterAPI = setupRegisterAPI;
8
+ var _handle = require("../../common/event-emitter/handle");
9
+ var _console = require("../../common/util/console");
10
+ var _target = require("../../common/util/target");
11
+ var _features = require("../features/features");
12
+ var _now = require("../../common/timing/now");
13
+ var _constants = require("../../features/metrics/constants");
14
+ var _sharedHandlers = require("./sharedHandlers");
15
+ var _constants2 = require("./constants");
16
+ var _log = require("./log");
17
+ var _addPageAction = require("./addPageAction");
18
+ var _noticeError = require("./noticeError");
19
+ /**
20
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
21
+ * SPDX-License-Identifier: Apache-2.0
22
+ */
23
+
24
+ /**
25
+ * @typedef {import('./register-api-types').RegisterAPI} RegisterAPI
26
+ */
27
+
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
+ function setupRegisterAPI(agent) {
34
+ (0, _sharedHandlers.setupAPI)(_constants2.REGISTER, function (target) {
35
+ return buildRegisterApi(agent, target);
36
+ }, agent);
37
+ }
38
+
39
+ /**
40
+ * Builds the api object that will be returned from the register api method.
41
+ * Also conducts certain side-effects, such as harvesting a PageView event when triggered and gathering metadata for the registered entity.
42
+ * @param {Object} agentRef the reference to the base agent instance
43
+ * @param {Object} handlers the shared handlers to be used by both the base agent's API and the external target's API
44
+ * @param {Object} target the target information to be used by the external target's API to send data to the correct location
45
+ * @returns {RegisterAPI} the api object to be returned from the register api method
46
+ */
47
+ function buildRegisterApi(agentRef, target) {
48
+ const attrs = {};
49
+ (0, _console.warn)(54, 'newrelic.register');
50
+
51
+ /** @type {Function|undefined} a function that is set and reports when APIs are triggered -- warns the customer of the invalid state */
52
+ let invalidApiResponse;
53
+
54
+ /**
55
+ * A promise that indicates when all needed connections for the registered child to be ready to report data
56
+ * 1. The main agent to be ready (made a RUM call and got its entity guid)
57
+ * 2. The child to be registered with the main agent (made its own RUM call and got its entity guid)
58
+ * @type {Promise<RegisterAPI>}
59
+ */
60
+ let _connected;
61
+ if (!agentRef.init.api.allow_registered_children) invalidApiResponse = () => (0, _console.warn)(55);
62
+ if (!target || !(0, _target.isValidTarget)(target)) invalidApiResponse = () => (0, _console.warn)(48, target);
63
+
64
+ /** @type {RegisterAPI} */
65
+ const api = {
66
+ addPageAction: (name, attributes = {}) => {
67
+ report(_addPageAction.addPageAction, [name, {
68
+ ...attrs,
69
+ ...attributes
70
+ }, agentRef], target);
71
+ },
72
+ log: (message, options = {}) => {
73
+ report(_log.log, [message, {
74
+ ...options,
75
+ customAttributes: {
76
+ ...attrs,
77
+ ...(options.customAttributes || {})
78
+ }
79
+ }, agentRef], target);
80
+ },
81
+ noticeError: (error, attributes = {}) => {
82
+ report(_noticeError.noticeError, [error, {
83
+ ...attrs,
84
+ ...attributes
85
+ }, agentRef], target);
86
+ },
87
+ setApplicationVersion: value => {
88
+ attrs['application.version'] = value;
89
+ },
90
+ setCustomAttribute: (key, value) => {
91
+ attrs[key] = value;
92
+ },
93
+ setUserId: value => {
94
+ attrs['enduser.id'] = value;
95
+ },
96
+ /** metadata */
97
+ metadata: {
98
+ customAttributes: attrs,
99
+ target,
100
+ /** set in a getter so that later access of the Promise is not polluted before customer is allowed to set a catch block */
101
+ get connected() {
102
+ return _connected || Promise.reject(new Error('Failed to connect'));
103
+ }
104
+ }
105
+ };
106
+ if (invalidApiResponse) {
107
+ invalidApiResponse();
108
+ } else {
109
+ _connected = new Promise((resolve, reject) => {
110
+ try {
111
+ const entityManager = agentRef.runtime?.entityManager;
112
+ /** check if main agent already has main agent entity guid */
113
+ let mainAgentReady = !!entityManager?.get().entityGuid;
114
+ /** check if registered target already has entity guid */
115
+ let registeredEntityGuid = entityManager?.getEntityGuidFor(target.licenseKey, target.applicationID);
116
+ let registrationReady = !!registeredEntityGuid;
117
+
118
+ /** check if we can just resolve immediately without making another connect call */
119
+ if (mainAgentReady && registrationReady) {
120
+ target.entityGuid = registeredEntityGuid;
121
+ resolve(api);
122
+ } else {
123
+ /** we need to make a new connection call since we dont already have a registered entity for this call */
124
+
125
+ /** if the connect callback doesnt resolve in 15 seconds... reject */
126
+ const timeout = setTimeout(() => reject(new Error('Failed to connect - Timeout')), 15000);
127
+
128
+ // tell the main agent to send a rum call for this target
129
+ // when the rum call resolves, it will emit an "entity-added" event, see below
130
+ agentRef.ee.emit('api-send-rum', [attrs, target]);
131
+
132
+ // wait for entity events to emit to see when main agent and/or API registration is ready
133
+ agentRef.ee.on('entity-added', entityEventHandler);
134
+ function entityEventHandler(entity) {
135
+ if ((0, _target.isContainerAgentTarget)(entity, agentRef)) mainAgentReady ||= true;else {
136
+ if (target.licenseKey === entity.licenseKey && target.applicationID === entity.applicationID) {
137
+ registrationReady = true;
138
+ target.entityGuid = entity.entityGuid;
139
+ }
140
+ }
141
+ if (mainAgentReady && registrationReady) {
142
+ clearTimeout(timeout);
143
+ // unsubscribe from the event emitter
144
+ agentRef.ee.removeEventListener('entity-added', entityEventHandler);
145
+ resolve(api);
146
+ }
147
+ }
148
+ }
149
+ } catch (err) {
150
+ reject(err);
151
+ }
152
+ });
153
+ }
154
+
155
+ /**
156
+ * 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.
157
+ * 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
158
+ * @param {*} methodToCall the container agent's API method to call
159
+ * @param {*} args the arguments to supply to the container agent's API method
160
+ * @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.
161
+ * @returns
162
+ */
163
+ const report = async (methodToCall, args, target) => {
164
+ if (invalidApiResponse) return invalidApiResponse();
165
+ /** set the timestamp before the async part of waiting for the rum response for better accuracy */
166
+ const timestamp = (0, _now.now)();
167
+ (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ["API/register/".concat(methodToCall.name, "/called")], undefined, _features.FEATURE_NAMES.metrics, agentRef.ee);
168
+ try {
169
+ await _connected;
170
+ // target should be decorated with entityGuid by the rum resp at this point
171
+ const shouldDuplicate = agentRef.init.api.duplicate_registered_data;
172
+ if (shouldDuplicate === true || Array.isArray(shouldDuplicate) && shouldDuplicate.includes(target.entityGuid)) {
173
+ // also report to container by providing undefined target
174
+ methodToCall(...args, undefined, timestamp);
175
+ }
176
+ methodToCall(...args, target.entityGuid, timestamp); // always report to target
177
+ } catch (err) {
178
+ (0, _console.warn)(50, err);
179
+ }
180
+ };
181
+ return api;
182
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupSetApplicationVersionAPI = setupSetApplicationVersionAPI;
7
+ var _console = require("../../common/util/console");
8
+ var _constants = require("./constants");
9
+ var _sharedHandlers = require("./sharedHandlers");
10
+ /**
11
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
12
+ * SPDX-License-Identifier: Apache-2.0
13
+ */
14
+
15
+ function setupSetApplicationVersionAPI(agent) {
16
+ /**
17
+ * Attach the 'applcation.version' attribute onto agent payloads. This may be used in NR queries to group all browser events by a specific customer-defined release.
18
+ * @param {string|null} value - Application version -- if null, will "unset" the value
19
+ * @returns @see apiCall
20
+ */
21
+ (0, _sharedHandlers.setupAPI)(_constants.SET_APPLICATION_VERSION, function (value) {
22
+ if (!(typeof value === 'string' || value === null)) {
23
+ (0, _console.warn)(42, typeof value);
24
+ return;
25
+ }
26
+ return (0, _sharedHandlers.appendJsAttribute)(agent, 'application.version', value, _constants.SET_APPLICATION_VERSION, false);
27
+ }, agent);
28
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupSetCustomAttributeAPI = setupSetCustomAttributeAPI;
7
+ var _console = require("../../common/util/console");
8
+ var _constants = require("./constants");
9
+ var _sharedHandlers = require("./sharedHandlers");
10
+ /**
11
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
12
+ * SPDX-License-Identifier: Apache-2.0
13
+ */
14
+
15
+ function setupSetCustomAttributeAPI(agent) {
16
+ (0, _sharedHandlers.setupAPI)(_constants.SET_CUSTOM_ATTRIBUTE, function (name, value, persistAttribute = false) {
17
+ if (typeof name !== 'string') {
18
+ (0, _console.warn)(39, typeof name);
19
+ return;
20
+ }
21
+ if (!(['string', 'number', 'boolean'].includes(typeof value) || value === null)) {
22
+ (0, _console.warn)(40, typeof value);
23
+ return;
24
+ }
25
+ return (0, _sharedHandlers.appendJsAttribute)(agent, name, value, _constants.SET_CUSTOM_ATTRIBUTE, persistAttribute);
26
+ }, agent);
27
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupSetErrorHandlerAPI = setupSetErrorHandlerAPI;
7
+ var _constants = require("./constants");
8
+ var _sharedHandlers = require("./sharedHandlers");
9
+ /**
10
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
11
+ * SPDX-License-Identifier: Apache-2.0
12
+ */
13
+
14
+ function setupSetErrorHandlerAPI(agent) {
15
+ (0, _sharedHandlers.setupAPI)(_constants.SET_ERROR_HANDLER, function (callback) {
16
+ agent.runtime.onerror = callback;
17
+ }, agent);
18
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupSetPageViewNameAPI = setupSetPageViewNameAPI;
7
+ var _handle = require("../../common/event-emitter/handle");
8
+ var _now = require("../../common/timing/now");
9
+ var _constants = require("./constants");
10
+ var _sharedHandlers = require("./sharedHandlers");
11
+ /**
12
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ */
15
+
16
+ function setupSetPageViewNameAPI(agent) {
17
+ (0, _sharedHandlers.setupAPI)(_constants.SET_PAGE_VIEW_NAME, function (name, host) {
18
+ if (typeof name !== 'string') return;
19
+ if (name.charAt(0) !== '/') name = '/' + name;
20
+ agent.runtime.customTransaction = (host || 'http://custom.transaction') + name;
21
+ (0, _handle.handle)(_constants.prefix + _constants.SET_PAGE_VIEW_NAME, [(0, _now.now)()], undefined, undefined, agent.ee);
22
+ }, agent);
23
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupSetUserIdAPI = setupSetUserIdAPI;
7
+ var _console = require("../../common/util/console");
8
+ var _constants = require("./constants");
9
+ var _sharedHandlers = require("./sharedHandlers");
10
+ /**
11
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
12
+ * SPDX-License-Identifier: Apache-2.0
13
+ */
14
+
15
+ function setupSetUserIdAPI(agent) {
16
+ /**
17
+ * Attach the 'enduser.id' attribute onto agent payloads. This may be used in NR queries to group all browser events by specific users.
18
+ * @param {string} value - unique user identifier; a null user id suggests none should exist
19
+ * @returns @see apiCall
20
+ */
21
+ (0, _sharedHandlers.setupAPI)(_constants.SET_USER_ID, function (value) {
22
+ if (!(typeof value === 'string' || value === null)) {
23
+ (0, _console.warn)(41, typeof value);
24
+ return;
25
+ }
26
+ return (0, _sharedHandlers.appendJsAttribute)(agent, 'enduser.id', value, _constants.SET_USER_ID, true);
27
+ }, agent);
28
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.appendJsAttribute = appendJsAttribute;
7
+ exports.setupAPI = setupAPI;
8
+ var _globalEvent = require("../../common/dispatch/global-event");
9
+ var _handle = require("../../common/event-emitter/handle");
10
+ var _now = require("../../common/timing/now");
11
+ var _console = require("../../common/util/console");
12
+ var _featureFlags = require("../../common/util/feature-flags");
13
+ var _constants = require("../../features/metrics/constants");
14
+ var _agentBase = require("../agent-base");
15
+ var _features = require("../features/features");
16
+ var _constants2 = require("./constants");
17
+ /**
18
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
19
+ * SPDX-License-Identifier: Apache-2.0
20
+ */
21
+
22
+ /**
23
+ * setupAPI is a utility function that assigns API methods to an object while emitting supportability metrics and global events.
24
+ * @param {string} name The API method name to be set up.
25
+ * @param {Function} fn The function to be executed when the API method is called.
26
+ * @param {Object} agent The agent instance. Will be used if no object is provided to assign the api method to.
27
+ * @param {Object} [obj] The object to which the API method will be assigned.
28
+ * @returns {*} The output of the function being called.
29
+ */
30
+ function setupAPI(name, fn, agent, obj) {
31
+ /* use object if provided, otherwise use agent as base for api method assignment */
32
+ const api = obj || agent;
33
+ // We only set the global API event if the API is not already overridden from the default
34
+ if (!api || !!api[name] && api[name] !== _agentBase.AgentBase.prototype[name]) return;
35
+ api[name] = function () {
36
+ (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, ['API/' + name + '/called'], undefined, _features.FEATURE_NAMES.metrics, agent.ee);
37
+ (0, _globalEvent.dispatchGlobalEvent)({
38
+ agentIdentifier: agent.agentIdentifier,
39
+ drained: !!_featureFlags.activatedFeatures?.[agent.agentIdentifier],
40
+ type: 'data',
41
+ name: 'api',
42
+ feature: _constants2.prefix + name,
43
+ data: {}
44
+ });
45
+ try {
46
+ return fn.apply(this, arguments);
47
+ } catch (err) {
48
+ (0, _console.warn)(23, err);
49
+ }
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Attach the key-value attribute onto agent payloads. All browser events in NR will be affected.
55
+ * @param {Agent} agent the agent instance reference
56
+ * @param {string} key
57
+ * @param {string|number|boolean|null} value - null indicates the key should be removed or erased
58
+ * @param {string} apiName
59
+ * @param {boolean} addToBrowserStorage - whether this attribute should be stored in browser storage API and retrieved by the next agent context or initialization
60
+ * @returns @see apiCall
61
+ */
62
+ function appendJsAttribute(agent, key, value, apiName, addToBrowserStorage) {
63
+ const currentInfo = agent.info;
64
+ if (value === null) {
65
+ delete currentInfo.jsAttributes[key];
66
+ } else {
67
+ agent.info = {
68
+ ...agent.info,
69
+ jsAttributes: {
70
+ ...currentInfo.jsAttributes,
71
+ [key]: value
72
+ }
73
+ };
74
+ }
75
+ if (addToBrowserStorage || value === null) (0, _handle.handle)(_constants2.prefix + apiName, [(0, _now.now)(), key, value], undefined, 'session', agent.ee);
76
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupStartAPI = setupStartAPI;
7
+ var _constants = require("./constants");
8
+ var _sharedHandlers = require("./sharedHandlers");
9
+ /**
10
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
11
+ * SPDX-License-Identifier: Apache-2.0
12
+ */
13
+
14
+ function setupStartAPI(agent) {
15
+ (0, _sharedHandlers.setupAPI)(_constants.START, function () {
16
+ agent.ee.emit('manual-start-all');
17
+ }, agent);
18
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setTopLevelCallers = setTopLevelCallers;
7
+ var _nreum = require("../../common/window/nreum");
8
+ var _apiBase = require("../api-base");
9
+ /**
10
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
11
+ * SPDX-License-Identifier: Apache-2.0
12
+ */
13
+
14
+ function setTopLevelCallers(agentRef) {
15
+ const nr = (0, _nreum.gosCDN)();
16
+ Object.getOwnPropertyNames(_apiBase.ApiBase.prototype).forEach(fnName => {
17
+ const origFn = _apiBase.ApiBase.prototype[fnName];
18
+ if (typeof origFn !== 'function' || origFn === 'constructor') return;
19
+ /** if the method already exists on the top and we are allowed to -- we can call it multiple times */
20
+ let origNrFn = nr[fnName];
21
+ if (!agentRef[fnName] || agentRef.exposed === false || agentRef.runtime?.loaderType === 'micro-agent') return; // dont set the top level callers if we are not allowed to
22
+
23
+ nr[fnName] = (...args) => {
24
+ const thisAgentFnResult = agentRef[fnName](...args);
25
+ if (!origNrFn) return thisAgentFnResult;
26
+ return origNrFn(...args); // if origFn is defined, we want to return the value from that call (ie the first agent that was set)
27
+ };
28
+ });
29
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupWrapLoggerAPI = setupWrapLoggerAPI;
7
+ var _wrapLogger = require("../../common/wrap/wrap-logger");
8
+ var _constants = require("../../features/logging/constants");
9
+ var _constants2 = require("./constants");
10
+ var _sharedHandlers = require("./sharedHandlers");
11
+ /**
12
+ * Copyright 2020-2025 New Relic, Inc. All rights reserved.
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ */
15
+
16
+ function setupWrapLoggerAPI(agent) {
17
+ (0, _sharedHandlers.setupAPI)(_constants2.WRAP_LOGGER, (parent, functionName, {
18
+ customAttributes = {},
19
+ level = _constants.LOG_LEVELS.INFO
20
+ } = {}) => {
21
+ (0, _wrapLogger.wrapLogger)(agent.ee, parent, functionName, {
22
+ customAttributes,
23
+ level
24
+ });
25
+ }, agent);
26
+ }