@datadog/mobile-react-native 2.1.1 → 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 +8 -7
- package/android/build.gradle +5 -4
- 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/DdRumImplementation.kt +3 -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/ActionEventForgeryFactory.kt +1 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +9 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +1 -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 +22 -19
- 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
|
@@ -19,15 +19,16 @@ Pod::Spec.new do |s|
|
|
|
19
19
|
s.dependency "React-Core"
|
|
20
20
|
|
|
21
21
|
# /!\ Remember to keep the versions in sync with DatadogSDKReactNativeSessionReplay.podspec
|
|
22
|
-
s.dependency 'DatadogCore', '~> 2.
|
|
23
|
-
s.dependency 'DatadogLogs', '~> 2.
|
|
24
|
-
s.dependency 'DatadogTrace', '~> 2.
|
|
25
|
-
s.dependency 'DatadogRUM', '~> 2.
|
|
26
|
-
s.dependency 'DatadogCrashReporting', '~> 2.
|
|
27
|
-
s.dependency 'DatadogWebViewTracking', '~> 2.
|
|
22
|
+
s.dependency 'DatadogCore', '~> 2.7.1'
|
|
23
|
+
s.dependency 'DatadogLogs', '~> 2.7.1'
|
|
24
|
+
s.dependency 'DatadogTrace', '~> 2.7.1'
|
|
25
|
+
s.dependency 'DatadogRUM', '~> 2.7.1'
|
|
26
|
+
s.dependency 'DatadogCrashReporting', '~> 2.7.1'
|
|
27
|
+
s.dependency 'DatadogWebViewTracking', '~> 2.7.1'
|
|
28
28
|
|
|
29
29
|
s.test_spec 'Tests' do |test_spec|
|
|
30
|
-
test_spec.source_files = 'ios/Tests
|
|
30
|
+
test_spec.source_files = 'ios/Tests/**/*.{swift,json}'
|
|
31
|
+
test_spec.resources = 'ios/Tests/Fixtures'
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
|
package/android/build.gradle
CHANGED
|
@@ -186,10 +186,11 @@ dependencies {
|
|
|
186
186
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
187
187
|
compileOnly "com.squareup.okhttp3:okhttp:3.12.13"
|
|
188
188
|
|
|
189
|
-
implementation "com.datadoghq:dd-sdk-android-rum:2.
|
|
190
|
-
implementation "com.datadoghq:dd-sdk-android-logs:2.
|
|
191
|
-
implementation "com.datadoghq:dd-sdk-android-trace:2.
|
|
192
|
-
implementation "com.datadoghq:dd-sdk-android-webview:2.
|
|
189
|
+
implementation "com.datadoghq:dd-sdk-android-rum:2.6.2"
|
|
190
|
+
implementation "com.datadoghq:dd-sdk-android-logs:2.6.2"
|
|
191
|
+
implementation "com.datadoghq:dd-sdk-android-trace:2.6.2"
|
|
192
|
+
implementation "com.datadoghq:dd-sdk-android-webview:2.6.2"
|
|
193
|
+
implementation "com.google.code.gson:gson:2.10.0"
|
|
193
194
|
testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
|
|
194
195
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
|
|
195
196
|
testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
|
|
@@ -70,6 +70,8 @@ object DatadogSDKWrapperStorage {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
internal class DatadogSDKWrapper : DatadogWrapper {
|
|
73
|
+
override var bundleLogsWithRum = DefaultConfiguration.bundleLogsWithRum
|
|
74
|
+
override var bundleLogsWithTraces = DefaultConfiguration.bundleLogsWithTraces
|
|
73
75
|
|
|
74
76
|
// We use Kotlin backing field here to initialize once the telemetry proxy
|
|
75
77
|
// and make sure it is only after SDK is initialized.
|
|
@@ -10,7 +10,6 @@ import android.content.Context
|
|
|
10
10
|
import com.datadog.android.core.configuration.Configuration
|
|
11
11
|
import com.datadog.android.log.LogsConfiguration
|
|
12
12
|
import com.datadog.android.privacy.TrackingConsent
|
|
13
|
-
import com.datadog.android.rum.GlobalRumMonitor
|
|
14
13
|
import com.datadog.android.rum.RumConfiguration
|
|
15
14
|
import com.datadog.android.rum.RumMonitor
|
|
16
15
|
import com.datadog.android.trace.TraceConfiguration
|
|
@@ -21,6 +20,17 @@ import java.lang.IllegalArgumentException
|
|
|
21
20
|
*/
|
|
22
21
|
@Suppress("ComplexInterface", "TooManyFunctions")
|
|
23
22
|
interface DatadogWrapper {
|
|
23
|
+
/**
|
|
24
|
+
* Enables RUM for logs.
|
|
25
|
+
* By default, RUM is enabled for logs.
|
|
26
|
+
*/
|
|
27
|
+
var bundleLogsWithRum : Boolean
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Enables Traces for logs.
|
|
31
|
+
* By default, Traces is enabled for logs.
|
|
32
|
+
*/
|
|
33
|
+
var bundleLogsWithTraces : Boolean
|
|
24
34
|
|
|
25
35
|
/**
|
|
26
36
|
* Sets the verbosity of the Datadog library.
|
|
@@ -19,8 +19,13 @@ class DdLogsImplementation(
|
|
|
19
19
|
private val datadog: DatadogWrapper = DatadogSDKWrapper()
|
|
20
20
|
) {
|
|
21
21
|
private val reactNativeLogger: Logger by lazy {
|
|
22
|
+
val bundleLogsWithRum = datadog.bundleLogsWithRum
|
|
23
|
+
val bundleLogsWithTraces = datadog.bundleLogsWithTraces
|
|
24
|
+
|
|
22
25
|
logger ?: Logger.Builder(DatadogSDKWrapperStorage.getSdkCore())
|
|
23
26
|
.setLogcatLogsEnabled(true)
|
|
27
|
+
.setBundleWithRumEnabled(bundleLogsWithRum)
|
|
28
|
+
.setBundleWithTraceEnabled(bundleLogsWithTraces)
|
|
24
29
|
.setName("DdLogs")
|
|
25
30
|
.build()
|
|
26
31
|
}
|
|
@@ -314,6 +314,9 @@ class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrappe
|
|
|
314
314
|
"patch" -> RumResourceMethod.PATCH
|
|
315
315
|
"put" -> RumResourceMethod.PUT
|
|
316
316
|
"post" -> RumResourceMethod.POST
|
|
317
|
+
"trace" -> RumResourceMethod.TRACE
|
|
318
|
+
"options" -> RumResourceMethod.OPTIONS
|
|
319
|
+
"connect" -> RumResourceMethod.CONNECT
|
|
317
320
|
else -> {
|
|
318
321
|
Log.w(
|
|
319
322
|
DdRum::class.java.canonicalName,
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
package com.datadog.reactnative
|
|
8
8
|
|
|
9
|
+
import com.datadog.android.trace.TracingHeaderType
|
|
10
|
+
import java.net.Proxy
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* A configuration object to initialize Datadog's features.
|
|
11
14
|
* @param clientToken A valid Datadog client token.
|
|
@@ -26,6 +29,14 @@ package com.datadog.reactnative
|
|
|
26
29
|
* @param customEndpoints Custom endpoints for RUM/Logs/Trace features.
|
|
27
30
|
* @param additionalConfig Additional configuration parameters.
|
|
28
31
|
* @param configurationForTelemetry Additional configuration data for Datadog telemetry.
|
|
32
|
+
* @param nativeViewTracking Enables/Disables tracking RUM Views on the native level.
|
|
33
|
+
* @param nativeInteractionTracking Enables/Disables tracking RUM Actions on the native level.
|
|
34
|
+
* @param verbosity Verbosity level of the SDK.
|
|
35
|
+
* @param proxyConfig Configuration for proxying SDK data.
|
|
36
|
+
* @param serviceName Custom service name.
|
|
37
|
+
* @param firstPartyHosts List of backend hosts to enable tracing with.
|
|
38
|
+
* @param bundleLogsWithRum Enables RUM correlation with logs.
|
|
39
|
+
* @param bundleLogsWithTraces Enables Traces correlation with logs.
|
|
29
40
|
*/
|
|
30
41
|
data class DdSdkConfiguration(
|
|
31
42
|
val clientToken: String,
|
|
@@ -45,7 +56,59 @@ data class DdSdkConfiguration(
|
|
|
45
56
|
val trackBackgroundEvents: Boolean? = null,
|
|
46
57
|
val customEndpoints: CustomEndpoints? = null,
|
|
47
58
|
val additionalConfig: Map<String, Any?>? = null,
|
|
48
|
-
val configurationForTelemetry: ConfigurationForTelemetry? = null
|
|
59
|
+
val configurationForTelemetry: ConfigurationForTelemetry? = null,
|
|
60
|
+
val nativeViewTracking: Boolean? = null,
|
|
61
|
+
val nativeInteractionTracking: Boolean? = null,
|
|
62
|
+
val verbosity: String? = null,
|
|
63
|
+
val proxyConfig: Pair<Proxy, ProxyAuthenticator?>? = null,
|
|
64
|
+
val serviceName: String? = null,
|
|
65
|
+
val firstPartyHosts: Map<String, Set<TracingHeaderType>>? = null,
|
|
66
|
+
val bundleLogsWithRum: Boolean? = null,
|
|
67
|
+
val bundleLogsWithTraces: Boolean? = null
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
internal data class JSONConfigurationFile(
|
|
71
|
+
val configuration: JSONDdSdkConfiguration
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
internal data class JSONDdSdkConfiguration(
|
|
75
|
+
val clientToken: String,
|
|
76
|
+
val env: String,
|
|
77
|
+
val applicationId: String,
|
|
78
|
+
val nativeCrashReportEnabled: Boolean? = null,
|
|
79
|
+
val nativeLongTaskThresholdMs: Double? = null,
|
|
80
|
+
val longTaskThresholdMs: Double? = null,
|
|
81
|
+
val sessionSamplingRate: Double? = null,
|
|
82
|
+
val site: String? = null,
|
|
83
|
+
val trackingConsent: String? = null,
|
|
84
|
+
val telemetrySampleRate: Double? = null,
|
|
85
|
+
val vitalsUpdateFrequency: String? = null,
|
|
86
|
+
val trackFrustrations: Boolean? = null,
|
|
87
|
+
val uploadFrequency: String? = null,
|
|
88
|
+
val batchSize: String? = null,
|
|
89
|
+
val trackBackgroundEvents: Boolean? = null,
|
|
90
|
+
val customEndpoints: CustomEndpoints? = null,
|
|
91
|
+
val nativeViewTracking: Boolean? = null,
|
|
92
|
+
val nativeInteractionTracking: Boolean? = null,
|
|
93
|
+
val verbosity: String? = null,
|
|
94
|
+
val proxy: JSONProxyConfiguration? = null,
|
|
95
|
+
val serviceName: String? = null,
|
|
96
|
+
val firstPartyHosts: List<JSONFirstPartyHost>? = null,
|
|
97
|
+
val bundleLogsWithRum: Boolean? = null,
|
|
98
|
+
val bundleLogsWithTraces: Boolean? = null
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
internal data class JSONProxyConfiguration(
|
|
102
|
+
val type: String,
|
|
103
|
+
val address: String,
|
|
104
|
+
val port: Int,
|
|
105
|
+
val username: String? = null,
|
|
106
|
+
val password: String? = null
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
internal data class JSONFirstPartyHost(
|
|
110
|
+
val match: String,
|
|
111
|
+
val propagatorTypes: List<String>
|
|
49
112
|
)
|
|
50
113
|
|
|
51
114
|
/**
|
|
@@ -4,12 +4,17 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
@file:Suppress("TooManyFunctions")
|
|
7
8
|
package com.datadog.reactnative
|
|
8
9
|
|
|
10
|
+
import android.util.Log
|
|
9
11
|
import com.datadog.android.trace.TracingHeaderType
|
|
10
12
|
import com.facebook.react.bridge.ReadableArray
|
|
11
13
|
import com.facebook.react.bridge.ReadableMap
|
|
12
14
|
import com.facebook.react.bridge.WritableNativeMap
|
|
15
|
+
import java.net.InetSocketAddress
|
|
16
|
+
import java.net.Proxy
|
|
17
|
+
import java.util.Locale
|
|
13
18
|
|
|
14
19
|
internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
15
20
|
return DdSdkConfiguration(
|
|
@@ -32,7 +37,15 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
|
32
37
|
additionalConfig = getMap("additionalConfig")?.toHashMap(),
|
|
33
38
|
configurationForTelemetry = getMap(
|
|
34
39
|
"configurationForTelemetry"
|
|
35
|
-
)?.asConfigurationForTelemetry()
|
|
40
|
+
)?.asConfigurationForTelemetry(),
|
|
41
|
+
nativeViewTracking = getBoolean("nativeViewTracking"),
|
|
42
|
+
nativeInteractionTracking = getBoolean("nativeInteractionTracking"),
|
|
43
|
+
verbosity = getString("verbosity"),
|
|
44
|
+
proxyConfig = getMap("proxyConfig")?.asProxyConfig(),
|
|
45
|
+
serviceName = getString("serviceName"),
|
|
46
|
+
firstPartyHosts = getArray("firstPartyHosts")?.asFirstPartyHosts(),
|
|
47
|
+
bundleLogsWithRum = getBoolean("bundleLogsWithRum"),
|
|
48
|
+
bundleLogsWithTraces = getBoolean("bundleLogsWithTraces")
|
|
36
49
|
)
|
|
37
50
|
}
|
|
38
51
|
|
|
@@ -55,9 +68,127 @@ internal fun ReadableMap.asCustomEndpoints(): CustomEndpoints {
|
|
|
55
68
|
)
|
|
56
69
|
}
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
@Suppress("ComplexMethod")
|
|
72
|
+
internal fun ReadableMap.asProxyConfig(): Pair<Proxy, ProxyAuthenticator?>? {
|
|
73
|
+
val address: String? = getString("address")
|
|
74
|
+
|
|
75
|
+
// getInt expects the value to be non-null
|
|
76
|
+
var port: Int? = null
|
|
77
|
+
if (hasKey("port")) {
|
|
78
|
+
port = getInt("port")
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
val type = getString("type")
|
|
82
|
+
|
|
83
|
+
return if (address != null && port != null && type != null) {
|
|
84
|
+
buildProxyConfig(
|
|
85
|
+
type,
|
|
86
|
+
address,
|
|
87
|
+
port,
|
|
88
|
+
getString("username"),
|
|
89
|
+
getString("password")
|
|
90
|
+
)
|
|
91
|
+
} else {
|
|
92
|
+
null
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
internal fun ReadableArray.asFirstPartyHosts(): Map<String, Set<TracingHeaderType>> {
|
|
97
|
+
val firstPartyHosts = this.toArrayList() as List<ReadableMap>
|
|
98
|
+
return firstPartyHosts.mapNotNull<ReadableMap, JSONFirstPartyHost> {
|
|
99
|
+
val match = it.getString("match")
|
|
100
|
+
val propagatorTypes = it.getArray("propagatorTypes")
|
|
101
|
+
if (match != null && propagatorTypes != null) {
|
|
102
|
+
JSONFirstPartyHost(match, propagatorTypes.toArrayList() as List<String>)
|
|
103
|
+
} else null
|
|
104
|
+
}.asFirstPartyHosts()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
internal object DefaultConfiguration {
|
|
108
|
+
const val nativeCrashReportEnabled = false
|
|
109
|
+
const val sessionSamplingRate = 100.0
|
|
110
|
+
const val site = "US1"
|
|
111
|
+
const val longTaskThresholdMs = 0.0
|
|
112
|
+
const val nativeLongTaskThresholdMs = 200.0
|
|
113
|
+
const val nativeViewTracking = false
|
|
114
|
+
const val nativeInteractionTracking = false
|
|
115
|
+
const val trackingConsent = "GRANTED"
|
|
116
|
+
const val telemetrySampleRate = 20.0
|
|
117
|
+
const val vitalsUpdateFrequency = "AVERAGE"
|
|
118
|
+
const val trackFrustrations = true
|
|
119
|
+
const val uploadFrequency = "AVERAGE"
|
|
120
|
+
const val batchSize = "MEDIUM"
|
|
121
|
+
const val trackBackgroundEvents = false
|
|
122
|
+
const val bundleLogsWithRum = true
|
|
123
|
+
const val bundleLogsWithTraces = true
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Suppress("ComplexMethod")
|
|
127
|
+
internal fun JSONDdSdkConfiguration.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
128
|
+
return DdSdkConfiguration(
|
|
129
|
+
this.clientToken,
|
|
130
|
+
this.env,
|
|
131
|
+
this.applicationId,
|
|
132
|
+
this.nativeCrashReportEnabled ?: DefaultConfiguration.nativeCrashReportEnabled,
|
|
133
|
+
this.nativeLongTaskThresholdMs ?: DefaultConfiguration.nativeLongTaskThresholdMs,
|
|
134
|
+
this.longTaskThresholdMs ?: DefaultConfiguration.longTaskThresholdMs,
|
|
135
|
+
this.sessionSamplingRate ?: DefaultConfiguration.sessionSamplingRate,
|
|
136
|
+
this.site ?: DefaultConfiguration.site,
|
|
137
|
+
this.trackingConsent ?: DefaultConfiguration.trackingConsent,
|
|
138
|
+
this.telemetrySampleRate ?: DefaultConfiguration.telemetrySampleRate,
|
|
139
|
+
this.vitalsUpdateFrequency ?: DefaultConfiguration.vitalsUpdateFrequency,
|
|
140
|
+
this.trackFrustrations ?: DefaultConfiguration.trackFrustrations,
|
|
141
|
+
this.uploadFrequency ?: DefaultConfiguration.uploadFrequency,
|
|
142
|
+
this.batchSize ?: DefaultConfiguration.batchSize,
|
|
143
|
+
this.trackBackgroundEvents ?: DefaultConfiguration.trackBackgroundEvents,
|
|
144
|
+
this.customEndpoints,
|
|
145
|
+
mapOf(
|
|
146
|
+
"_dd.source" to "react-native",
|
|
147
|
+
"_dd.sdk_version" to SDK_VERSION
|
|
148
|
+
),
|
|
149
|
+
null,
|
|
150
|
+
this.nativeViewTracking ?: DefaultConfiguration.nativeViewTracking,
|
|
151
|
+
this.nativeInteractionTracking ?: DefaultConfiguration.nativeInteractionTracking,
|
|
152
|
+
this.verbosity,
|
|
153
|
+
this.proxy?.asProxyConfig(),
|
|
154
|
+
this.serviceName,
|
|
155
|
+
this.firstPartyHosts?.asFirstPartyHosts(),
|
|
156
|
+
this.bundleLogsWithRum ?: DefaultConfiguration.bundleLogsWithRum,
|
|
157
|
+
this.bundleLogsWithTraces ?: DefaultConfiguration.bundleLogsWithTraces
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
internal fun JSONProxyConfiguration.asProxyConfig(): Pair<Proxy, ProxyAuthenticator?>? {
|
|
162
|
+
return buildProxyConfig(type, address, port, username, password)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
internal fun List<JSONFirstPartyHost>.asFirstPartyHosts(): Map<String, Set<TracingHeaderType>> {
|
|
166
|
+
/**
|
|
167
|
+
* Adapts the data format from the React Native SDK configuration to match with the Android
|
|
168
|
+
* SDK configuration. For example:
|
|
169
|
+
*
|
|
170
|
+
* RN config: [{ match: "example.com", propagatorTypes: [DATADOG, B3] }] Android config: {
|
|
171
|
+
* "example.com": [DATADOG, B3] }
|
|
172
|
+
*/
|
|
173
|
+
val firstPartyHostsWithHeaderTypes = mutableMapOf<String, MutableSet<TracingHeaderType>>()
|
|
174
|
+
|
|
175
|
+
for (host in this) {
|
|
176
|
+
if (host.propagatorTypes.isNotEmpty()) {
|
|
177
|
+
val hostMatch = firstPartyHostsWithHeaderTypes[host.match]
|
|
178
|
+
if (hostMatch != null) {
|
|
179
|
+
hostMatch.addAll(host.propagatorTypes.asTracingHeaderTypes())
|
|
180
|
+
} else {
|
|
181
|
+
firstPartyHostsWithHeaderTypes[host.match] = host.propagatorTypes.asTracingHeaderTypes().toMutableSet()
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return firstPartyHostsWithHeaderTypes
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
internal fun List<String>.asTracingHeaderTypes(): Set<TracingHeaderType> {
|
|
190
|
+
return this.mapNotNull {
|
|
191
|
+
when (it.lowercase()) {
|
|
61
192
|
"datadog" -> TracingHeaderType.DATADOG
|
|
62
193
|
"b3" -> TracingHeaderType.B3
|
|
63
194
|
"b3multi" -> TracingHeaderType.B3MULTI
|
|
@@ -107,3 +238,32 @@ internal fun CustomEndpoints.toReadableMap(): ReadableMap {
|
|
|
107
238
|
trace?.let { map.putString("trace", it) }
|
|
108
239
|
return map
|
|
109
240
|
}
|
|
241
|
+
|
|
242
|
+
private fun buildProxyConfig(type: String, address: String, port: Int, username: String?, password: String?): Pair<Proxy, ProxyAuthenticator?>? {
|
|
243
|
+
val proxyType = when (type.lowercase(Locale.US)) {
|
|
244
|
+
"http", "https" -> Proxy.Type.HTTP
|
|
245
|
+
"socks" -> Proxy.Type.SOCKS
|
|
246
|
+
else -> {
|
|
247
|
+
Log.w(
|
|
248
|
+
DdSdk::class.java.canonicalName,
|
|
249
|
+
"Unknown proxy type given: $type, skipping proxy configuration."
|
|
250
|
+
)
|
|
251
|
+
null
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (proxyType == null) {
|
|
256
|
+
return null
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
val proxy = Proxy(proxyType, InetSocketAddress(address, port))
|
|
260
|
+
|
|
261
|
+
val authenticator =
|
|
262
|
+
if (username != null && password != null) {
|
|
263
|
+
ProxyAuthenticator(username, password)
|
|
264
|
+
} else {
|
|
265
|
+
null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return Pair(proxy, authenticator)
|
|
269
|
+
}
|