Skip to content

Commit

Permalink
Implement shared local logging (#682)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Magda <ivan.magda@hyperskill.org>
  • Loading branch information
XanderZhu and ivan-magda authored Sep 29, 2023
1 parent c46f66b commit 59fe8f4
Show file tree
Hide file tree
Showing 56 changed files with 487 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hyperskill.app.android.sentry.domain.model.manager

import io.sentry.Sentry
import io.sentry.SentryLevel
import io.sentry.SpanStatus
import io.sentry.android.core.SentryAndroid
import io.sentry.android.fragment.FragmentLifecycleIntegration
Expand All @@ -18,7 +17,10 @@ import org.hyperskill.app.sentry.domain.model.manager.SentryManager
import org.hyperskill.app.sentry.domain.model.transaction.HyperskillSentryTransaction
import org.hyperskill.app.sentry.domain.model.transaction.HyperskillSentryTransactionKeyValues

class SentryManagerImpl(private val buildKonfig: BuildKonfig) : SentryManager {
class SentryManagerImpl(
private val buildKonfig: BuildKonfig,
private val minLogLevel: HyperskillSentryLevel = HyperskillSentryLevel.min(buildKonfig.buildVariant)
) : SentryManager {
private val currentTransactionsMap = mutableMapOf<Int, PlatformHyperskillSentryTransaction>()

override fun setup() {
Expand All @@ -35,10 +37,10 @@ class SentryManagerImpl(private val buildKonfig: BuildKonfig) : SentryManager {
enableAutoFragmentLifecycleTracing = true
)
)
options.setDiagnosticLevel(minLogLevel.toSentryLevel())

if (BuildConfig.DEBUG) {
options.setDebug(true)
options.setDiagnosticLevel(SentryLevel.WARNING)
options.tracesSampleRate = 1.0
} else {
options.setDebug(false)
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dokka = '1.7.20'
androidxLifecycle = "2.6.0-alpha01"
coil = '2.2.0'
lottie = '6.1.0'
kermit = '2.0.0-RC4'

kotlinCompilerExtension = "1.4.8"
composeBom = "2023.06.01"
Expand Down Expand Up @@ -56,6 +57,8 @@ kit-ui-adapters = { module = "ru.nobird.android.ui:adapters", version.ref = "ada

multiplatform-settings = { module = "com.russhwolf:multiplatform-settings", version = "0.8.1" }

kermit-common = { module = "co.touchlab:kermit", version.ref = "kermit" }

android-ui-material = { module = "com.google.android.material:material", version = "1.4.0" }
android-ui-appcompat = { module = "androidx.appcompat:appcompat", version = "1.4.0" }
android-ui-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version = "2.1.4" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ final class SentryManager: shared.SentryManager {

#if DEBUG
options.debug = true
options.diagnosticLevel = .info
options.diagnosticLevel = .debug

options.tracesSampleRate = 1
#else
options.tracesSampleRate = 0.3
options.diagnosticLevel = .info
#endif

// HTTP Client Errors
Expand Down
1 change: 1 addition & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ kotlin {
implementation(libs.kit.model)
implementation(libs.kotlin.datetime)
implementation(libs.kit.presentation.reduxCoroutines)
implementation(libs.kermit.common)

api(libs.kit.presentation.redux)
api(libs.mokoResources.main)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import org.hyperskill.app.auth.presentation.AuthSocialWebViewViewModel
import org.hyperskill.app.core.injection.ReduxViewModelFactory
import ru.nobird.app.presentation.redux.container.wrapWithViewContainer

class PlatformAuthSocialWebViewComponentImpl : PlatformAuthSocialWebViewComponent {
class PlatformAuthSocialWebViewComponentImpl(
private val authSocialComponent: AuthSocialComponent
) : PlatformAuthSocialWebViewComponent {

override val reduxViewModelFactory: ReduxViewModelFactory
get() = ReduxViewModelFactory(
mapOf(
AuthSocialWebViewViewModel::class.java to {
AuthSocialWebViewViewModel(
AuthSocialWebViewFeatureBuilder.build().wrapWithViewContainer()
authSocialComponent.authSocialWebViewFeature.wrapWithViewContainer()
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import org.hyperskill.app.track_selection.list.injection.TrackSelectionListParam
abstract class CommonAndroidAppGraphImpl : CommonAndroidAppGraph, BaseAppGraph() {

override fun buildPlatformAuthSocialWebViewComponent(): PlatformAuthSocialWebViewComponent =
PlatformAuthSocialWebViewComponentImpl()
PlatformAuthSocialWebViewComponentImpl(authSocialComponent = buildAuthSocialComponent())

/**
* Auth social component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.hyperskill.app.analytic.injection.AnalyticComponent
import org.hyperskill.app.auth.presentation.AuthCredentialsFeature
import org.hyperskill.app.auth.view.mapper.AuthCredentialsErrorMapper
import org.hyperskill.app.core.injection.CommonComponent
import org.hyperskill.app.logging.inject.LoggerComponent
import org.hyperskill.app.magic_links.injection.MagicLinksDataComponent
import org.hyperskill.app.profile.injection.ProfileDataComponent
import org.hyperskill.app.sentry.injection.SentryComponent
Expand All @@ -15,7 +16,8 @@ class AuthCredentialsComponentImpl(
private val profileDataComponent: ProfileDataComponent,
private val magicLinkComponent: MagicLinksDataComponent,
private val analyticComponent: AnalyticComponent,
private val sentryComponent: SentryComponent
private val sentryComponent: SentryComponent,
private val loggerComponent: LoggerComponent,
) : AuthCredentialsComponent {
override val authCredentialsFeature: Feature<
AuthCredentialsFeature.State, AuthCredentialsFeature.Message, AuthCredentialsFeature.Action>
Expand All @@ -24,7 +26,9 @@ class AuthCredentialsComponentImpl(
profileDataComponent.currentProfileStateRepository,
magicLinkComponent.urlPathProcessor,
analyticComponent.analyticInteractor,
sentryComponent.sentryInteractor
sentryComponent.sentryInteractor,
loggerComponent.logger,
commonComponent.buildKonfig.buildVariant
)

override val authCredentialsErrorMapper: AuthCredentialsErrorMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.hyperskill.app.auth.injection

import co.touchlab.kermit.Logger
import org.hyperskill.app.analytic.domain.interactor.AnalyticInteractor
import org.hyperskill.app.auth.domain.interactor.AuthInteractor
import org.hyperskill.app.auth.presentation.AuthCredentialsActionDispatcher
Expand All @@ -8,7 +9,9 @@ import org.hyperskill.app.auth.presentation.AuthCredentialsFeature.Action
import org.hyperskill.app.auth.presentation.AuthCredentialsFeature.Message
import org.hyperskill.app.auth.presentation.AuthCredentialsFeature.State
import org.hyperskill.app.auth.presentation.AuthCredentialsReducer
import org.hyperskill.app.core.domain.BuildVariant
import org.hyperskill.app.core.presentation.ActionDispatcherOptions
import org.hyperskill.app.logging.presentation.wrapWithLogger
import org.hyperskill.app.magic_links.domain.interactor.UrlPathProcessor
import org.hyperskill.app.profile.domain.repository.CurrentProfileStateRepository
import org.hyperskill.app.sentry.domain.interactor.SentryInteractor
Expand All @@ -17,12 +20,16 @@ import ru.nobird.app.presentation.redux.feature.Feature
import ru.nobird.app.presentation.redux.feature.ReduxFeature

object AuthCredentialsFeatureBuilder {
private const val LOG_TAG = "AuthCredentialsFeature"

fun build(
authInteractor: AuthInteractor,
currentProfileStateRepository: CurrentProfileStateRepository,
urlPathProcessor: UrlPathProcessor,
analyticInteractor: AnalyticInteractor,
sentryInteractor: SentryInteractor
sentryInteractor: SentryInteractor,
logger: Logger,
buildVariant: BuildVariant
): Feature<State, Message, Action> {
val authReducer = AuthCredentialsReducer()
val authActionDispatcher = AuthCredentialsActionDispatcher(
Expand All @@ -34,7 +41,9 @@ object AuthCredentialsFeatureBuilder {
sentryInteractor
)

return ReduxFeature(State("", "", AuthCredentialsFeature.FormState.Editing), authReducer)
.wrapWithActionDispatcher(authActionDispatcher)
return ReduxFeature(
State("", "", AuthCredentialsFeature.FormState.Editing),
authReducer.wrapWithLogger(buildVariant, logger, LOG_TAG)
).wrapWithActionDispatcher(authActionDispatcher)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package org.hyperskill.app.auth.injection

import org.hyperskill.app.auth.presentation.AuthSocialFeature
import org.hyperskill.app.auth.view.mapper.AuthSocialErrorMapper
import ru.nobird.app.presentation.redux.feature.Feature
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Action as AuthSocialAction
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Message as AuthSocialMessage
import org.hyperskill.app.auth.presentation.AuthSocialFeature.State as AuthSocialState
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Action as AuthSocialWebViewAction
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Message as AuthSocialWebViewMessage
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.State as AuthSocialWebViewState

interface AuthSocialComponent {
val authSocialFeature: Feature<AuthSocialFeature.State, AuthSocialFeature.Message, AuthSocialFeature.Action>
val authSocialFeature: Feature<AuthSocialState, AuthSocialMessage, AuthSocialAction>
val authSocialErrorMapper: AuthSocialErrorMapper
val authSocialWebViewFeature: Feature<AuthSocialWebViewState, AuthSocialWebViewMessage, AuthSocialWebViewAction>
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
package org.hyperskill.app.auth.injection

import org.hyperskill.app.analytic.injection.AnalyticComponent
import org.hyperskill.app.auth.presentation.AuthSocialFeature
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Action
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Message
import org.hyperskill.app.auth.presentation.AuthSocialFeature.State
import org.hyperskill.app.auth.view.mapper.AuthSocialErrorMapper
import org.hyperskill.app.core.injection.CommonComponent
import org.hyperskill.app.logging.inject.LoggerComponent
import org.hyperskill.app.profile.injection.ProfileDataComponent
import org.hyperskill.app.sentry.injection.SentryComponent
import ru.nobird.app.presentation.redux.feature.Feature
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Action as WebViewAction
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Message as WebViewMessage
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.State as WebViewState

class AuthSocialComponentImpl(
private val commonComponent: CommonComponent,
private val authComponent: AuthComponent,
private val profileDataComponent: ProfileDataComponent,
private val analyticComponent: AnalyticComponent,
private var sentryComponent: SentryComponent
private val sentryComponent: SentryComponent,
private val loggerComponent: LoggerComponent
) : AuthSocialComponent {
override val authSocialFeature: Feature<
AuthSocialFeature.State, AuthSocialFeature.Message, AuthSocialFeature.Action>
override val authSocialFeature: Feature<State, Message, Action>
get() = AuthSocialFeatureBuilder.build(
authComponent.authInteractor,
profileDataComponent.currentProfileStateRepository,
analyticComponent.analyticInteractor,
sentryComponent.sentryInteractor
sentryComponent.sentryInteractor,
loggerComponent.logger,
commonComponent.buildKonfig.buildVariant
)

override val authSocialErrorMapper: AuthSocialErrorMapper
get() = AuthSocialErrorMapper(commonComponent.resourceProvider)

override val authSocialWebViewFeature: Feature<WebViewState, WebViewMessage, WebViewAction>
get() = AuthSocialWebViewFeatureBuilder.build(
logger = loggerComponent.logger,
buildVariant = commonComponent.buildKonfig.buildVariant
)
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package org.hyperskill.app.auth.injection

import co.touchlab.kermit.Logger
import org.hyperskill.app.analytic.domain.interactor.AnalyticInteractor
import org.hyperskill.app.auth.domain.interactor.AuthInteractor
import org.hyperskill.app.auth.presentation.AuthSocialActionDispatcher
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Action
import org.hyperskill.app.auth.presentation.AuthSocialFeature.Message
import org.hyperskill.app.auth.presentation.AuthSocialFeature.State
import org.hyperskill.app.auth.presentation.AuthSocialReducer
import org.hyperskill.app.core.domain.BuildVariant
import org.hyperskill.app.core.presentation.ActionDispatcherOptions
import org.hyperskill.app.logging.presentation.wrapWithLogger
import org.hyperskill.app.profile.domain.repository.CurrentProfileStateRepository
import org.hyperskill.app.sentry.domain.interactor.SentryInteractor
import ru.nobird.app.presentation.redux.dispatcher.wrapWithActionDispatcher
import ru.nobird.app.presentation.redux.feature.Feature
import ru.nobird.app.presentation.redux.feature.ReduxFeature

object AuthSocialFeatureBuilder {
private const val LOG_TAG = "AuthSocialFeature"

fun build(
authInteractor: AuthInteractor,
currentProfileStateRepository: CurrentProfileStateRepository,
analyticInteractor: AnalyticInteractor,
sentryInteractor: SentryInteractor
sentryInteractor: SentryInteractor,
logger: Logger,
buildVariant: BuildVariant
): Feature<State, Message, Action> {
val authReducer = AuthSocialReducer()
val authActionDispatcher = AuthSocialActionDispatcher(
Expand All @@ -30,7 +37,9 @@ object AuthSocialFeatureBuilder {
sentryInteractor
)

return ReduxFeature(State.Idle, authReducer)
.wrapWithActionDispatcher(authActionDispatcher)
return ReduxFeature(
State.Idle,
authReducer.wrapWithLogger(buildVariant, logger, LOG_TAG)
).wrapWithActionDispatcher(authActionDispatcher)
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package org.hyperskill.app.auth.injection

import co.touchlab.kermit.Logger
import org.hyperskill.app.auth.presentation.AuthSocialWebViewActionDispatcher
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Action
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.Message
import org.hyperskill.app.auth.presentation.AuthSocialWebViewFeature.State
import org.hyperskill.app.auth.presentation.AuthSocialWebViewReducer
import org.hyperskill.app.core.domain.BuildVariant
import org.hyperskill.app.core.presentation.ActionDispatcherOptions
import org.hyperskill.app.logging.presentation.wrapWithLogger
import ru.nobird.app.presentation.redux.dispatcher.wrapWithActionDispatcher
import ru.nobird.app.presentation.redux.feature.Feature
import ru.nobird.app.presentation.redux.feature.ReduxFeature

object AuthSocialWebViewFeatureBuilder {
fun build(): Feature<State, Message, Action> {
private const val LOG_TAG = "AuthSocialWebViewFeature"

fun build(
logger: Logger,
buildVariant: BuildVariant
): Feature<State, Message, Action> {
val authReducer = AuthSocialWebViewReducer()
val authActionDispatcher = AuthSocialWebViewActionDispatcher(ActionDispatcherOptions())

return ReduxFeature(State.Idle, authReducer)
.wrapWithActionDispatcher(authActionDispatcher)
return ReduxFeature(
State.Idle,
authReducer.wrapWithLogger(buildVariant, logger, LOG_TAG)
).wrapWithActionDispatcher(authActionDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.hyperskill.app.home.injection.HomeComponent
import org.hyperskill.app.items.injection.ItemsDataComponent
import org.hyperskill.app.learning_activities.injection.LearningActivitiesDataComponent
import org.hyperskill.app.likes.injection.LikesDataComponent
import org.hyperskill.app.logging.inject.LoggerComponent
import org.hyperskill.app.magic_links.injection.MagicLinksDataComponent
import org.hyperskill.app.main.injection.MainComponent
import org.hyperskill.app.main.injection.MainDataComponent
Expand Down Expand Up @@ -71,6 +72,7 @@ import org.hyperskill.app.user_storage.injection.UserStorageComponent
interface AppGraph {
val commonComponent: CommonComponent
val networkComponent: NetworkComponent
val loggerComponent: LoggerComponent
val authComponent: AuthComponent
val mainComponent: MainComponent
val analyticComponent: AnalyticComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import org.hyperskill.app.learning_activities.injection.LearningActivitiesDataCo
import org.hyperskill.app.learning_activities.injection.LearningActivitiesDataComponentImpl
import org.hyperskill.app.likes.injection.LikesDataComponent
import org.hyperskill.app.likes.injection.LikesDataComponentImpl
import org.hyperskill.app.logging.inject.LoggerComponent
import org.hyperskill.app.logging.inject.LoggerComponentImpl
import org.hyperskill.app.magic_links.injection.MagicLinksDataComponent
import org.hyperskill.app.magic_links.injection.MagicLinksDataComponentImpl
import org.hyperskill.app.main.injection.MainComponent
Expand Down Expand Up @@ -138,6 +140,10 @@ abstract class BaseAppGraph : AppGraph {
NetworkComponentImpl(this)
}

override val loggerComponent: LoggerComponent by lazy {
LoggerComponentImpl(this)
}

override val submissionDataComponent: SubmissionDataComponent by lazy {
SubmissionDataComponentImpl(this)
}
Expand Down Expand Up @@ -201,7 +207,8 @@ abstract class BaseAppGraph : AppGraph {
authComponent,
profileDataComponent,
analyticComponent,
sentryComponent
sentryComponent,
loggerComponent
)

/**
Expand All @@ -214,7 +221,8 @@ abstract class BaseAppGraph : AppGraph {
profileDataComponent,
buildMagicLinksDataComponent(),
analyticComponent,
sentryComponent
sentryComponent,
loggerComponent
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class DebugComponentImpl(private val appGraph: AppGraph) : DebugComponent {
override val debugFeature: Feature<DebugFeature.ViewState, DebugFeature.Message, DebugFeature.Action>
get() = DebugFeatureBuilder.build(
debugInteractor,
appGraph.buildMainDataComponent().appInteractor
appGraph.buildMainDataComponent().appInteractor,
appGraph.loggerComponent.logger,
appGraph.commonComponent.buildKonfig.buildVariant
)
}
Loading

0 comments on commit 59fe8f4

Please sign in to comment.