> For the complete documentation index, see [llms.txt](https://docs.poja.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.poja.io/integrating-with-third-party-tools/monitor-errors-with-sentry.md).

# Monitor errors with Sentry

## Goal

Configure [Sentry](https://sentry.io/) 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](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

![](https://content.gitbook.com/content/l1HmqOCSTkQSmQ8LQPL2/blobs/4hnx22X6Wy6H1UdK4hRN/image\(16\).png)

* Copy your Sentry [DSN](https://docs.sentry.io/concepts/key-terms/dsn-explainer/) 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

![](https://content.gitbook.com/content/l1HmqOCSTkQSmQ8LQPL2/blobs/OenxtZNhNTC8eahlBHvi/image\(17\).png)

* Create the `SENTRY_DSN` environment variable and paste the previously copied DSN from your Sentry project

![](https://content.gitbook.com/content/l1HmqOCSTkQSmQ8LQPL2/blobs/uFchc9UIqCIt8H5trl3o/image\(19\).png)

{% hint style="info" %}
**Sentry environment**

You can optionally set the `SENTRY_ENVIRONMENT` environment variable if you want a custom name for your environment when retrieving errors on Sentry Dashboard
{% endhint %}

* 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.

{% code title="Java" %}

```java
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");
  }
}
```

{% endcode %}

Once the deployment is successful, visit `/exception` and the error should appear on your Sentry dashboard.

<figure><img src="https://3438488152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl1HmqOCSTkQSmQ8LQPL2%2Fuploads%2Feg9ju1NqnTvqdHbx9jYM%2F591772843_2427336354455676_3780038659942908037_n.png?alt=media&amp;token=ee55908a-9556-4e3e-be3f-fa79bd6d95a1" alt=""><figcaption></figcaption></figure>

## Test the Sentry Logback integration

Poja's Sentry integration comes with an builtin configuration of Sentry's [Logback](https://docs.sentry.io/platforms/java/guides/logback/) which allows you to see errors logged with [Lombok's Slf4j](https://projectlombok.org/api/lombok/extern/slf4j/Slf4j).

Here's an updated version of `ErrorController` :

{% code title="Java" %}

```java
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";
  }
}
```

{% endcode %}

Deploy your application and visit `/log-error` and voilà!

<figure><img src="https://3438488152-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl1HmqOCSTkQSmQ8LQPL2%2Fuploads%2FGSDDaZ3DlKDZjgPUJLPs%2F591827317_1689658972259418_1281150640213628758_n.png?alt=media&amp;token=110c0361-17eb-40ea-90c4-f5fe4f8da7ab" alt=""><figcaption></figcaption></figure>
