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:5.0.1'
implementation 'io.sentry:sentry-android-timber:5.0.1'

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.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").