@newrelic/browser-agent 1.262.0 → 1.264.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 (259) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -2
  3. package/dist/cjs/cdn/experimental.js +3 -7
  4. package/dist/cjs/cdn/pro.js +2 -2
  5. package/dist/cjs/cdn/spa.js +2 -2
  6. package/dist/cjs/common/aggregate/aggregator.js +3 -3
  7. package/dist/cjs/common/config/state/configurable.js +4 -4
  8. package/dist/cjs/common/config/state/init.js +11 -6
  9. package/dist/cjs/common/constants/env.cdn.js +1 -1
  10. package/dist/cjs/common/constants/env.npm.js +1 -1
  11. package/dist/cjs/common/constants/runtime.js +1 -3
  12. package/dist/cjs/common/context/shared-context.js +2 -2
  13. package/dist/cjs/common/drain/drain.js +5 -5
  14. package/dist/cjs/common/harvest/harvest.js +3 -3
  15. package/dist/cjs/common/serialize/bel-serializer.js +2 -2
  16. package/dist/cjs/common/session/session-entity.js +3 -3
  17. package/dist/cjs/common/timing/time-keeper.js +13 -2
  18. package/dist/cjs/common/url/encode.js +3 -5
  19. package/dist/cjs/common/util/console.js +3 -4
  20. package/dist/cjs/common/util/obfuscate.js +3 -3
  21. package/dist/cjs/common/util/submit-data.js +0 -1
  22. package/dist/cjs/common/vitals/vital-metric.js +1 -1
  23. package/dist/cjs/common/wrap/wrap-logger.js +1 -2
  24. package/dist/cjs/common/wrap/wrap-xhr.js +1 -1
  25. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  26. package/dist/cjs/features/ajax/instrument/index.js +1 -1
  27. package/dist/cjs/features/generic_events/aggregate/index.js +137 -0
  28. package/dist/cjs/features/generic_events/constants.js +8 -0
  29. package/dist/cjs/features/generic_events/index.js +12 -0
  30. package/dist/cjs/features/generic_events/instrument/index.js +27 -0
  31. package/dist/cjs/features/jserrors/aggregate/index.js +13 -12
  32. package/dist/cjs/features/jserrors/instrument/index.js +1 -1
  33. package/dist/cjs/features/logging/aggregate/index.js +6 -6
  34. package/dist/cjs/features/logging/constants.js +2 -5
  35. package/dist/cjs/features/logging/instrument/index.js +1 -1
  36. package/dist/cjs/features/metrics/aggregate/index.js +17 -1
  37. package/dist/cjs/features/metrics/instrument/index.js +1 -1
  38. package/dist/cjs/features/page_action/instrument/index.js +6 -6
  39. package/dist/cjs/features/page_view_event/aggregate/index.js +21 -5
  40. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -1
  41. package/dist/cjs/features/page_view_event/instrument/index.js +1 -1
  42. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -3
  43. package/dist/cjs/features/page_view_timing/instrument/index.js +1 -1
  44. package/dist/cjs/features/session_replay/aggregate/index.js +3 -3
  45. package/dist/cjs/features/session_replay/instrument/index.js +1 -1
  46. package/dist/cjs/features/session_replay/shared/recorder.js +1 -1
  47. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +1 -1
  48. package/dist/cjs/features/session_trace/aggregate/index.js +1 -1
  49. package/dist/cjs/features/session_trace/aggregate/trace/storage.js +2 -2
  50. package/dist/cjs/features/session_trace/instrument/index.js +1 -1
  51. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +1 -1
  52. package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -1
  53. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +5 -5
  54. package/dist/cjs/features/soft_navigations/instrument/index.js +1 -1
  55. package/dist/cjs/features/spa/aggregate/index.js +3 -4
  56. package/dist/cjs/features/spa/aggregate/interaction.js +2 -2
  57. package/dist/cjs/features/spa/aggregate/serializer.js +1 -2
  58. package/dist/cjs/features/spa/instrument/index.js +1 -1
  59. package/dist/cjs/features/utils/aggregate-base.js +6 -3
  60. package/dist/cjs/features/utils/instrument-base.js +2 -2
  61. package/dist/cjs/features/utils/lazy-feature-loader.js +2 -2
  62. package/dist/cjs/index.js +21 -0
  63. package/dist/cjs/loaders/agent-base.js +1 -5
  64. package/dist/cjs/loaders/agent.js +3 -4
  65. package/dist/cjs/loaders/api/api.js +10 -8
  66. package/dist/cjs/loaders/api/apiAsync.js +1 -1
  67. package/dist/cjs/loaders/browser-agent.js +4 -3
  68. package/dist/cjs/loaders/configure/configure.js +4 -3
  69. package/dist/cjs/loaders/features/features.js +8 -4
  70. package/dist/cjs/loaders/micro-agent.js +6 -6
  71. package/dist/esm/cdn/experimental.js +2 -5
  72. package/dist/esm/cdn/pro.js +2 -2
  73. package/dist/esm/cdn/spa.js +2 -2
  74. package/dist/esm/common/aggregate/aggregator.js +3 -3
  75. package/dist/esm/common/config/state/configurable.js +4 -4
  76. package/dist/esm/common/config/state/init.js +11 -6
  77. package/dist/esm/common/constants/env.cdn.js +1 -1
  78. package/dist/esm/common/constants/env.npm.js +1 -1
  79. package/dist/esm/common/constants/runtime.js +0 -2
  80. package/dist/esm/common/context/shared-context.js +2 -2
  81. package/dist/esm/common/drain/drain.js +5 -5
  82. package/dist/esm/common/harvest/harvest.js +4 -4
  83. package/dist/esm/common/serialize/bel-serializer.js +2 -2
  84. package/dist/esm/common/session/session-entity.js +4 -4
  85. package/dist/esm/common/timing/time-keeper.js +12 -2
  86. package/dist/esm/common/url/encode.js +3 -5
  87. package/dist/esm/common/util/console.js +3 -4
  88. package/dist/esm/common/util/obfuscate.js +3 -3
  89. package/dist/esm/common/util/submit-data.js +0 -1
  90. package/dist/esm/common/vitals/vital-metric.js +1 -1
  91. package/dist/esm/common/wrap/wrap-logger.js +1 -2
  92. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  93. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  94. package/dist/esm/features/ajax/instrument/index.js +1 -1
  95. package/dist/esm/features/generic_events/aggregate/index.js +129 -0
  96. package/dist/esm/features/generic_events/constants.js +2 -0
  97. package/dist/esm/features/generic_events/index.js +1 -0
  98. package/dist/esm/features/generic_events/instrument/index.js +20 -0
  99. package/dist/esm/features/jserrors/aggregate/index.js +13 -12
  100. package/dist/esm/features/jserrors/instrument/index.js +1 -1
  101. package/dist/esm/features/logging/aggregate/index.js +7 -7
  102. package/dist/esm/features/logging/constants.js +1 -4
  103. package/dist/esm/features/logging/instrument/index.js +1 -1
  104. package/dist/esm/features/metrics/aggregate/index.js +17 -1
  105. package/dist/esm/features/metrics/instrument/index.js +1 -1
  106. package/dist/esm/features/page_action/instrument/index.js +7 -6
  107. package/dist/esm/features/page_view_event/aggregate/index.js +22 -6
  108. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -1
  109. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  110. package/dist/esm/features/page_view_timing/aggregate/index.js +3 -3
  111. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  112. package/dist/esm/features/session_replay/aggregate/index.js +3 -3
  113. package/dist/esm/features/session_replay/instrument/index.js +1 -1
  114. package/dist/esm/features/session_replay/shared/recorder.js +1 -1
  115. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +1 -1
  116. package/dist/esm/features/session_trace/aggregate/index.js +1 -1
  117. package/dist/esm/features/session_trace/aggregate/trace/storage.js +2 -2
  118. package/dist/esm/features/session_trace/instrument/index.js +1 -1
  119. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +1 -1
  120. package/dist/esm/features/soft_navigations/aggregate/index.js +1 -1
  121. package/dist/esm/features/soft_navigations/aggregate/interaction.js +5 -5
  122. package/dist/esm/features/soft_navigations/instrument/index.js +1 -1
  123. package/dist/esm/features/spa/aggregate/index.js +3 -4
  124. package/dist/esm/features/spa/aggregate/interaction.js +2 -2
  125. package/dist/esm/features/spa/aggregate/serializer.js +1 -2
  126. package/dist/esm/features/spa/instrument/index.js +1 -1
  127. package/dist/esm/features/utils/aggregate-base.js +7 -4
  128. package/dist/esm/features/utils/instrument-base.js +2 -2
  129. package/dist/esm/features/utils/lazy-feature-loader.js +2 -2
  130. package/dist/esm/index.js +3 -0
  131. package/dist/esm/loaders/agent-base.js +1 -5
  132. package/dist/esm/loaders/agent.js +3 -4
  133. package/dist/esm/loaders/api/api.js +10 -8
  134. package/dist/esm/loaders/api/apiAsync.js +1 -1
  135. package/dist/esm/loaders/browser-agent.js +3 -2
  136. package/dist/esm/loaders/configure/configure.js +4 -3
  137. package/dist/esm/loaders/features/features.js +8 -4
  138. package/dist/esm/loaders/micro-agent.js +6 -6
  139. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  140. package/dist/types/common/config/state/init.d.ts.map +1 -1
  141. package/dist/types/common/constants/runtime.d.ts +0 -1
  142. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  143. package/dist/types/common/drain/drain.d.ts.map +1 -1
  144. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  145. package/dist/types/common/timing/time-keeper.d.ts +2 -1
  146. package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
  147. package/dist/types/common/url/encode.d.ts.map +1 -1
  148. package/dist/types/common/util/console.d.ts +1 -1
  149. package/dist/types/common/util/console.d.ts.map +1 -1
  150. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  151. package/dist/types/common/wrap/wrap-logger.d.ts.map +1 -1
  152. package/dist/types/features/{page_action → generic_events}/aggregate/index.d.ts +7 -5
  153. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -0
  154. package/dist/types/features/generic_events/constants.d.ts +2 -0
  155. package/dist/types/features/generic_events/constants.d.ts.map +1 -0
  156. package/dist/types/features/generic_events/index.d.ts +2 -0
  157. package/dist/types/features/generic_events/index.d.ts.map +1 -0
  158. package/dist/types/features/generic_events/instrument/index.d.ts +6 -0
  159. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -0
  160. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  161. package/dist/types/features/logging/constants.d.ts +0 -3
  162. package/dist/types/features/logging/constants.d.ts.map +1 -1
  163. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  164. package/dist/types/features/page_action/instrument/index.d.ts +5 -4
  165. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  166. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  167. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  168. package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
  169. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  170. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  171. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -1
  172. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  173. package/dist/types/index.d.ts +3 -0
  174. package/dist/types/loaders/agent-base.d.ts +0 -1
  175. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  176. package/dist/types/loaders/agent.d.ts.map +1 -1
  177. package/dist/types/loaders/api/api.d.ts.map +1 -1
  178. package/dist/types/loaders/browser-agent.d.ts.map +1 -1
  179. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  180. package/dist/types/loaders/features/features.d.ts +1 -0
  181. package/dist/types/loaders/features/features.d.ts.map +1 -1
  182. package/package.json +25 -6
  183. package/src/cdn/experimental.js +2 -4
  184. package/src/cdn/pro.js +2 -2
  185. package/src/cdn/spa.js +2 -2
  186. package/src/common/aggregate/aggregator.js +2 -3
  187. package/src/common/config/state/configurable.js +4 -4
  188. package/src/common/config/state/init.js +6 -4
  189. package/src/common/constants/runtime.js +0 -2
  190. package/src/common/context/shared-context.js +2 -2
  191. package/src/common/drain/drain.js +4 -5
  192. package/src/common/harvest/harvest.js +4 -4
  193. package/src/common/serialize/bel-serializer.js +1 -2
  194. package/src/common/session/session-entity.js +4 -4
  195. package/src/common/timing/time-keeper.js +14 -2
  196. package/src/common/url/encode.js +2 -3
  197. package/src/common/util/console.js +3 -4
  198. package/src/common/util/obfuscate.js +3 -3
  199. package/src/common/util/submit-data.js +0 -1
  200. package/src/common/wrap/wrap-logger.js +1 -2
  201. package/src/common/wrap/wrap-xhr.js +1 -1
  202. package/src/features/generic_events/aggregate/index.js +133 -0
  203. package/src/features/generic_events/constants.js +3 -0
  204. package/src/features/generic_events/index.js +1 -0
  205. package/src/features/generic_events/instrument/index.js +22 -0
  206. package/src/features/jserrors/aggregate/index.js +4 -5
  207. package/src/features/logging/aggregate/index.js +6 -6
  208. package/src/features/logging/constants.js +0 -4
  209. package/src/features/metrics/aggregate/index.js +12 -0
  210. package/src/features/page_action/instrument/index.js +6 -6
  211. package/src/features/page_view_event/aggregate/index.js +22 -5
  212. package/src/features/page_view_event/aggregate/initialized-features.js +1 -1
  213. package/src/features/page_view_timing/aggregate/index.js +1 -2
  214. package/src/features/session_replay/aggregate/index.js +1 -1
  215. package/src/features/session_replay/shared/recorder.js +1 -1
  216. package/src/features/spa/aggregate/index.js +2 -3
  217. package/src/features/spa/aggregate/interaction.js +1 -2
  218. package/src/features/spa/aggregate/serializer.js +1 -2
  219. package/src/features/utils/aggregate-base.js +7 -4
  220. package/src/features/utils/instrument-base.js +2 -2
  221. package/src/features/utils/lazy-feature-loader.js +2 -2
  222. package/src/index.js +3 -0
  223. package/src/loaders/agent-base.js +1 -5
  224. package/src/loaders/agent.js +3 -4
  225. package/src/loaders/api/api.js +10 -8
  226. package/src/loaders/api/apiAsync.js +1 -1
  227. package/src/loaders/browser-agent.js +5 -3
  228. package/src/loaders/configure/configure.js +5 -1
  229. package/src/loaders/features/features.js +8 -4
  230. package/src/loaders/micro-agent.js +6 -6
  231. package/dist/cjs/cdn/polyfills/lite.js +0 -16
  232. package/dist/cjs/cdn/polyfills/pro.js +0 -21
  233. package/dist/cjs/cdn/polyfills/spa.js +0 -22
  234. package/dist/cjs/cdn/polyfills.js +0 -24
  235. package/dist/cjs/common/util/map-own.js +0 -31
  236. package/dist/cjs/features/page_action/aggregate/index.js +0 -121
  237. package/dist/esm/cdn/polyfills/lite.js +0 -14
  238. package/dist/esm/cdn/polyfills/pro.js +0 -19
  239. package/dist/esm/cdn/polyfills/spa.js +0 -20
  240. package/dist/esm/cdn/polyfills.js +0 -27
  241. package/dist/esm/common/util/map-own.js +0 -24
  242. package/dist/esm/features/page_action/aggregate/index.js +0 -114
  243. package/dist/types/cdn/polyfills/lite.d.ts +0 -2
  244. package/dist/types/cdn/polyfills/lite.d.ts.map +0 -1
  245. package/dist/types/cdn/polyfills/pro.d.ts +0 -2
  246. package/dist/types/cdn/polyfills/pro.d.ts.map +0 -1
  247. package/dist/types/cdn/polyfills/spa.d.ts +0 -2
  248. package/dist/types/cdn/polyfills/spa.d.ts.map +0 -1
  249. package/dist/types/cdn/polyfills.d.ts +0 -2
  250. package/dist/types/cdn/polyfills.d.ts.map +0 -1
  251. package/dist/types/common/util/map-own.d.ts +0 -3
  252. package/dist/types/common/util/map-own.d.ts.map +0 -1
  253. package/dist/types/features/page_action/aggregate/index.d.ts.map +0 -1
  254. package/src/cdn/polyfills/lite.js +0 -20
  255. package/src/cdn/polyfills/pro.js +0 -30
  256. package/src/cdn/polyfills/spa.js +0 -32
  257. package/src/cdn/polyfills.js +0 -27
  258. package/src/common/util/map-own.js +0 -22
  259. package/src/features/page_action/aggregate/index.js +0 -114
@@ -0,0 +1,133 @@
1
+ /*
2
+ * Copyright 2020 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { stringify } from '../../../common/util/stringify'
6
+ import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
7
+ import { cleanURL } from '../../../common/url/clean-url'
8
+ import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
9
+ import { FEATURE_NAME } from '../constants'
10
+ import { isBrowserScope } from '../../../common/constants/runtime'
11
+ import { AggregateBase } from '../../utils/aggregate-base'
12
+ import { warn } from '../../../common/util/console'
13
+ import { now } from '../../../common/timing/now'
14
+ import { registerHandler } from '../../../common/event-emitter/register-handler'
15
+ import { deregisterDrain } from '../../../common/drain/drain'
16
+ import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
17
+
18
+ export class Aggregate extends AggregateBase {
19
+ #agentRuntime
20
+ static featureName = FEATURE_NAME
21
+ constructor (agentIdentifier, aggregator) {
22
+ super(agentIdentifier, aggregator, FEATURE_NAME)
23
+
24
+ this.eventsPerHarvest = 1000
25
+ this.harvestTimeSeconds = getConfigurationValue(this.agentIdentifier, 'generic_events.harvestTimeSeconds')
26
+
27
+ this.referrerUrl = (isBrowserScope && document.referrer) ? cleanURL(document.referrer) : undefined
28
+ this.currentEvents = []
29
+
30
+ this.events = []
31
+ this.overflow = []
32
+
33
+ this.#agentRuntime = getRuntime(this.agentIdentifier)
34
+
35
+ this.waitForFlags(['ins']).then(([ins]) => {
36
+ if (!ins) {
37
+ this.blocked = true
38
+ deregisterDrain(this.agentIdentifier, this.featureName)
39
+ return
40
+ }
41
+
42
+ if (getConfigurationValue(this.agentIdentifier, 'page_action.enabled')) {
43
+ registerHandler('api-addPageAction', (timestamp, name, attributes) => {
44
+ this.addEvent({
45
+ ...attributes,
46
+ eventType: 'PageAction',
47
+ timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(timestamp),
48
+ timeSinceLoad: timestamp / 1000,
49
+ actionName: name,
50
+ referrerUrl: this.referrerUrl,
51
+ currentUrl: cleanURL('' + location),
52
+ ...(isBrowserScope && {
53
+ browserWidth: window.document.documentElement?.clientWidth,
54
+ browserHeight: window.document.documentElement?.clientHeight
55
+ })
56
+ })
57
+ }, this.featureName, this.ee)
58
+ }
59
+
60
+ this.harvestScheduler = new HarvestScheduler('ins', { onFinished: (...args) => this.onHarvestFinished(...args) }, this)
61
+ this.harvestScheduler.harvest.on('ins', (...args) => this.onHarvestStarted(...args))
62
+ this.harvestScheduler.startTimer(this.harvestTimeSeconds, 0)
63
+
64
+ this.drain()
65
+ })
66
+ }
67
+
68
+ onHarvestStarted (options) {
69
+ const { userAttributes, atts } = getInfo(this.agentIdentifier)
70
+ const harvestEvents = this.overflow.length ? this.overflow.splice(0, Infinity) : this.events.splice(0, Infinity)
71
+ var payload = ({
72
+ qs: {
73
+ ua: userAttributes,
74
+ at: atts
75
+ },
76
+ body: {
77
+ ins: harvestEvents
78
+ }
79
+ })
80
+
81
+ if (options.retry) {
82
+ this.currentEvents = harvestEvents
83
+ }
84
+
85
+ return payload
86
+ }
87
+
88
+ onHarvestFinished (result) {
89
+ if (result && result.sent && result.retry && this.currentEvents.length) {
90
+ this.events = this.currentEvents.concat(this.events)
91
+ this.currentEvents = []
92
+ }
93
+ }
94
+
95
+ // WARNING: Insights times are in seconds. EXCEPT timestamp, which is in ms.
96
+ addEvent (obj = {}) {
97
+ if (!obj || !Object.keys(obj).length) return
98
+ if (!obj.eventType) {
99
+ warn(44)
100
+ return
101
+ }
102
+
103
+ for (let key in obj) {
104
+ let val = obj[key]
105
+ obj[key] = (val && typeof val === 'object' ? stringify(val) : val)
106
+ }
107
+
108
+ const defaultEventAttributes = {
109
+ /** should be overridden by the event-specific attributes, but just in case -- set it to now() */
110
+ timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(now()),
111
+ /** all generic events require a pageUrl */
112
+ pageUrl: cleanURL(getRuntime(this.agentIdentifier).origin)
113
+ }
114
+
115
+ const eventAttributes = {
116
+ /** Agent-level custom attributes */
117
+ ...(getInfo(this.agentIdentifier).jsAttributes || {}),
118
+ /** Fallbacks for required properties in-case the event did not supply them, should take precedence over agent-level custom attrs */
119
+ ...defaultEventAttributes,
120
+ /** Event-specific attributes take precedence over agent-level custom attributes and fallbacks */
121
+ ...obj
122
+ }
123
+
124
+ this.events.push(eventAttributes)
125
+
126
+ // check if we've reached the harvest limit...
127
+ if (this.events.length >= this.eventsPerHarvest) {
128
+ this.ee.emit(SUPPORTABILITY_METRIC_CHANNEL, ['GenericEvents/Harvest/Max/Seen'])
129
+ this.overflow = [...this.overflow, ...this.events.splice(0, Infinity)]
130
+ this.harvestScheduler.runHarvest()
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,3 @@
1
+ import { FEATURE_NAMES } from '../../loaders/features/features'
2
+
3
+ export const FEATURE_NAME = FEATURE_NAMES.genericEvents
@@ -0,0 +1 @@
1
+ export { Instrument as GenericEvents } from './instrument/index'
@@ -0,0 +1,22 @@
1
+ /* Copyright 2020 New Relic Corporation. All rights reserved.
2
+ * SPDX-License-Identifier: Apache-2.0
3
+ */
4
+
5
+ import { getConfigurationValue } from '../../../common/config/config'
6
+ import { deregisterDrain } from '../../../common/drain/drain'
7
+ import { InstrumentBase } from '../../utils/instrument-base'
8
+ import { FEATURE_NAME } from '../constants'
9
+
10
+ export class Instrument extends InstrumentBase {
11
+ static featureName = FEATURE_NAME
12
+ constructor (agentIdentifier, aggregator, auto = true) {
13
+ super(agentIdentifier, aggregator, FEATURE_NAME, auto)
14
+ const genericEventSourceConfigs = [
15
+ getConfigurationValue(this.agentIdentifier, 'page_action.enabled')
16
+ // other future generic event source configs to go here, like M&Ms, PageResouce, etc.
17
+ ]
18
+ /** If any of the sources are active, import the aggregator. otherwise deregister */
19
+ if (genericEventSourceConfigs.some(x => x)) this.importAggregator()
20
+ else deregisterDrain(this.agentIdentifier, this.featureName)
21
+ }
22
+ }
@@ -12,7 +12,6 @@ import { registerHandler as register } from '../../../common/event-emitter/regis
12
12
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
13
13
  import { stringify } from '../../../common/util/stringify'
14
14
  import { handle } from '../../../common/event-emitter/handle'
15
- import { mapOwn } from '../../../common/util/map-own'
16
15
  import { getInfo, getConfigurationValue, getRuntime } from '../../../common/config/config'
17
16
  import { globalScope } from '../../../common/constants/runtime'
18
17
 
@@ -91,7 +90,7 @@ export class Aggregate extends AggregateBase {
91
90
 
92
91
  onHarvestFinished (result) {
93
92
  if (result.retry && this.currentBody) {
94
- mapOwn(this.currentBody, (key, value) => {
93
+ Object.entries(this.currentBody || {}).forEach(([key, value]) => {
95
94
  for (var i = 0; i < value.length; i++) {
96
95
  var bucket = value[i]
97
96
  var name = this.getBucketName(key, bucket.params, bucket.custom)
@@ -264,8 +263,8 @@ export class Aggregate extends AggregateBase {
264
263
  var allCustomAttrs = {}
265
264
  const localCustomAttrs = item[4]
266
265
 
267
- mapOwn(interaction.root.attrs.custom, setCustom) // tack on custom attrs from the interaction
268
- mapOwn(localCustomAttrs, setCustom)
266
+ Object.entries(interaction.root.attrs.custom || {}).forEach(setCustom) // tack on custom attrs from the interaction
267
+ Object.entries(localCustomAttrs || {}).forEach(setCustom)
269
268
 
270
269
  var params = item[2]
271
270
  if (wasSaved) {
@@ -281,7 +280,7 @@ export class Aggregate extends AggregateBase {
281
280
 
282
281
  this.aggregator.store(item[0], aggregateHash, params, item[3], allCustomAttrs)
283
282
 
284
- function setCustom (key, val) {
283
+ function setCustom ([key, val]) {
285
284
  allCustomAttrs[key] = (val && typeof val === 'object' ? stringify(val) : val)
286
285
  }
287
286
  })
@@ -6,7 +6,7 @@ import { warn } from '../../../common/util/console'
6
6
  import { stringify } from '../../../common/util/stringify'
7
7
  import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
8
8
  import { AggregateBase } from '../../utils/aggregate-base'
9
- import { FEATURE_NAME, LOGGING_EVENT_EMITTER_CHANNEL, LOGGING_IGNORED, LOGGING_LEVEL_FAILURE_MESSAGE, LOG_LEVELS, MAX_PAYLOAD_SIZE } from '../constants'
9
+ import { FEATURE_NAME, LOGGING_EVENT_EMITTER_CHANNEL, LOG_LEVELS, MAX_PAYLOAD_SIZE } from '../constants'
10
10
  import { Log } from '../shared/log'
11
11
  import { isValidLogLevel } from '../shared/utils'
12
12
 
@@ -49,7 +49,7 @@ export class Aggregate extends AggregateBase {
49
49
 
50
50
  if (!attributes || typeof attributes !== 'object') attributes = {}
51
51
  if (typeof level === 'string') level = level.toUpperCase()
52
- if (!isValidLogLevel(level)) return warn(LOGGING_LEVEL_FAILURE_MESSAGE + level, Object.values(LOG_LEVELS))
52
+ if (!isValidLogLevel(level)) return warn(30, level)
53
53
 
54
54
  try {
55
55
  if (typeof message !== 'string') {
@@ -63,13 +63,13 @@ export class Aggregate extends AggregateBase {
63
63
  else message = String(message)
64
64
  }
65
65
  } catch (err) {
66
- warn('could not cast log message to string', message)
66
+ warn(16, message)
67
67
  return
68
68
  }
69
- if (typeof message !== 'string' || !message) return warn(LOGGING_IGNORED + 'invalid message')
69
+ if (typeof message !== 'string' || !message) return warn(32)
70
70
  if (message.length > MAX_PAYLOAD_SIZE) {
71
71
  handle(SUPPORTABILITY_METRIC_CHANNEL, ['Logging/Harvest/Failed/Seen', message.length])
72
- return warn(LOGGING_IGNORED + '> ' + MAX_PAYLOAD_SIZE + ' bytes: ', message.slice(0, 25) + '...')
72
+ return warn(31, message.slice(0, 25) + '...')
73
73
  }
74
74
 
75
75
  const log = new Log(
@@ -81,7 +81,7 @@ export class Aggregate extends AggregateBase {
81
81
  const logBytes = log.message.length + stringify(log.attributes).length + log.level.length + 10 // timestamp == 10 chars
82
82
  if (logBytes > MAX_PAYLOAD_SIZE) {
83
83
  handle(SUPPORTABILITY_METRIC_CHANNEL, ['Logging/Harvest/Failed/Seen', logBytes])
84
- return warn(LOGGING_IGNORED + '> ' + MAX_PAYLOAD_SIZE + ' bytes: ', log.message.slice(0, 25) + '...')
84
+ return warn(31, log.message.slice(0, 25) + '...')
85
85
  }
86
86
 
87
87
  if (this.estimatedBytes + logBytes >= MAX_PAYLOAD_SIZE) {
@@ -13,7 +13,3 @@ export const LOGGING_EVENT_EMITTER_CHANNEL = 'log'
13
13
  export const FEATURE_NAME = FEATURE_NAMES.logging
14
14
 
15
15
  export const MAX_PAYLOAD_SIZE = 1000000
16
-
17
- export const LOGGING_FAILURE_MESSAGE = 'failed to wrap logger: '
18
- export const LOGGING_LEVEL_FAILURE_MESSAGE = 'invalid log level: '
19
- export const LOGGING_IGNORED = 'ignored log: '
@@ -96,6 +96,18 @@ export class Aggregate extends AggregateBase {
96
96
  // Check if proxy for either chunks or beacon is being used
97
97
  if (proxy.assets) this.storeSupportabilityMetrics('Config/AssetsUrl/Changed')
98
98
  if (proxy.beacon) this.storeSupportabilityMetrics('Config/BeaconUrl/Changed')
99
+
100
+ if (isBrowserScope && window.MutationObserver) {
101
+ this.storeSupportabilityMetrics('Generic/VideoElement/Added', window.document.querySelectorAll('video').length)
102
+ const mo = new MutationObserver(records => {
103
+ records.forEach(record => {
104
+ record.addedNodes.forEach(addedNode => {
105
+ if (addedNode instanceof HTMLVideoElement) { this.storeSupportabilityMetrics('Generic/VideoElement/Added', 1) }
106
+ })
107
+ })
108
+ })
109
+ mo.observe(window.document.body, { childList: true, subtree: true })
110
+ }
99
111
  }
100
112
 
101
113
  eachSessionChecks () {
@@ -3,13 +3,13 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
- import { InstrumentBase } from '../../utils/instrument-base'
7
- import { FEATURE_NAME } from '../constants'
6
+ import { GenericEvents } from '../../generic_events'
8
7
 
9
- export class Instrument extends InstrumentBase {
10
- static featureName = FEATURE_NAME
8
+ /**
9
+ * @deprecated This feature has been replaced by Generic Events. Use/Import `GenericEvents` instead. This wrapper will be removed in a future release
10
+ */
11
+ export class Instrument extends GenericEvents {
11
12
  constructor (agentIdentifier, aggregator, auto = true) {
12
- super(agentIdentifier, aggregator, FEATURE_NAME, auto)
13
- this.importAggregator()
13
+ super(agentIdentifier, aggregator, auto)
14
14
  }
15
15
  }
@@ -1,7 +1,7 @@
1
1
  import { globalScope, isBrowserScope, originTime } from '../../../common/constants/runtime'
2
2
  import { addPT, addPN } from '../../../common/timing/nav-timing'
3
3
  import { stringify } from '../../../common/util/stringify'
4
- import { getInfo, getRuntime } from '../../../common/config/config'
4
+ import { getInfo, getRuntime, isConfigured } from '../../../common/config/config'
5
5
  import { Harvest } from '../../../common/harvest/harvest'
6
6
  import * as CONSTANTS from '../constants'
7
7
  import { getActivatedFeaturesFlags } from './initialized-features'
@@ -28,6 +28,11 @@ export class Aggregate extends AggregateBase {
28
28
  this.firstByteToDomContent = 0 // our "dom processing" duration
29
29
  this.timeKeeper = new TimeKeeper(this.agentIdentifier)
30
30
 
31
+ if (!isConfigured(agentIdentifier)) {
32
+ this.ee.abort()
33
+ return warn(43)
34
+ }
35
+
31
36
  if (isBrowserScope) {
32
37
  timeToFirstByte.subscribe(({ value, attrs }) => {
33
38
  const navEntry = attrs.navigationEntry
@@ -48,7 +53,6 @@ export class Aggregate extends AggregateBase {
48
53
  const agentRuntime = getRuntime(this.agentIdentifier)
49
54
  const harvester = new Harvest(this)
50
55
 
51
- if (!info.beacon) return
52
56
  if (info.queueTime) this.aggregator.store('measures', 'qt', { value: info.queueTime })
53
57
  if (info.applicationTime) this.aggregator.store('measures', 'ap', { value: info.applicationTime })
54
58
 
@@ -126,11 +130,24 @@ export class Aggregate extends AggregateBase {
126
130
  if (!this.timeKeeper.ready) throw new Error('TimeKeeper not ready')
127
131
 
128
132
  agentRuntime.timeKeeper = this.timeKeeper
133
+
134
+ // Check if the time diff is such that we need to capture a supportability metric
135
+ if (this.timeKeeper.localTimeDiff >= 12 * 60 * 60 * 1000) {
136
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/DiffExceed12Hrs'], undefined, FEATURE_NAMES.metrics, this.ee)
137
+ } else if (this.timeKeeper.localTimeDiff >= 6 * 60 * 60 * 1000) {
138
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/DiffExceed6Hrs'], undefined, FEATURE_NAMES.metrics, this.ee)
139
+ } else if (this.timeKeeper.localTimeDiff >= 60 * 60 * 1000) {
140
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/DiffExceed1Hrs'], undefined, FEATURE_NAMES.metrics, this.ee)
141
+ }
129
142
  } catch (error) {
130
- handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/Failed'], undefined, FEATURE_NAMES.metrics, this.ee)
143
+ if (error?.message?.indexOf('invalid format') > 0) {
144
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/InvalidFormat'], undefined, FEATURE_NAMES.metrics, this.ee)
145
+ } else {
146
+ handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/Failed'], undefined, FEATURE_NAMES.metrics, this.ee)
147
+ }
131
148
  drain(this.agentIdentifier, FEATURE_NAMES.metrics, true)
132
149
  this.ee.abort()
133
- warn('Could not calculate New Relic server time. Agent shutting down.', error)
150
+ warn(17, error)
134
151
  return
135
152
  }
136
153
 
@@ -141,7 +158,7 @@ export class Aggregate extends AggregateBase {
141
158
  this.drain()
142
159
  } catch (err) {
143
160
  this.ee.abort()
144
- warn('RUM call failed. Agent shutting down.', err)
161
+ warn(18, err)
145
162
  }
146
163
  }
147
164
  })
@@ -18,7 +18,7 @@ export function getActivatedFeaturesFlags (agentId) {
18
18
  flagArr.push('xhr'); break
19
19
  case FEATURE_NAMES.jserrors:
20
20
  flagArr.push('err'); break
21
- case FEATURE_NAMES.pageAction:
21
+ case FEATURE_NAMES.genericEvents:
22
22
  flagArr.push('ins'); break
23
23
  case FEATURE_NAMES.sessionTrace:
24
24
  flagArr.push('stn'); break
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
7
- import { mapOwn } from '../../../common/util/map-own'
8
7
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
9
8
  import { registerHandler } from '../../../common/event-emitter/register-handler'
10
9
  import { handle } from '../../../common/event-emitter/handle'
@@ -138,7 +137,7 @@ export class Aggregate extends AggregateBase {
138
137
 
139
138
  var reservedAttributes = ['size', 'eid', 'cls', 'type', 'fid', 'elTag', 'elUrl', 'net-type',
140
139
  'net-etype', 'net-rtt', 'net-dlink']
141
- mapOwn(customAttributes, function (key, val) {
140
+ Object.entries(customAttributes || {}).forEach(([key, val]) => {
142
141
  if (reservedAttributes.indexOf(key) < 0) {
143
142
  timingAttributes[key] = val
144
143
  }
@@ -394,7 +394,7 @@ export class Aggregate extends AggregateBase {
394
394
 
395
395
  /** Abort the feature, once aborted it will not resume */
396
396
  abort (reason = {}, data) {
397
- warn(`SR aborted -- ${reason.message}`)
397
+ warn(33, reason.message)
398
398
  handle(SUPPORTABILITY_METRIC_CHANNEL, [`SessionReplay/Abort/${reason.sm}`, data], undefined, FEATURE_NAMES.metrics, this.ee)
399
399
  this.blocked = true
400
400
  this.mode = MODE.OFF
@@ -35,7 +35,7 @@ export class Recorder {
35
35
  /** Config to inform to inline stylesheet contents (true default) */
36
36
  this.shouldInlineStylesheets = getConfigurationValue(this.parent.agentIdentifier, 'session_replay.inline_stylesheet')
37
37
  /** A flag that can be set to false by failing conversions to stop the fetching process */
38
- this.shouldFix = this.shouldInlineStylesheets
38
+ this.shouldFix = this.shouldInlineStylesheets && getConfigurationValue(this.parent.agentIdentifier, 'session_replay.fix_stylesheets')
39
39
  /** The method to stop recording. This defaults to a noop, but is overwritten once the recording library is imported and initialized */
40
40
  this.stopRecording = () => { /* no-op until set by rrweb initializer */ }
41
41
  }
@@ -6,7 +6,6 @@
6
6
  import { registerHandler as register } from '../../../common/event-emitter/register-handler'
7
7
  import { parseUrl } from '../../../common/url/parse-url'
8
8
  import { shouldCollectEvent } from '../../../common/deny-list/deny-list'
9
- import { mapOwn } from '../../../common/util/map-own'
10
9
  import { navTimingValues as navTiming } from '../../../common/timing/nav-timing'
11
10
  import { generateUuid } from '../../../common/ids/unique-id'
12
11
  import { Interaction } from './interaction'
@@ -668,7 +667,7 @@ export class Aggregate extends AggregateBase {
668
667
 
669
668
  // make sure that newrelic[INTERACTION]() works in end handler
670
669
  state.currentNode = root
671
- mapOwn(interaction.handlers, function (i, cb) {
670
+ Object.values(interaction.handlers || {}).forEach(function (cb) {
672
671
  cb(attrs.store)
673
672
  })
674
673
  setCurrentNode(null)
@@ -757,7 +756,7 @@ export class Aggregate extends AggregateBase {
757
756
  handle(SUPPORTABILITY_METRIC_CHANNEL, [`Spa/Interaction/${smCategory}/Duration/Ms`, Math.max((interaction.root?.end || 0) - (interaction.root?.start || 0), 0)], undefined, FEATURE_NAMES.metrics, baseEE)
758
757
 
759
758
  scheduler?.scheduleHarvest(0)
760
- if (!scheduler) warn('SPA scheduler is not initialized. Saved interaction is not sent!')
759
+ if (!scheduler) warn(19)
761
760
  }
762
761
 
763
762
  function isEnabled () {
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { getInfo, getRuntime, originals } from '../../../common/config/config'
7
- import { mapOwn } from '../../../common/util/map-own'
8
7
  import { ee } from '../../../common/event-emitter/contextual-ee'
9
8
  import { InteractionNode } from './interaction-node'
10
9
 
@@ -101,7 +100,7 @@ InteractionPrototype.finish = function finishInteraction () {
101
100
  this.onFinished(this)
102
101
  }
103
102
 
104
- mapOwn(getInfo(interaction.agentIdentifier).jsAttributes, function (attr, value) {
103
+ Object.entries(getInfo(interaction.agentIdentifier).jsAttributes || {}).forEach(([attr, value]) => {
105
104
  if (!(attr in customAttrs)) customAttrs[attr] = value
106
105
  })
107
106
 
@@ -3,7 +3,6 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { cleanURL } from '../../../common/url/clean-url'
6
- import { mapOwn } from '../../../common/util/map-own'
7
6
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
8
7
  import { SharedContext } from '../../../common/context/shared-context'
9
8
  import { getInfo } from '../../../common/config/config'
@@ -181,7 +180,7 @@ export class Serializer extends SharedContext {
181
180
  // get all navTiming values except navigationStart
182
181
  // (since its the same as interaction.start)
183
182
  // and limit to just the first 20 values we know about
184
- mapOwn(navTiming.slice(1, 21), function (i, v) {
183
+ Object.values(navTiming.slice(1, 21) || {}).forEach((v) => {
185
184
  if (v !== undefined) {
186
185
  navTimingNode += seperator + numeric(v - prev)
187
186
  seperator = ','
@@ -2,7 +2,7 @@ import { FeatureBase } from './feature-base'
2
2
  import { getInfo, isConfigured, getRuntime } from '../../common/config/config'
3
3
  import { configure } from '../../loaders/configure/configure'
4
4
  import { gosCDN } from '../../common/window/nreum'
5
- import { drain } from '../../common/drain/drain'
5
+ import { deregisterDrain, drain } from '../../common/drain/drain'
6
6
  import { activatedFeatures } from '../../common/util/feature-flags'
7
7
 
8
8
  export class AggregateBase extends FeatureBase {
@@ -34,6 +34,8 @@ export class AggregateBase extends FeatureBase {
34
34
  })
35
35
  return flagsPromise.catch(err => {
36
36
  this.ee.emit('internal-error', [err])
37
+ this.blocked = true
38
+ deregisterDrain(this.agentIdentifier, this.featureName)
37
39
  })
38
40
  }
39
41
 
@@ -49,7 +51,8 @@ export class AggregateBase extends FeatureBase {
49
51
  checkConfiguration () {
50
52
  // NOTE: This check has to happen at aggregator load time
51
53
  if (!isConfigured(this.agentIdentifier)) {
52
- let jsAttributes = { ...gosCDN().info?.jsAttributes }
54
+ const cdn = gosCDN()
55
+ let jsAttributes = { ...cdn.info?.jsAttributes }
53
56
  try {
54
57
  jsAttributes = {
55
58
  ...jsAttributes,
@@ -59,9 +62,9 @@ export class AggregateBase extends FeatureBase {
59
62
  // do nothing
60
63
  }
61
64
  configure({ agentIdentifier: this.agentIdentifier }, {
62
- ...gosCDN(),
65
+ ...cdn,
63
66
  info: {
64
- ...gosCDN().info,
67
+ ...cdn.info,
65
68
  jsAttributes
66
69
  },
67
70
  runtime: getRuntime(this.agentIdentifier)
@@ -85,7 +85,7 @@ export class InstrumentBase extends FeatureBase {
85
85
  session = setupAgentSession(this.agentIdentifier)
86
86
  }
87
87
  } catch (e) {
88
- warn('A problem occurred when starting up session manager. This page will not start or extend any session.', e)
88
+ warn(20, e)
89
89
  this.ee.emit('internal-error', [e])
90
90
  if (this.featureName === FEATURE_NAMES.sessionReplay) this.abortHandler?.() // SR should stop recording if session DNE
91
91
  }
@@ -105,7 +105,7 @@ export class InstrumentBase extends FeatureBase {
105
105
  this.featAggregate = new Aggregate(this.agentIdentifier, this.aggregator, argsObjFromInstrument)
106
106
  loadedSuccessfully(true)
107
107
  } catch (e) {
108
- warn(`Downloading and initializing ${this.featureName} failed...`, e)
108
+ warn(34, e)
109
109
  this.abortHandler?.() // undo any important alterations made to the page
110
110
  // not supported yet but nice to do: "abort" this agent's EE for this feature specifically
111
111
  drain(this.agentIdentifier, this.featureName, true)
@@ -18,12 +18,12 @@ export function lazyFeatureLoader (featureName, featurePart) {
18
18
  return import(/* webpackChunkName: "ajax-aggregate" */ '../ajax/aggregate')
19
19
  case FEATURE_NAMES.jserrors:
20
20
  return import(/* webpackChunkName: "jserrors-aggregate" */ '../jserrors/aggregate')
21
+ case FEATURE_NAMES.genericEvents:
22
+ return import(/* webpackChunkName: "generic_events-aggregate" */ '../generic_events/aggregate')
21
23
  case FEATURE_NAMES.logging:
22
24
  return import(/* webpackChunkName: "logging-aggregate" */ '../logging/aggregate')
23
25
  case FEATURE_NAMES.metrics:
24
26
  return import(/* webpackChunkName: "metrics-aggregate" */ '../metrics/aggregate')
25
- case FEATURE_NAMES.pageAction:
26
- return import(/* webpackChunkName: "page_action-aggregate" */ '../page_action/aggregate')
27
27
  case FEATURE_NAMES.pageViewEvent:
28
28
  return import(/* webpackChunkName: "page_view_event-aggregate" */ '../page_view_event/aggregate')
29
29
  case FEATURE_NAMES.pageViewTiming:
package/src/index.js CHANGED
@@ -4,9 +4,12 @@ export { MicroAgent } from './loaders/micro-agent'
4
4
 
5
5
  export { Ajax } from './features/ajax'
6
6
  export { JSErrors } from './features/jserrors'
7
+ export { GenericEvents } from './features/generic_events'
8
+ export { Logging } from './features/logging'
7
9
  export { Metrics } from './features/metrics'
8
10
  export { PageAction } from './features/page_action'
9
11
  export { PageViewEvent } from './features/page_view_event'
10
12
  export { PageViewTiming } from './features/page_view_timing'
11
13
  export { SessionTrace } from './features/session_trace'
14
+ export { SessionReplay } from './features/session_replay'
12
15
  export { Spa } from './features/spa'
@@ -3,7 +3,6 @@
3
3
  import { warn } from '../common/util/console'
4
4
  import { SR_EVENT_EMITTER_TYPES } from '../features/session_replay/constants'
5
5
  import { generateRandomHexString } from '../common/ids/unique-id'
6
- import { ee } from '../common/event-emitter/contextual-ee'
7
6
 
8
7
  /**
9
8
  * @typedef {import('./api/interaction-types').InteractionInstance} InteractionInstance
@@ -14,9 +13,6 @@ export class AgentBase {
14
13
 
15
14
  constructor (agentIdentifier = generateRandomHexString(16)) {
16
15
  this.agentIdentifier = agentIdentifier
17
-
18
- // Assign the observation context to the event emitter, so it knows how to create observation contexts
19
- this.ee = ee.get(agentIdentifier)
20
16
  }
21
17
 
22
18
  /**
@@ -25,7 +21,7 @@ export class AgentBase {
25
21
  * @param {...any} args
26
22
  */
27
23
  #callMethod (methodName, ...args) {
28
- if (typeof this.api?.[methodName] !== 'function') warn(`Call to agent api ${methodName} failed. The API is not currently initialized.`)
24
+ if (typeof this.api?.[methodName] !== 'function') warn(35, methodName)
29
25
  else return this.api[methodName](...args)
30
26
  }
31
27
 
@@ -13,7 +13,6 @@ import { Instrument as PageViewEvent } from '../features/page_view_event/instrum
13
13
  import { Aggregator } from '../common/aggregate/aggregator'
14
14
  import { gosNREUM, setNREUMInitializedAgent } from '../common/window/nreum'
15
15
  import { warn } from '../common/util/console'
16
- import { stringify } from '../common/util/stringify'
17
16
  import { globalScope } from '../common/constants/runtime'
18
17
 
19
18
  /**
@@ -31,7 +30,7 @@ export class Agent extends AgentBase {
31
30
  if (!globalScope) {
32
31
  // We could not determine the runtime environment. Short-circuite the agent here
33
32
  // to avoid possible exceptions later that may cause issues with customer's application.
34
- warn('Failed to initialize the agent. Could not determine the runtime environment.')
33
+ warn(21)
35
34
  return
36
35
  }
37
36
 
@@ -74,12 +73,12 @@ export class Agent extends AgentBase {
74
73
 
75
74
  const dependencies = getFeatureDependencyNames(InstrumentCtor.featureName)
76
75
  const hasAllDeps = dependencies.every(featName => featName in this.features) // any other feature(s) this depends on should've been initialized on prior iterations by priority order
77
- if (!hasAllDeps) warn(`${InstrumentCtor.featureName} is enabled but one or more dependent features has not been initialized (${stringify(dependencies)}). This may cause unintended consequences or missing data...`)
76
+ if (!hasAllDeps) warn(36, InstrumentCtor.featureName)
78
77
 
79
78
  this.features[InstrumentCtor.featureName] = new InstrumentCtor(this.agentIdentifier, this.sharedAggregator)
80
79
  })
81
80
  } catch (err) {
82
- warn('Failed to initialize all enabled instrument classes (agent aborted) -', err)
81
+ warn(22, err)
83
82
  for (const featName in this.features) { // this.features hold only features that have been instantiated
84
83
  this.features[featName].abortHandler?.()
85
84
  }