DEV Community

Andrei
Andrei

Posted on • Originally published at Medium on

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. 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(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(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>
view raw logback.xml hosted with ❤ by GitHub

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()
}
view raw config.kt hosted with ❤ by GitHub

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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay