@datadog/mobile-react-native 1.2.0 → 1.3.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 (258) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +31 -1
  3. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +222 -0
  4. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +6 -0
  5. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +106 -0
  6. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +2 -0
  7. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +116 -0
  8. package/datadog-sourcemaps.gradle +7 -7
  9. package/ios/Sources/Attributes.swift +14 -0
  10. package/ios/Sources/DdSdk.swift +18 -0
  11. package/jest/mock.js +103 -0
  12. package/lib/commonjs/DdSdkReactNative.js +40 -8
  13. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js +42 -2
  15. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  16. package/lib/commonjs/foundation.js +2 -139
  17. package/lib/commonjs/foundation.js.map +1 -1
  18. package/lib/commonjs/index.js +18 -14
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/commonjs/logs/DdLogs.js +71 -0
  21. package/lib/commonjs/logs/DdLogs.js.map +1 -0
  22. package/lib/commonjs/logs/eventMapper.js +39 -0
  23. package/lib/commonjs/logs/eventMapper.js.map +1 -0
  24. package/lib/commonjs/logs/types.js +2 -0
  25. package/lib/commonjs/{rum/instrumentation/EventsInterceptor.js.map → logs/types.js.map} +0 -0
  26. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  27. package/lib/commonjs/rum/DdRum.js +234 -0
  28. package/lib/commonjs/rum/DdRum.js.map +1 -0
  29. package/lib/commonjs/rum/eventMappers/actionEventMapper.js +36 -0
  30. package/lib/commonjs/rum/eventMappers/actionEventMapper.js.map +1 -0
  31. package/lib/commonjs/rum/eventMappers/errorEventMapper.js +32 -0
  32. package/lib/commonjs/rum/eventMappers/errorEventMapper.js.map +1 -0
  33. package/lib/commonjs/rum/eventMappers/resourceEventMapper.js +38 -0
  34. package/lib/commonjs/rum/eventMappers/resourceEventMapper.js.map +1 -0
  35. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  36. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  37. package/lib/commonjs/rum/instrumentation/{DdEventsInterceptor.js → interactionTracking/DdEventsInterceptor.js} +6 -6
  38. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -0
  39. package/lib/commonjs/rum/instrumentation/{DdRumUserInteractionTracking.js → interactionTracking/DdRumUserInteractionTracking.js} +4 -4
  40. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -0
  41. package/lib/commonjs/rum/instrumentation/{EventsInterceptor.js → interactionTracking/EventsInterceptor.js} +0 -0
  42. package/lib/{module/rum/instrumentation → commonjs/rum/instrumentation/interactionTracking}/EventsInterceptor.js.map +0 -0
  43. package/lib/commonjs/rum/instrumentation/{NoOpEventsInterceptor.js → interactionTracking/NoOpEventsInterceptor.js} +0 -0
  44. package/lib/commonjs/rum/instrumentation/{NoOpEventsInterceptor.js.map → interactionTracking/NoOpEventsInterceptor.js.map} +0 -0
  45. package/lib/commonjs/rum/instrumentation/{ShallowObjectEqualityChecker.js → interactionTracking/ShallowObjectEqualityChecker.js} +0 -0
  46. package/lib/commonjs/rum/instrumentation/{ShallowObjectEqualityChecker.js.map → interactionTracking/ShallowObjectEqualityChecker.js.map} +0 -0
  47. package/lib/commonjs/rum/instrumentation/{getJsxRuntime.js → interactionTracking/getJsxRuntime.js} +0 -0
  48. package/lib/commonjs/rum/instrumentation/{getJsxRuntime.js.map → interactionTracking/getJsxRuntime.js.map} +0 -0
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +2 -1
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  53. package/lib/commonjs/rum/types.js +42 -0
  54. package/lib/commonjs/rum/types.js.map +1 -0
  55. package/lib/commonjs/sdk/AttributesSingleton/AttributesSingleton.js +45 -0
  56. package/lib/commonjs/sdk/AttributesSingleton/AttributesSingleton.js.map +1 -0
  57. package/lib/commonjs/sdk/AttributesSingleton/types.js +2 -0
  58. package/lib/commonjs/sdk/AttributesSingleton/types.js.map +1 -0
  59. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.js +4 -4
  60. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  61. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js +0 -0
  62. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js.map +0 -0
  63. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js +0 -0
  64. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js.map +0 -0
  65. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js +0 -0
  66. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js.map +0 -0
  67. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js +0 -0
  68. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js.map +0 -0
  69. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.js +4 -4
  70. package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -0
  71. package/lib/commonjs/sdk/EventMappers/EventMapper.js +85 -0
  72. package/lib/commonjs/sdk/EventMappers/EventMapper.js.map +1 -0
  73. package/lib/commonjs/sdk/EventMappers/utils/deepClone.js +98 -0
  74. package/lib/commonjs/sdk/EventMappers/utils/deepClone.js.map +1 -0
  75. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +43 -0
  76. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -0
  77. package/lib/commonjs/sdk/UserInfoSingleton/types.js +2 -0
  78. package/lib/commonjs/sdk/UserInfoSingleton/types.js.map +1 -0
  79. package/lib/commonjs/types.js +1 -26
  80. package/lib/commonjs/types.js.map +1 -1
  81. package/lib/commonjs/version.js +1 -1
  82. package/lib/commonjs/version.js.map +1 -1
  83. package/lib/module/DdSdkReactNative.js +33 -7
  84. package/lib/module/DdSdkReactNative.js.map +1 -1
  85. package/lib/module/DdSdkReactNativeConfiguration.js +42 -2
  86. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  87. package/lib/module/foundation.js +2 -124
  88. package/lib/module/foundation.js.map +1 -1
  89. package/lib/module/index.js +5 -3
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/logs/DdLogs.js +64 -0
  92. package/lib/module/logs/DdLogs.js.map +1 -0
  93. package/lib/module/logs/eventMapper.js +20 -0
  94. package/lib/module/logs/eventMapper.js.map +1 -0
  95. package/lib/module/logs/types.js +2 -0
  96. package/lib/module/logs/types.js.map +1 -0
  97. package/lib/module/nativeModulesTypes.js.map +1 -1
  98. package/lib/module/rum/DdRum.js +212 -0
  99. package/lib/module/rum/DdRum.js.map +1 -0
  100. package/lib/module/rum/eventMappers/actionEventMapper.js +26 -0
  101. package/lib/module/rum/eventMappers/actionEventMapper.js.map +1 -0
  102. package/lib/module/rum/eventMappers/errorEventMapper.js +22 -0
  103. package/lib/module/rum/eventMappers/errorEventMapper.js.map +1 -0
  104. package/lib/module/rum/eventMappers/resourceEventMapper.js +28 -0
  105. package/lib/module/rum/eventMappers/resourceEventMapper.js.map +1 -0
  106. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
  107. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  108. package/lib/module/rum/instrumentation/{DdEventsInterceptor.js → interactionTracking/DdEventsInterceptor.js} +6 -6
  109. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -0
  110. package/lib/module/rum/instrumentation/{DdRumUserInteractionTracking.js → interactionTracking/DdRumUserInteractionTracking.js} +4 -4
  111. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -0
  112. package/lib/module/rum/instrumentation/{EventsInterceptor.js → interactionTracking/EventsInterceptor.js} +0 -0
  113. package/lib/module/rum/instrumentation/interactionTracking/EventsInterceptor.js.map +1 -0
  114. package/lib/module/rum/instrumentation/{NoOpEventsInterceptor.js → interactionTracking/NoOpEventsInterceptor.js} +0 -0
  115. package/lib/module/rum/instrumentation/{NoOpEventsInterceptor.js.map → interactionTracking/NoOpEventsInterceptor.js.map} +0 -0
  116. package/lib/module/rum/instrumentation/{ShallowObjectEqualityChecker.js → interactionTracking/ShallowObjectEqualityChecker.js} +0 -0
  117. package/lib/module/rum/instrumentation/{ShallowObjectEqualityChecker.js.map → interactionTracking/ShallowObjectEqualityChecker.js.map} +0 -0
  118. package/lib/module/rum/instrumentation/{getJsxRuntime.js → interactionTracking/getJsxRuntime.js} +0 -0
  119. package/lib/module/rum/instrumentation/{getJsxRuntime.js.map → interactionTracking/getJsxRuntime.js.map} +0 -0
  120. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -2
  121. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  122. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +2 -1
  123. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  124. package/lib/module/rum/types.js +33 -0
  125. package/lib/module/rum/types.js.map +1 -0
  126. package/lib/module/sdk/AttributesSingleton/AttributesSingleton.js +36 -0
  127. package/lib/module/sdk/AttributesSingleton/AttributesSingleton.js.map +1 -0
  128. package/lib/module/sdk/AttributesSingleton/types.js +2 -0
  129. package/lib/module/sdk/AttributesSingleton/types.js.map +1 -0
  130. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.js +4 -4
  131. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  132. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js +0 -0
  133. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js.map +0 -0
  134. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js +0 -0
  135. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js.map +0 -0
  136. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js +0 -0
  137. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js.map +0 -0
  138. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js +0 -0
  139. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js.map +0 -0
  140. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.js +4 -4
  141. package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -0
  142. package/lib/module/sdk/EventMappers/EventMapper.js +72 -0
  143. package/lib/module/sdk/EventMappers/EventMapper.js.map +1 -0
  144. package/lib/module/sdk/EventMappers/utils/deepClone.js +89 -0
  145. package/lib/module/sdk/EventMappers/utils/deepClone.js.map +1 -0
  146. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +34 -0
  147. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -0
  148. package/lib/module/sdk/UserInfoSingleton/types.js +2 -0
  149. package/lib/module/sdk/UserInfoSingleton/types.js.map +1 -0
  150. package/lib/module/types.js +0 -23
  151. package/lib/module/types.js.map +1 -1
  152. package/lib/module/version.js +1 -1
  153. package/lib/module/version.js.map +1 -1
  154. package/lib/typescript/DdSdkReactNative.d.ts +7 -3
  155. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +22 -0
  156. package/lib/typescript/foundation.d.ts +2 -4
  157. package/lib/typescript/index.d.ts +5 -3
  158. package/lib/typescript/logs/DdLogs.d.ts +14 -0
  159. package/lib/typescript/logs/eventMapper.d.ts +11 -0
  160. package/lib/typescript/logs/types.d.ts +54 -0
  161. package/lib/typescript/nativeModulesTypes.d.ts +1 -1
  162. package/lib/typescript/rum/DdRum.d.ts +36 -0
  163. package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts +21 -0
  164. package/lib/typescript/rum/eventMappers/errorEventMapper.d.ts +21 -0
  165. package/lib/typescript/rum/eventMappers/resourceEventMapper.d.ts +25 -0
  166. package/lib/typescript/rum/instrumentation/{DdEventsInterceptor.d.ts → interactionTracking/DdEventsInterceptor.d.ts} +0 -0
  167. package/lib/typescript/rum/instrumentation/{DdRumUserInteractionTracking.d.ts → interactionTracking/DdRumUserInteractionTracking.d.ts} +0 -0
  168. package/lib/typescript/rum/instrumentation/{EventsInterceptor.d.ts → interactionTracking/EventsInterceptor.d.ts} +0 -0
  169. package/lib/typescript/rum/instrumentation/{NoOpEventsInterceptor.d.ts → interactionTracking/NoOpEventsInterceptor.d.ts} +0 -0
  170. package/lib/typescript/rum/instrumentation/{ShallowObjectEqualityChecker.d.ts → interactionTracking/ShallowObjectEqualityChecker.d.ts} +0 -0
  171. package/lib/typescript/rum/instrumentation/{getJsxRuntime.d.ts → interactionTracking/getJsxRuntime.d.ts} +0 -0
  172. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +3 -1
  173. package/lib/typescript/rum/types.d.ts +110 -0
  174. package/lib/typescript/sdk/AttributesSingleton/AttributesSingleton.d.ts +12 -0
  175. package/lib/typescript/sdk/AttributesSingleton/types.d.ts +3 -0
  176. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.d.ts +0 -0
  177. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.d.ts +0 -0
  178. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.d.ts +0 -0
  179. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.d.ts +0 -0
  180. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.d.ts +0 -0
  181. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.d.ts +2 -2
  182. package/lib/typescript/sdk/EventMappers/EventMapper.d.ts +24 -0
  183. package/lib/typescript/sdk/EventMappers/utils/deepClone.d.ts +10 -0
  184. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +12 -0
  185. package/lib/typescript/sdk/UserInfoSingleton/types.d.ts +6 -0
  186. package/lib/typescript/types.d.ts +0 -139
  187. package/lib/typescript/version.d.ts +1 -1
  188. package/package.json +3 -2
  189. package/scripts/replace-react-require.js +3 -2
  190. package/src/DdSdkReactNative.tsx +41 -7
  191. package/src/DdSdkReactNativeConfiguration.tsx +83 -3
  192. package/src/__tests__/DdSdkReactNative.test.tsx +244 -13
  193. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +22 -1
  194. package/src/__tests__/{longTasksUtils.ts → longTasksUtils.test.ts} +0 -0
  195. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +4 -3
  196. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +1 -1
  197. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +5 -3
  198. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +1 -1
  199. package/src/foundation.tsx +4 -114
  200. package/src/index.tsx +5 -3
  201. package/src/logs/DdLogs.ts +67 -0
  202. package/src/logs/__tests__/DdLogs.test.ts +51 -0
  203. package/src/logs/__tests__/eventMapper.test.ts +53 -0
  204. package/src/logs/eventMapper.ts +43 -0
  205. package/src/logs/types.ts +70 -0
  206. package/src/nativeModulesTypes.ts +1 -1
  207. package/src/rum/DdRum.ts +387 -0
  208. package/src/rum/__tests__/DdRum.test.ts +386 -0
  209. package/src/rum/eventMappers/actionEventMapper.ts +66 -0
  210. package/src/rum/eventMappers/errorEventMapper.ts +57 -0
  211. package/src/rum/eventMappers/resourceEventMapper.ts +74 -0
  212. package/src/rum/instrumentation/DdRumErrorTracking.tsx +2 -2
  213. package/src/rum/instrumentation/{DdEventsInterceptor.tsx → interactionTracking/DdEventsInterceptor.tsx} +14 -6
  214. package/src/rum/instrumentation/{DdRumUserInteractionTracking.tsx → interactionTracking/DdRumUserInteractionTracking.tsx} +4 -4
  215. package/src/rum/instrumentation/{EventsInterceptor.tsx → interactionTracking/EventsInterceptor.tsx} +0 -0
  216. package/src/rum/instrumentation/{NoOpEventsInterceptor.tsx → interactionTracking/NoOpEventsInterceptor.tsx} +0 -0
  217. package/src/rum/instrumentation/{ShallowObjectEqualityChecker.ts → interactionTracking/ShallowObjectEqualityChecker.ts} +0 -0
  218. package/src/rum/instrumentation/{getJsxRuntime.ts → interactionTracking/getJsxRuntime.ts} +0 -0
  219. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +1 -1
  220. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
  221. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +3 -2
  222. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +1 -1
  223. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +2 -1
  224. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +83 -39
  225. package/src/rum/types.ts +182 -0
  226. package/src/sdk/AttributesSingleton/AttributesSingleton.ts +34 -0
  227. package/src/sdk/AttributesSingleton/__tests__/AttributesSingleton.test.ts +44 -0
  228. package/src/sdk/AttributesSingleton/types.ts +9 -0
  229. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.ts +4 -4
  230. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.ts +0 -0
  231. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.ts +0 -0
  232. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.ts +0 -0
  233. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/__tests__/BoundedBuffer.test.ts +2 -2
  234. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/__tests__/BufferSingleton.test.ts +0 -0
  235. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.ts +0 -0
  236. package/src/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.tsx +5 -5
  237. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/__utils__/renderWithProvider.tsx +2 -2
  238. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/initialization.test.tsx +8 -6
  239. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/initializationModes.test.tsx +5 -5
  240. package/src/sdk/EventMappers/EventMapper.ts +94 -0
  241. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +50 -0
  242. package/src/sdk/EventMappers/utils/__tests__/deepClone.test.ts +79 -0
  243. package/src/sdk/EventMappers/utils/deepClone.ts +86 -0
  244. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +31 -0
  245. package/src/sdk/UserInfoSingleton/__tests__/UserInfoSingleton.test.ts +29 -0
  246. package/src/sdk/UserInfoSingleton/types.ts +12 -0
  247. package/src/types.tsx +0 -210
  248. package/src/version.ts +1 -1
  249. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +0 -1
  250. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +0 -1
  251. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +0 -1
  252. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +0 -1
  253. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +0 -1
  254. package/lib/module/DatadogProvider/DatadogProvider.js.map +0 -1
  255. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +0 -1
  256. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +0 -1
  257. package/src/__tests__/DdRumWrapper.test.tsx +0 -74
  258. package/src/__tests__/foundation.test.ts +0 -88
@@ -7,10 +7,10 @@
7
7
  import { fireEvent } from '@testing-library/react-native';
8
8
  import { NativeModules } from 'react-native';
9
9
 
10
- import { InitializationMode } from '../../DdSdkReactNativeConfiguration';
11
- import { DdSdkReactNative } from '../../DdSdkReactNative';
12
- import { TimeProvider } from '../../TimeProvider';
13
- import { DdRumUserInteractionTracking } from '../../rum/instrumentation/DdRumUserInteractionTracking';
10
+ import { InitializationMode } from '../../../DdSdkReactNativeConfiguration';
11
+ import { DdSdkReactNative } from '../../../DdSdkReactNative';
12
+ import { TimeProvider } from '../../../TimeProvider';
13
+ import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/interactionTracking/DdRumUserInteractionTracking';
14
14
  import { BufferSingleton } from '../Buffer/BufferSingleton';
15
15
  import {
16
16
  DatadogProvider,
@@ -24,7 +24,7 @@ import {
24
24
  renderWithProviderAndAnimation
25
25
  } from './__utils__/renderWithProvider';
26
26
 
27
- jest.mock('../../TimeProvider', () => {
27
+ jest.mock('../../../TimeProvider', () => {
28
28
  const now = jest.fn();
29
29
  return {
30
30
  TimeProvider: jest.fn().mockImplementation(() => {
@@ -0,0 +1,94 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { InternalLog } from '../../InternalLog';
8
+ import { SdkVerbosity } from '../../SdkVerbosity';
9
+ import { DdSdk } from '../../foundation';
10
+ import { AttributesSingleton } from '../AttributesSingleton/AttributesSingleton';
11
+ import type { Attributes } from '../AttributesSingleton/types';
12
+ import { UserInfoSingleton } from '../UserInfoSingleton/UserInfoSingleton';
13
+ import type { UserInfo } from '../UserInfoSingleton/types';
14
+
15
+ import { deepClone } from './utils/deepClone';
16
+
17
+ export type AdditionalEventDataForMapper = {
18
+ userInfo: UserInfo;
19
+ attributes: Attributes;
20
+ };
21
+
22
+ /**
23
+ * Generic class for applying event mappers.
24
+ *
25
+ * Calls params in this order: formatRawEventForMapper, eventMapper, formatMapperEventForNative.
26
+ *
27
+ * @param eventMapper the user-registered event mapper
28
+ * @param formatRawEventForMapper formatter that gets the raw event (from javascript call) and returns the input given to the mapper
29
+ * @param formatMapperEventForNative formatter that gets the ouput of the mapper, and returns the input given to the native SDKs
30
+ * @param formatRawEventForNative called when no event mapper is registered
31
+ */
32
+ export class EventMapper<RawEvent, MapperEvent, NativeEvent> {
33
+ private eventMapper?: (event: MapperEvent) => MapperEvent | null;
34
+ private formatRawEventForMapper: (
35
+ event: RawEvent,
36
+ additionalData: AdditionalEventDataForMapper
37
+ ) => MapperEvent;
38
+ private formatMapperEventForNative: (
39
+ event: MapperEvent,
40
+ originalEvent: MapperEvent
41
+ ) => NativeEvent;
42
+ private formatRawEventForNative: (event: RawEvent) => NativeEvent;
43
+
44
+ constructor(
45
+ eventMapper: ((event: MapperEvent) => MapperEvent | null) | undefined,
46
+ formatRawEventForMapper: (
47
+ event: RawEvent,
48
+ additionalData: AdditionalEventDataForMapper
49
+ ) => MapperEvent,
50
+ formatMapperEventForNative: (
51
+ event: MapperEvent,
52
+ originalEvent: MapperEvent
53
+ ) => NativeEvent,
54
+ formatRawEventForNative: (event: RawEvent) => NativeEvent
55
+ ) {
56
+ this.eventMapper = eventMapper;
57
+ this.formatRawEventForMapper = formatRawEventForMapper;
58
+ this.formatMapperEventForNative = formatMapperEventForNative;
59
+ this.formatRawEventForNative = formatRawEventForNative;
60
+ }
61
+
62
+ public applyEventMapper = (rawEvent: RawEvent): NativeEvent | null => {
63
+ if (!this.eventMapper) {
64
+ return this.formatRawEventForNative(rawEvent);
65
+ }
66
+
67
+ // formatting
68
+ const userInfo = UserInfoSingleton.getInstance().getUserInfo();
69
+ const attributes = AttributesSingleton.getInstance().getAttributes();
70
+ const initialEvent = this.formatRawEventForMapper(rawEvent, {
71
+ userInfo,
72
+ attributes
73
+ });
74
+
75
+ // mapper
76
+ const backupEvent = deepClone(initialEvent);
77
+ try {
78
+ const mappedEvent = this.eventMapper(initialEvent);
79
+ if (!mappedEvent) {
80
+ return null;
81
+ }
82
+ return this.formatMapperEventForNative(mappedEvent, backupEvent);
83
+ } catch (error) {
84
+ InternalLog.log(
85
+ `The event mapper crashed when mapping ${JSON.stringify(
86
+ backupEvent
87
+ )}: ${error}`,
88
+ SdkVerbosity.WARN
89
+ );
90
+ DdSdk.telemetryDebug('Error while running the event mapper');
91
+ return this.formatMapperEventForNative(backupEvent, backupEvent);
92
+ }
93
+ };
94
+ }
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { DdSdk } from '../../../foundation';
8
+ import { EventMapper } from '../EventMapper';
9
+
10
+ describe('EventMapper', () => {
11
+ it('returns the original log when the event log mapper crashes', () => {
12
+ const eventMapper = new EventMapper(
13
+ (event: object) => {
14
+ event['badData'] = 'bad data';
15
+ throw new Error('crashed');
16
+ },
17
+ (event: object) => event,
18
+ (event: object) => event,
19
+ (event: object) => event
20
+ );
21
+
22
+ expect(
23
+ eventMapper.applyEventMapper({
24
+ someData: 'some data'
25
+ })
26
+ ).toEqual({
27
+ someData: 'some data'
28
+ });
29
+ expect(DdSdk.telemetryDebug).toHaveBeenCalledWith(
30
+ 'Error while running the event mapper'
31
+ );
32
+ });
33
+
34
+ it('returns null when the mappers returns null', () => {
35
+ const eventMapper = new EventMapper(
36
+ (event: object) => {
37
+ return null;
38
+ },
39
+ (event: object) => event,
40
+ (event: object) => event,
41
+ (event: object) => event
42
+ );
43
+
44
+ expect(
45
+ eventMapper.applyEventMapper({
46
+ someData: 'some data'
47
+ })
48
+ ).toBeNull();
49
+ });
50
+ });
@@ -0,0 +1,79 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { deepClone } from '../deepClone';
8
+
9
+ describe('deepClone', () => {
10
+ it('clones a simple object with primitive types', () => {
11
+ const object = {
12
+ string: 'something',
13
+ number: 24,
14
+ boolean: true,
15
+ undefinedValue: undefined,
16
+ null: null
17
+ };
18
+
19
+ const clone = deepClone(object);
20
+ expect(clone).toEqual(object);
21
+
22
+ object['additionalProperty'] = 'value';
23
+ expect(clone).not.toEqual(object);
24
+ });
25
+ it('clones a nested object with nested arrays', () => {
26
+ const object = {
27
+ nestedObject: { string: 'something' },
28
+ nestedArray: [
29
+ {
30
+ nestedObject: { string: 'something' }
31
+ }
32
+ ]
33
+ };
34
+ const clone = deepClone(object);
35
+ expect(clone).toEqual(object);
36
+
37
+ object.nestedObject.string = 'something else';
38
+ expect(clone.nestedObject).not.toEqual(object.nestedObject);
39
+
40
+ object.nestedArray.push({
41
+ nestedObject: { string: 'something' }
42
+ });
43
+ expect(clone.nestedArray).not.toEqual(object.nestedArray);
44
+
45
+ object.nestedArray[0].nestedObject.string = 'something else';
46
+ expect(clone.nestedArray[0].nestedObject).not.toEqual(
47
+ object.nestedArray[0].nestedObject
48
+ );
49
+ });
50
+ it('clones an object with circular references', () => {
51
+ let error: Error | null = null;
52
+ const object = {
53
+ property: 'something'
54
+ };
55
+ object['nested'] = object;
56
+ try {
57
+ deepClone(object);
58
+ } catch (e) {
59
+ error = e;
60
+ }
61
+ expect(error).toBeNull();
62
+ });
63
+ it('clones an object with maps and sets', () => {
64
+ const someMap = new Map();
65
+ const someSet = new Set();
66
+ const object = {
67
+ someMap,
68
+ someSet
69
+ };
70
+ const clone = deepClone(object);
71
+ expect(clone).toEqual(object);
72
+
73
+ object.someMap.set('key', 'value');
74
+ expect(clone.someMap).not.toEqual(object.someMap);
75
+
76
+ object.someSet.add('value');
77
+ expect(clone.someSet).not.toEqual(object.someSet);
78
+ });
79
+ });
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ const isDate = (object: unknown): object is Date => {
8
+ const type = {}.toString.call(object).slice(8, -1);
9
+ return type === 'Date';
10
+ };
11
+
12
+ const isArray = (object: unknown): object is unknown[] => {
13
+ const type = {}.toString.call(object).slice(8, -1);
14
+ return type === 'Array';
15
+ };
16
+
17
+ const isObject = (object: unknown): object is Record<string, unknown> => {
18
+ const type = {}.toString.call(object).slice(8, -1);
19
+ return type === 'Object';
20
+ };
21
+
22
+ const isSet = (object: unknown): object is Set<unknown> => {
23
+ const type = {}.toString.call(object).slice(8, -1);
24
+ return type === 'Set';
25
+ };
26
+
27
+ const isMap = (object: unknown): object is Map<string, unknown> => {
28
+ const type = {}.toString.call(object).slice(8, -1);
29
+ return type === 'Map';
30
+ };
31
+
32
+ /**
33
+ * Simple deep clone inspired from https://github.com/angus-c/just/blob/master/packages/collection-clone/index.cjs
34
+ * Functions and RegExp will be returned as they are.
35
+ * Maps and Sets are cloned even though they won't be accepted by React Native, just in case they are mutated by the user to avoid side effects.
36
+ *
37
+ * We added support for circular references by limiting the number of depth levels to 8.
38
+ * @param originalObject
39
+ * @returns
40
+ */
41
+ export const deepClone = <T>(originalObject: T, depth: number = 0): T => {
42
+ if (isDate(originalObject)) {
43
+ return (new Date(originalObject.getTime()) as unknown) as T;
44
+ }
45
+ if (isSet(originalObject)) {
46
+ return (new Set(
47
+ [...originalObject].map(value => deepClone(value))
48
+ ) as unknown) as T;
49
+ }
50
+ if (isMap(originalObject)) {
51
+ return (new Map(
52
+ [...originalObject].map(kv => [deepClone(kv[0]), deepClone(kv[1])])
53
+ ) as unknown) as T;
54
+ }
55
+ if (isArray(originalObject)) {
56
+ if (depth >= 7) {
57
+ // Break the circular reference here
58
+ return originalObject;
59
+ }
60
+ const result: unknown[] = [];
61
+ // eslint-disable-next-line guard-for-in
62
+ for (const key in originalObject) {
63
+ // include prototype properties
64
+ result[key] = deepClone(originalObject[key], depth + 1);
65
+ }
66
+
67
+ return (result as unknown) as T;
68
+ }
69
+ if (isObject(originalObject)) {
70
+ if (depth >= 7) {
71
+ // Break the circular reference here
72
+ return originalObject;
73
+ }
74
+ const result: Record<string, unknown> = {};
75
+ // eslint-disable-next-line guard-for-in
76
+ for (const key in originalObject) {
77
+ // include prototype properties
78
+ result[key] = deepClone(originalObject[key], depth + 1);
79
+ }
80
+
81
+ return (result as unknown) as T;
82
+ }
83
+
84
+ // primitives and non-supported objects (e.g. functions) land here
85
+ return originalObject;
86
+ };
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import type { UserInfo } from './types';
8
+
9
+ class UserInfoProvider {
10
+ private userInfo: UserInfo = {};
11
+
12
+ setUserInfo = (userInfo: UserInfo) => {
13
+ this.userInfo = userInfo;
14
+ };
15
+
16
+ getUserInfo = (): UserInfo => {
17
+ return this.userInfo;
18
+ };
19
+ }
20
+
21
+ export class UserInfoSingleton {
22
+ private static userInfoProvider = new UserInfoProvider();
23
+
24
+ static getInstance = (): UserInfoProvider => {
25
+ return UserInfoSingleton.userInfoProvider;
26
+ };
27
+
28
+ static reset = () => {
29
+ UserInfoSingleton.userInfoProvider = new UserInfoProvider();
30
+ };
31
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ import { UserInfoSingleton } from '../UserInfoSingleton';
8
+
9
+ describe('UserInfoSingleton', () => {
10
+ it('sets, returns and resets the user info', () => {
11
+ UserInfoSingleton.getInstance().setUserInfo({
12
+ email: 'user@mail.com',
13
+ extraInfo: {
14
+ loggedIn: true
15
+ }
16
+ });
17
+
18
+ expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual({
19
+ email: 'user@mail.com',
20
+ extraInfo: {
21
+ loggedIn: true
22
+ }
23
+ });
24
+
25
+ UserInfoSingleton.reset();
26
+
27
+ expect(UserInfoSingleton.getInstance().getUserInfo()).toEqual({});
28
+ });
29
+ });
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
3
+ * This product includes software developed at Datadog (https://www.datadoghq.com/).
4
+ * Copyright 2016-Present Datadog, Inc.
5
+ */
6
+
7
+ export type UserInfo = {
8
+ readonly id?: string;
9
+ readonly name?: string;
10
+ readonly email?: string;
11
+ readonly [key: string]: unknown;
12
+ };
package/src/types.tsx CHANGED
@@ -59,39 +59,6 @@ export type DdSdkType = {
59
59
  setTrackingConsent(trackingConsent: string): Promise<void>;
60
60
  };
61
61
 
62
- /**
63
- * The entry point to use Datadog's Logs feature.
64
- */
65
- export type DdLogsType = {
66
- /**
67
- * Send a log with level debug.
68
- * @param message: The message to send.
69
- * @param context: The additional context to send.
70
- */
71
- debug(message: string, context?: object): Promise<void>;
72
-
73
- /**
74
- * Send a log with level info.
75
- * @param message: The message to send.
76
- * @param context: The additional context to send.
77
- */
78
- info(message: string, context?: object): Promise<void>;
79
-
80
- /**
81
- * Send a log with level warn.
82
- * @param message: The message to send.
83
- * @param context: The additional context to send.
84
- */
85
- warn(message: string, context?: object): Promise<void>;
86
-
87
- /**
88
- * Send a log with level error.
89
- * @param message: The message to send.
90
- * @param context: The additional context to send.
91
- */
92
- error(message: string, context?: object): Promise<void>;
93
- };
94
-
95
62
  /**
96
63
  * The entry point to use Datadog's Trace feature.
97
64
  */
@@ -120,180 +87,3 @@ export type DdTraceType = {
120
87
  timestampMs?: number
121
88
  ): Promise<void>;
122
89
  };
123
-
124
- /**
125
- * The entry point to use Datadog's RUM feature.
126
- */
127
- export type DdRumType = {
128
- /**
129
- * Start tracking a RUM View.
130
- * @param key: The view unique key identifier.
131
- * @param name: The view name.
132
- * @param context: The additional context to send.
133
- * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
134
- */
135
- startView(
136
- key: string,
137
- name: string,
138
- context?: object,
139
- timestampMs?: number
140
- ): Promise<void>;
141
-
142
- /**
143
- * Stop tracking a RUM View.
144
- * @param key: The view unique key identifier.
145
- * @param context: The additional context to send.
146
- * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
147
- */
148
- stopView(
149
- key: string,
150
- context?: object,
151
- timestampMs?: number
152
- ): Promise<void>;
153
-
154
- /**
155
- * Start tracking a RUM Action.
156
- * @param type: The action type (tap, scroll, swipe, back, custom).
157
- * @param name: The action name.
158
- * @param context: The additional context to send.
159
- * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
160
- */
161
- startAction(
162
- type: RumActionType,
163
- name: string,
164
- context?: object,
165
- timestampMs?: number
166
- ): Promise<void>;
167
-
168
- /**
169
- * Stop tracking the ongoing RUM Action.
170
- * @param type: The action type (tap, scroll, swipe, back, custom).
171
- * @param name: The action name.
172
- * @param context: The additional context to send.
173
- * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
174
- */
175
- stopAction(
176
- type: RumActionType,
177
- name: string,
178
- context?: object,
179
- timestampMs?: number
180
- ): Promise<void>;
181
-
182
- /**
183
- * Stop tracking the ongoing RUM Action.
184
- *
185
- * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.
186
- *
187
- * @deprecated add the `type` and `name` of the action as first two arguments.
188
- * @param context: The additional context to send.
189
- * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
190
- */
191
- stopAction(context?: object, timestampMs?: number): Promise<void>;
192
-
193
- /**
194
- * Add a RUM Action.
195
- * @param type: The action type (tap, scroll, swipe, back, custom).
196
- * @param name: The action name.
197
- * @param context: The additional context to send.
198
- * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
199
- */
200
- addAction(
201
- type: RumActionType,
202
- name: string,
203
- context?: object,
204
- timestampMs?: number
205
- ): Promise<void>;
206
-
207
- /**
208
- * Start tracking a RUM Resource.
209
- * @param key: The resource unique key identifier.
210
- * @param method: The resource method (GET, POST, …).
211
- * @param url: The resource url.
212
- * @param context: The additional context to send.
213
- * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
214
- */
215
- startResource(
216
- key: string,
217
- method: string,
218
- url: string,
219
- context?: object,
220
- timestampMs?: number
221
- ): Promise<void>;
222
-
223
- /**
224
- * Stop tracking a RUM Resource.
225
- * @param key: The resource unique key identifier.
226
- * @param statusCode: The resource status code.
227
- * @param kind: The resource's kind (xhr, document, image, css, font, …).
228
- * @param size: The resource size in bytes. If size is unknown, use -1.
229
- * @param context: The additional context to send.
230
- * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
231
- */
232
- stopResource(
233
- key: string,
234
- statusCode: number,
235
- kind: ResourceKind,
236
- size?: number,
237
- context?: object,
238
- timestampMs?: number
239
- ): Promise<void>;
240
-
241
- /**
242
- * Add a RUM Error.
243
- * @param message: The error message.
244
- * @param source: The error source (network, source, console, webview, custom).
245
- * @param stacktrace: The error stacktrace.
246
- * @param context: The additional context to send.
247
- * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
248
- */
249
- addError(
250
- message: string,
251
- source: ErrorSource,
252
- stacktrace: string,
253
- context?: object,
254
- timestampMs?: number
255
- ): Promise<void>;
256
-
257
- /**
258
- * Adds a specific timing in the active View. The timing duration will be computed as the difference between the time the View was started and the time this function was called.
259
- * @param name: The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK.
260
- */
261
- addTiming(name: string): Promise<void>;
262
- };
263
-
264
- /**
265
- * Describe the type of a RUM Action.
266
- */
267
- export enum RumActionType {
268
- /** User tapped on a widget. */
269
- TAP = 'TAP',
270
- /** User scrolled a view. */
271
- SCROLL = 'SCROLL',
272
- /** User swiped on a view. */
273
- SWIPE = 'SWIPE',
274
- /** User pressed hardware back button (Android only). */
275
- BACK = 'BACK',
276
- /** A custom action. */
277
- CUSTOM = 'CUSTOM'
278
- }
279
-
280
- export type ResourceKind =
281
- | 'image'
282
- | 'xhr'
283
- | 'beacon'
284
- | 'css'
285
- | 'document'
286
- | 'fetch'
287
- | 'font'
288
- | 'js'
289
- | 'media'
290
- | 'other'
291
- | 'native';
292
-
293
- export enum ErrorSource {
294
- NETWORK = 'NETWORK',
295
- SOURCE = 'SOURCE',
296
- CONSOLE = 'CONSOLE',
297
- WEBVIEW = 'WEBVIEW',
298
- CUSTOM = 'CUSTOM'
299
- }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '1.2.0';
2
+ export const version = '1.3.0';
@@ -1 +0,0 @@
1
- {"version":3,"sources":["BoundedBuffer.ts"],"names":["DEFAULT_BUFFER_SIZE","BoundedBuffer","DatadogBuffer","constructor","bufferSize","callback","buffer","length","push","_type","addTelemetryEvent","Promise","resolve","undefined","bufferId","generateRandomBufferId","returnedBufferId","idTable","error","console","warn","Math","random","withBufferId","bufferIndex","item","callbackId","InternalLog","log","SdkVerbosity","WARN","drainTelemetry","tries","hash","toString","slice","Error","message","stack","kind","telemetryBuffer","occurences","Object","values","forEach","DdSdk","telemetryError"],"mappings":";;;;;;;AAMA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,mBAAmB,GAAG,GAA5B;;AAqBO,MAAMC,aAAN,SAA4BC,4BAA5B,CAA0C;AAa7CC,EAAAA,WAAW,CAACC,UAAkB,GAAGJ,mBAAtB,EAA2C;AAClD;;AADkD;;AAAA,oCAXvB,EAWuB;;AAAA,qCAVG,EAUH;;AAAA,6CAFlD,EAEkD;;AAAA,yCAKvCK,QAAD,IAAmC;AAC7C,UAAI,KAAKC,MAAL,CAAYC,MAAZ,GAAqB,KAAKH,UAA9B,EAA0C;AACtC,aAAKE,MAAL,CAAYE,IAAZ,CAAiB;AAAEH,UAAAA,QAAF;AAAYI,UAAAA,KAAK,EAAE;AAAnB,SAAjB;AACH,OAFD,MAEO;AACH,aAAKC,iBAAL,CAAuB,iBAAvB,EAA0C,EAA1C,EAA8C,gBAA9C;AACH;;AAED,aAAO,IAAIC,OAAJ,CAAkBC,OAAO,IAAIA,OAAO,CAACC,SAAD,CAApC,CAAP;AACH,KAbqD;;AAAA,oDAe5BR,QAAD,IAAqC;AAC1D,UAAI;AACA,cAAMS,QAAQ,GAAG,KAAKC,sBAAL,EAAjB;;AACA,YAAI,KAAKT,MAAL,CAAYC,MAAZ,GAAqB,KAAKH,UAA9B,EAA0C;AACtC,eAAKE,MAAL,CAAYE,IAAZ,CAAiB;AACbH,YAAAA,QADa;AAEbW,YAAAA,gBAAgB,EAAEF,QAFL;AAGbL,YAAAA,KAAK,EAAE;AAHM,WAAjB;AAKA,eAAKQ,OAAL,CAAaH,QAAb,IAAyB,IAAzB;AACH,SAPD,MAOO;AACH,eAAKJ,iBAAL,CAAuB,iBAAvB,EAA0C,EAA1C,EAA8C,gBAA9C;AACH;;AAED,eAAO,IAAIC,OAAJ,CAAoBC,OAAO,IAAIA,OAAO,CAACE,QAAD,CAAtC,CAAP;AACH,OAdD,CAcE,OAAOI,KAAP,EAAc;AACZ,aAAKR,iBAAL,CACI,0CADJ,EAEI,oCAAmBQ,KAAnB,CAFJ,EAGI,yBAHJ,EADY,CAMZ;;AACAC,QAAAA,OAAO,CAACC,IAAR,CACK,6IAA4IC,IAAI,CAACC,MAAL,EAAc,EAD/J;AAIA,eAAO,IAAIX,OAAJ,CAAoBC,OAAO,IAAIA,OAAO,CAAC,EAAD,CAAtC,CAAP;AACH;AACJ,KA3CqD;;AAAA,+CA6ClC,CAChBP,QADgB,EAEhBS,QAFgB,KAGf;AACD,UAAI,KAAKG,OAAL,CAAaH,QAAb,MAA2BD,SAA/B,EAA0C;AACtC,aAAKP,MAAL,CAAYE,IAAZ,CAAiB;AACbH,UAAAA,QADa;AAEbkB,UAAAA,YAAY,EAAET,QAFD;AAGbL,UAAAA,KAAK,EAAE;AAHM,SAAjB;AAKH,OAND,MAMO;AACH,aAAKC,iBAAL,CAAuB,iBAAvB,EAA0C,EAA1C,EAA8C,gBAA9C;AACH;;AAED,aAAO,IAAIC,OAAJ,CAAkBC,OAAO,IAAIA,OAAO,CAACC,SAAD,CAApC,CAAP;AACH,KA5DqD;;AAAA,mCA8D9C,YAAY;AAChB,WACI,IAAIW,WAAW,GAAG,CADtB,EAEIA,WAAW,GAAG,KAAKlB,MAAL,CAAYC,MAF9B,EAGIiB,WAAW,EAHf,EAIE;AACE,YAAI;AACA,gBAAMC,IAAI,GAAG,KAAKnB,MAAL,CAAYkB,WAAZ,CAAb;;AACA,cAAIC,IAAI,CAAChB,KAAL,KAAe,cAAnB,EAAmC;AAC/B,gBAAI;AACA;AACA;AACA;AACA,oBAAMiB,UAAU,GAAG,MAAMD,IAAI,CAACpB,QAAL,EAAzB;AACA,mBAAKY,OAAL,CAAaQ,IAAI,CAACT,gBAAlB,IAAsCU,UAAtC;AACH,aAND,CAME,OAAOR,KAAP,EAAc;AACZS,uCAAYC,GAAZ,CACK,uDAAsDV,KAAM,EADjE,EAEIW,2BAAaC,IAFjB;AAIH;;AACD;AACH;;AAED,cAAIL,IAAI,CAAChB,KAAL,KAAe,SAAnB,EAA8B;AAC1B,kBAAMiB,UAAU,GAAG,KAAKT,OAAL,CAAaQ,IAAI,CAACF,YAAlB,CAAnB,CAD0B,CAE1B;;AACA,gBAAIG,UAAU,KAAK,IAAf,IAAuBA,UAAU,KAAKb,SAA1C,EAAqD;AACjDY,cAAAA,IAAI,CAACpB,QAAL,CAAcqB,UAAd;AACA,qBAAO,KAAKT,OAAL,CAAaQ,IAAI,CAACF,YAAlB,CAAP;AACH,aAHD,MAGO;AACHI,uCAAYC,GAAZ,CACK,2CACGF,UAAU,KAAK,IAAf,GACM,SADN,GAEM,eACT,EALL,EAMIG,2BAAaC,IANjB;AAQH;;AACD;AACH;;AAEDL,UAAAA,IAAI,CAACpB,QAAL;AACH,SAtCD,CAsCE,OAAOa,KAAP,EAAc;AACZS,mCAAYC,GAAZ,CACK,wCAAuCV,KAAM,EADlD,EAEIW,2BAAaC,IAFjB;AAIH;AACJ;;AAED,WAAKxB,MAAL,GAAc,EAAd;AAEA,WAAKyB,cAAL;AACH,KArHqD;;AAAA,oDAuHrB,MAAc;AAC3C,UAAIC,KAAK,GAAG,CAAZ;;AACA,aAAOA,KAAK,GAAG,EAAf,EAAmB;AACf,cAAMC,IAAI,GAAGZ,IAAI,CAACC,MAAL,GAAcY,QAAd,CAAuB,EAAvB,EAA2BC,KAA3B,CAAiC,CAAjC,CAAb;;AACA,YAAI,KAAKlB,OAAL,CAAagB,IAAb,MAAuBpB,SAA3B,EAAsC;AAClCmB,UAAAA,KAAK;AACR,SAFD,MAEO;AACH,iBAAOC,IAAP;AACH;AACJ;;AAED,YAAM,IAAIG,KAAJ,CAAU,qCAAV,CAAN;AACH,KAnIqD;;AAAA,+CAqI1B,CACxBC,OADwB,EAExBC,KAFwB,EAGxBC,IAHwB,KAIvB;AACD,UAAI,KAAKC,eAAL,CAAqBD,IAArB,CAAJ,EAAgC;AAC5B,aAAKC,eAAL,CAAqBD,IAArB,EAA2BE,UAA3B;AACH,OAFD,MAEO;AACH,aAAKD,eAAL,CAAqBD,IAArB,IAA6B;AACzBF,UAAAA,OADyB;AAEzBC,UAAAA,KAFyB;AAGzBC,UAAAA,IAHyB;AAIzBE,UAAAA,UAAU,EAAE;AAJa,SAA7B;AAMH;AACJ,KApJqD;;AAAA,4CAsJ7B,MAAM;AAC3BC,MAAAA,MAAM,CAACC,MAAP,CAAc,KAAKH,eAAnB,EAAoCI,OAApC,CACI,CAAC;AAAEP,QAAAA,OAAF;AAAWC,QAAAA,KAAX;AAAkBC,QAAAA,IAAlB;AAAwBE,QAAAA;AAAxB,OAAD,KAA0C;AACtCI,0BAAMC,cAAN,CACK,GAAET,OAAQ,aAAYI,UAAW,SADtC,EAEIH,KAFJ,EAGIC,IAHJ;AAKH,OAPL;AASH,KAhKqD;;AAElD,SAAKnC,UAAL,GAAkBA,UAAlB;AACH;;AAhB4C","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nimport { InternalLog } from '../../InternalLog';\nimport { SdkVerbosity } from '../../SdkVerbosity';\nimport { getErrorStackTrace } from '../../errorUtils';\nimport { DdSdk } from '../../foundation';\n\nimport { DatadogBuffer } from './DatadogBuffer';\n\nconst DEFAULT_BUFFER_SIZE = 100;\n\ntype VoidCallback = {\n callback: () => Promise<void>;\n _type: 'VOID';\n};\n\ntype CallbackReturningId = {\n callback: () => Promise<string>;\n returnedBufferId: string;\n _type: 'RETURNING_ID';\n};\n\ntype CallbackWithId = {\n callback: (id: string) => Promise<void>;\n withBufferId: string;\n _type: 'WITH_ID';\n};\n\ntype BufferItem = VoidCallback | CallbackReturningId | CallbackWithId;\n\nexport class BoundedBuffer extends DatadogBuffer {\n private bufferSize: number;\n private buffer: BufferItem[] = [];\n private idTable: { [bufferId: string]: string | null } = {};\n private telemetryBuffer: {\n [kind: string]: {\n message: string;\n stack: string;\n kind: string;\n occurences: number;\n };\n } = {};\n\n constructor(bufferSize: number = DEFAULT_BUFFER_SIZE) {\n super();\n this.bufferSize = bufferSize;\n }\n\n addCallback = (callback: () => Promise<void>) => {\n if (this.buffer.length < this.bufferSize) {\n this.buffer.push({ callback, _type: 'VOID' });\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<void>(resolve => resolve(undefined));\n };\n\n addCallbackReturningId = (callback: () => Promise<string>) => {\n try {\n const bufferId = this.generateRandomBufferId();\n if (this.buffer.length < this.bufferSize) {\n this.buffer.push({\n callback,\n returnedBufferId: bufferId,\n _type: 'RETURNING_ID'\n });\n this.idTable[bufferId] = null;\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<string>(resolve => resolve(bufferId));\n } catch (error) {\n this.addTelemetryEvent(\n 'Could not generate enough random numbers',\n getErrorStackTrace(error),\n 'RandomIdGenerationError'\n );\n // Not using InternalLog here as it is not yet instantiated\n console.warn(\n `[Datadog] Could not generate enough random numbers for RUM buffer. Please check that Math.random is not overwritten. Math.random returns: ${Math.random()}`\n );\n\n return new Promise<string>(resolve => resolve(''));\n }\n };\n\n addCallbackWithId = (\n callback: (id: string) => Promise<void>,\n bufferId: string\n ) => {\n if (this.idTable[bufferId] !== undefined) {\n this.buffer.push({\n callback,\n withBufferId: bufferId,\n _type: 'WITH_ID'\n });\n } else {\n this.addTelemetryEvent('Buffer overflow', '', 'BufferOverflow');\n }\n\n return new Promise<void>(resolve => resolve(undefined));\n };\n\n drain = async () => {\n for (\n let bufferIndex = 0;\n bufferIndex < this.buffer.length;\n bufferIndex++\n ) {\n try {\n const item = this.buffer[bufferIndex];\n if (item._type === 'RETURNING_ID') {\n try {\n // Here we want to await the callback result to make sure that it has registered the id returned\n // by the callback before executing the callback needing this id.\n // eslint-disable-next-line no-await-in-loop\n const callbackId = await item.callback();\n this.idTable[item.returnedBufferId] = callbackId;\n } catch (error) {\n InternalLog.log(\n `Error running a callback returning an id in Buffer: ${error}`,\n SdkVerbosity.WARN\n );\n }\n continue;\n }\n\n if (item._type === 'WITH_ID') {\n const callbackId = this.idTable[item.withBufferId];\n // callbackId can be `null` if the callback supposed to return the id errored. In this case, let's ignore the next callback.\n if (callbackId !== null && callbackId !== undefined) {\n item.callback(callbackId);\n delete this.idTable[item.withBufferId];\n } else {\n InternalLog.log(\n `1 event was not sent as callback id was ${\n callbackId === null\n ? 'not set'\n : 'already unset'\n }`,\n SdkVerbosity.WARN\n );\n }\n continue;\n }\n\n item.callback();\n } catch (error) {\n InternalLog.log(\n `Error while draining Datadog Buffer: ${error}`,\n SdkVerbosity.WARN\n );\n }\n }\n\n this.buffer = [];\n\n this.drainTelemetry();\n };\n\n private generateRandomBufferId = (): string => {\n let tries = 0;\n while (tries < 20) {\n const hash = Math.random().toString(36).slice(2);\n if (this.idTable[hash] !== undefined) {\n tries++;\n } else {\n return hash;\n }\n }\n\n throw new Error('Could not generate random Buffer id');\n };\n\n private addTelemetryEvent = (\n message: string,\n stack: string,\n kind: string\n ) => {\n if (this.telemetryBuffer[kind]) {\n this.telemetryBuffer[kind].occurences++;\n } else {\n this.telemetryBuffer[kind] = {\n message,\n stack,\n kind,\n occurences: 1\n };\n }\n };\n\n private drainTelemetry = () => {\n Object.values(this.telemetryBuffer).forEach(\n ({ message, stack, kind, occurences }) => {\n DdSdk.telemetryError(\n `${message} happened ${occurences} times.`,\n stack,\n kind\n );\n }\n );\n };\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["DatadogProvider.tsx"],"names":["isInitialized","isConfigurationPartial","configuration","DatadogProviderConfiguration","DdSdkReactNativeConfiguration","console","warn","initializeDatadog","onInitialization","DdSdkReactNative","_initializeFromDatadogProvider","error","InternalLog","log","SdkVerbosity","WARN","DatadogProvider","children","_enableFeaturesFromDatadogProvider","initialize","_initializeFromDatadogProviderWithConfigurationAsync","__internalResetIsInitializedForTesting"],"mappings":";;;;;;;AAKA;;AAGA;;AAQA;;AACA;;AACA;;;;AAlBA;AACA;AACA;AACA;AACA;AAgBA,IAAIA,aAAa,GAAG,KAApB;;AAwBA,MAAMC,sBAAsB,GACxBC,aAD2B,IAIyB;AACpD,MAAIA,aAAa,YAAYC,2DAA7B,EAA2D;AACvD,WAAO,KAAP;AACH;;AACD,MAAID,aAAa,YAAYE,4DAA7B,EAA4D;AACxD;AACAC,IAAAA,OAAO,CAACC,IAAR,CACI,iHADJ;AAGA,WAAO,KAAP;AACH;;AACD,SAAO,IAAP;AACH,CAhBD;;AAkBA,MAAMC,iBAAiB,GAAG,OACtBL,aADsB,EAEtBM,gBAFsB,KAGrB;AACD,QAAMC,mCAAiBC,8BAAjB,CAAgDR,aAAhD,CAAN;;AACA,MAAIM,gBAAJ,EAAsB;AAClB,QAAI;AACAA,MAAAA,gBAAgB;AACnB,KAFD,CAEE,OAAOG,KAAP,EAAc;AACZC,+BAAYC,GAAZ,CACK,2CAA0CF,KAAM,EADrD,EAEIG,2BAAaC,IAFjB;AAIH;AACJ;AACJ,CAfD;AAiBA;AACA;AACA;;;AACO,MAAMC,eAAmD,GAAG,CAAC;AAChEC,EAAAA,QADgE;AAEhEf,EAAAA,aAFgE;AAGhEM,EAAAA;AAHgE,CAAD,KAI7D;AACF,MAAI,CAACR,aAAL,EAAoB;AAChB;AACA;AACA;AACA;AACA,QAAIC,sBAAsB,CAACC,aAAD,CAA1B,EAA2C;AACvCO,yCAAiBS,kCAAjB,CAAoDhB,aAApD;;AACAc,MAAAA,eAAe,CAACR,gBAAhB,GAAmCA,gBAAnC;AACH,KAHD,MAGO;AACHD,MAAAA,iBAAiB,CAACL,aAAD,EAAgBM,gBAAhB,CAAjB;AACH;;AACDR,IAAAA,aAAa,GAAG,IAAhB;AACH;;AAED,sBAAO,4DAAGiB,QAAH,CAAP;AACH,CApBM;AAsBP;AACA;AACA;AACA;;;;;AACAD,eAAe,CAACG,UAAhB,GAA6B,MACzBjB,aADyB,IAExB;AACD,QAAMO,mCAAiBW,oDAAjB,CACFlB,aADE,CAAN;;AAGA,MAAIc,eAAe,CAACR,gBAApB,EAAsC;AAClCQ,IAAAA,eAAe,CAACR,gBAAhB;AACH;AACJ,CATD;;AAWO,MAAMa,sCAAsC,GAAG,MAAM;AACxDrB,EAAAA,aAAa,GAAG,KAAhB;AACH,CAFM","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\nimport React from 'react';\nimport type { PropsWithChildren } from 'react';\n\nimport {\n DatadogProviderConfiguration,\n DdSdkReactNativeConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport type {\n PartialInitializationConfiguration,\n AutoInstrumentationConfiguration\n} from '../DdSdkReactNativeConfiguration';\nimport { DdSdkReactNative } from '../DdSdkReactNative';\nimport { InternalLog } from '../InternalLog';\nimport { SdkVerbosity } from '../SdkVerbosity';\n\nlet isInitialized = false;\n\ntype Props = PropsWithChildren<{\n /**\n * If a `DatadogProviderConfiguration` instance is passed, the SDK will start tracking errors, resources and actions and sending events.\n *\n * If a `AutoInstrumentationConfiguration` object is passed, the SDK will start tracking errors, resources and actions. To start sending events, call `DatadogProvider.initialize`.\n */\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration;\n /**\n * Callback to be run once the SDK starts sending events.\n */\n onInitialization?: () => void;\n}>;\n\ntype StaticProperties = {\n initialize: (\n configuration: PartialInitializationConfiguration\n ) => Promise<void>;\n onInitialization?: () => void;\n};\n\nconst isConfigurationPartial = (\n configuration:\n | DatadogProviderConfiguration\n | AutoInstrumentationConfiguration\n): configuration is AutoInstrumentationConfiguration => {\n if (configuration instanceof DatadogProviderConfiguration) {\n return false;\n }\n if (configuration instanceof DdSdkReactNativeConfiguration) {\n // Not using InternalLog here as it is not yet instanciated\n console.warn(\n 'A DdSdkReactNativeConfiguration was passed to DatadogProvider. Please use DatadogProviderConfiguration instead.'\n );\n return false;\n }\n return true;\n};\n\nconst initializeDatadog = async (\n configuration: DatadogProviderConfiguration,\n onInitialization?: () => void\n) => {\n await DdSdkReactNative._initializeFromDatadogProvider(configuration);\n if (onInitialization) {\n try {\n onInitialization();\n } catch (error) {\n InternalLog.log(\n `Error running onInitialization callback ${error}`,\n SdkVerbosity.WARN\n );\n }\n }\n};\n\n/**\n * Set up the Datadog React Native SDK.\n */\nexport const DatadogProvider: React.FC<Props> & StaticProperties = ({\n children,\n configuration,\n onInitialization\n}) => {\n if (!isInitialized) {\n // Here we cannot use a useEffect hook since it would be called after\n // the first render. Thus, we wouldn't enable auto-instrumentation on\n // the elements rendered in this first render and what happens during\n // the first render.\n if (isConfigurationPartial(configuration)) {\n DdSdkReactNative._enableFeaturesFromDatadogProvider(configuration);\n DatadogProvider.onInitialization = onInitialization;\n } else {\n initializeDatadog(configuration, onInitialization);\n }\n isInitialized = true;\n }\n\n return <>{children}</>;\n};\n\n/**\n * Initialize the Datadog SDK to start sending RUM events, logs and traces,\n * then execute onInitialization callback if any was provided.\n */\nDatadogProvider.initialize = async (\n configuration: PartialInitializationConfiguration\n) => {\n await DdSdkReactNative._initializeFromDatadogProviderWithConfigurationAsync(\n configuration\n );\n if (DatadogProvider.onInitialization) {\n DatadogProvider.onInitialization();\n }\n};\n\nexport const __internalResetIsInitializedForTesting = () => {\n isInitialized = false;\n};\n"]}