Commit 3bf4bbcc authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Updated sentry

parent de125676
......@@ -150,7 +150,7 @@ dependencies {
implementation "androidx.room:room-coroutines:2.1.0-alpha04"
testImplementation "androidx.room:room-testing:$room_version"
implementation 'io.sentry:sentry-android:1.7.30'
implementation 'io.sentry:sentry-android:2.2.0'
implementation 'com.github.jorgecastilloprz:fabprogresscircle:1.01@aar'
implementation 'com.squareup.leakcanary:leaksentry:2.0-alpha-3'
......
......@@ -7,10 +7,10 @@ import androidx.fragment.app.Fragment
import com.frostnerd.smokescreen.database.AppDatabase
import com.frostnerd.smokescreen.database.EXECUTED_MIGRATIONS
import com.frostnerd.smokescreen.util.preferences.Crashreporting
import io.sentry.Sentry
import io.sentry.event.Event
import io.sentry.event.EventBuilder
import io.sentry.event.interfaces.ExceptionInterface
import io.sentry.core.Sentry
import io.sentry.core.SentryEvent
import io.sentry.core.SentryLevel
import io.sentry.core.protocol.Message
import leakcanary.LeakSentry
import java.io.*
import java.text.SimpleDateFormat
......@@ -48,30 +48,33 @@ private fun Context.logErrorSentry(e: Throwable, extras: Map<String, String>? =
}
} || publishedExceptions.put(e, e.stackTrace.toHashSet()) != null) return
else {
Sentry.getContext().addExtra("database_migrations", EXECUTED_MIGRATIONS.sortedBy { it.first }.joinToString {
EXECUTED_MIGRATIONS.sortedBy { it.first }.joinToString {
"${it.first} -> ${it.second}"
})
}.takeIf { it.isNotBlank() }?.apply {
Sentry.setExtra("database_migrations", this)
}
if (e is OutOfMemoryError) {
EventBuilder().withMessage(e.message)
.withLevel(Event.Level.ERROR)
.withExtra("retainedInstanceCount", LeakSentry.refWatcher.retainedInstanceCount)
.withSentryInterface(ExceptionInterface(e)).build().apply {
Sentry.capture(this)
Sentry.captureEvent(SentryEvent(e).apply {
message = Message().apply {
this.message = e.message
}
level = SentryLevel.ERROR
setExtra("retainedInstanceCount", LeakSentry.refWatcher.retainedInstanceCount)
})
} else if (getPreferences().crashreportingType == Crashreporting.FULL && extras != null && extras.isNotEmpty()) {
// Extra data is only passed when not in data-saving mode.
EventBuilder().withMessage(e.message)
.withLevel(Event.Level.ERROR)
.apply {
extras.forEach { (key, value) ->
withExtra(key, value)
}
Sentry.captureEvent(SentryEvent(e).apply {
message = Message().apply {
this.message = e.message
}
.withSentryInterface(ExceptionInterface(e)).build().apply {
Sentry.capture(this)
level = SentryLevel.ERROR
extras.forEach { (key, value) ->
setTag(key, value)
}
setExtra("retainedInstanceCount", LeakSentry.refWatcher.retainedInstanceCount)
})
} else {
Sentry.capture(e)
Sentry.captureException(e)
}
}
}
......
......@@ -12,12 +12,15 @@ import com.frostnerd.smokescreen.activity.PinActivity
import com.frostnerd.smokescreen.database.AppDatabase
import com.frostnerd.smokescreen.util.Notifications
import com.frostnerd.smokescreen.util.RequestCodes
import com.frostnerd.smokescreen.util.crashhelpers.DatasavingSentryEventHelper
import com.frostnerd.smokescreen.util.crashhelpers.DataSavingSentryEventProcessor
import com.frostnerd.smokescreen.util.preferences.AppSettings
import com.frostnerd.smokescreen.util.preferences.Crashreporting
import io.sentry.Sentry
import io.sentry.android.AndroidSentryClientFactory
import io.sentry.event.User
import io.sentry.android.core.*
import io.sentry.core.Integration
import io.sentry.core.Sentry
import io.sentry.core.SentryOptions
import io.sentry.core.UncaughtExceptionHandlerIntegration
import io.sentry.core.protocol.User
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
......@@ -117,54 +120,53 @@ class SmokeScreen : Application() {
// This passes some device-related data, but nothing which allows user actions to be tracked across the app
// Info: Some data is attached by the AndroidEventBuilderHelper class, which is present by default
Sentry.init(
BuildConfig.SENTRY_DSN,
AndroidSentryClientFactory(this@SmokeScreen)
)
Sentry.getContext().user =
User(getPreferences().crashReportingUUID, null, null, null)
Sentry.getStoredClient().apply {
addTag("user.language", Locale.getDefault().displayLanguage)
addTag("app.database_version", AppDatabase.currentVersion.toString())
addTag("app.dns_server_name", getPreferences().dnsServerConfig.name)
addTag(
"app.dns_server_primary",
getPreferences().dnsServerConfig.servers[0].address.formatToString()
)
addTag(
"app.dns_server_secondary",
getPreferences().dnsServerConfig.servers.getOrNull(1)?.address?.formatToString()
)
addTag(
"app.installer_package",
packageManager.getInstallerPackageName(packageName)
)
addTag("richdata", "true")
addTag("app.fromCi", BuildConfig.FROM_CI.toString())
addTag("app.commit", BuildConfig.COMMIT_HASH)
SentryAndroid.init(this@SmokeScreen) {
it.dsn = BuildConfig.SENTRY_DSN
}
Sentry.setUser(User().apply {
this.username = getPreferences().crashReportingUUID
})
Sentry.setTag("user.language", Locale.getDefault().displayLanguage)
Sentry.setTag(
"app.database_version",
AppDatabase.currentVersion.toString()
)
Sentry.setTag(
"app.dns_server_name",
getPreferences().dnsServerConfig.name
)
Sentry.setTag(
"app.dns_server_primary",
getPreferences().dnsServerConfig.servers[0].address.formatToString()
)
Sentry.setTag(
"app.dns_server_secondary",
getPreferences().dnsServerConfig.servers.getOrNull(1)?.address?.formatToString()
?: ""
)
Sentry.setTag(
"app.installer_package",
packageManager.getInstallerPackageName(packageName) ?: ""
)
Sentry.setTag("richdata", "true")
Sentry.setTag("app.fromCi", BuildConfig.FROM_CI.toString())
Sentry.setTag("app.commit", BuildConfig.COMMIT_HASH)
sentryReady = true
} else if (enabledType == Crashreporting.MINIMAL || forceStatus == Status.DATASAVING) {
// Inits Sentry in datasaving mode
// Only data absolutely necessary is transmitted (Android version, app version).
// Only crashes will be reported, no regular events.
Sentry.init(
BuildConfig.SENTRY_DSN,
AndroidSentryClientFactory(this@SmokeScreen)
)
Sentry.getContext().user =
User("anon-" + BuildConfig.VERSION_CODE, null, null, null)
Sentry.getStoredClient().apply {
addTag("richdata", "false")
addTag("dist", BuildConfig.VERSION_CODE.toString())
addTag("app.commit", BuildConfig.COMMIT_HASH)
addTag("app.fromCi", BuildConfig.FROM_CI.toString())
addExtra("dist", BuildConfig.VERSION_CODE)
this.builderHelpers.forEach {
this.removeBuilderHelper(it)
}
this.addBuilderHelper(DatasavingSentryEventHelper())
SentryAndroid.init(this@SmokeScreen) {
it.dsn = BuildConfig.SENTRY_DSN
setupSentryForDatasaving(it)
}
Sentry.setUser(User().apply {
this.username = "anon-" + BuildConfig.VERSION_CODE
})
Sentry.setTag("richdata", "false")
Sentry.setTag("dist", BuildConfig.VERSION_CODE.toString())
Sentry.setTag("app.commit", BuildConfig.COMMIT_HASH)
Sentry.setTag("app.fromCi", BuildConfig.FROM_CI.toString())
sentryReady = true
}
}
......@@ -175,6 +177,21 @@ class SmokeScreen : Application() {
}
}
private fun setupSentryForDatasaving(sentryOptions: SentryOptions) {
val remove = mutableListOf<Integration>()
sentryOptions.integrations.forEach {
if (it is PhoneStateBreadcrumbsIntegration ||
it is SystemEventsBreadcrumbsIntegration ||
it is TempSensorBreadcrumbsIntegration ||
it is AppComponentsBreadcrumbsIntegration ||
it is SystemEventsBreadcrumbsIntegration ||
it is AppLifecycleIntegration
) remove.add(it)
}
remove.forEach { sentryOptions.integrations.remove(it) }
sentryOptions.eventProcessors.add(DataSavingSentryEventProcessor())
}
override fun onLowMemory() {
super.onLowMemory()
log("The system seems to have low memory")
......
......@@ -2,8 +2,10 @@ package com.frostnerd.smokescreen.util.crashhelpers
import android.os.Build
import com.frostnerd.smokescreen.BuildConfig
import io.sentry.event.EventBuilder
import io.sentry.event.helper.EventBuilderHelper
import io.sentry.core.*
import io.sentry.core.protocol.App
import io.sentry.core.protocol.Device
import io.sentry.core.protocol.OperatingSystem
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
......@@ -23,27 +25,22 @@ import io.sentry.event.helper.EventBuilderHelper
*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class DatasavingSentryEventHelper :EventBuilderHelper {
class DataSavingSentryEventProcessor:EventProcessor {
override fun helpBuildingEvent(eventBuilder: EventBuilder) {
eventBuilder.withDist(BuildConfig.VERSION_CODE.toString())
eventBuilder.withRelease("com.frostnerd.smokescreen-" + BuildConfig.VERSION_NAME)
eventBuilder.withContexts(contexts)
}
private val contexts = mutableMapOf<String, MutableMap<String, Any>>()
init {
val osMap = mutableMapOf<String, Any>()
val appMap = mutableMapOf<String, Any>()
osMap["name"] = "Android"
osMap["version"] = Build.VERSION.RELEASE
osMap["build"] = Build.DISPLAY
appMap["app_version"] = BuildConfig.VERSION_NAME
appMap["app_identifier"] = "com.frostnerd.smokescreen"
appMap["app_build"] = BuildConfig.VERSION_CODE
contexts["os"] = osMap
contexts["app"] = appMap
override fun process(event: SentryEvent, hint: Any?): SentryEvent? {
event.contexts.device = Device()
event.contexts.app = App().apply {
appVersion = BuildConfig.VERSION_NAME
appIdentifier = "com.frostnerd.smokescreen"
appName = "Nebulo"
appBuild = BuildConfig.VERSION_CODE.toString()
}
event.contexts.operatingSystem = OperatingSystem().apply {
name = "Android"
version = Build.VERSION.RELEASE
build = Build.DISPLAY
}
event.dist = BuildConfig.VERSION_CODE.toString()
return event
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment