Skip to content

Commit

Permalink
Merge pull request #842 from embrace-io/remove-app-state
Browse files Browse the repository at this point in the history
Remove app state from internal errors
  • Loading branch information
fractalwrench committed May 14, 2024
2 parents f87a761 + 086b1fa commit 04ad926
Show file tree
Hide file tree
Showing 23 changed files with 36 additions and 185 deletions.
2 changes: 1 addition & 1 deletion embrace-android-sdk/config/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>DataClassContainsFunctions:LegacyExceptionError.kt$LegacyExceptionError$fun addException(ex: Throwable?, appState: String?, clock: Clock)</ID>
<ID>DataClassContainsFunctions:LegacyExceptionError.kt$LegacyExceptionError$fun addException(ex: Throwable?, clock: Clock)</ID>
<ID>DataClassContainsFunctions:LegacyExceptionError.kt$LegacyExceptionError$private fun getExceptionInfo(ex: Throwable?): List&lt;LegacyExceptionInfo&gt;</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "c") var occurrences: Int = 0</ID>
<ID>DataClassShouldBeImmutable:LegacyExceptionError.kt$LegacyExceptionError$@Json(name = "rep") var exceptionErrors: MutableList&lt;LegacyExceptionErrorInfo&gt; = mutableListOf()</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import io.embrace.android.embracesdk.injection.DeliveryModule;
import io.embrace.android.embracesdk.injection.EssentialServiceModule;
import io.embrace.android.embracesdk.injection.ModuleInitBootstrapper;
import io.embrace.android.embracesdk.injection.SdkObservabilityModule;
import io.embrace.android.embracesdk.injection.SessionModule;
import io.embrace.android.embracesdk.internal.ApkToolsConfig;
import io.embrace.android.embracesdk.internal.EmbraceInternalInterface;
Expand Down Expand Up @@ -304,9 +303,8 @@ private void startImpl(@NonNull Context context,
final AnrModule anrModule = moduleInitBootstrapper.getAnrModule();
anrService = anrModule.getAnrService();

final SdkObservabilityModule sdkObservabilityModule = moduleInitBootstrapper.getSdkObservabilityModule();
internalErrorService = sdkObservabilityModule.getInternalErrorService();
sdkObservabilityModule.getInternalErrorService().setConfigService(configService);
internalErrorService = moduleInitBootstrapper.getInitModule().getInternalErrorService();
internalErrorService.setConfigService(configService);

final DeliveryModule deliveryModule = moduleInitBootstrapper.getDeliveryModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import io.embrace.android.embracesdk.internal.clock.NormalizedIntervalClock
import io.embrace.android.embracesdk.internal.clock.SystemClock
import io.embrace.android.embracesdk.logging.EmbLogger
import io.embrace.android.embracesdk.logging.EmbLoggerImpl
import io.embrace.android.embracesdk.logging.EmbraceInternalErrorService
import io.embrace.android.embracesdk.logging.InternalErrorService
import io.embrace.android.embracesdk.telemetry.EmbraceTelemetryService
import io.embrace.android.embracesdk.telemetry.TelemetryService

Expand Down Expand Up @@ -45,6 +47,11 @@ internal interface InitModule {
* this out by proximity for stitched sessions.
*/
val processIdentifier: String

/**
* Tracks internal errors
*/
val internalErrorService: InternalErrorService
}

internal class InitModuleImpl(
Expand All @@ -55,6 +62,12 @@ internal class InitModuleImpl(
override val systemInfo: SystemInfo = SystemInfo()
) : InitModule {

override val internalErrorService: InternalErrorService = EmbraceInternalErrorService(clock)

init {
logger.internalErrorService = internalErrorService
}

override val telemetryService: TelemetryService by singleton {
EmbraceTelemetryService(
systemInfo = systemInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import io.embrace.android.embracesdk.internal.utils.EssentialServiceModuleSuppli
import io.embrace.android.embracesdk.internal.utils.NativeModuleSupplier
import io.embrace.android.embracesdk.internal.utils.PayloadModuleSupplier
import io.embrace.android.embracesdk.internal.utils.Provider
import io.embrace.android.embracesdk.internal.utils.SdkObservabilityModuleSupplier
import io.embrace.android.embracesdk.internal.utils.SessionModuleSupplier
import io.embrace.android.embracesdk.internal.utils.StorageModuleSupplier
import io.embrace.android.embracesdk.internal.utils.SystemServiceModuleSupplier
Expand Down Expand Up @@ -59,7 +58,6 @@ internal class ModuleInitBootstrapper(
private val dataCaptureServiceModuleSupplier: DataCaptureServiceModuleSupplier = ::DataCaptureServiceModuleImpl,
private val deliveryModuleSupplier: DeliveryModuleSupplier = ::DeliveryModuleImpl,
private val anrModuleSupplier: AnrModuleSupplier = ::AnrModuleImpl,
private val sdkObservabilityModuleSupplier: SdkObservabilityModuleSupplier = ::SdkObservabilityModuleImpl,
private val customerLogModuleSupplier: CustomerLogModuleSupplier = ::CustomerLogModuleImpl,
private val nativeModuleSupplier: NativeModuleSupplier = ::NativeModuleImpl,
private val dataContainerModuleSupplier: DataContainerModuleSupplier = ::DataContainerModuleImpl,
Expand Down Expand Up @@ -94,9 +92,6 @@ internal class ModuleInitBootstrapper(
lateinit var anrModule: AnrModule
private set

lateinit var sdkObservabilityModule: SdkObservabilityModule
private set

lateinit var customerLogModule: CustomerLogModule
private set

Expand Down Expand Up @@ -147,6 +142,11 @@ internal class ModuleInitBootstrapper(
synchronized(asyncInitTask) {
return if (!isInitialized()) {
coreModule = init(CoreModule::class) { coreModuleSupplier(context, appFramework, logger) }

val serviceRegistry = coreModule.serviceRegistry
postInit(InitModule::class) {
serviceRegistry.registerService(initModule.internalErrorService)
}
workerThreadModule = init(WorkerThreadModule::class) { workerThreadModuleSupplier(initModule) }

val initTask = postInit(OpenTelemetryModule::class) {
Expand All @@ -157,8 +157,6 @@ internal class ModuleInitBootstrapper(
asyncInitCompletionMs = initModule.clock.now()
}
}

val serviceRegistry = coreModule.serviceRegistry
postInit(OpenTelemetryModule::class) {
serviceRegistry.registerService(initModule.telemetryService)
serviceRegistry.registerService(openTelemetryModule.spanService)
Expand Down Expand Up @@ -194,6 +192,7 @@ internal class ModuleInitBootstrapper(
)
}
postInit(EssentialServiceModule::class) {
initModule.internalErrorService.configService = essentialServiceModule.configService
serviceRegistry.registerServices(
essentialServiceModule.processStateService,
essentialServiceModule.metadataService,
Expand Down Expand Up @@ -277,17 +276,6 @@ internal class ModuleInitBootstrapper(
)
}

// initialize the logger early so that logged exceptions have a good chance of
// being appended to the exceptions service rather than logcat
sdkObservabilityModule = init(SdkObservabilityModule::class) {
sdkObservabilityModuleSupplier(initModule, essentialServiceModule)
}

postInit(SdkObservabilityModule::class) {
serviceRegistry.registerService(sdkObservabilityModule.internalErrorService)
initModule.logger.internalErrorService = sdkObservabilityModule.internalErrorService
}

nativeModule = init(NativeModule::class) {
nativeModuleSupplier(
initModule,
Expand Down Expand Up @@ -357,8 +345,7 @@ internal class ModuleInitBootstrapper(
systemServiceModule,
workerThreadModule,
nativeModule,
openTelemetryModule,
sdkObservabilityModule
openTelemetryModule
) { sessionModule.sessionPropertiesService }
}

Expand Down Expand Up @@ -413,7 +400,6 @@ internal class ModuleInitBootstrapper(
deliveryModule,
dataCaptureServiceModule,
customerLogModule,
sdkObservabilityModule,
workerThreadModule,
dataSourceModule,
payloadModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ internal class PayloadModuleImpl(
workerThreadModule: WorkerThreadModule,
nativeModule: NativeModule,
otelModule: OpenTelemetryModule,
sdkObservabilityModule: SdkObservabilityModule,
sessionPropertiesServiceProvider: Provider<SessionPropertiesService>,
) : PayloadModule {

Expand Down Expand Up @@ -66,7 +65,7 @@ internal class PayloadModuleImpl(

private val sessionPayloadSource by singleton {
SessionPayloadSourceImpl(
sdkObservabilityModule.internalErrorService,
initModule.internalErrorService,
nativeModule.nativeThreadSamplerService,
otelModule.spanSink,
otelModule.currentSessionSpan,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ internal class SessionModuleImpl(
deliveryModule: DeliveryModule,
dataCaptureServiceModule: DataCaptureServiceModule,
customerLogModule: CustomerLogModule,
sdkObservabilityModule: SdkObservabilityModule,
workerThreadModule: WorkerThreadModule,
dataSourceModule: DataSourceModule,
payloadModule: PayloadModule,
Expand All @@ -50,7 +49,7 @@ internal class SessionModuleImpl(
essentialServiceModule.metadataService,
dataContainerModule.eventService,
customerLogModule.logMessageService,
sdkObservabilityModule.internalErrorService,
initModule.internalErrorService,
dataContainerModule.performanceInfoService,
dataCaptureServiceModule.webviewService,
nativeModule.nativeThreadSamplerService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

/**
*
*
* @param timestamp The timestamp in milliseconds of when an error happened. Previous name: s.e.rep.ts
* @param appState The app state at the time of the error (foreground/background). Previous name: s.e.rep.s
* @param exceptions A list of exceptions. Previous name: s.e.rep.ex
*/
@JsonClass(generateAdapter = true)
Expand All @@ -17,26 +14,7 @@ internal data class ExceptionErrorInfo(
@Json(name = "timestamp")
val timestamp: Long? = null,

/* The app state at the time of the error (foreground/background). Previous name: s.e.rep.s */
@Json(name = "app_state")
val appState: AppState? = null,

/* A list of exceptions. Previous name: s.e.rep.ex */
@Json(name = "exceptions")
val exceptions: List<ExceptionInfo>? = null

) {

/**
* The app state at the time of the error (foreground/background). Previous name: s.e.rep.s
*
* Values: FOREGROUND, BACKGROUND
*/
internal enum class AppState(val value: String) {
@Json(name = "foreground")
FOREGROUND("foreground"),

@Json(name = "background")
BACKGROUND("background")
}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import io.embrace.android.embracesdk.injection.EssentialServiceModule
import io.embrace.android.embracesdk.injection.InitModule
import io.embrace.android.embracesdk.injection.OpenTelemetryModule
import io.embrace.android.embracesdk.injection.PayloadModule
import io.embrace.android.embracesdk.injection.SdkObservabilityModule
import io.embrace.android.embracesdk.injection.SessionModule
import io.embrace.android.embracesdk.injection.StorageModule
import io.embrace.android.embracesdk.injection.SystemServiceModule
Expand Down Expand Up @@ -129,15 +128,6 @@ internal typealias AnrModuleSupplier = (
otelModule: OpenTelemetryModule
) -> AnrModule

/**
* Function that returns an instance of [SdkObservabilityModule]. Matches the signature of the constructor for [SdkObservabilityModuleImpl]
*/

internal typealias SdkObservabilityModuleSupplier = (
initModule: InitModule,
essentialServiceModule: EssentialServiceModule
) -> SdkObservabilityModule

/**
* Function that returns an instance of [CustomerLogModule]. Matches the signature of the constructor for [CustomerLogModuleImpl]
*/
Expand Down Expand Up @@ -207,7 +197,6 @@ internal typealias SessionModuleSupplier = (
deliveryModule: DeliveryModule,
dataCaptureServiceModule: DataCaptureServiceModule,
customerLogModule: CustomerLogModule,
sdkObservabilityModule: SdkObservabilityModule,
workerThreadModule: WorkerThreadModule,
dataSourceModule: DataSourceModule,
payloadModule: PayloadModule,
Expand Down Expand Up @@ -244,7 +233,6 @@ internal typealias PayloadModuleSupplier = (
workerThreadModule: WorkerThreadModule,
nativeModule: NativeModule,
otelModule: OpenTelemetryModule,
sdkObservabilityModule: SdkObservabilityModule,
sessionPropertiesServiceProvider: Provider<SessionPropertiesService>,
) -> PayloadModule

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package io.embrace.android.embracesdk.logging
import io.embrace.android.embracesdk.config.ConfigService
import io.embrace.android.embracesdk.internal.clock.Clock
import io.embrace.android.embracesdk.payload.LegacyExceptionError
import io.embrace.android.embracesdk.session.lifecycle.ProcessStateService

/**
* Intercepts Embrace SDK's exceptions errors and forwards them to the Embrace API.
*/
internal class EmbraceInternalErrorService(
private val processStateService: ProcessStateService,
private val clock: Clock
) : InternalErrorService {

Expand All @@ -20,7 +18,6 @@ internal class EmbraceInternalErrorService(
if (configService == null || configService?.dataCaptureEventBehavior?.isInternalExceptionCaptureEnabled() == true) {
err.addException(
throwable,
getApplicationState(),
clock
)
}
Expand All @@ -36,22 +33,4 @@ internal class EmbraceInternalErrorService(
override fun cleanCollections() {
err = LegacyExceptionError()
}

private fun getApplicationState(): String = when {
processStateService.isInBackground -> APPLICATION_STATE_BACKGROUND
else -> APPLICATION_STATE_FOREGROUND
}

companion object {

/**
* Signals to the API that the application was in the foreground.
*/
private const val APPLICATION_STATE_FOREGROUND = "foreground"

/**
* Signals to the API that the application was in the background.
*/
private const val APPLICATION_STATE_BACKGROUND = "background"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ internal data class LegacyExceptionError(
* For each exceptions, occurrences is incremented by 1.
*
* @param ex the exception error.
* @param appState (foreground or background).
*/
fun addException(ex: Throwable?, appState: String?, clock: Clock) {
fun addException(ex: Throwable?, clock: Clock) {
occurrences++
if (exceptionErrors.size < DEFAULT_EXCEPTION_ERROR_LIMIT) {
exceptionErrors.add(
LegacyExceptionErrorInfo(
clock.now(),
appState,
getExceptionInfo(ex)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,14 @@ internal data class LegacyExceptionErrorInfo(
*/
@Json(name = "ts") val timestamp: Long? = null,

/**
* App state (foreground or background).
*/
@Json(name = "s") val state: String? = null,

/**
* A list of exceptions.
*/
@Json(name = "ex") val exceptions: List<LegacyExceptionInfo>? = null

) {
fun toNewPayload(): ExceptionErrorInfo {
val mappedState = when (state) {
"background" -> ExceptionErrorInfo.AppState.BACKGROUND
else -> ExceptionErrorInfo.AppState.FOREGROUND
}
return ExceptionErrorInfo(
timestamp,
mappedState,
exceptions?.map(LegacyExceptionInfo::toNewPayload)
)
}
fun toNewPayload(): ExceptionErrorInfo = ExceptionErrorInfo(
timestamp,
exceptions?.map(LegacyExceptionInfo::toNewPayload)
)
}

0 comments on commit 04ad926

Please sign in to comment.