The sentry-spring library provides Spring support for Sentry via a HandlerExceptionResolver that sends exceptions to Sentry. Once this integration is configured you can also use Sentry’s static API, as shown on the usage page, in order to do things like record breadcrumbs, set the current user, or manually send events.

The source can be found on GitHub.

Important Note About Logging Integrations

Note that you should not configure sentry-spring alongside a Sentry logging integration (such as sentry-logback), or you will most likely double-report exceptions.

A Sentry logging integration is more general and will capture errors (and possibly warnings, depending on your configuration) that occur inside or outside of a Spring controller. In most scenarios, using one of the logging integrations instead of sentry-spring is preferred.


Using Maven:


Using Gradle:

compile 'io.sentry:sentry-spring:1.7.16'

Using SBT:

libraryDependencies += "io.sentry" % "sentry-spring" % "1.7.16"

For other dependency managers see the central Maven repository.


The sentry-spring library provides two classes that can be enabled by registering them as Beans in your Spring application.

Recording Exceptions

In order to record all exceptions thrown by your controllers, you can register io.sentry.spring.SentryExceptionResolver as a Bean in your application. Once registered, all exceptions will be sent to Sentry and then passed on to the default exception handlers.

Configuration via web.xml:

<bean class="io.sentry.spring.SentryExceptionResolver"/>

Or via a configuration class:

public HandlerExceptionResolver sentryExceptionResolver() {
    return new io.sentry.spring.SentryExceptionResolver();

Next, you’ll need to configure your DSN (client key) and optionally other values such as environment and release. See the configuration page for ways you can do this.

Spring Boot HTTP Data

Spring Boot doesn’t automatically load any javax.servlet.ServletContainerInitializer, which means the Sentry SDK doesn’t have an opportunity to hook into the request cycle to collect information about the HTTP request. In order to add HTTP request data to your Sentry events in Spring Boot, you need to register the io.sentry.spring.SentryServletContextInitializer class as a Bean in your application.

Configuration via web.xml:

<bean class="io.sentry.spring.SentryServletContextInitializer"/>

Or via a configuration class:

public ServletContextInitializer sentryServletContextInitializer() {
    return new io.sentry.spring.SentryServletContextInitializer();

After that, your Sentry events should contain information such as HTTP request headers.