Sentry
Sentry는 오픈소스 기반의 에러 트래킹 및 로깅 도구로, 애플리케이션에서 발생하는 버그, 예외, 성능 문제 등을 감지하고 이를 기록하여 개발자들에게 제공한다. 구독형인 클라우드 버전과 설치형인 온 프레미스 버전으로 나뉜다.
주요 기능
- 에러 모니터링: 애플리케이션에서 발생하는 에러와 예외를 실시간으로 모니터링하여 개발자들에게 알린다. 이를 통해 빠르게 에러에 대처할 수 있고 사용자들의 문제를 사전에 감지할 수 있다.
- 스택 추적(Stack Trace): 에러가 발생한 위치를 포함한 스택 추적 정보를 제공하여, 어떤 코드에서 에러가 발생했는지를 파악할 수 있다. 이를 통해 디버깅과 문제 해결을 용이하게 한다.
- 사용자 정보: 에러가 발생한 사용자의 정보(환경, 브라우저, 디바이스 등)를 수집하여, 특정 환경에서 에러가 발생하는 경우를 파악할 수 있다.
- 통합 알림: 에러가 발생할 경우, 이를 이메일, 메시지, 슬랙 등 다양한 방법으로 개발자들에게 알림을 보내준다.
- 이벤트 기록: 애플리케이션에서 발생하는 다양한 이벤트와 로그를 기록하고 추적하여 애플리케이션 동작을 파악하고 문제점을 파악할 수 있다.
선택 이유
1. 굵직한 테크 기업들이 많이 사용한다.
2. 다양한 프로그래밍 언어와 프레임워크를 지원한다.
3. 프로젝트 리드 분이 현 회사에서 사용 중인 툴이다.
- 세 번째가 이유가 가장 컸는데, 에러 로그 모니터링 도구 사용은 처음이라 다양한 도구들을 비교 후 선택하기에는 무리가 있어서 선배 개발자가 현 실무에서 사용 중인 툴을 선택하게 되었다.
Sentry를 Spring Boot에 연동하기
Sentry 연동 시 요구사항은 두 가지였다.
1. 5XX 에러 및 로그 레벨 WARN을 Sentry로 전송
2. Sentry로 전송된 issue들은 Slack 알림으로 발송
위와 같이 우선 기본적인 틀을 만들고 세부적으로 어떤 예외들을 추가할지는 추후 의논하기로 했다.
1. Sentry 프로젝트 생성
Application Performance Monitoring & Error Tracking Software
Self-hosted and cloud-based application performance monitoring & error tracking that helps software teams see clearer, solve quicker, & learn continuously.
sentry.io
- Sentry 회원가입 후 왼쪽 사이드바에 Projects-Create project
- Popular > Spring Boot 👉 Alert me on every new issue 👉 sentry-project 👉 Create Project
2. Gradle
implementation 'io.sentry:sentry-spring-boot-starter:6.27.0'
implementation 'io.sentry:sentry-logback:6.27.0'
3. application.yml
- Settings > Projects > sentry-project > Client Keys (DSN)
sentry:
dsn: {dsn}
4. logback-spring.xml
- resources 아래에 logback 설정 파일 추가
- Console에 로그를 어떻게 출력할 것인지, Sentry 로그 레벨, local과 prod 환경에서의 로그 레벨 등을 설정
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<!-- Configure the Console appender -->
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Configure the Sentry appender, overriding the logging threshold to the WARN level -->
<appender name="Sentry" class="io.sentry.logback.SentryAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>WARN</level>
</filter>
<!-- Optionally add an encoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- Enable the Console and Sentry appenders, Console is provided as an example
of a non-Sentry logger that is set to a different logging threshold -->
<springProfile name="local">
<root level="INFO">
<appender-ref ref="Console"/>
</root>
</springProfile>
<springProfile name="prod">
<root level="INFO">
<appender-ref ref="Console"/>
<appender-ref ref="Sentry"/>
</root>
</springProfile>
</configuration>
The Sentry SDK는 추가적인 설정이나 처리 없이 애플리케이션 실행 중 발생하는 모든 Unhandled Exceptions를 자동으로 감지하고 보고한다.
해당 설정이 default인 것으로 알고 있는데, 다시 말하자면 ControllerAdvice를 통해 전역 예외를 처리하는 경우에는 에러가 감지되지 않고 패스 된다. 나는 500번대 서버 에러만 모니터링 할 예정이기에 이것으로 모든 설정이 끝이 났다.
Sentry와 Slack 연동 방법 및 WARN 로그 레벨 알림 전송은 다음 포스팅에서 다루겠다.
'Etc.' 카테고리의 다른 글
[GIT] Trunk-based development (0) | 2023.11.20 |
---|---|
[Sentry] Exception Handler를 거치기 전 Sentry로 에러 전달 및 Exception 필터링 (Spring Boot) (0) | 2023.08.09 |
[Sentry] Sentry Slack 연동 및 Logging 레벨 설정 (Spring Boot) (0) | 2023.08.07 |