> 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

![](/files/81e92e85729e2e208c99c726ab141f69308b9def)

* 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

![](/files/04f6b741d4ae1ef12fbe729018de5543add6708b)

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

![](/files/5e957f607d6f4bad465bac46f8474bbc9fc46f16)

{% 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="/files/CN3Bq71tu49tw5UARAcz" 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="/files/iJbBwobQUdJT2wXBfcwX" alt=""><figcaption></figcaption></figure>
