@datadog/mobile-react-native 3.11.0 → 3.12.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 (304) hide show
  1. package/README.md +2 -1
  2. package/android/build.gradle +14 -5
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/datadog-configuration.gradle +59 -18
  5. package/datadog-configuration.schema.json +119 -0
  6. package/ios/Sources/SdkVersion.swift +1 -1
  7. package/lib/commonjs/DdSdkReactNative.js +6 -1
  8. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  9. package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
  10. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  11. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
  12. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  13. package/lib/commonjs/config/features/RumConfiguration.js +4 -0
  14. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  15. package/lib/commonjs/flags/DdFlags.js +4 -2
  16. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  17. package/lib/commonjs/flags/FlagsClient.js +4 -2
  18. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  19. package/lib/commonjs/internal.js +97 -0
  20. package/lib/commonjs/internal.js.map +1 -0
  21. package/lib/commonjs/logs/DdLogs.js +4 -2
  22. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  23. package/lib/commonjs/rum/DdRum.js +4 -2
  24. package/lib/commonjs/rum/DdRum.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  26. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  33. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  34. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  35. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  63. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  64. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  65. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  66. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  67. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  68. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  69. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  70. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  71. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  72. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  73. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  74. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  75. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  76. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  77. package/lib/commonjs/trace/DdTrace.js +4 -2
  78. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  79. package/lib/commonjs/utils/stringUtils.js +48 -0
  80. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  81. package/lib/commonjs/version.js +1 -1
  82. package/lib/module/DdSdkReactNative.js +6 -1
  83. package/lib/module/DdSdkReactNative.js.map +1 -1
  84. package/lib/module/config/FileBasedConfiguration.js +2 -0
  85. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  86. package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
  87. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  88. package/lib/module/config/features/RumConfiguration.js +4 -0
  89. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  90. package/lib/module/flags/DdFlags.js +4 -2
  91. package/lib/module/flags/DdFlags.js.map +1 -1
  92. package/lib/module/flags/FlagsClient.js +5 -2
  93. package/lib/module/flags/FlagsClient.js.map +1 -1
  94. package/lib/module/internal.js +27 -0
  95. package/lib/module/internal.js.map +1 -0
  96. package/lib/module/logs/DdLogs.js +4 -2
  97. package/lib/module/logs/DdLogs.js.map +1 -1
  98. package/lib/module/rum/DdRum.js +4 -2
  99. package/lib/module/rum/DdRum.js.map +1 -1
  100. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  101. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  102. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  103. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  104. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  105. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  106. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  107. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  108. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  109. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  110. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  111. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  112. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  113. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  114. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  115. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  116. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  117. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  118. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  119. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  120. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  121. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  122. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  123. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  124. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  125. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  126. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  127. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  128. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  129. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  130. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  131. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  133. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  134. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  135. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  138. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  139. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  140. package/lib/module/sdk/DdSdkInternal.js +27 -22
  141. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  142. package/lib/module/specs/NativeDdFlags.js +14 -2
  143. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  144. package/lib/module/specs/NativeDdLogs.js +14 -2
  145. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  146. package/lib/module/specs/NativeDdRum.js +14 -2
  147. package/lib/module/specs/NativeDdRum.js.map +1 -1
  148. package/lib/module/specs/NativeDdSdk.js +14 -2
  149. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  150. package/lib/module/specs/NativeDdTrace.js +14 -2
  151. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  152. package/lib/module/trace/DdTrace.js +4 -2
  153. package/lib/module/trace/DdTrace.js.map +1 -1
  154. package/lib/module/utils/stringUtils.js +42 -0
  155. package/lib/module/utils/stringUtils.js.map +1 -0
  156. package/lib/module/version.js +1 -1
  157. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  158. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  159. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
  160. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  161. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
  162. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  163. package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
  164. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  165. package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
  166. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  167. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  168. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  169. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  170. package/lib/typescript/index.d.ts +1 -0
  171. package/lib/typescript/index.d.ts.map +1 -1
  172. package/lib/typescript/internal.d.ts +26 -0
  173. package/lib/typescript/internal.d.ts.map +1 -0
  174. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  175. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  176. package/lib/typescript/rum/DdRum.d.ts +1 -1
  177. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  178. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  179. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  180. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  181. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  182. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  183. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  184. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  185. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  186. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  187. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  188. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  189. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  190. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  191. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  192. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  193. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  194. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  195. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  196. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  197. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  198. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  199. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  200. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  201. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  202. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  203. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  204. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  205. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  206. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  207. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  208. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  209. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  210. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  211. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  212. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  213. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  214. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  215. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  216. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  217. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  218. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  219. package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
  220. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  221. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  222. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  223. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  224. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  225. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  226. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  227. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  228. package/lib/typescript/version.d.ts +1 -1
  229. package/package.json +7 -2
  230. package/src/DdSdkReactNative.tsx +11 -1
  231. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  232. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
  233. package/src/__tests__/internalEntry.test.ts +26 -0
  234. package/src/__tests__/mock.test.ts +1 -3
  235. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  236. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  237. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  238. package/src/config/FileBasedConfiguration.ts +3 -0
  239. package/src/config/FileBasedConfiguration.type.ts +2 -0
  240. package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
  241. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
  242. package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
  243. package/src/config/features/RumConfiguration.ts +9 -0
  244. package/src/config/features/RumConfiguration.type.ts +117 -0
  245. package/src/flags/DdFlags.ts +4 -3
  246. package/src/flags/FlagsClient.ts +4 -3
  247. package/src/index.tsx +7 -0
  248. package/src/internal.ts +32 -0
  249. package/src/logs/DdLogs.ts +4 -3
  250. package/src/rum/DdRum.ts +4 -3
  251. package/src/rum/__tests__/DdRum.test.ts +4 -4
  252. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  253. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  254. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  255. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  256. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  257. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  258. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  259. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  260. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  261. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  262. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  263. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  264. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  265. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  266. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  267. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  268. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  269. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  270. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  271. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  272. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  273. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  274. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  275. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  276. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  277. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  278. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
  279. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
  280. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  281. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
  282. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
  283. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  284. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
  285. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  286. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  287. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  288. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  289. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  290. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  291. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  292. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  293. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
  294. package/src/sdk/DdSdkInternal.ts +27 -24
  295. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  296. package/src/specs/NativeDdFlags.ts +14 -2
  297. package/src/specs/NativeDdLogs.ts +14 -2
  298. package/src/specs/NativeDdRum.ts +14 -2
  299. package/src/specs/NativeDdSdk.ts +14 -2
  300. package/src/specs/NativeDdTrace.ts +14 -2
  301. package/src/trace/DdTrace.ts +4 -3
  302. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  303. package/src/utils/stringUtils.ts +41 -0
  304. package/src/version.ts +1 -1
@@ -7,6 +7,7 @@
7
7
  import { InternalLog } from '../InternalLog';
8
8
  import { SdkVerbosity } from '../config/types/SdkVerbosity';
9
9
  import type { DdNativeFlagsType } from '../nativeModulesTypes';
10
+ import { getNativeDdFlags } from '../specs/NativeDdFlags';
10
11
  import { getGlobalInstance } from '../utils/singletonUtils';
11
12
 
12
13
  import { FlagsClient } from './FlagsClient';
@@ -18,9 +19,9 @@ const FLAGS_MODULE = 'com.datadog.reactnative.flags';
18
19
  * Implementation class for {@link DdFlagsType}. Please see the interface for documentation.
19
20
  */
20
21
  class DdFlagsWrapper implements DdFlagsType {
21
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
22
- private nativeFlags: DdNativeFlagsType = require('../specs/NativeDdFlags')
23
- .default;
22
+ private get nativeFlags(): DdNativeFlagsType {
23
+ return getNativeDdFlags() as DdNativeFlagsType;
24
+ }
24
25
 
25
26
  private isFeatureEnabled = false;
26
27
 
@@ -7,6 +7,7 @@
7
7
  import { InternalLog } from '../InternalLog';
8
8
  import { SdkVerbosity } from '../config/types/SdkVerbosity';
9
9
  import type { DdNativeFlagsType } from '../nativeModulesTypes';
10
+ import { getNativeDdFlags } from '../specs/NativeDdFlags';
10
11
 
11
12
  // Imported directly (not via the module index): context matching is an internal helper,
12
13
  // used here only to detect a runtime context an offline precomputed configuration cannot honor.
@@ -82,9 +83,9 @@ interface OfflineFlagsEvaluator {
82
83
  }
83
84
 
84
85
  export class FlagsClient {
85
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
86
- private nativeFlags: DdNativeFlagsType = require('../specs/NativeDdFlags')
87
- .default;
86
+ private get nativeFlags(): DdNativeFlagsType {
87
+ return getNativeDdFlags() as DdNativeFlagsType;
88
+ }
88
89
 
89
90
  private clientName: string;
90
91
 
package/src/index.tsx CHANGED
@@ -116,6 +116,13 @@ export {
116
116
  __ddExtractText,
117
117
  __ddEnrichEvaluationContextWithRumUser
118
118
  };
119
+ export type {
120
+ HeaderCaptureRule,
121
+ DefaultsRule,
122
+ MatchHeadersRule,
123
+ MatchRequestHeadersRule,
124
+ MatchResponseHeadersRule
125
+ } from './config/features/RumConfiguration.type';
119
126
  export type {
120
127
  Timestamp,
121
128
  FirstPartyHost,
@@ -0,0 +1,32 @@
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
+ * Sanctioned entry point for cross-package internals consumed by platform
9
+ * packages (e.g. @datadog/mobile-react-native-vega). NOT part of the public API
10
+ * and may change between minor versions. Everything re-exported here must be
11
+ * native-free at import (must not call TurboModuleRegistry / NativeModules at
12
+ * module load).
13
+ */
14
+ export { addDefaultValuesToAutoInstrumentationConfiguration } from './config/async/AutoInstrumentationConfiguration';
15
+ export { buildConfigurationFromPartialConfiguration } from './config/async/asyncInitializationHelper';
16
+ export { DdSdkNativeConfiguration } from './config/features/CoreConfigurationNative';
17
+ export { RUM_DEFAULTS } from './config/features/RumConfiguration';
18
+ export { adaptLongTaskThreshold } from './utils/longTasksUtils';
19
+ export { version } from './version';
20
+ export { AccountInfoSingleton } from './sdk/AccountInfoSingleton/AccountInfoSingleton';
21
+ export { AttributesSingleton } from './sdk/AttributesSingleton/AttributesSingleton';
22
+ export { UserInfoSingleton } from './sdk/UserInfoSingleton/UserInfoSingleton';
23
+ export { GlobalState } from './sdk/GlobalState/GlobalState';
24
+ export { BufferSingleton } from './sdk/DatadogProvider/Buffer/BufferSingleton';
25
+ export { DatadogProviderState } from './sdk/DatadogProvider/DatadogProviderState';
26
+ export { DdRumResourceTracking } from './rum/instrumentation/resourceTracking/DdRumResourceTracking';
27
+
28
+ export type { Attributes } from './sdk/AttributesSingleton/types';
29
+ export type { LogsNativeConfiguration } from './config/features/LogsConfigurationNative';
30
+ export type { RumNativeConfiguration } from './config/features/RumConfigurationNative';
31
+ export type { TraceNativeConfiguration } from './config/features/TraceConfigurationNative';
32
+ export type { InitializationModeForTelemetry } from './config/types/InitializationModeForTelemetry';
@@ -11,6 +11,7 @@ import { debugId } from '../metro/debugIdResolver';
11
11
  import type { DdNativeLogsType } from '../nativeModulesTypes';
12
12
  import { encodeAttributes } from '../sdk/AttributesEncoding/attributesEncoding';
13
13
  import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
14
+ import { getNativeDdLogs } from '../specs/NativeDdLogs';
14
15
  import type { ErrorSource, LogEventMapper } from '../types';
15
16
  import { getGlobalInstance } from '../utils/singletonUtils';
16
17
 
@@ -44,9 +45,9 @@ const isLogWithError = (
44
45
  };
45
46
 
46
47
  class DdLogsWrapper implements DdLogsType {
47
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
48
- private nativeLogs: DdNativeLogsType = require('../specs/NativeDdLogs')
49
- .default;
48
+ private get nativeLogs(): DdNativeLogsType {
49
+ return getNativeDdLogs() as DdNativeLogsType;
50
+ }
50
51
  private logEventMapper = generateEventMapper(undefined);
51
52
 
52
53
  debug = (...args: LogArguments | LogWithErrorArguments): Promise<void> => {
package/src/rum/DdRum.ts CHANGED
@@ -15,6 +15,7 @@ import type { Attributes } from '../sdk/AttributesSingleton/types';
15
15
  import { bufferVoidNativeCall } from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
16
16
  import { DdSdk } from '../sdk/DdSdk';
17
17
  import { GlobalState } from '../sdk/GlobalState/GlobalState';
18
+ import { getNativeDdRum } from '../specs/NativeDdRum';
18
19
  import type { ErrorSource, FeatureOperationFailure } from '../types';
19
20
  import { getGlobalInstance } from '../utils/singletonUtils';
20
21
  import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
@@ -77,9 +78,9 @@ const touchDataFromEvent = (
77
78
  };
78
79
 
79
80
  class DdRumWrapper implements DdRumType {
80
- // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
81
- private nativeRum: DdNativeRumType = require('../specs/NativeDdRum')
82
- .default;
81
+ private get nativeRum(): DdNativeRumType {
82
+ return getNativeDdRum() as DdNativeRumType;
83
+ }
83
84
  private lastActionData?: { type: RumActionType; name: string };
84
85
  private errorEventMapper = generateErrorEventMapper(undefined);
85
86
  private resourceEventMapper = generateResourceEventMapper(undefined);
@@ -12,7 +12,7 @@ import { InternalLog } from '../../InternalLog';
12
12
  import { SdkVerbosity } from '../../config/types';
13
13
  import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
14
14
  import { GlobalState } from '../../sdk/GlobalState/GlobalState';
15
- import NativeDdSdkSpec from '../../specs/NativeDdSdk';
15
+ import { getNativeDdSdk } from '../../specs/NativeDdSdk';
16
16
  import { ErrorSource } from '../../types';
17
17
  import { DdRum } from '../DdRum';
18
18
  import type { ActionEventMapper } from '../eventMappers/actionEventMapper';
@@ -1444,7 +1444,7 @@ describe('DdRum', () => {
1444
1444
  test('does not call the native SDK when startAction has not been called before and using old API', async () => {
1445
1445
  await DdRum.stopAction({ user: 'me' }, 789);
1446
1446
  expect(NativeModules.DdRum.stopAction).not.toHaveBeenCalled();
1447
- expect(NativeDdSdkSpec.telemetryDebug).not.toHaveBeenCalled();
1447
+ expect(getNativeDdSdk()?.telemetryDebug).not.toHaveBeenCalled();
1448
1448
  });
1449
1449
 
1450
1450
  test('calls the native SDK when called with old API', async () => {
@@ -1456,7 +1456,7 @@ describe('DdRum', () => {
1456
1456
  { user: 'me' },
1457
1457
  789
1458
1458
  );
1459
- expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
1459
+ expect(getNativeDdSdk()?.telemetryDebug).toHaveBeenCalledWith(
1460
1460
  'DDdRum.stopAction called with the old signature'
1461
1461
  );
1462
1462
  });
@@ -1470,7 +1470,7 @@ describe('DdRum', () => {
1470
1470
  {},
1471
1471
  456
1472
1472
  );
1473
- expect(NativeDdSdkSpec.telemetryDebug).toHaveBeenCalledWith(
1473
+ expect(getNativeDdSdk()?.telemetryDebug).toHaveBeenCalledWith(
1474
1474
  'DDdRum.stopAction called with the old signature'
1475
1475
  );
1476
1476
  });
@@ -4,7 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
- import DdSdk from '../../../specs/NativeDdSdk';
7
+ import { getNativeDdSdk } from '../../../specs/NativeDdSdk';
8
8
  import { getGlobalInstance } from '../../../utils/singletonUtils';
9
9
  import { DefaultTimeProvider } from '../../../utils/time-provider/DefaultTimeProvider';
10
10
  import type { TimeProvider } from '../../../utils/time-provider/TimeProvider';
@@ -76,41 +76,48 @@ class BabelInteractionTracking {
76
76
 
77
77
  const { useAccessibilityLabel } = this.config;
78
78
 
79
- const tryContent = () => {
80
- const content = getContent?.();
81
- if (content && content.length > 0) {
82
- return content;
79
+ const index = handlerArgs
80
+ ? handlerArgs.find(x => typeof x === 'number') || 0
81
+ : 0;
82
+
83
+ // Picks the value at `index` (positions map to compound component parts).
84
+ // Values can come from runtime expressions, so a value that doesn't resolve
85
+ // to a usable name returns null and lets the next naming source take over.
86
+ const getIndexedValue = (values: unknown): string | null => {
87
+ if (!Array.isArray(values) || values.length === 0) {
88
+ return null;
89
+ }
90
+
91
+ // Fail-safe in case the our 'index' value turns out to not be a real index
92
+ const value =
93
+ index + 1 > values.length || index < 0
94
+ ? values[0]
95
+ : values[index];
96
+
97
+ if (
98
+ (typeof value === 'string' && value.length > 0) ||
99
+ (typeof value === 'number' && Number.isFinite(value))
100
+ ) {
101
+ return String(value);
83
102
  }
84
103
 
85
104
  return null;
86
105
  };
87
106
 
88
107
  const getAccessibilityLabel = () =>
89
- useAccessibilityLabel && accessibilityLabel
90
- ? accessibilityLabel
91
- : null;
92
-
93
- const index = handlerArgs
94
- ? handlerArgs.find(x => typeof x === 'number') || 0
95
- : 0;
108
+ useAccessibilityLabel ? getIndexedValue(accessibilityLabel) : null;
96
109
 
97
110
  // Order: actionName → actionNameAttribute → accessibilityLabel → content
98
- const selectedContent =
99
- actionName ||
100
- Object.values(attrs)[0] ||
101
- getAccessibilityLabel() ||
102
- tryContent();
111
+ const output =
112
+ getIndexedValue(actionName) ??
113
+ getIndexedValue(Object.values(attrs)[0]) ??
114
+ getAccessibilityLabel() ??
115
+ getIndexedValue(getContent?.());
103
116
 
104
- if (!selectedContent) {
117
+ if (output === null) {
105
118
  return componentName;
106
119
  }
107
120
 
108
- // Fail-safe in case the our 'index' value turns out to not be a real index
109
- const output =
110
- index + 1 > selectedContent.length || index < 0
111
- ? selectedContent[0]
112
- : selectedContent[index];
113
-
114
121
  return options.useNamePrefix
115
122
  ? `${componentName} ("${output}")`
116
123
  : output;
@@ -123,7 +130,7 @@ class BabelInteractionTracking {
123
130
  ): (...args: any[]) => any {
124
131
  return (...args: any[]) => {
125
132
  if (!this.telemetrySent) {
126
- DdSdk?.sendTelemetryLog(
133
+ getNativeDdSdk()?.sendTelemetryLog(
127
134
  BABEL_PLUGIN_TELEMETRY,
128
135
  this.getTelemetryConfig(),
129
136
  { onlyOnce: true }
@@ -147,7 +154,7 @@ class BabelInteractionTracking {
147
154
  )
148
155
  .catch(e => {
149
156
  if (e instanceof Error) {
150
- DdSdk?.telemetryError(
157
+ getNativeDdSdk()?.telemetryError(
151
158
  e.message,
152
159
  e.stack || '',
153
160
  'BabelActionTrack'
@@ -0,0 +1,120 @@
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
+ // Babel is a development dependency of the workspace root.
8
+ // eslint-disable-next-line import/no-extraneous-dependencies
9
+ import { transformSync } from '@babel/core';
10
+ import { createRequire } from 'module';
11
+ import Pressability from 'react-native/Libraries/Pressability/Pressability';
12
+ import * as ReactNative from 'react-native';
13
+ import * as React from 'react';
14
+
15
+ import plugin from '../../../../../../react-native-babel-plugin/src';
16
+
17
+ const nodeRequire = createRequire(__filename);
18
+
19
+ function loadButtonFixture(trackingAvailable: boolean) {
20
+ const trackAction = jest.fn();
21
+ const tracking = {
22
+ getInstance: () => (trackingAvailable ? tracking : null),
23
+ wrapRumAction: (handler: (...args: any[]) => any) => (
24
+ ...args: any[]
25
+ ) => {
26
+ trackAction();
27
+ return handler?.(...args);
28
+ }
29
+ };
30
+ // Reproduce #1509 independently of the example app: optional handlers must
31
+ // remain absent after transforming a component with Metro's preset.
32
+ const output = transformSync(
33
+ `
34
+ import React from 'react';
35
+ import { Pressable } from 'react-native';
36
+
37
+ export function OptionalHandlerButton({ onPress, onLongPress }) {
38
+ return <Pressable onPress={onPress} onLongPress={onLongPress} />;
39
+ }
40
+ `,
41
+ {
42
+ filename: 'optional-handlers.tsx',
43
+ configFile: false,
44
+ babelrc: false,
45
+ presets: ['module:@react-native/babel-preset'],
46
+ plugins: [[plugin, { sessionReplay: { svgTracking: false } }]]
47
+ }
48
+ )?.code as string;
49
+ const modules: Record<string, any> = {
50
+ react: React,
51
+ 'react-native': ReactNative,
52
+ '@datadog/mobile-react-native': {
53
+ DdBabelInteractionTracking: tracking
54
+ }
55
+ };
56
+ const exports: Record<string, any> = {};
57
+ // eslint-disable-next-line no-new-func
58
+ new Function('require', 'exports', output)(
59
+ (id: string) => modules[id] ?? nodeRequire(id),
60
+ exports
61
+ );
62
+ return { Button: exports.OptionalHandlerButton, trackAction };
63
+ }
64
+
65
+ describe.each([true, false])(
66
+ 'issue #1509 with tracking available=%s',
67
+ trackingAvailable => {
68
+ beforeEach(() => jest.useFakeTimers());
69
+ afterEach(() => {
70
+ jest.clearAllTimers();
71
+ jest.useRealTimers();
72
+ });
73
+
74
+ it.each([undefined, null, 'defined'])(
75
+ 'preserves short and long presses with onLongPress=%s',
76
+ value => {
77
+ const { Button, trackAction } = loadButtonFixture(
78
+ trackingAvailable
79
+ );
80
+ const onPress = jest.fn();
81
+ const onLongPress = value === 'defined' ? jest.fn() : value;
82
+ const element = Button({ onPress, onLongPress });
83
+ // Exercise React Native's actual state machine, including its timer
84
+ // and the onLongPress-presence check that suppresses onPress.
85
+ const pressability = new Pressability(element.props);
86
+ const handlers = pressability.getEventHandlers();
87
+ const event = {
88
+ currentTarget: 1,
89
+ nativeEvent: { pageX: 0, pageY: 0 },
90
+ persist: jest.fn()
91
+ } as any;
92
+
93
+ handlers.onResponderGrant(event);
94
+ jest.advanceTimersByTime(100);
95
+ handlers.onResponderRelease(event);
96
+ expect(onPress).toHaveBeenCalledTimes(1);
97
+ if (typeof onLongPress === 'function') {
98
+ expect(onLongPress).not.toHaveBeenCalled();
99
+ }
100
+
101
+ handlers.onResponderGrant(event);
102
+ jest.advanceTimersByTime(600);
103
+ handlers.onResponderRelease(event);
104
+ expect(onPress).toHaveBeenCalledTimes(
105
+ onLongPress == null ? 2 : 1
106
+ );
107
+ if (onLongPress == null) {
108
+ expect(element.props.onLongPress).toBe(onLongPress);
109
+ }
110
+ if (typeof onLongPress === 'function') {
111
+ expect(onLongPress).toHaveBeenCalledTimes(1);
112
+ }
113
+ expect(trackAction).toHaveBeenCalledTimes(
114
+ trackingAvailable ? 2 : 0
115
+ );
116
+ pressability.reset();
117
+ }
118
+ );
119
+ }
120
+ );
@@ -9,10 +9,10 @@ import { DdBabelInteractionTracking } from '../DdBabelInteractionTracking';
9
9
 
10
10
  jest.mock('../../../../specs/NativeDdSdk', () => ({
11
11
  __esModule: true,
12
- default: {
12
+ getNativeDdSdk: jest.fn().mockReturnValue({
13
13
  sendTelemetryLog: jest.fn(),
14
14
  telemetryError: jest.fn()
15
- }
15
+ })
16
16
  }));
17
17
 
18
18
  jest.mock('../../../../utils/time-provider/DefaultTimeProvider', () => ({
@@ -198,3 +198,83 @@ describe('DdBabelInteractionTracking.wrapRumAction', () => {
198
198
  );
199
199
  });
200
200
  });
201
+
202
+ describe('DdBabelInteractionTracking target name resolution', () => {
203
+ const mockAddAction = jest.fn().mockResolvedValue(undefined);
204
+
205
+ beforeEach(() => {
206
+ mockAddAction.mockClear();
207
+ DdBabelInteractionTracking.config = {
208
+ trackInteractions: true,
209
+ useAccessibilityLabel: true
210
+ };
211
+ DdBabelInteractionTracking.attachRumInstance({
212
+ addAction: mockAddAction
213
+ } as any);
214
+ });
215
+
216
+ const getTargetName = (targetObject: Record<string, any>) => {
217
+ DdBabelInteractionTracking.wrapRumAction(jest.fn(), RumActionType.TAP, {
218
+ ...mockTargetObject,
219
+ options: { useContent: true, useNamePrefix: false },
220
+ ...targetObject
221
+ } as any)();
222
+ return mockAddAction.mock.calls[0][1];
223
+ };
224
+
225
+ it('should use the actionNameAttribute value', () => {
226
+ expect(getTargetName({ testID: ['save_button'] })).toBe('save_button');
227
+ });
228
+
229
+ it('should skip undefined and empty actionNameAttribute values', () => {
230
+ expect(
231
+ getTargetName({
232
+ testID: [undefined, ''],
233
+ accessibilityLabel: ['Save']
234
+ })
235
+ ).toBe('Save');
236
+ });
237
+
238
+ it('should skip empty dd-action-name and fall back to actionNameAttribute', () => {
239
+ expect(
240
+ getTargetName({ 'dd-action-name': [], testID: ['save_button'] })
241
+ ).toBe('save_button');
242
+ });
243
+
244
+ it('should fall back to content when no attribute resolves', () => {
245
+ expect(
246
+ getTargetName({
247
+ testID: [null],
248
+ accessibilityLabel: [undefined],
249
+ getContent: () => ['Save content']
250
+ })
251
+ ).toBe('Save content');
252
+ });
253
+
254
+ it('should fall back to the component name when nothing resolves', () => {
255
+ expect(getTargetName({ testID: [undefined] })).toBe('Button');
256
+ });
257
+
258
+ it('should stringify numeric values', () => {
259
+ expect(getTargetName({ testID: [42] })).toBe('42');
260
+ });
261
+
262
+ it('should keep positions when resolving the indexed value', () => {
263
+ expect(
264
+ getTargetName({
265
+ testID: ['first', undefined, 'third'],
266
+ handlerArgs: [2]
267
+ })
268
+ ).toBe('third');
269
+ });
270
+
271
+ it('should fall back to the next source when the indexed value is unresolved', () => {
272
+ expect(
273
+ getTargetName({
274
+ testID: ['first', undefined, 'third'],
275
+ accessibilityLabel: ['a11y_first', 'a11y_second'],
276
+ handlerArgs: [1]
277
+ })
278
+ ).toBe('a11y_second');
279
+ });
280
+ });
@@ -7,12 +7,14 @@
7
7
  import BigInt from 'big-integer';
8
8
 
9
9
  import { InternalLog } from '../../../InternalLog';
10
+ import type { HeaderCaptureRule } from '../../../config/features/RumConfiguration.type';
10
11
  import { SdkVerbosity } from '../../../config/types/SdkVerbosity';
11
12
  import { getGlobalInstance } from '../../../utils/singletonUtils';
12
13
  import type { FirstPartyHost } from '../../types';
13
14
 
14
15
  import { DistributedTracingSampling } from './distributedTracing/distributedTracingSampling';
15
16
  import { firstPartyHostsRegexMapBuilder } from './distributedTracing/firstPartyHosts';
17
+ import { compileHeaderCaptureConfig } from './headerCapture/compileHeaderConfig';
16
18
  import { FetchProxy } from './requestProxy/FetchProxy/FetchProxy';
17
19
  import { XHRProxy } from './requestProxy/XHRProxy/XHRProxy';
18
20
  import type { RequestProxy } from './requestProxy/interfaces/RequestProxy';
@@ -42,11 +44,13 @@ class RumResourceTracking {
42
44
  startTracking({
43
45
  resourceTraceSampleRate,
44
46
  firstPartyHosts,
45
- trackFetchResources = false
47
+ trackFetchResources = false,
48
+ headerCaptureRules
46
49
  }: {
47
50
  resourceTraceSampleRate: number;
48
51
  firstPartyHosts: FirstPartyHost[];
49
52
  trackFetchResources?: boolean;
53
+ headerCaptureRules?: 'defaults' | HeaderCaptureRule[] | undefined;
50
54
  }): void {
51
55
  // extra safety to avoid proxying the XHR class twice
52
56
  if (this._isTracking) {
@@ -61,7 +65,8 @@ class RumResourceTracking {
61
65
  tracingSamplingRate: resourceTraceSampleRate,
62
66
  firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder(
63
67
  firstPartyHosts
64
- )
68
+ ),
69
+ headerCaptureConfig: compileHeaderCaptureConfig(headerCaptureRules)
65
70
  };
66
71
 
67
72
  const xhrProxy = XHRProxy.createWithResourceReporter();
@@ -193,6 +193,52 @@ describe('DdRumResourceTracking', () => {
193
193
  );
194
194
  });
195
195
 
196
+ it('captures headers once on an XHR-backed Fetch when header capture is enabled', async () => {
197
+ const fetchResponse = ({
198
+ status: 200,
199
+ headers: new Headers({ 'cache-control': 'max-age=60' })
200
+ } as unknown) as Response;
201
+ const xhrBackedFetch = jest.fn(
202
+ (input: RequestInfo | URL, init?: RequestInit) => {
203
+ const xhr = new XMLHttpRequestMock();
204
+ xhr.open(init?.method ?? 'GET', String(input));
205
+ new Headers(init?.headers).forEach((value, header) => {
206
+ xhr.setRequestHeader(header, value);
207
+ });
208
+ xhr.send();
209
+ xhr.notifyResponseArrived();
210
+ xhr.getAllResponseHeaders.mockReturnValue(
211
+ 'cache-control: max-age=60\r\n'
212
+ );
213
+ xhr.complete(200, 'ok');
214
+ return Promise.resolve(fetchResponse);
215
+ }
216
+ ) as jest.MockedFunction<typeof fetch>;
217
+ global.fetch = xhrBackedFetch;
218
+
219
+ DdRumResourceTracking.startTracking({
220
+ resourceTraceSampleRate: 100,
221
+ firstPartyHosts: [],
222
+ trackFetchResources: true,
223
+ headerCaptureRules: 'defaults'
224
+ });
225
+
226
+ await global.fetch('https://api.example.com/fetch', {
227
+ headers: { 'Content-Type': 'application/json' }
228
+ });
229
+ await flushPromises();
230
+
231
+ expect(DdRum.stopResource).toHaveBeenCalledTimes(1);
232
+ const [, , kind, , context] = DdRum.stopResource.mock.calls[0];
233
+ expect(kind).toBe('fetch');
234
+ expect(context['_dd.request_headers']).toEqual({
235
+ 'Content-Type': 'application/json'
236
+ });
237
+ expect(context['_dd.response_headers']).toEqual({
238
+ 'Cache-Control': 'max-age=60'
239
+ });
240
+ });
241
+
196
242
  describe('updateTrackingContext', () => {
197
243
  beforeEach(() => {
198
244
  DdRumResourceTracking.stopTracking();
@@ -27,7 +27,7 @@ export class XMLHttpRequestMock implements XMLHttpRequest {
27
27
  timeout: number = -1;
28
28
  upload: XMLHttpRequestUpload = {} as XMLHttpRequestUpload;
29
29
  withCredentials: boolean = false;
30
- getAllResponseHeaders = jest.fn();
30
+ getAllResponseHeaders = jest.fn().mockReturnValue('');
31
31
  overrideMimeType = jest.fn();
32
32
  DONE = 4 as const;
33
33
  HEADERS_RECEIVED = 2 as const;
@@ -15,7 +15,7 @@ export type Hostname = { _type: 'Hostname' } & string;
15
15
  export const NO_MATCH_REGEX = new RegExp('a^');
16
16
 
17
17
  // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
18
- const escapeRegExp = (string: string) => {
18
+ export const escapeRegExp = (string: string) => {
19
19
  return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
20
20
  };
21
21