Kotlin SentryOptions.BeforeSendCallback doesn't work

Hi there,

I work on a Kotlin application (with Spring boot) and want to ignore some Exception/Sentry events from Error logging for all exceptions that come from some particular libraries. What I have tried to do so far is to override the class SentryOptions.BeforeSendCallback but it doesn’t seem to work.

See code:

class SentryBeforeSendCallback : SentryOptions.BeforeSendCallback {
    override fun execute(event: SentryEvent, hint: Any?): SentryEvent? {
        // Any exceptions from the following list of loggers will be ignored in Sentry (a.k.a. no Sentry issue will be created)
        val loggersToIgnore = hashSetOf("com.microsoft.azure.sdk")
        if ((event.throwable != null && loggersToIgnore.any { event.throwable!!.toString().contains(it) }) ||
            (event.logger != null && loggersToIgnore.any { event.logger!!.toString().contains(it) })
        ) {
            return null

        return event

Locally I can successfully ignore exceptions (manually and via tests) but in production it doesn’t seem to work.
I came upon this PR in the JavaScript version of sentry and they say that BeforeSendCallback is disabled, but I couldn’t reproduce the suggested code in Kotlin.

Another attempt at it was to create a class TracesSamplerCallback but this class doesn’t seem to be triggered at all.

A follow up question is then- is it possible to ignore exception that are triggered via log Error but NOT ignore them if they are unhandled?


Hi, That should work, please double-check your logic for filtering events.
See Filtering for Spring Boot | Sentry Documentation

TracesSamplerCallback is something else, used for Performance Monitoring.

You can also use the Ignored Exceptions For Type feature.

@liat-gcx just to make sure - you need to create a bean for this class so that SentryAutoConfiguration picks it up.

If you do have this bean, could you please create a minimal example on github that reproduces your problem? I am happy to investigate and guide you further.