Skip to content

Commit c8d5c9f

Browse files
authored
[#219] Sentry 에러 모니터링 추가
* [#219] feat : Exception.class 로깅 추가 * [#219] refactor : 로깅 Exception 출력으로 변경 e.getMessage() 대신 e를 찍는 방식으로 변경 e를 찍어야 어떤 클래스에서 에러가 발생했는지 추적 가능 * [#219] feat : Sentry 에러 모니터링 코드 추가 * [#219] feat : Sentry 설정 추가
1 parent a2ea904 commit c8d5c9f

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'java'
33
id 'org.springframework.boot' version '3.2.3'
44
id 'io.spring.dependency-management' version '1.1.5'
5+
id "io.sentry.jvm.gradle" version "5.3.0"
56
}
67

78
group = 'com.juu'
@@ -23,6 +24,15 @@ repositories {
2324
mavenCentral()
2425
}
2526

27+
28+
sentry {
29+
includeSourceContext = true
30+
org = "kwongio"
31+
projectName = "juulabel"
32+
authToken = System.getenv("SENTRY_AUTH_TOKEN")
33+
}
34+
35+
2636
dependencies {
2737
// web
2838
implementation 'org.springframework.boot:spring-boot-starter-web'

src/main/java/com/juu/juulabel/common/exception/handler/GlobalExceptionHandler.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.juu.juulabel.common.response.CommonResponse;
66
import io.jsonwebtoken.ExpiredJwtException;
77
import io.jsonwebtoken.MalformedJwtException;
8+
import io.sentry.Sentry;
89
import lombok.extern.slf4j.Slf4j;
910
import org.springframework.http.ResponseEntity;
1011
import org.springframework.web.bind.MethodArgumentNotValidException;
@@ -17,33 +18,42 @@
1718
@RestControllerAdvice
1819
public class GlobalExceptionHandler {
1920

21+
@ExceptionHandler(Exception.class)
22+
public ResponseEntity<CommonResponse<String>> handle(Exception e) {
23+
log.error("Exception :", e);
24+
Sentry.captureException(e);
25+
return CommonResponse.fail(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
26+
}
27+
2028
@ExceptionHandler(BaseException.class)
2129
public ResponseEntity<CommonResponse<String>> handle(BaseException e) {
22-
log.error("BaseException : {} ", e.getMessage());
30+
log.error("BaseException :", e);
31+
Sentry.captureException(e);
2332
return CommonResponse.fail(e.getErrorCode());
2433
}
2534

2635
@ExceptionHandler(RuntimeException.class)
2736
public ResponseEntity<CommonResponse<String>> handle(RuntimeException e) {
28-
log.error("RuntimeException : {}", e.getMessage());
37+
log.error("RuntimeException :", e);
38+
Sentry.captureException(e);
2939
return CommonResponse.fail(ErrorCode.INTERNAL_SERVER_ERROR, e.getMessage());
3040
}
3141

3242
@ExceptionHandler(MethodArgumentNotValidException.class)
3343
public ResponseEntity<CommonResponse<String>> handle(MethodArgumentNotValidException e) {
34-
log.error("MethodArgumentNotValidException : {}", e.getMessage());
44+
log.error("MethodArgumentNotValidException :", e);
3545
return CommonResponse.fail(ErrorCode.VALIDATION_ERROR, Objects.requireNonNull(e.getBindingResult().getFieldError()).getDefaultMessage());
3646
}
3747

3848
@ExceptionHandler(ExpiredJwtException.class)
3949
public ResponseEntity<CommonResponse<String>> handle(ExpiredJwtException e) {
40-
log.error("ExpiredJwtException : {}", e.getMessage());
50+
log.error("ExpiredJwtException :", e);
4151
return CommonResponse.fail(ErrorCode.EXPIRED_JWT_EXCEPTION, e.getMessage());
4252
}
4353

4454
@ExceptionHandler(MalformedJwtException.class)
4555
public ResponseEntity<CommonResponse<String>> handle(MalformedJwtException e) {
46-
log.error("MalformedJwtException : {}", e.getMessage());
56+
log.error("MalformedJwtException :", e);
4757
return CommonResponse.fail(ErrorCode.MALFORMED_JWT_EXCEPTION, "잘못된 토큰 형식입니다.");
4858
}
4959

0 commit comments

Comments
 (0)