No issue: Add Sentry breadcrumbs to ease crash investigations

nightly-build-test
Colin Lee 5 years ago committed by Jeff Boek
parent e1e4c7c1f9
commit ea7841b8c5

@ -12,9 +12,13 @@ import android.view.View
import androidx.annotation.IdRes
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import io.sentry.Sentry
import io.sentry.event.Breadcrumb
import io.sentry.event.BreadcrumbBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -28,6 +32,7 @@ import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.ktx.kotlin.isUrl
import mozilla.components.support.ktx.kotlin.toNormalizedUrl
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.components.isSentryEnabled
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
@ -55,10 +60,47 @@ open class HomeActivity : AppCompatActivity() {
lateinit var browsingModeManager: BrowsingModeManager
private val onDestinationChangedListener = NavController.OnDestinationChangedListener { _, dest, _ ->
val fragmentName = resources.getResourceEntryName(dest.id)
Sentry.getContext().recordBreadcrumb(
BreadcrumbBuilder()
.setCategory("DestinationChanged")
.setMessage("Changing to fragment $fragmentName, isCustomTab: $isCustomTab")
.setLevel(Breadcrumb.Level.INFO)
.build()
)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
components.publicSuffixList.prefetch()
setupThemeAndBrowsingMode()
setContentView(R.layout.activity_home)
setupToolbarAndNavigation()
if (Settings.getInstance(this).isTelemetryEnabled && isSentryEnabled()) {
navHost.navController.addOnDestinationChangedListener(onDestinationChangedListener)
}
intent
?.let { SafeIntent(it) }
?.let {
when {
isCustomTab -> Event.OpenedApp.Source.CUSTOM_TAB
it.isLauncherIntent -> Event.OpenedApp.Source.APP_ICON
it.action == Intent.ACTION_VIEW -> Event.OpenedApp.Source.LINK
else -> null
}
}
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
handleOpenedFromExternalSourceIfNecessary(intent)
}
private fun setupThemeAndBrowsingMode() {
browsingModeManager = createBrowsingModeManager()
themeManager = createThemeManager(
when (browsingModeManager.isPrivate) {
@ -66,12 +108,11 @@ open class HomeActivity : AppCompatActivity() {
false -> ThemeManager.Theme.Normal
}
)
setTheme(themeManager.currentTheme)
ThemeManager.applyStatusBarTheme(window, themeManager, this)
}
setContentView(R.layout.activity_home)
private fun setupToolbarAndNavigation() {
// Add ids to this that we don't want to have a toolbar back button
val appBarConfiguration = AppBarConfiguration.Builder().build()
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar)
@ -81,24 +122,11 @@ open class HomeActivity : AppCompatActivity() {
onBackPressed()
}
supportActionBar?.hide()
intent
?.let { SafeIntent(it) }
?.let {
when {
isCustomTab -> Event.OpenedApp.Source.CUSTOM_TAB
it.isLauncherIntent -> Event.OpenedApp.Source.APP_ICON
it.action == Intent.ACTION_VIEW -> Event.OpenedApp.Source.LINK
else -> null
}
}
?.also { components.analytics.metrics.track(Event.OpenedApp(it)) }
handleOpenedFromExternalSourceIfNecessary(intent)
}
override fun onDestroy() {
sessionObserver?.let { components.core.sessionManager.unregister(it) }
navHost.navController.removeOnDestinationChangedListener(onDestinationChangedListener)
super.onDestroy()
}

@ -34,7 +34,7 @@ class Analytics(
val crashReporter: CrashReporter by lazy {
val services = mutableListOf<CrashReporterService>()
if (!BuildConfig.SENTRY_TOKEN.isNullOrEmpty()) {
if (isSentryEnabled()) {
val sentryService = SentryService(
context,
BuildConfig.SENTRY_TOKEN,
@ -85,3 +85,5 @@ class Analytics(
)
}
}
fun isSentryEnabled() = !BuildConfig.SENTRY_TOKEN.isNullOrEmpty()

Loading…
Cancel
Save