Advanced Usage

Sentry's Spring Boot integration automatically includes the release and sets options as described in the following sections.

When Spring Boot is configured to generate Git information, every event triggered by Sentry will have a release field set to the current Git commit ID that will enable Sentry's release health feature.

This feature can be disabled in application.properties file:

application.properties
Copied
sentry.use-git-commit-id-as-release=false

Any Spring bean implementing EventProcessor will be automatically set on SentryOptions during Sentry SDK auto-configuration. There can be multiple event processors registered in single application.

Copied
import io.sentry.SentryEvent;
import io.sentry.EventProcessor;
import io.sentry.Hint
import org.springframework.stereotype.Component;

@Component
public class CustomEventProcessor implements EventProcessor {
  @Override
  public SentryEvent process(SentryEvent event, Hint hint) {
    // modify the event or return null to drop it
    return event;
  }
}

Any Spring bean implementing the BeforeSendCallback will be automatically set on SentryOptions during the SDK's auto-configuration. Note that there can be only a single bean set this way.

Copied
import io.sentry.SentryEvent;
import io.sentry.SentryOptions;
import io.sentry.Hint
import org.springframework.stereotype.Component;

@Component
public class CustomBeforeSendCallback implements SentryOptions.BeforeSendCallback {
  @Override
  public SentryEvent execute(SentryEvent event, Hint hint) {
    // Example: Never send server name in events
    event.setServerName(null);
    return event;
  }
}

Any Spring bean implementing the BeforeBreadcrumbCallback will be automatically set on SentryOptions during the SDK's auto-configuration. Note that there can be only a single bean set this way.

Copied
import io.sentry.Breadcrumb;
import io.sentry.SentryOptions;
import io.sentry.Hint
import org.springframework.stereotype.Component;

@Component
public class CustomBeforeBreadcrumbCallback implements SentryOptions.BeforeBreadcrumbCallback {

  @Override
  public Breadcrumb execute(Breadcrumb breadcrumb, Hint hint) {
    // Don't add breadcrumbs with message containing:
    if (breadcrumb.getMessage() != null
      && breadcrumb.getMessage().contains("bad breadcrumb")) {
      return null;
    }
    return breadcrumb;
  }
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").