Timber

The sentry-android-timber library provides Timber support for Sentry via Timber Tree that sends events and breadcrumbs to Sentry. Once this integration is configured you can use Timber’s static API.

The source can be found on GitHub.

Install

To add the Timber integration, manually initialize the Android SDK, then add the sentry-android-timber dependency. Using Gradle:

Copied
implementation 'io.sentry:sentry-android:7.13.0'
implementation 'io.sentry:sentry-android-timber:7.13.0'

Configure

Configuration should happen as early as possible in your application's lifecycle.

Copied
import io.sentry.android.core.SentryAndroid
import io.sentry.android.timber.SentryTimberIntegration
import timber.log.Timber
// import BuildConfig

SentryAndroid.init(this) { options ->
  if (!BuildConfig.DEBUG) {

    // default values:
    // minEventLevel = ERROR
    // minBreadcrumbLevel = INFO
    options.addIntegration(
      SentryTimberIntegration(
        minEventLevel = SentryLevel.ERROR,
        minBreadcrumbLevel = SentryLevel.INFO
      )
    )
  } else {
    Timber.plant(Timber.DebugTree())
  }
}

Verify

This snippet includes a HTTP Request and captures an intentional message, so you can test that everything is working as soon as you set it up:

Copied
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exception
import timber.log.Timber

class MyActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    try {
      throw Exception("This is a test.")
    } catch (e: Exception) {
      Timber.e(e);
    }
  }
}

To view and resolve the recorded message, log into sentry.io and open your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.