Connect Spring Framework to Bugsink

The Spring MVC integration reports unhandled controller exceptions with their parameterized route, HTTP request, breadcrumb, and application stack.

This guide adds the integration to a Spring Framework 7 application and triggers a deliberate controller failure. To follow along, create a Bugsink project and copy its DSN from the project setup page.

Install the Spring integration

Add the open-source Spring 7 integration to your Maven project. Bugsink accepts the Sentry event protocol, so the SDK can send events directly to your Bugsink project:

<dependency>
  <groupId>io.sentry</groupId>
  <artifactId>sentry-spring-7</artifactId>
  <version>${sentry.version}</version>
</dependency>

Spring Framework 6 applications use sentry-spring-jakarta; Spring 5 uses sentry-spring. The configuration below follows the same shape, with imports from that integration’s package.

Enable Bugsink in Spring MVC

Add @EnableSentry to a Spring configuration class. The annotation creates the SDK and registers Spring’s exception resolver, which sees exceptions that leave a controller while allowing the rest of Spring’s error handling to continue:

package com.example.inventory;

import io.sentry.spring7.EnableSentry;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@ComponentScan(basePackageClasses = InventoryController.class)
@EnableSentry
public class InventoryConfiguration {}

Set SENTRY_DSN to the DSN shown by your Bugsink project when the application starts:

export SENTRY_DSN=https://key@bugsink.example/1

Mark your package as application code in src/main/resources/sentry.properties. This lets Bugsink distinguish the controller frame from framework internals:

in-app-includes=com.example.inventory

Keep request details with the error

The integration’s servlet filter gives each request its own SDK scope and adds the URL, method, safe headers, and HTTP breadcrumb to events from that request. A normally deployed servlet application discovers the filter automatically.

If your application creates its servlet context entirely in code, register the same filter when you create that context. This embedded Jetty service does so before adding Spring’s dispatcher servlet:

context.addFilter(
        SentrySpringFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
context.addServlet(new ServletHolder(new DispatcherServlet(applicationContext)), "/");

Send a test error

Temporarily throw an exception in a controller action you can request. The controller needs no Bugsink-specific call: the registered exception resolver captures the failure as it leaves Spring MVC.

if (!INVENTORY.containsKey(sku)) {
    throw new ProductNotFound("Product " + sku + " is not in inventory");
}

Build and start the application with its DSN, then request that action once:

mvn package
java -jar target/inventory-spring-framework-1.0.0.jar
:::bash
curl http://127.0.0.1:8080/checkout/spring-missing

The request still follows Spring MVC’s normal error handling and returns an HTTP 500 response. The integration reports the original failure separately.

See the error in Bugsink

Open your Bugsink project. The new ProductNotFound issue contains the concrete request, parameterized Spring route, HTTP breadcrumb, and controller frame which raised it.

Bugsink preview

That’s it: unhandled Spring MVC controller exceptions will now be reported to Bugsink. Remove the deliberate exception; the integration remains active for future request failures.

For handled exceptions, messages, logging, tags, structured context, breadcrumbs, and short-lived Java processes, continue with the Java guide.