From 1755e7e4775ed24bc1ec236cc9759548d0316730 Mon Sep 17 00:00:00 2001 From: Jeonghyun Kang Date: Thu, 2 May 2024 00:26:09 +0900 Subject: [PATCH] =?UTF-8?q?[WEAV-315]=20Sentry=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=97=B0=EB=8F=99=20(#257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootstrap/http/build.gradle.kts | 3 +++ .../bootstrap/common/exception/UnknownExceptionHandler.kt | 7 +++++++ .../common/exception/WebSocketExceptionHandler.kt | 2 ++ bootstrap/http/src/main/resources/application.yaml | 6 ++++++ gradle/libs.versions.toml | 3 +++ 5 files changed, 21 insertions(+) diff --git a/bootstrap/http/build.gradle.kts b/bootstrap/http/build.gradle.kts index 474a21b1..17cb05a3 100644 --- a/bootstrap/http/build.gradle.kts +++ b/bootstrap/http/build.gradle.kts @@ -16,6 +16,9 @@ dependencies { implementation(libs.spring.boot.starter.data.jpa) implementation(libs.springdoc.openapi.starter.webmvc.ui) + implementation(libs.sentry.spring.boot.starter.jarkarta) + implementation(libs.sentry.logback) + developmentOnly(libs.spring.boot.devtools) developmentOnly(libs.spring.boot.docker.compose) diff --git a/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/UnknownExceptionHandler.kt b/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/UnknownExceptionHandler.kt index 692740a9..1a9d46ee 100644 --- a/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/UnknownExceptionHandler.kt +++ b/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/UnknownExceptionHandler.kt @@ -2,6 +2,7 @@ package com.studentcenter.weave.bootstrap.common.exception import com.studentcenter.weave.support.common.exception.SystemException import io.github.oshai.kotlinlogging.KotlinLogging +import io.sentry.Sentry import io.swagger.v3.oas.annotations.Hidden import jakarta.servlet.http.HttpServletRequest import org.springframework.core.Ordered @@ -46,6 +47,12 @@ class UnknownExceptionHandler { ): ErrorResponse { logger.error { e.stackTraceToString() } + Sentry.captureException(e) { scope -> + scope.setExtra("method", request.method) + scope.setExtra("requestURI", request.requestURI) + scope.setExtra("queryString", request.queryString?.let { "?$it" } ?: "") + scope.setExtra("clientIp", request.getHeader("X-Forwarded-For") ?: request.remoteAddr) + } return ErrorResponse( exceptionCode = SystemException.InternalServerError().code, message = "Internal Server Error" diff --git a/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/WebSocketExceptionHandler.kt b/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/WebSocketExceptionHandler.kt index 8c85cd3a..1137c712 100644 --- a/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/WebSocketExceptionHandler.kt +++ b/bootstrap/http/src/main/kotlin/com/studentcenter/weave/bootstrap/common/exception/WebSocketExceptionHandler.kt @@ -2,6 +2,7 @@ package com.studentcenter.weave.bootstrap.common.exception import com.studentcenter.weave.support.common.exception.CustomException import com.studentcenter.weave.support.common.exception.SystemException +import io.sentry.Sentry import org.springframework.messaging.handler.annotation.MessageExceptionHandler import org.springframework.web.bind.annotation.ControllerAdvice @@ -26,6 +27,7 @@ class WebSocketExceptionHandler { @MessageExceptionHandler(Exception::class) fun handleException(exception: Exception): ErrorResponse { + Sentry.captureException(exception) return ErrorResponse( exceptionCode = SystemException.InternalServerError().code, message = exception.message ?: "Internal server error" diff --git a/bootstrap/http/src/main/resources/application.yaml b/bootstrap/http/src/main/resources/application.yaml index aff0510a..83ca9684 100644 --- a/bootstrap/http/src/main/resources/application.yaml +++ b/bootstrap/http/src/main/resources/application.yaml @@ -39,6 +39,9 @@ spring: springdoc: swagger-ui: enabled: true +sentry: + dsn: ${SENTRY_DSN} + environment: dev --- spring: config: @@ -50,6 +53,9 @@ spring: springdoc: swagger-ui: enabled: true +sentry: + dsn: ${SENTRY_DSN} + environment: prod --- spring: config: diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c9d2512b..cfa26039 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -84,6 +84,9 @@ redisson-spring-boot-starter = { group = "org.redisson", name = "redisson-spring java-jwt = { group = "com.auth0", name = "java-jwt", version.ref = "auth0-java-jwt" } jwks-rsa = { group = "com.auth0", name = "jwks-rsa", version.ref = "auth0-jwks-rsa" } +sentry-spring-boot-starter-jarkarta = { group = "io.sentry", name = "sentry-spring-boot-starter-jakarta", version = "7.8.0" } +sentry-logback = { group = "io.sentry", name = "sentry-logback", version = "7.8.0" } + [plugins] sonarqube = { id = "org.sonarqube", version.ref = "sonar-cloud" }