@datadog/mobile-react-native 3.11.0 → 3.13.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 (342) hide show
  1. package/DatadogSDKReactNative.podspec +357 -14
  2. package/README.md +5 -3
  3. package/android/build.gradle +23 -14
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +27 -2
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +27 -2
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +25 -0
  7. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  8. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +4 -0
  9. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +104 -0
  10. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +8 -0
  11. package/android/src/test/resources/input/complete-configuration.json +5 -0
  12. package/datadog-configuration.gradle +59 -18
  13. package/datadog-configuration.schema.json +140 -0
  14. package/ios/Sources/DdFlagsImplementation.swift +3 -0
  15. package/ios/Sources/DdSdkConfiguration.swift +11 -1
  16. package/ios/Sources/DdSdkNativeInitialization.swift +24 -2
  17. package/ios/Sources/RNDdSdkConfiguration.swift +14 -2
  18. package/ios/Sources/SdkVersion.swift +1 -1
  19. package/lib/commonjs/DdSdkReactNative.js +6 -1
  20. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  21. package/lib/commonjs/config/FileBasedConfiguration.js +4 -1
  22. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  23. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +3 -1
  24. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  25. package/lib/commonjs/config/features/RumConfiguration.js +8 -0
  26. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  27. package/lib/commonjs/config/features/RumConfigurationNative.js +4 -0
  28. package/lib/commonjs/config/types/TimeseriesConfiguration.js +25 -0
  29. package/lib/commonjs/config/types/TimeseriesConfiguration.js.map +1 -0
  30. package/lib/commonjs/config/types/index.js +7 -0
  31. package/lib/commonjs/config/types/index.js.map +1 -1
  32. package/lib/commonjs/flags/DdFlags.js +4 -2
  33. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  34. package/lib/commonjs/flags/FlagsClient.js +4 -2
  35. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  36. package/lib/commonjs/index.js +7 -0
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/commonjs/internal.js +97 -0
  39. package/lib/commonjs/internal.js.map +1 -0
  40. package/lib/commonjs/logs/DdLogs.js +4 -2
  41. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  42. package/lib/commonjs/rum/DdRum.js +4 -2
  43. package/lib/commonjs/rum/DdRum.js.map +1 -1
  44. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  45. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  63. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  64. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  65. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  66. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  67. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  68. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  69. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  70. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  71. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  72. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  73. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  74. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  75. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  76. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  77. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  78. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  79. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  80. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  81. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  82. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  83. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  84. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  85. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  86. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  87. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  88. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  89. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  90. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  91. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  92. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  93. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  94. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  95. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  96. package/lib/commonjs/trace/DdTrace.js +4 -2
  97. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  98. package/lib/commonjs/utils/stringUtils.js +48 -0
  99. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  100. package/lib/commonjs/version.js +1 -1
  101. package/lib/module/DdSdkReactNative.js +6 -1
  102. package/lib/module/DdSdkReactNative.js.map +1 -1
  103. package/lib/module/config/FileBasedConfiguration.js +4 -1
  104. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  105. package/lib/module/config/async/AutoInstrumentationConfiguration.js +3 -1
  106. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  107. package/lib/module/config/features/RumConfiguration.js +8 -0
  108. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  109. package/lib/module/config/features/RumConfigurationNative.js +1 -1
  110. package/lib/module/config/types/TimeseriesConfiguration.js +19 -0
  111. package/lib/module/config/types/TimeseriesConfiguration.js.map +1 -0
  112. package/lib/module/config/types/index.js +1 -0
  113. package/lib/module/config/types/index.js.map +1 -1
  114. package/lib/module/flags/DdFlags.js +4 -2
  115. package/lib/module/flags/DdFlags.js.map +1 -1
  116. package/lib/module/flags/FlagsClient.js +5 -2
  117. package/lib/module/flags/FlagsClient.js.map +1 -1
  118. package/lib/module/index.js +2 -1
  119. package/lib/module/index.js.map +1 -1
  120. package/lib/module/internal.js +27 -0
  121. package/lib/module/internal.js.map +1 -0
  122. package/lib/module/logs/DdLogs.js +4 -2
  123. package/lib/module/logs/DdLogs.js.map +1 -1
  124. package/lib/module/rum/DdRum.js +4 -2
  125. package/lib/module/rum/DdRum.js.map +1 -1
  126. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  127. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  128. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  129. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  130. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  131. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  133. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  134. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  135. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  138. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  139. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  140. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  141. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  142. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  143. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  144. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  145. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  146. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  147. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  148. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  149. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  150. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  151. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  152. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  153. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  154. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  155. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  156. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  157. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  158. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  159. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  160. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  161. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  162. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  163. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  164. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  165. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  166. package/lib/module/sdk/DdSdkInternal.js +27 -22
  167. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  168. package/lib/module/specs/NativeDdFlags.js +14 -2
  169. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  170. package/lib/module/specs/NativeDdLogs.js +14 -2
  171. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  172. package/lib/module/specs/NativeDdRum.js +14 -2
  173. package/lib/module/specs/NativeDdRum.js.map +1 -1
  174. package/lib/module/specs/NativeDdSdk.js +14 -2
  175. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  176. package/lib/module/specs/NativeDdTrace.js +14 -2
  177. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  178. package/lib/module/trace/DdTrace.js +4 -2
  179. package/lib/module/trace/DdTrace.js.map +1 -1
  180. package/lib/module/utils/stringUtils.js +42 -0
  181. package/lib/module/utils/stringUtils.js.map +1 -0
  182. package/lib/module/version.js +1 -1
  183. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  184. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  185. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +4 -1
  186. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  187. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +6 -0
  188. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  189. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts +2 -1
  190. package/lib/typescript/config/async/PartialInitializationConfiguration.d.ts.map +1 -1
  191. package/lib/typescript/config/features/RumConfiguration.d.ts +6 -1
  192. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  193. package/lib/typescript/config/features/RumConfiguration.type.d.ts +116 -1
  194. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  195. package/lib/typescript/config/features/RumConfigurationNative.d.ts +2 -0
  196. package/lib/typescript/config/features/RumConfigurationNative.d.ts.map +1 -1
  197. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts +19 -0
  198. package/lib/typescript/config/types/TimeseriesConfiguration.d.ts.map +1 -0
  199. package/lib/typescript/config/types/index.d.ts +2 -0
  200. package/lib/typescript/config/types/index.d.ts.map +1 -1
  201. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  202. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  203. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  204. package/lib/typescript/index.d.ts +5 -2
  205. package/lib/typescript/index.d.ts.map +1 -1
  206. package/lib/typescript/internal.d.ts +26 -0
  207. package/lib/typescript/internal.d.ts.map +1 -0
  208. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  209. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  210. package/lib/typescript/rum/DdRum.d.ts +1 -1
  211. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  212. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  213. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  214. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  215. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  216. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  217. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  218. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  219. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  220. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  221. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  222. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  223. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  224. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  225. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  226. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  227. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  228. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  229. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  230. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  231. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  232. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  233. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  234. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  235. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  236. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  237. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  238. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  239. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  240. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  241. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  242. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  243. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  244. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  245. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  246. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  247. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  248. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  249. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  250. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  251. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  252. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  253. package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
  254. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  255. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  256. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  257. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  258. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  259. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  260. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  261. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  262. package/lib/typescript/version.d.ts +1 -1
  263. package/package.json +8 -3
  264. package/src/DdSdkReactNative.tsx +11 -1
  265. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  266. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +6 -0
  267. package/src/__tests__/internalEntry.test.ts +26 -0
  268. package/src/__tests__/mock.test.ts +1 -3
  269. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  270. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  271. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  272. package/src/config/FileBasedConfiguration.ts +6 -1
  273. package/src/config/FileBasedConfiguration.type.ts +4 -0
  274. package/src/config/__tests__/FileBasedConfiguration.test.ts +73 -0
  275. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +14 -1
  276. package/src/config/async/AutoInstrumentationConfiguration.ts +9 -1
  277. package/src/config/async/PartialInitializationConfiguration.ts +2 -0
  278. package/src/config/features/RumConfiguration.ts +15 -0
  279. package/src/config/features/RumConfiguration.type.ts +128 -1
  280. package/src/config/features/RumConfigurationNative.ts +3 -0
  281. package/src/config/types/TimeseriesConfiguration.ts +26 -0
  282. package/src/config/types/index.ts +5 -0
  283. package/src/flags/DdFlags.ts +4 -3
  284. package/src/flags/FlagsClient.ts +4 -3
  285. package/src/index.tsx +15 -0
  286. package/src/internal.ts +32 -0
  287. package/src/logs/DdLogs.ts +4 -3
  288. package/src/rum/DdRum.ts +4 -3
  289. package/src/rum/__tests__/DdRum.test.ts +4 -4
  290. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  291. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  292. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  293. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  294. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  295. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  296. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  297. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  298. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  299. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  300. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  301. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  302. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  303. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  304. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  305. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  306. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  307. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  308. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  309. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  310. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  311. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  312. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  313. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  314. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  315. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  316. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
  317. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
  318. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  319. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
  320. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
  321. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  322. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
  323. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  324. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  325. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  326. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  327. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  328. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  329. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  330. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  331. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +54 -1
  332. package/src/sdk/DdSdkInternal.ts +27 -24
  333. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  334. package/src/specs/NativeDdFlags.ts +14 -2
  335. package/src/specs/NativeDdLogs.ts +14 -2
  336. package/src/specs/NativeDdRum.ts +14 -2
  337. package/src/specs/NativeDdSdk.ts +14 -2
  338. package/src/specs/NativeDdTrace.ts +14 -2
  339. package/src/trace/DdTrace.ts +4 -3
  340. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  341. package/src/utils/stringUtils.ts +41 -0
  342. package/src/version.ts +1 -1
@@ -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
 
@@ -0,0 +1,142 @@
1
+ # Resource Header Capture
2
+
3
+ The Datadog React Native SDK can capture HTTP request and response headers on RUM resource events. This helps debug caching, CDN, and content negotiation issues without extra instrumentation.
4
+
5
+ Header capture is **disabled by default** and requires `trackResources: true`.
6
+
7
+ ## Configuration
8
+
9
+ Set `headerCaptureRules` in your RUM configuration:
10
+
11
+ ```typescript
12
+ import {
13
+ DatadogProvider,
14
+ DatadogProviderConfiguration,
15
+ TrackingConsent
16
+ } from '@datadog/mobile-react-native';
17
+
18
+ const config = new DatadogProviderConfiguration(
19
+ '<CLIENT_TOKEN>',
20
+ '<ENVIRONMENT_NAME>',
21
+ TrackingConsent.GRANTED,
22
+ {
23
+ rumConfiguration: {
24
+ applicationId: '<RUM_APPLICATION_ID>',
25
+ trackResources: true,
26
+ headerCaptureRules: 'defaults'
27
+ }
28
+ }
29
+ );
30
+
31
+ // <DatadogProvider configuration={config}>...</DatadogProvider>
32
+ ```
33
+
34
+ With `FileBasedConfiguration`, set the same value under `rumConfiguration` in your JSON configuration file:
35
+
36
+ ```json
37
+ {
38
+ "configuration": {
39
+ "rumConfiguration": {
40
+ "trackResources": true,
41
+ "headerCaptureRules": "defaults"
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Modes
48
+
49
+ | Value | What gets captured |
50
+ |---|---|
51
+ | Omitted (default) | Nothing |
52
+ | `'defaults'` | A predefined set of caching and content headers across all URLs |
53
+ | `HeaderCaptureRule[]` | Custom rules — see below |
54
+
55
+ ### Default headers
56
+
57
+ `'defaults'` captures:
58
+
59
+ - **Response:** `Cache-Control`, `ETag`, `Age`, `Expires`, `Content-Type`, `Content-Encoding`, `Content-Length`, `Vary`, `Server-Timing`, `X-Cache`
60
+ - **Request:** `Cache-Control`, `Content-Type`
61
+
62
+ ### Custom rules
63
+
64
+ Use an array of rules to control exactly which headers are captured and for which URLs:
65
+
66
+ ```typescript
67
+ headerCaptureRules: [
68
+ // Capture default headers everywhere
69
+ { type: 'defaults' },
70
+
71
+ // Capture a custom response header on a specific API
72
+ {
73
+ type: 'matchResponseHeaders',
74
+ headers: ['x-request-id', 'x-ratelimit-remaining'],
75
+ forURLs: ['api.example.com']
76
+ },
77
+
78
+ // Capture a custom request header on a path prefix
79
+ {
80
+ type: 'matchRequestHeaders',
81
+ headers: ['x-device-id'],
82
+ forURLs: ['api.example.com/v2']
83
+ }
84
+ ]
85
+ ```
86
+
87
+ Each rule has a `type`:
88
+
89
+ | `type` | Captures from |
90
+ |---|---|
91
+ | `'defaults'` | Request + response (predefined set) |
92
+ | `'matchHeaders'` | Both request and response (named headers) |
93
+ | `'matchRequestHeaders'` | Request only |
94
+ | `'matchResponseHeaders'` | Response only |
95
+
96
+ The optional `forURLs` field scopes a rule to specific URL patterns. Supports hostname-only (`api.example.com`) or hostname + path prefix (`api.example.com/v2`). Omit it (or use `['*']`) to match all URLs.
97
+
98
+ - A hostname matches itself and its subdomains (`api.example.com` matches `cdn.api.example.com`), but never a hostname that only appears in the path or query of another URL.
99
+ - A path prefix matches whole path segments: `api.example.com/v2` matches `/v2` and `/v2/users`, but not `/v22`.
100
+ - URLs are matched the way HTTP clients resolve them: `..` and `.` segments (including `%2e` encodings) are resolved first, so `api.example.com/public/../private` does not match `api.example.com/public`. Equivalent hostname spellings are normalized (percent-encodings, fullwidth characters, `。`/`.`/`。` label separators, extra slashes after `https:`), and a URL without a path (`https://api.example.com?x=1`) matches as `/`. Hostnames in `forURLs` are normalized the same way. Hostnames match case-insensitively, paths case-sensitively.
101
+
102
+ **Rule precedence:** when multiple rules match a URL, their header sets are merged. However, if at least one scoped rule (with explicit `forURLs` patterns) matches, catch-all rules (no `forURLs`, or a `forURLs` list containing `'*'`) are ignored for that URL. For example, `[{ type: 'defaults' }, { type: 'matchResponseHeaders', headers: ['x-request-id'], forURLs: ['api.example.com'] }]` captures only `x-request-id` on `api.example.com`, and the default headers everywhere else.
103
+
104
+ ## Output
105
+
106
+ Captured headers appear as attributes on RUM resource events:
107
+
108
+ - `_dd.request_headers` — captured request headers
109
+ - `_dd.response_headers` — captured response headers
110
+
111
+ Header names use RFC Title-Case for default headers (`Cache-Control`, `ETag`, …) and preserve the casing from your rule's `headers` array for custom headers.
112
+
113
+ When nothing is captured these attributes are omitted entirely.
114
+
115
+ ## Supported clients
116
+
117
+ Headers are captured for every request tracked by the SDK:
118
+
119
+ - **XHR** (`trackResources: true`) — covers React Native's built-in `fetch`, axios and any other XMLHttpRequest-based client.
120
+ - **Global Fetch** (`trackFetchResources: true`) — covers the Expo-installed global `fetch`. When the global `fetch` is backed by XHR, headers are reported once, on the Fetch resource. Direct imports retained from `expo/fetch` are not intercepted.
121
+
122
+ Fetch `Headers` lowercase header names, so on Fetch resources custom request headers use the casing from your rule's `headers` array rather than the casing passed to `fetch`.
123
+
124
+ Requests that fail without a response (aborted, network error) never report headers.
125
+
126
+ ## Security
127
+
128
+ Two filters are always enforced, regardless of configuration:
129
+
130
+ **Sensitive header blocklist** — headers matching patterns like `token`, `cookie`, `secret`, `authorization`, `password`, `bearer`, `api-key`, `x-forwarded-for`, etc. are always blocked and never stored.
131
+
132
+ **SDK tracing headers** — the Datadog and W3C/B3 tracing headers injected by the SDK itself (`x-datadog-trace-id`, `traceparent`, `b3`, etc.) are always excluded.
133
+
134
+ ## Size limits
135
+
136
+ To protect event size, the SDK enforces:
137
+
138
+ - **128 bytes** max per header value (values are truncated)
139
+ - **100 headers** max total (request + response combined)
140
+ - **2 048 bytes** max total across all header names and values
141
+
142
+ All limits are measured in UTF-8 bytes.