feat: auto downgrade environmental issues to warnings
This commit is contained in:
1 parent
6cf083d73b
commit
1d7c98d0cb
2 files changed
+28
No files matched your search
@@ -13,10 +13,12 @@ import com.google.firebase.crashlytics.CustomKeysAndValues
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.google.firebase.crashlytics.crashlytics
|
||||
import eu.depau.etchdroid.BuildConfig
|
||||
import eu.depau.etchdroid.utils.exception.base.isEnvironmentalFault
|
||||
import io.sentry.Breadcrumb
|
||||
import io.sentry.IScope
|
||||
import io.sentry.Sentry
|
||||
import io.sentry.SentryLevel
|
||||
import io.sentry.SentryOptions
|
||||
import io.sentry.android.core.SentryAndroid
|
||||
import io.sentry.compose.SentryModifier.sentryTag
|
||||
import io.sentry.compose.SentryTraced
|
||||
@@ -162,6 +164,18 @@ object Telemetry : ITelemetry {
|
||||
it.profilesSampleRate = SAMPLE_RATE
|
||||
it.sessionReplay.sessionSampleRate = SAMPLE_RATE
|
||||
it.sessionReplay.onErrorSampleRate = ERROR_SAMPLE_RATE
|
||||
|
||||
// Recoverable, environmental failures (USB stalls/unplugs, init
|
||||
// failures, libusb errors) aren't app bugs: keep them for
|
||||
// visibility but downgrade to WARNING + tag so they don't pollute
|
||||
// the error page.
|
||||
it.beforeSend = SentryOptions.BeforeSendCallback { event, _ ->
|
||||
if (event.throwable.isEnvironmentalFault()) {
|
||||
event.level = SentryLevel.WARNING
|
||||
event.setTag("recoverable", "true")
|
||||
}
|
||||
event
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
|
||||
@@ -9,3 +9,17 @@ abstract class RecoverableException(message: String, cause: Throwable? = null) :
|
||||
|
||||
val RecoverableException.isUnplugged: Boolean
|
||||
get() = rootCause is LibusbException && (rootCause as LibusbException).libusbError == LibusbError.NO_DEVICE
|
||||
|
||||
/**
|
||||
* A known non-app-fault: a recoverable EtchDroid error or a libusb hardware error
|
||||
* anywhere in the cause chain. Used to de-prioritize such failures in telemetry.
|
||||
*/
|
||||
fun Throwable?.isEnvironmentalFault(): Boolean {
|
||||
var t = this
|
||||
val seen = HashSet<Throwable>()
|
||||
while (t != null && seen.add(t)) {
|
||||
if (t is RecoverableException || t is LibusbException) return true
|
||||
t = t.cause
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in new issue
Block a user