@openobserve/browser-core 0.2.9 → 0.2.11-rc1

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 (393) hide show
  1. package/cjs/boot/init.js +1 -1
  2. package/cjs/boot/init.js.map +1 -1
  3. package/cjs/browser/addEventListener.d.ts +12 -4
  4. package/cjs/browser/addEventListener.js +50 -8
  5. package/cjs/browser/addEventListener.js.map +1 -1
  6. package/cjs/browser/cookie.d.ts +7 -0
  7. package/cjs/browser/cookie.js +19 -2
  8. package/cjs/browser/cookie.js.map +1 -1
  9. package/cjs/browser/fetchObservable.js +14 -19
  10. package/cjs/browser/fetchObservable.js.map +1 -1
  11. package/cjs/browser/pageExitObservable.js +6 -7
  12. package/cjs/browser/pageExitObservable.js.map +1 -1
  13. package/cjs/browser/runOnReadyState.js +1 -1
  14. package/cjs/browser/runOnReadyState.js.map +1 -1
  15. package/cjs/browser/xhrObservable.d.ts +1 -2
  16. package/cjs/browser/xhrObservable.js +26 -34
  17. package/cjs/browser/xhrObservable.js.map +1 -1
  18. package/cjs/domain/configuration/configuration.d.ts +17 -12
  19. package/cjs/domain/configuration/configuration.js +8 -9
  20. package/cjs/domain/configuration/configuration.js.map +1 -1
  21. package/cjs/domain/configuration/endpointBuilder.d.ts +6 -10
  22. package/cjs/domain/configuration/endpointBuilder.js +28 -38
  23. package/cjs/domain/configuration/endpointBuilder.js.map +1 -1
  24. package/cjs/domain/configuration/index.d.ts +2 -1
  25. package/cjs/domain/configuration/index.js +3 -1
  26. package/cjs/domain/configuration/index.js.map +1 -1
  27. package/cjs/domain/configuration/tags.js.map +1 -1
  28. package/cjs/domain/configuration/transportConfiguration.js +1 -1
  29. package/cjs/domain/configuration/transportConfiguration.js.map +1 -1
  30. package/cjs/domain/connectivity/connectivity.d.ts +13 -0
  31. package/cjs/domain/connectivity/connectivity.js +14 -0
  32. package/cjs/domain/connectivity/connectivity.js.map +1 -0
  33. package/cjs/domain/connectivity/index.d.ts +1 -0
  34. package/cjs/domain/{deflate → connectivity}/index.js +1 -1
  35. package/cjs/domain/connectivity/index.js.map +1 -0
  36. package/cjs/domain/console/consoleObservable.js +4 -7
  37. package/cjs/domain/console/consoleObservable.js.map +1 -1
  38. package/cjs/domain/context/contextConstants.d.ts +5 -0
  39. package/cjs/domain/{tracekit/types.js → context/contextConstants.js} +1 -1
  40. package/cjs/domain/context/contextConstants.js.map +1 -0
  41. package/cjs/domain/context/contextManager.d.ts +12 -0
  42. package/cjs/domain/context/contextManager.js +43 -0
  43. package/cjs/domain/context/contextManager.js.map +1 -0
  44. package/cjs/domain/context/customerDataTracker.d.ts +45 -0
  45. package/cjs/domain/context/customerDataTracker.js +107 -0
  46. package/cjs/domain/context/customerDataTracker.js.map +1 -0
  47. package/cjs/domain/context/storeContextManager.d.ts +6 -0
  48. package/cjs/domain/context/storeContextManager.js +38 -0
  49. package/cjs/domain/context/storeContextManager.js.map +1 -0
  50. package/cjs/domain/deflate/types.d.ts +0 -26
  51. package/cjs/domain/error/computeStackTrace.d.ts +33 -0
  52. package/cjs/domain/{tracekit → error}/computeStackTrace.js +28 -4
  53. package/cjs/domain/error/computeStackTrace.js.map +1 -0
  54. package/cjs/domain/error/error.d.ts +1 -1
  55. package/cjs/domain/error/error.js +3 -3
  56. package/cjs/domain/error/error.js.map +1 -1
  57. package/cjs/domain/error/error.types.d.ts +2 -2
  58. package/cjs/domain/error/error.types.js.map +1 -1
  59. package/cjs/domain/error/trackRuntimeError.d.ts +8 -0
  60. package/cjs/domain/error/trackRuntimeError.js +39 -6
  61. package/cjs/domain/error/trackRuntimeError.js.map +1 -1
  62. package/cjs/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -1
  63. package/cjs/domain/report/browser.types.d.ts +10 -0
  64. package/cjs/domain/report/reportObservable.d.ts +2 -0
  65. package/cjs/domain/report/reportObservable.js +7 -7
  66. package/cjs/domain/report/reportObservable.js.map +1 -1
  67. package/cjs/domain/session/oldCookiesMigration.js +4 -4
  68. package/cjs/domain/session/oldCookiesMigration.js.map +1 -1
  69. package/cjs/domain/session/sessionManager.js +2 -2
  70. package/cjs/domain/session/sessionManager.js.map +1 -1
  71. package/cjs/domain/session/sessionState.js.map +1 -1
  72. package/cjs/domain/session/sessionStore.js.map +1 -1
  73. package/cjs/domain/session/sessionStoreOperations.d.ts +0 -5
  74. package/cjs/domain/session/sessionStoreOperations.js +6 -14
  75. package/cjs/domain/session/sessionStoreOperations.js.map +1 -1
  76. package/cjs/domain/session/storeStrategies/sessionInCookie.js +13 -2
  77. package/cjs/domain/session/storeStrategies/sessionInCookie.js.map +1 -1
  78. package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js +1 -0
  79. package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -1
  80. package/cjs/domain/session/storeStrategies/sessionStoreStrategy.d.ts +1 -0
  81. package/cjs/domain/synthetics/syntheticsWorkerValues.js +3 -3
  82. package/cjs/domain/synthetics/syntheticsWorkerValues.js.map +1 -1
  83. package/cjs/domain/telemetry/rawTelemetryEvent.types.d.ts +4 -0
  84. package/cjs/domain/telemetry/telemetry.d.ts +5 -1
  85. package/cjs/domain/telemetry/telemetry.js +17 -6
  86. package/cjs/domain/telemetry/telemetry.js.map +1 -1
  87. package/cjs/domain/telemetry/telemetryEvent.types.d.ts +18 -2
  88. package/cjs/domain/user/user.js.map +1 -1
  89. package/cjs/tools/abstractLifeCycle.js.map +1 -1
  90. package/cjs/tools/boundedBuffer.js.map +1 -1
  91. package/cjs/tools/catchUserErrors.js.map +1 -1
  92. package/cjs/tools/display.d.ts +2 -2
  93. package/cjs/tools/display.js +13 -17
  94. package/cjs/tools/display.js.map +1 -1
  95. package/cjs/tools/encoder.d.ts +53 -0
  96. package/cjs/tools/encoder.js +41 -0
  97. package/cjs/tools/encoder.js.map +1 -0
  98. package/cjs/tools/experimentalFeatures.d.ts +3 -5
  99. package/cjs/tools/experimentalFeatures.js +2 -4
  100. package/cjs/tools/experimentalFeatures.js.map +1 -1
  101. package/cjs/tools/getGlobalObject.js.map +1 -1
  102. package/cjs/tools/getZoneJsOriginalValue.js.map +1 -1
  103. package/cjs/tools/instrumentMethod.d.ts +50 -10
  104. package/cjs/tools/instrumentMethod.js +59 -36
  105. package/cjs/tools/instrumentMethod.js.map +1 -1
  106. package/cjs/tools/matchOption.js.map +1 -1
  107. package/cjs/tools/mergeInto.js.map +1 -1
  108. package/cjs/tools/monitor.d.ts +1 -2
  109. package/cjs/tools/monitor.js +6 -6
  110. package/cjs/tools/monitor.js.map +1 -1
  111. package/cjs/tools/observable.d.ts +1 -1
  112. package/cjs/tools/observable.js +2 -3
  113. package/cjs/tools/observable.js.map +1 -1
  114. package/cjs/tools/readBytesFromStream.js.map +1 -1
  115. package/cjs/tools/sendToExtension.js.map +1 -1
  116. package/cjs/tools/serialisation/jsonStringify.d.ts +1 -2
  117. package/cjs/tools/serialisation/jsonStringify.js.map +1 -1
  118. package/cjs/tools/serialisation/sanitize.js.map +1 -1
  119. package/cjs/tools/utils/browserDetection.d.ts +8 -0
  120. package/cjs/tools/utils/browserDetection.js +33 -3
  121. package/cjs/tools/utils/browserDetection.js.map +1 -1
  122. package/cjs/tools/utils/byteUtils.js.map +1 -1
  123. package/cjs/tools/utils/functionUtils.js.map +1 -1
  124. package/cjs/tools/utils/objectUtils.js.map +1 -1
  125. package/cjs/tools/utils/polyfills.js.map +1 -1
  126. package/cjs/tools/utils/responseUtils.js.map +1 -1
  127. package/cjs/tools/utils/stringUtils.d.ts +1 -0
  128. package/cjs/tools/utils/stringUtils.js +31 -4
  129. package/cjs/tools/utils/stringUtils.js.map +1 -1
  130. package/cjs/tools/utils/timeUtils.js.map +1 -1
  131. package/cjs/tools/utils/typeUtils.js.map +1 -1
  132. package/cjs/tools/utils/urlPolyfill.js.map +1 -1
  133. package/cjs/tools/valueHistory.js.map +1 -1
  134. package/cjs/transport/batch.d.ts +5 -3
  135. package/cjs/transport/batch.js +73 -29
  136. package/cjs/transport/batch.js.map +1 -1
  137. package/cjs/transport/eventBridge.js.map +1 -1
  138. package/cjs/transport/flushController.d.ts +12 -2
  139. package/cjs/transport/flushController.js +22 -7
  140. package/cjs/transport/flushController.js.map +1 -1
  141. package/cjs/transport/httpRequest.d.ts +3 -2
  142. package/cjs/transport/httpRequest.js +21 -17
  143. package/cjs/transport/httpRequest.js.map +1 -1
  144. package/cjs/transport/sendWithRetryStrategy.d.ts +2 -2
  145. package/cjs/transport/sendWithRetryStrategy.js +9 -9
  146. package/cjs/transport/sendWithRetryStrategy.js.map +1 -1
  147. package/cjs/transport/startBatchWithReplica.d.ts +9 -4
  148. package/cjs/transport/startBatchWithReplica.js +9 -4
  149. package/cjs/transport/startBatchWithReplica.js.map +1 -1
  150. package/esm/boot/init.js +1 -1
  151. package/esm/boot/init.js.map +1 -1
  152. package/esm/browser/addEventListener.d.ts +12 -4
  153. package/esm/browser/addEventListener.js +49 -7
  154. package/esm/browser/addEventListener.js.map +1 -1
  155. package/esm/browser/cookie.d.ts +7 -0
  156. package/esm/browser/cookie.js +17 -2
  157. package/esm/browser/cookie.js.map +1 -1
  158. package/esm/browser/fetchObservable.js +15 -20
  159. package/esm/browser/fetchObservable.js.map +1 -1
  160. package/esm/browser/pageExitObservable.js +7 -8
  161. package/esm/browser/pageExitObservable.js.map +1 -1
  162. package/esm/browser/runOnReadyState.js +2 -2
  163. package/esm/browser/runOnReadyState.js.map +1 -1
  164. package/esm/browser/xhrObservable.d.ts +1 -2
  165. package/esm/browser/xhrObservable.js +28 -36
  166. package/esm/browser/xhrObservable.js.map +1 -1
  167. package/esm/domain/configuration/configuration.d.ts +17 -12
  168. package/esm/domain/configuration/configuration.js +8 -9
  169. package/esm/domain/configuration/configuration.js.map +1 -1
  170. package/esm/domain/configuration/endpointBuilder.d.ts +6 -10
  171. package/esm/domain/configuration/endpointBuilder.js +27 -37
  172. package/esm/domain/configuration/endpointBuilder.js.map +1 -1
  173. package/esm/domain/configuration/index.d.ts +2 -1
  174. package/esm/domain/configuration/index.js +1 -0
  175. package/esm/domain/configuration/index.js.map +1 -1
  176. package/esm/domain/configuration/tags.js.map +1 -1
  177. package/esm/domain/configuration/transportConfiguration.js +1 -1
  178. package/esm/domain/configuration/transportConfiguration.js.map +1 -1
  179. package/esm/domain/connectivity/connectivity.d.ts +13 -0
  180. package/esm/domain/connectivity/connectivity.js +10 -0
  181. package/esm/domain/connectivity/connectivity.js.map +1 -0
  182. package/esm/domain/connectivity/index.d.ts +1 -0
  183. package/esm/domain/connectivity/index.js +2 -0
  184. package/esm/domain/connectivity/index.js.map +1 -0
  185. package/esm/domain/console/consoleObservable.js +2 -5
  186. package/esm/domain/console/consoleObservable.js.map +1 -1
  187. package/esm/domain/context/contextConstants.d.ts +5 -0
  188. package/esm/domain/context/contextConstants.js +2 -0
  189. package/esm/domain/context/contextConstants.js.map +1 -0
  190. package/esm/domain/context/contextManager.d.ts +12 -0
  191. package/esm/domain/context/contextManager.js +39 -0
  192. package/esm/domain/context/contextManager.js.map +1 -0
  193. package/esm/domain/context/customerDataTracker.d.ts +45 -0
  194. package/esm/domain/context/customerDataTracker.js +102 -0
  195. package/esm/domain/context/customerDataTracker.js.map +1 -0
  196. package/esm/domain/context/storeContextManager.d.ts +6 -0
  197. package/esm/domain/context/storeContextManager.js +32 -0
  198. package/esm/domain/context/storeContextManager.js.map +1 -0
  199. package/esm/domain/deflate/types.d.ts +12 -0
  200. package/esm/domain/error/computeStackTrace.d.ts +33 -0
  201. package/esm/domain/{tracekit → error}/computeStackTrace.js +26 -3
  202. package/esm/domain/error/computeStackTrace.js.map +1 -0
  203. package/esm/domain/error/error.d.ts +1 -1
  204. package/esm/domain/error/error.js +1 -1
  205. package/esm/domain/error/error.js.map +1 -1
  206. package/esm/domain/error/error.types.d.ts +2 -2
  207. package/esm/domain/error/error.types.js.map +1 -1
  208. package/esm/domain/error/trackRuntimeError.d.ts +8 -0
  209. package/esm/domain/error/trackRuntimeError.js +35 -4
  210. package/esm/domain/error/trackRuntimeError.js.map +1 -1
  211. package/esm/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -1
  212. package/esm/domain/report/browser.types.d.ts +10 -0
  213. package/esm/domain/report/reportObservable.d.ts +2 -0
  214. package/esm/domain/report/reportObservable.js +8 -8
  215. package/esm/domain/report/reportObservable.js.map +1 -1
  216. package/esm/domain/session/oldCookiesMigration.js +5 -5
  217. package/esm/domain/session/oldCookiesMigration.js.map +1 -1
  218. package/esm/domain/session/sessionManager.js +3 -3
  219. package/esm/domain/session/sessionManager.js.map +1 -1
  220. package/esm/domain/session/sessionState.js.map +1 -1
  221. package/esm/domain/session/sessionStore.js.map +1 -1
  222. package/esm/domain/session/sessionStoreOperations.d.ts +0 -5
  223. package/esm/domain/session/sessionStoreOperations.js +5 -12
  224. package/esm/domain/session/sessionStoreOperations.js.map +1 -1
  225. package/esm/domain/session/storeStrategies/sessionInCookie.js +13 -2
  226. package/esm/domain/session/storeStrategies/sessionInCookie.js.map +1 -1
  227. package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +1 -0
  228. package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -1
  229. package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +1 -0
  230. package/esm/domain/synthetics/syntheticsWorkerValues.js +4 -4
  231. package/esm/domain/synthetics/syntheticsWorkerValues.js.map +1 -1
  232. package/esm/domain/telemetry/rawTelemetryEvent.types.d.ts +4 -0
  233. package/esm/domain/telemetry/telemetry.d.ts +5 -1
  234. package/esm/domain/telemetry/telemetry.js +16 -5
  235. package/esm/domain/telemetry/telemetry.js.map +1 -1
  236. package/esm/domain/telemetry/telemetryEvent.types.d.ts +18 -2
  237. package/esm/domain/user/user.js.map +1 -1
  238. package/esm/index.d.ts +9 -5
  239. package/esm/index.js +8 -5
  240. package/esm/index.js.map +1 -1
  241. package/esm/tools/abstractLifeCycle.js.map +1 -1
  242. package/esm/tools/boundedBuffer.js.map +1 -1
  243. package/esm/tools/catchUserErrors.js.map +1 -1
  244. package/esm/tools/display.d.ts +2 -2
  245. package/esm/tools/display.js +12 -15
  246. package/esm/tools/display.js.map +1 -1
  247. package/esm/tools/encoder.d.ts +53 -0
  248. package/esm/tools/encoder.js +37 -0
  249. package/esm/tools/encoder.js.map +1 -0
  250. package/esm/tools/experimentalFeatures.d.ts +3 -5
  251. package/esm/tools/experimentalFeatures.js +2 -4
  252. package/esm/tools/experimentalFeatures.js.map +1 -1
  253. package/esm/tools/getGlobalObject.js.map +1 -1
  254. package/esm/tools/getZoneJsOriginalValue.js.map +1 -1
  255. package/esm/tools/instrumentMethod.d.ts +50 -10
  256. package/esm/tools/instrumentMethod.js +58 -34
  257. package/esm/tools/instrumentMethod.js.map +1 -1
  258. package/esm/tools/matchOption.js.map +1 -1
  259. package/esm/tools/mergeInto.js.map +1 -1
  260. package/esm/tools/monitor.d.ts +1 -2
  261. package/esm/tools/monitor.js +7 -7
  262. package/esm/tools/monitor.js.map +1 -1
  263. package/esm/tools/observable.d.ts +1 -1
  264. package/esm/tools/observable.js +2 -3
  265. package/esm/tools/observable.js.map +1 -1
  266. package/esm/tools/readBytesFromStream.js.map +1 -1
  267. package/esm/tools/sendToExtension.js.map +1 -1
  268. package/esm/tools/serialisation/jsonStringify.d.ts +1 -2
  269. package/esm/tools/serialisation/jsonStringify.js.map +1 -1
  270. package/esm/tools/serialisation/sanitize.js.map +1 -1
  271. package/esm/tools/utils/browserDetection.d.ts +8 -0
  272. package/esm/tools/utils/browserDetection.js +30 -2
  273. package/esm/tools/utils/browserDetection.js.map +1 -1
  274. package/esm/tools/utils/byteUtils.js.map +1 -1
  275. package/esm/tools/utils/functionUtils.js.map +1 -1
  276. package/esm/tools/utils/objectUtils.js.map +1 -1
  277. package/esm/tools/utils/polyfills.js.map +1 -1
  278. package/esm/tools/utils/responseUtils.js.map +1 -1
  279. package/esm/tools/utils/stringUtils.d.ts +1 -0
  280. package/esm/tools/utils/stringUtils.js +29 -3
  281. package/esm/tools/utils/stringUtils.js.map +1 -1
  282. package/esm/tools/utils/timeUtils.js.map +1 -1
  283. package/esm/tools/utils/typeUtils.js.map +1 -1
  284. package/esm/tools/utils/urlPolyfill.js.map +1 -1
  285. package/esm/tools/valueHistory.js.map +1 -1
  286. package/esm/transport/batch.d.ts +5 -3
  287. package/esm/transport/batch.js +73 -29
  288. package/esm/transport/batch.js.map +1 -1
  289. package/esm/transport/eventBridge.js.map +1 -1
  290. package/esm/transport/flushController.d.ts +12 -2
  291. package/esm/transport/flushController.js +22 -7
  292. package/esm/transport/flushController.js.map +1 -1
  293. package/esm/transport/httpRequest.d.ts +3 -2
  294. package/esm/transport/httpRequest.js +21 -17
  295. package/esm/transport/httpRequest.js.map +1 -1
  296. package/esm/transport/sendWithRetryStrategy.d.ts +2 -2
  297. package/esm/transport/sendWithRetryStrategy.js +9 -9
  298. package/esm/transport/sendWithRetryStrategy.js.map +1 -1
  299. package/esm/transport/startBatchWithReplica.d.ts +9 -4
  300. package/esm/transport/startBatchWithReplica.js +9 -4
  301. package/esm/transport/startBatchWithReplica.js.map +1 -1
  302. package/package.json +1 -1
  303. package/src/browser/addEventListener.ts +37 -31
  304. package/src/browser/cookie.ts +21 -2
  305. package/src/browser/fetchObservable.ts +21 -25
  306. package/src/browser/pageExitObservable.ts +1 -3
  307. package/src/browser/xhrObservable.ts +31 -37
  308. package/src/domain/configuration/configuration.ts +24 -22
  309. package/src/domain/configuration/endpointBuilder.ts +40 -53
  310. package/src/domain/configuration/index.ts +2 -1
  311. package/src/domain/configuration/transportConfiguration.ts +1 -1
  312. package/src/domain/connectivity/connectivity.ts +27 -0
  313. package/src/domain/connectivity/index.ts +1 -0
  314. package/src/domain/console/consoleObservable.ts +3 -7
  315. package/src/domain/context/contextConstants.ts +5 -0
  316. package/src/domain/context/contextManager.ts +48 -0
  317. package/src/domain/context/customerDataTracker.ts +134 -0
  318. package/src/domain/context/storeContextManager.ts +51 -0
  319. package/src/domain/deflate/types.ts +14 -0
  320. package/src/domain/{tracekit → error}/computeStackTrace.ts +49 -4
  321. package/src/domain/error/error.ts +2 -2
  322. package/src/domain/error/error.types.ts +11 -2
  323. package/src/domain/error/trackRuntimeError.ts +44 -12
  324. package/src/domain/report/browser.types.ts +12 -0
  325. package/src/domain/report/reportObservable.ts +8 -6
  326. package/src/domain/session/oldCookiesMigration.ts +5 -5
  327. package/src/domain/session/sessionStoreOperations.ts +5 -13
  328. package/src/domain/session/storeStrategies/sessionInCookie.ts +13 -2
  329. package/src/domain/session/storeStrategies/sessionInLocalStorage.ts +1 -0
  330. package/src/domain/session/storeStrategies/sessionStoreStrategy.ts +1 -0
  331. package/src/domain/synthetics/syntheticsWorkerValues.ts +4 -4
  332. package/src/domain/telemetry/rawTelemetryEvent.types.ts +5 -0
  333. package/src/domain/telemetry/telemetry.ts +22 -7
  334. package/src/domain/telemetry/telemetryEvent.types.ts +18 -2
  335. package/src/index.ts +13 -7
  336. package/src/tools/display.ts +14 -13
  337. package/src/tools/encoder.ts +102 -0
  338. package/src/tools/experimentalFeatures.ts +2 -4
  339. package/src/tools/instrumentMethod.ts +103 -59
  340. package/src/tools/mergeInto.ts +16 -16
  341. package/src/tools/monitor.ts +5 -5
  342. package/src/tools/observable.ts +3 -5
  343. package/src/tools/utils/browserDetection.ts +43 -2
  344. package/src/tools/utils/polyfills.ts +1 -4
  345. package/src/tools/utils/stringUtils.ts +30 -4
  346. package/src/transport/batch.ts +86 -31
  347. package/src/transport/flushController.ts +22 -7
  348. package/src/transport/httpRequest.ts +23 -16
  349. package/src/transport/sendWithRetryStrategy.ts +10 -10
  350. package/src/transport/startBatchWithReplica.ts +22 -6
  351. package/cjs/domain/deflate/index.d.ts +0 -1
  352. package/cjs/domain/deflate/index.js.map +0 -1
  353. package/cjs/domain/tracekit/computeStackTrace.d.ts +0 -5
  354. package/cjs/domain/tracekit/computeStackTrace.js.map +0 -1
  355. package/cjs/domain/tracekit/index.d.ts +0 -3
  356. package/cjs/domain/tracekit/index.js +0 -8
  357. package/cjs/domain/tracekit/index.js.map +0 -1
  358. package/cjs/domain/tracekit/tracekit.d.ts +0 -35
  359. package/cjs/domain/tracekit/tracekit.js +0 -95
  360. package/cjs/domain/tracekit/tracekit.js.map +0 -1
  361. package/cjs/domain/tracekit/types.d.ts +0 -44
  362. package/cjs/domain/tracekit/types.js.map +0 -1
  363. package/cjs/index.d.ts +0 -63
  364. package/cjs/index.js +0 -155
  365. package/cjs/index.js.map +0 -1
  366. package/cjs/tools/serialisation/contextManager.d.ts +0 -21
  367. package/cjs/tools/serialisation/contextManager.js +0 -70
  368. package/cjs/tools/serialisation/contextManager.js.map +0 -1
  369. package/cjs/tools/serialisation/heavyCustomerDataWarning.d.ts +0 -8
  370. package/cjs/tools/serialisation/heavyCustomerDataWarning.js +0 -18
  371. package/cjs/tools/serialisation/heavyCustomerDataWarning.js.map +0 -1
  372. package/esm/domain/tracekit/computeStackTrace.d.ts +0 -5
  373. package/esm/domain/tracekit/computeStackTrace.js.map +0 -1
  374. package/esm/domain/tracekit/index.d.ts +0 -3
  375. package/esm/domain/tracekit/index.js +0 -3
  376. package/esm/domain/tracekit/index.js.map +0 -1
  377. package/esm/domain/tracekit/tracekit.d.ts +0 -35
  378. package/esm/domain/tracekit/tracekit.js +0 -91
  379. package/esm/domain/tracekit/tracekit.js.map +0 -1
  380. package/esm/domain/tracekit/types.d.ts +0 -44
  381. package/esm/domain/tracekit/types.js +0 -2
  382. package/esm/domain/tracekit/types.js.map +0 -1
  383. package/esm/tools/serialisation/contextManager.d.ts +0 -21
  384. package/esm/tools/serialisation/contextManager.js +0 -66
  385. package/esm/tools/serialisation/contextManager.js.map +0 -1
  386. package/esm/tools/serialisation/heavyCustomerDataWarning.d.ts +0 -8
  387. package/esm/tools/serialisation/heavyCustomerDataWarning.js +0 -14
  388. package/esm/tools/serialisation/heavyCustomerDataWarning.js.map +0 -1
  389. package/src/domain/tracekit/index.ts +0 -3
  390. package/src/domain/tracekit/tracekit.ts +0 -96
  391. package/src/domain/tracekit/types.ts +0 -47
  392. package/src/tools/serialisation/contextManager.ts +0 -79
  393. package/src/tools/serialisation/heavyCustomerDataWarning.ts +0 -26
@@ -4,8 +4,6 @@ import { toStackTraceString, NO_ERROR_STACK_PRESENT_MESSAGE } from '../error/err
4
4
  import { getExperimentalFeatures } from '../../tools/experimentalFeatures'
5
5
  import type { Configuration } from '../configuration'
6
6
  import { INTAKE_SITE_STAGING, INTAKE_SITE_US1_FED } from '../configuration'
7
- import type { StackTrace } from '../tracekit'
8
- import { computeStackTrace } from '../tracekit'
9
7
  import { Observable } from '../../tools/observable'
10
8
  import { timeStampNow } from '../../tools/utils/timeUtils'
11
9
  import { displayIfDebugEnabled, startMonitorErrorCollection } from '../../tools/monitor'
@@ -15,8 +13,11 @@ import { performDraw } from '../../tools/utils/numberUtils'
15
13
  import { jsonStringify } from '../../tools/serialisation/jsonStringify'
16
14
  import { combine } from '../../tools/mergeInto'
17
15
  import { NonErrorPrefix } from '../error/error.types'
16
+ import type { StackTrace } from '../error/computeStackTrace'
17
+ import { computeStackTrace } from '../error/computeStackTrace'
18
+ import { getConnectivity } from '../connectivity'
18
19
  import type { TelemetryEvent } from './telemetryEvent.types'
19
- import type { RawTelemetryConfiguration, RawTelemetryEvent } from './rawTelemetryEvent.types'
20
+ import type { RawTelemetryConfiguration, RawTelemetryEvent, RuntimeEnvInfo } from './rawTelemetryEvent.types'
20
21
  import { StatusType, TelemetryType } from './rawTelemetryEvent.types'
21
22
 
22
23
  // replaced at build time
@@ -58,9 +59,10 @@ export function startTelemetry(telemetryService: TelemetryService, configuration
58
59
  telemetryConfiguration.telemetryConfigurationEnabled =
59
60
  telemetryConfiguration.telemetryEnabled && performDraw(configuration.telemetryConfigurationSampleRate)
60
61
 
62
+ const runtimeEnvInfo = getRuntimeEnvInfo()
61
63
  onRawTelemetryEventCollected = (rawEvent: RawTelemetryEvent) => {
62
64
  if (telemetryConfiguration.telemetryEnabled) {
63
- const event = toTelemetryEvent(telemetryService, rawEvent)
65
+ const event = toTelemetryEvent(telemetryService, rawEvent, runtimeEnvInfo)
64
66
  observable.notify(event)
65
67
  sendToExtension('telemetry', event)
66
68
  }
@@ -72,7 +74,11 @@ export function startTelemetry(telemetryService: TelemetryService, configuration
72
74
  sentEventCount: 0,
73
75
  })
74
76
 
75
- function toTelemetryEvent(telemetryService: TelemetryService, event: RawTelemetryEvent): TelemetryEvent & Context {
77
+ function toTelemetryEvent(
78
+ telemetryService: TelemetryService,
79
+ event: RawTelemetryEvent,
80
+ runtimeEnvInfo: RuntimeEnvInfo
81
+ ): TelemetryEvent & Context {
76
82
  return combine(
77
83
  {
78
84
  type: 'telemetry' as const,
@@ -83,11 +89,14 @@ export function startTelemetry(telemetryService: TelemetryService, configuration
83
89
  _oo: {
84
90
  format_version: 2 as const,
85
91
  },
86
- telemetry: event as any, // https://github.com/microsoft/TypeScript/issues/48457
92
+ telemetry: combine(event, {
93
+ runtime_env: runtimeEnvInfo,
94
+ connectivity: getConnectivity(),
95
+ }),
87
96
  experimental_features: arrayFrom(getExperimentalFeatures()),
88
97
  },
89
98
  contextProvider !== undefined ? contextProvider() : {}
90
- )
99
+ ) as TelemetryEvent & Context
91
100
  }
92
101
 
93
102
  return {
@@ -98,6 +107,12 @@ export function startTelemetry(telemetryService: TelemetryService, configuration
98
107
  enabled: telemetryConfiguration.telemetryEnabled,
99
108
  }
100
109
  }
110
+ function getRuntimeEnvInfo(): RuntimeEnvInfo {
111
+ return {
112
+ is_local_file: window.location.protocol === 'file:',
113
+ is_worker: 'WorkerGlobalScope' in self,
114
+ }
115
+ }
101
116
 
102
117
  export function startFakeTelemetry() {
103
118
  const events: RawTelemetryEvent[] = []
@@ -142,9 +142,13 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
142
142
  */
143
143
  track_long_task?: boolean
144
144
  /**
145
- * Whether a secure cross-site session cookie is used
145
+ * Whether a secure cross-site session cookie is used (deprecated)
146
146
  */
147
147
  use_cross_site_session_cookie?: boolean
148
+ /**
149
+ * Whether a partitioned secure cross-site session cookie is used
150
+ */
151
+ use_partitioned_cross_site_session_cookie?: boolean
148
152
  /**
149
153
  * Whether a secure session cookie is used
150
154
  */
@@ -153,6 +157,10 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
153
157
  * Whether it is allowed to use LocalStorage when cookies are not available
154
158
  */
155
159
  allow_fallback_to_local_storage?: boolean
160
+ /**
161
+ * Whether contexts are stored in local storage
162
+ */
163
+ store_contexts_across_pages?: boolean
156
164
  /**
157
165
  * Whether untrusted events are allowed
158
166
  */
@@ -281,6 +289,14 @@ export type TelemetryConfigurationEvent = CommonTelemetryProperties & {
281
289
  * The upload frequency of batches (in milliseconds)
282
290
  */
283
291
  batch_upload_frequency?: number
292
+ /**
293
+ * Maximum number of batches processed sequencially without a delay
294
+ */
295
+ batch_processing_level?: number
296
+ /**
297
+ * Whether UIApplication background tasks are enabled
298
+ */
299
+ background_tasks_enabled?: boolean
284
300
  /**
285
301
  * The version of React used in a ReactNative application
286
302
  */
@@ -329,7 +345,7 @@ export interface CommonTelemetryProperties {
329
345
  /**
330
346
  * The source of this event
331
347
  */
332
- readonly source: 'android' | 'ios' | 'browser' | 'flutter' | 'react-native'
348
+ readonly source: 'android' | 'ios' | 'browser' | 'flutter' | 'react-native' | 'unity'
333
349
  /**
334
350
  * The version of the SDK generating the telemetry event
335
351
  */
package/src/index.ts CHANGED
@@ -5,7 +5,6 @@ export {
5
5
  DefaultPrivacyLevel,
6
6
  EndpointBuilder,
7
7
  serializeConfiguration,
8
- INTAKE_SITE_AP1,
9
8
  INTAKE_SITE_STAGING,
10
9
  INTAKE_SITE_US1,
11
10
  INTAKE_SITE_US1_FED,
@@ -19,7 +18,7 @@ export {
19
18
  ExperimentalFeature,
20
19
  } from './tools/experimentalFeatures'
21
20
  export { trackRuntimeError } from './domain/error/trackRuntimeError'
22
- export { computeStackTrace, StackTrace } from './domain/tracekit'
21
+ export { computeStackTrace, StackTrace } from './domain/error/computeStackTrace'
23
22
  export { defineGlobal, makePublicApi } from './boot/init'
24
23
  export { initReportObservable, RawReport, RawReportType } from './domain/report/reportObservable'
25
24
  export {
@@ -62,6 +61,7 @@ export {
62
61
  FlushReason,
63
62
  } from './transport'
64
63
  export * from './tools/display'
64
+ export { Encoder, EncoderResult, createIdentityEncoder } from './tools/encoder'
65
65
  export * from './tools/utils/urlPolyfill'
66
66
  export * from './tools/utils/timeUtils'
67
67
  export * from './tools/utils/arrayUtils'
@@ -73,7 +73,7 @@ export * from './tools/utils/browserDetection'
73
73
  export { sendToExtension } from './tools/sendToExtension'
74
74
  export { runOnReadyState } from './browser/runOnReadyState'
75
75
  export { getZoneJsOriginalValue } from './tools/getZoneJsOriginalValue'
76
- export { instrumentMethod, instrumentMethodAndCallOriginal, instrumentSetter } from './tools/instrumentMethod'
76
+ export { instrumentMethod, instrumentSetter, InstrumentedMethodCall } from './tools/instrumentMethod'
77
77
  export {
78
78
  computeRawError,
79
79
  createHandlingStack,
@@ -92,12 +92,17 @@ export * from './tools/timer'
92
92
  export { initConsoleObservable, resetConsoleObservable, ConsoleLog } from './domain/console/consoleObservable'
93
93
  export { BoundedBuffer } from './tools/boundedBuffer'
94
94
  export { catchUserErrors } from './tools/catchUserErrors'
95
- export { createContextManager, ContextManager } from './tools/serialisation/contextManager'
95
+ export { createContextManager, ContextManager } from './domain/context/contextManager'
96
+ export { storeContextManager, removeStorageListeners } from './domain/context/storeContextManager'
96
97
  export {
97
- warnIfCustomerDataLimitReached,
98
- CustomerDataType,
98
+ createCustomerDataTrackerManager,
99
+ createCustomerDataTracker,
100
+ CustomerDataTracker,
101
+ CustomerDataTrackerManager,
99
102
  CUSTOMER_DATA_BYTES_LIMIT,
100
- } from './tools/serialisation/heavyCustomerDataWarning'
103
+ CustomerDataCompressionStatus,
104
+ } from './domain/context/customerDataTracker'
105
+ export { CustomerDataType } from './domain/context/contextConstants'
101
106
  export { ValueHistory, ValueHistoryEntry, CLEAR_OLD_VALUES_INTERVAL } from './tools/valueHistory'
102
107
  export { readBytesFromStream } from './tools/readBytesFromStream'
103
108
  export { STORAGE_POLL_DELAY } from './domain/session/sessionStore'
@@ -126,3 +131,4 @@ export { RawError } from './domain/error/error.types'
126
131
  export { RawErrorCause } from './domain/error/error.types'
127
132
  export { ErrorWithCause } from './domain/error/error.types'
128
133
  export * from './domain/deflate'
134
+ export * from './domain/connectivity'
@@ -18,7 +18,6 @@ export const ConsoleApiName = {
18
18
  export type ConsoleApiName = (typeof ConsoleApiName)[keyof typeof ConsoleApiName]
19
19
 
20
20
  interface Display {
21
- (api: ConsoleApiName, ...args: any[]): void
22
21
  debug: typeof console.debug
23
22
  log: typeof console.log
24
23
  info: typeof console.info
@@ -26,13 +25,6 @@ interface Display {
26
25
  error: typeof console.error
27
26
  }
28
27
 
29
- export const display: Display = (api, ...args) => {
30
- if (!Object.prototype.hasOwnProperty.call(ConsoleApiName, api)) {
31
- api = ConsoleApiName.log
32
- }
33
- display[api](...args)
34
- }
35
-
36
28
  /**
37
29
  * When building JS bundles, some users might use a plugin[1] or configuration[2] to remove
38
30
  * "console.*" references. This causes some issue as we expect `console.*` to be defined.
@@ -44,8 +36,17 @@ export const display: Display = (api, ...args) => {
44
36
  */
45
37
  export const globalConsole = console
46
38
 
47
- display.debug = globalConsole.debug.bind(globalConsole)
48
- display.log = globalConsole.log.bind(globalConsole)
49
- display.info = globalConsole.info.bind(globalConsole)
50
- display.warn = globalConsole.warn.bind(globalConsole)
51
- display.error = globalConsole.error.bind(globalConsole)
39
+ export const originalConsoleMethods = {} as Display
40
+ Object.keys(ConsoleApiName).forEach((name) => {
41
+ originalConsoleMethods[name as ConsoleApiName] = globalConsole[name as ConsoleApiName]
42
+ })
43
+
44
+ const PREFIX = 'Datadog Browser SDK:'
45
+
46
+ export const display: Display = {
47
+ debug: originalConsoleMethods.debug.bind(globalConsole, PREFIX),
48
+ log: originalConsoleMethods.log.bind(globalConsole, PREFIX),
49
+ info: originalConsoleMethods.info.bind(globalConsole, PREFIX),
50
+ warn: originalConsoleMethods.warn.bind(globalConsole, PREFIX),
51
+ error: originalConsoleMethods.error.bind(globalConsole, PREFIX),
52
+ }
@@ -0,0 +1,102 @@
1
+ import { computeBytesCount } from './utils/byteUtils'
2
+
3
+ export interface Encoder<Output extends string | Uint8Array = string | Uint8Array> {
4
+ /**
5
+ * Whether this encoder might call the provided callbacks asynchronously
6
+ */
7
+ isAsync: boolean
8
+
9
+ /**
10
+ * Whether some data has been written since the last finish() or finishSync() call
11
+ */
12
+ isEmpty: boolean
13
+
14
+ /**
15
+ * Write a string to be encoded.
16
+ *
17
+ * This operation can be synchronous or asynchronous depending on the encoder implementation.
18
+ *
19
+ * If specified, the callback will be invoked when the operation finishes, unless the operation is
20
+ * asynchronous and finish() or finishSync() is called in the meantime.
21
+ */
22
+ write(data: string, callback?: (additionalEncodedBytesCount: number) => void): void
23
+
24
+ /**
25
+ * Waits for pending data to be encoded and resets the encoder state.
26
+ *
27
+ * This operation can be synchronous or asynchronous depending on the encoder implementation.
28
+ *
29
+ * The callback will be invoked when the operation finishes, unless the operation is asynchronous
30
+ * and another call to finish() or finishSync() occurs in the meantime.
31
+ */
32
+ finish(callback: (result: EncoderResult<Output>) => void): void
33
+
34
+ /**
35
+ * Resets the encoder state then returns the encoded data and any potential pending data directly,
36
+ * discarding all pending write operations and finish() callbacks.
37
+ */
38
+ finishSync(): EncoderResult<Output> & { pendingData: string }
39
+
40
+ /**
41
+ * Returns a rough estimation of the bytes count if the data was encoded.
42
+ */
43
+ estimateEncodedBytesCount(data: string): number
44
+ }
45
+
46
+ export interface EncoderResult<Output extends string | Uint8Array = string | Uint8Array> {
47
+ output: Output
48
+ outputBytesCount: number
49
+
50
+ /**
51
+ * An encoding type supported by HTTP Content-Encoding, if applicable.
52
+ * See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding#directives
53
+ */
54
+ encoding?: 'deflate'
55
+
56
+ /**
57
+ * Total bytes count of the input strings encoded to UTF-8.
58
+ */
59
+ rawBytesCount: number
60
+ }
61
+
62
+ export function createIdentityEncoder(): Encoder<string> {
63
+ let output = ''
64
+ let outputBytesCount = 0
65
+
66
+ return {
67
+ isAsync: false,
68
+
69
+ get isEmpty() {
70
+ return !output
71
+ },
72
+
73
+ write(data, callback) {
74
+ const additionalEncodedBytesCount = computeBytesCount(data)
75
+ outputBytesCount += additionalEncodedBytesCount
76
+ output += data
77
+ if (callback) {
78
+ callback(additionalEncodedBytesCount)
79
+ }
80
+ },
81
+
82
+ finish(callback) {
83
+ callback(this.finishSync())
84
+ },
85
+
86
+ finishSync() {
87
+ const result = {
88
+ output,
89
+ outputBytesCount,
90
+ rawBytesCount: outputBytesCount,
91
+ pendingData: '',
92
+ }
93
+ output = ''
94
+ outputBytesCount = 0
95
+ return result
96
+ },
97
+
98
+ estimateEncodedBytesCount(data) {
99
+ return data.length
100
+ },
101
+ }
102
+ }
@@ -14,12 +14,10 @@ export enum ExperimentalFeature {
14
14
  PAGEHIDE = 'pagehide',
15
15
  FEATURE_FLAGS = 'feature_flags',
16
16
  RESOURCE_PAGE_STATES = 'resource_page_states',
17
- PAGE_STATES = 'page_states',
18
17
  COLLECT_FLUSH_REASON = 'collect_flush_reason',
19
- NO_RESOURCE_DURATION_FROZEN_STATE = 'no_resource_duration_frozen_state',
20
- SCROLLMAP = 'scrollmap',
21
- INTERACTION_TO_NEXT_PAINT = 'interaction_to_next_paint',
18
+ ZERO_LCP_TELEMETRY = 'zero_lcp_telemetry',
22
19
  DISABLE_REPLAY_INLINE_CSS = 'disable_replay_inline_css',
20
+ WRITABLE_RESOURCE_GRAPHQL = 'writable_resource_graphql',
23
21
  }
24
22
 
25
23
  const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
@@ -2,30 +2,77 @@ import { setTimeout } from './timer'
2
2
  import { callMonitored } from './monitor'
3
3
  import { noop } from './utils/functionUtils'
4
4
 
5
- export function instrumentMethod<OBJECT extends { [key: string]: any }, METHOD extends keyof OBJECT>(
6
- object: OBJECT,
5
+ /**
6
+ * Object passed to the callback of an instrumented method call. See `instrumentMethod` for more
7
+ * info.
8
+ */
9
+ export type InstrumentedMethodCall<TARGET extends { [key: string]: any }, METHOD extends keyof TARGET> = {
10
+ /**
11
+ * The target object on which the method was called.
12
+ */
13
+ target: TARGET
14
+
15
+ /**
16
+ * The parameters with which the method was called. To avoid having to clone the argument list
17
+ * every time, this property is actually an instance of Argument, not Array, so not all methods
18
+ * are available (like .forEach).
19
+ *
20
+ * Note: if needed, parameters can be mutated by the instrumentation
21
+ */
22
+ parameters: Parameters<TARGET[METHOD]>
23
+
24
+ /**
25
+ * Registers a callback that will be called after the original method is called, with the method
26
+ * result passed as argument.
27
+ */
28
+ onPostCall: (callback: PostCallCallback<TARGET, METHOD>) => void
29
+ }
30
+
31
+ type PostCallCallback<TARGET extends { [key: string]: any }, METHOD extends keyof TARGET> = (
32
+ result: ReturnType<TARGET[METHOD]>
33
+ ) => void
34
+
35
+ /**
36
+ * Instruments a method on a object, calling the given callback before the original method is
37
+ * invoked. The callback receives an object with information about the method call.
38
+ *
39
+ * Note: it is generally better to instrument methods that are "owned" by the object instead of ones
40
+ * that are inherited from the prototype chain. Example:
41
+ * * do: `instrumentMethod(Array.prototype, 'push', ...)`
42
+ * * don't: `instrumentMethod([], 'push', ...)`
43
+ *
44
+ * @example
45
+ *
46
+ * instrumentMethod(window, 'fetch', ({ target, parameters, onPostCall }) => {
47
+ * console.log('Before calling fetch on', target, 'with parameters', parameters)
48
+ *
49
+ * onPostCall((result) => {
50
+ * console.log('After fetch calling on', target, 'with parameters', parameters, 'and result', result)
51
+ * })
52
+ * })
53
+ */
54
+ export function instrumentMethod<TARGET extends { [key: string]: any }, METHOD extends keyof TARGET>(
55
+ targetPrototype: TARGET,
7
56
  method: METHOD,
8
- instrumentationFactory: (
9
- original: OBJECT[METHOD]
10
- ) => (this: OBJECT, ...args: Parameters<OBJECT[METHOD]>) => ReturnType<OBJECT[METHOD]>
57
+ onPreCall: (this: null, callInfos: InstrumentedMethodCall<TARGET, METHOD>) => void
11
58
  ) {
12
- const original = object[method]
59
+ const original = targetPrototype[method]
13
60
 
14
- let instrumentation = instrumentationFactory(original)
61
+ let instrumentation = createInstrumentedMethod(original, onPreCall)
15
62
 
16
- const instrumentationWrapper = function (this: OBJECT): ReturnType<OBJECT[METHOD]> | undefined {
63
+ const instrumentationWrapper = function (this: TARGET): ReturnType<TARGET[METHOD]> | undefined {
17
64
  if (typeof instrumentation !== 'function') {
18
65
  return undefined
19
66
  }
20
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
21
- return instrumentation.apply(this, arguments as unknown as Parameters<OBJECT[METHOD]>)
67
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
68
+ return instrumentation.apply(this, arguments as unknown as Parameters<TARGET[METHOD]>)
22
69
  }
23
- object[method] = instrumentationWrapper as OBJECT[METHOD]
70
+ targetPrototype[method] = instrumentationWrapper as TARGET[METHOD]
24
71
 
25
72
  return {
26
73
  stop: () => {
27
- if (object[method] === instrumentationWrapper) {
28
- object[method] = original
74
+ if (targetPrototype[method] === instrumentationWrapper) {
75
+ targetPrototype[method] = original
29
76
  } else {
30
77
  instrumentation = original
31
78
  }
@@ -33,74 +80,71 @@ export function instrumentMethod<OBJECT extends { [key: string]: any }, METHOD e
33
80
  }
34
81
  }
35
82
 
36
- export function instrumentMethodAndCallOriginal<OBJECT extends { [key: string]: any }, METHOD extends keyof OBJECT>(
37
- object: OBJECT,
38
- method: METHOD,
39
- {
40
- before,
41
- after,
42
- }: {
43
- before?: (this: OBJECT, ...args: Parameters<OBJECT[METHOD]>) => void
44
- after?: (this: OBJECT, ...args: Parameters<OBJECT[METHOD]>) => void
45
- }
46
- ) {
47
- return instrumentMethod(
48
- object,
49
- method,
50
- (original) =>
51
- function () {
52
- const args = arguments as unknown as Parameters<OBJECT[METHOD]>
53
- let result
54
-
55
- if (before) {
56
- callMonitored(before, this, args)
57
- }
58
-
59
- if (typeof original === 'function') {
60
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
61
- result = original.apply(this, args)
62
- }
63
-
64
- if (after) {
65
- callMonitored(after, this, args)
66
- }
67
-
68
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
69
- return result
70
- }
71
- )
83
+ function createInstrumentedMethod<TARGET extends { [key: string]: any }, METHOD extends keyof TARGET>(
84
+ original: TARGET[METHOD],
85
+ onPreCall: (this: null, callInfos: InstrumentedMethodCall<TARGET, METHOD>) => void
86
+ ): TARGET[METHOD] {
87
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
88
+ return function (this: TARGET) {
89
+ const parameters = arguments as unknown as Parameters<TARGET[METHOD]>
90
+ let result
91
+
92
+ let postCallCallback: PostCallCallback<TARGET, METHOD> | undefined
93
+
94
+ callMonitored(onPreCall, null, [
95
+ {
96
+ target: this,
97
+ parameters,
98
+ onPostCall: (callback) => {
99
+ postCallCallback = callback
100
+ },
101
+ },
102
+ ])
103
+
104
+ if (typeof original === 'function') {
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
106
+ result = original.apply(this, parameters)
107
+ }
108
+
109
+ if (postCallCallback) {
110
+ callMonitored(postCallCallback, null, [result])
111
+ }
112
+
113
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
114
+ return result
115
+ } as TARGET[METHOD]
72
116
  }
73
117
 
74
- export function instrumentSetter<OBJECT extends { [key: string]: any }, PROPERTY extends keyof OBJECT>(
75
- object: OBJECT,
118
+ export function instrumentSetter<TARGET extends { [key: string]: any }, PROPERTY extends keyof TARGET>(
119
+ targetPrototype: TARGET,
76
120
  property: PROPERTY,
77
- after: (thisObject: OBJECT, value: OBJECT[PROPERTY]) => void
121
+ after: (target: TARGET, value: TARGET[PROPERTY]) => void
78
122
  ) {
79
- const originalDescriptor = Object.getOwnPropertyDescriptor(object, property)
123
+ const originalDescriptor = Object.getOwnPropertyDescriptor(targetPrototype, property)
80
124
  if (!originalDescriptor || !originalDescriptor.set || !originalDescriptor.configurable) {
81
125
  return { stop: noop }
82
126
  }
83
127
 
84
- let instrumentation = (thisObject: OBJECT, value: OBJECT[PROPERTY]) => {
128
+ let instrumentation = (target: TARGET, value: TARGET[PROPERTY]) => {
85
129
  // put hooked setter into event loop to avoid of set latency
86
130
  setTimeout(() => {
87
- after(thisObject, value)
131
+ after(target, value)
88
132
  }, 0)
89
133
  }
90
134
 
91
- const instrumentationWrapper = function (this: OBJECT, value: OBJECT[PROPERTY]) {
135
+ const instrumentationWrapper = function (this: TARGET, value: TARGET[PROPERTY]) {
92
136
  originalDescriptor.set!.call(this, value)
93
137
  instrumentation(this, value)
94
138
  }
95
139
 
96
- Object.defineProperty(object, property, {
140
+ Object.defineProperty(targetPrototype, property, {
97
141
  set: instrumentationWrapper,
98
142
  })
99
143
 
100
144
  return {
101
145
  stop: () => {
102
- if (Object.getOwnPropertyDescriptor(object, property)?.set === instrumentationWrapper) {
103
- Object.defineProperty(object, property, originalDescriptor)
146
+ if (Object.getOwnPropertyDescriptor(targetPrototype, property)?.set === instrumentationWrapper) {
147
+ Object.defineProperty(targetPrototype, property, originalDescriptor)
104
148
  } else {
105
149
  instrumentation = noop
106
150
  }
@@ -5,22 +5,22 @@ type Merged<TDestination, TSource> =
5
5
  TSource extends undefined
6
6
  ? TDestination
7
7
  : // case 2 - destination is undefined - return source
8
- TDestination extends undefined
9
- ? TSource
10
- : // case 3 - source is an array - see if it merges or overwrites
11
- TSource extends any[]
12
- ? TDestination extends any[]
13
- ? TDestination & TSource
14
- : TSource
15
- : // case 4 - source is an object - see if it merges or overwrites
16
- TSource extends object
17
- ? TDestination extends object
18
- ? TDestination extends any[]
19
- ? TSource
20
- : TDestination & TSource
21
- : TSource
22
- : // case 5 - cannot merge - return source
23
- TSource
8
+ TDestination extends undefined
9
+ ? TSource
10
+ : // case 3 - source is an array - see if it merges or overwrites
11
+ TSource extends any[]
12
+ ? TDestination extends any[]
13
+ ? TDestination & TSource
14
+ : TSource
15
+ : // case 4 - source is an object - see if it merges or overwrites
16
+ TSource extends object
17
+ ? TDestination extends object
18
+ ? TDestination extends any[]
19
+ ? TSource
20
+ : TDestination & TSource
21
+ : TSource
22
+ : // case 5 - cannot merge - return source
23
+ TSource
24
24
 
25
25
  /**
26
26
  * Iterate over source and affect its sub values into destination, recursively.
@@ -1,4 +1,4 @@
1
- import { ConsoleApiName, display } from './display'
1
+ import { display } from './display'
2
2
 
3
3
  let onMonitorErrorCollected: undefined | ((error: unknown) => void)
4
4
  let debugMode = false
@@ -50,19 +50,19 @@ export function callMonitored<T extends (...args: any[]) => any>(
50
50
  // eslint-disable-next-line @typescript-eslint/no-unsafe-return
51
51
  return fn.apply(context, args)
52
52
  } catch (e) {
53
- displayIfDebugEnabled(ConsoleApiName.error, e)
53
+ displayIfDebugEnabled(e)
54
54
  if (onMonitorErrorCollected) {
55
55
  try {
56
56
  onMonitorErrorCollected(e)
57
57
  } catch (e) {
58
- displayIfDebugEnabled(ConsoleApiName.error, e)
58
+ displayIfDebugEnabled(e)
59
59
  }
60
60
  }
61
61
  }
62
62
  }
63
63
 
64
- export function displayIfDebugEnabled(api: ConsoleApiName, ...args: any[]) {
64
+ export function displayIfDebugEnabled(...args: any[]) {
65
65
  if (debugMode) {
66
- display(api, '[MONITOR]', ...args)
66
+ display.error('[MONITOR]', ...args)
67
67
  }
68
68
  }
@@ -6,11 +6,11 @@ export class Observable<T> {
6
6
  private observers: Array<(data: T) => void> = []
7
7
  private onLastUnsubscribe?: () => void
8
8
 
9
- constructor(private onFirstSubscribe?: () => (() => void) | void) {}
9
+ constructor(private onFirstSubscribe?: (observable: Observable<T>) => (() => void) | void) {}
10
10
 
11
11
  subscribe(f: (data: T) => void): Subscription {
12
12
  if (!this.observers.length && this.onFirstSubscribe) {
13
- this.onLastUnsubscribe = this.onFirstSubscribe() || undefined
13
+ this.onLastUnsubscribe = this.onFirstSubscribe(this) || undefined
14
14
  }
15
15
  this.observers.push(f)
16
16
  return {
@@ -29,12 +29,10 @@ export class Observable<T> {
29
29
  }
30
30
 
31
31
  export function mergeObservables<T>(...observables: Array<Observable<T>>) {
32
- const globalObservable = new Observable<T>(() => {
32
+ return new Observable<T>((globalObservable) => {
33
33
  const subscriptions: Subscription[] = observables.map((observable) =>
34
34
  observable.subscribe((data) => globalObservable.notify(data))
35
35
  )
36
36
  return () => subscriptions.forEach((subscription) => subscription.unsubscribe())
37
37
  })
38
-
39
- return globalObservable
40
38
  }