@datadog/mobile-react-native 2.2.0 → 2.3.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.
- package/DatadogSDKReactNative.podspec +2 -1
- package/android/build.gradle +1 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +2 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +11 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +5 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +64 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +164 -4
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +6 -354
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +351 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +5 -3
- package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +10 -0
- package/android/src/main/kotlin/com/datadog/reactnative/JSONFileReader.kt +20 -0
- package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +4 -1
- package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +10 -0
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +3 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -2
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +3 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkConfigurationTest.kt +196 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +181 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +12 -271
- package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +10 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +28 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +24 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +9 -1
- package/android/src/test/resources/input/complete-configuration.json +48 -0
- package/android/src/test/resources/input/malformed-configuration.json +5 -0
- package/android/src/test/resources/input/minimal-configuration.json +8 -0
- package/datadog-configuration.gradle +57 -0
- package/datadog-configuration.schema.json +200 -0
- package/ios/Sources/DatadogSDKWrapper.swift +16 -13
- package/ios/Sources/DdLogsImplementation.swift +14 -0
- package/ios/Sources/DdSdk.h +2 -0
- package/ios/Sources/DdSdk.mm +6 -1
- package/ios/Sources/DdSdkConfiguration.swift +47 -56
- package/ios/Sources/DdSdkImplementation.swift +10 -279
- package/ios/Sources/DdSdkNativeInitialization.swift +218 -0
- package/ios/Sources/DdTraceImplementation.swift +3 -1
- package/ios/Sources/GlobalState.swift +1 -1
- package/ios/Sources/JSONFileReader.swift +28 -0
- package/ios/Sources/RNDdSdkConfiguration.swift +227 -9
- package/ios/Sources/SdkVersion.swift +10 -0
- package/lib/commonjs/DdSdkReactNative.js +24 -66
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -4
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/ProxyConfiguration.js +15 -2
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js +2 -2
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js +214 -0
- package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/commonjs/types.js +10 -2
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +23 -65
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +22 -4
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/ProxyConfiguration.js +15 -2
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeModulesTypes.js +2 -2
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js +197 -0
- package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
- package/lib/module/types.js +10 -2
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +0 -9
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +43 -3
- package/lib/typescript/ProxyConfiguration.d.ts +4 -12
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/nativeModulesTypes.d.ts +2 -2
- package/lib/typescript/sdk/DatadogProvider/DatadogProvider.d.ts +2 -1
- package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +31 -0
- package/lib/typescript/types.d.ts +29 -3
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +7 -4
- package/src/DdSdkReactNative.tsx +58 -101
- package/src/DdSdkReactNativeConfiguration.tsx +26 -7
- package/src/ProxyConfiguration.tsx +17 -3
- package/src/__tests__/DdSdkReactNative.test.tsx +134 -112
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +19 -10
- package/src/__tests__/mock.test.ts +0 -9
- package/src/index.tsx +2 -0
- package/src/nativeModulesTypes.ts +1 -1
- package/src/sdk/DatadogProvider/DatadogProvider.tsx +3 -1
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +12 -5
- package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -2
- package/src/sdk/FileBasedConfiguration/FileBasedConfiguration.ts +235 -0
- package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +245 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/configuration-all-fields.json +22 -0
- package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/malformed-configuration.json +5 -0
- package/src/types.tsx +21 -2
- package/src/version.ts +1 -1
|
@@ -47,13 +47,10 @@ import fr.xgouchet.elmyr.annotation.StringForgery
|
|
|
47
47
|
import fr.xgouchet.elmyr.annotation.StringForgeryType
|
|
48
48
|
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
|
|
49
49
|
import fr.xgouchet.elmyr.junit5.ForgeExtension
|
|
50
|
-
import java.net.InetSocketAddress
|
|
51
|
-
import java.net.Proxy
|
|
52
50
|
import java.util.Locale
|
|
53
51
|
import java.util.stream.Stream
|
|
54
52
|
import org.assertj.core.api.Assertions.assertThat
|
|
55
53
|
import org.junit.jupiter.api.AfterEach
|
|
56
|
-
import org.junit.jupiter.api.Assumptions.assumeTrue
|
|
57
54
|
import org.junit.jupiter.api.BeforeEach
|
|
58
55
|
import org.junit.jupiter.api.Test
|
|
59
56
|
import org.junit.jupiter.api.extension.ExtendWith
|
|
@@ -97,7 +94,7 @@ fun mockChoreographerInstance(mock: Choreographer = mock()) {
|
|
|
97
94
|
ExtendWith(ForgeExtension::class)
|
|
98
95
|
)
|
|
99
96
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
|
100
|
-
@ForgeConfiguration(BaseConfigurator::class)
|
|
97
|
+
@ForgeConfiguration(value = BaseConfigurator::class)
|
|
101
98
|
internal class DdSdkTest {
|
|
102
99
|
|
|
103
100
|
lateinit var testedBridgeSdk: DdSdkImplementation
|
|
@@ -870,46 +867,13 @@ internal class DdSdkTest {
|
|
|
870
867
|
|
|
871
868
|
// endregion
|
|
872
869
|
|
|
873
|
-
@Test
|
|
874
|
-
fun `𝕄 initialize native SDK 𝕎 initialize() {no view tracking by default}`(
|
|
875
|
-
@Forgery configuration: DdSdkConfiguration
|
|
876
|
-
) {
|
|
877
|
-
// Given
|
|
878
|
-
val bridgeConfiguration = configuration.copy(additionalConfig = null)
|
|
879
|
-
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
880
|
-
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
881
|
-
val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
|
|
882
|
-
val traceConfigCaptor = argumentCaptor<TraceConfiguration>()
|
|
883
|
-
|
|
884
|
-
// When
|
|
885
|
-
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
886
|
-
|
|
887
|
-
// Then
|
|
888
|
-
inOrder(mockDatadog) {
|
|
889
|
-
verify(mockDatadog).initialize(
|
|
890
|
-
same(mockContext),
|
|
891
|
-
sdkConfigCaptor.capture(),
|
|
892
|
-
any()
|
|
893
|
-
)
|
|
894
|
-
verify(mockDatadog).enableRum(rumConfigCaptor.capture())
|
|
895
|
-
verify(mockDatadog).enableTrace(traceConfigCaptor.capture())
|
|
896
|
-
verify(mockDatadog).enableLogs(logsConfigCaptor.capture())
|
|
897
|
-
}
|
|
898
|
-
assertThat(rumConfigCaptor.firstValue)
|
|
899
|
-
.hasField("featureConfiguration") {
|
|
900
|
-
it.hasFieldEqualTo("viewTrackingStrategy", NoOpViewTrackingStrategy)
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
904
870
|
@Test
|
|
905
871
|
fun `𝕄 initialize native SDK 𝕎 initialize() {no view tracking}`(
|
|
906
872
|
@Forgery configuration: DdSdkConfiguration
|
|
907
873
|
) {
|
|
908
874
|
// Given
|
|
909
875
|
val bridgeConfiguration = configuration.copy(
|
|
910
|
-
|
|
911
|
-
DdSdkImplementation.DD_NATIVE_VIEW_TRACKING to false
|
|
912
|
-
)
|
|
876
|
+
nativeViewTracking = false
|
|
913
877
|
)
|
|
914
878
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
915
879
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -942,9 +906,7 @@ internal class DdSdkTest {
|
|
|
942
906
|
) {
|
|
943
907
|
// Given
|
|
944
908
|
val bridgeConfiguration = configuration.copy(
|
|
945
|
-
|
|
946
|
-
DdSdkImplementation.DD_NATIVE_VIEW_TRACKING to true
|
|
947
|
-
)
|
|
909
|
+
nativeViewTracking = true
|
|
948
910
|
)
|
|
949
911
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
950
912
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -977,9 +939,7 @@ internal class DdSdkTest {
|
|
|
977
939
|
) {
|
|
978
940
|
// Given
|
|
979
941
|
val bridgeConfiguration = configuration.copy(
|
|
980
|
-
|
|
981
|
-
DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to false
|
|
982
|
-
)
|
|
942
|
+
nativeInteractionTracking = false
|
|
983
943
|
)
|
|
984
944
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
985
945
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -1002,7 +962,7 @@ internal class DdSdkTest {
|
|
|
1002
962
|
}
|
|
1003
963
|
assertThat(rumConfigCaptor.firstValue)
|
|
1004
964
|
.hasField("featureConfiguration") {
|
|
1005
|
-
it.hasFieldEqualTo("
|
|
965
|
+
it.hasFieldEqualTo("userActionTracking", false)
|
|
1006
966
|
}
|
|
1007
967
|
}
|
|
1008
968
|
|
|
@@ -1078,44 +1038,7 @@ internal class DdSdkTest {
|
|
|
1078
1038
|
) {
|
|
1079
1039
|
// Given
|
|
1080
1040
|
val bridgeConfiguration = configuration.copy(
|
|
1081
|
-
|
|
1082
|
-
DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to true
|
|
1083
|
-
)
|
|
1084
|
-
)
|
|
1085
|
-
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1086
|
-
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
1087
|
-
val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
|
|
1088
|
-
val traceConfigCaptor = argumentCaptor<TraceConfiguration>()
|
|
1089
|
-
|
|
1090
|
-
// When
|
|
1091
|
-
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
1092
|
-
|
|
1093
|
-
// Then
|
|
1094
|
-
inOrder(mockDatadog) {
|
|
1095
|
-
verify(mockDatadog).initialize(
|
|
1096
|
-
same(mockContext),
|
|
1097
|
-
sdkConfigCaptor.capture(),
|
|
1098
|
-
any()
|
|
1099
|
-
)
|
|
1100
|
-
verify(mockDatadog).enableRum(rumConfigCaptor.capture())
|
|
1101
|
-
verify(mockDatadog).enableTrace(traceConfigCaptor.capture())
|
|
1102
|
-
verify(mockDatadog).enableLogs(logsConfigCaptor.capture())
|
|
1103
|
-
}
|
|
1104
|
-
assertThat(rumConfigCaptor.firstValue)
|
|
1105
|
-
.hasField("featureConfiguration") {
|
|
1106
|
-
it.hasFieldEqualTo("userActionTracking", true)
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
@Test
|
|
1111
|
-
fun `𝕄 initialize native SDK 𝕎 initialize() {invalid user action tracking}`(
|
|
1112
|
-
@Forgery configuration: DdSdkConfiguration
|
|
1113
|
-
) {
|
|
1114
|
-
// Given
|
|
1115
|
-
val bridgeConfiguration = configuration.copy(
|
|
1116
|
-
additionalConfig = mapOf(
|
|
1117
|
-
DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to null
|
|
1118
|
-
)
|
|
1041
|
+
nativeInteractionTracking = true
|
|
1119
1042
|
)
|
|
1120
1043
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1121
1044
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -1156,9 +1079,7 @@ internal class DdSdkTest {
|
|
|
1156
1079
|
else -> ""
|
|
1157
1080
|
}
|
|
1158
1081
|
val bridgeConfiguration = configuration.copy(
|
|
1159
|
-
|
|
1160
|
-
DdSdkImplementation.DD_SDK_VERBOSITY to verbosityName
|
|
1161
|
-
)
|
|
1082
|
+
verbosity = verbosityName
|
|
1162
1083
|
)
|
|
1163
1084
|
|
|
1164
1085
|
// When
|
|
@@ -1175,9 +1096,7 @@ internal class DdSdkTest {
|
|
|
1175
1096
|
) {
|
|
1176
1097
|
// Given
|
|
1177
1098
|
val bridgeConfiguration = configuration.copy(
|
|
1178
|
-
|
|
1179
|
-
DdSdkImplementation.DD_SDK_VERBOSITY to verbosity
|
|
1180
|
-
)
|
|
1099
|
+
verbosity = verbosity
|
|
1181
1100
|
)
|
|
1182
1101
|
|
|
1183
1102
|
// When
|
|
@@ -1194,9 +1113,7 @@ internal class DdSdkTest {
|
|
|
1194
1113
|
) {
|
|
1195
1114
|
// Given
|
|
1196
1115
|
val bridgeConfiguration = configuration.copy(
|
|
1197
|
-
|
|
1198
|
-
DdSdkImplementation.DD_SERVICE_NAME to serviceName
|
|
1199
|
-
)
|
|
1116
|
+
serviceName = serviceName
|
|
1200
1117
|
)
|
|
1201
1118
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1202
1119
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -1345,9 +1262,7 @@ internal class DdSdkTest {
|
|
|
1345
1262
|
|
|
1346
1263
|
// Given
|
|
1347
1264
|
val bridgeConfiguration = configuration.copy(
|
|
1348
|
-
|
|
1349
|
-
DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
|
|
1350
|
-
)
|
|
1265
|
+
firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
|
|
1351
1266
|
)
|
|
1352
1267
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1353
1268
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -1406,9 +1321,7 @@ internal class DdSdkTest {
|
|
|
1406
1321
|
|
|
1407
1322
|
// Given
|
|
1408
1323
|
val bridgeConfiguration = configuration.copy(
|
|
1409
|
-
|
|
1410
|
-
DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
|
|
1411
|
-
)
|
|
1324
|
+
firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
|
|
1412
1325
|
)
|
|
1413
1326
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1414
1327
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -1474,9 +1387,7 @@ internal class DdSdkTest {
|
|
|
1474
1387
|
|
|
1475
1388
|
// Given
|
|
1476
1389
|
val bridgeConfiguration = configuration.copy(
|
|
1477
|
-
|
|
1478
|
-
DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray()
|
|
1479
|
-
)
|
|
1390
|
+
firstPartyHosts = firstPartyHosts.toReadableArray().asFirstPartyHosts()
|
|
1480
1391
|
)
|
|
1481
1392
|
val sdkConfigCaptor = argumentCaptor<Configuration>()
|
|
1482
1393
|
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
@@ -2336,176 +2247,6 @@ internal class DdSdkTest {
|
|
|
2336
2247
|
verify(mockDatadog).setTrackingConsent(consent.asTrackingConsent())
|
|
2337
2248
|
}
|
|
2338
2249
|
|
|
2339
|
-
@Test
|
|
2340
|
-
fun `𝕄 not build proxy config 𝕎 no proxy config specified`(
|
|
2341
|
-
@Forgery configuration: DdSdkConfiguration
|
|
2342
|
-
) {
|
|
2343
|
-
// Given
|
|
2344
|
-
val config = configuration.copy(additionalConfig = null)
|
|
2345
|
-
|
|
2346
|
-
// When
|
|
2347
|
-
val proxyConfig = testedBridgeSdk.buildProxyConfiguration(config)
|
|
2348
|
-
|
|
2349
|
-
// Then
|
|
2350
|
-
assertThat(proxyConfig).isNull()
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
@Test
|
|
2354
|
-
fun `𝕄 not build proxy config 𝕎 buildProxyConfiguration() { type is missing }`(
|
|
2355
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2356
|
-
forge: Forge
|
|
2357
|
-
) {
|
|
2358
|
-
// Given
|
|
2359
|
-
val additionalConfig = mapOf(
|
|
2360
|
-
DdSdkImplementation.DD_PROXY_ADDRESS to "1.1.1.1",
|
|
2361
|
-
DdSdkImplementation.DD_PROXY_PORT to forge.anInt(min = 0, max = 65536)
|
|
2362
|
-
)
|
|
2363
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2364
|
-
|
|
2365
|
-
// When
|
|
2366
|
-
val proxyConfig = testedBridgeSdk.buildProxyConfiguration(config)
|
|
2367
|
-
|
|
2368
|
-
// Then
|
|
2369
|
-
assertThat(proxyConfig).isNull()
|
|
2370
|
-
}
|
|
2371
|
-
|
|
2372
|
-
@Test
|
|
2373
|
-
fun `𝕄 not build proxy config 𝕎 buildProxyConfiguration() { wrong type is used } `(
|
|
2374
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2375
|
-
forge: Forge
|
|
2376
|
-
) {
|
|
2377
|
-
// Given
|
|
2378
|
-
|
|
2379
|
-
val proxyType = forge.anAlphabeticalString()
|
|
2380
|
-
assumeTrue(proxyType.lowercase(Locale.US) !in arrayOf("http", "https", "socks"))
|
|
2381
|
-
|
|
2382
|
-
val additionalConfig = mapOf(
|
|
2383
|
-
DdSdkImplementation.DD_PROXY_TYPE to proxyType,
|
|
2384
|
-
DdSdkImplementation.DD_PROXY_ADDRESS to "1.1.1.1",
|
|
2385
|
-
DdSdkImplementation.DD_PROXY_PORT to forge.anInt(min = 0, max = 65536)
|
|
2386
|
-
)
|
|
2387
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2388
|
-
|
|
2389
|
-
// When
|
|
2390
|
-
val proxyConfig = testedBridgeSdk.buildProxyConfiguration(config)
|
|
2391
|
-
|
|
2392
|
-
// Then
|
|
2393
|
-
assertThat(proxyConfig).isNull()
|
|
2394
|
-
}
|
|
2395
|
-
|
|
2396
|
-
@Test
|
|
2397
|
-
fun `𝕄 not build proxy config 𝕎 buildProxyConfiguration() { address is missing }`(
|
|
2398
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2399
|
-
forge: Forge
|
|
2400
|
-
) {
|
|
2401
|
-
// Given
|
|
2402
|
-
val additionalConfig = mapOf(
|
|
2403
|
-
DdSdkImplementation.DD_PROXY_TYPE to forge.anElementFrom("http", "https", "socks"),
|
|
2404
|
-
DdSdkImplementation.DD_PROXY_PORT to forge.anInt(min = 0, max = 65536)
|
|
2405
|
-
)
|
|
2406
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2407
|
-
|
|
2408
|
-
// When
|
|
2409
|
-
val proxyConfig = testedBridgeSdk.buildProxyConfiguration(config)
|
|
2410
|
-
|
|
2411
|
-
// Then
|
|
2412
|
-
assertThat(proxyConfig).isNull()
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
@Test
|
|
2416
|
-
fun `𝕄 not build proxy config 𝕎 buildProxyConfiguration() { port is missing }`(
|
|
2417
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2418
|
-
forge: Forge
|
|
2419
|
-
) {
|
|
2420
|
-
// Given
|
|
2421
|
-
val additionalConfig = mapOf(
|
|
2422
|
-
DdSdkImplementation.DD_PROXY_TYPE to forge.anElementFrom("http", "https", "socks"),
|
|
2423
|
-
DdSdkImplementation.DD_PROXY_ADDRESS to "1.1.1.1"
|
|
2424
|
-
)
|
|
2425
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2426
|
-
|
|
2427
|
-
// When
|
|
2428
|
-
val proxyConfig = testedBridgeSdk.buildProxyConfiguration(config)
|
|
2429
|
-
|
|
2430
|
-
// Then
|
|
2431
|
-
assertThat(proxyConfig).isNull()
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
@Test
|
|
2435
|
-
fun `𝕄 build proxy configuration 𝕎 buildProxyConfiguration() { no credentials }`(
|
|
2436
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2437
|
-
forge: Forge
|
|
2438
|
-
) {
|
|
2439
|
-
// Given
|
|
2440
|
-
val proxyType = forge.anElementFrom("http", "https", "socks")
|
|
2441
|
-
|
|
2442
|
-
val additionalConfig = mapOf(
|
|
2443
|
-
DdSdkImplementation.DD_PROXY_TYPE to proxyType,
|
|
2444
|
-
DdSdkImplementation.DD_PROXY_ADDRESS to "1.1.1.1",
|
|
2445
|
-
DdSdkImplementation.DD_PROXY_PORT to forge.anInt(min = 0, max = 65536)
|
|
2446
|
-
)
|
|
2447
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2448
|
-
|
|
2449
|
-
// When
|
|
2450
|
-
val (proxy, authenticator) = testedBridgeSdk.buildProxyConfiguration(config)!!
|
|
2451
|
-
|
|
2452
|
-
// Then
|
|
2453
|
-
assertThat(proxy.type()).matches {
|
|
2454
|
-
when (proxyType) {
|
|
2455
|
-
"http", "https" -> it == Proxy.Type.HTTP
|
|
2456
|
-
else -> it == Proxy.Type.SOCKS
|
|
2457
|
-
}
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
assertThat(proxy.address()).isNotNull
|
|
2461
|
-
|
|
2462
|
-
assertThat(authenticator).isNull()
|
|
2463
|
-
}
|
|
2464
|
-
|
|
2465
|
-
@Test
|
|
2466
|
-
fun `𝕄 build proxy configuration+authenticator 𝕎 buildProxyConfiguration() { +credentials }`(
|
|
2467
|
-
@Forgery configuration: DdSdkConfiguration,
|
|
2468
|
-
forge: Forge
|
|
2469
|
-
) {
|
|
2470
|
-
// Given
|
|
2471
|
-
val proxyType = forge.anElementFrom("http", "https", "socks")
|
|
2472
|
-
val proxyUsername = forge.anAlphabeticalString()
|
|
2473
|
-
val proxyPassword = forge.anAlphabeticalString()
|
|
2474
|
-
val proxyPort = forge.anInt(min = 0, max = 65536)
|
|
2475
|
-
val proxyAddress = "1.1.1.1"
|
|
2476
|
-
|
|
2477
|
-
val additionalConfig = mapOf(
|
|
2478
|
-
DdSdkImplementation.DD_PROXY_TYPE to proxyType,
|
|
2479
|
-
DdSdkImplementation.DD_PROXY_ADDRESS to proxyAddress,
|
|
2480
|
-
DdSdkImplementation.DD_PROXY_PORT to proxyPort,
|
|
2481
|
-
DdSdkImplementation.DD_PROXY_USERNAME to proxyUsername,
|
|
2482
|
-
DdSdkImplementation.DD_PROXY_PASSWORD to proxyPassword
|
|
2483
|
-
)
|
|
2484
|
-
val config = configuration.copy(additionalConfig = additionalConfig)
|
|
2485
|
-
|
|
2486
|
-
// When
|
|
2487
|
-
val (proxy, authenticator) = testedBridgeSdk.buildProxyConfiguration(config)!!
|
|
2488
|
-
|
|
2489
|
-
// Then
|
|
2490
|
-
assertThat(proxy.type()).matches {
|
|
2491
|
-
when (proxyType) {
|
|
2492
|
-
"http", "https" -> it == Proxy.Type.HTTP
|
|
2493
|
-
else -> it == Proxy.Type.SOCKS
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
assertThat(proxy.address()).isNotNull
|
|
2498
|
-
assertThat(proxy.address()).isInstanceOf(InetSocketAddress::class.java)
|
|
2499
|
-
(proxy.address() as InetSocketAddress).let {
|
|
2500
|
-
assertThat(it.port).isEqualTo(proxyPort)
|
|
2501
|
-
assertThat(it.address.hostAddress).isEqualTo(proxyAddress)
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
|
-
assertThat(authenticator).isNotNull
|
|
2505
|
-
assertThat(authenticator?.username).isEqualTo(proxyUsername)
|
|
2506
|
-
assertThat(authenticator?.password).isEqualTo(proxyPassword)
|
|
2507
|
-
}
|
|
2508
|
-
|
|
2509
2250
|
fun `𝕄 initialize native SDK 𝕎 initialize() {with custom endpoints}`(
|
|
2510
2251
|
forge: Forge
|
|
2511
2252
|
) {
|
|
@@ -15,6 +15,8 @@ import fr.xgouchet.elmyr.annotation.MapForgery
|
|
|
15
15
|
import fr.xgouchet.elmyr.annotation.StringForgery
|
|
16
16
|
import fr.xgouchet.elmyr.annotation.StringForgeryType
|
|
17
17
|
import fr.xgouchet.elmyr.junit5.ForgeExtension
|
|
18
|
+
import io.opentracing.Scope
|
|
19
|
+
import io.opentracing.ScopeManager
|
|
18
20
|
import io.opentracing.Span
|
|
19
21
|
import io.opentracing.SpanContext
|
|
20
22
|
import io.opentracing.Tracer
|
|
@@ -57,9 +59,15 @@ internal class DdTraceTest {
|
|
|
57
59
|
@Mock
|
|
58
60
|
lateinit var mockSpanContext: SpanContext
|
|
59
61
|
|
|
62
|
+
@Mock
|
|
63
|
+
lateinit var mockScopeManager: ScopeManager
|
|
64
|
+
|
|
60
65
|
@Mock
|
|
61
66
|
lateinit var mockSpan: Span
|
|
62
67
|
|
|
68
|
+
@Mock
|
|
69
|
+
lateinit var mockScope: Scope
|
|
70
|
+
|
|
63
71
|
@StringForgery
|
|
64
72
|
lateinit var fakeOperation: String
|
|
65
73
|
|
|
@@ -94,6 +102,7 @@ internal class DdTraceTest {
|
|
|
94
102
|
@BeforeEach
|
|
95
103
|
fun `set up`() {
|
|
96
104
|
whenever(mockTracer.buildSpan(fakeOperation)) doReturn mockSpanBuilder
|
|
105
|
+
whenever(mockTracer.scopeManager()) doReturn mockScopeManager
|
|
97
106
|
whenever(
|
|
98
107
|
mockSpanBuilder.withStartTimestamp(
|
|
99
108
|
fakeTimestamp.toLong() * 1000
|
|
@@ -103,6 +112,7 @@ internal class DdTraceTest {
|
|
|
103
112
|
whenever(mockSpan.context()) doReturn mockSpanContext
|
|
104
113
|
whenever(mockSpanContext.toSpanId()) doReturn fakeSpanId
|
|
105
114
|
whenever(mockSpanContext.toTraceId()) doReturn fakeTraceId
|
|
115
|
+
whenever(mockScopeManager.activate(mockSpan)) doReturn mockScope
|
|
106
116
|
|
|
107
117
|
testedTrace = DdTraceImplementation(tracerProvider = { mockTracer })
|
|
108
118
|
}
|
|
@@ -12,8 +12,9 @@ import com.datadog.android.rum.configuration.VitalsUpdateFrequency
|
|
|
12
12
|
import com.datadog.reactnative.ConfigurationForTelemetry
|
|
13
13
|
import com.datadog.reactnative.CustomEndpoints
|
|
14
14
|
import com.datadog.reactnative.DdSdkConfiguration
|
|
15
|
-
import com.datadog.reactnative.
|
|
15
|
+
import com.datadog.reactnative.ProxyAuthenticator
|
|
16
16
|
import com.facebook.react.bridge.ReadableMap
|
|
17
|
+
import java.net.Proxy
|
|
17
18
|
|
|
18
19
|
fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
19
20
|
val map = mutableMapOf<String, Any?>()
|
|
@@ -85,6 +86,19 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
85
86
|
configurationForTelemetry?.let {
|
|
86
87
|
map.put("configurationForTelemetry", it.toReadableJavaOnlyMap())
|
|
87
88
|
}
|
|
89
|
+
map.put("nativeViewTracking", nativeViewTracking)
|
|
90
|
+
map.put("nativeInteractionTracking", nativeInteractionTracking)
|
|
91
|
+
verbosity?.let { map.put("verbosity", it) }
|
|
92
|
+
proxyConfig?.let {
|
|
93
|
+
map.put("proxyConfig", it.toReadableMap())
|
|
94
|
+
}
|
|
95
|
+
serviceName?.let { map.put("serviceName", it) }
|
|
96
|
+
firstPartyHosts?.let {
|
|
97
|
+
map.put("firstPartyHosts", it.toFirstPartyHostsReadableArray())
|
|
98
|
+
}
|
|
99
|
+
map.put("bundleLogsWithRum", bundleLogsWithRum)
|
|
100
|
+
map.put("bundleLogsWithTraces", bundleLogsWithTraces)
|
|
101
|
+
|
|
88
102
|
return map.toReadableMap()
|
|
89
103
|
}
|
|
90
104
|
|
|
@@ -106,3 +120,16 @@ internal fun CustomEndpoints.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
106
120
|
trace?.let { map.put("trace", it) }
|
|
107
121
|
return map.toReadableMap()
|
|
108
122
|
}
|
|
123
|
+
|
|
124
|
+
internal fun Pair<Proxy, ProxyAuthenticator?>.toReadableMap(): ReadableMap {
|
|
125
|
+
val map = mutableMapOf<String, Any?>()
|
|
126
|
+
val inetAddress = first.address().toString()
|
|
127
|
+
val address = inetAddress.substringBeforeLast(":")
|
|
128
|
+
val port = inetAddress.substringAfterLast(":").toInt()
|
|
129
|
+
map.put("type", first.type())
|
|
130
|
+
map.put("address", address)
|
|
131
|
+
map.put("port", port)
|
|
132
|
+
map.put("username", second?.username)
|
|
133
|
+
map.put("password", second?.password)
|
|
134
|
+
return map.toReadableMap()
|
|
135
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
package com.datadog.tools.unit
|
|
8
8
|
|
|
9
|
+
import com.datadog.android.trace.TracingHeaderType
|
|
9
10
|
import com.facebook.react.bridge.JavaOnlyArray
|
|
10
11
|
import com.facebook.react.bridge.JavaOnlyMap
|
|
11
12
|
import com.facebook.react.bridge.ReadableArray
|
|
@@ -23,7 +24,30 @@ fun Map<*, *>.toReadableMap(): ReadableMap {
|
|
|
23
24
|
return JavaOnlyMap.of(*keysAndValues.toTypedArray())
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
fun Map<String, Set<TracingHeaderType>>.toFirstPartyHostsReadableArray(): ReadableArray {
|
|
28
|
+
val list = mutableListOf<Any>()
|
|
29
|
+
|
|
30
|
+
entries.forEach {
|
|
31
|
+
list.add(
|
|
32
|
+
mapOf(
|
|
33
|
+
"match" to it.key,
|
|
34
|
+
"propagatorTypes" to it.value.map {
|
|
35
|
+
tracingHeaderType ->
|
|
36
|
+
tracingHeaderType.toString().lowercase()
|
|
37
|
+
}.toReadableArray()
|
|
38
|
+
).toReadableMap()
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return JavaOnlyArray.from(list)
|
|
43
|
+
}
|
|
44
|
+
|
|
26
45
|
fun List<*>.toReadableArray(): ReadableArray {
|
|
27
46
|
// this FB implementation is not backed by Android-specific .so library, so ok for unit tests
|
|
28
47
|
return JavaOnlyArray.from(this)
|
|
29
48
|
}
|
|
49
|
+
|
|
50
|
+
fun Set<*>.toReadableArray(): ReadableArray {
|
|
51
|
+
// this FB implementation is not backed by Android-specific .so library, so ok for unit tests
|
|
52
|
+
return JavaOnlyArray.from(this.toList())
|
|
53
|
+
}
|
package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt
CHANGED
|
@@ -71,7 +71,15 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
|
|
|
71
71
|
rum = forge.aNullable { aString() },
|
|
72
72
|
logs = forge.aNullable { aString() },
|
|
73
73
|
trace = forge.aNullable { aString() }
|
|
74
|
-
)
|
|
74
|
+
),
|
|
75
|
+
nativeViewTracking = forge.aBool(),
|
|
76
|
+
nativeInteractionTracking = forge.aBool(),
|
|
77
|
+
verbosity = forge.aNullable { anElementFrom("debug", "info", "warn", "error") },
|
|
78
|
+
proxyConfig = null,
|
|
79
|
+
serviceName = forge.aNullable { forge.anAlphabeticalString() },
|
|
80
|
+
firstPartyHosts = null,
|
|
81
|
+
bundleLogsWithRum = forge.aBool(),
|
|
82
|
+
bundleLogsWithTraces = forge.aBool()
|
|
75
83
|
)
|
|
76
84
|
}
|
|
77
85
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../../../../datadog-configuration.schema.json",
|
|
3
|
+
"configuration": {
|
|
4
|
+
"applicationId": "fake-app-id",
|
|
5
|
+
"env": "fake-env",
|
|
6
|
+
"clientToken": "fake-client-token",
|
|
7
|
+
"trackInteractions": true,
|
|
8
|
+
"trackResources": true,
|
|
9
|
+
"trackErrors": true,
|
|
10
|
+
"trackingConsent": "NOT_GRANTED",
|
|
11
|
+
"longTaskThresholdMs": 44,
|
|
12
|
+
"verbosity": "WARN",
|
|
13
|
+
"actionNameAttribute": "action-name-attr",
|
|
14
|
+
"resourceTracingSamplingRate": 33,
|
|
15
|
+
"batchSize": "SMALL",
|
|
16
|
+
"customEndpoints": {
|
|
17
|
+
"logs": "https://logs.example.com",
|
|
18
|
+
"rum": "https://rum.example.com",
|
|
19
|
+
"trace": "https://trace.example.com"
|
|
20
|
+
},
|
|
21
|
+
"firstPartyHosts": [
|
|
22
|
+
{
|
|
23
|
+
"match": "example.com",
|
|
24
|
+
"propagatorTypes": ["B3MULTI", "TRACECONTEXT"]
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"nativeCrashReportEnabled": true,
|
|
28
|
+
"nativeInteractionTracking": true,
|
|
29
|
+
"nativeLongTaskThresholdMs": 333,
|
|
30
|
+
"nativeViewTracking": true,
|
|
31
|
+
"proxy": {
|
|
32
|
+
"address": "1.1.1.1",
|
|
33
|
+
"port": 4444,
|
|
34
|
+
"type": "HTTPS",
|
|
35
|
+
"password": "proxypassword",
|
|
36
|
+
"username": "proxyusername"
|
|
37
|
+
},
|
|
38
|
+
"serviceName": "my.app",
|
|
39
|
+
"sessionSamplingRate": 80,
|
|
40
|
+
"site": "US3",
|
|
41
|
+
"telemetrySampleRate": 60,
|
|
42
|
+
"trackBackgroundEvents": true,
|
|
43
|
+
"trackFrustrations": false,
|
|
44
|
+
"uploadFrequency": "FREQUENT",
|
|
45
|
+
"version": "2.3.1",
|
|
46
|
+
"vitalsUpdateFrequency": "NEVER"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
def getConfigurationFilePath() {
|
|
8
|
+
if (project.hasProperty("datadog")) {
|
|
9
|
+
if (project.datadog.configurationFilePath) {
|
|
10
|
+
return project.datadog.configurationFilePath
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return '../../datadog-configuration.json'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def getBuildAssetsDirectory(sourceName) {
|
|
17
|
+
return project.layout.buildDirectory
|
|
18
|
+
.dir("generated/assets/datadog/configuration$sourceName")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def getConfigurationFile() {
|
|
22
|
+
def filePath = getConfigurationFilePath()
|
|
23
|
+
def rootProjectPath = projectDir.getAbsolutePath()
|
|
24
|
+
|
|
25
|
+
// The path to the configuration file is relative to the app's android/app/ directory.
|
|
26
|
+
def absoluteFilePath = "$rootProjectPath/$filePath"
|
|
27
|
+
|
|
28
|
+
assert file(absoluteFilePath).exists() : "Datadog configuration file at $absoluteFilePath does not exist"
|
|
29
|
+
return absoluteFilePath
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Copies the configuration file into the build directory and renames it.
|
|
34
|
+
*/
|
|
35
|
+
task copyDatadogConfigurationFile() {
|
|
36
|
+
// Note: there can be multiple source sets depending on the variants declared, so we
|
|
37
|
+
// create a configuration for all of them. This prevents warnings in Android Studio when
|
|
38
|
+
// adding the same directory to sources for different variants.
|
|
39
|
+
android.sourceSets.forEach { source ->
|
|
40
|
+
copy {
|
|
41
|
+
from getConfigurationFile()
|
|
42
|
+
into getBuildAssetsDirectory(source.name)
|
|
43
|
+
rename {
|
|
44
|
+
'datadog-configuration.json'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Adds the copied configuration file to the assets of the app for every sourceSet.
|
|
50
|
+
android.sourceSets.forEach { source ->
|
|
51
|
+
source.assets.srcDir(getBuildAssetsDirectory(source.name))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
gradle.projectsEvaluated {
|
|
56
|
+
preBuild.dependsOn(copyDatadogConfigurationFile)
|
|
57
|
+
}
|