The sentry-spring library provides Spring MVC support for Sentry via:

  • a HandlerExceptionResolver that sends unhandled exceptions to Sentry.
  • attaches HTTP request information to all SentryEvents recorded within the scope of the request
  • adds option to attach user information retrieved from HTTP request to all SentryEvents recorded within the scope of the request
  • adds a SentryUserProvider hook that can be used to provide additional user information

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 @EnableSentry annotation that registers all required Spring beans. @EnableSentry can be placed on any class annotated with @Configuration including main entry class in Spring Boot applications annotated with @SpringBootApplication.

import io.sentry.spring.EnableSentry;
// NOTE: Replace the test DSN below with YOUR OWN DSN to see the events from this app in your Sentry
// project/dashboard
@EnableSentry(dsn = "https://examplePublicKey@o0.ingest.sentry.io/0")
class SentryConfiguration {

The DSN can be also provided through the system property sentry.dsn, environment variable SENTRY_DSN or the dsn property in sentry.properties file. See the configuration page for more details on external configuration.

Recording User Information From HTTP Request

In order to record user's IP address and Principal#name as the username, sending personal information flag has to be set to true.

import io.sentry.spring.EnableSentry;

@EnableSentry(dsn = "https://examplePublicKey@o0.ingest.sentry.io/0", sendDefaultPii = true)
class SentryConfiguration {

Recording Custom User Information

In order to record custom user information, you can register a bean that implements SentryUserProvider interface.

import org.springframework.stereotype.Component;
import io.sentry.core.protocol.User;
import io.sentry.spring.SentryUserProvider;

class CustomSentryUserProvider implements SentryUserProvider {
    public User provideUser() {
        User user = User();
        // ... set user information
        return user
You can edit this page on GitHub.