From 8a70f02a4d7a69659178fe6ea71f58b1bb0afd2f Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Thu, 31 Aug 2023 14:07:32 +0200 Subject: [PATCH 01/12] Update Android SDK to v2 --- example/android/build.gradle | 3 +- packages/core/android/build.gradle | 5 +- packages/core/android/gradle.properties | 2 +- .../datadog/reactnative/DatadogSDKWrapper.kt | 26 ++-- .../com/datadog/reactnative/DatadogWrapper.kt | 9 -- .../reactnative/DdLogsImplementation.kt | 3 +- .../reactnative/DdRumImplementation.kt | 24 +-- .../reactnative/DdSdkConfigurationExt.kt | 2 +- .../reactnative/DdSdkImplementation.kt | 138 +++++++++--------- .../reactnative/DdTraceImplementation.kt | 12 +- 10 files changed, 113 insertions(+), 111 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 4dcd21c1c..0aa14077a 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -2,7 +2,6 @@ buildscript { ext { - RNNKotlinVersion = "1.5.31" buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 @@ -16,7 +15,7 @@ buildscript { mavenCentral() } dependencies { - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.21" classpath("com.android.tools.build:gradle:7.3.1") classpath("com.facebook.react:react-native-gradle-plugin") } diff --git a/packages/core/android/build.gradle b/packages/core/android/build.gradle index 493864754..f2aff0433 100644 --- a/packages/core/android/build.gradle +++ b/packages/core/android/build.gradle @@ -159,7 +159,10 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compileOnly "com.squareup.okhttp3:okhttp:3.12.13" - implementation "com.datadoghq:dd-sdk-android:1.19.2" + implementation "com.datadoghq:dd-sdk-android-rum:2.0.0" + implementation "com.datadoghq:dd-sdk-android-logs:2.0.0" + implementation "com.datadoghq:dd-sdk-android-trace:2.0.0" + implementation "com.datadoghq:dd-sdk-android-webview:2.0.0" testImplementation "org.junit.platform:junit-platform-launcher:1.6.2" testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2" testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2" diff --git a/packages/core/android/gradle.properties b/packages/core/android/gradle.properties index 0401e18b4..4f16df59e 100644 --- a/packages/core/android/gradle.properties +++ b/packages/core/android/gradle.properties @@ -1,4 +1,4 @@ -DdSdkReactNative_kotlinVersion=1.6.21 +DdSdkReactNative_kotlinVersion=1.7.21 DdSdkReactNative_compileSdkVersion=31 DdSdkReactNative_buildToolsVersion=31.0.0 DdSdkReactNative_targetSdkVersion=31 diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt index 8a501fecd..7918dcb52 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt @@ -9,10 +9,9 @@ package com.datadog.reactnative import android.content.Context import com.datadog.android.Datadog import com.datadog.android.core.configuration.Configuration -import com.datadog.android.core.configuration.Credentials import com.datadog.android.privacy.TrackingConsent -import com.datadog.android.rum.GlobalRum -import com.datadog.android.rum.RumMonitor +import com.datadog.android.rum.GlobalRumMonitor +import com.datadog.android.webview.WebViewTracking internal class DatadogSDKWrapper : DatadogWrapper { @@ -22,11 +21,10 @@ internal class DatadogSDKWrapper : DatadogWrapper { override fun initialize( context: Context, - credentials: Credentials, configuration: Configuration, consent: TrackingConsent ) { - Datadog.initialize(context, credentials, configuration, consent) + Datadog.initialize(context, configuration, consent) } override fun setUserInfo( @@ -38,13 +36,9 @@ internal class DatadogSDKWrapper : DatadogWrapper { Datadog.setUserInfo(id, name, email, extraInfo) } - override fun registerRumMonitor(rumMonitor: RumMonitor) { - GlobalRum.registerIfAbsent(rumMonitor) - } - override fun addRumGlobalAttributes(attributes: Map) { attributes.forEach { - GlobalRum.addAttribute(it.key, it.value) + GlobalRumMonitor.get().addAttribute(it.key, it.value) } } @@ -53,19 +47,23 @@ internal class DatadogSDKWrapper : DatadogWrapper { } override fun telemetryDebug(message: String) { - Datadog._internal._telemetry.debug(message) + // TODO: store instance of proxy to avoid creating one every time + Datadog._internalProxy()._telemetry.debug(message) } override fun telemetryError(message: String, stack: String?, kind: String?) { - Datadog._internal._telemetry.error(message, stack, kind) + // TODO: store instance of proxy to avoid creating one every time + Datadog._internalProxy()._telemetry.error(message, stack, kind) } override fun telemetryError(message: String, throwable: Throwable?) { - Datadog._internal._telemetry.error(message, throwable) + // TODO: store instance of proxy to avoid creating one every time + Datadog._internalProxy()._telemetry.error(message, throwable) } override fun consumeWebviewEvent(message: String) { - Datadog._internal.consumeWebviewEvent(message) + // TODO: store instance of proxy to avoid creating one every time + WebViewTracking._InternalWebViewProxy(Datadog.getInstance()).consumeWebviewEvent(message) } override fun isInitialized(): Boolean { diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt index 3c39e7303..c568082e7 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt @@ -8,7 +8,6 @@ package com.datadog.reactnative import android.content.Context import com.datadog.android.core.configuration.Configuration -import com.datadog.android.core.configuration.Credentials import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.RumMonitor import java.lang.IllegalArgumentException @@ -45,7 +44,6 @@ interface DatadogWrapper { */ fun initialize( context: Context, - credentials: Credentials, configuration: Configuration, consent: TrackingConsent ) @@ -66,13 +64,6 @@ interface DatadogWrapper { extraInfo: Map ) - /** - * Registers a given monitor in [GlobalRum]. - * - * @param rumMonitor to register - */ - fun registerRumMonitor(rumMonitor: RumMonitor) - /** * Adds global attributes. * diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt index 5dbcf41c8..f57b00ff8 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt @@ -20,9 +20,8 @@ class DdLogsImplementation( ) { private val reactNativeLogger: Logger by lazy { logger ?: Logger.Builder() - .setDatadogLogsEnabled(true) .setLogcatLogsEnabled(true) - .setLoggerName("DdLogs") + .setName("DdLogs") .build() } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt index 4fba8f88a..f5d3b58fa 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt @@ -6,7 +6,7 @@ package com.datadog.reactnative -import com.datadog.android.rum.GlobalRum +import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.RumActionType import com.datadog.android.rum.RumAttributes import com.datadog.android.rum.RumErrorSource @@ -37,7 +37,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().startView( + GlobalRumMonitor.get().startView( key = key, name = name, attributes = attributes @@ -55,7 +55,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().stopView( + GlobalRumMonitor.get().stopView( key = key, attributes = attributes ) @@ -79,7 +79,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().startUserAction( + GlobalRumMonitor.get().startAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -104,7 +104,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().stopUserAction( + GlobalRumMonitor.get().stopAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -129,7 +129,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().addUserAction( + GlobalRumMonitor.get().addAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -157,7 +157,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().startResource( + GlobalRumMonitor.get().startResource( key = key, method = method, url = url, @@ -193,7 +193,7 @@ class DdRumImplementation { } else { size.toLong() } - GlobalRum.get().stopResource( + GlobalRumMonitor.get().stopResource( key = key, statusCode = statusCode.toInt(), kind = kind.asRumResourceKind(), @@ -223,7 +223,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRum.get().addErrorWithStacktrace( + GlobalRumMonitor.get().addErrorWithStacktrace( message = message, source = source.asErrorSource(), stacktrace = stacktrace, @@ -237,7 +237,7 @@ class DdRumImplementation { * @param name The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK. */ fun addTiming(name: String, promise: Promise) { - GlobalRum.get().addTiming(name) + GlobalRumMonitor.get().addTiming(name) promise.resolve(null) } @@ -245,7 +245,7 @@ class DdRumImplementation { * Stops the current RUM Session. */ fun stopSession(promise: Promise) { - GlobalRum.get().stopSession() + GlobalRumMonitor.get().stopSession() promise.resolve(null) } @@ -258,7 +258,7 @@ class DdRumImplementation { fun addFeatureFlagEvaluation(name: String, value: ReadableMap, promise: Promise) { val value = value.toHashMap()["value"] if (value != null) { - GlobalRum.get().addFeatureFlagEvaluation(name, value) + GlobalRumMonitor.get().addFeatureFlagEvaluation(name, value) } promise.resolve(null) } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt index 23e2593c9..c2ed552bb 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt @@ -6,7 +6,7 @@ package com.datadog.reactnative -import com.datadog.android.tracing.TracingHeaderType +import com.datadog.android.trace.TracingHeaderType import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.WritableNativeMap diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index 3adcb9306..d3459c75d 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -11,22 +11,26 @@ import android.content.pm.PackageManager import android.util.Log import android.view.Choreographer import com.datadog.android.DatadogSite -import com.datadog.android._InternalProxy import com.datadog.android.core.configuration.BatchSize import com.datadog.android.core.configuration.Configuration -import com.datadog.android.core.configuration.Credentials import com.datadog.android.core.configuration.UploadFrequency -import com.datadog.android.core.configuration.VitalsUpdateFrequency import com.datadog.android.event.EventMapper +import com.datadog.android.log.Logs +import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent -import com.datadog.android.rum.GlobalRum -import com.datadog.android.rum.RumMonitor +import com.datadog.android.rum.configuration.VitalsUpdateFrequency +import com.datadog.android.rum.GlobalRumMonitor +import com.datadog.android.rum.Rum +import com.datadog.android.rum.RumConfiguration import com.datadog.android.rum.RumPerformanceMetric +import com.datadog.android.rum._RumInternalProxy import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ResourceEvent import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy import com.datadog.android.telemetry.model.TelemetryConfigurationEvent -import com.datadog.android.tracing.TracingHeaderType +import com.datadog.android.trace.Trace +import com.datadog.android.trace.TraceConfiguration +import com.datadog.android.trace.TracingHeaderType import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableArray @@ -54,16 +58,21 @@ class DdSdkImplementation( */ fun initialize(configuration: ReadableMap, promise: Promise) { val ddSdkConfiguration = configuration.asDdSdkConfiguration() - val credentials = buildCredentials(ddSdkConfiguration) - val nativeConfiguration = buildConfiguration(ddSdkConfiguration) + val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration) + val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration) val trackingConsent = buildTrackingConsent(ddSdkConfiguration.trackingConsent) configureSdkVerbosity(ddSdkConfiguration) - datadog.initialize(appContext, credentials, nativeConfiguration, trackingConsent) + datadog.initialize(appContext, sdkConfiguration, trackingConsent) - datadog.registerRumMonitor(RumMonitor.Builder().build()) + Rum.enable(rumConfiguration) monitorJsRefreshRate(ddSdkConfiguration) + + Trace.enable(TraceConfiguration.Builder().build()) + + Logs.enable(LogsConfiguration.Builder().build()) + initialized.set(true) promise.resolve(null) @@ -171,49 +180,24 @@ class DdSdkImplementation( } @Suppress("ComplexMethod", "LongMethod", "UnsafeCallOnNullableType") - private fun buildConfiguration(configuration: DdSdkConfiguration): Configuration { - val additionalConfig = configuration.additionalConfig?.toMutableMap() - - val versionSuffix = configuration.additionalConfig?.get(DD_VERSION_SUFFIX) as? String - if (versionSuffix != null && additionalConfig != null) { - val defaultVersion = getDefaultAppVersion() - additionalConfig.put(DD_VERSION, defaultVersion + versionSuffix) - } - + private fun buildRUMConfiguration(configuration: DdSdkConfiguration): RumConfiguration { val configBuilder = - Configuration.Builder( - logsEnabled = true, - tracesEnabled = true, - crashReportsEnabled = configuration.nativeCrashReportEnabled - ?: false, - rumEnabled = true + RumConfiguration.Builder( + applicationId = configuration.applicationId!! ) - .setAdditionalConfiguration( - additionalConfig?.filterValues { it != null }?.mapValues { - it.value!! - } - ?: emptyMap() - ) if (configuration.sampleRate != null) { - configBuilder.sampleRumSessions(configuration.sampleRate.toFloat()) + configBuilder.setSessionSampleRate(configuration.sampleRate.toFloat()) } configBuilder.trackFrustrations(configuration.trackFrustrations ?: true) - configBuilder.trackBackgroundRumEvents(configuration.trackBackgroundEvents ?: false) + configBuilder.trackBackgroundEvents(configuration.trackBackgroundEvents ?: false) - configBuilder.useSite(buildSite(configuration.site)) configBuilder.setVitalsUpdateFrequency( buildVitalUpdateFrequency(configuration.vitalsUpdateFrequency) ) - configBuilder.setUploadFrequency( - buildUploadFrequency(configuration.uploadFrequency) - ) - configBuilder.setBatchSize( - buildBatchSize(configuration.batchSize) - ) val telemetrySampleRate = (configuration.telemetrySampleRate as? Number)?.toFloat() - telemetrySampleRate?.let { configBuilder.sampleTelemetry(it) } + telemetrySampleRate?.let { configBuilder.setTelemetrySampleRate(it) } val longTask = (configuration.nativeLongTaskThresholdMs as? Number)?.toLong() if (longTask != null) { @@ -231,25 +215,10 @@ class DdSdkImplementation( val interactionTracking = configuration.additionalConfig?.get(DD_NATIVE_INTERACTION_TRACKING) as? Boolean if (interactionTracking == false) { - configBuilder.disableInteractionTracking() - } - - @Suppress("UNCHECKED_CAST") - val firstPartyHosts = - (configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) - ?.toArrayList() as? - List - if (firstPartyHosts != null) { - val firstPartyHostsWithHeaderTypes = buildFirstPartyHosts(firstPartyHosts) - - configBuilder.setFirstPartyHostsWithHeaderType(firstPartyHostsWithHeaderTypes) - } - - buildProxyConfiguration(configuration)?.let { (proxy, authenticator) -> - configBuilder.setProxy(proxy, authenticator) + configBuilder.disableUserInteractionTracking() } - configBuilder.setRumResourceEventMapper( + configBuilder.setResourceEventMapper( object : EventMapper { override fun map(event: ResourceEvent): ResourceEvent? { if (event.context?.additionalProperties?.containsKey(DD_DROP_RESOURCE) == @@ -262,7 +231,7 @@ class DdSdkImplementation( } ) - configBuilder.setRumActionEventMapper( + configBuilder.setActionEventMapper( object : EventMapper { override fun map(event: ActionEvent): ActionEvent? { if (event.context?.additionalProperties?.containsKey(DD_DROP_ACTION) == true @@ -274,7 +243,7 @@ class DdSdkImplementation( } ) - _InternalProxy.setTelemetryConfigurationEventMapper( + _RumInternalProxy.setTelemetryConfigurationEventMapper( configBuilder, object : EventMapper { override fun map( @@ -341,15 +310,50 @@ class DdSdkImplementation( return firstPartyHostsWithHeaderTypes } - private fun buildCredentials(configuration: DdSdkConfiguration): Credentials { + private fun buildSDKConfiguration(configuration: DdSdkConfiguration): Configuration { val serviceName = configuration.additionalConfig?.get(DD_SERVICE_NAME) as? String - return Credentials( + val configBuilder = Configuration.Builder( clientToken = configuration.clientToken, - envName = configuration.env, - rumApplicationId = configuration.applicationId, + env = configuration.env, variant = "", - serviceName = serviceName + service = serviceName + ) + + val additionalConfig = configuration.additionalConfig?.toMutableMap() + val versionSuffix = configuration.additionalConfig?.get(DD_VERSION_SUFFIX) as? String + if (versionSuffix != null && additionalConfig != null) { + val defaultVersion = getDefaultAppVersion() + additionalConfig.put(DD_VERSION, defaultVersion + versionSuffix) + } + configBuilder.setAdditionalConfiguration( + additionalConfig?.filterValues { it != null }?.mapValues { + it.value!! + } + ?: emptyMap() + ) + + configBuilder.useSite(buildSite(configuration.site)) + configBuilder.setUploadFrequency( + buildUploadFrequency(configuration.uploadFrequency) + ) + configBuilder.setBatchSize( + buildBatchSize(configuration.batchSize) ) + + buildProxyConfiguration(configuration)?.let { (proxy, authenticator) -> + configBuilder.setProxy(proxy, authenticator) + } + + val firstPartyHosts = + (configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) + ?.toArrayList() as? + List + if (firstPartyHosts != null) { + val firstPartyHostsWithHeaderTypes = buildFirstPartyHosts(firstPartyHosts) + configBuilder.setFirstPartyHostsWithHeaderType(firstPartyHostsWithHeaderTypes) + } + + return configBuilder.build() } internal fun buildTrackingConsent(trackingConsent: String?): TrackingConsent { @@ -489,7 +493,7 @@ class DdSdkImplementation( return { if (jsRefreshRateMonitoringEnabled && it > 0.0) { - GlobalRum.get() + GlobalRumMonitor.get() ._getInternal() ?.updatePerformanceMetric(RumPerformanceMetric.JS_FRAME_TIME, it) } @@ -499,7 +503,7 @@ class DdSdkImplementation( ddSdkConfiguration.longTaskThresholdMs?.toLong() ?: 0L ) ) { - GlobalRum.get()._getInternal()?.addLongTask(it.toLong(), "javascript") + GlobalRumMonitor.get()._getInternal()?.addLongTask(it.toLong(), "javascript") } } } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt index c69b26ebe..7f47221f2 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt @@ -6,18 +6,26 @@ package com.datadog.reactnative -import com.datadog.android.tracing.AndroidTracer +import com.datadog.android.trace.AndroidTracer +import com.datadog.android.trace.Trace +import com.datadog.android.trace.TraceConfiguration import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReadableMap import io.opentracing.Span import io.opentracing.Tracer +import io.opentracing.util.GlobalTracer import java.util.concurrent.TimeUnit /** * The entry point to use Datadog's Trace feature. */ class DdTraceImplementation( - private val tracerProvider: () -> Tracer = { AndroidTracer.Builder().build() } + private val tracerProvider: () -> Tracer = { + val tracer = AndroidTracer.Builder().build() + GlobalTracer.registerIfAbsent(tracer) + + GlobalTracer.get() + } ) { private val spanMap: MutableMap = mutableMapOf() From b5bce9bc9ddc7f2d3053a384e884f87e92505a93 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Thu, 31 Aug 2023 15:42:13 +0200 Subject: [PATCH 02/12] Extract features enablement to Datadog Wrapper --- .../datadog/reactnative/DatadogSDKWrapper.kt | 18 +++++++++++ .../com/datadog/reactnative/DatadogWrapper.kt | 30 +++++++++++++++++++ .../reactnative/DdSdkImplementation.kt | 9 ++---- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt index 7918dcb52..d20a5d586 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt @@ -9,8 +9,14 @@ package com.datadog.reactnative import android.content.Context import com.datadog.android.Datadog import com.datadog.android.core.configuration.Configuration +import com.datadog.android.log.Logs +import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.GlobalRumMonitor +import com.datadog.android.rum.Rum +import com.datadog.android.rum.RumConfiguration +import com.datadog.android.trace.Trace +import com.datadog.android.trace.TraceConfiguration import com.datadog.android.webview.WebViewTracking internal class DatadogSDKWrapper : DatadogWrapper { @@ -27,6 +33,18 @@ internal class DatadogSDKWrapper : DatadogWrapper { Datadog.initialize(context, configuration, consent) } + override fun enableRum(configuration: RumConfiguration) { + Rum.enable(configuration) + } + + override fun enableLogs(configuration: LogsConfiguration) { + Logs.enable(configuration) + } + + override fun enableTrace(configuration: TraceConfiguration) { + Trace.enable(configuration) + } + override fun setUserInfo( id: String?, name: String?, diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt index c568082e7..a0fdcd847 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt @@ -8,8 +8,11 @@ package com.datadog.reactnative import android.content.Context import com.datadog.android.core.configuration.Configuration +import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent +import com.datadog.android.rum.RumConfiguration import com.datadog.android.rum.RumMonitor +import com.datadog.android.trace.TraceConfiguration import java.lang.IllegalArgumentException /** @@ -48,6 +51,33 @@ interface DatadogWrapper { consent: TrackingConsent ) + /** + * Enables the RUM feature of the SDK. + * + * @param configuration the configuration for the RUM feature + */ + fun enableRum( + configuration: RumConfiguration + ) + + /** + * Enables the Logs feature of the SDK. + * + * @param configuration the configuration for the Logs feature + */ + fun enableLogs( + configuration: LogsConfiguration + ) + + /** + * Enables the Trace feature of the SDK. + * + * @param configuration the configuration for the Trace feature + */ + fun enableTrace( + configuration: TraceConfiguration + ) + /** * Sets the user information. * diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index d3459c75d..88e42e75a 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -15,12 +15,10 @@ import com.datadog.android.core.configuration.BatchSize import com.datadog.android.core.configuration.Configuration import com.datadog.android.core.configuration.UploadFrequency import com.datadog.android.event.EventMapper -import com.datadog.android.log.Logs import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.configuration.VitalsUpdateFrequency import com.datadog.android.rum.GlobalRumMonitor -import com.datadog.android.rum.Rum import com.datadog.android.rum.RumConfiguration import com.datadog.android.rum.RumPerformanceMetric import com.datadog.android.rum._RumInternalProxy @@ -28,7 +26,6 @@ import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ResourceEvent import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy import com.datadog.android.telemetry.model.TelemetryConfigurationEvent -import com.datadog.android.trace.Trace import com.datadog.android.trace.TraceConfiguration import com.datadog.android.trace.TracingHeaderType import com.facebook.react.bridge.Promise @@ -66,12 +63,12 @@ class DdSdkImplementation( datadog.initialize(appContext, sdkConfiguration, trackingConsent) - Rum.enable(rumConfiguration) + datadog.enableRum(rumConfiguration) monitorJsRefreshRate(ddSdkConfiguration) - Trace.enable(TraceConfiguration.Builder().build()) + datadog.enableTrace(TraceConfiguration.Builder().build()) - Logs.enable(LogsConfiguration.Builder().build()) + datadog.enableLogs(LogsConfiguration.Builder().build()) initialized.set(true) From dde10922b57235dc91e3bc2a1bb826a412638299 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Thu, 31 Aug 2023 17:26:44 +0200 Subject: [PATCH 03/12] Fix NoOpViewTrackingStrategy after v2 --- .../kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt index 198827a61..929857f0a 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/NoOpViewTrackingStrategy.kt @@ -7,13 +7,14 @@ package com.datadog.reactnative import android.content.Context +import com.datadog.android.api.SdkCore import com.datadog.android.rum.tracking.ViewTrackingStrategy /** * No-op implementation of the [ViewTrackingStrategy]. */ object NoOpViewTrackingStrategy : ViewTrackingStrategy { - override fun register(context: Context) { + override fun register(sdkCore: SdkCore, context: Context) { // No-op } From c104c157105ae164270d43a8728a27e8ff74db7c Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Thu, 31 Aug 2023 17:33:17 +0200 Subject: [PATCH 04/12] Fix Kotlin upgrade errors --- .../kotlin/com/datadog/reactnative/DdRumImplementation.kt | 6 +++--- .../kotlin/com/datadog/reactnative/DdSdkImplementation.kt | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt index f5d3b58fa..0d5d2c00c 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt @@ -253,10 +253,10 @@ class DdRumImplementation { * Adds result of evaluating a feature flag to the view. * Feature flag evaluations are local to the active view and are cleared when the view is stopped. * @param name The name of the feature flag - * @param value The value the feature flag evaluated to, encapsulated in a Map + * @param valueAsMap The value the feature flag evaluated to, encapsulated in a Map */ - fun addFeatureFlagEvaluation(name: String, value: ReadableMap, promise: Promise) { - val value = value.toHashMap()["value"] + fun addFeatureFlagEvaluation(name: String, valueAsMap: ReadableMap, promise: Promise) { + val value = valueAsMap.toHashMap()["value"] if (value != null) { GlobalRumMonitor.get().addFeatureFlagEvaluation(name, value) } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index 88e42e75a..78840e58a 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -171,7 +171,8 @@ class DdSdkImplementation( return packageInfo?.let { // we need to use the deprecated method because getLongVersionCode method is only // available from API 28 and above - @Suppress("DEPRECATION") it.versionName ?: it.versionCode.toString() + @Suppress("DEPRECATION") + it.versionName ?: it.versionCode.toString() } ?: DEFAULT_APP_VERSION } @@ -341,6 +342,7 @@ class DdSdkImplementation( configBuilder.setProxy(proxy, authenticator) } + @Suppress("UNCHECKED_CAST") val firstPartyHosts = (configuration.additionalConfig?.get(DD_FIRST_PARTY_HOSTS) as? ReadableArray) ?.toArrayList() as? @@ -436,8 +438,7 @@ class DdSdkImplementation( } private fun buildUploadFrequency(uploadFrequency: String?): UploadFrequency { - val uploadFrequency = uploadFrequency?.lowercase(Locale.US) - return when (uploadFrequency) { + return when (uploadFrequency?.lowercase(Locale.US)) { "rare" -> UploadFrequency.RARE "average" -> UploadFrequency.AVERAGE "frequent" -> UploadFrequency.FREQUENT From ab6bc2c0ef29118c0efc54848bbe426a74d1751e Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Fri, 1 Sep 2023 13:47:33 +0200 Subject: [PATCH 05/12] Get RUM monitor from DD Wrapper --- .../datadog/reactnative/DatadogSDKWrapper.kt | 7 +++++- .../com/datadog/reactnative/DatadogWrapper.kt | 6 +++++ .../reactnative/DdRumImplementation.kt | 25 +++++++++---------- .../reactnative/DdSdkImplementation.kt | 5 ++-- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt index d20a5d586..f6870d890 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt @@ -15,6 +15,7 @@ import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.Rum import com.datadog.android.rum.RumConfiguration +import com.datadog.android.rum.RumMonitor import com.datadog.android.trace.Trace import com.datadog.android.trace.TraceConfiguration import com.datadog.android.webview.WebViewTracking @@ -56,7 +57,7 @@ internal class DatadogSDKWrapper : DatadogWrapper { override fun addRumGlobalAttributes(attributes: Map) { attributes.forEach { - GlobalRumMonitor.get().addAttribute(it.key, it.value) + this.getRumMonitor().addAttribute(it.key, it.value) } } @@ -87,4 +88,8 @@ internal class DatadogSDKWrapper : DatadogWrapper { override fun isInitialized(): Boolean { return Datadog.isInitialized() } + + override fun getRumMonitor(): RumMonitor { + return GlobalRumMonitor.get() + } } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt index a0fdcd847..94b9071c4 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt @@ -10,6 +10,7 @@ import android.content.Context import com.datadog.android.core.configuration.Configuration import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent +import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.RumConfiguration import com.datadog.android.rum.RumMonitor import com.datadog.android.trace.TraceConfiguration @@ -130,4 +131,9 @@ interface DatadogWrapper { * Returns whether the SDK is initialized. */ fun isInitialized(): Boolean + + /** + * Returns the RUM Monitor for the default SDK core. + */ + fun getRumMonitor(): RumMonitor } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt index 0d5d2c00c..3764248d0 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdRumImplementation.kt @@ -6,7 +6,6 @@ package com.datadog.reactnative -import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.RumActionType import com.datadog.android.rum.RumAttributes import com.datadog.android.rum.RumErrorSource @@ -19,7 +18,7 @@ import java.util.Locale * The entry point to use Datadog's RUM feature. */ @Suppress("TooManyFunctions") -class DdRumImplementation { +class DdRumImplementation(private val datadog: DatadogWrapper = DatadogSDKWrapper()) { /** * Start tracking a RUM View. * @param key The view unique key identifier. @@ -37,7 +36,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().startView( + datadog.getRumMonitor().startView( key = key, name = name, attributes = attributes @@ -55,7 +54,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().stopView( + datadog.getRumMonitor().stopView( key = key, attributes = attributes ) @@ -79,7 +78,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().startAction( + datadog.getRumMonitor().startAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -104,7 +103,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().stopAction( + datadog.getRumMonitor().stopAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -129,7 +128,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().addAction( + datadog.getRumMonitor().addAction( type = type.asRumActionType(), name = name, attributes = attributes @@ -157,7 +156,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().startResource( + datadog.getRumMonitor().startResource( key = key, method = method, url = url, @@ -193,7 +192,7 @@ class DdRumImplementation { } else { size.toLong() } - GlobalRumMonitor.get().stopResource( + datadog.getRumMonitor().stopResource( key = key, statusCode = statusCode.toInt(), kind = kind.asRumResourceKind(), @@ -223,7 +222,7 @@ class DdRumImplementation { val attributes = context.toHashMap().toMutableMap().apply { put(RumAttributes.INTERNAL_TIMESTAMP, timestampMs.toLong()) } - GlobalRumMonitor.get().addErrorWithStacktrace( + datadog.getRumMonitor().addErrorWithStacktrace( message = message, source = source.asErrorSource(), stacktrace = stacktrace, @@ -237,7 +236,7 @@ class DdRumImplementation { * @param name The name of the new custom timing attribute. Timings can be nested up to 8 levels deep. Names using more than 8 levels will be sanitized by SDK. */ fun addTiming(name: String, promise: Promise) { - GlobalRumMonitor.get().addTiming(name) + datadog.getRumMonitor().addTiming(name) promise.resolve(null) } @@ -245,7 +244,7 @@ class DdRumImplementation { * Stops the current RUM Session. */ fun stopSession(promise: Promise) { - GlobalRumMonitor.get().stopSession() + datadog.getRumMonitor().stopSession() promise.resolve(null) } @@ -258,7 +257,7 @@ class DdRumImplementation { fun addFeatureFlagEvaluation(name: String, valueAsMap: ReadableMap, promise: Promise) { val value = valueAsMap.toHashMap()["value"] if (value != null) { - GlobalRumMonitor.get().addFeatureFlagEvaluation(name, value) + datadog.getRumMonitor().addFeatureFlagEvaluation(name, value) } promise.resolve(null) } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index 78840e58a..e26d3c62a 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -18,7 +18,6 @@ import com.datadog.android.event.EventMapper import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.configuration.VitalsUpdateFrequency -import com.datadog.android.rum.GlobalRumMonitor import com.datadog.android.rum.RumConfiguration import com.datadog.android.rum.RumPerformanceMetric import com.datadog.android.rum._RumInternalProxy @@ -491,7 +490,7 @@ class DdSdkImplementation( return { if (jsRefreshRateMonitoringEnabled && it > 0.0) { - GlobalRumMonitor.get() + datadog.getRumMonitor() ._getInternal() ?.updatePerformanceMetric(RumPerformanceMetric.JS_FRAME_TIME, it) } @@ -501,7 +500,7 @@ class DdSdkImplementation( ddSdkConfiguration.longTaskThresholdMs?.toLong() ?: 0L ) ) { - GlobalRumMonitor.get()._getInternal()?.addLongTask(it.toLong(), "javascript") + datadog.getRumMonitor()._getInternal()?.addLongTask(it.toLong(), "javascript") } } } From a5298d6d41f61473756540c63e8123b0a47ed2df Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Fri, 1 Sep 2023 16:58:27 +0200 Subject: [PATCH 06/12] Make applicationId mandatory in android config --- .../main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt | 2 +- .../kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt | 4 ++-- .../kotlin/com/datadog/reactnative/DdSdkImplementation.kt | 3 ++- .../tools/unit/forge/DdSdkConfigurationForgeryFactory.kt | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt index a3f8f667b..87db41ad5 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt @@ -29,7 +29,7 @@ package com.datadog.reactnative data class DdSdkConfiguration( val clientToken: String, val env: String, - val applicationId: String? = null, + val applicationId: String, val nativeCrashReportEnabled: Boolean? = null, val nativeLongTaskThresholdMs: Double? = null, val longTaskThresholdMs: Double? = null, diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt index c2ed552bb..f1507f190 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt @@ -15,7 +15,7 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration { return DdSdkConfiguration( clientToken = getString("clientToken").orEmpty(), env = getString("env").orEmpty(), - applicationId = getString("applicationId"), + applicationId = getString("applicationId").orEmpty(), nativeCrashReportEnabled = getBoolean("nativeCrashReportEnabled"), nativeLongTaskThresholdMs = getDouble("nativeLongTaskThresholdMs"), longTaskThresholdMs = getDouble("longTaskThresholdMs"), @@ -63,7 +63,7 @@ internal fun DdSdkConfiguration.toReadableMap(): ReadableMap { val map = WritableNativeMap() map.putString("clientToken", clientToken) map.putString("env", env) - applicationId?.let { map.putString("applicationId", it) } + map.putString("applicationId", applicationId) nativeCrashReportEnabled?.let { map.putBoolean("nativeCrashReportEnabled", it) } nativeLongTaskThresholdMs?.let { map.putDouble("nativeLongTaskThresholdMs", it) } longTaskThresholdMs?.let { map.putDouble("longTaskThresholdMs", it) } diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index e26d3c62a..56d433dde 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -180,7 +180,7 @@ class DdSdkImplementation( private fun buildRUMConfiguration(configuration: DdSdkConfiguration): RumConfiguration { val configBuilder = RumConfiguration.Builder( - applicationId = configuration.applicationId!! + applicationId = configuration.applicationId ) if (configuration.sampleRate != null) { configBuilder.setSessionSampleRate(configuration.sampleRate.toFloat()) @@ -329,6 +329,7 @@ class DdSdkImplementation( ?: emptyMap() ) + configBuilder.setCrashReportsEnabled(configuration.nativeCrashReportEnabled ?: false) configBuilder.useSite(buildSite(configuration.site)) configBuilder.setUploadFrequency( buildUploadFrequency(configuration.uploadFrequency) diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt index adb0e2587..6ca158254 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt @@ -17,7 +17,7 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory { return DdSdkConfiguration( clientToken = forge.aStringMatching("pub[a-f0-9]{32}"), env = forge.anAlphabeticalString(), - applicationId = forge.aNullable { getForgery().toString() }, + applicationId = forge.getForgery().toString(), nativeCrashReportEnabled = forge.aNullable { aBool() }, nativeLongTaskThresholdMs = forge.aNullable { aDouble(100.0, 5000.0) }, longTaskThresholdMs = forge.aDouble(0.0, 100.0), From d25d24303f95fd4c13d2995fc2c01ec339534c06 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Thu, 31 Aug 2023 17:40:53 +0200 Subject: [PATCH 07/12] Fix tests after v2 upgrade --- .../com/datadog/reactnative/DdRumTest.kt | 34 +- .../com/datadog/reactnative/DdSdkTest.kt | 1256 +++++++++-------- .../tools/unit/DdSdkConfigurationExt.kt | 2 +- .../com/datadog/tools/unit/MockRumMonitor.kt | 49 + ...lemetryConfigurationEventForgeryFactory.kt | 1 + 5 files changed, 697 insertions(+), 645 deletions(-) create mode 100644 packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt index e1f12c5a5..a328cecbc 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt @@ -6,19 +6,15 @@ package com.datadog.reactnative -import com.datadog.android.rum.GlobalRum -import com.datadog.android.rum.RumActionType -import com.datadog.android.rum.RumAttributes -import com.datadog.android.rum.RumErrorSource -import com.datadog.android.rum.RumMonitor -import com.datadog.android.rum.RumResourceKind +import com.datadog.android.api.SdkCore +import com.datadog.android.rum.* import com.datadog.tools.unit.forge.BaseConfigurator -import com.datadog.tools.unit.getStaticValue import com.datadog.tools.unit.setStaticValue import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise -import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.verify +import com.nhaarman.mockitokotlin2.whenever import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.annotation.BoolForgery import fr.xgouchet.elmyr.annotation.DoubleForgery @@ -29,7 +25,6 @@ import fr.xgouchet.elmyr.annotation.StringForgeryType import fr.xgouchet.elmyr.junit5.ForgeConfiguration import fr.xgouchet.elmyr.junit5.ForgeExtension import java.util.Date -import java.util.concurrent.atomic.AtomicBoolean import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -55,6 +50,9 @@ internal class DdRumTest { @Mock lateinit var mockRumMonitor: RumMonitor + @Mock + lateinit var mockDatadog: DatadogWrapper + @Mock lateinit var mockPromise: Promise @@ -65,7 +63,7 @@ internal class DdRumTest { @BeforeEach fun `set up`(forge: Forge) { - GlobalRum.registerIfAbsent(mockRumMonitor) + whenever(mockDatadog.getRumMonitor()) doReturn mockRumMonitor fakeContext = forge.aMap { anAlphabeticalString() to aNullable { @@ -79,13 +77,11 @@ internal class DdRumTest { } } - testedDdRum = DdRumImplementation() + testedDdRum = DdRumImplementation(mockDatadog) } @AfterEach fun `tear down`() { - GlobalRum.javaClass.setStaticValue("monitor", mock()) - GlobalRum.javaClass.getStaticValue("isRegistered").set(false) } @Test @@ -138,7 +134,7 @@ internal class DdRumTest { ) // Then - verify(mockRumMonitor).addUserAction(type, name, updatedContext) + verify(mockRumMonitor).addAction(type, name, updatedContext) } @Test @@ -155,7 +151,7 @@ internal class DdRumTest { testedDdRum.addAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise) // Then - verify(mockRumMonitor).addUserAction(RumActionType.CUSTOM, name, updatedContext) + verify(mockRumMonitor).addAction(RumActionType.CUSTOM, name, updatedContext) } @Test @@ -175,7 +171,7 @@ internal class DdRumTest { ) // Then - verify(mockRumMonitor).startUserAction(type, name, updatedContext) + verify(mockRumMonitor).startAction(type, name, updatedContext) } @Test @@ -192,7 +188,7 @@ internal class DdRumTest { testedDdRum.startAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise) // Then - verify(mockRumMonitor).startUserAction(RumActionType.CUSTOM, name, updatedContext) + verify(mockRumMonitor).startAction(RumActionType.CUSTOM, name, updatedContext) } @Test @@ -212,7 +208,7 @@ internal class DdRumTest { ) // Then - verify(mockRumMonitor).stopUserAction(type, name, updatedContext) + verify(mockRumMonitor).stopAction(type, name, updatedContext) } @Test @@ -229,7 +225,7 @@ internal class DdRumTest { testedDdRum.stopAction(type, name, fakeContext.toReadableMap(), fakeTimestamp, mockPromise) // Then - verify(mockRumMonitor).stopUserAction(RumActionType.CUSTOM, name, updatedContext) + verify(mockRumMonitor).stopAction(RumActionType.CUSTOM, name, updatedContext) } @Test diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt index 6ec62d4f6..e83a8a77a 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt @@ -12,28 +12,21 @@ import android.view.Choreographer import com.datadog.android.DatadogSite import com.datadog.android.core.configuration.BatchSize import com.datadog.android.core.configuration.Configuration -import com.datadog.android.core.configuration.Credentials import com.datadog.android.core.configuration.UploadFrequency -import com.datadog.android.core.configuration.VitalsUpdateFrequency import com.datadog.android.event.EventMapper -import com.datadog.android.plugin.DatadogPlugin +import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent -import com.datadog.android.rum.GlobalRum -import com.datadog.android.rum.RumMonitor -import com.datadog.android.rum.RumPerformanceMetric -import com.datadog.android.rum._RumInternalProxy +import com.datadog.android.rum.* +import com.datadog.android.rum.configuration.VitalsUpdateFrequency import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ResourceEvent import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy import com.datadog.android.telemetry.model.TelemetryConfigurationEvent -import com.datadog.android.tracing.TracingHeaderType +import com.datadog.android.trace.TraceConfiguration +import com.datadog.android.trace.TracingHeaderType +import com.datadog.tools.unit.* import com.datadog.tools.unit.GenericAssert.Companion.assertThat import com.datadog.tools.unit.forge.BaseConfigurator -import com.datadog.tools.unit.getStaticValue -import com.datadog.tools.unit.setStaticValue -import com.datadog.tools.unit.toReadableArray -import com.datadog.tools.unit.toReadableJavaOnlyMap -import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableMap @@ -111,7 +104,7 @@ internal class DdSdkTest { lateinit var mockContext: ReactApplicationContext @Mock - lateinit var mockRumMonitor: RumMonitor + lateinit var mockRumMonitor: MockRumMonitor @Mock lateinit var mockRumInternalProxy: _RumInternalProxy @@ -133,7 +126,7 @@ internal class DdSdkTest { @BeforeEach fun `set up`() { - GlobalRum.registerIfAbsent(mockRumMonitor) + whenever(mockDatadog.getRumMonitor()) doReturn mockRumMonitor whenever(mockRumMonitor._getInternal()) doReturn mockRumInternalProxy doNothing().whenever(mockChoreographer).postFrameCallback(any()) @@ -156,8 +149,6 @@ internal class DdSdkTest { @AfterEach fun `tear down`() { GlobalState.globalAttributes.clear() - GlobalRum.javaClass.setStaticValue("monitor", mock()) - GlobalRum.javaClass.getStaticValue("isRegistered").set(false) } // region initialize / nativeCrashReportEnabled @@ -166,8 +157,10 @@ internal class DdSdkTest { fun `𝕄 initialize native SDK 𝕎 initialize() {nativeCrashReportEnabled=true}`() { // Given val bridgeConfiguration = fakeConfiguration.copy(nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -176,46 +169,38 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") + .hasFieldEqualTo("crashReportsEnabled", true) .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test fun `𝕄 initialize native SDK 𝕎 initialize() {nativeCrashReportEnabled=false}`() { // Given fakeConfiguration = fakeConfiguration.copy(nativeCrashReportEnabled = false, site = null) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -224,44 +209,38 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasFieldEqualTo("crashReportConfig", null) - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") + .hasFieldEqualTo("crashReportsEnabled", false) .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test fun `𝕄 initialize native SDK 𝕎 initialize() {nativeCrashReportEnabled=null}`() { // Given fakeConfiguration = fakeConfiguration.copy(nativeCrashReportEnabled = false, site = null) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -270,36 +249,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasFieldEqualTo("crashReportConfig", null) - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") + .hasFieldEqualTo("crashReportsEnabled", false) .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } // endregion @@ -309,8 +280,10 @@ internal class DdSdkTest { @Test fun `𝕄 initialize native with sample rate SDK 𝕎 initialize() {}`() { // Given - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() val expectedRumSampleRate = fakeConfiguration.sampleRate?.toFloat() ?: 100f // When @@ -320,36 +293,31 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - it.hasFieldEqualTo("samplingRate", expectedRumSampleRate) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("sampleRate", expectedRumSampleRate) + } + } // endregion @@ -359,8 +327,10 @@ internal class DdSdkTest { @Test fun `𝕄 initialize native with telemetry sample rate SDK 𝕎 initialize() {}`() { // Given - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() val expectedTelemetrySampleRate = fakeConfiguration.telemetrySampleRate?.toFloat() ?: 20f // When @@ -370,36 +340,30 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - it.hasFieldEqualTo("telemetrySamplingRate", expectedTelemetrySampleRate) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("telemetrySampleRate", expectedTelemetrySampleRate) + } } // endregion @@ -410,8 +374,10 @@ internal class DdSdkTest { fun `𝕄 initialize native SDK 𝕎 initialize() {additionalConfig=null}`() { // Given fakeConfiguration = fakeConfiguration.copy(additionalConfig = null) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -420,39 +386,33 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo("additionalConfig", emptyMap()) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test fun `𝕄 initialize native SDK 𝕎 initialize() {additionalConfig=nonNull}`() { // Given - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -461,35 +421,27 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) } - .hasField("logsConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } // endregion @@ -502,8 +454,10 @@ internal class DdSdkTest { ) { // Given fakeConfiguration = fakeConfiguration.copy(site = null, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -512,42 +466,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.US1) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -557,8 +497,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("us1") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -567,42 +509,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.US1) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -612,8 +540,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("us3") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -622,42 +552,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.US3) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US3.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US3.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US3.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US3.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -667,8 +583,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("us5") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -677,42 +595,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.US5) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US5.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US5.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US5.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US5.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -722,8 +626,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("us1_fed") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -732,42 +638,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.US1_FED) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1_FED.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1_FED.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1_FED.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.US1_FED.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -777,8 +669,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("eu1") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -787,42 +681,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.EU1) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.EU1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.EU1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.EU1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.EU1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } @Test @@ -832,8 +712,10 @@ internal class DdSdkTest { // Given val site = forge.randomizeCase("ap1") fakeConfiguration = fakeConfiguration.copy(site = site, nativeCrashReportEnabled = true) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -842,42 +724,28 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { it.hasFieldEqualTo("needsClearTextHttp", false) it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + it.hasFieldEqualTo("site", DatadogSite.AP1) } - .hasField("logsConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.AP1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("tracesConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.AP1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("rumConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.AP1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } - .hasField("crashReportConfig") { - it.hasFieldEqualTo("endpointUrl", DatadogSite.AP1.intakeEndpoint) - it.hasFieldEqualTo("plugins", emptyList()) - } + .hasFieldEqualTo("clientToken", fakeConfiguration.clientToken) + .hasFieldEqualTo("env", fakeConfiguration.env) + .hasFieldEqualTo("variant", "") .hasFieldEqualTo( "additionalConfig", fakeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() ) - val credentials = credentialCaptor.firstValue - assertThat(credentials.clientToken).isEqualTo(fakeConfiguration.clientToken) - assertThat(credentials.envName).isEqualTo(fakeConfiguration.env) - assertThat(credentials.rumApplicationId).isEqualTo(fakeConfiguration.applicationId) - assertThat(credentials.variant).isEqualTo("") + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", fakeConfiguration.applicationId) } // endregion @@ -888,8 +756,10 @@ internal class DdSdkTest { fun `𝕄 initialize native SDK 𝕎 initialize() {trackingConsent=null}`() { // Given fakeConfiguration = fakeConfiguration.copy(trackingConsent = null) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -898,11 +768,12 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), eq(TrackingConsent.PENDING) ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } } @@ -913,8 +784,10 @@ internal class DdSdkTest { // Given val consent = forge.randomizeCase("PENDING") fakeConfiguration = fakeConfiguration.copy(trackingConsent = consent) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -923,11 +796,12 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), eq(TrackingConsent.PENDING) ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } } @@ -938,8 +812,10 @@ internal class DdSdkTest { // Given val consent = forge.randomizeCase("GRANTED") fakeConfiguration = fakeConfiguration.copy(trackingConsent = consent) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -948,11 +824,12 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), eq(TrackingConsent.GRANTED) ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } } @@ -963,8 +840,10 @@ internal class DdSdkTest { // Given val consent = forge.randomizeCase("NOT_GRANTED") fakeConfiguration = fakeConfiguration.copy(trackingConsent = consent) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -973,11 +852,12 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), + sdkConfigCaptor.capture(), eq(TrackingConsent.NOT_GRANTED) ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } } @@ -989,8 +869,10 @@ internal class DdSdkTest { ) { // Given val bridgeConfiguration = configuration.copy(additionalConfig = null) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -999,14 +881,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("viewTrackingStrategy", NoOpViewTrackingStrategy) } } @@ -1021,8 +904,10 @@ internal class DdSdkTest { DdSdkImplementation.DD_NATIVE_VIEW_TRACKING to false ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1031,14 +916,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("viewTrackingStrategy", NoOpViewTrackingStrategy) } } @@ -1053,8 +939,10 @@ internal class DdSdkTest { DdSdkImplementation.DD_NATIVE_VIEW_TRACKING to true ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1063,14 +951,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("viewTrackingStrategy", ActivityViewTrackingStrategy(false)) } } @@ -1085,8 +974,10 @@ internal class DdSdkTest { DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to false ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1095,18 +986,16 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { - it.hasFieldWithClass( - "userActionTrackingStrategy", - "com.datadog.android.rum.internal.tracking.NoOpUserActionTrackingStrategy" - ) + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("viewTrackingStrategy", NoOpViewTrackingStrategy) } } @@ -1118,8 +1007,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( trackFrustrations = true ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1128,18 +1019,16 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { - it.hasFieldEqualTo( - "trackFrustrations", - true - ) + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("trackFrustrations", true) } } @@ -1151,8 +1040,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( trackFrustrations = false ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1161,18 +1052,16 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { - it.hasFieldEqualTo( - "trackFrustrations", - false - ) + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("trackFrustrations", false) } } @@ -1186,8 +1075,10 @@ internal class DdSdkTest { DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to true ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1196,19 +1087,16 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - verify(mockDatadog).registerRumMonitor(any()) - } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { - it.hasFieldWithClass( - "userActionTrackingStrategy", - "com.datadog.android.rum.internal" + - ".instrumentation.UserActionTrackingStrategyLegacy" - ) + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("userActionTracking", true) } } @@ -1222,8 +1110,10 @@ internal class DdSdkTest { DdSdkImplementation.DD_NATIVE_INTERACTION_TRACKING to null ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1232,19 +1122,16 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - verify(mockDatadog).registerRumMonitor(any()) - } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { - it.hasFieldWithClass( - "userActionTrackingStrategy", - "com.datadog.android.rum.internal" + - ".instrumentation.UserActionTrackingStrategyLegacy" - ) + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { + it.hasFieldEqualTo("userActionTracking", true) } } @Test @@ -1303,20 +1190,40 @@ internal class DdSdkTest { DdSdkImplementation.DD_SERVICE_NAME to serviceName ) ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(credentialCaptor.firstValue.serviceName).isEqualTo(serviceName) + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(sdkConfigCaptor.firstValue) + .hasField("coreConfig") { + it.hasFieldEqualTo("needsClearTextHttp", false) + it.hasFieldEqualTo("firstPartyHostsWithHeaderTypes", emptyMap()) + } + .hasFieldEqualTo("clientToken", bridgeConfiguration.clientToken) + .hasFieldEqualTo("env", bridgeConfiguration.env) + .hasFieldEqualTo("variant", "") + .hasFieldEqualTo("service", serviceName) + .hasFieldEqualTo( + "additionalConfig", + bridgeConfiguration.additionalConfig?.filterValues { it != null }.orEmpty() + ) + assertThat(rumConfigCaptor.firstValue) + .hasFieldEqualTo("applicationId", bridgeConfiguration.applicationId) } @Test @@ -1330,26 +1237,32 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( nativeLongTaskThresholdMs = threshold ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { rumConfig -> + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { rumConfig -> rumConfig.hasField("longTaskTrackingStrategy") { longTaskTrackingStrategy -> longTaskTrackingStrategy .isInstanceOf( "com.datadog.android.rum.internal.instrumentation." + - "MainLooperLongTaskStrategy" + "MainLooperLongTaskStrategy" ) .hasFieldEqualTo("thresholdMs", threshold.toLong()) } @@ -1365,21 +1278,27 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( nativeLongTaskThresholdMs = 0.0 ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { rumConfig -> + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { rumConfig -> rumConfig.doesNotHaveField("longTaskTrackingStrategy") } } @@ -1422,19 +1341,26 @@ internal class DdSdkTest { DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray() ) ) - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { coreConfig -> coreConfig.hasFieldEqualTo( "firstPartyHostsWithHeaderTypes", @@ -1476,19 +1402,26 @@ internal class DdSdkTest { DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray() ) ) - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { coreConfig -> coreConfig.hasFieldEqualTo( "firstPartyHostsWithHeaderTypes", @@ -1537,19 +1470,26 @@ internal class DdSdkTest { DdSdkImplementation.DD_FIRST_PARTY_HOSTS to firstPartyHosts.toReadableArray() ) ) - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(sdkConfigCaptor.firstValue) .hasField("coreConfig") { coreConfig -> coreConfig.hasFieldEqualTo( "firstPartyHostsWithHeaderTypes", @@ -1569,8 +1509,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( uploadFrequency = input, ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1579,15 +1521,19 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("coreConfig") { - it.hasFieldEqualTo("uploadFrequency", expectedUploadFrequency) + assertThat(sdkConfigCaptor.firstValue) + .hasField("coreConfig") { coreConfig -> + coreConfig.hasFieldEqualTo( + "uploadFrequency", + expectedUploadFrequency + ) } } @@ -1602,8 +1548,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( batchSize = input, ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1612,15 +1560,19 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("coreConfig") { - it.hasFieldEqualTo("batchSize", expectedBatchSize) + assertThat(sdkConfigCaptor.firstValue) + .hasField("coreConfig") { coreConfig -> + coreConfig.hasFieldEqualTo( + "batchSize", + expectedBatchSize + ) } } @@ -1634,8 +1586,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( trackBackgroundEvents = trackBackgroundEvents, ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1644,14 +1598,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("backgroundEventTracking", trackBackgroundEvents ?: false) } } @@ -1664,8 +1619,10 @@ internal class DdSdkTest { val bridgeConfiguration = configuration.copy( vitalsUpdateFrequency = "RARE" ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1674,14 +1631,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.RARE) } argumentCaptor { @@ -1700,8 +1658,10 @@ internal class DdSdkTest { vitalsUpdateFrequency = "NEVER", longTaskThresholdMs = 0.0 ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) @@ -1710,14 +1670,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.NEVER) } verifyZeroInteractions(mockChoreographer) @@ -1736,8 +1697,10 @@ internal class DdSdkTest { vitalsUpdateFrequency = fakeFrequency, longTaskThresholdMs = 0.0 ) - val credentialCaptor = argumentCaptor() - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() val frameDurationNs = threshold + frameDurationOverThreshold // When @@ -1747,14 +1710,15 @@ internal class DdSdkTest { inOrder(mockDatadog) { verify(mockDatadog).initialize( same(mockContext), - credentialCaptor.capture(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) + sdkConfigCaptor.capture(), + any() ) - verify(mockDatadog).registerRumMonitor(any()) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { it.hasFieldEqualTo("vitalsMonitorUpdateFrequency", VitalsUpdateFrequency.AVERAGE) } argumentCaptor { @@ -1866,19 +1830,26 @@ internal class DdSdkTest { DdSdkImplementation.DD_VERSION_SUFFIX to versionSuffix ) ) - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(sdkConfigCaptor.firstValue) .hasFieldEqualTo( "additionalConfig", mapOf( @@ -1919,22 +1890,29 @@ internal class DdSdkTest { reactNativeVersion = reactNativeVersion ) ) - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(bridgeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - eq(configuration.trackingConsent.asTrackingConsent()) - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { val configurationMapper = it - .getActualValue>("rumEventMapper") + .getActualValue>("telemetryConfigurationMapper") val result = configurationMapper.map(telemetryConfigurationEvent)!! assertThat(result.telemetry.configuration.trackNativeErrors!!).isEqualTo( trackNativeErrors @@ -1967,22 +1945,29 @@ internal class DdSdkTest { @Forgery resourceEvent: ResourceEvent, ) { // Given - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - any() - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { val resourceMapper = it - .getActualValue>("rumEventMapper") + .getActualValue>("resourceEventMapper") val notDroppedEvent = resourceMapper.map(resourceEvent) assertThat(notDroppedEvent).isNotNull } @@ -1993,23 +1978,30 @@ internal class DdSdkTest { @Forgery resourceEvent: ResourceEvent, ) { // Given - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() resourceEvent.context?.additionalProperties?.put("_dd.resource.drop_resource", true) // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - any() - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { val resourceMapper = it - .getActualValue>("rumEventMapper") + .getActualValue>("resourceEventMapper") val droppedEvent = resourceMapper.map(resourceEvent) assertThat(droppedEvent).isNull() } @@ -2024,22 +2016,29 @@ internal class DdSdkTest { @Forgery actionEvent: ActionEvent, ) { // Given - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - any() - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { val actionMapper = it - .getActualValue>("rumEventMapper") + .getActualValue>("actionEventMapper") val notDroppedEvent = actionMapper.map(actionEvent) assertThat(notDroppedEvent).isNotNull } @@ -2050,23 +2049,30 @@ internal class DdSdkTest { @Forgery actionEvent: ActionEvent, ) { // Given - val configCaptor = argumentCaptor() + val sdkConfigCaptor = argumentCaptor() + val rumConfigCaptor = argumentCaptor() + val logsConfigCaptor = argumentCaptor() + val traceConfigCaptor = argumentCaptor() actionEvent.context?.additionalProperties?.put("_dd.action.drop_action", true) // When testedBridgeSdk.initialize(fakeConfiguration.toReadableJavaOnlyMap(), mockPromise) // Then - verify(mockDatadog).initialize( - same(mockContext), - any(), - configCaptor.capture(), - any() - ) - assertThat(configCaptor.firstValue) - .hasField("rumConfig") { + inOrder(mockDatadog) { + verify(mockDatadog).initialize( + same(mockContext), + sdkConfigCaptor.capture(), + any() + ) + verify(mockDatadog).enableRum(rumConfigCaptor.capture()) + verify(mockDatadog).enableTrace(traceConfigCaptor.capture()) + verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) + } + assertThat(rumConfigCaptor.firstValue) + .hasField("featureConfiguration") { val actionMapper = it - .getActualValue>("rumEventMapper") + .getActualValue>("actionEventMapper") val droppedEvent = actionMapper.map(actionEvent) assertThat(droppedEvent).isNull() } diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt index 6e4e61b7e..ec19003cc 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt @@ -8,7 +8,7 @@ package com.datadog.tools.unit import com.datadog.android.core.configuration.BatchSize import com.datadog.android.core.configuration.UploadFrequency -import com.datadog.android.core.configuration.VitalsUpdateFrequency +import com.datadog.android.rum.configuration.VitalsUpdateFrequency import com.datadog.reactnative.ConfigurationForTelemetry import com.datadog.reactnative.DdSdkConfiguration import com.facebook.react.bridge.ReadableMap diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt new file mode 100644 index 000000000..46d39b825 --- /dev/null +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt @@ -0,0 +1,49 @@ +package com.datadog.tools.unit + +import com.datadog.android.rum.RumMonitor + +class MockRumMonitor: RumMonitor { + override var debug = false + + override fun _getInternal(): com.datadog.android.rum._RumInternalProxy? { + return null + } + + override fun addAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun addAttribute(key: kotlin.String, value: kotlin.Any?): kotlin.Unit {} + + override fun addError(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable?, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun addErrorWithStacktrace(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stacktrace: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun addFeatureFlagEvaluation(name: kotlin.String, value: kotlin.Any): kotlin.Unit {} + + override fun addTiming(name: kotlin.String): kotlin.Unit {} + + override fun clearAttributes(): kotlin.Unit {} + + override fun getAttributes(): kotlin.collections.Map { + return mapOf() + } + + override fun removeAttribute(key: kotlin.String): kotlin.Unit {} + + override fun startAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun startResource(key: kotlin.String, method: kotlin.String, url: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun startView(key: kotlin.Any, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun stopAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun stopResource(key: kotlin.String, statusCode: kotlin.Int?, size: kotlin.Long?, kind: com.datadog.android.rum.RumResourceKind, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stackTrace: kotlin.String, errorType: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable, attributes: kotlin.collections.Map): kotlin.Unit {} + + override fun stopSession(): kotlin.Unit {} + + override fun stopView(key: kotlin.Any, attributes: kotlin.collections.Map): kotlin.Unit {} +} \ No newline at end of file diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt index 7f56c3219..98a550338 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/TelemetryConfigurationEventForgeryFactory.kt @@ -59,6 +59,7 @@ internal class TelemetryConfigurationEventForgeryFactory : forge.aNullable { aBool() }, forge.aNullable { aBool() }, forge.aNullable { aBool() }, + forge.aNullable { aBool() }, forge.aNullable { aString() }, forge.aNullable { aBool() }, forge.aNullable { aBool() }, From 798ae72beac27cf4e9a90f7f2e35d13dd4aac6e3 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Mon, 4 Sep 2023 10:38:00 +0200 Subject: [PATCH 08/12] Do not recreate proxies at every call --- .../datadog/reactnative/DatadogSDKWrapper.kt | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt index f6870d890..32cebbfe3 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt @@ -22,6 +22,16 @@ import com.datadog.android.webview.WebViewTracking internal class DatadogSDKWrapper : DatadogWrapper { + // lazy here is on purpose. The thing is that this class will be instantiated even before + // Sdk.initialize is called, but telemetry proxy can be created only after SDK is initialized. + private val telemetryProxy by lazy { Datadog._internalProxy() } + + // lazy here is on purpose. The thing is that this class will be instantiated even before + // Sdk.initialize is called, but webview proxy can be created only after SDK is initialized. + private val webViewProxy by lazy { + WebViewTracking._InternalWebViewProxy(Datadog.getInstance()) + } + override fun setVerbosity(level: Int) { Datadog.setVerbosity(level) } @@ -66,23 +76,31 @@ internal class DatadogSDKWrapper : DatadogWrapper { } override fun telemetryDebug(message: String) { - // TODO: store instance of proxy to avoid creating one every time - Datadog._internalProxy()._telemetry.debug(message) + // Do not initialize the telemetry proxy before SDK is initialized + if (isInitialized()) { + telemetryProxy._telemetry.debug(message) + } } override fun telemetryError(message: String, stack: String?, kind: String?) { - // TODO: store instance of proxy to avoid creating one every time - Datadog._internalProxy()._telemetry.error(message, stack, kind) + // Do not initialize the telemetry proxy before SDK is initialized + if (isInitialized()) { + telemetryProxy._telemetry.error(message, stack, kind) + } } override fun telemetryError(message: String, throwable: Throwable?) { - // TODO: store instance of proxy to avoid creating one every time - Datadog._internalProxy()._telemetry.error(message, throwable) + // Do not initialize the telemetry proxy before SDK is initialized + if (isInitialized()) { + telemetryProxy._telemetry.error(message, throwable) + } } override fun consumeWebviewEvent(message: String) { - // TODO: store instance of proxy to avoid creating one every time - WebViewTracking._InternalWebViewProxy(Datadog.getInstance()).consumeWebviewEvent(message) + // Do not initialize the webview proxy before SDK is initialized + if (isInitialized()) { + webViewProxy.consumeWebviewEvent(message) + } } override fun isInitialized(): Boolean { From e36026fb189fc42bae1d7b5e93e68c13a930199e Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Mon, 4 Sep 2023 10:52:54 +0200 Subject: [PATCH 09/12] Update ktlint --- packages/core/android/build.gradle | 3 +- .../kotlin/com/datadog/reactnative/DdTrace.kt | 2 +- .../com/datadog/reactnative/DdRumTest.kt | 55 +++++++---- .../com/datadog/reactnative/DdSdkTest.kt | 61 ++++++------ .../com/datadog/tools/unit/MockRumMonitor.kt | 93 +++++++++++++++---- .../com/datadog/tools/unit/ReflectUtils.kt | 1 - .../unit/forge/ActionEventForgeryFactory.kt | 2 +- .../forge/DdSdkConfigurationForgeryFactory.kt | 4 +- .../unit/forge/ResourceEventForgeryFactory.kt | 2 +- 9 files changed, 149 insertions(+), 74 deletions(-) diff --git a/packages/core/android/build.gradle b/packages/core/android/build.gradle index f2aff0433..10b8a18e7 100644 --- a/packages/core/android/build.gradle +++ b/packages/core/android/build.gradle @@ -12,7 +12,7 @@ buildscript { classpath 'com.android.tools.build:gradle:7.2.2' // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1" + classpath "org.jlleitschuh.gradle:ktlint-gradle:11.5.1" classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.18.0" classpath 'com.github.bjoernq:unmockplugin:0.7.9' } @@ -207,7 +207,6 @@ ktlint { outputToConsole.set(true) ignoreFailures.set(false) enableExperimentalRules.set(false) - additionalEditorconfigFile.set(file("${project.rootDir}/script/config/.editorconfig")) filter { exclude("**/generated/**") include("**/kotlin/**") diff --git a/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt b/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt index 42687a692..7c26f4b75 100644 --- a/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt +++ b/packages/core/android/src/oldarch/kotlin/com/datadog/reactnative/DdTrace.kt @@ -16,7 +16,7 @@ import com.facebook.react.bridge.ReadableMap * The entry point to use Datadog's Trace feature. */ class DdTrace( - reactContext: ReactApplicationContext, + reactContext: ReactApplicationContext ) : ReactContextBaseJavaModule(reactContext) { private val implementation = DdTraceImplementation() diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt index a328cecbc..b9c3797d2 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt @@ -6,10 +6,12 @@ package com.datadog.reactnative -import com.datadog.android.api.SdkCore -import com.datadog.android.rum.* +import com.datadog.android.rum.RumActionType +import com.datadog.android.rum.RumAttributes +import com.datadog.android.rum.RumErrorSource +import com.datadog.android.rum.RumMonitor +import com.datadog.android.rum.RumResourceKind import com.datadog.tools.unit.forge.BaseConfigurator -import com.datadog.tools.unit.setStaticValue import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise import com.nhaarman.mockitokotlin2.doReturn @@ -129,8 +131,11 @@ internal class DdRumTest { // When testedDdRum.addAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -166,8 +171,11 @@ internal class DdRumTest { // When testedDdRum.startAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -203,8 +211,11 @@ internal class DdRumTest { // When testedDdRum.stopAction( - type.name, name, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + type.name, + name, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -241,8 +252,12 @@ internal class DdRumTest { // When testedDdRum.startResource( - key, method, url, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + key, + method, + url, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -360,8 +375,12 @@ internal class DdRumTest { // When testedDdRum.addError( - message, source.name, stackTrace, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + message, + source.name, + stackTrace, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -381,8 +400,12 @@ internal class DdRumTest { // When testedDdRum.addError( - message, source, stackTrace, fakeContext.toReadableMap(), - fakeTimestamp, mockPromise + message, + source, + stackTrace, + fakeContext.toReadableMap(), + fakeTimestamp, + mockPromise ) // Then @@ -396,7 +419,6 @@ internal class DdRumTest { @Test fun `M call addTiming W addTiming()`(@StringForgery timing: String) { - // When testedDdRum.addTiming(timing, mockPromise) @@ -406,7 +428,6 @@ internal class DdRumTest { @Test fun `M call stopSession W stopSession()`() { - // When testedDdRum.stopSession(mockPromise) diff --git a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt index e83a8a77a..2d2654384 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt @@ -16,7 +16,9 @@ import com.datadog.android.core.configuration.UploadFrequency import com.datadog.android.event.EventMapper import com.datadog.android.log.LogsConfiguration import com.datadog.android.privacy.TrackingConsent -import com.datadog.android.rum.* +import com.datadog.android.rum.RumConfiguration +import com.datadog.android.rum.RumPerformanceMetric +import com.datadog.android.rum._RumInternalProxy import com.datadog.android.rum.configuration.VitalsUpdateFrequency import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ResourceEvent @@ -24,9 +26,13 @@ import com.datadog.android.rum.tracking.ActivityViewTrackingStrategy import com.datadog.android.telemetry.model.TelemetryConfigurationEvent import com.datadog.android.trace.TraceConfiguration import com.datadog.android.trace.TracingHeaderType -import com.datadog.tools.unit.* import com.datadog.tools.unit.GenericAssert.Companion.assertThat +import com.datadog.tools.unit.MockRumMonitor import com.datadog.tools.unit.forge.BaseConfigurator +import com.datadog.tools.unit.setStaticValue +import com.datadog.tools.unit.toReadableArray +import com.datadog.tools.unit.toReadableJavaOnlyMap +import com.datadog.tools.unit.toReadableMap import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReadableMap @@ -58,7 +64,6 @@ import fr.xgouchet.elmyr.junit5.ForgeExtension import java.net.InetSocketAddress import java.net.Proxy import java.util.Locale -import java.util.concurrent.atomic.AtomicBoolean import java.util.stream.Stream import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.AfterEach @@ -317,7 +322,6 @@ internal class DdSdkTest { .hasField("featureConfiguration") { it.hasFieldEqualTo("sampleRate", expectedRumSampleRate) } - } // endregion @@ -1134,6 +1138,7 @@ internal class DdSdkTest { it.hasFieldEqualTo("userActionTracking", true) } } + @Test fun `𝕄 initialize native SDK 𝕎 initialize() {sdk verbosity}`( @Forgery configuration: DdSdkConfiguration, @@ -1257,12 +1262,12 @@ internal class DdSdkTest { verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } assertThat(rumConfigCaptor.firstValue) - .hasField("featureConfiguration") { rumConfig -> + .hasField("featureConfiguration") { rumConfig -> rumConfig.hasField("longTaskTrackingStrategy") { longTaskTrackingStrategy -> longTaskTrackingStrategy .isInstanceOf( "com.datadog.android.rum.internal.instrumentation." + - "MainLooperLongTaskStrategy" + "MainLooperLongTaskStrategy" ) .hasFieldEqualTo("thresholdMs", threshold.toLong()) } @@ -1298,7 +1303,7 @@ internal class DdSdkTest { verify(mockDatadog).enableLogs(logsConfigCaptor.capture()) } assertThat(rumConfigCaptor.firstValue) - .hasField("featureConfiguration") { rumConfig -> + .hasField("featureConfiguration") { rumConfig -> rumConfig.doesNotHaveField("longTaskTrackingStrategy") } } @@ -1378,7 +1383,7 @@ internal class DdSdkTest { Pair( forge.aStringMatching("[a-z]+\\.[a-z]{3}"), setOf( - TracingHeaderType.DATADOG, + TracingHeaderType.DATADOG ) ) } @@ -1441,9 +1446,9 @@ internal class DdSdkTest { host, setOf( TracingHeaderType.DATADOG, - TracingHeaderType.B3, + TracingHeaderType.B3 ) - ), + ) ) val firstPartyHosts = mutableListOf() @@ -1451,7 +1456,7 @@ internal class DdSdkTest { mapOf( "match" to host, "propagatorTypes" to listOf( - TracingHeaderType.DATADOG.name.lowercase(), + TracingHeaderType.DATADOG.name.lowercase() ).toReadableArray() ).toReadableMap() ) @@ -1459,7 +1464,7 @@ internal class DdSdkTest { mapOf( "match" to host, "propagatorTypes" to listOf( - TracingHeaderType.B3.name.lowercase(), + TracingHeaderType.B3.name.lowercase() ).toReadableArray() ).toReadableMap() ) @@ -1507,7 +1512,7 @@ internal class DdSdkTest { ) { // Given val bridgeConfiguration = configuration.copy( - uploadFrequency = input, + uploadFrequency = input ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1546,7 +1551,7 @@ internal class DdSdkTest { ) { // Given val bridgeConfiguration = configuration.copy( - batchSize = input, + batchSize = input ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1584,7 +1589,7 @@ internal class DdSdkTest { // Given val trackBackgroundEvents = forge.aNullable { forge.aBool() } val bridgeConfiguration = configuration.copy( - trackBackgroundEvents = trackBackgroundEvents, + trackBackgroundEvents = trackBackgroundEvents ) val sdkConfigCaptor = argumentCaptor() val rumConfigCaptor = argumentCaptor() @@ -1751,7 +1756,7 @@ internal class DdSdkTest { // Given val bridgeConfiguration = configuration.copy( vitalsUpdateFrequency = "AVERAGE", - longTaskThresholdMs = (threshold / 1_000_000).toDouble(), + longTaskThresholdMs = (threshold / 1_000_000).toDouble() ) val frameDurationNs = threshold + frameDurationOverThreshold @@ -1788,7 +1793,7 @@ internal class DdSdkTest { // Given val bridgeConfiguration = configuration.copy( vitalsUpdateFrequency = "NEVER", - longTaskThresholdMs = (threshold / 1_000_000).toDouble(), + longTaskThresholdMs = (threshold / 1_000_000).toDouble() ) val frameDurationNs = threshold + frameDurationOverThreshold @@ -1912,7 +1917,9 @@ internal class DdSdkTest { assertThat(rumConfigCaptor.firstValue) .hasField("featureConfiguration") { val configurationMapper = it - .getActualValue>("telemetryConfigurationMapper") + .getActualValue>( + "telemetryConfigurationMapper" + ) val result = configurationMapper.map(telemetryConfigurationEvent)!! assertThat(result.telemetry.configuration.trackNativeErrors!!).isEqualTo( trackNativeErrors @@ -1942,7 +1949,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a resource mapper that does not drop resources 𝕎 initialize() {}`( - @Forgery resourceEvent: ResourceEvent, + @Forgery resourceEvent: ResourceEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -1975,7 +1982,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a resource mapper that drops flagged resources 𝕎 initialize() {}`( - @Forgery resourceEvent: ResourceEvent, + @Forgery resourceEvent: ResourceEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2013,7 +2020,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a action mapper that does not drop actions 𝕎 initialize() {}`( - @Forgery actionEvent: ActionEvent, + @Forgery actionEvent: ActionEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2046,7 +2053,7 @@ internal class DdSdkTest { @Test fun `𝕄 set a action mapper that drops flagged actions 𝕎 initialize() {}`( - @Forgery actionEvent: ActionEvent, + @Forgery actionEvent: ActionEvent ) { // Given val sdkConfigCaptor = argumentCaptor() @@ -2272,7 +2279,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Granted consent 𝕎 buildTrackingConsent {granted}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("granted", "GRANTED") @@ -2284,7 +2290,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Pending consent 𝕎 buildTrackingConsent {pending}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("pending", "PENDING") @@ -2296,7 +2301,6 @@ internal class DdSdkTest { @Test fun `𝕄 build Granted consent 𝕎 buildTrackingConsent {not_granted}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom("not_granted", "NOT_GRANTED") @@ -2308,7 +2312,6 @@ internal class DdSdkTest { @Test fun `𝕄 build default Pending consent 𝕎 buildTrackingConsent {any}`(forge: Forge) { - // When val consent = testedBridgeSdk.buildTrackingConsent( forge.anElementFrom(null, "some-type") @@ -2320,7 +2323,6 @@ internal class DdSdkTest { @Test fun `𝕄 call setTrackingConsent 𝕎 setTrackingConsent ()`(forge: Forge) { - // Given val consent = forge.anElementFrom("pending", "granted", "not_granted") @@ -2335,7 +2337,6 @@ internal class DdSdkTest { fun `𝕄 not build proxy config 𝕎 no proxy config specified`( @Forgery configuration: DdSdkConfiguration ) { - // Given val config = configuration.copy(additionalConfig = null) @@ -2526,7 +2527,7 @@ internal class DdSdkTest { return Stream.of( Arguments.of("SMALL", BatchSize.SMALL), Arguments.of("MEDIUM", BatchSize.MEDIUM), - Arguments.of("LARGE", BatchSize.LARGE), + Arguments.of("LARGE", BatchSize.LARGE) ) } @@ -2535,7 +2536,7 @@ internal class DdSdkTest { return Stream.of( Arguments.of("RARE", UploadFrequency.RARE), Arguments.of("AVERAGE", UploadFrequency.AVERAGE), - Arguments.of("FREQUENT", UploadFrequency.FREQUENT), + Arguments.of("FREQUENT", UploadFrequency.FREQUENT) ) } } diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt index 46d39b825..2ae8cfd50 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt @@ -2,20 +2,34 @@ package com.datadog.tools.unit import com.datadog.android.rum.RumMonitor -class MockRumMonitor: RumMonitor { +class MockRumMonitor : RumMonitor { override var debug = false override fun _getInternal(): com.datadog.android.rum._RumInternalProxy? { return null } - override fun addAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun addAttribute(key: kotlin.String, value: kotlin.Any?): kotlin.Unit {} - override fun addError(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable?, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addError( + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + throwable: kotlin.Throwable?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} - override fun addErrorWithStacktrace(message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stacktrace: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun addErrorWithStacktrace( + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + stacktrace: kotlin.String?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun addFeatureFlagEvaluation(name: kotlin.String, value: kotlin.Any): kotlin.Unit {} @@ -29,21 +43,62 @@ class MockRumMonitor: RumMonitor { override fun removeAttribute(key: kotlin.String): kotlin.Unit {} - override fun startAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun startResource(key: kotlin.String, method: kotlin.String, url: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun startView(key: kotlin.Any, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopAction(type: com.datadog.android.rum.RumActionType, name: kotlin.String, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResource(key: kotlin.String, statusCode: kotlin.Int?, size: kotlin.Long?, kind: com.datadog.android.rum.RumResourceKind, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, stackTrace: kotlin.String, errorType: kotlin.String?, attributes: kotlin.collections.Map): kotlin.Unit {} - - override fun stopResourceWithError(key: kotlin.String, statusCode: kotlin.Int?, message: kotlin.String, source: com.datadog.android.rum.RumErrorSource, throwable: kotlin.Throwable, attributes: kotlin.collections.Map): kotlin.Unit {} + override fun startAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun startResource( + key: kotlin.String, + method: kotlin.String, + url: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun startView( + key: kotlin.Any, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopAction( + type: com.datadog.android.rum.RumActionType, + name: kotlin.String, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResource( + key: kotlin.String, + statusCode: kotlin.Int?, + size: kotlin.Long?, + kind: com.datadog.android.rum.RumResourceKind, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResourceWithError( + key: kotlin.String, + statusCode: kotlin.Int?, + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + stackTrace: kotlin.String, + errorType: kotlin.String?, + attributes: kotlin.collections.Map + ): kotlin.Unit {} + + override fun stopResourceWithError( + key: kotlin.String, + statusCode: kotlin.Int?, + message: kotlin.String, + source: com.datadog.android.rum.RumErrorSource, + throwable: kotlin.Throwable, + attributes: kotlin.collections.Map + ): kotlin.Unit {} override fun stopSession(): kotlin.Unit {} - override fun stopView(key: kotlin.Any, attributes: kotlin.collections.Map): kotlin.Unit {} -} \ No newline at end of file + override fun stopView( + key: kotlin.Any, + attributes: kotlin.collections.Map + ): kotlin.Unit {} +} diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt index 291c840f8..49beb4465 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/ReflectUtils.kt @@ -81,7 +81,6 @@ inline fun getStaticValue( * @param fieldName the name of the field */ inline fun Class.getStaticValue(fieldName: String): R { - val field = getDeclaredField(fieldName) // make it accessible diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt index e39a24f3c..994f28703 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ActionEventForgeryFactory.kt @@ -92,7 +92,7 @@ internal class ActionEventForgeryFactory : name = forge.anAlphabeticalString(), model = forge.anAlphabeticalString(), brand = forge.anAlphabeticalString(), - type = forge.aValueFrom(ActionEvent.DeviceType::class.java), + type = forge.aValueFrom(ActionEvent.DeviceType::class.java) ), context = ActionEvent.Context( additionalProperties = mutableMapOf() diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt index 6ca158254..5294931b1 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt @@ -63,9 +63,9 @@ class DdSdkConfigurationForgeryFactory : ForgeryFactory { trackInteractions = forge.aBool(), trackNetworkRequests = forge.aBool(), reactVersion = forge.aString(), - reactNativeVersion = forge.aString(), + reactNativeVersion = forge.aString() ), - trackFrustrations = forge.aNullable { aBool() }, + trackFrustrations = forge.aNullable { aBool() } ) } } diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt index 6cfaf3930..dae18a67d 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/forge/ResourceEventForgeryFactory.kt @@ -100,7 +100,7 @@ internal class ResourceEventForgeryFactory : name = forge.anAlphabeticalString(), model = forge.anAlphabeticalString(), brand = forge.anAlphabeticalString(), - type = forge.aValueFrom(ResourceEvent.DeviceType::class.java), + type = forge.aValueFrom(ResourceEvent.DeviceType::class.java) ), context = ResourceEvent.Context( additionalProperties = mutableMapOf() From 23a619ff2cd89a7a9b69008c1a5f04484b223ff8 Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Wed, 6 Sep 2023 11:07:57 +0200 Subject: [PATCH 10/12] Get RUM Monitor only once when adding attributes --- .../main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt index 32cebbfe3..e2b5b89cc 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt @@ -66,8 +66,9 @@ internal class DatadogSDKWrapper : DatadogWrapper { } override fun addRumGlobalAttributes(attributes: Map) { + val rumMonitor = this.getRumMonitor() attributes.forEach { - this.getRumMonitor().addAttribute(it.key, it.value) + rumMonitor.addAttribute(it.key, it.value) } } From 6cca754a215da7e095b04971bea46cce04103f9a Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Wed, 6 Sep 2023 11:10:18 +0200 Subject: [PATCH 11/12] Rename configuration builders --- .../kotlin/com/datadog/reactnative/DdSdkImplementation.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt index 56d433dde..fac7489ab 100644 --- a/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +++ b/packages/core/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt @@ -54,8 +54,8 @@ class DdSdkImplementation( */ fun initialize(configuration: ReadableMap, promise: Promise) { val ddSdkConfiguration = configuration.asDdSdkConfiguration() - val sdkConfiguration = buildSDKConfiguration(ddSdkConfiguration) - val rumConfiguration = buildRUMConfiguration(ddSdkConfiguration) + val sdkConfiguration = buildSdkConfiguration(ddSdkConfiguration) + val rumConfiguration = buildRumConfiguration(ddSdkConfiguration) val trackingConsent = buildTrackingConsent(ddSdkConfiguration.trackingConsent) configureSdkVerbosity(ddSdkConfiguration) @@ -177,7 +177,7 @@ class DdSdkImplementation( } @Suppress("ComplexMethod", "LongMethod", "UnsafeCallOnNullableType") - private fun buildRUMConfiguration(configuration: DdSdkConfiguration): RumConfiguration { + private fun buildRumConfiguration(configuration: DdSdkConfiguration): RumConfiguration { val configBuilder = RumConfiguration.Builder( applicationId = configuration.applicationId @@ -307,7 +307,7 @@ class DdSdkImplementation( return firstPartyHostsWithHeaderTypes } - private fun buildSDKConfiguration(configuration: DdSdkConfiguration): Configuration { + private fun buildSdkConfiguration(configuration: DdSdkConfiguration): Configuration { val serviceName = configuration.additionalConfig?.get(DD_SERVICE_NAME) as? String val configBuilder = Configuration.Builder( clientToken = configuration.clientToken, From 7136dd94339cd8c85ffb9c9e9bf2ba9b997e002a Mon Sep 17 00:00:00 2001 From: louiszawadzki Date: Wed, 6 Sep 2023 11:13:17 +0200 Subject: [PATCH 12/12] Clean imports in MockRumMonitor --- .../com/datadog/tools/unit/MockRumMonitor.kt | 130 +++++++++--------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt index 2ae8cfd50..d389be984 100644 --- a/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt +++ b/packages/core/android/src/test/kotlin/com/datadog/tools/unit/MockRumMonitor.kt @@ -1,104 +1,108 @@ package com.datadog.tools.unit +import com.datadog.android.rum.RumActionType +import com.datadog.android.rum.RumErrorSource import com.datadog.android.rum.RumMonitor +import com.datadog.android.rum.RumResourceKind +import com.datadog.android.rum._RumInternalProxy class MockRumMonitor : RumMonitor { override var debug = false - override fun _getInternal(): com.datadog.android.rum._RumInternalProxy? { + override fun _getInternal(): _RumInternalProxy? { return null } override fun addAction( - type: com.datadog.android.rum.RumActionType, - name: kotlin.String, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + type: RumActionType, + name: String, + attributes: Map + ) {} - override fun addAttribute(key: kotlin.String, value: kotlin.Any?): kotlin.Unit {} + override fun addAttribute(key: String, value: Any?) {} override fun addError( - message: kotlin.String, - source: com.datadog.android.rum.RumErrorSource, - throwable: kotlin.Throwable?, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + message: String, + source: RumErrorSource, + throwable: Throwable?, + attributes: Map + ) {} override fun addErrorWithStacktrace( - message: kotlin.String, - source: com.datadog.android.rum.RumErrorSource, - stacktrace: kotlin.String?, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + message: String, + source: RumErrorSource, + stacktrace: String?, + attributes: Map + ) {} - override fun addFeatureFlagEvaluation(name: kotlin.String, value: kotlin.Any): kotlin.Unit {} + override fun addFeatureFlagEvaluation(name: String, value: Any) {} - override fun addTiming(name: kotlin.String): kotlin.Unit {} + override fun addTiming(name: String) {} - override fun clearAttributes(): kotlin.Unit {} + override fun clearAttributes() {} - override fun getAttributes(): kotlin.collections.Map { + override fun getAttributes(): Map { return mapOf() } - override fun removeAttribute(key: kotlin.String): kotlin.Unit {} + override fun removeAttribute(key: String) {} override fun startAction( - type: com.datadog.android.rum.RumActionType, - name: kotlin.String, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + type: RumActionType, + name: String, + attributes: Map + ) {} override fun startResource( - key: kotlin.String, - method: kotlin.String, - url: kotlin.String, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: String, + method: String, + url: String, + attributes: Map + ) {} override fun startView( - key: kotlin.Any, - name: kotlin.String, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: Any, + name: String, + attributes: Map + ) {} override fun stopAction( - type: com.datadog.android.rum.RumActionType, - name: kotlin.String, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + type: RumActionType, + name: String, + attributes: Map + ) {} override fun stopResource( - key: kotlin.String, - statusCode: kotlin.Int?, - size: kotlin.Long?, - kind: com.datadog.android.rum.RumResourceKind, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: String, + statusCode: Int?, + size: Long?, + kind: RumResourceKind, + attributes: Map + ) {} override fun stopResourceWithError( - key: kotlin.String, - statusCode: kotlin.Int?, - message: kotlin.String, - source: com.datadog.android.rum.RumErrorSource, - stackTrace: kotlin.String, - errorType: kotlin.String?, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: String, + statusCode: Int?, + message: String, + source: RumErrorSource, + stackTrace: String, + errorType: String?, + attributes: Map + ) {} override fun stopResourceWithError( - key: kotlin.String, - statusCode: kotlin.Int?, - message: kotlin.String, - source: com.datadog.android.rum.RumErrorSource, - throwable: kotlin.Throwable, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: String, + statusCode: Int?, + message: String, + source: RumErrorSource, + throwable: Throwable, + attributes: Map + ) {} - override fun stopSession(): kotlin.Unit {} + override fun stopSession() {} override fun stopView( - key: kotlin.Any, - attributes: kotlin.collections.Map - ): kotlin.Unit {} + key: Any, + attributes: Map + ) {} }