From dfee5c0299e105800cfade246782d03c6f16dd8a Mon Sep 17 00:00:00 2001 From: Jamie Lynch Date: Tue, 21 May 2024 10:20:54 +0100 Subject: [PATCH] poc: remove app id --- .../metadata/EmbraceMetadataService.kt | 2 +- .../capture/metadata/MetadataService.kt | 2 +- .../comms/delivery/NoopDeliveryService.kt | 41 ++++++++++ .../embracesdk/config/EmbraceConfigService.kt | 8 +- .../embracesdk/config/LocalConfigParser.kt | 43 ++++++++--- .../config/behavior/SdkEndpointBehavior.kt | 14 +++- .../config/behavior/SdkModeBehavior.kt | 2 +- .../embracesdk/config/local/LocalConfig.kt | 2 +- .../embracesdk/injection/DeliveryModule.kt | 20 +++-- .../injection/EssentialServiceModule.kt | 10 ++- .../android/embracesdk/internal/BuildInfo.kt | 5 +- .../OpenTelemetryConfiguration.kt | 2 + .../embracesdk/payload/NetworkEvent.kt | 2 +- .../EmbraceGatingServiceV1PayloadTest.kt | 12 +++ .../android/embracesdk/LocalConfigTest.kt | 76 +++++++++++++++++-- .../config/behavior/NetworkBehaviorTest.kt | 12 ++- .../EmbraceNetworkCaptureServiceTest.kt | 11 +++ .../session/PayloadFactoryBaTest.kt | 11 +++ .../session/PayloadFactorySessionTest.kt | 11 +++ 19 files changed, 241 insertions(+), 45 deletions(-) create mode 100644 embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/comms/delivery/NoopDeliveryService.kt diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/EmbraceMetadataService.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/EmbraceMetadataService.kt index da98296d00..656ef510ec 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/EmbraceMetadataService.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/EmbraceMetadataService.kt @@ -300,7 +300,7 @@ internal class EmbraceMetadataService private constructor( override fun getLightweightAppInfo(): AppInfo = getAppInfo(false) - override fun getAppId(): String { + override fun getAppId(): String? { return configService.sdkModeBehavior.appId } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/MetadataService.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/MetadataService.kt index 2f103c5df6..2d4d9e0304 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/MetadataService.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/capture/metadata/MetadataService.kt @@ -33,7 +33,7 @@ internal interface MetadataService { * * @return the app ID. */ - fun getAppId(): String + fun getAppId(): String? /** * Gets information and specifications of the current device. This is sent with the following diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/comms/delivery/NoopDeliveryService.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/comms/delivery/NoopDeliveryService.kt new file mode 100644 index 0000000000..6b37c115d5 --- /dev/null +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/comms/delivery/NoopDeliveryService.kt @@ -0,0 +1,41 @@ +package io.embrace.android.embracesdk.comms.delivery + +import io.embrace.android.embracesdk.internal.payload.Envelope +import io.embrace.android.embracesdk.internal.payload.LogPayload +import io.embrace.android.embracesdk.internal.utils.Provider +import io.embrace.android.embracesdk.ndk.NativeCrashService +import io.embrace.android.embracesdk.payload.EventMessage +import io.embrace.android.embracesdk.payload.NetworkEvent +import io.embrace.android.embracesdk.payload.SessionMessage +import io.embrace.android.embracesdk.session.id.SessionIdTracker +import io.embrace.android.embracesdk.session.orchestrator.SessionSnapshotType + +internal class NoopDeliveryService : DeliveryService { + + override fun sendSession(sessionMessage: SessionMessage, snapshotType: SessionSnapshotType) { + } + + override fun sendCachedSessions( + nativeCrashServiceProvider: Provider, + sessionIdTracker: SessionIdTracker + ) { + } + + override fun sendLog(eventMessage: EventMessage) { + } + + override fun sendLogs(logEnvelope: Envelope) { + } + + override fun saveLogs(logEnvelope: Envelope) { + } + + override fun sendNetworkCall(networkEvent: NetworkEvent) { + } + + override fun sendCrash(crash: EventMessage, processTerminating: Boolean) { + } + + override fun sendMoment(eventMessage: EventMessage) { + } +} diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/EmbraceConfigService.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/EmbraceConfigService.kt index 34137b28eb..5ae5ef598c 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/EmbraceConfigService.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/EmbraceConfigService.kt @@ -36,7 +36,7 @@ import kotlin.math.min */ internal class EmbraceConfigService @JvmOverloads constructor( private val localConfig: LocalConfig, - private val apiService: ApiService, + private val apiService: ApiService?, private val preferencesService: PreferencesService, private val clock: Clock, private val logger: EmbLogger, @@ -181,8 +181,8 @@ internal class EmbraceConfigService @JvmOverloads constructor( */ fun loadConfigFromCache() { - val cachedConfig = apiService.getCachedConfig() - val obj = cachedConfig.remoteConfig + val cachedConfig = apiService?.getCachedConfig() + val obj = cachedConfig?.remoteConfig if (obj != null) { val oldConfig = configProp @@ -214,7 +214,7 @@ internal class EmbraceConfigService @JvmOverloads constructor( if (configRequiresRefresh()) { try { lastRefreshConfigAttempt = clock.now() - val newConfig = apiService.getConfig() + val newConfig = apiService?.getConfig() if (newConfig != null) { updateConfig(previousConfig, newConfig) lastUpdated = clock.now() diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/LocalConfigParser.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/LocalConfigParser.kt index 8383643720..eaa6e3ce28 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/LocalConfigParser.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/LocalConfigParser.kt @@ -1,5 +1,6 @@ package io.embrace.android.embracesdk.config +import android.content.res.Resources.NotFoundException import android.util.Base64 import io.embrace.android.embracesdk.config.local.LocalConfig import io.embrace.android.embracesdk.config.local.SdkLocalConfig @@ -7,13 +8,14 @@ import io.embrace.android.embracesdk.internal.AndroidResourcesService import io.embrace.android.embracesdk.internal.ApkToolsConfig import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer import io.embrace.android.embracesdk.logging.EmbLogger +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration internal object LocalConfigParser { /** * Build info app id name. */ - public const val BUILD_INFO_APP_ID = "emb_app_id" + const val BUILD_INFO_APP_ID = "emb_app_id" /** * Build info sdk config id name. @@ -23,12 +25,12 @@ internal object LocalConfigParser { /** * Build info ndk enabled. */ - public const val BUILD_INFO_NDK_ENABLED = "emb_ndk_enabled" + const val BUILD_INFO_NDK_ENABLED = "emb_ndk_enabled" /** * The default value for native crash capture enabling */ - public const val NDK_ENABLED_DEFAULT = false + const val NDK_ENABLED_DEFAULT = false /** * Loads the build information from resources provided by the config file packaged within the application by Gradle at @@ -42,16 +44,11 @@ internal object LocalConfigParser { packageName: String, customAppId: String?, serializer: EmbraceSerializer, + openTelemetryCfg: OpenTelemetryConfiguration, logger: EmbLogger ): LocalConfig { return try { - val appId: String = customAppId ?: resources.getString( - resources.getIdentifier( - BUILD_INFO_APP_ID, - "string", - packageName - ) - ) + val appId = resolveAppId(customAppId, resources, packageName) val ndkEnabledJsonId = resources.getIdentifier(BUILD_INFO_NDK_ENABLED, "string", packageName) val ndkEnabled = when { @@ -74,20 +71,42 @@ internal object LocalConfigParser { else -> null } - buildConfig(appId, ndkEnabled, sdkConfigJson, serializer, logger) + buildConfig(appId, ndkEnabled, sdkConfigJson, serializer, openTelemetryCfg, logger) } catch (ex: Exception) { throw IllegalStateException("Failed to load local config from resources.", ex) } } + private fun resolveAppId( + customAppId: String?, + resources: AndroidResourcesService, + packageName: String + ): String? { + return try { + customAppId ?: resources.getString( + resources.getIdentifier( + BUILD_INFO_APP_ID, + "string", + packageName + ) + ) + } catch (exc: NotFoundException) { + null + } + } + fun buildConfig( appId: String?, ndkEnabled: Boolean, sdkConfigs: String?, serializer: EmbraceSerializer, + openTelemetryCfg: OpenTelemetryConfiguration, logger: EmbLogger ): LocalConfig { - require(!appId.isNullOrEmpty()) { "Embrace AppId cannot be null or empty." } + require(!appId.isNullOrEmpty() || openTelemetryCfg.hasConfiguredOtelExporters()) { + "No appId supplied in embrace-config.json. This is required if you want to " + + "send data to Embrace, unless you configure an OTel exporter." + } val enabledStr = when { ndkEnabled -> "enabled" diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkEndpointBehavior.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkEndpointBehavior.kt index be23448a78..13c6401d04 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkEndpointBehavior.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkEndpointBehavior.kt @@ -23,10 +23,20 @@ internal class SdkEndpointBehavior( /** * Data base URL. */ - fun getData(appId: String): String = local?.data ?: "https://a-$appId.$DATA_DEFAULT" + fun getData(appId: String?): String { + if (appId == null) { + return "" + } + return local?.data ?: "https://a-$appId.$DATA_DEFAULT" + } /** * Config base URL. */ - fun getConfig(appId: String): String = local?.config ?: "https://a-$appId.$CONFIG_DEFAULT" + fun getConfig(appId: String?): String { + if (appId == null) { + return "" + } + return local?.config ?: "https://a-$appId.$CONFIG_DEFAULT" + } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkModeBehavior.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkModeBehavior.kt index 698e6ac1f8..460c386b38 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkModeBehavior.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/behavior/SdkModeBehavior.kt @@ -75,7 +75,7 @@ internal class SdkModeBehavior( /** * The Embrace app ID. This is used to identify the app within the database. */ - val appId: String by lazy { local?.appId ?: error("App ID not supplied.") } + val appId: String? by lazy { local?.appId } /** * The % of devices that should be enabled. diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/local/LocalConfig.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/local/LocalConfig.kt index 6e2e1daa32..298521f092 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/local/LocalConfig.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/config/local/LocalConfig.kt @@ -9,7 +9,7 @@ internal class LocalConfig( /** * The Embrace app ID. This is used to identify the app within the database. */ - val appId: String, + val appId: String?, /** * Control whether the Embrace SDK is able to capture native crashes. diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/DeliveryModule.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/DeliveryModule.kt index 58dc87783e..843cb19dab 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/DeliveryModule.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/DeliveryModule.kt @@ -2,6 +2,7 @@ package io.embrace.android.embracesdk.injection import io.embrace.android.embracesdk.comms.delivery.DeliveryService import io.embrace.android.embracesdk.comms.delivery.EmbraceDeliveryService +import io.embrace.android.embracesdk.comms.delivery.NoopDeliveryService import io.embrace.android.embracesdk.worker.WorkerName import io.embrace.android.embracesdk.worker.WorkerThreadModule @@ -18,12 +19,17 @@ internal class DeliveryModuleImpl( ) : DeliveryModule { override val deliveryService: DeliveryService by singleton { - EmbraceDeliveryService( - storageModule.deliveryCacheManager, - essentialServiceModule.apiService, - workerThreadModule.backgroundWorker(WorkerName.DELIVERY_CACHE), - coreModule.jsonSerializer, - initModule.logger - ) + val apiService = essentialServiceModule.apiService + if (apiService == null) { + NoopDeliveryService() + } else { + EmbraceDeliveryService( + storageModule.deliveryCacheManager, + apiService, + workerThreadModule.backgroundWorker(WorkerName.DELIVERY_CACHE), + coreModule.jsonSerializer, + initModule.logger + ) + } } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/EssentialServiceModule.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/EssentialServiceModule.kt index a79eba541f..8a396fa10b 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/EssentialServiceModule.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/injection/EssentialServiceModule.kt @@ -63,7 +63,7 @@ internal interface EssentialServiceModule { val userService: UserService val urlBuilder: ApiUrlBuilder val apiClient: ApiClient - val apiService: ApiService + val apiService: ApiService? val sharedObjectLoader: SharedObjectLoader val cpuInfoDelegate: CpuInfoDelegate val deviceArchitecture: DeviceArchitecture @@ -95,6 +95,7 @@ internal class EssentialServiceModuleImpl( coreModule.context.packageName, customAppId, coreModule.jsonSerializer, + openTelemetryModule.openTelemetryConfiguration, initModule.logger ) } @@ -226,7 +227,7 @@ internal class EssentialServiceModuleImpl( thresholdCheck = thresholdCheck, localSupplier = localConfig.sdkConfig::baseUrls, ) - + checkNotNull(appId) val coreBaseUrl = sdkEndpointBehavior.getData(appId) val configBaseUrl = sdkEndpointBehavior.getConfig(appId) @@ -278,7 +279,10 @@ internal class EssentialServiceModuleImpl( } } - override val apiService: ApiService by singleton { + override val apiService: ApiService? by singleton { + if (appId == null) { + return@singleton null + } Systrace.traceSynchronous("api-service-init") { EmbraceApiService( apiClient = apiClient, diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/BuildInfo.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/BuildInfo.kt index b831419f60..2be4785d1a 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/BuildInfo.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/BuildInfo.kt @@ -66,10 +66,7 @@ internal class BuildInfo internal constructor( ex ) } catch (ex: Resources.NotFoundException) { - throw IllegalArgumentException( - "No resource found for $buildProperty property. Failed to create build info.", - ex - ) + null } } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/opentelemetry/OpenTelemetryConfiguration.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/opentelemetry/OpenTelemetryConfiguration.kt index 50cc3ad728..d14b3b3f05 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/opentelemetry/OpenTelemetryConfiguration.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/opentelemetry/OpenTelemetryConfiguration.kt @@ -64,4 +64,6 @@ internal class OpenTelemetryConfiguration( fun addLogExporter(logExporter: LogRecordExporter) { externalLogExporters.add(logExporter) } + + fun hasConfiguredOtelExporters() = externalLogExporters.isNotEmpty() || externalSpanExporters.isNotEmpty() } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/NetworkEvent.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/NetworkEvent.kt index dc2a3b33b6..9c3fc99756 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/NetworkEvent.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/payload/NetworkEvent.kt @@ -6,7 +6,7 @@ import com.squareup.moshi.JsonClass @JsonClass(generateAdapter = true) internal data class NetworkEvent( @Json(name = "app_id") - val appId: String, + val appId: String?, @Json(name = "a") val appInfo: AppInfo, diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/EmbraceGatingServiceV1PayloadTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/EmbraceGatingServiceV1PayloadTest.kt index 4f4d8abc78..c8a4a87a98 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/EmbraceGatingServiceV1PayloadTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/EmbraceGatingServiceV1PayloadTest.kt @@ -32,10 +32,14 @@ import io.embrace.android.embracesdk.gating.SessionGatingKeys.SESSION_PROPERTIES import io.embrace.android.embracesdk.gating.SessionGatingKeys.SESSION_USER_TERMINATION import io.embrace.android.embracesdk.gating.SessionGatingKeys.STARTUP_MOMENT import io.embrace.android.embracesdk.gating.SessionGatingKeys.USER_PERSONAS +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.internal.utils.Uuid import io.embrace.android.embracesdk.logging.EmbLogger import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import io.embrace.android.embracesdk.payload.DiskUsage import io.embrace.android.embracesdk.payload.Event import io.embrace.android.embracesdk.payload.EventMessage @@ -81,6 +85,13 @@ internal class EmbraceGatingServiceV1PayloadTest { LOGS_WARN ) + private val otelCfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) + private lateinit var sessionBehavior: SessionBehavior private var cfg: RemoteConfig? = RemoteConfig() @@ -176,6 +187,7 @@ internal class EmbraceGatingServiceV1PayloadTest { "]" + "}}", EmbraceSerializer(), + otelCfg, EmbLoggerImpl() ) diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/LocalConfigTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/LocalConfigTest.kt index 0e95fc0c3b..b29736680d 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/LocalConfigTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/LocalConfigTest.kt @@ -1,8 +1,13 @@ package io.embrace.android.embracesdk import io.embrace.android.embracesdk.config.LocalConfigParser +import io.embrace.android.embracesdk.fakes.FakeLogRecordExporter +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -14,10 +19,33 @@ internal class LocalConfigTest { private val serializer = EmbraceSerializer() private val logger = EmbLoggerImpl() + private val cfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) + + @Test(expected = IllegalArgumentException::class) + fun testEmptyAppId() { + LocalConfigParser.buildConfig(null, false, null, serializer, cfg, logger) + } + + @Test(expected = IllegalArgumentException::class) + fun testNullAppId() { + LocalConfigParser.buildConfig("", false, null, serializer, cfg, logger) + } + + @Test + fun testNoAppIdRequiredWithExporters() { + cfg.addLogExporter(FakeLogRecordExporter()) + val cfg = LocalConfigParser.buildConfig("abcdefoi", false, null, serializer, cfg, logger) + assertNotNull(cfg) + } @Test fun testEmptyConfig() { - val localConfig = LocalConfigParser.buildConfig("GrCPU", false, null, serializer, logger) + val localConfig = LocalConfigParser.buildConfig("GrCPU", false, null, serializer, cfg, logger) assertNotNull(localConfig) } @@ -29,6 +57,7 @@ internal class LocalConfigTest { false, "{\"app\": {\"report_disk_usage\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.app?.reportDiskUsage)) @@ -38,7 +67,7 @@ internal class LocalConfigTest { fun testBetaFunctionalityOnlyConfig() { // disabled explicitly var localConfig = - LocalConfigParser.buildConfig("GrCPU", false, "{\"beta_features_enabled\": false}", serializer, logger) + LocalConfigParser.buildConfig("GrCPU", false, "{\"beta_features_enabled\": false}", serializer, cfg, logger) assertFalse(checkNotNull(localConfig.sdkConfig.betaFeaturesEnabled)) // enabled explicitly @@ -47,12 +76,13 @@ internal class LocalConfigTest { false, "{\"beta_features_enabled\": true}", serializer, + cfg, logger ) assertTrue(checkNotNull(localConfig.sdkConfig.betaFeaturesEnabled)) // enabled by default - localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, logger) + localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, cfg, logger) assertNull(localConfig.sdkConfig.betaFeaturesEnabled) } @@ -60,7 +90,7 @@ internal class LocalConfigTest { fun testSigHandlerDetectionOnlyConfig() { // disabled explicitly var localConfig = - LocalConfigParser.buildConfig("GrCPU", false, "{\"sig_handler_detection\": false}", serializer, logger) + LocalConfigParser.buildConfig("GrCPU", false, "{\"sig_handler_detection\": false}", serializer, cfg, logger) assertFalse(checkNotNull(localConfig.sdkConfig.sigHandlerDetection)) // enabled explicitly @@ -69,12 +99,13 @@ internal class LocalConfigTest { false, "{\"sig_handler_detection\": true}", serializer, + cfg, logger ) assertTrue(checkNotNull(localConfig.sdkConfig.sigHandlerDetection)) // enabled by default - localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, logger) + localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, cfg, logger) assertNull(localConfig.sdkConfig.sigHandlerDetection) } @@ -85,6 +116,7 @@ internal class LocalConfigTest { false, "{\"base_urls\": {\"config\": \"custom_config\"}}", serializer, + cfg, logger ) assertEquals(localConfig.sdkConfig.baseUrls?.config, "custom_config") @@ -94,6 +126,7 @@ internal class LocalConfigTest { false, "{\"base_urls\": {\"data\": \"custom_data\"}}", serializer, + cfg, logger ) assertEquals(localConfig.sdkConfig.baseUrls?.data, "custom_data") @@ -102,6 +135,7 @@ internal class LocalConfigTest { false, "{\"base_urls\": {\"images\": \"custom_images\"}}", serializer, + cfg, logger ) assertEquals(localConfig.sdkConfig.baseUrls?.images, "custom_images") @@ -109,7 +143,7 @@ internal class LocalConfigTest { @Test fun testViewConfigOnlyConfig() { - var localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, logger) + var localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, cfg, logger) assertNull( localConfig.sdkConfig.viewConfig?.enableAutomaticActivityCapture, ) @@ -118,6 +152,7 @@ internal class LocalConfigTest { false, "{\"view_config\":{\"enable_automatic_activity_capture\":false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.viewConfig?.enableAutomaticActivityCapture)) @@ -131,6 +166,7 @@ internal class LocalConfigTest { false, "{\"crash_handler\": {\"enabled\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.crashHandler?.enabled)) @@ -140,6 +176,7 @@ internal class LocalConfigTest { false, "{\"crash_handler\": {\"ndk_enabled\": false}}", serializer, + cfg, logger ) assertFalse(localConfig.ndkEnabled) @@ -152,6 +189,7 @@ internal class LocalConfigTest { false, "{\"session\": {\"components\": [\"breadcrumbs_taps\"]}}", serializer, + cfg, logger ) assertTrue( @@ -166,6 +204,7 @@ internal class LocalConfigTest { false, "{\"session\": {\"send_full_for\": []}}", serializer, + cfg, logger ) assertTrue( @@ -178,6 +217,7 @@ internal class LocalConfigTest { false, "{\"session\": {\"send_full_for\": [\"crashes\"]}}", serializer, + cfg, logger ) val sessionConfig = localConfig.sdkConfig.sessionConfig @@ -196,6 +236,7 @@ internal class LocalConfigTest { false, "{\"startup_moment\": {\"automatically_end\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.startupMoment?.automaticallyEnd)) @@ -209,6 +250,7 @@ internal class LocalConfigTest { false, "{\"taps\": {\"capture_coordinates\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.taps?.captureCoordinates)) @@ -221,6 +263,7 @@ internal class LocalConfigTest { false, "{\"networking\": {\"capture_request_content_length\": true}}", serializer, + cfg, logger ) assertTrue( @@ -232,6 +275,7 @@ internal class LocalConfigTest { false, "{\"networking\": {\"enable_native_monitoring\": true}}", serializer, + cfg, logger ) assertTrue(checkNotNull(localConfig.sdkConfig.networking?.enableNativeMonitoring)) @@ -240,6 +284,7 @@ internal class LocalConfigTest { false, "{\"networking\": {\"trace_id_header\": \"custom-value\"}}", serializer, + cfg, logger ) assertEquals( @@ -251,6 +296,7 @@ internal class LocalConfigTest { false, "{\"networking\": {\"disabled_url_patterns\": [\"a.b.c\", \"https://example.com\", \"https://example2.com/foo/123/bar\"]}}", serializer, + cfg, logger ) assertEquals( @@ -266,6 +312,7 @@ internal class LocalConfigTest { false, "{\"webview\": {\"enable\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.webViewConfig?.captureWebViews)) @@ -274,6 +321,7 @@ internal class LocalConfigTest { false, "{\"webview\": {\"capture_query_params\": false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.webViewConfig?.captureQueryParams)) @@ -286,6 +334,7 @@ internal class LocalConfigTest { false, "{\"background_activity\": {}}", serializer, + cfg, logger ) var backgroundActivityCfg = checkNotNull(localConfig.sdkConfig.backgroundActivityConfig) @@ -306,6 +355,7 @@ internal class LocalConfigTest { false, "{\"background_activity\": {\"capture_enabled\": true}}", serializer, + cfg, logger ) backgroundActivityCfg = checkNotNull(localConfig.sdkConfig.backgroundActivityConfig) @@ -318,6 +368,7 @@ internal class LocalConfigTest { false, "{\"background_activity\": {\"capture_enabled\": true, \"manual_background_activity_limit\": 50}}", serializer, + cfg, logger ) backgroundActivityCfg = checkNotNull(localConfig.sdkConfig.backgroundActivityConfig) @@ -333,6 +384,7 @@ internal class LocalConfigTest { false, "{\"background_activity\": {\"capture_enabled\": true, \"min_background_activity_duration\": 300}}", serializer, + cfg, logger ) backgroundActivityCfg = checkNotNull(localConfig.sdkConfig.backgroundActivityConfig) @@ -348,6 +400,7 @@ internal class LocalConfigTest { false, "{\"background_activity\": {\"capture_enabled\": true, \"max_cached_activities\": 50}}", serializer, + cfg, logger ) backgroundActivityCfg = checkNotNull(localConfig.sdkConfig.backgroundActivityConfig) @@ -362,7 +415,7 @@ internal class LocalConfigTest { @Test fun testComposeConfig() { - var localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, logger) + var localConfig = LocalConfigParser.buildConfig("GrCPU", false, "{}", serializer, cfg, logger) assertNull( localConfig.sdkConfig.composeConfig?.captureComposeOnClick, ) @@ -371,6 +424,7 @@ internal class LocalConfigTest { false, "{\"compose\":{\"capture_compose_onclick\":false}}", serializer, + cfg, logger ) assertFalse(checkNotNull(localConfig.sdkConfig.composeConfig?.captureComposeOnClick)) @@ -383,6 +437,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"memory_info\": false}}", serializer, + cfg, logger ) var cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -394,6 +449,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"memory_info\": true}}", serializer, + this.cfg, logger ) cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -409,6 +465,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"power_save_mode_info\": false}}", serializer, + cfg, logger ) var cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -420,6 +477,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"power_save_mode_info\": true}}", serializer, + this.cfg, logger ) cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -435,6 +493,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"network_connectivity_info\": false}}", serializer, + cfg, logger ) var cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -447,6 +506,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"network_connectivity_info\": true}}", serializer, + this.cfg, logger ) cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -463,6 +523,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"anr_info\": false}}", serializer, + cfg, logger ) var cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) @@ -474,6 +535,7 @@ internal class LocalConfigTest { false, "{\"automatic_data_capture\": { \"anr_info\": true}}", serializer, + this.cfg, logger ) cfg = checkNotNull(localConfig.sdkConfig.automaticDataCaptureConfig) diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/config/behavior/NetworkBehaviorTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/config/behavior/NetworkBehaviorTest.kt index 67177a1d5b..58ccdfd7d1 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/config/behavior/NetworkBehaviorTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/config/behavior/NetworkBehaviorTest.kt @@ -9,8 +9,12 @@ import io.embrace.android.embracesdk.config.remote.NetworkCaptureRuleRemoteConfi import io.embrace.android.embracesdk.config.remote.NetworkRemoteConfig import io.embrace.android.embracesdk.config.remote.RemoteConfig import io.embrace.android.embracesdk.fakes.fakeNetworkBehavior +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull @@ -146,8 +150,14 @@ internal class NetworkBehaviorTest { @Test fun testGetCapturePublicKey() { + val otelCfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) val json = ResourceReader.readResourceAsText("public_key_config.json") - val localConfig = LocalConfigParser.buildConfig("aaa", false, json, EmbraceSerializer(), EmbLoggerImpl()) + val localConfig = LocalConfigParser.buildConfig("aaa", false, json, EmbraceSerializer(), otelCfg, EmbLoggerImpl()) val behavior = fakeNetworkBehavior(localCfg = localConfig::sdkConfig) assertEquals(testCleanPublicKey, behavior.getCapturePublicKey()) } diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/network/logging/EmbraceNetworkCaptureServiceTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/network/logging/EmbraceNetworkCaptureServiceTest.kt index 38d5a2acd6..ab5e0c17b6 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/network/logging/EmbraceNetworkCaptureServiceTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/network/logging/EmbraceNetworkCaptureServiceTest.kt @@ -12,9 +12,13 @@ import io.embrace.android.embracesdk.fakes.FakePreferenceService import io.embrace.android.embracesdk.fakes.FakeSessionIdTracker import io.embrace.android.embracesdk.fakes.fakeNetworkBehavior import io.embrace.android.embracesdk.fakes.fakeSdkEndpointBehavior +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.network.http.NetworkCaptureData import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import io.mockk.clearAllMocks import io.mockk.unmockkAll import org.junit.AfterClass @@ -50,12 +54,19 @@ internal class EmbraceNetworkCaptureServiceTest { @BeforeClass @JvmStatic fun beforeClass() { + val otelCfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) mockLocalConfig = LocalConfigParser.buildConfig( "GrCPU", false, "{\"base_urls\": {\"data\": \"https://data.emb-api.com\"}}", EmbraceSerializer(), + otelCfg, EmbLoggerImpl() ) } diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactoryBaTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactoryBaTest.kt index 358668c7a1..06586d34b1 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactoryBaTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactoryBaTest.kt @@ -34,12 +34,16 @@ import io.embrace.android.embracesdk.fakes.FakeStartupService import io.embrace.android.embracesdk.fakes.FakeUserService import io.embrace.android.embracesdk.fakes.FakeWebViewService import io.embrace.android.embracesdk.fakes.injection.FakeInitModule +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer import io.embrace.android.embracesdk.internal.spans.CurrentSessionSpan import io.embrace.android.embracesdk.internal.spans.SpanRepository import io.embrace.android.embracesdk.internal.spans.SpanService import io.embrace.android.embracesdk.internal.spans.SpanSink +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import io.embrace.android.embracesdk.session.lifecycle.ProcessState import io.embrace.android.embracesdk.session.message.PayloadFactoryImpl import io.embrace.android.embracesdk.session.message.V1PayloadMessageCollator @@ -96,11 +100,18 @@ internal class PayloadFactoryBaTest { backgroundActivityCaptureEnabled = true ) configService.updateListeners() + val otelCfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) localConfig = LocalConfigParser.buildConfig( "GrCPU", false, "{\"background_activity\": {\"max_background_activity_seconds\": 3600}}", EmbraceSerializer(), + otelCfg, EmbLoggerImpl() ) diff --git a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactorySessionTest.kt b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactorySessionTest.kt index 27e714ba6f..0ed4502c32 100644 --- a/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactorySessionTest.kt +++ b/embrace-android-sdk/src/test/java/io/embrace/android/embracesdk/session/PayloadFactorySessionTest.kt @@ -32,12 +32,16 @@ import io.embrace.android.embracesdk.fakes.FakeSessionPayloadSource import io.embrace.android.embracesdk.fakes.FakeStartupService import io.embrace.android.embracesdk.fakes.FakeUserService import io.embrace.android.embracesdk.fakes.injection.FakeInitModule +import io.embrace.android.embracesdk.internal.SystemInfo +import io.embrace.android.embracesdk.internal.logs.LogSinkImpl import io.embrace.android.embracesdk.internal.serialization.EmbraceSerializer import io.embrace.android.embracesdk.internal.spans.CurrentSessionSpan import io.embrace.android.embracesdk.internal.spans.SpanRepository import io.embrace.android.embracesdk.internal.spans.SpanService import io.embrace.android.embracesdk.internal.spans.SpanSink +import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl import io.embrace.android.embracesdk.logging.EmbLoggerImpl +import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration import io.embrace.android.embracesdk.session.lifecycle.ProcessState import io.embrace.android.embracesdk.session.message.PayloadFactory import io.embrace.android.embracesdk.session.message.PayloadFactoryImpl @@ -119,11 +123,18 @@ internal class PayloadFactorySessionTest { currentSessionSpan = initModule.openTelemetryModule.currentSessionSpan spanService = initModule.openTelemetryModule.spanService configService.updateListeners() + val otelCfg = OpenTelemetryConfiguration( + SpanSinkImpl(), + LogSinkImpl(), + SystemInfo(), + "my-id" + ) localConfig = LocalConfigParser.buildConfig( "GrCPU", false, "{\"background_activity\": {\"max_background_activity_seconds\": 3600}}", EmbraceSerializer(), + otelCfg, EmbLoggerImpl() )