@datadog/mobile-react-native 2.0.4 → 2.1.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/android/build.gradle +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +63 -8
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +5 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkBridgeExt.kt +4 -2
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +14 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +17 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +38 -4
- package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +1 -1
- package/android/src/newarch/kotlin/com/datadog/reactnative/DdSdk.kt +8 -0
- package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +8 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +53 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +13 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +24 -5
- package/android/src/test/kotlin/com/datadog/tools/unit/RemoveFinalModifierJava.java +32 -0
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +7 -1
- package/ios/Sources/DatadogSDKWrapper.swift +163 -0
- package/ios/Sources/DdLogsImplementation.swift +1 -2
- package/ios/Sources/DdSdk.mm +10 -0
- package/ios/Sources/DdSdkConfiguration.swift +21 -1
- package/ios/Sources/DdSdkImplementation.swift +56 -17
- package/ios/Sources/RNDdSdkConfiguration.swift +14 -0
- package/jest/mock.js +3 -0
- package/lib/commonjs/DdSdkReactNative.js +7 -1
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +5 -3
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/specs/NativeDdLogs.js.map +1 -1
- package/lib/commonjs/specs/NativeDdSdk.js.map +1 -1
- package/lib/commonjs/types.js +2 -1
- 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 +6 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +5 -3
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/specs/NativeDdLogs.js.map +1 -1
- package/lib/module/specs/NativeDdSdk.js.map +1 -1
- package/lib/module/types.js +2 -1
- 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 +5 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +7 -0
- package/lib/typescript/specs/NativeDdLogs.d.ts +8 -8
- package/lib/typescript/specs/NativeDdSdk.d.ts +4 -0
- package/lib/typescript/types.d.ts +10 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +10 -0
- package/src/DdSdkReactNativeConfiguration.tsx +11 -1
- package/src/__tests__/DdSdkReactNative.test.tsx +44 -0
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +15 -2
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +1 -0
- package/src/specs/NativeDdLogs.ts +20 -20
- package/src/specs/NativeDdSdk.ts +5 -0
- package/src/types.tsx +5 -0
- package/src/version.ts +1 -1
package/android/build.gradle
CHANGED
|
@@ -217,6 +217,10 @@ tasks.withType(Test) {
|
|
|
217
217
|
useJUnitPlatform {
|
|
218
218
|
includeEngines("spek", "junit-jupiter", "junit-vintage")
|
|
219
219
|
}
|
|
220
|
+
jvmArgs(
|
|
221
|
+
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
|
|
222
|
+
"--add-opens=java.base/java.util.concurrent=ALL-UNNAMED"
|
|
223
|
+
)
|
|
220
224
|
reports {
|
|
221
225
|
junitXml.required.set(true)
|
|
222
226
|
html.required.set(true)
|
|
@@ -7,8 +7,11 @@
|
|
|
7
7
|
package com.datadog.reactnative
|
|
8
8
|
|
|
9
9
|
import android.content.Context
|
|
10
|
+
import android.util.Log
|
|
10
11
|
import com.datadog.android.Datadog
|
|
11
12
|
import com.datadog.android._InternalProxy
|
|
13
|
+
import com.datadog.android.api.SdkCore
|
|
14
|
+
import com.datadog.android.core.InternalSdkCore
|
|
12
15
|
import com.datadog.android.core.configuration.Configuration
|
|
13
16
|
import com.datadog.android.log.Logs
|
|
14
17
|
import com.datadog.android.log.LogsConfiguration
|
|
@@ -21,6 +24,51 @@ import com.datadog.android.trace.Trace
|
|
|
21
24
|
import com.datadog.android.trace.TraceConfiguration
|
|
22
25
|
import com.datadog.android.webview.WebViewTracking
|
|
23
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Internal object used to add internal testing.
|
|
29
|
+
*/
|
|
30
|
+
object DatadogSDKWrapperStorage {
|
|
31
|
+
internal val onInitializedListeners: MutableList<(InternalSdkCore) -> Unit> = mutableListOf()
|
|
32
|
+
private var core: InternalSdkCore? = null
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Adds a Listener called when the core is initialized.
|
|
36
|
+
*/
|
|
37
|
+
fun addOnInitializedListener(listener: (InternalSdkCore) -> Unit) {
|
|
38
|
+
onInitializedListeners.add(listener)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Exposed for testing purposes only.
|
|
43
|
+
*/
|
|
44
|
+
fun notifyOnInitializedListeners(ddCore: InternalSdkCore) {
|
|
45
|
+
for (listener in onInitializedListeners) {
|
|
46
|
+
listener(ddCore)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Sets instance of core SDK to be used to initialize features.
|
|
52
|
+
*/
|
|
53
|
+
fun setSdkCore(core: InternalSdkCore?) {
|
|
54
|
+
this.core = core
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns the core set by setSdkCore or the default core instance by default.
|
|
59
|
+
*/
|
|
60
|
+
fun getSdkCore(): SdkCore {
|
|
61
|
+
core?.let {
|
|
62
|
+
return it
|
|
63
|
+
}
|
|
64
|
+
Log.d(
|
|
65
|
+
DatadogSDKWrapperStorage::class.java.canonicalName,
|
|
66
|
+
"SdkCore was not set in DatadogSDKWrapperStorage, using default instance."
|
|
67
|
+
)
|
|
68
|
+
return Datadog.getInstance()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
24
72
|
internal class DatadogSDKWrapper : DatadogWrapper {
|
|
25
73
|
|
|
26
74
|
// We use Kotlin backing field here to initialize once the telemetry proxy
|
|
@@ -39,7 +87,7 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
39
87
|
private var webViewProxy: WebViewTracking._InternalWebViewProxy? = null
|
|
40
88
|
get() {
|
|
41
89
|
if (field == null && isInitialized()) {
|
|
42
|
-
field = WebViewTracking._InternalWebViewProxy(
|
|
90
|
+
field = WebViewTracking._InternalWebViewProxy(DatadogSDKWrapperStorage.getSdkCore())
|
|
43
91
|
}
|
|
44
92
|
|
|
45
93
|
return field
|
|
@@ -54,19 +102,21 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
54
102
|
configuration: Configuration,
|
|
55
103
|
consent: TrackingConsent
|
|
56
104
|
) {
|
|
57
|
-
Datadog.initialize(context, configuration, consent)
|
|
105
|
+
val core = Datadog.initialize(context, configuration, consent)
|
|
106
|
+
DatadogSDKWrapperStorage.setSdkCore(core as InternalSdkCore)
|
|
107
|
+
DatadogSDKWrapperStorage.notifyOnInitializedListeners(core)
|
|
58
108
|
}
|
|
59
109
|
|
|
60
110
|
override fun enableRum(configuration: RumConfiguration) {
|
|
61
|
-
Rum.enable(configuration)
|
|
111
|
+
Rum.enable(configuration, DatadogSDKWrapperStorage.getSdkCore())
|
|
62
112
|
}
|
|
63
113
|
|
|
64
114
|
override fun enableLogs(configuration: LogsConfiguration) {
|
|
65
|
-
Logs.enable(configuration)
|
|
115
|
+
Logs.enable(configuration, DatadogSDKWrapperStorage.getSdkCore())
|
|
66
116
|
}
|
|
67
117
|
|
|
68
118
|
override fun enableTrace(configuration: TraceConfiguration) {
|
|
69
|
-
Trace.enable(configuration)
|
|
119
|
+
Trace.enable(configuration, DatadogSDKWrapperStorage.getSdkCore())
|
|
70
120
|
}
|
|
71
121
|
|
|
72
122
|
override fun setUserInfo(
|
|
@@ -80,8 +130,8 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
80
130
|
|
|
81
131
|
override fun addRumGlobalAttributes(attributes: Map<String, Any?>) {
|
|
82
132
|
val rumMonitor = this.getRumMonitor()
|
|
83
|
-
attributes
|
|
84
|
-
rumMonitor.addAttribute(
|
|
133
|
+
for (attribute in attributes) {
|
|
134
|
+
rumMonitor.addAttribute(attribute.key, attribute.value)
|
|
85
135
|
}
|
|
86
136
|
}
|
|
87
137
|
|
|
@@ -110,6 +160,11 @@ internal class DatadogSDKWrapper : DatadogWrapper {
|
|
|
110
160
|
}
|
|
111
161
|
|
|
112
162
|
override fun getRumMonitor(): RumMonitor {
|
|
113
|
-
return GlobalRumMonitor.get()
|
|
163
|
+
return GlobalRumMonitor.get(DatadogSDKWrapperStorage.getSdkCore())
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
override fun clearAllData() {
|
|
167
|
+
return Datadog.clearAllData(DatadogSDKWrapperStorage.getSdkCore())
|
|
114
168
|
}
|
|
115
169
|
}
|
|
170
|
+
|
|
@@ -19,7 +19,7 @@ class DdLogsImplementation(
|
|
|
19
19
|
private val datadog: DatadogWrapper = DatadogSDKWrapper()
|
|
20
20
|
) {
|
|
21
21
|
private val reactNativeLogger: Logger by lazy {
|
|
22
|
-
logger ?: Logger.Builder()
|
|
22
|
+
logger ?: Logger.Builder(DatadogSDKWrapperStorage.getSdkCore())
|
|
23
23
|
.setLogcatLogsEnabled(true)
|
|
24
24
|
.setName("DdLogs")
|
|
25
25
|
.build()
|
|
@@ -11,7 +11,8 @@ import com.facebook.react.bridge.WritableNativeMap
|
|
|
11
11
|
|
|
12
12
|
internal fun List<*>.toWritableArray(): WritableNativeArray {
|
|
13
13
|
val list = WritableNativeArray()
|
|
14
|
-
|
|
14
|
+
for (it in iterator()) {
|
|
15
|
+
@Suppress("NotImplementedDeclaration")
|
|
15
16
|
when (it) {
|
|
16
17
|
null -> list.pushNull()
|
|
17
18
|
is Int -> list.pushInt(it)
|
|
@@ -29,8 +30,9 @@ internal fun List<*>.toWritableArray(): WritableNativeArray {
|
|
|
29
30
|
|
|
30
31
|
internal fun Map<*, *>.toWritableMap(): WritableNativeMap {
|
|
31
32
|
val map = WritableNativeMap()
|
|
32
|
-
|
|
33
|
+
for ((k,v) in iterator()) {
|
|
33
34
|
val key = (k as? String) ?: k.toString()
|
|
35
|
+
@Suppress("NotImplementedDeclaration")
|
|
34
36
|
when (v) {
|
|
35
37
|
null -> map.putNull(key)
|
|
36
38
|
is Int -> map.putInt(key, v)
|
|
@@ -23,6 +23,7 @@ package com.datadog.reactnative
|
|
|
23
23
|
* @param uploadFrequency The frequency to which batches of data are sent (can be 'RARE', 'AVERAGE' (default), 'FREQUENT')
|
|
24
24
|
* @param batchSize The preferred size for uploaded batches of data (can be 'SMALL', 'MEDIUM' (default), 'LARGE')
|
|
25
25
|
* @param trackBackgroundEvents Enables/Disables tracking RUM event when no RUM View is active. Might increase number of sessions and billing.
|
|
26
|
+
* @param customEndpoints Custom endpoints for RUM/Logs/Trace features.
|
|
26
27
|
* @param additionalConfig Additional configuration parameters.
|
|
27
28
|
* @param configurationForTelemetry Additional configuration data for Datadog telemetry.
|
|
28
29
|
*/
|
|
@@ -42,6 +43,7 @@ data class DdSdkConfiguration(
|
|
|
42
43
|
val uploadFrequency: String? = null,
|
|
43
44
|
val batchSize: String? = null,
|
|
44
45
|
val trackBackgroundEvents: Boolean? = null,
|
|
46
|
+
val customEndpoints: CustomEndpoints? = null,
|
|
45
47
|
val additionalConfig: Map<String, Any?>? = null,
|
|
46
48
|
val configurationForTelemetry: ConfigurationForTelemetry? = null
|
|
47
49
|
)
|
|
@@ -63,3 +65,15 @@ data class ConfigurationForTelemetry(
|
|
|
63
65
|
val reactVersion: String? = null,
|
|
64
66
|
val reactNativeVersion: String? = null
|
|
65
67
|
)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Custom endpoints for features.
|
|
71
|
+
* @param rum Custom endpoint for RUM.
|
|
72
|
+
* @param logs Custom endpoint for Logs.
|
|
73
|
+
* @param trace Custom endpoint for Trace.
|
|
74
|
+
*/
|
|
75
|
+
data class CustomEndpoints(
|
|
76
|
+
val rum: String? = null,
|
|
77
|
+
val logs: String? = null,
|
|
78
|
+
val trace: String? = null
|
|
79
|
+
)
|
|
@@ -28,6 +28,7 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
|
|
|
28
28
|
uploadFrequency = getString("uploadFrequency"),
|
|
29
29
|
batchSize = getString("batchSize"),
|
|
30
30
|
trackBackgroundEvents = getBoolean("trackBackgroundEvents"),
|
|
31
|
+
customEndpoints = getMap("customEndpoints")?.asCustomEndpoints(),
|
|
31
32
|
additionalConfig = getMap("additionalConfig")?.toHashMap(),
|
|
32
33
|
configurationForTelemetry = getMap(
|
|
33
34
|
"configurationForTelemetry"
|
|
@@ -46,6 +47,14 @@ internal fun ReadableMap.asConfigurationForTelemetry(): ConfigurationForTelemetr
|
|
|
46
47
|
)
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
internal fun ReadableMap.asCustomEndpoints(): CustomEndpoints {
|
|
51
|
+
return CustomEndpoints(
|
|
52
|
+
rum = getString("rum"),
|
|
53
|
+
logs = getString("logs"),
|
|
54
|
+
trace = getString("trace"),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
internal fun ReadableArray.asTracingHeaderTypes(): Set<TracingHeaderType> {
|
|
50
59
|
return this.toArrayList().mapNotNull {
|
|
51
60
|
when (it) {
|
|
@@ -90,3 +99,11 @@ internal fun ConfigurationForTelemetry.toReadableMap(): ReadableMap {
|
|
|
90
99
|
reactNativeVersion?.let { map.putString("reactNativeVersion", it) }
|
|
91
100
|
return map
|
|
92
101
|
}
|
|
102
|
+
|
|
103
|
+
internal fun CustomEndpoints.toReadableMap(): ReadableMap {
|
|
104
|
+
val map = WritableNativeMap()
|
|
105
|
+
rum?.let { map.putString("rum", it) }
|
|
106
|
+
logs?.let { map.putString("logs", it) }
|
|
107
|
+
trace?.let { map.putString("trace", it) }
|
|
108
|
+
return map
|
|
109
|
+
}
|
|
@@ -56,6 +56,8 @@ class DdSdkImplementation(
|
|
|
56
56
|
val ddSdkConfiguration = configuration.asDdSdkConfiguration()
|
|
57
57
|
val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration)
|
|
58
58
|
val rumConfiguration = buildRumConfiguration(ddSdkConfiguration)
|
|
59
|
+
val logsConfiguration = buildLogsConfiguration(ddSdkConfiguration)
|
|
60
|
+
val traceConfiguration = buildTraceConfiguration(ddSdkConfiguration)
|
|
59
61
|
val trackingConsent = buildTrackingConsent(ddSdkConfiguration.trackingConsent)
|
|
60
62
|
|
|
61
63
|
configureSdkVerbosity(ddSdkConfiguration)
|
|
@@ -65,9 +67,9 @@ class DdSdkImplementation(
|
|
|
65
67
|
datadog.enableRum(rumConfiguration)
|
|
66
68
|
monitorJsRefreshRate(ddSdkConfiguration)
|
|
67
69
|
|
|
68
|
-
datadog.enableTrace(
|
|
70
|
+
datadog.enableTrace(traceConfiguration)
|
|
69
71
|
|
|
70
|
-
datadog.enableLogs(
|
|
72
|
+
datadog.enableLogs(logsConfiguration)
|
|
71
73
|
|
|
72
74
|
initialized.set(true)
|
|
73
75
|
|
|
@@ -81,7 +83,9 @@ class DdSdkImplementation(
|
|
|
81
83
|
*/
|
|
82
84
|
fun setAttributes(attributes: ReadableMap, promise: Promise) {
|
|
83
85
|
datadog.addRumGlobalAttributes(attributes.toHashMap())
|
|
84
|
-
|
|
86
|
+
for ((k,v) in attributes.toHashMap()) {
|
|
87
|
+
GlobalState.addAttribute(k, v)
|
|
88
|
+
}
|
|
85
89
|
promise.resolve(null)
|
|
86
90
|
}
|
|
87
91
|
|
|
@@ -138,6 +142,14 @@ class DdSdkImplementation(
|
|
|
138
142
|
promise.resolve(null)
|
|
139
143
|
}
|
|
140
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Clears all data that has not already been sent to Datadog servers.
|
|
147
|
+
*/
|
|
148
|
+
fun clearAllData(promise: Promise) {
|
|
149
|
+
datadog.clearAllData()
|
|
150
|
+
promise.resolve(null)
|
|
151
|
+
}
|
|
152
|
+
|
|
141
153
|
// endregion
|
|
142
154
|
|
|
143
155
|
// region Internal
|
|
@@ -276,6 +288,28 @@ class DdSdkImplementation(
|
|
|
276
288
|
}
|
|
277
289
|
)
|
|
278
290
|
|
|
291
|
+
configuration.customEndpoints?.rum?.let {
|
|
292
|
+
configBuilder.useCustomEndpoint(it)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return configBuilder.build()
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private fun buildLogsConfiguration(configuration: DdSdkConfiguration): LogsConfiguration {
|
|
299
|
+
val configBuilder = LogsConfiguration.Builder()
|
|
300
|
+
configuration.customEndpoints?.logs?.let {
|
|
301
|
+
configBuilder.useCustomEndpoint(it)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return configBuilder.build()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private fun buildTraceConfiguration(configuration: DdSdkConfiguration): TraceConfiguration {
|
|
308
|
+
val configBuilder = TraceConfiguration.Builder()
|
|
309
|
+
configuration.customEndpoints?.trace?.let {
|
|
310
|
+
configBuilder.useCustomEndpoint(it)
|
|
311
|
+
}
|
|
312
|
+
|
|
279
313
|
return configBuilder.build()
|
|
280
314
|
}
|
|
281
315
|
|
|
@@ -291,7 +325,7 @@ class DdSdkImplementation(
|
|
|
291
325
|
*/
|
|
292
326
|
val firstPartyHostsWithHeaderTypes = mutableMapOf<String, MutableSet<TracingHeaderType>>()
|
|
293
327
|
|
|
294
|
-
firstPartyHosts
|
|
328
|
+
for (it in firstPartyHosts) {
|
|
295
329
|
val match = it.getString("match")
|
|
296
330
|
val propagatorTypes = it.getArray("propagatorTypes")?.asTracingHeaderTypes()
|
|
297
331
|
if (match != null && propagatorTypes != null && propagatorTypes.isNotEmpty()) {
|
|
@@ -87,4 +87,12 @@ class DdSdk(
|
|
|
87
87
|
override fun consumeWebviewEvent(message: String, promise: Promise) {
|
|
88
88
|
implementation.consumeWebviewEvent(message, promise)
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Clears all data that has not already been sent to Datadog servers.
|
|
93
|
+
*/
|
|
94
|
+
@ReactMethod
|
|
95
|
+
override fun clearAllData(promise: Promise) {
|
|
96
|
+
implementation.clearAllData(promise)
|
|
97
|
+
}
|
|
90
98
|
}
|
|
@@ -88,4 +88,12 @@ class DdSdk(
|
|
|
88
88
|
fun consumeWebviewEvent(message: String, promise: Promise) {
|
|
89
89
|
implementation.consumeWebviewEvent(message, promise)
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Clears all data that has not already been sent to Datadog servers.
|
|
94
|
+
*/
|
|
95
|
+
@ReactMethod
|
|
96
|
+
fun clearAllData(promise: Promise) {
|
|
97
|
+
implementation.clearAllData(promise)
|
|
98
|
+
}
|
|
91
99
|
}
|
|
@@ -149,6 +149,9 @@ internal class DdSdkTest {
|
|
|
149
149
|
true
|
|
150
150
|
}
|
|
151
151
|
testedBridgeSdk = DdSdkImplementation(mockReactContext, mockDatadog)
|
|
152
|
+
|
|
153
|
+
DatadogSDKWrapperStorage.setSdkCore(null)
|
|
154
|
+
DatadogSDKWrapperStorage.onInitializedListeners.clear()
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
@AfterEach
|
|
@@ -2503,6 +2506,56 @@ internal class DdSdkTest {
|
|
|
2503
2506
|
assertThat(authenticator?.password).isEqualTo(proxyPassword)
|
|
2504
2507
|
}
|
|
2505
2508
|
|
|
2509
|
+
fun `𝕄 initialize native SDK 𝕎 initialize() {with custom endpoints}`(
|
|
2510
|
+
forge: Forge
|
|
2511
|
+
) {
|
|
2512
|
+
// Given
|
|
2513
|
+
val customRumEndpoint = forge.aNullable { aString() }
|
|
2514
|
+
val customLogsEndpoint = forge.aNullable { aString() }
|
|
2515
|
+
val customTraceEndpoint = forge.aNullable { aString() }
|
|
2516
|
+
val bridgeConfiguration = fakeConfiguration.copy(
|
|
2517
|
+
customEndpoints = CustomEndpoints(
|
|
2518
|
+
rum = customRumEndpoint,
|
|
2519
|
+
logs = customLogsEndpoint,
|
|
2520
|
+
trace = customTraceEndpoint
|
|
2521
|
+
)
|
|
2522
|
+
)
|
|
2523
|
+
val rumConfigCaptor = argumentCaptor<RumConfiguration>()
|
|
2524
|
+
val logsConfigCaptor = argumentCaptor<LogsConfiguration>()
|
|
2525
|
+
val traceConfigCaptor = argumentCaptor<TraceConfiguration>()
|
|
2526
|
+
|
|
2527
|
+
// When
|
|
2528
|
+
testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise)
|
|
2529
|
+
|
|
2530
|
+
// Then
|
|
2531
|
+
inOrder(mockDatadog) {
|
|
2532
|
+
verify(mockDatadog).enableRum(rumConfigCaptor.capture())
|
|
2533
|
+
verify(mockDatadog).enableTrace(traceConfigCaptor.capture())
|
|
2534
|
+
verify(mockDatadog).enableLogs(logsConfigCaptor.capture())
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
assertThat(rumConfigCaptor.firstValue)
|
|
2538
|
+
.hasField("featureConfiguration") {
|
|
2539
|
+
it.hasFieldEqualTo("customEndpointUrl", customRumEndpoint)
|
|
2540
|
+
}
|
|
2541
|
+
assertThat(logsConfigCaptor.firstValue)
|
|
2542
|
+
.hasFieldEqualTo("customEndpointUrl", customLogsEndpoint)
|
|
2543
|
+
assertThat(traceConfigCaptor.firstValue)
|
|
2544
|
+
.hasFieldEqualTo("customEndpointUrl", customTraceEndpoint)
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
@Test
|
|
2548
|
+
fun `𝕄 clear all data 𝕎 clearAllData()`() {
|
|
2549
|
+
// When
|
|
2550
|
+
testedBridgeSdk.clearAllData(mockPromise)
|
|
2551
|
+
|
|
2552
|
+
// Then
|
|
2553
|
+
argumentCaptor<Map<String, Any?>> {
|
|
2554
|
+
verify(mockDatadog)
|
|
2555
|
+
.clearAllData()
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2506
2559
|
// endregion
|
|
2507
2560
|
|
|
2508
2561
|
// region Internal
|
|
@@ -10,7 +10,9 @@ import com.datadog.android.core.configuration.BatchSize
|
|
|
10
10
|
import com.datadog.android.core.configuration.UploadFrequency
|
|
11
11
|
import com.datadog.android.rum.configuration.VitalsUpdateFrequency
|
|
12
12
|
import com.datadog.reactnative.ConfigurationForTelemetry
|
|
13
|
+
import com.datadog.reactnative.CustomEndpoints
|
|
13
14
|
import com.datadog.reactnative.DdSdkConfiguration
|
|
15
|
+
import com.datadog.reactnative.toReadableMap
|
|
14
16
|
import com.facebook.react.bridge.ReadableMap
|
|
15
17
|
|
|
16
18
|
fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
@@ -76,6 +78,9 @@ fun DdSdkConfiguration.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
76
78
|
} else {
|
|
77
79
|
trackBackgroundEvents
|
|
78
80
|
}
|
|
81
|
+
customEndpoints?.let {
|
|
82
|
+
map.put("customEndpoints", it.toReadableJavaOnlyMap())
|
|
83
|
+
}
|
|
79
84
|
additionalConfig?.let { map.put("additionalConfig", it.toReadableMap()) }
|
|
80
85
|
configurationForTelemetry?.let {
|
|
81
86
|
map.put("configurationForTelemetry", it.toReadableJavaOnlyMap())
|
|
@@ -93,3 +98,11 @@ internal fun ConfigurationForTelemetry.toReadableJavaOnlyMap(): ReadableMap {
|
|
|
93
98
|
reactNativeVersion?.let { map.put("reactNativeVersion", it) }
|
|
94
99
|
return map.toReadableMap()
|
|
95
100
|
}
|
|
101
|
+
|
|
102
|
+
internal fun CustomEndpoints.toReadableJavaOnlyMap(): ReadableMap {
|
|
103
|
+
val map = mutableMapOf<String, Any?>()
|
|
104
|
+
rum?.let { map.put("rum", it) }
|
|
105
|
+
logs?.let { map.put("logs", it) }
|
|
106
|
+
trace?.let { map.put("trace", it) }
|
|
107
|
+
return map.toReadableMap()
|
|
108
|
+
}
|
|
@@ -48,12 +48,22 @@ inline fun <reified T, R> Class<T>.setStaticValue(
|
|
|
48
48
|
|
|
49
49
|
// Make it non final
|
|
50
50
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// Android JVM does not use the JDK sources for reflection therefore the property access type
|
|
52
|
+
// field is named `accessFlags` instead of `modifiers` as in a default JVM
|
|
53
|
+
// Because these methods are being shared between JUnit and AndroidJUnit runtimes we will
|
|
54
|
+
// have to support both implementations.
|
|
55
|
+
val androidVmAccessField = resolveAndroidVMAccessField()
|
|
56
|
+
if (androidVmAccessField == null) {
|
|
57
|
+
// by some reason Kotlin produces wrong java bytecode while working with VarHandle,
|
|
58
|
+
// resulting to the following (basically for .set(Field, int) it creates
|
|
59
|
+
// .set(new Object[...]), because .set has vararg signature):
|
|
60
|
+
// cannot convert MethodHandle(VarHandle,Field,int)void to (VarHandle,Object[])void
|
|
61
|
+
// so will do the work on Java side
|
|
62
|
+
RemoveFinalModifierJava.remove(field)
|
|
63
|
+
} else {
|
|
64
|
+
androidVmAccessField.set(field, field.modifiers and Modifier.FINAL.inv())
|
|
65
|
+
}
|
|
54
66
|
} catch (e: NoSuchFieldException) {
|
|
55
|
-
// do nothing
|
|
56
|
-
@Suppress("PrintStackTrace")
|
|
57
67
|
e.printStackTrace()
|
|
58
68
|
}
|
|
59
69
|
field.set(null, fieldValue)
|
|
@@ -264,3 +274,12 @@ private fun <T : Any> T.getDeclaredMethodRecursively(
|
|
|
264
274
|
|
|
265
275
|
return method
|
|
266
276
|
}
|
|
277
|
+
|
|
278
|
+
@SuppressWarnings("SwallowedException")
|
|
279
|
+
fun resolveAndroidVMAccessField(): Field? {
|
|
280
|
+
return try {
|
|
281
|
+
Field::class.java.getDeclaredField("accessFlags")
|
|
282
|
+
} catch (e: NoSuchFieldException) {
|
|
283
|
+
null
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
package com.datadog.tools.unit;
|
|
8
|
+
|
|
9
|
+
import java.lang.invoke.MethodHandles;
|
|
10
|
+
import java.lang.reflect.Field;
|
|
11
|
+
import java.lang.reflect.Modifier;
|
|
12
|
+
|
|
13
|
+
public class RemoveFinalModifierJava {
|
|
14
|
+
|
|
15
|
+
// Supposed to be run only for JVM
|
|
16
|
+
// by some reason Kotlin produces wrong java bytecode while working with VarHandle,
|
|
17
|
+
// resulting to the following (basically for .set(Field, int) it creates
|
|
18
|
+
// .set(new Object[...]), because .set has vararg signature):
|
|
19
|
+
// cannot convert MethodHandle(VarHandle,Field,int)void to (VarHandle,Object[])void
|
|
20
|
+
// so will do the work on Java side
|
|
21
|
+
@SuppressWarnings("NewApi")
|
|
22
|
+
static public void remove(Field field) {
|
|
23
|
+
try {
|
|
24
|
+
var lookup = MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup());
|
|
25
|
+
//noinspection JavaLangInvokeHandleSignature
|
|
26
|
+
var handle = lookup.findVarHandle(Field.class, "modifiers", int.class);
|
|
27
|
+
handle.set(field, field.getModifiers() & ~Modifier.FINAL);
|
|
28
|
+
} catch (IllegalAccessException | NoSuchFieldException e) {
|
|
29
|
+
throw new RuntimeException(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
package com.datadog.tools.unit.forge
|
|
8
8
|
|
|
9
9
|
import com.datadog.reactnative.ConfigurationForTelemetry
|
|
10
|
+
import com.datadog.reactnative.CustomEndpoints
|
|
10
11
|
import com.datadog.reactnative.DdSdkConfiguration
|
|
11
12
|
import fr.xgouchet.elmyr.Forge
|
|
12
13
|
import fr.xgouchet.elmyr.ForgeryFactory
|
|
@@ -65,7 +66,12 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory<DdSdkConfiguration> {
|
|
|
65
66
|
reactVersion = forge.aString(),
|
|
66
67
|
reactNativeVersion = forge.aString()
|
|
67
68
|
),
|
|
68
|
-
trackFrustrations = forge.aNullable { aBool() }
|
|
69
|
+
trackFrustrations = forge.aNullable { aBool() },
|
|
70
|
+
customEndpoints = CustomEndpoints(
|
|
71
|
+
rum = forge.aNullable { aString() },
|
|
72
|
+
logs = forge.aNullable { aString() },
|
|
73
|
+
trace = forge.aNullable { aString() }
|
|
74
|
+
)
|
|
69
75
|
)
|
|
70
76
|
}
|
|
71
77
|
}
|