-
Notifications
You must be signed in to change notification settings - Fork 1
Introduce crashlogging / Sentry
#109
Changes from all commits
fe1de08
248dc1f
7cffc1c
f672f18
eb5826b
ef87a6c
f1595f3
25e9146
f27f8cb
791097c
c5383e7
a0f1392
0399e57
f376c13
2159ba2
d90ac40
8ec849a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import java.util.Properties | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.gravatar.android.library) | ||
| alias(libs.plugins.kotlin.android) | ||
| } | ||
|
|
||
| fun secretsProperties(): Properties { | ||
| return rootProject.extra["secretsProperties"] as Properties | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.gravatar.crashlogging" | ||
| buildFeatures.buildConfig = true | ||
|
|
||
| defaultConfig { | ||
| buildConfigField( | ||
| "String", | ||
| "SENTRY_DSN", | ||
| "\"${secretsProperties()["sentryDsn"]?.toString() ?: ""}\"", | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":userComponent")) | ||
|
|
||
| implementation(libs.koin.core) | ||
| implementation(libs.koin.android) | ||
| implementation(libs.kotlinx.coroutines) | ||
| implementation(libs.androidx.core.ktx) | ||
|
|
||
| api(libs.automattic.crashlogging) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.gravatar.crashlogging | ||
|
|
||
| import android.app.Application | ||
| import androidx.core.os.ConfigurationCompat | ||
| import java.util.Locale | ||
|
|
||
| internal class ContextBasedLocaleProvider( | ||
| private val context: Application, | ||
| ) : LocaleProvider { | ||
| override fun provideLocale(): Locale? { | ||
| return ConfigurationCompat.getLocales(context.resources.configuration)[0] | ||
wzieba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.gravatar.crashlogging | ||
|
|
||
| import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider | ||
| import com.automattic.android.tracks.crashlogging.CrashLoggingUser | ||
| import com.automattic.android.tracks.crashlogging.EventLevel | ||
| import com.automattic.android.tracks.crashlogging.ExtraKnownKey | ||
| import com.automattic.android.tracks.crashlogging.PerformanceMonitoringConfig | ||
| import com.automattic.android.tracks.crashlogging.ReleaseName | ||
| import com.gravatar.app.usercomponent.domain.repository.UserRepository | ||
| import kotlinx.coroutines.flow.emptyFlow | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| internal class GravatarCrashLoggingDataProvider( | ||
| localeProvider: LocaleProvider, | ||
| userRepository: UserRepository | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm aware that this can circular DI dependency if
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although not ideal and I would imagine pushing the new profile (or rather
I assume that fatal crashes are reported automatically. So that would only be needed if we wanted to report non-fatal ones, correct?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I get you, but I also like the reactiveness of this solution - it'd be great if code related to
True, you're correct! 👍 |
||
| ) : CrashLoggingDataProvider { | ||
|
|
||
| override val applicationContextProvider = emptyFlow<Map<String, String>>() | ||
|
|
||
| override val buildType = BuildConfig.BUILD_TYPE | ||
|
|
||
| override val enableCrashLoggingLogs = BuildConfig.DEBUG | ||
|
|
||
| override val locale = localeProvider.provideLocale() | ||
|
|
||
| override val performanceMonitoringConfig = PerformanceMonitoringConfig.Disabled | ||
|
|
||
| override val releaseName = if (BuildConfig.DEBUG) { | ||
| ReleaseName.SetByApplication(DEBUG_RELEASE_NAME) | ||
| } else { | ||
| ReleaseName.SetByTracksLibrary | ||
| } | ||
|
|
||
| override val sentryDSN = BuildConfig.SENTRY_DSN | ||
|
|
||
| override val user = userRepository.getProfile().map { profile -> | ||
| CrashLoggingUser( | ||
| userID = profile?.userId?.toString(), | ||
| email = profile?.hash, | ||
| username = profile?.displayName, | ||
| ) | ||
| } | ||
|
|
||
| override fun crashLoggingEnabled() = false | ||
|
|
||
| override fun extraKnownKeys() = emptyList<ExtraKnownKey>() | ||
|
|
||
| override fun provideExtrasForEvent( | ||
| currentExtras: Map<ExtraKnownKey, String>, | ||
| eventLevel: EventLevel | ||
| ) = emptyMap<ExtraKnownKey, String>() | ||
|
|
||
| override fun shouldDropWrappingException( | ||
| module: String, | ||
| type: String, | ||
| value: String | ||
| ) = false | ||
|
|
||
| companion object { | ||
| const val DEBUG_RELEASE_NAME = "debug" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.gravatar.crashlogging | ||
|
|
||
| import java.util.Locale | ||
|
|
||
| internal fun interface LocaleProvider { | ||
| fun provideLocale(): Locale? | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.gravatar.crashlogging.di | ||
|
|
||
| import com.automattic.android.tracks.crashlogging.CrashLoggingDataProvider | ||
| import com.automattic.android.tracks.crashlogging.CrashLoggingProvider | ||
| import com.gravatar.crashlogging.ContextBasedLocaleProvider | ||
| import com.gravatar.crashlogging.GravatarCrashLoggingDataProvider | ||
| import com.gravatar.crashlogging.LocaleProvider | ||
| import org.koin.android.ext.koin.androidApplication | ||
| import org.koin.core.module.dsl.bind | ||
| import org.koin.core.module.dsl.factoryOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val crashLoggingModule = module { | ||
| factory<LocaleProvider> { | ||
| ContextBasedLocaleProvider( | ||
| context = androidApplication() | ||
| ) | ||
| } | ||
| factoryOf(::GravatarCrashLoggingDataProvider) { | ||
| bind<CrashLoggingDataProvider>() | ||
| } | ||
| single { | ||
| CrashLoggingProvider.createInstance( | ||
| context = get(), | ||
| dataProvider = get(), | ||
| appScope = get() | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,4 @@ include(":clock") | |
| include(":design") | ||
| include(":networkMonitor") | ||
| include(":api") | ||
| include(":crashlogging") | ||
Uh oh!
There was an error while loading. Please reload this page.