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.



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

DSNThe Data Source Name (DSN) key tells the Sentry SDK where to send events, ensuring they go to the right project.
(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.

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").
Suggest an edit to this page   |  Contribute to Docs   |  

Report a Problem

🎉 Thank you for your feedback! 🙌
Report a problem