From 97c83d1710469d435d97116f5f14d7b04369fc53 Mon Sep 17 00:00:00 2001 From: Marius Constantin Date: Tue, 5 Nov 2024 14:15:58 +0100 Subject: [PATCH] RUM-6400 Add warning log when initializing the sdk outside of main process --- .../com/datadog/android/core/internal/CoreFeature.kt | 11 +++++++++++ .../datadog/android/core/internal/CoreFeatureTest.kt | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt index 646e673723..554cbc7e2d 100644 --- a/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt +++ b/dd-sdk-android-core/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt @@ -626,6 +626,13 @@ internal class CoreFeature( } else { appContext.packageName == currentProcess.processName } + if (!isMainProcess) { + internalLogger.log( + InternalLogger.Level.WARN, + InternalLogger.Target.USER, + { SDK_INITIALIZED_IN_SECONDARY_PROCESS_WARNING_MESSAGE } + ) + } } private fun shutDownExecutors() { @@ -676,6 +683,10 @@ internal class CoreFeature( // endregion companion object { + internal const val SDK_INITIALIZED_IN_SECONDARY_PROCESS_WARNING_MESSAGE = + "Datadog SDK was initialized in a secondary process: although data will still be captured," + + " nothing will be uploaded from this process. Make sure to also initialize the SDK from the main" + + " process of your application." internal val DEFAULT_FLUSHABLE_EXECUTOR_SERVICE_FACTORY = FlushableExecutorService.Factory { logger, executorContext, backPressureStrategy -> diff --git a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt index 3b4fb6a167..4f5a0ef6f3 100644 --- a/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt +++ b/dd-sdk-android-core/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt @@ -781,6 +781,11 @@ internal class CoreFeatureTest { // Then assertThat(testedFeature.isMainProcess).isFalse() + mockInternalLogger.verifyLog( + InternalLogger.Level.WARN, + InternalLogger.Target.USER, + CoreFeature.SDK_INITIALIZED_IN_SECONDARY_PROCESS_WARNING_MESSAGE + ) } @Test