@datadog/mobile-react-native 1.3.0 → 1.4.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 (99) hide show
  1. package/DatadogSDKReactNative.podspec +2 -2
  2. package/android/build.gradle +58 -64
  3. package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +36 -2
  4. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +14 -0
  5. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +162 -16
  6. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +7 -0
  7. package/ios/Sources/DdSdk.swift +2 -2
  8. package/ios/Sources/RNDdSdkConfiguration.swift +42 -0
  9. package/lib/commonjs/DdSdkReactNative.js +2 -2
  10. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  11. package/lib/commonjs/DdSdkReactNativeConfiguration.js +26 -1
  12. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  13. package/lib/commonjs/index.js +12 -0
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +9 -0
  16. package/lib/commonjs/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  17. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +1 -1
  18. package/lib/commonjs/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  19. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js +59 -41
  20. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  21. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +136 -0
  22. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  23. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +39 -6
  24. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  25. package/lib/commonjs/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  26. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  27. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  28. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +12 -21
  29. package/lib/commonjs/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  30. package/lib/commonjs/rum/types.js +19 -1
  31. package/lib/commonjs/rum/types.js.map +1 -1
  32. package/lib/commonjs/version.js +1 -1
  33. package/lib/commonjs/version.js.map +1 -1
  34. package/lib/module/DdSdkReactNative.js +3 -3
  35. package/lib/module/DdSdkReactNative.js.map +1 -1
  36. package/lib/module/DdSdkReactNativeConfiguration.js +22 -0
  37. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  38. package/lib/module/index.js +3 -3
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js +9 -0
  41. package/lib/module/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.js.map +1 -1
  42. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js +2 -2
  43. package/lib/module/rum/instrumentation/resourceTracking/DdRumResourceTracking.js.map +1 -1
  44. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js +57 -35
  45. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracing.js.map +1 -1
  46. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js +115 -0
  47. package/lib/module/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.js.map +1 -0
  48. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js +37 -3
  49. package/lib/module/rum/instrumentation/resourceTracking/domain/firstPartyHosts.js.map +1 -1
  50. package/lib/module/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.js.map +1 -1
  51. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js +3 -3
  52. package/lib/module/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.js.map +1 -1
  53. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js +10 -15
  54. package/lib/module/rum/instrumentation/resourceTracking/implementation/XHRProxy.js.map +1 -1
  55. package/lib/module/rum/types.js +16 -0
  56. package/lib/module/rum/types.js.map +1 -1
  57. package/lib/module/version.js +1 -1
  58. package/lib/module/version.js.map +1 -1
  59. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +11 -3
  60. package/lib/typescript/index.d.ts +3 -3
  61. package/lib/typescript/rum/eventMappers/resourceEventMapper.d.ts +0 -1
  62. package/lib/typescript/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.d.ts +1 -0
  63. package/lib/typescript/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +2 -1
  64. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +32 -6
  65. package/lib/typescript/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.d.ts +21 -0
  66. package/lib/typescript/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +4 -2
  67. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +6 -1
  68. package/lib/typescript/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +0 -1
  69. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +0 -6
  70. package/lib/typescript/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +0 -1
  71. package/lib/typescript/rum/types.d.ts +17 -0
  72. package/lib/typescript/version.d.ts +1 -1
  73. package/package.json +2 -2
  74. package/src/DdSdkReactNative.tsx +8 -4
  75. package/src/DdSdkReactNativeConfiguration.tsx +36 -3
  76. package/src/__tests__/DdSdkReactNative.test.tsx +16 -4
  77. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +7 -6
  78. package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +2 -1
  79. package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +130 -114
  80. package/src/index.tsx +6 -3
  81. package/src/rum/__tests__/DdRum.test.ts +17 -1
  82. package/src/rum/instrumentation/interactionTracking/DdRumUserInteractionTracking.tsx +8 -0
  83. package/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.tsx +6 -3
  84. package/src/rum/instrumentation/resourceTracking/__tests__/DdRumResourceTracking.test.ts +15 -3
  85. package/src/rum/instrumentation/resourceTracking/domain/__tests__/distributedTracing.test.ts +64 -24
  86. package/src/rum/instrumentation/resourceTracking/domain/__tests__/firstPartyHosts.test.ts +19 -7
  87. package/src/rum/instrumentation/resourceTracking/domain/distributedTracing.tsx +82 -40
  88. package/src/rum/instrumentation/resourceTracking/domain/distributedTracingHeaders.ts +141 -0
  89. package/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.ts +43 -7
  90. package/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.ts +8 -1
  91. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.ts +4 -4
  92. package/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/__tests__/ResourceReporter.test.ts +2 -1
  93. package/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.ts +8 -23
  94. package/src/rum/instrumentation/resourceTracking/implementation/__tests__/XHRProxy.test.ts +257 -74
  95. package/src/rum/types.ts +19 -0
  96. package/src/sdk/DatadogProvider/Buffer/__tests__/BufferSingleton.test.ts +2 -1
  97. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -4
  98. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +6 -2
  99. package/src/version.ts +1 -1
@@ -17,8 +17,8 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/Sources/*.{h,m,mm,swift}"
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency 'DatadogSDK', '~> 1.14.0'
21
- s.dependency 'DatadogSDKCrashReporting', '~> 1.14.0'
20
+ s.dependency 'DatadogSDK', '~> 1.15.0'
21
+ s.dependency 'DatadogSDKCrashReporting', '~> 1.15.0'
22
22
 
23
23
  s.test_spec 'Tests' do |test_spec|
24
24
  test_spec.source_files = 'ios/Tests/*.swift'
@@ -25,6 +25,46 @@ apply plugin: 'kotlin-android'
25
25
  apply plugin: 'org.jlleitschuh.gradle.ktlint'
26
26
  apply plugin: "io.gitlab.arturbosch.detekt"
27
27
 
28
+ def resolveReactNativeDirectory() {
29
+ def reactNativeLocation = rootProject.hasProperty("reactNativeDir") ? rootProject.getProperty("reactNativeDir") : null
30
+
31
+ if (reactNativeLocation != null) {
32
+ return file(reactNativeLocation)
33
+ }
34
+
35
+ try {
36
+ // Resolve React Native location with Node
37
+ // This will make sure that we get installation location correctly in monorepos
38
+ def reactNativePackageJsonPathStdout = new ByteArrayOutputStream()
39
+
40
+ exec {
41
+ commandLine("node", "-p", "require.resolve('react-native/package.json')")
42
+ ignoreExitValue true
43
+ standardOutput = reactNativePackageJsonPathStdout
44
+ }
45
+
46
+ def reactNativeFromProjectNodeModules = file(reactNativePackageJsonPathStdout.toString().trim()).getParentFile();
47
+
48
+ if (reactNativeFromProjectNodeModules.exists()) {
49
+ return reactNativeFromProjectNodeModules
50
+ }
51
+ } catch (e) {
52
+ // Ignore
53
+ }
54
+
55
+ throw new Exception(
56
+ "${project.name}: Failed to resolve 'react-native' in the project. " +
57
+ "Altenatively, you can specify 'reactNativeDir' with the path to 'react-native' in your 'gradle.properties' file."
58
+ )
59
+ }
60
+
61
+ def reactNativeRootDir = resolveReactNativeDirectory()
62
+ def reactProperties = new Properties()
63
+ file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
64
+
65
+ def reactNativeVersion = reactProperties.getProperty("VERSION_NAME")
66
+ def (reactNativeMajorVersion, reactNativeMinorVersion) = reactNativeVersion.split("\\.").collect { it.isInteger() ? it.toInteger() : it }
67
+
28
68
  def getExtOrDefault(name) {
29
69
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['DdSdkReactNative_' + name]
30
70
  }
@@ -78,81 +118,35 @@ repositories {
78
118
  maven { url "https://jitpack.io" }
79
119
  mavenLocal()
80
120
 
81
- def found = false
82
- def defaultDir = null
83
- def androidSourcesName = 'React Native sources'
84
-
85
- if (rootProject.ext.has('reactNativeAndroidRoot')) {
86
- defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
87
- } else {
88
- defaultDir = new File(
89
- projectDir,
90
- '/../../../node_modules/react-native/android'
91
- )
92
- }
93
-
94
- if (defaultDir.exists()) {
95
- maven {
96
- url defaultDir.toString()
97
- name androidSourcesName
98
- }
121
+ if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
122
+ def androidSourcesDir = file("$reactNativeRootDir/android")
123
+ def androidSourcesName = "React Native sources"
99
124
 
100
- logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
101
- found = true
102
- } else {
103
- def parentDir = rootProject.projectDir
104
-
105
- 1.upto(5, {
106
- if (found) return true
107
- parentDir = parentDir.parentFile
108
-
109
- def androidSourcesDir = new File(
110
- parentDir,
111
- 'node_modules/react-native'
112
- )
113
-
114
- def androidPrebuiltBinaryDir = new File(
115
- parentDir,
116
- 'node_modules/react-native/android'
117
- )
118
-
119
- if (androidPrebuiltBinaryDir.exists()) {
120
- maven {
121
- url androidPrebuiltBinaryDir.toString()
122
- name androidSourcesName
123
- }
124
-
125
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
126
- found = true
127
- } else if (androidSourcesDir.exists()) {
128
- maven {
129
- url androidSourcesDir.toString()
130
- name androidSourcesName
131
- }
132
-
133
- logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
134
- found = true
125
+ if (androidSourcesDir.exists()) {
126
+ maven {
127
+ url androidSourcesDir.toString()
128
+ name androidSourcesName
135
129
  }
136
- })
137
- }
138
-
139
- if (!found) {
140
- throw new GradleException(
141
- "${project.name}: unable to locate React Native android sources. " +
142
- "Ensure you have you installed React Native as a dependency in your project and try again."
143
- )
130
+ }
144
131
  }
145
132
  }
146
133
 
147
134
  def kotlin_version = getExtOrDefault('kotlinVersion')
148
135
 
149
136
  dependencies {
150
- // noinspection GradleDynamicVersion
151
- api 'com.facebook.react:react-native:+'
137
+ if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
138
+ // noinspection GradleDynamicVersion
139
+ api 'com.facebook.react:react-native:+'
140
+ } else {
141
+ // We specify the $reactNativeVersion, like it's done on the react-native-gradle-plugin, as the plugin is not applied in tests.
142
+ // There is no impact for apps as we apply the same logic:
143
+ // https://github.com/facebook/react-native/blob/e1a1e6aa8030bf11d691c3dcf7abd13b25175027/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/utils/DependencyUtils.kt
144
+ api "com.facebook.react:react-android:$reactNativeVersion"
145
+ }
152
146
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
153
147
  compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
154
148
 
155
- implementation "com.datadoghq:dd-sdk-android:1.16.0"
149
+ implementation "com.datadoghq:dd-sdk-android:1.17.0"
156
150
  testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
157
151
  testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
158
152
  testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
@@ -24,10 +24,12 @@ import com.datadog.android.rum.model.ActionEvent
24
24
  import com.datadog.android.rum.model.ResourceEvent
25
25
  import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
26
26
  import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
27
+ import com.datadog.android.tracing.TracingHeaderType
27
28
  import com.facebook.react.bridge.Promise
28
29
  import com.facebook.react.bridge.ReactApplicationContext
29
30
  import com.facebook.react.bridge.ReactContextBaseJavaModule
30
31
  import com.facebook.react.bridge.ReactMethod
32
+ import com.facebook.react.bridge.ReadableArray
31
33
  import com.facebook.react.bridge.ReadableMap
32
34
  import java.net.InetSocketAddress
33
35
  import java.net.Proxy
@@ -220,10 +222,14 @@ class DdSdk(
220
222
  configBuilder.disableInteractionTracking()
221
223
  }
222
224
 
225
+ @Suppress("UNCHECKED_CAST")
223
226
  val firstPartyHosts =
224
- (configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? List<String>)
227
+ (configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray)
228
+ ?.toArrayList() as? List<ReadableMap>
225
229
  if (firstPartyHosts != null) {
226
- configBuilder.setFirstPartyHosts(firstPartyHosts)
230
+ val firstPartyHostsWithHeaderTypes = buildFirstPartyHosts(firstPartyHosts)
231
+
232
+ configBuilder.setFirstPartyHostsWithHeaderType(firstPartyHostsWithHeaderTypes)
227
233
  }
228
234
 
229
235
  buildProxyConfiguration(configuration)?.let { (proxy, authenticator) ->
@@ -281,6 +287,34 @@ class DdSdk(
281
287
  return configBuilder.build()
282
288
  }
283
289
 
290
+ private fun buildFirstPartyHosts(
291
+ firstPartyHosts: List<ReadableMap>
292
+ ): Map<String, Set<TracingHeaderType>> {
293
+ /**
294
+ * Adapts the data format from the React Native SDK configuration to match with the
295
+ * Android SDK configuration. For example:
296
+ *
297
+ * RN config: [{ match: "example.com", propagatorTypes: [DATADOG, B3] }]
298
+ * Android config: { "example.com": [DATADOG, B3] }
299
+ */
300
+ val firstPartyHostsWithHeaderTypes = mutableMapOf<String, MutableSet<TracingHeaderType>>()
301
+
302
+ firstPartyHosts.forEach {
303
+ val match = it.getString("match")
304
+ val propagatorTypes = it.getArray("propagatorTypes")?.asTracingHeaderTypes()
305
+ if (match != null && propagatorTypes != null && propagatorTypes.isNotEmpty()) {
306
+ val hostMatch = firstPartyHostsWithHeaderTypes[match]
307
+ if (hostMatch != null) {
308
+ hostMatch.addAll(propagatorTypes)
309
+ } else {
310
+ firstPartyHostsWithHeaderTypes[match] = propagatorTypes.toMutableSet()
311
+ }
312
+ }
313
+ }
314
+
315
+ return firstPartyHostsWithHeaderTypes
316
+ }
317
+
284
318
  private fun buildCredentials(configuration: DdSdkConfiguration): Credentials {
285
319
  val serviceName = configuration.additionalConfig?.get(DD_SERVICE_NAME) as? String
286
320
  return Credentials(
@@ -6,6 +6,8 @@
6
6
 
7
7
  package com.datadog.reactnative
8
8
 
9
+ import com.datadog.android.tracing.TracingHeaderType
10
+ import com.facebook.react.bridge.ReadableArray
9
11
  import com.facebook.react.bridge.ReadableMap
10
12
  import com.facebook.react.bridge.WritableNativeMap
11
13
 
@@ -38,6 +40,18 @@ internal fun ReadableMap.asConfigurationForTelemetry(): ConfigurationForTelemetr
38
40
  )
39
41
  }
40
42
 
43
+ internal fun ReadableArray.asTracingHeaderTypes(): Set<TracingHeaderType> {
44
+ return this.toArrayList().mapNotNull {
45
+ when (it) {
46
+ "datadog" -> TracingHeaderType.DATADOG
47
+ "b3" -> TracingHeaderType.B3
48
+ "b3multi" -> TracingHeaderType.B3MULTI
49
+ "tracecontext" -> TracingHeaderType.TRACECONTEXT
50
+ else -> null
51
+ }
52
+ }.toSet()
53
+ }
54
+
41
55
  @Suppress("ComplexMethod")
42
56
  internal fun DdSdkConfiguration.toReadableMap(): ReadableMap {
43
57
  val map = WritableNativeMap()
@@ -26,14 +26,17 @@ import com.datadog.android.rum.model.ActionEvent
26
26
  import com.datadog.android.rum.model.ResourceEvent
27
27
  import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy
28
28
  import com.datadog.android.telemetry.model.TelemetryConfigurationEvent
29
+ import com.datadog.android.tracing.TracingHeaderType
29
30
  import com.datadog.tools.unit.GenericAssert.Companion.assertThat
30
31
  import com.datadog.tools.unit.forge.BaseConfigurator
31
32
  import com.datadog.tools.unit.getStaticValue
32
33
  import com.datadog.tools.unit.setStaticValue
34
+ import com.datadog.tools.unit.toReadableArray
33
35
  import com.datadog.tools.unit.toReadableJavaOnlyMap
34
36
  import com.datadog.tools.unit.toReadableMap
35
37
  import com.facebook.react.bridge.Promise
36
38
  import com.facebook.react.bridge.ReactApplicationContext
39
+ import com.facebook.react.bridge.ReadableMap
37
40
  import com.nhaarman.mockitokotlin2.any
38
41
  import com.nhaarman.mockitokotlin2.argumentCaptor
39
42
  import com.nhaarman.mockitokotlin2.doNothing
@@ -178,7 +181,7 @@ internal class DdSdkTest {
178
181
  assertThat(configCaptor.firstValue)
179
182
  .hasField("coreConfig") {
180
183
  it.hasFieldEqualTo("needsClearTextHttp", false)
181
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
184
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
182
185
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
183
186
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
184
187
  }
@@ -228,7 +231,7 @@ internal class DdSdkTest {
228
231
  assertThat(configCaptor.firstValue)
229
232
  .hasField("coreConfig") {
230
233
  it.hasFieldEqualTo("needsClearTextHttp", false)
231
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
234
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
232
235
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
233
236
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
234
237
  }
@@ -276,7 +279,7 @@ internal class DdSdkTest {
276
279
  assertThat(configCaptor.firstValue)
277
280
  .hasField("coreConfig") {
278
281
  it.hasFieldEqualTo("needsClearTextHttp", false)
279
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
282
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
280
283
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
281
284
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
282
285
  }
@@ -328,7 +331,7 @@ internal class DdSdkTest {
328
331
  assertThat(configCaptor.firstValue)
329
332
  .hasField("coreConfig") {
330
333
  it.hasFieldEqualTo("needsClearTextHttp", false)
331
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
334
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
332
335
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
333
336
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
334
337
  }
@@ -380,7 +383,7 @@ internal class DdSdkTest {
380
383
  assertThat(configCaptor.firstValue)
381
384
  .hasField("coreConfig") {
382
385
  it.hasFieldEqualTo("needsClearTextHttp", false)
383
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
386
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
384
387
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
385
388
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
386
389
  }
@@ -432,7 +435,7 @@ internal class DdSdkTest {
432
435
  assertThat(configCaptor.firstValue)
433
436
  .hasField("coreConfig") {
434
437
  it.hasFieldEqualTo("needsClearTextHttp", false)
435
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
438
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
436
439
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
437
440
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
438
441
  }
@@ -475,7 +478,7 @@ internal class DdSdkTest {
475
478
  assertThat(configCaptor.firstValue)
476
479
  .hasField("coreConfig") {
477
480
  it.hasFieldEqualTo("needsClearTextHttp", false)
478
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
481
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
479
482
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
480
483
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
481
484
  }
@@ -528,7 +531,7 @@ internal class DdSdkTest {
528
531
  assertThat(configCaptor.firstValue)
529
532
  .hasField("coreConfig") {
530
533
  it.hasFieldEqualTo("needsClearTextHttp", false)
531
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
534
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
532
535
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
533
536
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
534
537
  }
@@ -585,7 +588,7 @@ internal class DdSdkTest {
585
588
  assertThat(configCaptor.firstValue)
586
589
  .hasField("coreConfig") {
587
590
  it.hasFieldEqualTo("needsClearTextHttp", false)
588
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
591
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
589
592
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
590
593
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
591
594
  }
@@ -642,7 +645,7 @@ internal class DdSdkTest {
642
645
  assertThat(configCaptor.firstValue)
643
646
  .hasField("coreConfig") {
644
647
  it.hasFieldEqualTo("needsClearTextHttp", false)
645
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
648
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
646
649
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
647
650
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
648
651
  }
@@ -699,7 +702,7 @@ internal class DdSdkTest {
699
702
  assertThat(configCaptor.firstValue)
700
703
  .hasField("coreConfig") {
701
704
  it.hasFieldEqualTo("needsClearTextHttp", false)
702
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
705
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
703
706
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
704
707
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
705
708
  }
@@ -756,7 +759,7 @@ internal class DdSdkTest {
756
759
  assertThat(configCaptor.firstValue)
757
760
  .hasField("coreConfig") {
758
761
  it.hasFieldEqualTo("needsClearTextHttp", false)
759
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
762
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
760
763
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
761
764
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
762
765
  }
@@ -813,7 +816,7 @@ internal class DdSdkTest {
813
816
  assertThat(configCaptor.firstValue)
814
817
  .hasField("coreConfig") {
815
818
  it.hasFieldEqualTo("needsClearTextHttp", false)
816
- it.hasFieldEqualTo("firstPartyHosts", emptyList<String>())
819
+ it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap<String, String>())
817
820
  it.hasFieldEqualTo("batchSize", BatchSize.MEDIUM)
818
821
  it.hasFieldEqualTo("uploadFrequency", UploadFrequency.AVERAGE)
819
822
  }
@@ -1287,12 +1290,152 @@ internal class DdSdkTest {
1287
1290
  @Forgery configuration: DdSdkConfiguration,
1288
1291
  forge: Forge
1289
1292
  ) {
1290
- val firstPartyHosts = forge.aList { forge.aStringMatching("[a-z]+\\.[a-z]{3}") }
1293
+ val tracingHosts = forge.aMap {
1294
+ Pair(
1295
+ forge.aStringMatching("[a-z]+\\.[a-z]{3}"),
1296
+ forge.aSubSetOf(
1297
+ setOf(
1298
+ TracingHeaderType.DATADOG,
1299
+ TracingHeaderType.B3MULTI,
1300
+ TracingHeaderType.TRACECONTEXT,
1301
+ TracingHeaderType.B3
1302
+ ),
1303
+ anInt(1, 4)
1304
+ )
1305
+ )
1306
+ }
1307
+
1308
+ val firstPartyHosts = mutableListOf<ReadableMap>()
1309
+ tracingHosts.forEach { (match, headerTypes) ->
1310
+ firstPartyHosts.add(
1311
+ mapOf(
1312
+ "match" to match,
1313
+ "propagatorTypes" to headerTypes.map {
1314
+ it.name.lowercase()
1315
+ }.toReadableArray()
1316
+ ).toReadableMap()
1317
+ )
1318
+ }
1319
+
1320
+ // Given
1321
+ val bridgeConfiguration = configuration.copy(
1322
+ additionalConfig = mapOf(
1323
+ DdSdk.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
1324
+ )
1325
+ )
1326
+ val configCaptor = argumentCaptor<Configuration>()
1327
+
1328
+ // When
1329
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1330
+
1331
+ // Then
1332
+ verify(mockDatadog).initialize(
1333
+ same(mockContext),
1334
+ any(),
1335
+ configCaptor.capture(),
1336
+ eq(configuration.trackingConsent.asTrackingConsent())
1337
+ )
1338
+ assertThat(configCaptor.firstValue)
1339
+ .hasField("coreConfig") { coreConfig ->
1340
+ coreConfig.hasFieldEqualTo(
1341
+ "firstPartyHostsWithHeaderTypes",
1342
+ tracingHosts
1343
+ )
1344
+ }
1345
+ }
1346
+
1347
+ @Test
1348
+ fun `𝕄 set first party hosts 𝕎 initialize() {wrong first party hosts}`(
1349
+ @Forgery configuration: DdSdkConfiguration,
1350
+ forge: Forge
1351
+ ) {
1352
+ val tracingHosts = forge.aMap {
1353
+ Pair(
1354
+ forge.aStringMatching("[a-z]+\\.[a-z]{3}"),
1355
+ setOf(
1356
+ TracingHeaderType.DATADOG,
1357
+ )
1358
+ )
1359
+ }
1360
+
1361
+ val firstPartyHosts = mutableListOf<ReadableMap>()
1362
+ tracingHosts.forEach { (match) ->
1363
+ firstPartyHosts.add(
1364
+ mapOf(
1365
+ "match" to match,
1366
+ "propagatorTypes" to listOf(
1367
+ TracingHeaderType.DATADOG.name.lowercase(),
1368
+ forge.aString()
1369
+ ).toReadableArray()
1370
+ ).toReadableMap()
1371
+ )
1372
+ }
1373
+
1374
+ // Given
1375
+ val bridgeConfiguration = configuration.copy(
1376
+ additionalConfig = mapOf(
1377
+ DdSdk.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
1378
+ )
1379
+ )
1380
+ val configCaptor = argumentCaptor<Configuration>()
1381
+
1382
+ // When
1383
+ testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
1384
+
1385
+ // Then
1386
+ verify(mockDatadog).initialize(
1387
+ same(mockContext),
1388
+ any(),
1389
+ configCaptor.capture(),
1390
+ eq(configuration.trackingConsent.asTrackingConsent())
1391
+ )
1392
+ assertThat(configCaptor.firstValue)
1393
+ .hasField("coreConfig") { coreConfig ->
1394
+ coreConfig.hasFieldEqualTo(
1395
+ "firstPartyHostsWithHeaderTypes",
1396
+ tracingHosts
1397
+ )
1398
+ }
1399
+ }
1400
+
1401
+ @Test
1402
+ fun `𝕄 set first party hosts 𝕎 initialize() {duplicated first party hosts}`(
1403
+ @Forgery configuration: DdSdkConfiguration,
1404
+ forge: Forge
1405
+ ) {
1406
+ val host = forge.aStringMatching("[a-z]+\\.[a-z]{3}")
1407
+ val tracingHosts = mapOf(
1408
+ Pair(
1409
+ host,
1410
+ setOf(
1411
+ TracingHeaderType.DATADOG,
1412
+ TracingHeaderType.B3,
1413
+ )
1414
+ ),
1415
+ )
1416
+
1417
+ val firstPartyHosts = mutableListOf<ReadableMap>()
1418
+ firstPartyHosts.add(
1419
+ mapOf(
1420
+ "match" to host,
1421
+ "propagatorTypes" to listOf(
1422
+ TracingHeaderType.DATADOG.name.lowercase(),
1423
+ ).toReadableArray()
1424
+ ).toReadableMap()
1425
+ )
1426
+ firstPartyHosts.add(
1427
+ mapOf(
1428
+ "match" to host,
1429
+ "propagatorTypes" to listOf(
1430
+ TracingHeaderType.B3.name.lowercase(),
1431
+ ).toReadableArray()
1432
+ ).toReadableMap()
1433
+ )
1291
1434
 
1292
1435
  // Given
1293
1436
  val bridgeConfiguration = configuration.copy(
1294
1437
  additionalConfig = mapOf(
1295
- DdSdk.DD_FIRST_PARTY_HOSTS to firstPartyHosts
1438
+ DdSdk.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
1296
1439
  )
1297
1440
  )
1298
1441
  val configCaptor = argumentCaptor<Configuration>()
@@ -1309,7 +1452,10 @@ internal class DdSdkTest {
1309
1452
  )
1310
1453
  assertThat(configCaptor.firstValue)
1311
1454
  .hasField("coreConfig") { coreConfig ->
1312
- coreConfig.hasFieldEqualTo("firstPartyHosts", firstPartyHosts)
1455
+ coreConfig.hasFieldEqualTo(
1456
+ "firstPartyHostsWithHeaderTypes",
1457
+ tracingHosts
1458
+ )
1313
1459
  }
1314
1460
  }
1315
1461
 
@@ -6,7 +6,9 @@
6
6
 
7
7
  package com.datadog.tools.unit
8
8
 
9
+ import com.facebook.react.bridge.JavaOnlyArray
9
10
  import com.facebook.react.bridge.JavaOnlyMap
11
+ import com.facebook.react.bridge.ReadableArray
10
12
  import com.facebook.react.bridge.ReadableMap
11
13
 
12
14
  fun Map<*, *>.toReadableMap(): ReadableMap {
@@ -20,3 +22,8 @@ fun Map<*, *>.toReadableMap(): ReadableMap {
20
22
  // this FB implementation is not backed by Android-specific .so library, so ok for unit tests
21
23
  return JavaOnlyMap.of(*keysAndValues.toTypedArray())
22
24
  }
25
+
26
+ fun List<*>.toReadableArray(): ReadableArray {
27
+ // this FB implementation is not backed by Android-specific .so library, so ok for unit tests
28
+ return JavaOnlyArray.from(this)
29
+ }
@@ -205,8 +205,8 @@ class RNDdSdk: NSObject {
205
205
  _ = ddConfigBuilder.set(serviceName: serviceName)
206
206
  }
207
207
 
208
- if let firstPartyHosts = additionalConfig?[InternalConfigurationAttributes.firstPartyHosts] as? [String] {
209
- _ = ddConfigBuilder.trackURLSession(firstPartyHosts: Set(firstPartyHosts))
208
+ if let firstPartyHosts = additionalConfig?[InternalConfigurationAttributes.firstPartyHosts] as? NSArray {
209
+ _ = ddConfigBuilder.trackURLSession(firstPartyHostsWithHeaderTypes: firstPartyHosts.asFirstPartyHosts())
210
210
  }
211
211
 
212
212
  if let proxyConfiguration = buildProxyConfiguration(config: additionalConfig) {
@@ -4,6 +4,7 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ import Datadog
7
8
  import Foundation
8
9
 
9
10
  extension NSDictionary {
@@ -53,3 +54,44 @@ extension NSDictionary {
53
54
  )
54
55
  }
55
56
  }
57
+
58
+ extension NSArray {
59
+ /*
60
+ * Adapts the data format from the React Native SDK configuration to match with the
61
+ * iOS SDK configuration. For example:
62
+ *
63
+ * RN config: [{ match: "example.com", propagatorTypes: [DATADOG, B3] }]
64
+ * iOS config: { "example.com": [DATADOG, B3] }
65
+ */
66
+ func asFirstPartyHosts() -> [String: Set<TracingHeaderType>] {
67
+ return reduce(into: [:], { firstPartyHosts, h in
68
+ let host = (h as? NSDictionary)
69
+
70
+ if let match = (host?.value(forKey: "match") as? String),
71
+ let propagatorTypes = (host?.value(forKey: "propagatorTypes") as? NSArray) {
72
+ if let hostPropagatorTypes = firstPartyHosts[match] {
73
+ firstPartyHosts[match] = hostPropagatorTypes.union(propagatorTypes.asTracingHeaderType())
74
+ } else {
75
+ firstPartyHosts[match] = propagatorTypes.asTracingHeaderType()
76
+ }
77
+ }
78
+ })
79
+ }
80
+
81
+ func asTracingHeaderType() -> Set<TracingHeaderType> {
82
+ return Set(compactMap { headerType in
83
+ switch(headerType as? String) {
84
+ case "datadog":
85
+ return TracingHeaderType.datadog
86
+ case "b3":
87
+ return TracingHeaderType.b3
88
+ case "b3multi":
89
+ return TracingHeaderType.b3multi
90
+ case "tracecontext":
91
+ return TracingHeaderType.tracecontext
92
+ default:
93
+ return nil
94
+ }
95
+ })
96
+ }
97
+ }
@@ -156,7 +156,7 @@ class DdSdkReactNative {
156
156
  if (configuration.trackResources) {
157
157
  _DdRumResourceTracking.DdRumResourceTracking.startTracking({
158
158
  tracingSamplingRate: configuration.resourceTracingSamplingRate,
159
- firstPartyHosts: configuration.firstPartyHosts
159
+ firstPartyHosts: (0, _DdSdkReactNativeConfiguration.formatFirstPartyHosts)(configuration.firstPartyHosts)
160
160
  });
161
161
  }
162
162
 
@@ -299,6 +299,6 @@ _defineProperty(DdSdkReactNative, "buildConfiguration", configuration => {
299
299
  configuration.additionalConfig[DdSdkReactNative.DD_VERSION_SUFFIX] = `-${configuration.versionSuffix}`;
300
300
  }
301
301
 
302
- configuration.additionalConfig['_dd.first_party_hosts'] = configuration.firstPartyHosts;
302
+ configuration.additionalConfig['_dd.first_party_hosts'] = (0, _DdSdkReactNativeConfiguration.formatFirstPartyHosts)(configuration.firstPartyHosts);
303
303
  });
304
304
  //# sourceMappingURL=DdSdkReactNative.js.map