Goal
Configure Sentry as a monitoring system for an existing Poja Application using Poja’s built in Sentry integration.
How-to
Configure the Sentry project
Create an account on https://sentry.io
Create a new or select an already existing one
For development purposes, we will configure our project to notify us when there is more than one error occurrence
.png)
Copy your Sentry DSN from [Your Project] > Settings > SDK Setup > Client Keys (DSN), which will be used by the application to send events to the Sentry project
Configure the Poja application
Create a new application on the Poja console or select an already existing one
Select an environment (PROD or PREPROD)
Edit the application’s configuration as follows:
Enable the Sentry integration
.png)
Create the
SENTRY_DSNenvironment variable and paste the previously copied DSN from your Sentry project.png)
Sentry environment
You can optionally set the
SENTRY_ENVIRONMENTenvironment variable if you want a custom name for your environment when retrieving errors on Sentry Dashboard
Click on the Save button and wait for the deployment to complete
Test the Sentry Integration
Integrate the following endpoint, commit and push to the preprod branch and wait for the deployment to finish.
package com.example.demo.endpoint.rest.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ErrorController {
@GetMapping("/exception")
public void getError() {
throw new RuntimeException("This is an error");
}
}
Once the deployment is successful, visit /exception and the error should appear on your Sentry dashboard.
.png)
Test the Sentry Logback integration
Poja’s Sentry integration comes with an builtin configuration of Sentry’s Logback which allows you to see errors logged with Lombok's Slf4j.
Here’s an updated version of ErrorController :
package com.example.demo.endpoint.rest.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class ErrorController {
@GetMapping("/exception")
public void getError() {
throw new RuntimeException("This is an error");
}
@GetMapping("/log-error")
public String logError() {
log.error("This is an error");
return "OK";
}
}
Deploy your application and visit /log-error and voilà!
.png)