Rollbar is a cloud-based bug tracking and monitoring solution that caters to organizations of all sizes. Rollbar supports multiple programming languages and frameworks like Java, Java Spring, JavaScript, Python, . NET, Drupal, Wordpress and Pyramid. The Rollbar service will alert you of problems with your code and help you understand them in a ways never possible before.
Lets configure rollbar with springboot. don’t worry its easy to configure, so relax.
Step 1: Create Rollbar Account
After signup you ll get home page like this
Step 2: Click on Projects
Step 3: Add new project
Check top right corner, click on “New Project” button
I am adding project name as “RollbarSpringbootDemo”. you can add project name along with timezone etc etc.
And click on “Create Project”
Step 4: Select SDK (like Java Spring, Go etc)
It is mandate to select sdk with project.
For Spring boot or Spring select “Java Spring” and click on “continue”
Step 5: Final Project step page
This is final project setup page leave it and go back to http://rollbar.com
Rollbar console now looks like
Step 6: Get Project Access Token
To get project access token click on side bar “projects” button and “select your project” and later “project access token” button. Project access token help you to connect spring boot application to the specific rollbar project.
Copy “post_server_item” token
Step 6: Create a Spring boot web project
Step 7: Add rollbar dependency to the pom.xml/build.gradle
https://mvnrepository.com/artifact/com.rollbar/rollbar-spring-boot-webmvc
implementation 'com.rollbar:rollbar-spring-boot-webmvc:1.8.1'
Step 8: Add Rollbar bean
We need post_server_item token right here to connect to rollbar project. If you don’t have, Please check step 6 and set token in withAccessToken(token)
@Configuration
public class RollbarConfiguration {
private final String token = "7dea12a58a414d7ab69456ea2c280ae9"; @Bean(name = "rollbar")
public Rollbar getRollbar() {
return new Rollbar(getConfig());
}
public Config getConfig() {
return ConfigBuilder.withAccessToken(token)
.environment().build();
}
}
Step 9: Add Rollbar Utility/Service to Spring boot application
Create a concrete class and add methods as per your requirements
public interface ExternalErrorHandlerService {
void sendError(Exception e);
void sendError(Exception e, String message);
void sendInfo(Exception e);
void sendInfo(Exception e, String message);
void sendDebug(Exception e);
void sendDebug(Exception e, String message);
}
Rollbar utility or service
package com.rollbar.rollbardemo.services.error.impl;
import com.rollbar.notifier.Rollbar;
import com.rollbar.rollbardemo.services.error.ExternalErrorHandlerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@Service
public class RollbarErrorHandlerService implements ExternalErrorHandlerService {
private final Rollbar rollbar;
@Autowired
public RollbarErrorHandlerService(@Qualifier("rollbar") Rollbar rollbar) {
this.rollbar = rollbar;
}
@Override
public void sendError(Exception e) {
rollbar.error(e);
}
@Override
public void sendError(Exception e, String message) {
rollbar.error(e,message);
}
@Override
public void sendInfo(Exception e) {
rollbar.info(e);
}
@Override
public void sendInfo(Exception e, String message) {
rollbar.info(e,message);
}
@Override
public void sendDebug(Exception e) {
rollbar.debug(e);
}
@Override
public void sendDebug(Exception e, String message) {
rollbar.debug(e,message);
}
}
Congrats !!! Now your application ready to use rollbar dashboard
Step 10: Select project and enviroment
You can run sample application from github.
You will get sample api documentation which push errors into your rollbar dashboard.
Thanks for reading !!!