Sentry je primárně zaměřeno na chyby. Je to místo, kam budou všechny pády systému reportovány. Na sentry si musíte vytvořit účet a nastavit projekt tak, aby chyby posílal do sentry a mít je na jednom místě.
build.gradle
implementation("io.sentry:sentry-spring-boot-starter:4.3.0")
application.yml
Tato data dostanete při registraci do sentry.
sentry:
dsn: https://xxx@yyy.ingest.sentry.io/zzz
Kód, který pošle chybu do sentry.
try {
throw Exception("This is a v1 test.")
} catch (e: Exception) {
Sentry.captureException(e)
}
Je možné přidat tento kód do GlobalErrorHandleru.
@ControllerAdvice
@RestController
class GlobalErrorHandler {
private val logger: Logger = LoggerFactory.getLogger(javaClass)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler
fun handle(e: Exception) {
logger.error("Error", e)
Sentry.captureException(e)
}
}




