Sentri.io — errors handling

Today I want to talk about one service I’ve discovered for myself last week. As you probably already got from article title it is Sentry.io (opens new window). This open source project helps you to aggregate and monitor information regarding errors happening in your application. Beside opensource version, there is also hosted paid (opens new window)(with free Hobbyist plan) version which supposes to be the same.

This service provides wide support for different programming languages like Java, C#, Elixir, Go, Javascript, Node, Perl, PHP, Python, etc. The integration process is super easy — you just need to add proper dependency into your project and provide a little bit of configuration (opens new window)(at least access token), and you are ready to go. In my case, it was a Spring-Boot application with logback logging framework. Both those technologies are supported by Sentry.io. So, I’ve placed io.sentry:sentry-spring and io.sentry:sentry-logback libraries into projects Gradle script. Then I’ve created a new project inside Sentry’s dashboard and generated a token for it. Next step — configuration inside the project. And that is something I don’t like about all that story. Maybe there is some way around but I can’t find it — so, I had to duplicate configuration twice — for logback and for spring-boot respectively. I’ve added sentry.properties file in project’s resource folder with dsn key inside and sentry.dsn key to my application.yaml. Also, the configuration of logback appenders was updated with the following block:

<appender name="SENTRY" class="io.sentry.logback.SentryAppender">
        <minLevel>ERROR</minLevel>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>ERROR</level>
        </filter>
</appender>

And as a final step additional beans for Spring to handle unhandled exceptions and provide additional request context(yes, a little bit of  Kotlin ):

@Bean
fun sentryExceptionResolver(): HandlerExceptionResolver {
    return SentryExceptionResolver()
}

@Bean
fun sentryServletContextInitializer(): ServletContextInitializer {
    return SentryServletContextInitializer()
}

That’s it.

But there is much more than just aggregation of errors. Sentry provides useful report channels integrations. For example, it can send notifications by email or to S lack when there is a new type of error. Or notify you if same error happened more then 100 times per hour. All those rules are extremely flexible and can be configured with Sentry’s dashboard.

And there is integration with popular issue trackers like Jira. So, it will create a new bug ticket for each new error with stacktrace and all context it has. That should make it easier to fix them.

So far looks good.