@newrelic/browser-agent 1.237.1 → 1.239.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 (307) hide show
  1. package/dist/cjs/common/config/state/init.js +21 -13
  2. package/dist/cjs/common/config/state/runtime.js +0 -4
  3. package/dist/cjs/common/constants/env.cdn.js +1 -1
  4. package/dist/cjs/common/constants/env.npm.js +1 -1
  5. package/dist/cjs/common/constants/runtime.js +3 -3
  6. package/dist/cjs/common/constants/shared-channel.js +3 -1
  7. package/dist/cjs/common/deny-list/deny-list.js +3 -9
  8. package/dist/cjs/common/drain/drain.js +1 -1
  9. package/dist/cjs/common/event-emitter/contextual-ee.js +24 -32
  10. package/dist/cjs/common/event-emitter/event-context.js +12 -0
  11. package/dist/cjs/common/harvest/harvest-scheduler.js +2 -4
  12. package/dist/cjs/common/harvest/harvest.js +4 -7
  13. package/dist/cjs/common/ids/bundle-id.js +19 -0
  14. package/dist/cjs/common/serialize/bel-serializer.js +1 -1
  15. package/dist/cjs/common/session/session-entity.js +16 -12
  16. package/dist/cjs/common/storage/first-party-cookies.js +5 -4
  17. package/dist/cjs/common/storage/local-storage.js +3 -2
  18. package/dist/cjs/common/timer/interaction-timer.js +14 -6
  19. package/dist/cjs/common/timing/nav-timing.js +1 -1
  20. package/dist/cjs/common/unload/eol.js +4 -30
  21. package/dist/cjs/common/util/feature-flags.js +14 -15
  22. package/dist/cjs/common/util/invoke.js +3 -1
  23. package/dist/cjs/common/util/obfuscate.js +3 -5
  24. package/dist/cjs/common/util/traverse.js +1 -0
  25. package/dist/cjs/common/window/page-visibility.js +1 -2
  26. package/dist/cjs/common/wrap/wrap-events.js +3 -2
  27. package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
  28. package/dist/cjs/common/wrap/wrap-function.js +15 -46
  29. package/dist/cjs/common/wrap/wrap-jsonp.js +1 -1
  30. package/dist/cjs/common/wrap/wrap-mutation.js +1 -2
  31. package/dist/cjs/common/wrap/wrap-promise.js +2 -3
  32. package/dist/cjs/common/wrap/wrap-xhr.js +23 -27
  33. package/dist/cjs/features/ajax/aggregate/index.js +5 -7
  34. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +8 -12
  35. package/dist/cjs/features/ajax/instrument/index.js +66 -24
  36. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +0 -1
  37. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  38. package/dist/cjs/features/jserrors/aggregate/index.js +4 -5
  39. package/dist/cjs/features/metrics/aggregate/framework-detection.js +103 -7
  40. package/dist/cjs/features/metrics/aggregate/index.js +20 -37
  41. package/dist/cjs/features/metrics/instrument/index.js +0 -2
  42. package/dist/cjs/features/page_action/aggregate/index.js +17 -19
  43. package/dist/cjs/features/page_view_event/aggregate/index.js +1 -2
  44. package/dist/cjs/features/page_view_event/instrument/index.js +4 -2
  45. package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -7
  46. package/dist/cjs/features/session_replay/aggregate/index.js +5 -3
  47. package/dist/cjs/features/session_trace/aggregate/index.js +22 -16
  48. package/dist/cjs/features/spa/aggregate/index.js +14 -20
  49. package/dist/cjs/features/spa/aggregate/interaction.js +0 -2
  50. package/dist/cjs/features/spa/aggregate/serializer.js +1 -1
  51. package/dist/cjs/features/utils/aggregate-base.js +4 -0
  52. package/dist/cjs/features/utils/handler-cache.js +3 -1
  53. package/dist/cjs/features/utils/instrument-base.js +24 -6
  54. package/dist/cjs/loaders/agent-base.js +23 -0
  55. package/dist/cjs/loaders/agent.js +7 -7
  56. package/dist/cjs/loaders/api/api.js +34 -4
  57. package/dist/cjs/loaders/api/apiAsync.js +19 -20
  58. package/dist/cjs/loaders/api/interaction-types.js +11 -4
  59. package/dist/cjs/loaders/configure/configure.js +3 -0
  60. package/dist/cjs/loaders/micro-agent.js +20 -3
  61. package/dist/esm/common/config/state/init.js +21 -13
  62. package/dist/esm/common/config/state/runtime.js +0 -4
  63. package/dist/esm/common/constants/env.cdn.js +1 -1
  64. package/dist/esm/common/constants/env.npm.js +1 -1
  65. package/dist/esm/common/constants/runtime.js +1 -1
  66. package/dist/esm/common/constants/shared-channel.js +3 -1
  67. package/dist/esm/common/deny-list/deny-list.js +3 -9
  68. package/dist/esm/common/drain/drain.js +1 -1
  69. package/dist/esm/common/event-emitter/contextual-ee.js +22 -29
  70. package/dist/esm/common/event-emitter/event-context.js +5 -0
  71. package/dist/esm/common/harvest/harvest-scheduler.js +2 -4
  72. package/dist/esm/common/harvest/harvest.js +4 -7
  73. package/dist/esm/common/ids/bundle-id.js +13 -0
  74. package/dist/esm/common/serialize/bel-serializer.js +1 -1
  75. package/dist/esm/common/session/session-entity.js +16 -12
  76. package/dist/esm/common/storage/first-party-cookies.js +5 -4
  77. package/dist/esm/common/storage/local-storage.js +3 -2
  78. package/dist/esm/common/timer/interaction-timer.js +14 -6
  79. package/dist/esm/common/timing/nav-timing.js +1 -1
  80. package/dist/esm/common/unload/eol.js +5 -31
  81. package/dist/esm/common/util/feature-flags.js +14 -15
  82. package/dist/esm/common/util/invoke.js +3 -1
  83. package/dist/esm/common/util/obfuscate.js +3 -5
  84. package/dist/esm/common/util/traverse.js +1 -0
  85. package/dist/esm/common/window/page-visibility.js +1 -2
  86. package/dist/esm/common/wrap/wrap-events.js +4 -3
  87. package/dist/esm/common/wrap/wrap-fetch.js +2 -4
  88. package/dist/esm/common/wrap/wrap-function.js +15 -44
  89. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  90. package/dist/esm/common/wrap/wrap-mutation.js +2 -3
  91. package/dist/esm/common/wrap/wrap-promise.js +3 -4
  92. package/dist/esm/common/wrap/wrap-xhr.js +23 -27
  93. package/dist/esm/features/ajax/aggregate/index.js +5 -7
  94. package/dist/esm/features/ajax/instrument/distributed-tracing.js +8 -12
  95. package/dist/esm/features/ajax/instrument/index.js +67 -25
  96. package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +0 -1
  97. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  98. package/dist/esm/features/jserrors/aggregate/index.js +4 -5
  99. package/dist/esm/features/metrics/aggregate/framework-detection.js +103 -7
  100. package/dist/esm/features/metrics/aggregate/index.js +22 -39
  101. package/dist/esm/features/metrics/instrument/index.js +1 -3
  102. package/dist/esm/features/page_action/aggregate/index.js +17 -19
  103. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  104. package/dist/esm/features/page_view_event/instrument/index.js +4 -2
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +7 -8
  106. package/dist/esm/features/session_replay/aggregate/index.js +4 -2
  107. package/dist/esm/features/session_trace/aggregate/index.js +22 -16
  108. package/dist/esm/features/spa/aggregate/index.js +14 -20
  109. package/dist/esm/features/spa/aggregate/interaction.js +0 -2
  110. package/dist/esm/features/spa/aggregate/serializer.js +1 -1
  111. package/dist/esm/features/utils/aggregate-base.js +4 -0
  112. package/dist/esm/features/utils/handler-cache.js +3 -1
  113. package/dist/esm/features/utils/instrument-base.js +24 -6
  114. package/dist/esm/loaders/agent-base.js +23 -0
  115. package/dist/esm/loaders/agent.js +7 -7
  116. package/dist/esm/loaders/api/api.js +34 -4
  117. package/dist/esm/loaders/api/apiAsync.js +19 -20
  118. package/dist/esm/loaders/api/interaction-types.js +11 -4
  119. package/dist/esm/loaders/configure/configure.js +3 -0
  120. package/dist/esm/loaders/features/enabled-features.js +1 -1
  121. package/dist/esm/loaders/micro-agent.js +21 -4
  122. package/dist/types/common/config/state/init.d.ts.map +1 -1
  123. package/dist/types/common/config/state/runtime.d.ts.map +1 -1
  124. package/dist/types/common/constants/runtime.d.ts +1 -1
  125. package/dist/types/common/constants/runtime.d.ts.map +1 -1
  126. package/dist/types/common/event-emitter/contextual-ee.d.ts +22 -2
  127. package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
  128. package/dist/types/common/event-emitter/event-context.d.ts +5 -0
  129. package/dist/types/common/event-emitter/event-context.d.ts.map +1 -0
  130. package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
  131. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  132. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  133. package/dist/types/common/ids/bundle-id.d.ts +5 -0
  134. package/dist/types/common/ids/bundle-id.d.ts.map +1 -0
  135. package/dist/types/common/session/session-entity.d.ts +12 -15
  136. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  137. package/dist/types/common/storage/first-party-cookies.d.ts +1 -1
  138. package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -1
  139. package/dist/types/common/storage/local-storage.d.ts.map +1 -1
  140. package/dist/types/common/timer/interaction-timer.d.ts +3 -0
  141. package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
  142. package/dist/types/common/unload/eol.d.ts +1 -2
  143. package/dist/types/common/unload/eol.d.ts.map +1 -1
  144. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  145. package/dist/types/common/util/obfuscate.d.ts.map +1 -1
  146. package/dist/types/common/util/traverse.d.ts.map +1 -1
  147. package/dist/types/common/window/nreum.d.ts +2 -2
  148. package/dist/types/common/window/page-visibility.d.ts.map +1 -1
  149. package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
  150. package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
  151. package/dist/types/common/wrap/wrap-function.d.ts +1 -19
  152. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  153. package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
  154. package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
  155. package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
  156. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  157. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +1 -1
  158. package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
  159. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  160. package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
  161. package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
  162. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  163. package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -1
  164. package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
  165. package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
  166. package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
  167. package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
  168. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  169. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  170. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  171. package/dist/types/features/session_trace/aggregate/index.d.ts +5 -0
  172. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  173. package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
  174. package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
  175. package/dist/types/features/utils/aggregate-base.d.ts +1 -0
  176. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  177. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  178. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  179. package/dist/types/loaders/agent-base.d.ts +15 -0
  180. package/dist/types/loaders/agent-base.d.ts.map +1 -1
  181. package/dist/types/loaders/agent.d.ts +1 -1
  182. package/dist/types/loaders/agent.d.ts.map +1 -1
  183. package/dist/types/loaders/api/api.d.ts +7 -0
  184. package/dist/types/loaders/api/api.d.ts.map +1 -1
  185. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  186. package/dist/types/loaders/api/interaction-types.d.ts +18 -7
  187. package/dist/types/loaders/api/interaction-types.d.ts.map +1 -1
  188. package/dist/types/loaders/configure/configure.d.ts +2 -0
  189. package/dist/types/loaders/configure/configure.d.ts.map +1 -1
  190. package/dist/types/loaders/features/features.d.ts +9 -9
  191. package/dist/types/loaders/micro-agent.d.ts +7 -1
  192. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  193. package/package.json +62 -38
  194. package/src/common/aggregate/aggregator.test.js +107 -0
  195. package/src/common/config/state/configurable.test.js +73 -0
  196. package/src/common/config/state/info.test.js +31 -0
  197. package/src/common/config/state/init.js +13 -12
  198. package/src/common/config/state/init.test.js +28 -0
  199. package/src/common/config/state/loader-config.test.js +21 -0
  200. package/src/common/config/state/runtime.js +0 -2
  201. package/src/common/config/state/runtime.test.js +21 -0
  202. package/src/common/constants/__mocks__/runtime.js +1 -1
  203. package/src/common/constants/runtime.js +1 -1
  204. package/src/common/constants/runtime.test.js +2 -2
  205. package/src/common/constants/shared-channel.js +1 -1
  206. package/src/common/deny-list/deny-list.js +3 -11
  207. package/src/common/deny-list/deny-list.test.js +103 -30
  208. package/src/common/drain/drain.js +1 -1
  209. package/src/common/drain/drain.test.js +74 -0
  210. package/src/common/event-emitter/{contextual-ee.test.js → contextual-ee.component-test.js} +15 -32
  211. package/src/common/event-emitter/contextual-ee.js +26 -37
  212. package/src/common/event-emitter/event-context.js +5 -0
  213. package/src/common/harvest/harvest-scheduler.js +2 -5
  214. package/src/common/harvest/harvest-scheduler.test.js +2 -6
  215. package/src/common/harvest/harvest.js +4 -7
  216. package/src/common/harvest/harvest.test.js +1 -3
  217. package/src/common/ids/__mocks__/bundle-id.js +2 -0
  218. package/src/common/ids/__mocks__/unique-id.js +17 -0
  219. package/src/common/ids/bundle-id.js +13 -0
  220. package/src/common/ids/id.test.js +6 -6
  221. package/src/common/serialize/bel-serializer.js +1 -1
  222. package/src/common/session/session-entity.component-test.js +3 -2
  223. package/src/common/session/session-entity.js +11 -9
  224. package/src/common/storage/first-party-cookies.js +5 -4
  225. package/src/common/storage/local-storage.js +3 -2
  226. package/src/common/timer/interaction-timer.component-test.js +52 -7
  227. package/src/common/timer/interaction-timer.js +15 -6
  228. package/src/common/timer/timer.test.js +0 -1
  229. package/src/common/timing/nav-timing.js +1 -1
  230. package/src/common/unload/eol.js +5 -31
  231. package/src/common/url/__mocks__/parse-url.js +15 -0
  232. package/src/common/url/{encode.component-test.js → encode.test.js} +1 -0
  233. package/src/common/util/__mocks__/get-or-set.js +5 -0
  234. package/src/common/util/__mocks__/invoke.js +1 -0
  235. package/src/common/util/data-size.test.js +0 -1
  236. package/src/common/util/feature-flags.js +15 -17
  237. package/src/common/util/feature-flags.test.js +4 -8
  238. package/src/common/util/invoke.js +1 -1
  239. package/src/common/util/obfuscate.js +3 -5
  240. package/src/common/util/submit-data.test.js +1 -1
  241. package/src/common/util/traverse.js +1 -0
  242. package/src/common/window/__mocks__/nreum.js +12 -0
  243. package/src/common/window/page-visibility.js +1 -2
  244. package/src/common/wrap/wrap-events.js +4 -3
  245. package/src/common/wrap/wrap-fetch.js +2 -4
  246. package/src/common/wrap/wrap-function.js +16 -44
  247. package/src/common/wrap/wrap-jsonp.js +1 -1
  248. package/src/common/wrap/wrap-mutation.js +2 -3
  249. package/src/common/wrap/{wrap-promise.test.js → wrap-promise.component-test.js} +2 -32
  250. package/src/common/wrap/wrap-promise.js +3 -4
  251. package/src/common/wrap/wrap-xhr.js +24 -28
  252. package/src/features/ajax/aggregate/index.js +5 -7
  253. package/src/features/ajax/instrument/distributed-tracing.js +8 -12
  254. package/src/features/ajax/instrument/distributed-tracing.test.js +375 -0
  255. package/src/features/ajax/instrument/index.js +62 -27
  256. package/src/features/jserrors/aggregate/canonical-function-name.js +0 -2
  257. package/src/features/jserrors/aggregate/compute-stack-trace.js +4 -4
  258. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  259. package/src/features/jserrors/aggregate/index.js +4 -5
  260. package/src/features/metrics/aggregate/framework-detection.js +129 -8
  261. package/src/features/metrics/aggregate/framework-detection.test.js +213 -82
  262. package/src/features/metrics/aggregate/index.js +22 -45
  263. package/src/features/metrics/instrument/index.js +1 -3
  264. package/src/features/page_action/aggregate/index.js +12 -13
  265. package/src/features/page_view_event/aggregate/index.js +1 -2
  266. package/src/features/page_view_event/instrument/index.js +2 -2
  267. package/src/features/page_view_timing/aggregate/index.js +7 -8
  268. package/src/features/session_replay/aggregate/index.component-test.js +3 -15
  269. package/src/features/session_replay/aggregate/index.js +4 -2
  270. package/src/features/session_trace/aggregate/index.js +22 -16
  271. package/src/features/spa/aggregate/index.js +14 -20
  272. package/src/features/spa/aggregate/interaction.js +0 -2
  273. package/src/features/spa/aggregate/serializer.js +1 -1
  274. package/src/features/utils/aggregate-base.js +5 -0
  275. package/src/features/utils/aggregate-base.test.js +2 -1
  276. package/src/features/utils/handler-cache.js +3 -2
  277. package/src/features/utils/instrument-base.js +25 -6
  278. package/src/features/utils/instrument-base.test.js +2 -2
  279. package/src/loaders/agent-base.js +23 -0
  280. package/src/loaders/agent.js +7 -7
  281. package/src/loaders/api/api.component-test.js +45 -0
  282. package/src/loaders/api/api.js +34 -4
  283. package/src/loaders/api/api.test.js +85 -0
  284. package/src/loaders/api/apiAsync.js +19 -20
  285. package/src/loaders/api/apiAsync.test.js +17 -0
  286. package/src/loaders/api/interaction-types.js +11 -4
  287. package/src/loaders/configure/configure.js +3 -0
  288. package/src/loaders/features/enabled-features.js +1 -1
  289. package/src/loaders/micro-agent.js +22 -4
  290. package/dist/cjs/features/metrics/aggregate/endpoint-map.js +0 -14
  291. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +0 -14
  292. package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +0 -53
  293. package/dist/esm/features/metrics/aggregate/endpoint-map.js +0 -7
  294. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
  295. package/dist/esm/features/metrics/aggregate/polyfill-detection.js +0 -47
  296. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +0 -8
  297. package/dist/types/features/metrics/aggregate/endpoint-map.d.ts.map +0 -1
  298. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +0 -6
  299. package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +0 -1
  300. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +0 -7
  301. package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +0 -1
  302. package/src/features/metrics/aggregate/endpoint-map.js +0 -7
  303. package/src/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
  304. package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -16
  305. package/src/features/metrics/aggregate/polyfill-detection.js +0 -48
  306. package/src/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  307. /package/src/common/url/{protocol.component-test.js → protocol.test.js} +0 -0
@@ -1,31 +1,104 @@
1
- describe('Setting deny list', () => {
2
- let DlMod
3
- beforeEach(() => {
4
- jest.isolateModules(() => import('./deny-list.js').then(m => DlMod = m)) // give every test its own denyList (sandbox)
5
- })
6
-
7
- it('respects path', () => {
8
- DlMod.setDenyList(['bam.nr-data.net/somepath'])
9
-
10
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '/somepath' })).toBeFalsy() // shouldCollectEvent returns 'false' when there IS a match...
11
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'https', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
12
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '' })).toBeTruthy()
13
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '/someotherpath' })).toBeTruthy()
14
- })
15
-
16
- it('ignores port', () => {
17
- DlMod.setDenyList(['bam.nr-data.net:1234'])
18
-
19
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '', port: '4321' })).toBeFalsy()
20
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'http', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
21
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '' })).toBeTruthy()
22
- })
23
-
24
- it('ignores protocol', () => {
25
- DlMod.setDenyList(['http://bam.nr-data.net'])
26
-
27
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '', protocol: 'https' })).toBeFalsy()
28
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'https', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
29
- expect(DlMod.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '', protocol: 'http' })).toBeTruthy()
30
- })
1
+ jest.enableAutomock()
2
+ jest.unmock('./deny-list')
3
+
4
+ let denyListModule
5
+
6
+ beforeEach(async () => {
7
+ denyListModule = await import('./deny-list')
8
+ })
9
+
10
+ afterEach(() => {
11
+ jest.resetModules()
12
+ })
13
+
14
+ test('domain-only blocks all subdomains and all paths', () => {
15
+ denyListModule.setDenyList(['foo.com'])
16
+
17
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/' })).toBeFalsy()
18
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a' })).toBeFalsy()
19
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a/b' })).toBeFalsy()
20
+
21
+ expect(denyListModule.shouldCollectEvent({ hostname: 'www.foo.com', pathname: '/' })).toBeFalsy()
22
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.b.foo.com', pathname: '/' })).toBeFalsy()
23
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.b.foo.com', pathname: '/c/d' })).toBeFalsy()
24
+
25
+ expect(denyListModule.shouldCollectEvent({ hostname: 'oo.com', pathname: '/' })).toBeTruthy()
26
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.com', pathname: '/' })).toBeTruthy()
27
+ })
28
+
29
+ test('subdomain blocks further subdomains, but not parent domain', () => {
30
+ denyListModule.setDenyList(['bar.foo.com'])
31
+
32
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.foo.com', pathname: '/' })).toBeFalsy()
33
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.foo.com', pathname: '/a' })).toBeFalsy()
34
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.foo.com', pathname: '/a/b' })).toBeFalsy()
35
+
36
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.bar.foo.com', pathname: '/' })).toBeFalsy()
37
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.bar.foo.com', pathname: '/a' })).toBeFalsy()
38
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.bar.foo.com', pathname: '/a/b' })).toBeFalsy()
39
+
40
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/' })).toBeTruthy()
41
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a' })).toBeTruthy()
42
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a/b' })).toBeTruthy()
43
+
44
+ expect(denyListModule.shouldCollectEvent({ hostname: 'oo.com', pathname: '/' })).toBeTruthy()
45
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.com', pathname: '/' })).toBeTruthy()
46
+ })
47
+
48
+ test('* blocks all domains', () => {
49
+ denyListModule.setDenyList(['*'])
50
+
51
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/' })).toBeFalsy()
52
+ expect(denyListModule.shouldCollectEvent({ hostname: 'www.foo.com', pathname: '/' })).toBeFalsy()
53
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.com', pathname: '/' })).toBeFalsy()
54
+ expect(denyListModule.shouldCollectEvent({ hostname: 'www.bar.com', pathname: '/' })).toBeFalsy()
55
+ })
56
+
57
+ test('respects path', () => {
58
+ denyListModule.setDenyList(['bam.nr-data.net/somepath'])
59
+
60
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '/somepath' })).toBeFalsy()
61
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'https', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
62
+
63
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '' })).toBeTruthy()
64
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '/someotherpath' })).toBeTruthy()
65
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '/some/otherpath' })).toBeTruthy()
66
+ })
67
+
68
+ test('ignores port', () => {
69
+ denyListModule.setDenyList(['bam.nr-data.net:1234'])
70
+
71
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '', port: '4321' })).toBeFalsy()
72
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'http', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
73
+
74
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '' })).toBeTruthy()
75
+ })
76
+
77
+ test('ignores protocol', () => {
78
+ denyListModule.setDenyList(['http://bam.nr-data.net'])
79
+
80
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', pathname: '', protocol: 'https' })).toBeFalsy()
81
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.net', port: '7890', protocol: 'https', host: 'bam.nr-data.net:7890', pathname: '/somepath' })).toBeFalsy()
82
+
83
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bam.nr-data.com', pathname: '', protocol: 'http' })).toBeTruthy()
84
+ })
85
+
86
+ test.each([
87
+ null,
88
+ undefined,
89
+ '!@$%^*',
90
+ 'https://example.com/http://foo.bar/'
91
+ ])('ignores invalid deny list value %s', (denyListValue) => {
92
+ denyListModule.setDenyList([denyListValue])
93
+
94
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/' })).toBeTruthy()
95
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a' })).toBeTruthy()
96
+ expect(denyListModule.shouldCollectEvent({ hostname: 'foo.com', pathname: '/a/b' })).toBeTruthy()
97
+
98
+ expect(denyListModule.shouldCollectEvent({ hostname: 'www.foo.com', pathname: '/' })).toBeTruthy()
99
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.b.foo.com', pathname: '/' })).toBeTruthy()
100
+ expect(denyListModule.shouldCollectEvent({ hostname: 'a.b.foo.com', pathname: '/c/d' })).toBeTruthy()
101
+
102
+ expect(denyListModule.shouldCollectEvent({ hostname: 'oo.com', pathname: '/' })).toBeTruthy()
103
+ expect(denyListModule.shouldCollectEvent({ hostname: 'bar.com', pathname: '/' })).toBeTruthy()
31
104
  })
@@ -44,7 +44,6 @@ function curateRegistry (agentIdentifier) {
44
44
  */
45
45
  export function drain (agentIdentifier = '', featureName = 'feature') {
46
46
  curateRegistry(agentIdentifier)
47
-
48
47
  // If the feature for the specified agent is not in the registry, that means the instrument file was bypassed.
49
48
  // This could happen in tests, or loaders that directly import the aggregator. In these cases it is safe to
50
49
  // drain the feature group immediately rather than waiting to drain all at once.
@@ -59,6 +58,7 @@ export function drain (agentIdentifier = '', featureName = 'feature') {
59
58
  if (items.every(([key, values]) => values.staged)) {
60
59
  items.sort((a, b) => a[1].priority - b[1].priority)
61
60
  items.forEach(([group]) => {
61
+ registry[agentIdentifier].delete(group)
62
62
  drainGroup(group)
63
63
  })
64
64
  }
@@ -0,0 +1,74 @@
1
+ let registerDrain, drain, ee
2
+ beforeEach(async () => {
3
+ jest.resetModules()
4
+ ;({ registerDrain, drain } = await import('./drain'))
5
+ ;({ ee } = await import('../event-emitter/contextual-ee'))
6
+ })
7
+
8
+ test('can register a feat and drain it', () => {
9
+ registerDrain('abcd', 'page_view_event')
10
+
11
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
12
+ drain('abcd', 'page_view_event')
13
+ expect(emitSpy).toHaveBeenCalledWith('drain-page_view_event', expect.anything())
14
+ })
15
+
16
+ test('other unregistered drains do not affect feat reg & drain', () => {
17
+ registerDrain('abcd', 'page_view_event')
18
+
19
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
20
+ drain('abcd', 'timon')
21
+ expect(emitSpy).toHaveBeenCalledWith('drain-timon', expect.anything())
22
+ expect(emitSpy).not.toHaveBeenCalledWith('drain-page_view_event', expect.anything())
23
+
24
+ drain('abcd', 'page_view_event')
25
+ expect(emitSpy).toHaveBeenCalledWith('drain-page_view_event', expect.anything())
26
+ })
27
+
28
+ describe('drain', () => {
29
+ test('does not execute until all registered groups calls it and in order', () => {
30
+ registerDrain('abcd', 'page_view_timing')
31
+ registerDrain('abcd', 'page_view_event')
32
+
33
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
34
+ drain('abcd', 'page_view_event')
35
+ expect(emitSpy).not.toHaveBeenCalled()
36
+
37
+ drain('abcd', 'page_view_timing')
38
+ // The priority order of features is also checked here, even though the latter was registered first.
39
+ expect(emitSpy).toHaveBeenNthCalledWith(1, 'drain-page_view_event', expect.anything())
40
+ expect(emitSpy).toHaveBeenNthCalledWith(2, 'drain-page_view_timing', expect.anything())
41
+ })
42
+
43
+ test('does not require registration for non-feat groups', () => {
44
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
45
+ drain('abcd', 'pumbaa')
46
+ expect(emitSpy).toHaveBeenCalledWith('drain-pumbaa', expect.anything())
47
+ })
48
+
49
+ test('defaults to "feature" group when not provided one', () => {
50
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
51
+ drain('abcd')
52
+ expect(emitSpy).toHaveBeenCalledWith('drain-feature', expect.anything())
53
+ })
54
+
55
+ test('works on the global ee when agent id not provided', () => {
56
+ let emitSpy = jest.spyOn(ee, 'emit')
57
+ drain()
58
+ expect(emitSpy).toHaveBeenCalledWith('drain-feature', expect.anything())
59
+ })
60
+ })
61
+
62
+ test('non-feat groups can register and drain too alongside features', () => {
63
+ registerDrain('abcd', 'page_view_event')
64
+ registerDrain('abcd', 'simba')
65
+
66
+ console.log(JSON.stringify(ee.get('abcd')))
67
+ let emitSpy = jest.spyOn(ee.get('abcd'), 'emit')
68
+ drain('abcd', 'simba')
69
+ expect(emitSpy).not.toHaveBeenCalled()
70
+
71
+ drain('abcd', 'page_view_event')
72
+ expect(emitSpy).toHaveBeenNthCalledWith(1, 'drain-simba', expect.anything()) // non-feat have prio of 0
73
+ expect(emitSpy).toHaveBeenNthCalledWith(2, 'drain-page_view_event', expect.anything())
74
+ })
@@ -24,19 +24,18 @@ afterEach(() => {
24
24
  })
25
25
 
26
26
  describe('global event-emitter', () => {
27
- test('it returns the event-emitter defined on window.NREUM', async () => {
28
- const mockEE = {}
29
- mockNREUM.ee = mockEE
30
-
27
+ test('it sets the global event-emitter on window.NREUM when it does not already exist', async () => {
31
28
  const { ee } = await import('./contextual-ee')
32
29
 
33
- expect(ee).toEqual(mockEE)
30
+ expect(ee).toEqual(mockNREUM.ee)
34
31
  })
35
32
 
36
- test('it sets the global event-emitter on window.NREUM', async () => {
33
+ test('it does not set the global event-emitter on window.NREUM when it already exists', async () => {
34
+ mockNREUM.ee = {}
35
+
37
36
  const { ee } = await import('./contextual-ee')
38
37
 
39
- expect(ee).toEqual(mockNREUM.ee)
38
+ expect(ee).not.toEqual(mockNREUM.ee)
40
39
  })
41
40
  })
42
41
 
@@ -79,7 +78,9 @@ describe('event-emitter context', () => {
79
78
 
80
79
  const result = ee.context()
81
80
 
82
- expect(result).toEqual({})
81
+ expect(result).toEqual(expect.objectContaining({
82
+ contextId: expect.stringContaining('nr@context:')
83
+ }))
83
84
  })
84
85
 
85
86
  test('it returns the same context', async () => {
@@ -87,7 +88,7 @@ describe('event-emitter context', () => {
87
88
 
88
89
  const result = ee.context()
89
90
 
90
- expect(result).toEqual(ee.context(result))
91
+ expect(result).toBe(ee.context(result))
91
92
  })
92
93
 
93
94
  test('it adds the context to the provided object', async () => {
@@ -95,8 +96,9 @@ describe('event-emitter context', () => {
95
96
 
96
97
  const obj = {}
97
98
  const result = ee.context(obj)
99
+ const ctxKey = Object.getOwnPropertyNames(obj).find(k => k.startsWith('nr@context'))
98
100
 
99
- expect(result).toEqual(obj['nr@context'])
101
+ expect(result).toBe(obj[ctxKey])
100
102
  })
101
103
  })
102
104
 
@@ -281,30 +283,11 @@ describe('event-emitter emit', () => {
281
283
  scopeEE,
282
284
  eventType,
283
285
  eventArgs,
284
- {}
286
+ expect.objectContaining({
287
+ contextId: expect.stringContaining('nr@context:')
288
+ })
285
289
  ])
286
290
  ]))
287
291
  expect(ee.backlog.feature).toEqual(scopeEE.backlog.feature)
288
292
  })
289
293
  })
290
-
291
- describe('getOrSetContext', () => {
292
- test('it returns a new context', async () => {
293
- const { getOrSetContext } = await import('./contextual-ee')
294
-
295
- const obj = {}
296
- const result = getOrSetContext(obj)
297
-
298
- expect(result).toEqual({})
299
- expect(result).toEqual(obj['nr@context'])
300
- })
301
-
302
- test('it returns the same context', async () => {
303
- const { getOrSetContext } = await import('./contextual-ee')
304
-
305
- const obj = {}
306
- const result = getOrSetContext(obj)
307
-
308
- expect(getOrSetContext(obj)).toEqual(result)
309
- })
310
- })
@@ -5,25 +5,22 @@
5
5
 
6
6
  import { gosNREUM } from '../window/nreum'
7
7
  import { getOrSet } from '../util/get-or-set'
8
- import { mapOwn } from '../util/map-own'
9
8
  import { getRuntime } from '../config/config'
9
+ import { EventContext } from './event-context'
10
+ import { bundleId } from '../ids/bundle-id'
10
11
 
11
- var ctxId = 'nr@context'
12
-
12
+ // create a unique id to store event context data for the current agent bundle
13
+ const contextId = `nr@context:${bundleId}`
13
14
  // create global emitter instance that can be shared among bundles
14
- let nr = gosNREUM()
15
- var globalInstance
15
+ const globalInstance = ee(undefined, 'globalEE')
16
16
 
17
- if (nr.ee) {
18
- globalInstance = nr.ee
19
- } else {
20
- globalInstance = ee(undefined, 'globalEE')
17
+ // Only override the exposed event emitter if one has not already been exposed
18
+ const nr = gosNREUM()
19
+ if (!nr.ee) {
21
20
  nr.ee = globalInstance
22
21
  }
23
22
 
24
- export { globalInstance as ee }
25
-
26
- function EventContext () { }
23
+ export { globalInstance as ee, contextId }
27
24
 
28
25
  function ee (old, debugId) {
29
26
  var handlers = {}
@@ -44,16 +41,16 @@ function ee (old, debugId) {
44
41
 
45
42
  var emitter = {
46
43
  on: addEventListener,
47
- addEventListener: addEventListener,
48
- removeEventListener: removeEventListener,
49
- emit: emit,
44
+ addEventListener,
45
+ removeEventListener,
46
+ emit,
50
47
  get: getOrCreate,
51
- listeners: listeners,
52
- context: context,
48
+ listeners,
49
+ context,
53
50
  buffer: bufferEventsByGroup,
54
51
  abort,
55
52
  aborted: false,
56
- isBuffering: isBuffering,
53
+ isBuffering,
57
54
  debugId,
58
55
  backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
59
56
 
@@ -65,9 +62,9 @@ function ee (old, debugId) {
65
62
  if (contextOrStore && contextOrStore instanceof EventContext) {
66
63
  return contextOrStore
67
64
  } else if (contextOrStore) {
68
- return getOrSet(contextOrStore, ctxId, getNewContext)
65
+ return getOrSet(contextOrStore, contextId, () => new EventContext(contextId))
69
66
  } else {
70
- return getNewContext()
67
+ return new EventContext(contextId)
71
68
  }
72
69
  }
73
70
 
@@ -119,17 +116,18 @@ function ee (old, debugId) {
119
116
  }
120
117
 
121
118
  function bufferEventsByGroup (types, group) {
122
- var eventBuffer = getBuffer()
119
+ const eventBuffer = getBuffer()
120
+ group = group || 'feature'
123
121
 
124
122
  // do not buffer events if agent has been aborted
125
123
  if (emitter.aborted) return
126
- mapOwn(types, function (i, type) {
127
- group = group || 'feature'
128
- bufferGroupMap[type] = group
129
- if (!(group in eventBuffer)) {
130
- eventBuffer[group] = []
131
- }
132
- })
124
+ Object.entries(types || {})
125
+ .forEach(([_, type]) => {
126
+ bufferGroupMap[type] = group
127
+ if (!(group in eventBuffer)) {
128
+ eventBuffer[group] = []
129
+ }
130
+ })
133
131
  }
134
132
 
135
133
  function isBuffering (type) {
@@ -144,15 +142,6 @@ function ee (old, debugId) {
144
142
  }
145
143
  }
146
144
 
147
- // get context object from store object, or create if does not exist
148
- export function getOrSetContext (obj) {
149
- return getOrSet(obj, ctxId, getNewContext)
150
- }
151
-
152
- function getNewContext () {
153
- return new EventContext()
154
- }
155
-
156
145
  function abort () {
157
146
  globalInstance.aborted = true
158
147
  globalInstance.backlog = {}
@@ -0,0 +1,5 @@
1
+ export class EventContext {
2
+ constructor (contextId) {
3
+ this.contextId = contextId
4
+ }
5
+ }
@@ -7,7 +7,6 @@ import * as submitData from '../util/submit-data'
7
7
  import { SharedContext } from '../context/shared-context'
8
8
  import { Harvest } from './harvest'
9
9
  import { subscribeToEOL } from '../unload/eol'
10
- import { getConfigurationValue } from '../config/config'
11
10
  import { SESSION_EVENTS } from '../session/session-entity'
12
11
 
13
12
  /**
@@ -36,7 +35,7 @@ export class HarvestScheduler extends SharedContext {
36
35
  this.harvest = new Harvest(this.sharedContext)
37
36
 
38
37
  // unload if EOL mechanism fires
39
- subscribeToEOL(this.unload.bind(this), getConfigurationValue(this.sharedContext.agentIdentifier, 'allow_bfcache')) // TO DO: remove feature flag after rls stable
38
+ subscribeToEOL(this.unload.bind(this))
40
39
 
41
40
  /* Flush all buffered data if session resets and give up retries. This should be synchronous to ensure that the correct `session` value is sent.
42
41
  Since session-reset generates a new session ID and the ID is grabbed at send-time, any delays or retries would cause the payload to be sent under
@@ -103,7 +102,7 @@ export class HarvestScheduler extends SharedContext {
103
102
  if (!submitMethod) return false
104
103
 
105
104
  const retry = !opts?.unload && submitMethod === submitData.xhr
106
- payload = this.opts.getPayload({ retry: retry })
105
+ payload = this.opts.getPayload({ retry })
107
106
 
108
107
  if (!payload) {
109
108
  if (this.started) {
@@ -143,8 +142,6 @@ export class HarvestScheduler extends SharedContext {
143
142
  if (this.started) {
144
143
  this.scheduleHarvest()
145
144
  }
146
-
147
- return
148
145
  }
149
146
 
150
147
  onHarvestFinished (opts, result) {
@@ -2,7 +2,6 @@ import { faker } from '@faker-js/faker'
2
2
 
3
3
  import * as submitData from '../util/submit-data'
4
4
  import { subscribeToEOL } from '../unload/eol'
5
- import { getConfigurationValue } from '../config/config'
6
5
  import { Harvest } from './harvest'
7
6
 
8
7
  import { HarvestScheduler } from './harvest-scheduler'
@@ -31,13 +30,10 @@ describe('unload', () => {
31
30
  jest.spyOn(harvestSchedulerInstance, 'runHarvest').mockImplementation(jest.fn())
32
31
  })
33
32
 
34
- test('should subscribe to eol with allow_bfcache setting', () => {
35
- const mockedBFCacheSetting = faker.datatype.uuid()
36
- jest.mocked(getConfigurationValue).mockReturnValue(mockedBFCacheSetting)
37
-
33
+ test('should subscribe to eol', () => {
38
34
  new HarvestScheduler()
39
35
 
40
- expect(subscribeToEOL).toHaveBeenCalledWith(expect.any(Function), mockedBFCacheSetting)
36
+ expect(subscribeToEOL).toHaveBeenCalledWith(expect.any(Function))
41
37
  })
42
38
 
43
39
  test('should run onUnload callback', () => {
@@ -47,7 +47,8 @@ export class Harvest extends SharedContext {
47
47
  sendX (spec = {}) {
48
48
  const submitMethod = submitData.getSubmitMethod({ isFinalHarvest: spec.opts?.unload })
49
49
  const options = {
50
- retry: !spec.opts?.unload && submitMethod === submitData.xhr
50
+ retry: !spec.opts?.unload && submitMethod === submitData.xhr,
51
+ isFinalHarvest: spec.opts?.unload === true
51
52
  }
52
53
  const payload = this.createPayload(spec.endpoint, options)
53
54
  const caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this)
@@ -95,7 +96,8 @@ export class Harvest extends SharedContext {
95
96
  return false
96
97
  }
97
98
 
98
- let url = `${this.getScheme()}://${info.errorBeacon}${endpoint !== 'rum' ? `/${endpoint}` : ''}/1/${info.licenseKey}`
99
+ const endpointURLPart = endpoint !== 'rum' ? `/${endpoint}` : ''
100
+ let url = `${this.getScheme()}://${info.errorBeacon}${endpointURLPart}/1/${info.licenseKey}`
99
101
  if (customUrl) url = customUrl
100
102
  if (raw) url = `${this.getScheme()}://${info.errorBeacon}/${endpoint}`
101
103
 
@@ -126,11 +128,6 @@ export class Harvest extends SharedContext {
126
128
  body = ''
127
129
  }
128
130
 
129
- // Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
130
- agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0
131
- // Get query bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
132
- agentRuntime.queryBytesSent[endpoint] = (agentRuntime.queryBytesSent[endpoint] || 0) + fullUrl.split('?').slice(-1)[0]?.length || 0
133
-
134
131
  const headers = []
135
132
 
136
133
  headers.push({ key: 'content-type', value: 'text/plain' })
@@ -53,7 +53,7 @@ describe('sendX', () => {
53
53
 
54
54
  harvestInstance.sendX(spec)
55
55
 
56
- expect(harvestInstance.createPayload).toHaveBeenCalledWith(spec.endpoint, { retry: true })
56
+ expect(harvestInstance.createPayload).toHaveBeenCalledWith(spec.endpoint, { retry: true, isFinalHarvest: false })
57
57
  })
58
58
 
59
59
  test('should not use obfuscateAndSend', async () => {
@@ -157,8 +157,6 @@ describe('_send', () => {
157
157
  licenseKey
158
158
  })
159
159
  jest.mocked(configModule.getRuntime).mockReturnValue({
160
- bytesSent: {},
161
- queryBytesSent: {},
162
160
  maxBytes: Infinity
163
161
  })
164
162
 
@@ -0,0 +1,2 @@
1
+ import { faker } from '@faker-js/faker'
2
+ export const bundleId = faker.datatype.uuid()
@@ -0,0 +1,17 @@
1
+ import { faker } from '@faker-js/faker'
2
+
3
+ export function generateUuid () {
4
+ return faker.datatype.uuid()
5
+ }
6
+
7
+ export function generateRandomHexString (length) {
8
+ return faker.datatype.hexadecimal({ length, prefix: '' })
9
+ }
10
+
11
+ export function generateSpanId () {
12
+ return generateRandomHexString(16)
13
+ }
14
+
15
+ export function generateTraceId () {
16
+ return generateRandomHexString(32)
17
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file Contains a unique identifier for the running agent bundle
3
+ * when loaded.
4
+ * @copyright 2023 New Relic Corporation. All rights reserved.
5
+ * @license Apache-2.0
6
+ */
7
+
8
+ import { generateUuid } from './unique-id'
9
+
10
+ /**
11
+ * Provides a unique id for the current agent bundle
12
+ */
13
+ export const bundleId = generateUuid()
@@ -67,25 +67,25 @@ test('id is zero on global scope', async () => {
67
67
  })
68
68
 
69
69
  test('id on prototype is correctly inherited', () => {
70
- const fn = jest.fn()
70
+ const Ctor = jest.fn()
71
71
  const a = {}
72
72
 
73
73
  idFn(a)
74
- fn.prototype = a
74
+ Ctor.prototype = a
75
75
 
76
- const b = new fn()
76
+ const b = new Ctor()
77
77
 
78
78
  expect(b['nr@id']).toEqual(a['nr@id'])
79
79
  })
80
80
 
81
81
  test('id on prototype is different from instance', () => {
82
- const fn = jest.fn()
82
+ const Ctor = jest.fn()
83
83
  const a = {}
84
84
 
85
85
  idFn(a)
86
- fn.prototype = a
86
+ Ctor.prototype = a
87
87
 
88
- const b = new fn()
88
+ const b = new Ctor()
89
89
  const result = idFn(b)
90
90
 
91
91
  expect(b['nr@id']).toEqual(result)
@@ -32,7 +32,7 @@ export function getAddStringContext (agentIdentifier) {
32
32
 
33
33
  function addString (str) {
34
34
  if (typeof str === 'undefined' || str === '') return ''
35
- var obfuscator = new Obfuscator({ agentIdentifier: agentIdentifier })
35
+ var obfuscator = new Obfuscator({ agentIdentifier })
36
36
  str = String(str)
37
37
  if (obfuscator.shouldObfuscate()) str = obfuscator.obfuscateString(str)
38
38
  if (hasOwnProp.call(stringTable, str)) {
@@ -13,6 +13,7 @@ class LocalMemory {
13
13
  try {
14
14
  return this.state[key]
15
15
  } catch (err) {
16
+ // Error is ignored
16
17
  return ''
17
18
  }
18
19
  }
@@ -22,7 +23,7 @@ class LocalMemory {
22
23
  if (value === undefined || value === null) return this.remove(key)
23
24
  this.state[key] = value
24
25
  } catch (err) {
25
- return
26
+ // Error is ignored
26
27
  }
27
28
  }
28
29
 
@@ -30,7 +31,7 @@ class LocalMemory {
30
31
  try {
31
32
  delete this.state[key]
32
33
  } catch (err) {
33
- return
34
+ // Error is ignored
34
35
  }
35
36
  }
36
37
  }