Introduce Rollbar and Slack for realtime exception alerts

Frankie Fan
5 min readOct 16, 2020

--

Quickly responding to new, reactivated, and otherwise important exceptions is a critical part of adopting continuous delivery and other DevOps best practices.

Rollbar provides code version-specific dashboards and a live feed for proactively monitoring for exceptions during a deploy, but for those exceptions that happen when you aren’t actively watching Rollbar, our Slack integration is the most popular way to get real-time alerts.

Connect Rollbar with Github

Log in Rollbar with the “Log in with GitHub” button, and enables the GitHub integration settings for all your projects. Get started by going to your account settings. Navigate to the “Connected Accounts” and Connect with GitHub.

Create a project

Click the “create new project” on the top dropdown list in Rollbar.

Create the project from a Github repo directly or specify the new project information to create.

Integrate a notifier

Select the platform your project is based on. Here I use Java and continue.

Wait the data

Now we can see the tutorial for your platform and the status for it is waiting.

Integrate source control

Click the 3rd step to connect source control and select Github, then input the information for your project.

Project integration

Follow the tutorial on the 1st step page. Add the Rollbar related maven dependencies into your project. Here I add logback dependency into it as well because I’ll use logback to send exceptions to Rollbar.

<!-- Rollbar -->
<dependency>
<groupId>com.rollbar</groupId>
<version>[1.0,)</version>
<artifactId>rollbar-java</artifactId>
</dependency>
<dependency>
<groupId>com.rollbar</groupId>
<artifactId>rollbar-logback</artifactId>
<version>1.3.1</version>
</dependency>

Logback configuration

Here is the configuration of logback file. Please fill in the access token of your Rollbar into the appender and specify your environment name. Use filter in the appender is because we want to log the exception stack into both the file and Rollbar.

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>

<appender name="ROLLBAR" class="com.rollbar.logback.RollbarAppender">
<accessToken>ec6e37c277c940dcb5d4bcf879fa425c</accessToken>
<environment>Dev</environment>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>warn</level>
</filter>
</appender>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level [%thread] %-5level %logger{36} [%file:%line] - %msg%n</pattern>
</encoder>
</appender>

<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>logs/agriculture.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>1</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%date %level [%thread] %-5level %logger{36} [%file:%line] - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="console" />
<appender-ref ref="file" />
<appender-ref ref="ROLLBAR" />
</root>

<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
</configuration>

The access token can be copied from the the settings of the Rollbar project.

Test integration with Rollbar

Write a unit test and run to see the integration status.

org.slf4j.Logger logger = LoggerFactory.getLogger(Test.class);
try {
throw new IllegalArgumentException("This is a test for Rollbar.");
} catch (IllegalArgumentException e) {
logger.error("error", e);
}

Check dashboard status

Wait on the Integrate a Notifier step page or click the Dashboard link on the top bar. You will see the new error coming after the unit test is executed. Until now we’ve integrated exceptions alert into the Rollbar, the next step will be integrated Rollbar with Slack.

Integrate Rollbar notification with Slack

Go to the Settings of the Rollbar project and click the Notifications menuitem. Find the Slack app in the available channels

Add Rollbar app in Slack

Go to your Slack workspace and add Rollbar app.

Enable Slack integration

Click the Slack app in the available channels and select your access token and enable the Slack integration.

Slack channel selection

Select the channel you will notify exceptions in your Slack workspace. The dropdown here will list all the channels in your Slack workspace.

Configure Slack app rules

You can configure the rules of the Slack notifications as your need. For example, I add the every occurrence rule here in order to notify every error to the Slack.

Test integration with Slack

Run the unit test again to see the integration status with Slack. Go into the channel you configured in Rollbar and you will see the coming error notification.

Slack channel settings

Remember to join the channel in order to get notified. Then configure the notification preferences to include mobile. You can install the Slack app in your mobile and login your workspace. Run the unit test again and you will see notifications on your mobile as soon as exceptions happen.

--

--

Frankie Fan
Frankie Fan

Written by Frankie Fan

Researcher | Architect | Full-Stack | @hustakin

No responses yet