diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt index 57a23005b8..205828cba7 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlin.time.measureTime sealed interface CoreFailure { @@ -371,12 +372,20 @@ internal inline fun wrapE2EIRequest(e2eiRequest: () -> T): Either wrapStorageRequest(storageRequest: () -> T?): Either { - val result = try { - storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound) - } catch (e: Exception) { - Either.Left(StorageFailure.Generic(e)) + val result: Either + measureTime { + result = try { + storageRequest()?.let { data -> Either.Right(data) } ?: Either.Left(StorageFailure.DataNotFound) + } catch (e: Exception) { + Either.Left(StorageFailure.Generic(e)) + } + result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } + }.run { + // Log error for requests longer than 1 second + if (inWholeSeconds > 1) { + kaliumLogger.e("storage request timeMs: $inWholeMilliseconds") + } } - result.onFailure { storageFailure -> kaliumLogger.e(storageFailure.toString()) } return result }