본문 바로가기

Backend

[Springboot] Sentry 에러 로그 수집기 설정하기

반응형

https://docs.sentry.io/platforms/java/guides/spring-boot/

 

Spring Boot | Sentry for Spring-boot

There are two variants of Sentry available for Spring Boot. If you're using our Gradle plugin it will pick the right dependency for you. If you're manually adding the dependency and using Spring Boot 2, use sentry-spring-boot-starter (GitHub). If you're us

docs.sentry.io


Sentry 는 에러수집과 모니터링을 지원하는 툴이다. 현재 진행중인, 배포된 프로젝트에 실시간으로 에러를 확인하기 위해 Sentry.io를 연동시키고자 한다. 

 

공식문서상으로 Springboot 2.x와 3.x는 gradle 라이브러리 버전이 다르니 참고해야한다.

// Sentry , Springboot 3.x
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:7.10.0'

코드개발을 진행할 때, 발생할 만한 예외들은 @ControllerAdvice 어노테이션을 활용해서 하나의 예외핸들러 클래스로 모아두었다. 

 

일단 예외핸들러로 잡히지 않는 에러들을 전부 Sentry에 전송해보려고 한다. logback으로 에러 formatting 작업은 추후에 필요하면 진행하고, 일단 정상 동작부터 지켜보려고 한다. 

 

에러를 발생시켜보았고, 정상적으로 연동은 되었다고 본다. 하지만 Sentry 도입 목적은 예상하지 못한 500번 에러들만 모니터링하는 것이다. 현재는 400, 500번대 모두 Sentry에서 수집되고 있다. 

 

Sentry Springboot Document를 읽고 application.yaml에 다음과 같이 작성해두었었다.

Sentry는 Default로 핸들링처리 되지 않은 예외들만 수집되게 되어있다. 하지만 exception-resolver-order를 명시해두면  @ExceptionHandler로 exception을 처리해둔 예외들도 수집이 된다. 결론적으론, 예상하지 못한 에러 로그만 모니터링하고 싶다면 dsn 키 하나만 작성해두면 된다. 

sentry:
  dsn: {개인키}
  exception-resolver-order: -2147483647

 

원문 참고

By default, only unhandled exceptions are sent to Sentry. This behavior can be tuned through configuring the sentry.exception-resolver-order property. For example, setting it to -2147483647 (the value of org.springframework.core.Ordered#HIGHEST_PRECEDENCE) ensures exceptions that have been handled by exception resolvers with higher order are sent to Sentry - including ones handled by @ExceptionHandler annotated methods.

 

exception-resolver-order 키를 제외하니 400번대로 정의해둔 예외들은 Sentry에 수집되지 않았다. 


https://zorba91.tistory.com/311

 

[Spring Boot] logback과 Sentry를 활용하여 에러 모니터링하기

Sentry는 에러 모니터링을 위한 툴로 굉장히 많이 쓰이고 있는 툴이다. 이번에 회사에서 Sentry 붙이는 작업을 했는데, 기존에는 global하게 적용되어 있지 않고, 선언적 방법으로 적용되어 있었다.

zorba91.tistory.com

https://www.baeldung.com/ops/java-sentry

https://velog.io/@woosim34/Springboot-Logback-%EC%84%A4%EC%A0%95%ED%95%B4%EB%B3%B4%EA%B8%B0

https://intothemaze.tistory.com/16

 

[Sentry] Exception Handler를 거치기 전 Sentry로 에러 전달 및 Exception 필터링 (Spring Boot)

https://intothemaze.tistory.com/14 [Sentry] Spring Boot에 Sentry 적용하기 Sentry Sentry는 오픈소스 기반의 에러 트래킹 및 로깅 도구로, 애플리케이션에서 발생하는 버그, 예외, 성능 문제 등을 감지하고 이를 기

intothemaze.tistory.com

 

 

반응형