@datadog/mobile-react-native 3.11.0 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/README.md +2 -1
  2. package/android/build.gradle +14 -5
  3. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
  4. package/datadog-configuration.gradle +59 -18
  5. package/datadog-configuration.schema.json +119 -0
  6. package/ios/Sources/SdkVersion.swift +1 -1
  7. package/lib/commonjs/DdSdkReactNative.js +6 -1
  8. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  9. package/lib/commonjs/config/FileBasedConfiguration.js +2 -0
  10. package/lib/commonjs/config/FileBasedConfiguration.js.map +1 -1
  11. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js +2 -1
  12. package/lib/commonjs/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  13. package/lib/commonjs/config/features/RumConfiguration.js +4 -0
  14. package/lib/commonjs/config/features/RumConfiguration.js.map +1 -1
  15. package/lib/commonjs/flags/DdFlags.js +4 -2
  16. package/lib/commonjs/flags/DdFlags.js.map +1 -1
  17. package/lib/commonjs/flags/FlagsClient.js +4 -2
  18. package/lib/commonjs/flags/FlagsClient.js.map +1 -1
  19. package/lib/commonjs/internal.js +97 -0
  20. package/lib/commonjs/internal.js.map +1 -0
  21. package/lib/commonjs/logs/DdLogs.js +4 -2
  22. package/lib/commonjs/logs/DdLogs.js.map +1 -1
  23. package/lib/commonjs/rum/DdRum.js +4 -2
  24. package/lib/commonjs/rum/DdRum.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -15
  26. package/lib/commonjs/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +2 -1
  30. package/lib/commonjs/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  31. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  32. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +308 -0
  33. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  34. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +275 -0
  35. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  36. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +167 -0
  37. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  38. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +36 -0
  39. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  40. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +158 -0
  41. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  42. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +58 -0
  43. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  44. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +39 -0
  45. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  46. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +38 -0
  47. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  48. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  49. package/lib/commonjs/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  50. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  51. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  52. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  53. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  54. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +2 -35
  55. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  56. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  57. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  58. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  59. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  60. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +88 -0
  61. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  62. package/lib/commonjs/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  63. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  64. package/lib/commonjs/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  65. package/lib/commonjs/sdk/DdSdkInternal.js +27 -22
  66. package/lib/commonjs/sdk/DdSdkInternal.js.map +1 -1
  67. package/lib/commonjs/specs/NativeDdFlags.js +19 -3
  68. package/lib/commonjs/specs/NativeDdFlags.js.map +1 -1
  69. package/lib/commonjs/specs/NativeDdLogs.js +19 -3
  70. package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
  71. package/lib/commonjs/specs/NativeDdRum.js +19 -3
  72. package/lib/commonjs/specs/NativeDdRum.js.map +1 -1
  73. package/lib/commonjs/specs/NativeDdSdk.js +19 -3
  74. package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
  75. package/lib/commonjs/specs/NativeDdTrace.js +19 -3
  76. package/lib/commonjs/specs/NativeDdTrace.js.map +1 -1
  77. package/lib/commonjs/trace/DdTrace.js +4 -2
  78. package/lib/commonjs/trace/DdTrace.js.map +1 -1
  79. package/lib/commonjs/utils/stringUtils.js +48 -0
  80. package/lib/commonjs/utils/stringUtils.js.map +1 -0
  81. package/lib/commonjs/version.js +1 -1
  82. package/lib/module/DdSdkReactNative.js +6 -1
  83. package/lib/module/DdSdkReactNative.js.map +1 -1
  84. package/lib/module/config/FileBasedConfiguration.js +2 -0
  85. package/lib/module/config/FileBasedConfiguration.js.map +1 -1
  86. package/lib/module/config/async/AutoInstrumentationConfiguration.js +2 -1
  87. package/lib/module/config/async/AutoInstrumentationConfiguration.js.map +1 -1
  88. package/lib/module/config/features/RumConfiguration.js +4 -0
  89. package/lib/module/config/features/RumConfiguration.js.map +1 -1
  90. package/lib/module/flags/DdFlags.js +4 -2
  91. package/lib/module/flags/DdFlags.js.map +1 -1
  92. package/lib/module/flags/FlagsClient.js +5 -2
  93. package/lib/module/flags/FlagsClient.js.map +1 -1
  94. package/lib/module/internal.js +27 -0
  95. package/lib/module/internal.js.map +1 -0
  96. package/lib/module/logs/DdLogs.js +4 -2
  97. package/lib/module/logs/DdLogs.js.map +1 -1
  98. package/lib/module/rum/DdRum.js +4 -2
  99. package/lib/module/rum/DdRum.js.map +1 -1
  100. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js +20 -14
  101. package/lib/module/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.js.map +1 -1
  102. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +5 -2
  103. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  104. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js +1 -1
  105. package/lib/module/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.js.map +1 -1
  106. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  107. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js +298 -0
  108. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.js.map +1 -0
  109. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js +268 -0
  110. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.js.map +1 -0
  111. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js +160 -0
  112. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.js.map +1 -0
  113. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js +30 -0
  114. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.js.map +1 -0
  115. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js +150 -0
  116. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.js.map +1 -0
  117. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js +51 -0
  118. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.js.map +1 -0
  119. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js +32 -0
  120. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.js.map +1 -0
  121. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js +32 -0
  122. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.js.map +1 -0
  123. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js +2 -0
  124. package/lib/module/rum/instrumentation/resourceTracking/headerCapture/types.js.map +1 -0
  125. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js +17 -2
  126. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.js.map +1 -1
  127. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js +25 -3
  128. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.js.map +1 -1
  129. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js +1 -34
  130. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.js.map +1 -1
  131. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js +3 -1
  132. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.js.map +1 -1
  133. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js +8 -2
  134. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.js.map +1 -1
  135. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js +79 -0
  136. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.js.map +1 -0
  137. package/lib/module/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.js.map +1 -1
  138. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js +2 -3
  139. package/lib/module/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.js.map +1 -1
  140. package/lib/module/sdk/DdSdkInternal.js +27 -22
  141. package/lib/module/sdk/DdSdkInternal.js.map +1 -1
  142. package/lib/module/specs/NativeDdFlags.js +14 -2
  143. package/lib/module/specs/NativeDdFlags.js.map +1 -1
  144. package/lib/module/specs/NativeDdLogs.js +14 -2
  145. package/lib/module/specs/NativeDdLogs.js.map +1 -1
  146. package/lib/module/specs/NativeDdRum.js +14 -2
  147. package/lib/module/specs/NativeDdRum.js.map +1 -1
  148. package/lib/module/specs/NativeDdSdk.js +14 -2
  149. package/lib/module/specs/NativeDdSdk.js.map +1 -1
  150. package/lib/module/specs/NativeDdTrace.js +14 -2
  151. package/lib/module/specs/NativeDdTrace.js.map +1 -1
  152. package/lib/module/trace/DdTrace.js +4 -2
  153. package/lib/module/trace/DdTrace.js.map +1 -1
  154. package/lib/module/utils/stringUtils.js +42 -0
  155. package/lib/module/utils/stringUtils.js.map +1 -0
  156. package/lib/module/version.js +1 -1
  157. package/lib/typescript/DdSdkReactNative.d.ts.map +1 -1
  158. package/lib/typescript/config/FileBasedConfiguration.d.ts.map +1 -1
  159. package/lib/typescript/config/FileBasedConfiguration.type.d.ts +2 -0
  160. package/lib/typescript/config/FileBasedConfiguration.type.d.ts.map +1 -1
  161. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts +3 -0
  162. package/lib/typescript/config/async/AutoInstrumentationConfiguration.d.ts.map +1 -1
  163. package/lib/typescript/config/features/RumConfiguration.d.ts +3 -1
  164. package/lib/typescript/config/features/RumConfiguration.d.ts.map +1 -1
  165. package/lib/typescript/config/features/RumConfiguration.type.d.ts +107 -0
  166. package/lib/typescript/config/features/RumConfiguration.type.d.ts.map +1 -1
  167. package/lib/typescript/flags/DdFlags.d.ts.map +1 -1
  168. package/lib/typescript/flags/FlagsClient.d.ts +1 -1
  169. package/lib/typescript/flags/FlagsClient.d.ts.map +1 -1
  170. package/lib/typescript/index.d.ts +1 -0
  171. package/lib/typescript/index.d.ts.map +1 -1
  172. package/lib/typescript/internal.d.ts +26 -0
  173. package/lib/typescript/internal.d.ts.map +1 -0
  174. package/lib/typescript/logs/DdLogs.d.ts +1 -1
  175. package/lib/typescript/logs/DdLogs.d.ts.map +1 -1
  176. package/lib/typescript/rum/DdRum.d.ts +1 -1
  177. package/lib/typescript/rum/DdRum.d.ts.map +1 -1
  178. package/lib/typescript/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.d.ts.map +1 -1
  179. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +3 -1
  180. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts.map +1 -1
  181. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts +1 -0
  182. package/lib/typescript/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.d.ts.map +1 -1
  183. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts +85 -0
  184. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.d.ts.map +1 -0
  185. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts +18 -0
  186. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.d.ts.map +1 -0
  187. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts +24 -0
  188. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.d.ts.map +1 -0
  189. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts +12 -0
  190. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.d.ts.map +1 -0
  191. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts +28 -0
  192. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.d.ts.map +1 -0
  193. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts +16 -0
  194. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.d.ts.map +1 -0
  195. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts +13 -0
  196. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.d.ts.map +1 -0
  197. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts +13 -0
  198. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.d.ts.map +1 -0
  199. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts +27 -0
  200. package/lib/typescript/rum/instrumentation/resourceTracking/headerCapture/types.d.ts.map +1 -0
  201. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.d.ts.map +1 -1
  202. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.d.ts.map +1 -1
  203. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.d.ts.map +1 -1
  204. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts +2 -0
  205. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.d.ts.map +1 -1
  206. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts +43 -0
  207. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.d.ts.map +1 -0
  208. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts +2 -0
  209. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.d.ts.map +1 -1
  210. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts +2 -0
  211. package/lib/typescript/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.d.ts.map +1 -1
  212. package/lib/typescript/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.d.ts.map +1 -1
  213. package/lib/typescript/sdk/DdSdkInternal.d.ts +1 -0
  214. package/lib/typescript/sdk/DdSdkInternal.d.ts.map +1 -1
  215. package/lib/typescript/specs/NativeDdFlags.d.ts +7 -2
  216. package/lib/typescript/specs/NativeDdFlags.d.ts.map +1 -1
  217. package/lib/typescript/specs/NativeDdLogs.d.ts +7 -2
  218. package/lib/typescript/specs/NativeDdLogs.d.ts.map +1 -1
  219. package/lib/typescript/specs/NativeDdRum.d.ts +7 -2
  220. package/lib/typescript/specs/NativeDdRum.d.ts.map +1 -1
  221. package/lib/typescript/specs/NativeDdSdk.d.ts +7 -2
  222. package/lib/typescript/specs/NativeDdSdk.d.ts.map +1 -1
  223. package/lib/typescript/specs/NativeDdTrace.d.ts +7 -2
  224. package/lib/typescript/specs/NativeDdTrace.d.ts.map +1 -1
  225. package/lib/typescript/trace/DdTrace.d.ts.map +1 -1
  226. package/lib/typescript/utils/stringUtils.d.ts +12 -0
  227. package/lib/typescript/utils/stringUtils.d.ts.map +1 -0
  228. package/lib/typescript/version.d.ts +1 -1
  229. package/package.json +7 -2
  230. package/src/DdSdkReactNative.tsx +11 -1
  231. package/src/__tests__/DdSdkReactNative.test.tsx +145 -20
  232. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +3 -0
  233. package/src/__tests__/internalEntry.test.ts +26 -0
  234. package/src/__tests__/mock.test.ts +1 -3
  235. package/src/__tests__/nativeSpecGetters.test.ts +102 -0
  236. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +3 -3
  237. package/src/__tests__/wrapperImportSafety.test.ts +129 -0
  238. package/src/config/FileBasedConfiguration.ts +3 -0
  239. package/src/config/FileBasedConfiguration.type.ts +2 -0
  240. package/src/config/__tests__/FileBasedConfiguration.test.ts +66 -0
  241. package/src/config/__tests__/__fixtures__/configuration-all-fields.json +8 -0
  242. package/src/config/async/AutoInstrumentationConfiguration.ts +5 -1
  243. package/src/config/features/RumConfiguration.ts +9 -0
  244. package/src/config/features/RumConfiguration.type.ts +117 -0
  245. package/src/flags/DdFlags.ts +4 -3
  246. package/src/flags/FlagsClient.ts +4 -3
  247. package/src/index.tsx +7 -0
  248. package/src/internal.ts +32 -0
  249. package/src/logs/DdLogs.ts +4 -3
  250. package/src/rum/DdRum.ts +4 -3
  251. package/src/rum/__tests__/DdRum.test.ts +4 -4
  252. package/src/rum/instrumentation/interactionTracking/DdBabelInteractionTracking.ts +33 -26
  253. package/src/rum/instrumentation/interactionTracking/__tests__/BabelOptionalHandlers.test.ts +120 -0
  254. package/src/rum/instrumentation/interactionTracking/__tests__/DdBabelInteractionTracking.test.ts +82 -2
  255. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +7 -2
  256. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +46 -0
  257. package/src/rum/instrumentation/resourceTracking/__tests__/__utils__/XMLHttpRequestMock.ts +1 -1
  258. package/src/rum/instrumentation/resourceTracking/distributedTracing/firstPartyHosts.ts +1 -1
  259. package/src/rum/instrumentation/resourceTracking/headerCapture/README.md +142 -0
  260. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/captureHeaders.test.ts +853 -0
  261. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/compileHeaderConfig.test.ts +697 -0
  262. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.integration.test.ts +183 -0
  263. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/enforceSizeLimits.test.ts +337 -0
  264. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/isHeaderAllowed.test.ts +35 -0
  265. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/normalizeUrlForMatching.test.ts +176 -0
  266. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/parseResponseHeaders.test.ts +114 -0
  267. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/sensitiveHeaderBlocklist.test.ts +112 -0
  268. package/src/rum/instrumentation/resourceTracking/headerCapture/__tests__/tracingHeaderExclusion.test.ts +59 -0
  269. package/src/rum/instrumentation/resourceTracking/headerCapture/captureHeaders.ts +437 -0
  270. package/src/rum/instrumentation/resourceTracking/headerCapture/compileHeaderConfig.ts +339 -0
  271. package/src/rum/instrumentation/resourceTracking/headerCapture/enforceSizeLimits.ts +208 -0
  272. package/src/rum/instrumentation/resourceTracking/headerCapture/isHeaderAllowed.ts +29 -0
  273. package/src/rum/instrumentation/resourceTracking/headerCapture/normalizeUrlForMatching.ts +181 -0
  274. package/src/rum/instrumentation/resourceTracking/headerCapture/parseResponseHeaders.ts +59 -0
  275. package/src/rum/instrumentation/resourceTracking/headerCapture/sensitiveHeaderBlocklist.ts +31 -0
  276. package/src/rum/instrumentation/resourceTracking/headerCapture/tracingHeaderExclusion.ts +61 -0
  277. package/src/rum/instrumentation/resourceTracking/headerCapture/types.ts +33 -0
  278. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/FetchProxy.ts +21 -2
  279. package/src/rum/instrumentation/resourceTracking/requestProxy/FetchProxy/__tests__/FetchProxy.test.ts +274 -0
  280. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/DatadogRumResource/__tests__/ResourceReporter.test.ts +120 -0
  281. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/XHRProxy.ts +34 -3
  282. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/__tests__/XHRProxy.test.ts +624 -2
  283. package/src/rum/instrumentation/resourceTracking/requestProxy/XHRProxy/baggageHeaderUtils.ts +1 -34
  284. package/src/rum/instrumentation/resourceTracking/requestProxy/common/RequestContext.ts +6 -1
  285. package/src/rum/instrumentation/resourceTracking/requestProxy/common/ResourceReporter.ts +16 -2
  286. package/src/rum/instrumentation/resourceTracking/requestProxy/common/__tests__/headerCapture.test.ts +164 -0
  287. package/src/rum/instrumentation/resourceTracking/requestProxy/common/headerCapture.ts +119 -0
  288. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RequestProxy.ts +2 -0
  289. package/src/rum/instrumentation/resourceTracking/requestProxy/interfaces/RumResource.ts +2 -0
  290. package/src/sdk/DatadogEventEmitter/DatadogDefaultEventEmitter.tsx +3 -4
  291. package/src/sdk/DatadogInternalBridge/__tests__/DdSdkNativeBridge.test.tsx +35 -2
  292. package/src/sdk/DatadogProvider/Buffer/__tests__/BoundedBuffer.test.ts +5 -5
  293. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +2 -1
  294. package/src/sdk/DdSdkInternal.ts +27 -24
  295. package/src/sdk/EventMappers/__tests__/EventMapper.test.ts +2 -2
  296. package/src/specs/NativeDdFlags.ts +14 -2
  297. package/src/specs/NativeDdLogs.ts +14 -2
  298. package/src/specs/NativeDdRum.ts +14 -2
  299. package/src/specs/NativeDdSdk.ts +14 -2
  300. package/src/specs/NativeDdTrace.ts +14 -2
  301. package/src/trace/DdTrace.ts +4 -3
  302. package/src/utils/__tests__/stringUtils.test.ts +90 -0
  303. package/src/utils/stringUtils.ts +41 -0
  304. package/src/version.ts +1 -1
@@ -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
  });