From 656255b97842deac6d948deaa5ff9823cfe284d4 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Thu, 15 Feb 2024 01:22:28 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20:=20sentry=20=EB=AA=A8=EB=8B=88?= =?UTF-8?q?=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + build.gradle | 4 + .../studyhubserver/TestController.java | 21 ++++ src/main/resources/application-prod.yml | 11 +- src/main/resources/logback-spring.xml | 110 ++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/main/java/kr/co/studyhubinu/studyhubserver/TestController.java create mode 100644 src/main/resources/logback-spring.xml diff --git a/.gitignore b/.gitignore index 8bad2fe3..84895382 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ build/bootJarMainClassName firebase-service-key.json +### 로깅 +logs + *.yml application.yml !application-prod.yml diff --git a/build.gradle b/build.gradle index 40a6e35d..0b17696c 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,10 @@ dependencies { // firebase implementation 'com.google.firebase:firebase-admin:9.2.0' + + // sentry + implementation 'io.sentry:sentry-spring-boot-starter:7.3.0' + implementation 'io.sentry:sentry-logback:5.3.0' } //querydsl 추가 diff --git a/src/main/java/kr/co/studyhubinu/studyhubserver/TestController.java b/src/main/java/kr/co/studyhubinu/studyhubserver/TestController.java new file mode 100644 index 00000000..3328e917 --- /dev/null +++ b/src/main/java/kr/co/studyhubinu/studyhubserver/TestController.java @@ -0,0 +1,21 @@ +package kr.co.studyhubinu.studyhubserver; + +import io.sentry.Sentry; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class TestController { + + @GetMapping("/v1/asd/12") + public ResponseEntity test() { + try { + throw new Exception("This is a test."); + } catch (Exception e) { + Sentry.captureException(e); + } + return ResponseEntity.ok().build(); + } +} diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index fa7b61f4..a8e2ddc4 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -63,4 +63,13 @@ cloud: firebase: project: - id: ${firebase.project.id} \ No newline at end of file + id: ${firebase.project.id} + +sentry: + dsn: ${sentry_dsn_value} + traces-sample-rate: 1.0 + exception-resolver-order: -2147483647 #including ones handled by @ExceptionHandler annotated methods. + debug: true + logging: + enabled: true + minimum-event-level: warn \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..a8c4d97c --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + ${LOG_PATTERN} + + + + + + ${LOGS_ABSOLUTE_PATH}/info.log + + INFO + ACCEPT + DENY + + + ${LOG_PATTERN} + + + ${LOGS_ABSOLUTE_PATH}/info.%d{yyyy-MM-dd}.%i.log.gz + + 100MB + + ${MAX_HISTORY} + + + + + + ${LOGS_ABSOLUTE_PATH}/warn.log + + WARN + ACCEPT + DENY + + + ${LOG_PATTERN} + + + ${LOGS_ABSOLUTE_PATH}/warn.%d{yyyy-MM-dd}.%i.log.gz + + 100MB + + ${MAX_HISTORY} + + + + + + ${LOGS_ABSOLUTE_PATH}/error.log + + ERROR + ACCEPT + DENY + + + ${LOG_PATTERN} + + + ${LOGS_ABSOLUTE_PATH}/error.%d{yyyy-MM-dd}.%i.log.gz + + 100MB + + ${MAX_HISTORY} + + + + + ${LOGS_ABSOLUTE_PATH}/performance.log + + ${LOGS_ABSOLUTE_PATH}/performance.%d{yyyy-MM-dd}.%i.log + + 15MB + + 7 + + + utf8 + ${PERFORMANCE_LOG_PATTERN} + + + + + + ERROR + + + + + + + + + + + + + + + \ No newline at end of file