@newrelic/browser-agent 1.301.0 → 1.302.0-rc.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 (142) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/common/config/init-types.js +1 -1
  3. package/dist/cjs/common/config/init.js +7 -1
  4. package/dist/cjs/common/config/runtime.js +1 -1
  5. package/dist/cjs/common/constants/agent-constants.js +11 -2
  6. package/dist/cjs/common/constants/env.cdn.js +1 -1
  7. package/dist/cjs/common/constants/env.npm.js +1 -1
  8. package/dist/cjs/common/drain/drain.js +1 -1
  9. package/dist/cjs/common/harvest/harvester.js +30 -39
  10. package/dist/cjs/common/util/mfe.js +45 -0
  11. package/dist/cjs/features/ajax/aggregate/index.js +5 -1
  12. package/dist/cjs/features/generic_events/aggregate/index.js +9 -8
  13. package/dist/cjs/features/generic_events/constants.js +3 -1
  14. package/dist/cjs/features/generic_events/instrument/index.js +38 -32
  15. package/dist/cjs/features/jserrors/aggregate/index.js +18 -17
  16. package/dist/cjs/features/logging/aggregate/index.js +19 -15
  17. package/dist/cjs/features/logging/shared/utils.js +3 -3
  18. package/dist/cjs/features/page_view_event/aggregate/index.js +3 -33
  19. package/dist/cjs/features/session_replay/aggregate/index.js +13 -13
  20. package/dist/cjs/features/session_replay/shared/recorder.js +3 -2
  21. package/dist/cjs/features/session_trace/aggregate/index.js +0 -2
  22. package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -2
  23. package/dist/cjs/features/utils/aggregate-base.js +45 -47
  24. package/dist/cjs/loaders/api/addPageAction.js +2 -2
  25. package/dist/cjs/loaders/api/log.js +2 -2
  26. package/dist/cjs/loaders/api/noticeError.js +2 -2
  27. package/dist/cjs/loaders/api/register-api-types.js +5 -5
  28. package/dist/cjs/loaders/api/register.js +80 -97
  29. package/dist/esm/common/config/init-types.js +1 -1
  30. package/dist/esm/common/config/init.js +7 -1
  31. package/dist/esm/common/config/runtime.js +1 -1
  32. package/dist/esm/common/constants/agent-constants.js +9 -1
  33. package/dist/esm/common/constants/env.cdn.js +1 -1
  34. package/dist/esm/common/constants/env.npm.js +1 -1
  35. package/dist/esm/common/drain/drain.js +1 -1
  36. package/dist/esm/common/harvest/harvester.js +30 -39
  37. package/dist/esm/common/util/mfe.js +38 -0
  38. package/dist/esm/features/ajax/aggregate/index.js +5 -1
  39. package/dist/esm/features/generic_events/aggregate/index.js +9 -8
  40. package/dist/esm/features/generic_events/constants.js +3 -1
  41. package/dist/esm/features/generic_events/instrument/index.js +38 -32
  42. package/dist/esm/features/jserrors/aggregate/index.js +18 -17
  43. package/dist/esm/features/logging/aggregate/index.js +19 -15
  44. package/dist/esm/features/logging/shared/utils.js +3 -3
  45. package/dist/esm/features/page_view_event/aggregate/index.js +3 -33
  46. package/dist/esm/features/session_replay/aggregate/index.js +13 -13
  47. package/dist/esm/features/session_replay/shared/recorder.js +3 -2
  48. package/dist/esm/features/session_trace/aggregate/index.js +0 -2
  49. package/dist/esm/features/soft_navigations/aggregate/index.js +1 -2
  50. package/dist/esm/features/utils/aggregate-base.js +46 -48
  51. package/dist/esm/loaders/api/addPageAction.js +2 -2
  52. package/dist/esm/loaders/api/log.js +2 -2
  53. package/dist/esm/loaders/api/noticeError.js +2 -2
  54. package/dist/esm/loaders/api/register-api-types.js +5 -5
  55. package/dist/esm/loaders/api/register.js +80 -97
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/dist/types/common/config/init-types.d.ts +4 -1
  58. package/dist/types/common/config/init-types.d.ts.map +1 -1
  59. package/dist/types/common/config/init.d.ts.map +1 -1
  60. package/dist/types/common/constants/agent-constants.d.ts +7 -4
  61. package/dist/types/common/constants/agent-constants.d.ts.map +1 -1
  62. package/dist/types/common/harvest/harvester.d.ts +2 -2
  63. package/dist/types/common/harvest/harvester.d.ts.map +1 -1
  64. package/dist/types/common/util/mfe.d.ts +20 -0
  65. package/dist/types/common/util/mfe.d.ts.map +1 -0
  66. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  67. package/dist/types/features/generic_events/aggregate/index.d.ts +2 -2
  68. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -1
  69. package/dist/types/features/generic_events/constants.d.ts +1 -0
  70. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -1
  71. package/dist/types/features/jserrors/aggregate/index.d.ts +3 -3
  72. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  73. package/dist/types/features/logging/aggregate/index.d.ts +3 -3
  74. package/dist/types/features/logging/aggregate/index.d.ts.map +1 -1
  75. package/dist/types/features/logging/shared/utils.d.ts +2 -2
  76. package/dist/types/features/logging/shared/utils.d.ts.map +1 -1
  77. package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -4
  78. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  79. package/dist/types/features/session_replay/aggregate/index.d.ts +13 -4
  80. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  81. package/dist/types/features/session_replay/shared/recorder.d.ts +1 -0
  82. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  83. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  84. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  85. package/dist/types/features/utils/aggregate-base.d.ts +13 -5
  86. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  87. package/dist/types/loaders/api/addPageAction.d.ts +1 -1
  88. package/dist/types/loaders/api/addPageAction.d.ts.map +1 -1
  89. package/dist/types/loaders/api/log.d.ts +1 -1
  90. package/dist/types/loaders/api/log.d.ts.map +1 -1
  91. package/dist/types/loaders/api/noticeError.d.ts +1 -1
  92. package/dist/types/loaders/api/noticeError.d.ts.map +1 -1
  93. package/dist/types/loaders/api/register-api-types.d.ts +4 -4
  94. package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
  95. package/dist/types/loaders/api/register.d.ts +8 -1
  96. package/dist/types/loaders/api/register.d.ts.map +1 -1
  97. package/package.json +2 -2
  98. package/src/common/config/init-types.js +1 -1
  99. package/src/common/config/init.js +3 -1
  100. package/src/common/config/runtime.js +1 -1
  101. package/src/common/constants/agent-constants.js +10 -0
  102. package/src/common/drain/drain.js +1 -1
  103. package/src/common/harvest/harvester.js +27 -32
  104. package/src/common/util/mfe.js +35 -0
  105. package/src/features/ajax/aggregate/index.js +7 -1
  106. package/src/features/generic_events/aggregate/index.js +9 -8
  107. package/src/features/generic_events/constants.js +3 -1
  108. package/src/features/generic_events/instrument/index.js +44 -35
  109. package/src/features/jserrors/aggregate/index.js +17 -17
  110. package/src/features/logging/aggregate/index.js +20 -13
  111. package/src/features/logging/shared/utils.js +3 -3
  112. package/src/features/page_view_event/aggregate/index.js +3 -28
  113. package/src/features/session_replay/aggregate/index.js +12 -10
  114. package/src/features/session_replay/shared/recorder.js +3 -2
  115. package/src/features/session_trace/aggregate/index.js +0 -2
  116. package/src/features/soft_navigations/aggregate/index.js +1 -2
  117. package/src/features/utils/aggregate-base.js +47 -42
  118. package/src/loaders/api/addPageAction.js +2 -2
  119. package/src/loaders/api/log.js +2 -2
  120. package/src/loaders/api/noticeError.js +2 -2
  121. package/src/loaders/api/register-api-types.js +5 -5
  122. package/src/loaders/api/register.js +62 -89
  123. package/dist/cjs/common/util/target.js +0 -34
  124. package/dist/cjs/features/utils/entity-manager.js +0 -46
  125. package/dist/cjs/features/utils/event-store-manager.js +0 -174
  126. package/dist/cjs/loaders/api/register-api.js +0 -165
  127. package/dist/esm/common/util/target.js +0 -27
  128. package/dist/esm/features/utils/entity-manager.js +0 -39
  129. package/dist/esm/features/utils/event-store-manager.js +0 -166
  130. package/dist/esm/loaders/api/register-api.js +0 -159
  131. package/dist/types/common/util/target.d.ts +0 -18
  132. package/dist/types/common/util/target.d.ts.map +0 -1
  133. package/dist/types/features/utils/entity-manager.d.ts +0 -11
  134. package/dist/types/features/utils/entity-manager.d.ts.map +0 -1
  135. package/dist/types/features/utils/event-store-manager.d.ts +0 -85
  136. package/dist/types/features/utils/event-store-manager.d.ts.map +0 -1
  137. package/dist/types/loaders/api/register-api.d.ts +0 -14
  138. package/dist/types/loaders/api/register-api.d.ts.map +0 -1
  139. package/src/common/util/target.js +0 -27
  140. package/src/features/utils/entity-manager.js +0 -45
  141. package/src/features/utils/event-store-manager.js +0 -165
  142. 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
- }