@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
@@ -10,6 +10,7 @@ import { Platform, NativeModules } from 'react-native';
10
10
  import { InternalLog } from '../../../../../../InternalLog';
11
11
  import { SdkVerbosity } from '../../../../../../config/types';
12
12
  import { BufferSingleton } from '../../../../../../sdk/DatadogProvider/Buffer/BufferSingleton';
13
+ import { Timer } from '../../../../../../utils/Timer';
13
14
  import { DdRum } from '../../../../../DdRum';
14
15
  import {
15
16
  setCachedSessionId,
@@ -43,6 +44,7 @@ import {
43
44
  DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
44
45
  DATADOG_GRAPH_QL_VARIABLES_HEADER
45
46
  } from '../../../graphql/graphqlHeaders';
47
+ import { compileHeaderCaptureConfig } from '../../../headerCapture/compileHeaderConfig';
46
48
  import { ResourceReporter } from '../../common/ResourceReporter';
47
49
  import { XHRProxy } from '../XHRProxy';
48
50
  import {
@@ -71,6 +73,42 @@ const hexToDecimal = (hex: string): string => {
71
73
  return BigInt(hex, 16).toString(10);
72
74
  };
73
75
 
76
+ const defaultsConfig = [
77
+ {
78
+ urlRegex: /.*/,
79
+ requestHeaderNames: new Set(['cache-control', 'content-type']),
80
+ responseHeaderNames: new Set([
81
+ 'cache-control',
82
+ 'etag',
83
+ 'age',
84
+ 'expires',
85
+ 'content-type',
86
+ 'content-encoding',
87
+ 'content-length',
88
+ 'vary',
89
+ 'server-timing',
90
+ 'x-cache'
91
+ ]),
92
+ isScoped: false,
93
+ requestHeaderCasing: new Map([
94
+ ['cache-control', 'Cache-Control'],
95
+ ['content-type', 'Content-Type']
96
+ ]),
97
+ responseHeaderCasing: new Map([
98
+ ['cache-control', 'Cache-Control'],
99
+ ['etag', 'ETag'],
100
+ ['age', 'Age'],
101
+ ['expires', 'Expires'],
102
+ ['content-type', 'Content-Type'],
103
+ ['content-encoding', 'Content-Encoding'],
104
+ ['content-length', 'Content-Length'],
105
+ ['vary', 'Vary'],
106
+ ['server-timing', 'Server-Timing'],
107
+ ['x-cache', 'X-Cache']
108
+ ])
109
+ }
110
+ ];
111
+
74
112
  beforeEach(() => {
75
113
  DdNativeRum.startResource.mockClear();
76
114
  DdNativeRum.stopResource.mockClear();
@@ -2337,7 +2375,7 @@ describe('XHRProxy', () => {
2337
2375
 
2338
2376
  // THEN - Application successfully read the response
2339
2377
  expect(applicationReadResponse).toBe(responseBody);
2340
- const parsedByApp = JSON.parse(applicationReadResponse!);
2378
+ const parsedByApp = JSON.parse(applicationReadResponse ?? '');
2341
2379
  expect(parsedByApp.errors).toHaveLength(1);
2342
2380
  expect(parsedByApp.errors[0].message).toBe('User not found');
2343
2381
 
@@ -2551,7 +2589,7 @@ describe('XHRProxy', () => {
2551
2589
 
2552
2590
  // THEN - Application got complete response with all error details
2553
2591
  expect(applicationReadResponse).toBe(responseBody);
2554
- const parsedByApp = JSON.parse(applicationReadResponse!);
2592
+ const parsedByApp = JSON.parse(applicationReadResponse ?? '');
2555
2593
  expect(parsedByApp.errors).toHaveLength(2);
2556
2594
  expect(parsedByApp.errors[0].extensions.details).toBe(
2557
2595
  'filtered'
@@ -2580,4 +2618,588 @@ describe('XHRProxy', () => {
2580
2618
  });
2581
2619
  });
2582
2620
  });
2621
+
2622
+ describe('header capture', () => {
2623
+ it('disabled mode: does not report request headers', async () => {
2624
+ // GIVEN
2625
+ const method = 'GET';
2626
+ const url = 'https://api.example.com/v2/user';
2627
+ xhrProxy.onTrackingStart({
2628
+ tracingSamplingRate: 100,
2629
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2630
+ headerCaptureConfig: null
2631
+ });
2632
+
2633
+ // WHEN
2634
+ const xhr = new XMLHttpRequestMock();
2635
+ xhr.open(method, url);
2636
+ xhr.setRequestHeader('Content-Type', 'application/json');
2637
+ xhr.send();
2638
+ xhr.notifyResponseArrived();
2639
+ xhr.complete(200, 'ok');
2640
+ await flushPromises();
2641
+
2642
+ // THEN
2643
+ expect(
2644
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
2645
+ ).toBeUndefined();
2646
+ });
2647
+
2648
+ it('disabled mode: does not capture response headers', async () => {
2649
+ // GIVEN
2650
+ const method = 'GET';
2651
+ const url = 'https://api.example.com/v2/user';
2652
+ xhrProxy.onTrackingStart({
2653
+ tracingSamplingRate: 100,
2654
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2655
+ headerCaptureConfig: null
2656
+ });
2657
+
2658
+ // WHEN
2659
+ const xhr = new XMLHttpRequestMock();
2660
+ xhr.open(method, url);
2661
+ xhr.send();
2662
+ xhr.notifyResponseArrived();
2663
+ xhr.getAllResponseHeaders.mockReturnValue(
2664
+ 'content-type: text/html\r\n'
2665
+ );
2666
+ xhr.complete(200, 'ok');
2667
+ await flushPromises();
2668
+
2669
+ // THEN
2670
+ expect(
2671
+ DdNativeRum.stopResource.mock.calls[0][4][
2672
+ '_dd.response_headers'
2673
+ ]
2674
+ ).toBeUndefined();
2675
+ });
2676
+
2677
+ it('defaults mode: accumulates and filters allowed request headers', async () => {
2678
+ // GIVEN
2679
+ const method = 'GET';
2680
+ const url = 'https://api.example.com/v2/user';
2681
+ xhrProxy.onTrackingStart({
2682
+ tracingSamplingRate: 100,
2683
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2684
+ headerCaptureConfig: defaultsConfig
2685
+ });
2686
+
2687
+ // WHEN
2688
+ const xhr = new XMLHttpRequestMock();
2689
+ xhr.open(method, url);
2690
+ xhr.setRequestHeader('Content-Type', 'application/json');
2691
+ xhr.setRequestHeader('X-Custom', 'val');
2692
+ xhr.send();
2693
+ xhr.notifyResponseArrived();
2694
+ xhr.complete(200, 'ok');
2695
+ await flushPromises();
2696
+
2697
+ // THEN — content-type is in defaults, x-custom is not
2698
+ expect(
2699
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
2700
+ ).toEqual({
2701
+ 'Content-Type': 'application/json'
2702
+ });
2703
+ });
2704
+
2705
+ it('defaults mode: captures default response headers', async () => {
2706
+ // GIVEN
2707
+ const method = 'GET';
2708
+ const url = 'https://api.example.com/v2/user';
2709
+ xhrProxy.onTrackingStart({
2710
+ tracingSamplingRate: 100,
2711
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2712
+ headerCaptureConfig: defaultsConfig
2713
+ });
2714
+
2715
+ // WHEN
2716
+ const xhr = new XMLHttpRequestMock();
2717
+ xhr.open(method, url);
2718
+ xhr.send();
2719
+ xhr.notifyResponseArrived();
2720
+ xhr.getAllResponseHeaders.mockReturnValue(
2721
+ 'content-type: text/html\r\ncache-control: no-cache\r\nx-custom: val\r\n'
2722
+ );
2723
+ xhr.complete(200, 'ok');
2724
+ await flushPromises();
2725
+
2726
+ // THEN — content-type, cache-control in defaults; x-custom not
2727
+ expect(
2728
+ DdNativeRum.stopResource.mock.calls[0][4][
2729
+ '_dd.response_headers'
2730
+ ]
2731
+ ).toEqual({
2732
+ 'Content-Type': 'text/html',
2733
+ 'Cache-Control': 'no-cache'
2734
+ });
2735
+ });
2736
+
2737
+ it('defaults mode: skips response capture on aborted request (status 0)', async () => {
2738
+ // GIVEN
2739
+ const method = 'GET';
2740
+ const url = 'https://api.example.com/v2/user';
2741
+ xhrProxy.onTrackingStart({
2742
+ tracingSamplingRate: 100,
2743
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2744
+ headerCaptureConfig: defaultsConfig
2745
+ });
2746
+
2747
+ // WHEN
2748
+ const xhr = new XMLHttpRequestMock();
2749
+ xhr.open(method, url);
2750
+ xhr.send();
2751
+ xhr.getAllResponseHeaders.mockReturnValue(
2752
+ 'content-type: text/html\r\n'
2753
+ );
2754
+ xhr.abort();
2755
+ xhr.complete(0, undefined);
2756
+ await flushPromises();
2757
+
2758
+ // THEN — status 0 means header capture is skipped
2759
+ expect(
2760
+ DdNativeRum.stopResource.mock.calls[0][4][
2761
+ '_dd.response_headers'
2762
+ ]
2763
+ ).toBeUndefined();
2764
+ });
2765
+
2766
+ it('custom mode: captures only rule-matched headers', async () => {
2767
+ // GIVEN
2768
+ const method = 'GET';
2769
+ const url = 'https://api.example.com/data';
2770
+ xhrProxy.onTrackingStart({
2771
+ tracingSamplingRate: 100,
2772
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2773
+ headerCaptureConfig: [
2774
+ {
2775
+ urlRegex: /.*example\.com.*/,
2776
+ requestHeaderNames: new Set(['x-request-id']),
2777
+ responseHeaderNames: new Set(['etag', 'x-cache']),
2778
+ isScoped: false,
2779
+ requestHeaderCasing: new Map([
2780
+ ['x-request-id', 'x-request-id']
2781
+ ]),
2782
+ responseHeaderCasing: new Map([
2783
+ ['etag', 'etag'],
2784
+ ['x-cache', 'x-cache']
2785
+ ])
2786
+ }
2787
+ ]
2788
+ });
2789
+
2790
+ // WHEN
2791
+ const xhr = new XMLHttpRequestMock();
2792
+ xhr.open(method, url);
2793
+ xhr.setRequestHeader('X-Request-Id', 'abc');
2794
+ xhr.setRequestHeader('Content-Type', 'application/json');
2795
+ xhr.send();
2796
+ xhr.notifyResponseArrived();
2797
+ xhr.getAllResponseHeaders.mockReturnValue(
2798
+ 'etag: abc123\r\ncontent-type: text/html\r\nx-cache: HIT\r\n'
2799
+ );
2800
+ xhr.complete(200, 'ok');
2801
+ await flushPromises();
2802
+
2803
+ // THEN — only rule-matched headers appear
2804
+ expect(
2805
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
2806
+ ).toEqual({
2807
+ 'X-Request-Id': 'abc'
2808
+ });
2809
+ expect(
2810
+ DdNativeRum.stopResource.mock.calls[0][4][
2811
+ '_dd.response_headers'
2812
+ ]
2813
+ ).toEqual({
2814
+ etag: 'abc123',
2815
+ 'x-cache': 'HIT'
2816
+ });
2817
+ });
2818
+
2819
+ it('security: sensitive request headers are never reported', async () => {
2820
+ // GIVEN
2821
+ const method = 'GET';
2822
+ const url = 'https://api.example.com/v2/user';
2823
+ xhrProxy.onTrackingStart({
2824
+ tracingSamplingRate: 100,
2825
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2826
+ headerCaptureConfig: defaultsConfig
2827
+ });
2828
+
2829
+ // WHEN
2830
+ const xhr = new XMLHttpRequestMock();
2831
+ xhr.open(method, url);
2832
+ xhr.setRequestHeader('Authorization', 'Bearer token');
2833
+ xhr.setRequestHeader('Content-Type', 'application/json');
2834
+ xhr.send();
2835
+ xhr.notifyResponseArrived();
2836
+ xhr.complete(200, 'ok');
2837
+ await flushPromises();
2838
+
2839
+ // THEN — authorization blocked by security filter
2840
+ expect(
2841
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
2842
+ ).toEqual({
2843
+ 'Content-Type': 'application/json'
2844
+ });
2845
+ });
2846
+
2847
+ it('security: sensitive response headers are filtered out', async () => {
2848
+ // GIVEN
2849
+ const method = 'GET';
2850
+ const url = 'https://api.example.com/v2/user';
2851
+ xhrProxy.onTrackingStart({
2852
+ tracingSamplingRate: 100,
2853
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2854
+ headerCaptureConfig: [
2855
+ {
2856
+ urlRegex: /.*/,
2857
+ requestHeaderNames: new Set<string>(),
2858
+ responseHeaderNames: new Set([
2859
+ 'set-cookie',
2860
+ 'cache-control'
2861
+ ]),
2862
+ isScoped: false,
2863
+ requestHeaderCasing: new Map(),
2864
+ responseHeaderCasing: new Map([
2865
+ ['set-cookie', 'set-cookie'],
2866
+ ['cache-control', 'cache-control']
2867
+ ])
2868
+ }
2869
+ ]
2870
+ });
2871
+
2872
+ // WHEN
2873
+ const xhr = new XMLHttpRequestMock();
2874
+ xhr.open(method, url);
2875
+ xhr.send();
2876
+ xhr.notifyResponseArrived();
2877
+ xhr.getAllResponseHeaders.mockReturnValue(
2878
+ 'set-cookie: session=abc\r\ncache-control: no-cache\r\n'
2879
+ );
2880
+ xhr.complete(200, 'ok');
2881
+ await flushPromises();
2882
+
2883
+ // THEN — set-cookie blocked by isSensitiveHeader; only cache-control appears
2884
+ expect(
2885
+ DdNativeRum.stopResource.mock.calls[0][4][
2886
+ '_dd.response_headers'
2887
+ ]
2888
+ ).toEqual({
2889
+ 'cache-control': 'no-cache'
2890
+ });
2891
+ });
2892
+ });
2893
+
2894
+ describe('header capture with request reuse', () => {
2895
+ it('reports the headers of the completed request when the XHR is reused during GraphQL body extraction', async () => {
2896
+ // GIVEN
2897
+ xhrProxy.onTrackingStart({
2898
+ tracingSamplingRate: 100,
2899
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2900
+ headerCaptureConfig: compileHeaderCaptureConfig('defaults')
2901
+ });
2902
+
2903
+ const xhr = new XMLHttpRequestMock();
2904
+ xhr.open('POST', 'https://api.example.com/graphql');
2905
+ xhr.setRequestHeader(
2906
+ DATADOG_GRAPH_QL_OPERATION_TYPE_HEADER,
2907
+ 'query'
2908
+ );
2909
+ xhr.setRequestHeader(DATADOG_GRAPH_QL_ERROR_HEADER, 'true');
2910
+ xhr.setRequestHeader('Content-Type', 'application/json');
2911
+ xhr.send();
2912
+ xhr.notifyResponseArrived();
2913
+ xhr.getAllResponseHeaders.mockReturnValue(
2914
+ 'cache-control: max-age=60\r\n'
2915
+ );
2916
+ const body = JSON.stringify({ errors: [{ message: 'boom' }] });
2917
+ xhr.responseText = body;
2918
+
2919
+ // WHEN the request completes, then the app reuses the XHR
2920
+ // before the GraphQL body has been read
2921
+ xhr.complete(200, body);
2922
+ xhr.status = 0;
2923
+ xhr.getAllResponseHeaders.mockReturnValue('etag: "other"\r\n');
2924
+ await flushPromises();
2925
+
2926
+ // THEN
2927
+ const [
2928
+ ,
2929
+ statusCode,
2930
+ ,
2931
+ ,
2932
+ context
2933
+ ] = DdNativeRum.stopResource.mock.calls[0];
2934
+ expect(statusCode).toBe(200);
2935
+ expect(context['_dd.request_headers']).toEqual({
2936
+ 'Content-Type': 'application/json'
2937
+ });
2938
+ expect(context['_dd.response_headers']).toEqual({
2939
+ 'Cache-Control': 'max-age=60'
2940
+ });
2941
+ });
2942
+
2943
+ it('stringifies non-string request header values and still reports the resource', async () => {
2944
+ // GIVEN
2945
+ xhrProxy.onTrackingStart({
2946
+ tracingSamplingRate: 100,
2947
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2948
+ headerCaptureConfig: compileHeaderCaptureConfig([
2949
+ {
2950
+ type: 'matchRequestHeaders',
2951
+ headers: ['x-count', 'x-empty']
2952
+ }
2953
+ ])
2954
+ });
2955
+
2956
+ // WHEN untyped callers pass non-string values
2957
+ const xhr = new XMLHttpRequestMock();
2958
+ xhr.open('GET', 'https://api.example.com/v2/user');
2959
+ xhr.setRequestHeader('x-count', (42 as unknown) as string);
2960
+ xhr.setRequestHeader('x-empty', (null as unknown) as string);
2961
+ xhr.send();
2962
+ xhr.notifyResponseArrived();
2963
+ xhr.complete(200, 'ok');
2964
+ await flushPromises();
2965
+
2966
+ // THEN the same string is sent and captured
2967
+ expect(xhr.requestHeaders.get('x-count')).toBe('42');
2968
+ expect(xhr.requestHeaders.get('x-empty')).toBe('null');
2969
+ expect(DdNativeRum.stopResource).toHaveBeenCalledTimes(1);
2970
+ expect(
2971
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
2972
+ ).toEqual({ 'x-count': '42', 'x-empty': 'null' });
2973
+ });
2974
+
2975
+ it('stops the resource timer before processing captured headers', async () => {
2976
+ // GIVEN
2977
+ const timerStop = jest.spyOn(Timer.prototype, 'stop');
2978
+ xhrProxy.onTrackingStart({
2979
+ tracingSamplingRate: 100,
2980
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
2981
+ headerCaptureConfig: compileHeaderCaptureConfig('defaults')
2982
+ });
2983
+
2984
+ // WHEN
2985
+ const xhr = new XMLHttpRequestMock();
2986
+ xhr.open('GET', 'https://api.example.com/v2/user');
2987
+ xhr.send();
2988
+ xhr.notifyResponseArrived();
2989
+ xhr.getAllResponseHeaders.mockReturnValue(
2990
+ 'cache-control: no-cache\r\n'
2991
+ );
2992
+ xhr.complete(200, 'ok');
2993
+ await flushPromises();
2994
+
2995
+ // THEN
2996
+ expect(timerStop).toHaveBeenCalledTimes(1);
2997
+ expect(xhr.getAllResponseHeaders).toHaveBeenCalled();
2998
+ expect(timerStop.mock.invocationCallOrder[0]).toBeLessThan(
2999
+ xhr.getAllResponseHeaders.mock.invocationCallOrder[0]
3000
+ );
3001
+ timerStop.mockRestore();
3002
+ });
3003
+
3004
+ it('does not capture the SDK tracked-by header even when a rule names it', async () => {
3005
+ // GIVEN
3006
+ xhrProxy.onTrackingStart({
3007
+ tracingSamplingRate: 100,
3008
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3009
+ headerCaptureConfig: compileHeaderCaptureConfig([
3010
+ {
3011
+ type: 'matchRequestHeaders',
3012
+ headers: [TRACKED_BY_HEADER_KEY, 'x-request-id']
3013
+ }
3014
+ ])
3015
+ });
3016
+
3017
+ // WHEN
3018
+ const xhr = new XMLHttpRequestMock();
3019
+ xhr.open('GET', 'https://api.example.com/v2/user');
3020
+ xhr.setRequestHeader('X-Request-Id', 'abc');
3021
+ xhr.send();
3022
+ xhr.notifyResponseArrived();
3023
+ xhr.complete(200, 'ok');
3024
+ await flushPromises();
3025
+
3026
+ // THEN the header was sent but not captured
3027
+ expect(xhr.requestHeaders.get(TRACKED_BY_HEADER_KEY)).toBe(
3028
+ TRACKED_BY_HEADER_VALUE
3029
+ );
3030
+ expect(
3031
+ DdNativeRum.stopResource.mock.calls[0][4]['_dd.request_headers']
3032
+ ).toEqual({ 'X-Request-Id': 'abc' });
3033
+ });
3034
+ });
3035
+
3036
+ describe('header capture integration', () => {
3037
+ it('disabled mode: no header attributes in stopResource context', async () => {
3038
+ // GIVEN
3039
+ const method = 'GET';
3040
+ const url = 'https://api.example.com/v2/user';
3041
+ xhrProxy.onTrackingStart({
3042
+ tracingSamplingRate: 100,
3043
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3044
+ headerCaptureConfig: null
3045
+ });
3046
+
3047
+ // WHEN
3048
+ const xhr = new XMLHttpRequestMock();
3049
+ xhr.open(method, url);
3050
+ xhr.setRequestHeader('Content-Type', 'application/json');
3051
+ xhr.setRequestHeader('Accept', 'text/html');
3052
+ xhr.send();
3053
+ xhr.notifyResponseArrived();
3054
+ xhr.getAllResponseHeaders.mockReturnValue(
3055
+ 'content-type: text/html\r\ncache-control: no-cache\r\n'
3056
+ );
3057
+ xhr.complete(200, 'ok');
3058
+ await flushPromises();
3059
+
3060
+ // THEN
3061
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4]; // 5th arg (index 4) = resource context
3062
+ expect(stopContext['_dd.request_headers']).toBeUndefined();
3063
+ expect(stopContext['_dd.response_headers']).toBeUndefined();
3064
+ });
3065
+
3066
+ it('defaults mode: correct default headers captured, sensitive headers excluded', async () => {
3067
+ // GIVEN
3068
+ const method = 'GET';
3069
+ const url = 'https://api.example.com/v2/user';
3070
+ xhrProxy.onTrackingStart({
3071
+ tracingSamplingRate: 100,
3072
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3073
+ headerCaptureConfig: defaultsConfig
3074
+ });
3075
+
3076
+ // WHEN
3077
+ const xhr = new XMLHttpRequestMock();
3078
+ xhr.open(method, url);
3079
+ xhr.setRequestHeader('Content-Type', 'application/json');
3080
+ xhr.setRequestHeader('Authorization', 'Bearer secret');
3081
+ xhr.setRequestHeader('X-Custom', 'val');
3082
+ xhr.send();
3083
+ xhr.notifyResponseArrived();
3084
+ xhr.getAllResponseHeaders.mockReturnValue(
3085
+ 'content-type: text/html\r\ncache-control: no-cache\r\netag: abc\r\nset-cookie: session=xyz\r\nx-custom-resp: val\r\n'
3086
+ );
3087
+ xhr.complete(200, 'ok');
3088
+ await flushPromises();
3089
+
3090
+ // THEN
3091
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4]; // 5th arg (index 4) = resource context
3092
+ // Only default, non-sensitive request headers
3093
+ expect(stopContext['_dd.request_headers']).toEqual({
3094
+ 'Content-Type': 'application/json'
3095
+ });
3096
+ // Only default response headers; set-cookie is sensitive, x-custom-resp not in defaults
3097
+ expect(stopContext['_dd.response_headers']).toEqual({
3098
+ 'Content-Type': 'text/html',
3099
+ 'Cache-Control': 'no-cache',
3100
+ ETag: 'abc'
3101
+ });
3102
+ });
3103
+
3104
+ it('custom mode: only rule-matched headers captured', async () => {
3105
+ // GIVEN
3106
+ const method = 'GET';
3107
+ const url = 'https://api.example.com/data';
3108
+ xhrProxy.onTrackingStart({
3109
+ tracingSamplingRate: 100,
3110
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3111
+ headerCaptureConfig: [
3112
+ {
3113
+ urlRegex: /.*/,
3114
+ requestHeaderNames: new Set(['x-request-id']),
3115
+ responseHeaderNames: new Set(['x-correlation-id']),
3116
+ isScoped: false,
3117
+ requestHeaderCasing: new Map([
3118
+ ['x-request-id', 'x-request-id']
3119
+ ]),
3120
+ responseHeaderCasing: new Map([
3121
+ ['x-correlation-id', 'x-correlation-id']
3122
+ ])
3123
+ }
3124
+ ]
3125
+ });
3126
+
3127
+ // WHEN
3128
+ const xhr = new XMLHttpRequestMock();
3129
+ xhr.open(method, url);
3130
+ xhr.setRequestHeader('X-Request-Id', 'test-123');
3131
+ xhr.setRequestHeader('Content-Type', 'application/json');
3132
+ xhr.send();
3133
+ xhr.notifyResponseArrived();
3134
+ xhr.getAllResponseHeaders.mockReturnValue(
3135
+ 'x-correlation-id: abc123\r\ncontent-type: text/html\r\n'
3136
+ );
3137
+ xhr.complete(200, 'ok');
3138
+ await flushPromises();
3139
+
3140
+ // THEN
3141
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4]; // 5th arg (index 4) = resource context
3142
+ // Only the custom rule match
3143
+ expect(stopContext['_dd.request_headers']).toEqual({
3144
+ 'X-Request-Id': 'test-123'
3145
+ });
3146
+ expect(stopContext['_dd.response_headers']).toEqual({
3147
+ 'x-correlation-id': 'abc123'
3148
+ });
3149
+ });
3150
+
3151
+ it('defaults mode: duplicate setRequestHeader uses last value (last-wins)', async () => {
3152
+ // GIVEN
3153
+ const method = 'GET';
3154
+ const url = 'https://api.example.com/v2/user';
3155
+ xhrProxy.onTrackingStart({
3156
+ tracingSamplingRate: 100,
3157
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3158
+ headerCaptureConfig: defaultsConfig
3159
+ });
3160
+
3161
+ // WHEN
3162
+ const xhr = new XMLHttpRequestMock();
3163
+ xhr.open(method, url);
3164
+ xhr.setRequestHeader('Content-Type', 'text/plain');
3165
+ xhr.setRequestHeader('Content-Type', 'application/json');
3166
+ xhr.send();
3167
+ xhr.notifyResponseArrived();
3168
+ xhr.complete(200, 'ok');
3169
+ await flushPromises();
3170
+
3171
+ // THEN
3172
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4]; // 5th arg (index 4) = resource context
3173
+ expect(stopContext['_dd.request_headers']).toEqual({
3174
+ 'Content-Type': 'application/json'
3175
+ });
3176
+ });
3177
+
3178
+ it('network failure: resource reported without throwing, no response headers', async () => {
3179
+ // GIVEN
3180
+ const method = 'GET';
3181
+ const url = 'https://api.example.com/v2/user';
3182
+ xhrProxy.onTrackingStart({
3183
+ tracingSamplingRate: 100,
3184
+ firstPartyHostsRegexMap: firstPartyHostsRegexMapBuilder([]),
3185
+ headerCaptureConfig: defaultsConfig
3186
+ });
3187
+
3188
+ // WHEN
3189
+ const xhr = new XMLHttpRequestMock();
3190
+ xhr.open(method, url);
3191
+ xhr.setRequestHeader('Content-Type', 'application/json');
3192
+ xhr.send();
3193
+ // Status 0 = network error/abort; XHRProxy skips response header capture by design
3194
+ xhr.getAllResponseHeaders.mockReturnValue(null);
3195
+ xhr.complete(0, undefined);
3196
+ await flushPromises();
3197
+
3198
+ // THEN
3199
+ expect(DdNativeRum.stopResource).toHaveBeenCalledTimes(1);
3200
+ const stopContext = DdNativeRum.stopResource.mock.calls[0][4]; // 5th arg (index 4) = resource context
3201
+ expect(stopContext['_dd.response_headers']).toBeUndefined();
3202
+ // Test completing without throwing is proof no exception occurred
3203
+ });
3204
+ });
2583
3205
  });