@datadog/mobile-react-native 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +58 -64
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +31 -1
  4. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +242 -14
  5. package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +6 -0
  6. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +106 -0
  7. package/android/src/test/kotlin/com/datadog/tools/unit/forge/BaseConfigurator.kt +2 -0
  8. package/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +116 -0
  9. package/ios/Sources/Attributes.swift +14 -0
  10. package/ios/Sources/DdSdk.swift +18 -0
  11. package/lib/commonjs/DdSdkReactNative.js +40 -8
  12. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  13. package/lib/commonjs/DdSdkReactNativeConfiguration.js +42 -2
  14. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  15. package/lib/commonjs/foundation.js +2 -139
  16. package/lib/commonjs/foundation.js.map +1 -1
  17. package/lib/commonjs/index.js +18 -14
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/logs/DdLogs.js +71 -0
  20. package/lib/commonjs/logs/DdLogs.js.map +1 -0
  21. package/lib/commonjs/logs/eventMapper.js +39 -0
  22. package/lib/commonjs/logs/eventMapper.js.map +1 -0
  23. package/lib/commonjs/logs/types.js +2 -0
  24. package/lib/commonjs/{rum/instrumentation/EventsInterceptor.js.map → logs/types.js.map} +0 -0
  25. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  26. package/lib/commonjs/rum/DdRum.js +234 -0
  27. package/lib/commonjs/rum/DdRum.js.map +1 -0
  28. package/lib/commonjs/rum/eventMappers/actionEventMapper.js +36 -0
  29. package/lib/commonjs/rum/eventMappers/actionEventMapper.js.map +1 -0
  30. package/lib/commonjs/rum/eventMappers/errorEventMapper.js +32 -0
  31. package/lib/commonjs/rum/eventMappers/errorEventMapper.js.map +1 -0
  32. package/lib/commonjs/rum/eventMappers/resourceEventMapper.js +38 -0
  33. package/lib/commonjs/rum/eventMappers/resourceEventMapper.js.map +1 -0
  34. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +4 -4
  35. package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  36. package/lib/commonjs/rum/instrumentation/{DdEventsInterceptor.js → interactionTracking/DdEventsInterceptor.js} +6 -6
  37. package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -0
  38. package/lib/commonjs/rum/instrumentation/{DdRumUserInteractionTracking.js → interactionTracking/DdRumUserInteractionTracking.js} +13 -4
  39. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -0
  40. package/lib/commonjs/rum/instrumentation/{EventsInterceptor.js → interactionTracking/EventsInterceptor.js} +0 -0
  41. package/lib/{module/rum/instrumentation → commonjs/rum/instrumentation/interactionTracking}/EventsInterceptor.js.map +0 -0
  42. package/lib/commonjs/rum/instrumentation/{NoOpEventsInterceptor.js → interactionTracking/NoOpEventsInterceptor.js} +0 -0
  43. package/lib/commonjs/rum/instrumentation/{NoOpEventsInterceptor.js.map → interactionTracking/NoOpEventsInterceptor.js.map} +0 -0
  44. package/lib/commonjs/rum/instrumentation/{ShallowObjectEqualityChecker.js → interactionTracking/ShallowObjectEqualityChecker.js} +0 -0
  45. package/lib/commonjs/rum/instrumentation/{ShallowObjectEqualityChecker.js.map → interactionTracking/ShallowObjectEqualityChecker.js.map} +0 -0
  46. package/lib/commonjs/rum/instrumentation/{getJsxRuntime.js → interactionTracking/getJsxRuntime.js} +0 -0
  47. package/lib/commonjs/rum/instrumentation/{getJsxRuntime.js.map → interactionTracking/getJsxRuntime.js.map} +0 -0
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +2 -1
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  52. package/lib/commonjs/rum/types.js +42 -0
  53. package/lib/commonjs/rum/types.js.map +1 -0
  54. package/lib/commonjs/sdk/AttributesSingleton/AttributesSingleton.js +45 -0
  55. package/lib/commonjs/sdk/AttributesSingleton/AttributesSingleton.js.map +1 -0
  56. package/lib/commonjs/sdk/AttributesSingleton/types.js +2 -0
  57. package/lib/commonjs/sdk/AttributesSingleton/types.js.map +1 -0
  58. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.js +4 -4
  59. package/lib/commonjs/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  60. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js +0 -0
  61. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js.map +0 -0
  62. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js +0 -0
  63. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js.map +0 -0
  64. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js +0 -0
  65. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js.map +0 -0
  66. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js +0 -0
  67. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js.map +0 -0
  68. package/lib/commonjs/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.js +4 -4
  69. package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -0
  70. package/lib/commonjs/sdk/EventMappers/EventMapper.js +85 -0
  71. package/lib/commonjs/sdk/EventMappers/EventMapper.js.map +1 -0
  72. package/lib/commonjs/sdk/EventMappers/utils/deepClone.js +98 -0
  73. package/lib/commonjs/sdk/EventMappers/utils/deepClone.js.map +1 -0
  74. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js +43 -0
  75. package/lib/commonjs/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -0
  76. package/lib/commonjs/sdk/UserInfoSingleton/types.js +2 -0
  77. package/lib/commonjs/sdk/UserInfoSingleton/types.js.map +1 -0
  78. package/lib/commonjs/types.js +1 -26
  79. package/lib/commonjs/types.js.map +1 -1
  80. package/lib/commonjs/version.js +1 -1
  81. package/lib/commonjs/version.js.map +1 -1
  82. package/lib/module/DdSdkReactNative.js +33 -7
  83. package/lib/module/DdSdkReactNative.js.map +1 -1
  84. package/lib/module/DdSdkReactNativeConfiguration.js +42 -2
  85. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  86. package/lib/module/foundation.js +2 -124
  87. package/lib/module/foundation.js.map +1 -1
  88. package/lib/module/index.js +5 -3
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/logs/DdLogs.js +64 -0
  91. package/lib/module/logs/DdLogs.js.map +1 -0
  92. package/lib/module/logs/eventMapper.js +20 -0
  93. package/lib/module/logs/eventMapper.js.map +1 -0
  94. package/lib/module/logs/types.js +2 -0
  95. package/lib/module/logs/types.js.map +1 -0
  96. package/lib/module/nativeModulesTypes.js.map +1 -1
  97. package/lib/module/rum/DdRum.js +212 -0
  98. package/lib/module/rum/DdRum.js.map +1 -0
  99. package/lib/module/rum/eventMappers/actionEventMapper.js +26 -0
  100. package/lib/module/rum/eventMappers/actionEventMapper.js.map +1 -0
  101. package/lib/module/rum/eventMappers/errorEventMapper.js +22 -0
  102. package/lib/module/rum/eventMappers/errorEventMapper.js.map +1 -0
  103. package/lib/module/rum/eventMappers/resourceEventMapper.js +28 -0
  104. package/lib/module/rum/eventMappers/resourceEventMapper.js.map +1 -0
  105. package/lib/module/rum/instrumentation/DdRumErrorTracking.js +2 -2
  106. package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
  107. package/lib/module/rum/instrumentation/{DdEventsInterceptor.js → interactionTracking/DdEventsInterceptor.js} +6 -6
  108. package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -0
  109. package/lib/module/rum/instrumentation/{DdRumUserInteractionTracking.js → interactionTracking/DdRumUserInteractionTracking.js} +13 -4
  110. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -0
  111. package/lib/module/rum/instrumentation/{EventsInterceptor.js → interactionTracking/EventsInterceptor.js} +0 -0
  112. package/lib/module/rum/instrumentation/interactionTracking/EventsInterceptor.js.map +1 -0
  113. package/lib/module/rum/instrumentation/{NoOpEventsInterceptor.js → interactionTracking/NoOpEventsInterceptor.js} +0 -0
  114. package/lib/module/rum/instrumentation/{NoOpEventsInterceptor.js.map → interactionTracking/NoOpEventsInterceptor.js.map} +0 -0
  115. package/lib/module/rum/instrumentation/{ShallowObjectEqualityChecker.js → interactionTracking/ShallowObjectEqualityChecker.js} +0 -0
  116. package/lib/module/rum/instrumentation/{ShallowObjectEqualityChecker.js.map → interactionTracking/ShallowObjectEqualityChecker.js.map} +0 -0
  117. package/lib/module/rum/instrumentation/{getJsxRuntime.js → interactionTracking/getJsxRuntime.js} +0 -0
  118. package/lib/module/rum/instrumentation/{getJsxRuntime.js.map → interactionTracking/getJsxRuntime.js.map} +0 -0
  119. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +2 -2
  120. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  121. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +2 -1
  122. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  123. package/lib/module/rum/types.js +33 -0
  124. package/lib/module/rum/types.js.map +1 -0
  125. package/lib/module/sdk/AttributesSingleton/AttributesSingleton.js +36 -0
  126. package/lib/module/sdk/AttributesSingleton/AttributesSingleton.js.map +1 -0
  127. package/lib/module/sdk/AttributesSingleton/types.js +2 -0
  128. package/lib/module/sdk/AttributesSingleton/types.js.map +1 -0
  129. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.js +4 -4
  130. package/lib/module/sdk/DatadogProvider/Buffer/BoundedBuffer.js.map +1 -0
  131. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js +0 -0
  132. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.js.map +0 -0
  133. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js +0 -0
  134. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.js.map +0 -0
  135. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js +0 -0
  136. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.js.map +0 -0
  137. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js +0 -0
  138. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.js.map +0 -0
  139. package/lib/module/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.js +4 -4
  140. package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -0
  141. package/lib/module/sdk/EventMappers/EventMapper.js +72 -0
  142. package/lib/module/sdk/EventMappers/EventMapper.js.map +1 -0
  143. package/lib/module/sdk/EventMappers/utils/deepClone.js +89 -0
  144. package/lib/module/sdk/EventMappers/utils/deepClone.js.map +1 -0
  145. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js +34 -0
  146. package/lib/module/sdk/UserInfoSingleton/UserInfoSingleton.js.map +1 -0
  147. package/lib/module/sdk/UserInfoSingleton/types.js +2 -0
  148. package/lib/module/sdk/UserInfoSingleton/types.js.map +1 -0
  149. package/lib/module/types.js +0 -23
  150. package/lib/module/types.js.map +1 -1
  151. package/lib/module/version.js +1 -1
  152. package/lib/module/version.js.map +1 -1
  153. package/lib/typescript/DdSdkReactNative.d.ts +7 -3
  154. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +22 -0
  155. package/lib/typescript/foundation.d.ts +2 -4
  156. package/lib/typescript/index.d.ts +5 -3
  157. package/lib/typescript/logs/DdLogs.d.ts +14 -0
  158. package/lib/typescript/logs/eventMapper.d.ts +11 -0
  159. package/lib/typescript/logs/types.d.ts +54 -0
  160. package/lib/typescript/nativeModulesTypes.d.ts +1 -1
  161. package/lib/typescript/rum/DdRum.d.ts +36 -0
  162. package/lib/typescript/rum/eventMappers/actionEventMapper.d.ts +21 -0
  163. package/lib/typescript/rum/eventMappers/errorEventMapper.d.ts +21 -0
  164. package/lib/typescript/rum/eventMappers/resourceEventMapper.d.ts +24 -0
  165. package/lib/typescript/rum/instrumentation/{DdEventsInterceptor.d.ts → interactionTracking/DdEventsInterceptor.d.ts} +0 -0
  166. package/lib/typescript/rum/instrumentation/{DdRumUserInteractionTracking.d.ts → interactionTracking/DdRumUserInteractionTracking.d.ts} +1 -0
  167. package/lib/typescript/rum/instrumentation/{EventsInterceptor.d.ts → interactionTracking/EventsInterceptor.d.ts} +0 -0
  168. package/lib/typescript/rum/instrumentation/{NoOpEventsInterceptor.d.ts → interactionTracking/NoOpEventsInterceptor.d.ts} +0 -0
  169. package/lib/typescript/rum/instrumentation/{ShallowObjectEqualityChecker.d.ts → interactionTracking/ShallowObjectEqualityChecker.d.ts} +0 -0
  170. package/lib/typescript/rum/instrumentation/{getJsxRuntime.d.ts → interactionTracking/getJsxRuntime.d.ts} +0 -0
  171. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +2 -1
  172. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -1
  173. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +0 -1
  174. package/lib/typescript/rum/types.d.ts +110 -0
  175. package/lib/typescript/sdk/AttributesSingleton/AttributesSingleton.d.ts +12 -0
  176. package/lib/typescript/sdk/AttributesSingleton/types.d.ts +3 -0
  177. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.d.ts +0 -0
  178. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.d.ts +0 -0
  179. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.d.ts +0 -0
  180. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.d.ts +0 -0
  181. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.d.ts +0 -0
  182. package/lib/typescript/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.d.ts +2 -2
  183. package/lib/typescript/sdk/EventMappers/EventMapper.d.ts +24 -0
  184. package/lib/typescript/sdk/EventMappers/utils/deepClone.d.ts +10 -0
  185. package/lib/typescript/sdk/UserInfoSingleton/UserInfoSingleton.d.ts +12 -0
  186. package/lib/typescript/sdk/UserInfoSingleton/types.d.ts +6 -0
  187. package/lib/typescript/types.d.ts +0 -139
  188. package/lib/typescript/version.d.ts +1 -1
  189. package/package.json +2 -2
  190. package/scripts/replace-react-require.js +3 -2
  191. package/src/DdSdkReactNative.tsx +41 -7
  192. package/src/DdSdkReactNativeConfiguration.tsx +83 -3
  193. package/src/__tests__/DdSdkReactNative.test.tsx +244 -13
  194. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +29 -7
  195. package/src/__tests__/{longTasksUtils.ts → longTasksUtils.test.ts} +0 -0
  196. package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +4 -3
  197. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +3 -2
  198. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +135 -117
  199. package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +1 -1
  200. package/src/foundation.tsx +4 -114
  201. package/src/index.tsx +5 -3
  202. package/src/logs/DdLogs.ts +67 -0
  203. package/src/logs/__tests__/DdLogs.test.ts +51 -0
  204. package/src/logs/__tests__/eventMapper.test.ts +53 -0
  205. package/src/logs/eventMapper.ts +43 -0
  206. package/src/logs/types.ts +70 -0
  207. package/src/nativeModulesTypes.ts +1 -1
  208. package/src/rum/DdRum.ts +387 -0
  209. package/src/rum/__tests__/DdRum.test.ts +386 -0
  210. package/src/rum/eventMappers/actionEventMapper.ts +66 -0
  211. package/src/rum/eventMappers/errorEventMapper.ts +57 -0
  212. package/src/rum/eventMappers/resourceEventMapper.ts +74 -0
  213. package/src/rum/instrumentation/DdRumErrorTracking.tsx +2 -2
  214. package/src/rum/instrumentation/{DdEventsInterceptor.tsx → interactionTracking/DdEventsInterceptor.tsx} +14 -6
  215. package/src/rum/instrumentation/{DdRumUserInteractionTracking.tsx → interactionTracking/DdRumUserInteractionTracking.tsx} +12 -4
  216. package/src/rum/instrumentation/{EventsInterceptor.tsx → interactionTracking/EventsInterceptor.tsx} +0 -0
  217. package/src/rum/instrumentation/{NoOpEventsInterceptor.tsx → interactionTracking/NoOpEventsInterceptor.tsx} +0 -0
  218. package/src/rum/instrumentation/{ShallowObjectEqualityChecker.ts → interactionTracking/ShallowObjectEqualityChecker.ts} +0 -0
  219. package/src/rum/instrumentation/{getJsxRuntime.ts → interactionTracking/getJsxRuntime.ts} +0 -0
  220. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +3 -2
  221. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.ts +2 -1
  222. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +3 -2
  223. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +3 -2
  224. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +2 -1
  225. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +89 -40
  226. package/src/rum/types.ts +182 -0
  227. package/src/sdk/AttributesSingleton/AttributesSingleton.ts +34 -0
  228. package/src/sdk/AttributesSingleton/__tests__/AttributesSingleton.test.ts +44 -0
  229. package/src/sdk/AttributesSingleton/types.ts +9 -0
  230. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BoundedBuffer.ts +4 -4
  231. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/BufferSingleton.ts +0 -0
  232. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/DatadogBuffer.ts +0 -0
  233. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/PassThroughBuffer.ts +0 -0
  234. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/__tests__/BoundedBuffer.test.ts +2 -2
  235. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/__tests__/BufferSingleton.test.ts +2 -1
  236. package/src/{DatadogProvider → sdk/DatadogProvider}/Buffer/bufferNativeCall.ts +0 -0
  237. package/src/{DatadogProvider → sdk/DatadogProvider}/DatadogProvider.tsx +5 -5
  238. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/__utils__/renderWithProvider.tsx +2 -2
  239. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/initialization.test.tsx +13 -10
  240. package/src/{DatadogProvider → sdk/DatadogProvider}/__tests__/initializationModes.test.tsx +10 -6
  241. package/src/sdk/EventMappers/EventMapper.ts +94 -0
  242. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +50 -0
  243. package/src/sdk/EventMappers/utils/__tests__/deepClone.test.ts +79 -0
  244. package/src/sdk/EventMappers/utils/deepClone.ts +86 -0
  245. package/src/sdk/UserInfoSingleton/UserInfoSingleton.ts +31 -0
  246. package/src/sdk/UserInfoSingleton/__tests__/UserInfoSingleton.test.ts +29 -0
  247. package/src/sdk/UserInfoSingleton/types.ts +12 -0
  248. package/src/types.tsx +0 -210
  249. package/src/version.ts +1 -1
  250. package/lib/commonjs/DatadogProvider/Buffer/BoundedBuffer.js.map +0 -1
  251. package/lib/commonjs/DatadogProvider/DatadogProvider.js.map +0 -1
  252. package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +0 -1
  253. package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +0 -1
  254. package/lib/module/DatadogProvider/Buffer/BoundedBuffer.js.map +0 -1
  255. package/lib/module/DatadogProvider/DatadogProvider.js.map +0 -1
  256. package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +0 -1
  257. package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +0 -1
  258. package/src/__tests__/DdRumWrapper.test.tsx +0 -74
  259. package/src/__tests__/foundation.test.ts +0 -88
@@ -6,14 +6,15 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
- import { BufferSingleton } from '../../../../DatadogProvider/Buffer/BufferSingleton';
9
+ import { BufferSingleton } from '../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
10
  import { DdRumResourceTracking } from '../DdRumResourceTracking';
11
11
 
12
12
  import { XMLHttpRequestMock } from './__utils__/XMLHttpRequestMock';
13
13
 
14
14
  const DdRum = NativeModules.DdRum;
15
15
 
16
- const flushPromises = () => new Promise(setImmediate);
16
+ const flushPromises = () =>
17
+ new Promise(jest.requireActual('timers').setImmediate);
17
18
 
18
19
  beforeEach(() => {
19
20
  DdRum.startResource.mockClear();
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import type { ResourceKind } from '../../../../../../src/types';
7
+ import type { ResourceKind } from '../../../../types';
8
8
  import type { DdRumResourceTracingAttributes } from '../distributedTracing';
9
9
 
10
10
  export interface RUMResource {
@@ -24,4 +24,5 @@ export interface RUMResource {
24
24
  stopTime: number;
25
25
  responseStartTime?: number;
26
26
  };
27
+ resourceContext?: XMLHttpRequest;
27
28
  }
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { DdRum } from '../../../../../foundation';
7
+ import { DdRum } from '../../../../DdRum';
8
8
  import type { RUMResource } from '../../domain/interfaces/RumResource';
9
9
 
10
10
  import { createTimings } from './resourceTiming';
@@ -74,6 +74,7 @@ const reportResource = async (resource: RUMResource) => {
74
74
  resource.request.kind,
75
75
  resource.response.size,
76
76
  formatResourceStopContext(resource.timings),
77
- resource.timings.stopTime
77
+ resource.timings.stopTime,
78
+ resource.resourceContext
78
79
  );
79
80
  };
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { NativeModules } from 'react-native';
8
8
 
9
- import { BufferSingleton } from '../../../../../../DatadogProvider/Buffer/BufferSingleton';
9
+ import { BufferSingleton } from '../../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
10
10
  import type { RUMResource } from '../../../domain/interfaces/RumResource';
11
11
  import { ResourceReporter } from '../ResourceReporter';
12
12
 
@@ -14,7 +14,8 @@ import { ResourceMockFactory } from './__utils__/ResourceMockFactory';
14
14
 
15
15
  const resourceMockFactory = new ResourceMockFactory();
16
16
  const DdRum = NativeModules.DdRum;
17
- const flushPromises = () => new Promise(setImmediate);
17
+ const flushPromises = () =>
18
+ new Promise(jest.requireActual('timers').setImmediate);
18
19
 
19
20
  beforeEach(() => {
20
21
  DdRum.startResource.mockClear();
@@ -192,6 +192,7 @@ const reportXhr = async (
192
192
  responseStartTime: context.timer.hasTickFor(RESPONSE_START_LABEL)
193
193
  ? context.timer.timeAt(RESPONSE_START_LABEL)
194
194
  : undefined
195
- }
195
+ },
196
+ resourceContext: xhrProxy
196
197
  });
197
198
  };
@@ -6,9 +6,10 @@
6
6
 
7
7
  import { Platform, NativeModules } from 'react-native';
8
8
 
9
- import { BufferSingleton } from '../../../../../DatadogProvider/Buffer/BufferSingleton';
10
9
  import { InternalLog } from '../../../../../InternalLog';
11
10
  import { SdkVerbosity } from '../../../../../SdkVerbosity';
11
+ import { BufferSingleton } from '../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
12
+ import { DdRum } from '../../../../DdRum';
12
13
  import { XMLHttpRequestMock } from '../../__tests__/__utils__/XMLHttpRequestMock';
13
14
  import { firstPartyHostsRegexBuilder } from '../../domain/firstPartyHosts';
14
15
  import { ResourceReporter } from '../DatadogRumResource/ResourceReporter';
@@ -32,18 +33,19 @@ const mockedInternalLog = (InternalLog as unknown) as {
32
33
  };
33
34
  jest.spyOn(global.Math, 'random');
34
35
 
35
- const DdRum = NativeModules.DdRum;
36
+ const DdNativeRum = NativeModules.DdRum;
36
37
 
37
38
  function randomInt(max: number): number {
38
39
  return Math.floor(Math.random() * max);
39
40
  }
40
41
 
41
- const flushPromises = () => new Promise(setImmediate);
42
+ const flushPromises = () =>
43
+ new Promise(jest.requireActual('timers').setImmediate);
42
44
  let xhrProxy;
43
45
 
44
46
  beforeEach(() => {
45
- DdRum.startResource.mockClear();
46
- DdRum.stopResource.mockClear();
47
+ DdNativeRum.startResource.mockClear();
48
+ DdNativeRum.stopResource.mockClear();
47
49
  BufferSingleton.onInitialization();
48
50
 
49
51
  xhrProxy = new XHRProxy({
@@ -66,6 +68,7 @@ afterEach(() => {
66
68
  xhrProxy.onTrackingStop();
67
69
  (Date.now as jest.MockedFunction<typeof Date.now>).mockClear();
68
70
  jest.spyOn(global.Math, 'random').mockRestore();
71
+ DdRum.unregisterResourceEventMapper();
69
72
  });
70
73
 
71
74
  describe('XHRPr', () => {
@@ -88,17 +91,19 @@ describe('XHRPr', () => {
88
91
  await flushPromises();
89
92
 
90
93
  // THEN
91
- expect(DdRum.startResource.mock.calls.length).toBe(1);
92
- expect(DdRum.startResource.mock.calls[0][1]).toBe(method);
93
- expect(DdRum.startResource.mock.calls[0][2]).toBe(url);
94
+ expect(DdNativeRum.startResource.mock.calls.length).toBe(1);
95
+ expect(DdNativeRum.startResource.mock.calls[0][1]).toBe(method);
96
+ expect(DdNativeRum.startResource.mock.calls[0][2]).toBe(url);
94
97
 
95
- expect(DdRum.stopResource.mock.calls.length).toBe(1);
96
- expect(DdRum.stopResource.mock.calls[0][0]).toBe(
97
- DdRum.startResource.mock.calls[0][0]
98
+ expect(DdNativeRum.stopResource.mock.calls.length).toBe(1);
99
+ expect(DdNativeRum.stopResource.mock.calls[0][0]).toBe(
100
+ DdNativeRum.startResource.mock.calls[0][0]
101
+ );
102
+ expect(DdNativeRum.stopResource.mock.calls[0][1]).toBe(200);
103
+ expect(DdNativeRum.stopResource.mock.calls[0][2]).toBe('xhr');
104
+ expect(DdNativeRum.stopResource.mock.calls[0][3]).toBeGreaterThan(
105
+ 0
98
106
  );
99
- expect(DdRum.stopResource.mock.calls[0][1]).toBe(200);
100
- expect(DdRum.stopResource.mock.calls[0][2]).toBe('xhr');
101
- expect(DdRum.stopResource.mock.calls[0][3]).toBeGreaterThan(0);
102
107
 
103
108
  expect(xhr.originalOpenCalled).toBe(true);
104
109
  expect(xhr.originalSendCalled).toBe(true);
@@ -123,17 +128,19 @@ describe('XHRPr', () => {
123
128
  await flushPromises();
124
129
 
125
130
  // THEN
126
- expect(DdRum.startResource.mock.calls.length).toBe(1);
127
- expect(DdRum.startResource.mock.calls[0][1]).toBe(method);
128
- expect(DdRum.startResource.mock.calls[0][2]).toBe(url);
131
+ expect(DdNativeRum.startResource.mock.calls.length).toBe(1);
132
+ expect(DdNativeRum.startResource.mock.calls[0][1]).toBe(method);
133
+ expect(DdNativeRum.startResource.mock.calls[0][2]).toBe(url);
129
134
 
130
- expect(DdRum.stopResource.mock.calls.length).toBe(1);
131
- expect(DdRum.stopResource.mock.calls[0][0]).toBe(
132
- DdRum.startResource.mock.calls[0][0]
135
+ expect(DdNativeRum.stopResource.mock.calls.length).toBe(1);
136
+ expect(DdNativeRum.stopResource.mock.calls[0][0]).toBe(
137
+ DdNativeRum.startResource.mock.calls[0][0]
138
+ );
139
+ expect(DdNativeRum.stopResource.mock.calls[0][1]).toBe(500);
140
+ expect(DdNativeRum.stopResource.mock.calls[0][2]).toBe('xhr');
141
+ expect(DdNativeRum.stopResource.mock.calls[0][3]).toBeGreaterThan(
142
+ 0
133
143
  );
134
- expect(DdRum.stopResource.mock.calls[0][1]).toBe(500);
135
- expect(DdRum.stopResource.mock.calls[0][2]).toBe('xhr');
136
- expect(DdRum.stopResource.mock.calls[0][3]).toBeGreaterThan(0);
137
144
 
138
145
  expect(xhr.originalOpenCalled).toBe(true);
139
146
  expect(xhr.originalSendCalled).toBe(true);
@@ -158,17 +165,17 @@ describe('XHRPr', () => {
158
165
  await flushPromises();
159
166
 
160
167
  // THEN
161
- expect(DdRum.startResource.mock.calls.length).toBe(1);
162
- expect(DdRum.startResource.mock.calls[0][1]).toBe(method);
163
- expect(DdRum.startResource.mock.calls[0][2]).toBe(url);
168
+ expect(DdNativeRum.startResource.mock.calls.length).toBe(1);
169
+ expect(DdNativeRum.startResource.mock.calls[0][1]).toBe(method);
170
+ expect(DdNativeRum.startResource.mock.calls[0][2]).toBe(url);
164
171
 
165
- expect(DdRum.stopResource.mock.calls.length).toBe(1);
166
- expect(DdRum.stopResource.mock.calls[0][0]).toBe(
167
- DdRum.startResource.mock.calls[0][0]
172
+ expect(DdNativeRum.stopResource.mock.calls.length).toBe(1);
173
+ expect(DdNativeRum.stopResource.mock.calls[0][0]).toBe(
174
+ DdNativeRum.startResource.mock.calls[0][0]
168
175
  );
169
- expect(DdRum.stopResource.mock.calls[0][1]).toBe(0);
170
- expect(DdRum.stopResource.mock.calls[0][2]).toBe('xhr');
171
- expect(DdRum.stopResource.mock.calls[0][3]).toBe(-1);
176
+ expect(DdNativeRum.stopResource.mock.calls[0][1]).toBe(0);
177
+ expect(DdNativeRum.stopResource.mock.calls[0][2]).toBe('xhr');
178
+ expect(DdNativeRum.stopResource.mock.calls[0][3]).toBe(-1);
172
179
 
173
180
  expect(xhr.originalOpenCalled).toBe(true);
174
181
  expect(xhr.originalSendCalled).toBe(true);
@@ -439,17 +446,18 @@ describe('XHRPr', () => {
439
446
  await flushPromises();
440
447
 
441
448
  // THEN
442
- const spanId = DdRum.startResource.mock.calls[0][3]['_dd.span_id'];
449
+ const spanId =
450
+ DdNativeRum.startResource.mock.calls[0][3]['_dd.span_id'];
443
451
  expect(spanId).toBeDefined();
444
452
  expect(spanId).toMatch(/[1-9].+/);
445
453
 
446
454
  const traceId =
447
- DdRum.startResource.mock.calls[0][3]['_dd.trace_id'];
455
+ DdNativeRum.startResource.mock.calls[0][3]['_dd.trace_id'];
448
456
  expect(traceId).toBeDefined();
449
457
  expect(traceId).toMatch(/[1-9].+/);
450
458
 
451
459
  const rulePsr =
452
- DdRum.startResource.mock.calls[0][3]['_dd.rule_psr'];
460
+ DdNativeRum.startResource.mock.calls[0][3]['_dd.rule_psr'];
453
461
  expect(rulePsr).toBe(1);
454
462
 
455
463
  // Check traceId and spanId are different
@@ -477,7 +485,7 @@ describe('XHRPr', () => {
477
485
  await flushPromises();
478
486
 
479
487
  // THEN
480
- expect(DdRum.startResource).not.toHaveBeenCalledWith(
488
+ expect(DdNativeRum.startResource).not.toHaveBeenCalledWith(
481
489
  expect.anything(),
482
490
  expect.anything(),
483
491
  expect.anything(),
@@ -488,7 +496,9 @@ describe('XHRPr', () => {
488
496
  }),
489
497
  expect.anything()
490
498
  );
491
- expect(DdRum.startResource.mock.calls[0][3]).toStrictEqual({});
499
+ expect(DdNativeRum.startResource.mock.calls[0][3]).toStrictEqual(
500
+ {}
501
+ );
492
502
  });
493
503
  });
494
504
 
@@ -510,13 +520,17 @@ describe('XHRPr', () => {
510
520
  const xhr = new XMLHttpRequestMock();
511
521
  xhr.open(method, url);
512
522
  xhr.send();
523
+ jest.advanceTimersByTime(50);
513
524
  xhr.notifyResponseArrived();
525
+ jest.advanceTimersByTime(50);
514
526
  xhr.complete(200, 'ok');
515
527
  await flushPromises();
516
528
 
517
529
  // THEN
518
530
  const timings =
519
- DdRum.stopResource.mock.calls[0][4]['_dd.resource_timings'];
531
+ DdNativeRum.stopResource.mock.calls[0][4][
532
+ '_dd.resource_timings'
533
+ ];
520
534
 
521
535
  if (Platform.OS === 'ios') {
522
536
  expect(timings['firstByte']['startTime']).toBeGreaterThan(0);
@@ -553,14 +567,18 @@ describe('XHRPr', () => {
553
567
  const xhr = new XMLHttpRequestMock();
554
568
  xhr.open(method, url);
555
569
  xhr.send();
570
+ jest.advanceTimersByTime(50);
556
571
  xhr.notifyResponseArrived();
572
+ jest.advanceTimersByTime(50);
557
573
  xhr.abort();
558
574
  xhr.complete(0, undefined);
559
575
  await flushPromises();
560
576
 
561
577
  // THEN
562
578
  const timings =
563
- DdRum.stopResource.mock.calls[0][4]['_dd.resource_timings'];
579
+ DdNativeRum.stopResource.mock.calls[0][4][
580
+ '_dd.resource_timings'
581
+ ];
564
582
 
565
583
  if (Platform.OS === 'ios') {
566
584
  expect(timings['firstByte']['startTime']).toBeGreaterThan(0);
@@ -600,10 +618,41 @@ describe('XHRPr', () => {
600
618
  await flushPromises();
601
619
 
602
620
  // THEN
603
- const attributes = DdRum.stopResource.mock.calls[0][4];
621
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
604
622
 
605
623
  expect(attributes['_dd.resource_timings']).toBeNull();
606
624
  });
625
+
626
+ it('attaches the XMLHttpRequest object containing response to the event mapper', async () => {
627
+ // GIVEN
628
+ const method = 'GET';
629
+ const url = 'https://api.example.com/v2/user';
630
+ xhrProxy.onTrackingStart({
631
+ tracingSamplingRate: 100,
632
+ firstPartyHostsRegex: firstPartyHostsRegexBuilder([])
633
+ });
634
+ DdRum.registerResourceEventMapper(event => {
635
+ event.context['body'] = JSON.parse(
636
+ event.resourceContext?.response
637
+ );
638
+ return event;
639
+ });
640
+
641
+ // WHEN
642
+ const xhr = new XMLHttpRequestMock();
643
+ xhr.open(method, url);
644
+ xhr.send();
645
+ xhr.abort();
646
+ xhr.complete(200, JSON.stringify({ body: 'content' }));
647
+ await flushPromises();
648
+
649
+ // THEN
650
+ const attributes = DdNativeRum.stopResource.mock.calls[0][4];
651
+
652
+ expect(attributes['body']).toEqual({
653
+ body: 'content'
654
+ });
655
+ });
607
656
  });
608
657
 
609
658
  describe.each(
@@ -0,0 +1,182 @@
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
+ /**
8
+ * The entry point to use Datadog's RUM feature.
9
+ */
10
+ export type DdRumType = {
11
+ /**
12
+ * Start tracking a RUM View.
13
+ * @param key: The view unique key identifier.
14
+ * @param name: The view name.
15
+ * @param context: The additional context to send.
16
+ * @param timestampMs: The timestamp when the view started (in milliseconds). If not provided, current timestamp will be used.
17
+ */
18
+ startView(
19
+ key: string,
20
+ name: string,
21
+ context?: object,
22
+ timestampMs?: number
23
+ ): Promise<void>;
24
+
25
+ /**
26
+ * Stop tracking a RUM View.
27
+ * @param key: The view unique key identifier.
28
+ * @param context: The additional context to send.
29
+ * @param timestampMs: The timestamp when the view stopped (in milliseconds). If not provided, current timestamp will be used.
30
+ */
31
+ stopView(
32
+ key: string,
33
+ context?: object,
34
+ timestampMs?: number
35
+ ): Promise<void>;
36
+
37
+ /**
38
+ * Start tracking a RUM Action.
39
+ * @param type: The action type (tap, scroll, swipe, back, custom).
40
+ * @param name: The action name.
41
+ * @param context: The additional context to send.
42
+ * @param timestampMs: The timestamp when the action started (in milliseconds). If not provided, current timestamp will be used.
43
+ */
44
+ startAction(
45
+ type: RumActionType,
46
+ name: string,
47
+ context?: object,
48
+ timestampMs?: number
49
+ ): Promise<void>;
50
+
51
+ /**
52
+ * Stop tracking the ongoing RUM Action.
53
+ * @param type: The action type (tap, scroll, swipe, back, custom).
54
+ * @param name: The action name.
55
+ * @param context: The additional context to send.
56
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
57
+ */
58
+ stopAction(
59
+ type: RumActionType,
60
+ name: string,
61
+ context?: object,
62
+ timestampMs?: number
63
+ ): Promise<void>;
64
+
65
+ /**
66
+ * Stop tracking the ongoing RUM Action.
67
+ *
68
+ * Warning: using this function signature can lead to inconsistent behaviors on iOS and Android when multiple actions are started in parallel.
69
+ *
70
+ * @deprecated add the `type` and `name` of the action as first two arguments.
71
+ * @param context: The additional context to send.
72
+ * @param timestampMs: The timestamp when the action stopped (in milliseconds). If not provided, current timestamp will be used.
73
+ */
74
+ stopAction(context?: object, timestampMs?: number): Promise<void>;
75
+
76
+ /**
77
+ * Add a RUM Action.
78
+ * @param type: The action type (tap, scroll, swipe, back, custom).
79
+ * @param name: The action name.
80
+ * @param context: The additional context to send.
81
+ * @param timestampMs: The timestamp when the action occurred (in milliseconds). If not provided, current timestamp will be used.
82
+ */
83
+ addAction(
84
+ type: RumActionType,
85
+ name: string,
86
+ context?: object,
87
+ timestampMs?: number
88
+ ): Promise<void>;
89
+
90
+ /**
91
+ * Start tracking a RUM Resource.
92
+ * @param key: The resource unique key identifier.
93
+ * @param method: The resource method (GET, POST, …).
94
+ * @param url: The resource url.
95
+ * @param context: The additional context to send.
96
+ * @param timestampMs: The timestamp when the resource started (in milliseconds). If not provided, current timestamp will be used.
97
+ */
98
+ startResource(
99
+ key: string,
100
+ method: string,
101
+ url: string,
102
+ context?: object,
103
+ timestampMs?: number
104
+ ): Promise<void>;
105
+
106
+ /**
107
+ * Stop tracking a RUM Resource.
108
+ * @param key: The resource unique key identifier.
109
+ * @param statusCode: The resource status code.
110
+ * @param kind: The resource's kind (xhr, document, image, css, font, …).
111
+ * @param size: The resource size in bytes. If size is unknown, use -1.
112
+ * @param context: The additional context to send.
113
+ * @param timestampMs: The timestamp when the resource stopped (in milliseconds). If not provided, current timestamp will be used.
114
+ */
115
+ stopResource(
116
+ key: string,
117
+ statusCode: number,
118
+ kind: ResourceKind,
119
+ size?: number,
120
+ context?: object,
121
+ timestampMs?: number
122
+ ): Promise<void>;
123
+
124
+ /**
125
+ * Add a RUM Error.
126
+ * @param message: The error message.
127
+ * @param source: The error source (network, source, console, webview, custom).
128
+ * @param stacktrace: The error stacktrace.
129
+ * @param context: The additional context to send.
130
+ * @param timestampMs: The timestamp when the error occurred (in milliseconds). If not provided, current timestamp will be used.
131
+ */
132
+ addError(
133
+ message: string,
134
+ source: ErrorSource,
135
+ stacktrace: string,
136
+ context?: object,
137
+ timestampMs?: number
138
+ ): Promise<void>;
139
+
140
+ /**
141
+ * 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.
142
+ * @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.
143
+ */
144
+ addTiming(name: string): Promise<void>;
145
+ };
146
+
147
+ /**
148
+ * Describe the type of a RUM Action.
149
+ */
150
+ export enum RumActionType {
151
+ /** User tapped on a widget. */
152
+ TAP = 'TAP',
153
+ /** User scrolled a view. */
154
+ SCROLL = 'SCROLL',
155
+ /** User swiped on a view. */
156
+ SWIPE = 'SWIPE',
157
+ /** User pressed hardware back button (Android only). */
158
+ BACK = 'BACK',
159
+ /** A custom action. */
160
+ CUSTOM = 'CUSTOM'
161
+ }
162
+
163
+ export type ResourceKind =
164
+ | 'image'
165
+ | 'xhr'
166
+ | 'beacon'
167
+ | 'css'
168
+ | 'document'
169
+ | 'fetch'
170
+ | 'font'
171
+ | 'js'
172
+ | 'media'
173
+ | 'other'
174
+ | 'native';
175
+
176
+ export enum ErrorSource {
177
+ NETWORK = 'NETWORK',
178
+ SOURCE = 'SOURCE',
179
+ CONSOLE = 'CONSOLE',
180
+ WEBVIEW = 'WEBVIEW',
181
+ CUSTOM = 'CUSTOM'
182
+ }
@@ -0,0 +1,34 @@
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 { Attributes } from './types';
8
+
9
+ class AttributesProvider {
10
+ private attributes: Attributes = {};
11
+
12
+ setAttributes = (attributes: Attributes) => {
13
+ this.attributes = {
14
+ ...this.attributes,
15
+ ...attributes
16
+ };
17
+ };
18
+
19
+ getAttributes = (): Attributes => {
20
+ return this.attributes;
21
+ };
22
+ }
23
+
24
+ export class AttributesSingleton {
25
+ private static attributesProvider = new AttributesProvider();
26
+
27
+ static getInstance = (): AttributesProvider => {
28
+ return AttributesSingleton.attributesProvider;
29
+ };
30
+
31
+ static reset = () => {
32
+ AttributesSingleton.attributesProvider = new AttributesProvider();
33
+ };
34
+ }
@@ -0,0 +1,44 @@
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 { AttributesSingleton } from '../AttributesSingleton';
8
+
9
+ describe('AttributesSingleton', () => {
10
+ it('adds, returns and resets the user info', () => {
11
+ // Adding first attributes
12
+ AttributesSingleton.getInstance().setAttributes({
13
+ appType: 'student',
14
+ extraInfo: {
15
+ loggedIn: true
16
+ }
17
+ });
18
+
19
+ expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
20
+ appType: 'student',
21
+ extraInfo: {
22
+ loggedIn: true
23
+ }
24
+ });
25
+
26
+ // Removing and adding new attributes
27
+ AttributesSingleton.getInstance().setAttributes({
28
+ appType: undefined,
29
+ newAttribute: false
30
+ });
31
+
32
+ expect(AttributesSingleton.getInstance().getAttributes()).toEqual({
33
+ newAttribute: false,
34
+ extraInfo: {
35
+ loggedIn: true
36
+ }
37
+ });
38
+
39
+ // Resetting attributes
40
+ AttributesSingleton.reset();
41
+
42
+ expect(AttributesSingleton.getInstance().getAttributes()).toEqual({});
43
+ });
44
+ });
@@ -0,0 +1,9 @@
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 Attributes = {
8
+ readonly [key: string]: unknown;
9
+ };
@@ -4,10 +4,10 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { InternalLog } from '../../InternalLog';
8
- import { SdkVerbosity } from '../../SdkVerbosity';
9
- import { getErrorStackTrace } from '../../errorUtils';
10
- import { DdSdk } from '../../foundation';
7
+ import { InternalLog } from '../../../InternalLog';
8
+ import { SdkVerbosity } from '../../../SdkVerbosity';
9
+ import { getErrorStackTrace } from '../../../errorUtils';
10
+ import { DdSdk } from '../../../foundation';
11
11
 
12
12
  import { DatadogBuffer } from './DatadogBuffer';
13
13
 
@@ -4,8 +4,8 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import { InternalLog } from '../../../InternalLog';
8
- import { DdSdk } from '../../../foundation';
7
+ import { InternalLog } from '../../../../InternalLog';
8
+ import { DdSdk } from '../../../../foundation';
9
9
  import { BoundedBuffer } from '../BoundedBuffer';
10
10
 
11
11
  describe('BoundedBuffer', () => {
@@ -6,7 +6,8 @@
6
6
 
7
7
  import { BufferSingleton } from '../BufferSingleton';
8
8
 
9
- const flushPromises = () => new Promise<void>(setImmediate);
9
+ const flushPromises = () =>
10
+ new Promise<void>(jest.requireActual('timers').setImmediate);
10
11
 
11
12
  describe('BufferSingleton', () => {
12
13
  afterEach(() => {
@@ -9,14 +9,14 @@ import type { PropsWithChildren } from 'react';
9
9
  import {
10
10
  DatadogProviderConfiguration,
11
11
  DdSdkReactNativeConfiguration
12
- } from '../DdSdkReactNativeConfiguration';
12
+ } from '../../DdSdkReactNativeConfiguration';
13
13
  import type {
14
14
  PartialInitializationConfiguration,
15
15
  AutoInstrumentationConfiguration
16
- } from '../DdSdkReactNativeConfiguration';
17
- import { DdSdkReactNative } from '../DdSdkReactNative';
18
- import { InternalLog } from '../InternalLog';
19
- import { SdkVerbosity } from '../SdkVerbosity';
16
+ } from '../../DdSdkReactNativeConfiguration';
17
+ import { DdSdkReactNative } from '../../DdSdkReactNative';
18
+ import { InternalLog } from '../../InternalLog';
19
+ import { SdkVerbosity } from '../../SdkVerbosity';
20
20
 
21
21
  let isInitialized = false;
22
22