@newrelic/browser-agent 1.263.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 (210) hide show
  1. package/CHANGELOG.md +8 -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/init.js +6 -3
  8. package/dist/cjs/common/constants/env.cdn.js +1 -1
  9. package/dist/cjs/common/constants/env.npm.js +1 -1
  10. package/dist/cjs/common/constants/runtime.js +1 -3
  11. package/dist/cjs/common/drain/drain.js +4 -4
  12. package/dist/cjs/common/harvest/harvest.js +2 -2
  13. package/dist/cjs/common/serialize/bel-serializer.js +2 -2
  14. package/dist/cjs/common/session/session-entity.js +1 -1
  15. package/dist/cjs/common/url/encode.js +3 -5
  16. package/dist/cjs/common/util/submit-data.js +0 -1
  17. package/dist/cjs/common/vitals/vital-metric.js +1 -1
  18. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  19. package/dist/cjs/features/ajax/instrument/index.js +1 -1
  20. package/dist/cjs/features/generic_events/aggregate/index.js +137 -0
  21. package/dist/cjs/features/generic_events/constants.js +8 -0
  22. package/dist/cjs/features/generic_events/index.js +12 -0
  23. package/dist/cjs/features/generic_events/instrument/index.js +27 -0
  24. package/dist/cjs/features/jserrors/aggregate/index.js +13 -12
  25. package/dist/cjs/features/jserrors/instrument/index.js +1 -1
  26. package/dist/cjs/features/logging/aggregate/index.js +1 -1
  27. package/dist/cjs/features/logging/instrument/index.js +1 -1
  28. package/dist/cjs/features/metrics/aggregate/index.js +1 -1
  29. package/dist/cjs/features/metrics/instrument/index.js +1 -1
  30. package/dist/cjs/features/page_action/instrument/index.js +6 -6
  31. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -1
  32. package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +1 -1
  33. package/dist/cjs/features/page_view_event/instrument/index.js +1 -1
  34. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -3
  35. package/dist/cjs/features/page_view_timing/instrument/index.js +1 -1
  36. package/dist/cjs/features/session_replay/aggregate/index.js +2 -2
  37. package/dist/cjs/features/session_replay/instrument/index.js +1 -1
  38. package/dist/cjs/features/session_replay/shared/stylesheet-evaluator.js +1 -1
  39. package/dist/cjs/features/session_trace/aggregate/index.js +1 -1
  40. package/dist/cjs/features/session_trace/aggregate/trace/storage.js +2 -2
  41. package/dist/cjs/features/session_trace/instrument/index.js +1 -1
  42. package/dist/cjs/features/soft_navigations/aggregate/bel-node.js +1 -1
  43. package/dist/cjs/features/soft_navigations/aggregate/index.js +1 -1
  44. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +5 -5
  45. package/dist/cjs/features/soft_navigations/instrument/index.js +1 -1
  46. package/dist/cjs/features/spa/aggregate/index.js +2 -3
  47. package/dist/cjs/features/spa/aggregate/interaction.js +2 -2
  48. package/dist/cjs/features/spa/aggregate/serializer.js +1 -2
  49. package/dist/cjs/features/spa/instrument/index.js +1 -1
  50. package/dist/cjs/features/utils/aggregate-base.js +2 -0
  51. package/dist/cjs/features/utils/lazy-feature-loader.js +2 -2
  52. package/dist/cjs/index.js +21 -0
  53. package/dist/cjs/loaders/agent-base.js +0 -4
  54. package/dist/cjs/loaders/api/api.js +1 -1
  55. package/dist/cjs/loaders/api/apiAsync.js +1 -1
  56. package/dist/cjs/loaders/browser-agent.js +4 -3
  57. package/dist/cjs/loaders/configure/configure.js +4 -3
  58. package/dist/cjs/loaders/features/features.js +8 -4
  59. package/dist/cjs/loaders/micro-agent.js +1 -1
  60. package/dist/esm/cdn/experimental.js +2 -5
  61. package/dist/esm/cdn/pro.js +2 -2
  62. package/dist/esm/cdn/spa.js +2 -2
  63. package/dist/esm/common/aggregate/aggregator.js +3 -3
  64. package/dist/esm/common/config/state/init.js +6 -3
  65. package/dist/esm/common/constants/env.cdn.js +1 -1
  66. package/dist/esm/common/constants/env.npm.js +1 -1
  67. package/dist/esm/common/constants/runtime.js +0 -2
  68. package/dist/esm/common/drain/drain.js +4 -4
  69. package/dist/esm/common/harvest/harvest.js +3 -3
  70. package/dist/esm/common/serialize/bel-serializer.js +2 -2
  71. package/dist/esm/common/session/session-entity.js +2 -2
  72. package/dist/esm/common/url/encode.js +3 -5
  73. package/dist/esm/common/util/submit-data.js +0 -1
  74. package/dist/esm/common/vitals/vital-metric.js +1 -1
  75. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  76. package/dist/esm/features/ajax/instrument/index.js +1 -1
  77. package/dist/esm/features/generic_events/aggregate/index.js +129 -0
  78. package/dist/esm/features/generic_events/constants.js +2 -0
  79. package/dist/esm/features/generic_events/index.js +1 -0
  80. package/dist/esm/features/generic_events/instrument/index.js +20 -0
  81. package/dist/esm/features/jserrors/aggregate/index.js +13 -12
  82. package/dist/esm/features/jserrors/instrument/index.js +1 -1
  83. package/dist/esm/features/logging/aggregate/index.js +1 -1
  84. package/dist/esm/features/logging/instrument/index.js +1 -1
  85. package/dist/esm/features/metrics/aggregate/index.js +1 -1
  86. package/dist/esm/features/metrics/instrument/index.js +1 -1
  87. package/dist/esm/features/page_action/instrument/index.js +7 -6
  88. package/dist/esm/features/page_view_event/aggregate/index.js +1 -1
  89. package/dist/esm/features/page_view_event/aggregate/initialized-features.js +1 -1
  90. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  91. package/dist/esm/features/page_view_timing/aggregate/index.js +3 -3
  92. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  93. package/dist/esm/features/session_replay/aggregate/index.js +2 -2
  94. package/dist/esm/features/session_replay/instrument/index.js +1 -1
  95. package/dist/esm/features/session_replay/shared/stylesheet-evaluator.js +1 -1
  96. package/dist/esm/features/session_trace/aggregate/index.js +1 -1
  97. package/dist/esm/features/session_trace/aggregate/trace/storage.js +2 -2
  98. package/dist/esm/features/session_trace/instrument/index.js +1 -1
  99. package/dist/esm/features/soft_navigations/aggregate/bel-node.js +1 -1
  100. package/dist/esm/features/soft_navigations/aggregate/index.js +1 -1
  101. package/dist/esm/features/soft_navigations/aggregate/interaction.js +5 -5
  102. package/dist/esm/features/soft_navigations/instrument/index.js +1 -1
  103. package/dist/esm/features/spa/aggregate/index.js +2 -3
  104. package/dist/esm/features/spa/aggregate/interaction.js +2 -2
  105. package/dist/esm/features/spa/aggregate/serializer.js +1 -2
  106. package/dist/esm/features/spa/instrument/index.js +1 -1
  107. package/dist/esm/features/utils/aggregate-base.js +3 -1
  108. package/dist/esm/features/utils/lazy-feature-loader.js +2 -2
  109. package/dist/esm/index.js +3 -0
  110. package/dist/esm/loaders/agent-base.js +0 -4
  111. package/dist/esm/loaders/api/api.js +1 -1
  112. package/dist/esm/loaders/api/apiAsync.js +1 -1
  113. package/dist/esm/loaders/browser-agent.js +3 -2
  114. package/dist/esm/loaders/configure/configure.js +4 -3
  115. package/dist/esm/loaders/features/features.js +8 -4
  116. package/dist/esm/loaders/micro-agent.js +1 -1
  117. package/dist/types/common/aggregate/aggregator.d.ts.map +1 -1
  118. package/dist/types/common/config/state/init.d.ts.map +1 -1
  119. package/dist/types/common/constants/runtime.d.ts +0 -1
  120. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  121. package/dist/types/common/drain/drain.d.ts.map +1 -1
  122. package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -1
  123. package/dist/types/common/url/encode.d.ts.map +1 -1
  124. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  125. package/dist/types/features/{page_action → generic_events}/aggregate/index.d.ts +7 -5
  126. package/dist/types/features/generic_events/aggregate/index.d.ts.map +1 -0
  127. package/dist/types/features/generic_events/constants.d.ts +2 -0
  128. package/dist/types/features/generic_events/constants.d.ts.map +1 -0
  129. package/dist/types/features/generic_events/index.d.ts +2 -0
  130. package/dist/types/features/generic_events/index.d.ts.map +1 -0
  131. package/dist/types/features/generic_events/instrument/index.d.ts +6 -0
  132. package/dist/types/features/generic_events/instrument/index.d.ts.map +1 -0
  133. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  134. package/dist/types/features/page_action/instrument/index.d.ts +5 -4
  135. package/dist/types/features/page_action/instrument/index.d.ts.map +1 -1
  136. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  137. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  138. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  139. package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -1
  140. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  141. package/dist/types/index.d.ts +3 -0
  142. package/dist/types/loaders/agent-base.d.ts +0 -1
  143. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  144. package/dist/types/loaders/browser-agent.d.ts.map +1 -1
  145. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  146. package/dist/types/loaders/features/features.d.ts +1 -0
  147. package/dist/types/loaders/features/features.d.ts.map +1 -1
  148. package/package.json +25 -6
  149. package/src/cdn/experimental.js +2 -4
  150. package/src/cdn/pro.js +2 -2
  151. package/src/cdn/spa.js +2 -2
  152. package/src/common/aggregate/aggregator.js +2 -3
  153. package/src/common/config/state/init.js +2 -1
  154. package/src/common/constants/runtime.js +0 -2
  155. package/src/common/drain/drain.js +3 -4
  156. package/src/common/harvest/harvest.js +3 -3
  157. package/src/common/serialize/bel-serializer.js +1 -2
  158. package/src/common/session/session-entity.js +2 -2
  159. package/src/common/url/encode.js +2 -3
  160. package/src/common/util/submit-data.js +0 -1
  161. package/src/features/generic_events/aggregate/index.js +133 -0
  162. package/src/features/generic_events/constants.js +3 -0
  163. package/src/features/generic_events/index.js +1 -0
  164. package/src/features/generic_events/instrument/index.js +22 -0
  165. package/src/features/jserrors/aggregate/index.js +4 -5
  166. package/src/features/page_action/instrument/index.js +6 -6
  167. package/src/features/page_view_event/aggregate/initialized-features.js +1 -1
  168. package/src/features/page_view_timing/aggregate/index.js +1 -2
  169. package/src/features/spa/aggregate/index.js +1 -2
  170. package/src/features/spa/aggregate/interaction.js +1 -2
  171. package/src/features/spa/aggregate/serializer.js +1 -2
  172. package/src/features/utils/aggregate-base.js +3 -1
  173. package/src/features/utils/lazy-feature-loader.js +2 -2
  174. package/src/index.js +3 -0
  175. package/src/loaders/agent-base.js +0 -4
  176. package/src/loaders/api/api.js +1 -1
  177. package/src/loaders/api/apiAsync.js +1 -1
  178. package/src/loaders/browser-agent.js +5 -3
  179. package/src/loaders/configure/configure.js +5 -1
  180. package/src/loaders/features/features.js +8 -4
  181. package/src/loaders/micro-agent.js +1 -1
  182. package/dist/cjs/cdn/polyfills/lite.js +0 -16
  183. package/dist/cjs/cdn/polyfills/pro.js +0 -21
  184. package/dist/cjs/cdn/polyfills/spa.js +0 -22
  185. package/dist/cjs/cdn/polyfills.js +0 -24
  186. package/dist/cjs/common/util/map-own.js +0 -31
  187. package/dist/cjs/features/page_action/aggregate/index.js +0 -121
  188. package/dist/esm/cdn/polyfills/lite.js +0 -14
  189. package/dist/esm/cdn/polyfills/pro.js +0 -19
  190. package/dist/esm/cdn/polyfills/spa.js +0 -20
  191. package/dist/esm/cdn/polyfills.js +0 -27
  192. package/dist/esm/common/util/map-own.js +0 -24
  193. package/dist/esm/features/page_action/aggregate/index.js +0 -114
  194. package/dist/types/cdn/polyfills/lite.d.ts +0 -2
  195. package/dist/types/cdn/polyfills/lite.d.ts.map +0 -1
  196. package/dist/types/cdn/polyfills/pro.d.ts +0 -2
  197. package/dist/types/cdn/polyfills/pro.d.ts.map +0 -1
  198. package/dist/types/cdn/polyfills/spa.d.ts +0 -2
  199. package/dist/types/cdn/polyfills/spa.d.ts.map +0 -1
  200. package/dist/types/cdn/polyfills.d.ts +0 -2
  201. package/dist/types/cdn/polyfills.d.ts.map +0 -1
  202. package/dist/types/common/util/map-own.d.ts +0 -3
  203. package/dist/types/common/util/map-own.d.ts.map +0 -1
  204. package/dist/types/features/page_action/aggregate/index.d.ts.map +0 -1
  205. package/src/cdn/polyfills/lite.js +0 -20
  206. package/src/cdn/polyfills/pro.js +0 -30
  207. package/src/cdn/polyfills/spa.js +0 -32
  208. package/src/cdn/polyfills.js +0 -27
  209. package/src/common/util/map-own.js +0 -22
  210. package/src/features/page_action/aggregate/index.js +0 -114
@@ -37,8 +37,6 @@ export const ffVersion = (() => {
37
37
  }
38
38
  return 0;
39
39
  })();
40
- export const isIE = Boolean(isBrowserScope && window.document.documentMode); // deprecated property that only works in IE
41
-
42
40
  export const supportsSendBeacon = !!globalScope.navigator?.sendBeacon;
43
41
 
44
42
  /**
@@ -4,7 +4,6 @@
4
4
  */
5
5
 
6
6
  import { ee } from '../event-emitter/contextual-ee';
7
- import { mapOwn } from '../util/map-own';
8
7
  import { registerHandler as defaultRegister } from '../event-emitter/register-handler';
9
8
  import { featurePriority } from '../../loaders/features/features';
10
9
  const registry = {};
@@ -111,8 +110,9 @@ function drainGroup(agentIdentifier, group) {
111
110
  // eslint-disable-line no-unmodified-loop-condition
112
111
  emitEvent(bufferedEventsInGroup[i], groupHandlers);
113
112
  }
114
- mapOwn(groupHandlers, function (eventType, handlerRegistrationList) {
115
- mapOwn(handlerRegistrationList, function (i, registration) {
113
+ Object.entries(groupHandlers).forEach(_ref3 => {
114
+ let [eventType, handlerRegistrationList] = _ref3;
115
+ Object.values(handlerRegistrationList || {}).forEach(registration => {
116
116
  // registration is an array of: [targetEE, eventHandler]
117
117
  registration[0].on(eventType, registration[1]);
118
118
  });
@@ -133,7 +133,7 @@ function drainGroup(agentIdentifier, group) {
133
133
  */
134
134
  function emitEvent(evt, groupHandlers) {
135
135
  var type = evt[1];
136
- mapOwn(groupHandlers[type], function (i, registration) {
136
+ Object.values(groupHandlers[type] || {}).forEach(registration => {
137
137
  var sourceEE = evt[0];
138
138
  var ee = registration[0];
139
139
  if (ee === sourceEE) {
@@ -14,7 +14,7 @@ import { Obfuscator } from '../util/obfuscate';
14
14
  import { applyFnToProps } from '../util/traverse';
15
15
  import { SharedContext } from '../context/shared-context';
16
16
  import { VERSION } from "../constants/env.npm";
17
- import { isWorkerScope, isIE } from '../constants/runtime';
17
+ import { isWorkerScope } from '../constants/runtime';
18
18
  import { warn } from '../util/console';
19
19
  import { now } from '../timing/now';
20
20
  const warnings = {};
@@ -163,11 +163,11 @@ export class Harvest extends SharedContext {
163
163
  /* Since workers don't support sendBeacon right now, they can only use XHR method.
164
164
  Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
165
165
  we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon.
166
- Following the removal of img-element method, IE will also use sync XHR on page dismissal to ensure final analytics are sent. */
166
+ Following the removal of img-element method. */
167
167
  let result = submitMethod({
168
168
  url: fullUrl,
169
169
  body,
170
- sync: opts.unload && (isWorkerScope || isIE),
170
+ sync: opts.unload && isWorkerScope,
171
171
  headers
172
172
  });
173
173
  if (!opts.unload && cbFinished && submitMethod === submitData.xhr) {
@@ -3,7 +3,6 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
- import { mapOwn } from '../util/map-own';
7
6
  import { stringify } from '../util/stringify';
8
7
  import { Obfuscator } from '../util/obfuscate';
9
8
  var hasOwnProp = Object.prototype.hasOwnProperty;
@@ -39,7 +38,8 @@ export function getAddStringContext(agentIdentifier) {
39
38
  }
40
39
  export function addCustomAttributes(attrs, addString) {
41
40
  var attrParts = [];
42
- mapOwn(attrs, function (key, val) {
41
+ Object.entries(attrs || {}).forEach(_ref => {
42
+ let [key, val] = _ref;
43
43
  if (attrParts.length >= MAX_ATTRIBUTES) return;
44
44
  var type = 5;
45
45
  var serializedValue;
@@ -3,7 +3,7 @@ import { warn } from '../util/console';
3
3
  import { stringify } from '../util/stringify';
4
4
  import { ee } from '../event-emitter/contextual-ee';
5
5
  import { Timer } from '../timer/timer';
6
- import { isBrowserScope, isIE } from '../constants/runtime';
6
+ import { isBrowserScope } from '../constants/runtime';
7
7
  import { DEFAULT_EXPIRES_MS, DEFAULT_INACTIVE_MS, MODE, PREFIX, SESSION_EVENTS, SESSION_EVENT_TYPES } from './constants';
8
8
  import { InteractionTimer } from '../timer/interaction-timer';
9
9
  import { wrapEvents } from '../wrap';
@@ -59,7 +59,7 @@ export class SessionEntity {
59
59
  * if the event was spawned on the current page or an adjacent page, and the behavior tied
60
60
  * to storage events is critical to apply only to cross-tab behavior
61
61
  * */
62
- if (isBrowserScope && !isIE) {
62
+ if (isBrowserScope) {
63
63
  windowAddEventListener('storage', event => {
64
64
  if (event.key === this.lookupKey) {
65
65
  const obj = typeof event.newValue === 'string' ? JSON.parse(event.newValue) : event.newValue;
@@ -3,7 +3,6 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
- import { mapOwn } from '../util/map-own';
7
6
  import { stringify } from '../util/stringify';
8
7
 
9
8
  // Characters that are safe in a qs, but get encoded.
@@ -15,9 +14,7 @@ var charMap = {
15
14
  '%24': '$',
16
15
  '%3B': ';'
17
16
  };
18
- var charList = mapOwn(charMap, function (k) {
19
- return k;
20
- });
17
+ var charList = Object.keys(charMap);
21
18
  var safeEncoded = new RegExp(charList.join('|'), 'g');
22
19
  function real(c) {
23
20
  return charMap[c];
@@ -40,7 +37,8 @@ export function fromArray(qs, maxBytes) {
40
37
  export function obj(payload, maxBytes) {
41
38
  var total = 0;
42
39
  var result = '';
43
- mapOwn(payload, function (feature, dataArray) {
40
+ Object.entries(payload || {}).forEach(_ref => {
41
+ let [feature, dataArray] = _ref;
44
42
  var intermediate = [];
45
43
  var next;
46
44
  var i;
@@ -23,7 +23,6 @@ export function getSubmitMethod() {
23
23
  return isFinalHarvest && isBrowserScope && supportsSendBeacon
24
24
  // Use sendBeacon for final harvest
25
25
  ? beacon
26
- // Only IE does not support sendBeacon for final harvest
27
26
  // If not final harvest, or not browserScope, always use xhr post
28
27
  : xhr;
29
28
  }
@@ -1,5 +1,5 @@
1
1
  export class VitalMetric {
2
- #subscribers = new Set();
2
+ #subscribers = (() => new Set())();
3
3
  history = [];
4
4
  constructor(name, roundingMethod) {
5
5
  this.name = name;
@@ -16,7 +16,7 @@ import { parseGQL } from './gql';
16
16
  import { getNREUMInitializedAgent } from '../../../common/window/nreum';
17
17
  import Chunk from './chunk';
18
18
  export class Aggregate extends AggregateBase {
19
- static featureName = FEATURE_NAME;
19
+ static featureName = (() => FEATURE_NAME)();
20
20
  #agentInfo;
21
21
  #agentRuntime;
22
22
  #agentInit;
@@ -23,7 +23,7 @@ var handlersLen = handlers.length;
23
23
  var origRequest = originals.REQ;
24
24
  var origXHR = originals.XHR;
25
25
  export class Instrument extends InstrumentBase {
26
- static featureName = FEATURE_NAME;
26
+ static featureName = (() => FEATURE_NAME)();
27
27
  constructor(agentIdentifier, aggregator) {
28
28
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
29
29
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
@@ -0,0 +1,129 @@
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
+ export class Aggregate extends AggregateBase {
18
+ #agentRuntime;
19
+ static featureName = (() => FEATURE_NAME)();
20
+ constructor(agentIdentifier, aggregator) {
21
+ var _this;
22
+ super(agentIdentifier, aggregator, FEATURE_NAME);
23
+ _this = this;
24
+ this.eventsPerHarvest = 1000;
25
+ this.harvestTimeSeconds = getConfigurationValue(this.agentIdentifier, 'generic_events.harvestTimeSeconds');
26
+ this.referrerUrl = isBrowserScope && document.referrer ? cleanURL(document.referrer) : undefined;
27
+ this.currentEvents = [];
28
+ this.events = [];
29
+ this.overflow = [];
30
+ this.#agentRuntime = getRuntime(this.agentIdentifier);
31
+ this.waitForFlags(['ins']).then(_ref => {
32
+ let [ins] = _ref;
33
+ if (!ins) {
34
+ this.blocked = true;
35
+ deregisterDrain(this.agentIdentifier, this.featureName);
36
+ return;
37
+ }
38
+ if (getConfigurationValue(this.agentIdentifier, 'page_action.enabled')) {
39
+ registerHandler('api-addPageAction', (timestamp, name, attributes) => {
40
+ this.addEvent({
41
+ ...attributes,
42
+ eventType: 'PageAction',
43
+ timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(timestamp),
44
+ timeSinceLoad: timestamp / 1000,
45
+ actionName: name,
46
+ referrerUrl: this.referrerUrl,
47
+ currentUrl: cleanURL('' + location),
48
+ ...(isBrowserScope && {
49
+ browserWidth: window.document.documentElement?.clientWidth,
50
+ browserHeight: window.document.documentElement?.clientHeight
51
+ })
52
+ });
53
+ }, this.featureName, this.ee);
54
+ }
55
+ this.harvestScheduler = new HarvestScheduler('ins', {
56
+ onFinished: function () {
57
+ return _this.onHarvestFinished(...arguments);
58
+ }
59
+ }, this);
60
+ this.harvestScheduler.harvest.on('ins', function () {
61
+ return _this.onHarvestStarted(...arguments);
62
+ });
63
+ this.harvestScheduler.startTimer(this.harvestTimeSeconds, 0);
64
+ this.drain();
65
+ });
66
+ }
67
+ onHarvestStarted(options) {
68
+ const {
69
+ userAttributes,
70
+ atts
71
+ } = getInfo(this.agentIdentifier);
72
+ const harvestEvents = this.overflow.length ? this.overflow.splice(0, Infinity) : this.events.splice(0, Infinity);
73
+ var payload = {
74
+ qs: {
75
+ ua: userAttributes,
76
+ at: atts
77
+ },
78
+ body: {
79
+ ins: harvestEvents
80
+ }
81
+ };
82
+ if (options.retry) {
83
+ this.currentEvents = harvestEvents;
84
+ }
85
+ return payload;
86
+ }
87
+ onHarvestFinished(result) {
88
+ if (result && result.sent && result.retry && this.currentEvents.length) {
89
+ this.events = this.currentEvents.concat(this.events);
90
+ this.currentEvents = [];
91
+ }
92
+ }
93
+
94
+ // WARNING: Insights times are in seconds. EXCEPT timestamp, which is in ms.
95
+ addEvent() {
96
+ let obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
97
+ if (!obj || !Object.keys(obj).length) return;
98
+ if (!obj.eventType) {
99
+ warn(44);
100
+ return;
101
+ }
102
+ for (let key in obj) {
103
+ let val = obj[key];
104
+ obj[key] = val && typeof val === 'object' ? stringify(val) : val;
105
+ }
106
+ const defaultEventAttributes = {
107
+ /** should be overridden by the event-specific attributes, but just in case -- set it to now() */
108
+ timestamp: this.#agentRuntime.timeKeeper.convertRelativeTimestamp(now()),
109
+ /** all generic events require a pageUrl */
110
+ pageUrl: cleanURL(getRuntime(this.agentIdentifier).origin)
111
+ };
112
+ const eventAttributes = {
113
+ /** Agent-level custom attributes */
114
+ ...(getInfo(this.agentIdentifier).jsAttributes || {}),
115
+ /** Fallbacks for required properties in-case the event did not supply them, should take precedence over agent-level custom attrs */
116
+ ...defaultEventAttributes,
117
+ /** Event-specific attributes take precedence over agent-level custom attributes and fallbacks */
118
+ ...obj
119
+ };
120
+ this.events.push(eventAttributes);
121
+
122
+ // check if we've reached the harvest limit...
123
+ if (this.events.length >= this.eventsPerHarvest) {
124
+ this.ee.emit(SUPPORTABILITY_METRIC_CHANNEL, ['GenericEvents/Harvest/Max/Seen']);
125
+ this.overflow = [...this.overflow, ...this.events.splice(0, Infinity)];
126
+ this.harvestScheduler.runHarvest();
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,2 @@
1
+ import { FEATURE_NAMES } from '../../loaders/features/features';
2
+ export const FEATURE_NAME = FEATURE_NAMES.genericEvents;
@@ -0,0 +1 @@
1
+ export { Instrument as GenericEvents } from './instrument/index';
@@ -0,0 +1,20 @@
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
+ export class Instrument extends InstrumentBase {
10
+ static featureName = (() => FEATURE_NAME)();
11
+ constructor(agentIdentifier, aggregator) {
12
+ let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
13
+ super(agentIdentifier, aggregator, FEATURE_NAME, auto);
14
+ const genericEventSourceConfigs = [getConfigurationValue(this.agentIdentifier, 'page_action.enabled')
15
+ // other future generic event source configs to go here, like M&Ms, PageResouce, etc.
16
+ ];
17
+ /** If any of the sources are active, import the aggregator. otherwise deregister */
18
+ if (genericEventSourceConfigs.some(x => x)) this.importAggregator();else deregisterDrain(this.agentIdentifier, this.featureName);
19
+ }
20
+ }
@@ -11,7 +11,6 @@ import { registerHandler as register } from '../../../common/event-emitter/regis
11
11
  import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler';
12
12
  import { stringify } from '../../../common/util/stringify';
13
13
  import { handle } from '../../../common/event-emitter/handle';
14
- import { mapOwn } from '../../../common/util/map-own';
15
14
  import { getInfo, getConfigurationValue, getRuntime } from '../../../common/config/config';
16
15
  import { globalScope } from '../../../common/constants/runtime';
17
16
  import { FEATURE_NAME } from '../constants';
@@ -26,7 +25,7 @@ import { now } from '../../../common/timing/now';
26
25
  */
27
26
 
28
27
  export class Aggregate extends AggregateBase {
29
- static featureName = FEATURE_NAME;
28
+ static featureName = (() => FEATURE_NAME)();
30
29
  constructor(agentIdentifier, aggregator) {
31
30
  var _this;
32
31
  super(agentIdentifier, aggregator, FEATURE_NAME);
@@ -95,7 +94,8 @@ export class Aggregate extends AggregateBase {
95
94
  }
96
95
  onHarvestFinished(result) {
97
96
  if (result.retry && this.currentBody) {
98
- mapOwn(this.currentBody, (key, value) => {
97
+ Object.entries(this.currentBody || {}).forEach(_ref2 => {
98
+ let [key, value] = _ref2;
99
99
  for (var i = 0; i < value.length; i++) {
100
100
  var bucket = value[i];
101
101
  var name = this.getBucketName(key, bucket.params, bucket.custom);
@@ -225,8 +225,8 @@ export class Aggregate extends AggregateBase {
225
225
  let [type, bucketHash, params, newMetrics, localAttrs] = errorInfoArr;
226
226
  const allCustomAttrs = {};
227
227
  if (softNavOccurredFinished) {
228
- Object.entries(softNavCustomAttrs).forEach(_ref2 => {
229
- let [k, v] = _ref2;
228
+ Object.entries(softNavCustomAttrs).forEach(_ref3 => {
229
+ let [k, v] = _ref3;
230
230
  return setCustom(k, v);
231
231
  }); // when an ixn finishes, it'll include stuff in jsAttributes + attrs specific to the ixn
232
232
  bucketHash += params.browserInteractionId;
@@ -234,14 +234,14 @@ export class Aggregate extends AggregateBase {
234
234
  delete params._softNavFinished;
235
235
  } else {
236
236
  // interaction was cancelled -> error should not be associated OR there was no interaction
237
- Object.entries(getInfo(this.agentIdentifier).jsAttributes).forEach(_ref3 => {
238
- let [k, v] = _ref3;
237
+ Object.entries(getInfo(this.agentIdentifier).jsAttributes).forEach(_ref4 => {
238
+ let [k, v] = _ref4;
239
239
  return setCustom(k, v);
240
240
  });
241
241
  delete params.browserInteractionId;
242
242
  }
243
- if (localAttrs) Object.entries(localAttrs).forEach(_ref4 => {
244
- let [k, v] = _ref4;
243
+ if (localAttrs) Object.entries(localAttrs).forEach(_ref5 => {
244
+ let [k, v] = _ref5;
245
245
  return setCustom(k, v);
246
246
  }); // local custom attrs are applied in either case with the highest precedence
247
247
 
@@ -259,8 +259,8 @@ export class Aggregate extends AggregateBase {
259
259
  this.bufferedErrorsUnderSpa[interaction.id].forEach(item => {
260
260
  var allCustomAttrs = {};
261
261
  const localCustomAttrs = item[4];
262
- mapOwn(interaction.root.attrs.custom, setCustom); // tack on custom attrs from the interaction
263
- mapOwn(localCustomAttrs, setCustom);
262
+ Object.entries(interaction.root.attrs.custom || {}).forEach(setCustom); // tack on custom attrs from the interaction
263
+ Object.entries(localCustomAttrs || {}).forEach(setCustom);
264
264
  var params = item[2];
265
265
  if (wasSaved) {
266
266
  params.browserInteractionId = interaction.root.attrs.id;
@@ -272,7 +272,8 @@ export class Aggregate extends AggregateBase {
272
272
  var jsAttributesHash = stringHashCode(stringify(allCustomAttrs));
273
273
  var aggregateHash = hash + ':' + jsAttributesHash;
274
274
  this.aggregator.store(item[0], aggregateHash, params, item[3], allCustomAttrs);
275
- function setCustom(key, val) {
275
+ function setCustom(_ref6) {
276
+ let [key, val] = _ref6;
276
277
  allCustomAttrs[key] = val && typeof val === 'object' ? stringify(val) : val;
277
278
  }
278
279
  });
@@ -12,7 +12,7 @@ import { now } from '../../../common/timing/now';
12
12
  import { SR_EVENT_EMITTER_TYPES } from '../../session_replay/constants';
13
13
  import { castError, castErrorEvent, castPromiseRejectionEvent } from '../shared/cast-error';
14
14
  export class Instrument extends InstrumentBase {
15
- static featureName = FEATURE_NAME;
15
+ static featureName = (() => FEATURE_NAME)();
16
16
  #replayRunning = false;
17
17
  constructor(agentIdentifier, aggregator) {
18
18
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
@@ -10,7 +10,7 @@ import { FEATURE_NAME, LOGGING_EVENT_EMITTER_CHANNEL, LOG_LEVELS, MAX_PAYLOAD_SI
10
10
  import { Log } from '../shared/log';
11
11
  import { isValidLogLevel } from '../shared/utils';
12
12
  export class Aggregate extends AggregateBase {
13
- static featureName = FEATURE_NAME;
13
+ static featureName = (() => FEATURE_NAME)();
14
14
  #agentRuntime;
15
15
  #agentInfo;
16
16
  constructor(agentIdentifier, aggregator) {
@@ -2,7 +2,7 @@ import { InstrumentBase } from '../../utils/instrument-base';
2
2
  import { FEATURE_NAME } from '../constants';
3
3
  import { bufferLog } from '../shared/utils';
4
4
  export class Instrument extends InstrumentBase {
5
- static featureName = FEATURE_NAME;
5
+ static featureName = (() => FEATURE_NAME)();
6
6
  constructor(agentIdentifier, aggregator) {
7
7
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
8
8
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
@@ -11,7 +11,7 @@ import { isBrowserScope, isWorkerScope } from '../../../common/constants/runtime
11
11
  import { AggregateBase } from '../../utils/aggregate-base';
12
12
  import { deregisterDrain } from '../../../common/drain/drain';
13
13
  export class Aggregate extends AggregateBase {
14
- static featureName = FEATURE_NAME;
14
+ static featureName = (() => FEATURE_NAME)();
15
15
  constructor(agentIdentifier, aggregator) {
16
16
  super(agentIdentifier, aggregator, FEATURE_NAME);
17
17
  this.waitForFlags(['err']).then(_ref => {
@@ -1,7 +1,7 @@
1
1
  import { InstrumentBase } from '../../utils/instrument-base';
2
2
  import { FEATURE_NAME } from '../constants';
3
3
  export class Instrument extends InstrumentBase {
4
- static featureName = FEATURE_NAME;
4
+ static featureName = (() => FEATURE_NAME)();
5
5
  constructor(agentIdentifier, aggregator) {
6
6
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
7
7
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
@@ -3,13 +3,14 @@
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';
8
- export class Instrument extends InstrumentBase {
9
- static featureName = FEATURE_NAME;
6
+ import { GenericEvents } from '../../generic_events';
7
+
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 {
10
12
  constructor(agentIdentifier, aggregator) {
11
13
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
12
- super(agentIdentifier, aggregator, FEATURE_NAME, auto);
13
- this.importAggregator();
14
+ super(agentIdentifier, aggregator, auto);
14
15
  }
15
16
  }
@@ -18,7 +18,7 @@ import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants';
18
18
  import { now } from '../../../common/timing/now';
19
19
  import { TimeKeeper } from '../../../common/timing/time-keeper';
20
20
  export class Aggregate extends AggregateBase {
21
- static featureName = CONSTANTS.FEATURE_NAME;
21
+ static featureName = (() => CONSTANTS.FEATURE_NAME)();
22
22
  constructor(agentIdentifier, aggregator) {
23
23
  super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME);
24
24
  this.timeToFirstByte = 0;
@@ -19,7 +19,7 @@ export function getActivatedFeaturesFlags(agentId) {
19
19
  case FEATURE_NAMES.jserrors:
20
20
  flagArr.push('err');
21
21
  break;
22
- case FEATURE_NAMES.pageAction:
22
+ case FEATURE_NAMES.genericEvents:
23
23
  flagArr.push('ins');
24
24
  break;
25
25
  case FEATURE_NAMES.sessionTrace:
@@ -1,7 +1,7 @@
1
1
  import { InstrumentBase } from '../../utils/instrument-base';
2
2
  import * as CONSTANTS from '../constants';
3
3
  export class Instrument extends InstrumentBase {
4
- static featureName = CONSTANTS.FEATURE_NAME;
4
+ static featureName = (() => CONSTANTS.FEATURE_NAME)();
5
5
  constructor(agentIdentifier, aggregator) {
6
6
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
7
7
  super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME, auto);
@@ -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';
@@ -23,7 +22,7 @@ import { longTask } from '../../../common/vitals/long-task';
23
22
  import { subscribeToVisibilityChange } from '../../../common/window/page-visibility';
24
23
  import { VITAL_NAMES } from '../../../common/vitals/constants';
25
24
  export class Aggregate extends AggregateBase {
26
- static featureName = FEATURE_NAME;
25
+ static featureName = (() => FEATURE_NAME)();
27
26
  #handleVitalMetric = _ref => {
28
27
  let {
29
28
  name,
@@ -141,7 +140,8 @@ export class Aggregate extends AggregateBase {
141
140
  var timingAttributes = timing.attrs || {};
142
141
  var customAttributes = getInfo(this.agentIdentifier).jsAttributes || {};
143
142
  var reservedAttributes = ['size', 'eid', 'cls', 'type', 'fid', 'elTag', 'elUrl', 'net-type', 'net-etype', 'net-rtt', 'net-dlink'];
144
- mapOwn(customAttributes, function (key, val) {
143
+ Object.entries(customAttributes || {}).forEach(_ref3 => {
144
+ let [key, val] = _ref3;
145
145
  if (reservedAttributes.indexOf(key) < 0) {
146
146
  timingAttributes[key] = val;
147
147
  }
@@ -10,7 +10,7 @@ import { FEATURE_NAME } from '../constants';
10
10
  import { isBrowserScope } from '../../../common/constants/runtime';
11
11
  import { now } from '../../../common/timing/now';
12
12
  export class Instrument extends InstrumentBase {
13
- static featureName = FEATURE_NAME;
13
+ static featureName = (() => FEATURE_NAME)();
14
14
  constructor(agentIdentifier, aggregator) {
15
15
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
16
16
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
@@ -30,8 +30,8 @@ import { deregisterDrain } from '../../../common/drain/drain';
30
30
  import { now } from '../../../common/timing/now';
31
31
  import { buildNRMetaNode } from '../shared/utils';
32
32
  export class Aggregate extends AggregateBase {
33
- static featureName = FEATURE_NAME;
34
- mode = MODE.OFF;
33
+ static featureName = (() => FEATURE_NAME)();
34
+ mode = (() => MODE.OFF)();
35
35
 
36
36
  // pass the recorder into the aggregator
37
37
  constructor(agentIdentifier, aggregator, args) {
@@ -15,7 +15,7 @@ import { InstrumentBase } from '../../utils/instrument-base';
15
15
  import { hasReplayPrerequisite, isPreloadAllowed } from '../shared/utils';
16
16
  import { FEATURE_NAME, SR_EVENT_EMITTER_TYPES, TRIGGERS } from '../constants';
17
17
  export class Instrument extends InstrumentBase {
18
- static featureName = FEATURE_NAME;
18
+ static featureName = (() => FEATURE_NAME)();
19
19
  #mode;
20
20
  constructor(agentIdentifier, aggregator) {
21
21
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
@@ -1,7 +1,7 @@
1
1
  import { originals } from '../../../common/config/config';
2
2
  import { isBrowserScope } from '../../../common/constants/runtime';
3
3
  class StylesheetEvaluator {
4
- #evaluated = new WeakSet();
4
+ #evaluated = (() => new WeakSet())();
5
5
  #fetchProms = [];
6
6
  /**
7
7
  * Flipped to true if stylesheets that cannot be natively inlined are detected by the stylesheetEvaluator class
@@ -12,7 +12,7 @@ const ERROR_MODE_SECONDS_WINDOW = 30 * 1000; // sliding window of nodes to track
12
12
  /** Reserved room for query param attrs */
13
13
  const QUERY_PARAM_PADDING = 5000;
14
14
  export class Aggregate extends AggregateBase {
15
- static featureName = FEATURE_NAME;
15
+ static featureName = (() => FEATURE_NAME)();
16
16
  constructor(agentIdentifier, aggregator) {
17
17
  super(agentIdentifier, aggregator, FEATURE_NAME);
18
18
  this.agentRuntime = getRuntime(agentIdentifier);
@@ -33,10 +33,10 @@ const toAggregate = {
33
33
  export class TraceStorage {
34
34
  nodeCount = 0;
35
35
  trace = {};
36
- earliestTimeStamp = Infinity;
36
+ earliestTimeStamp = (() => Infinity)();
37
37
  latestTimeStamp = 0;
38
38
  tempStorage = [];
39
- prevStoredEvents = new Set();
39
+ prevStoredEvents = (() => new Set())();
40
40
  constructor(parent) {
41
41
  this.parent = parent;
42
42
  }
@@ -21,7 +21,7 @@ const {
21
21
  PUSH_STATE
22
22
  } = CONSTANTS;
23
23
  export class Instrument extends InstrumentBase {
24
- static featureName = FEATURE_NAME;
24
+ static featureName = (() => FEATURE_NAME)();
25
25
  constructor(agentIdentifier, aggregator) {
26
26
  let auto = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
27
27
  super(agentIdentifier, aggregator, FEATURE_NAME, auto);
@@ -7,7 +7,7 @@ export class BelNode {
7
7
  end;
8
8
  callbackEnd = 0;
9
9
  callbackDuration = 0;
10
- nodeId = ++nodesSeen;
10
+ nodeId = (() => ++nodesSeen)();
11
11
  constructor(agentIdentifier) {
12
12
  if (!agentIdentifier) throw new Error('Interaction is missing core attributes');
13
13
  this.agentIdentifier = agentIdentifier;
@@ -13,7 +13,7 @@ import { AjaxNode } from './ajax-node';
13
13
  import { InitialPageLoadInteraction } from './initial-page-load-interaction';
14
14
  import { Interaction } from './interaction';
15
15
  export class Aggregate extends AggregateBase {
16
- static featureName = FEATURE_NAME;
16
+ static featureName = (() => FEATURE_NAME)();
17
17
  constructor(agentIdentifier, aggregator, _ref) {
18
18
  let {
19
19
  domObserver