From 2bf692eb1488b57adb1879230726766f7fdf522e Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 19 Dec 2024 00:40:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20Sentry=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 40 +++++++++++++++++++ buildSrc/src/main/kotlin/DependencyVersion.kt | 4 ++ 2 files changed, 44 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 6181afa1d..225061ab5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,6 +21,9 @@ plugins { id("com.epages.restdocs-api-spec") version DependencyVersion.EPAGES_REST_DOCS_API_SPEC id("org.hidetake.swagger.generator") version DependencyVersion.SWAGGER_GENERATOR + /** sentry */ + id("io.sentry.jvm.gradle") version DependencyVersion.SENTRY_JVM_GRADLE + id("org.jetbrains.dokka") version "1.9.20" } @@ -117,6 +120,7 @@ subprojects { apply(plugin = "org.asciidoctor.jvm.convert") apply(plugin = "com.epages.restdocs-api-spec") apply(plugin = "org.hidetake.swagger.generator") + apply(plugin = "io.sentry.jvm.gradle") /** * https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support @@ -175,6 +179,9 @@ subprojects { /** swagger ui */ swaggerUI("org.webjars:swagger-ui:${DependencyVersion.SWAGGER_UI}") + + /** sentry */ + implementation("io.sentry:sentry-spring-boot-starter-jakarta:${DependencyVersion.SENTRY_SPRING_BOOT}") } kapt { @@ -194,6 +201,39 @@ subprojects { } } + sentry { + // Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry. + // This enables source context, allowing you to see your source + // code as part of your stack traces in Sentry. + includeSourceContext = true + + // The organization slug in Sentry. + org = + project.hasProperty("sentryProjectName").let { + if (it) { + project.property("sentryProjectName") as String + } else { + "" + } + } + projectName = + project.hasProperty("sentryProjectName").let { + if (it) { + project.property("sentryProjectName") as String + } else { + "" + } + } + authToken = + project.hasProperty("sentryAuthToken").let { + if (it) { + project.property("sentryAuthToken") as String + } else { + "" + } + } + } + /** server url */ val serverUrl = project.hasProperty("serverUrl").let { diff --git a/buildSrc/src/main/kotlin/DependencyVersion.kt b/buildSrc/src/main/kotlin/DependencyVersion.kt index 910d617bd..80e62ea8b 100644 --- a/buildSrc/src/main/kotlin/DependencyVersion.kt +++ b/buildSrc/src/main/kotlin/DependencyVersion.kt @@ -65,4 +65,8 @@ object DependencyVersion { /** AspectJ **/ const val ASPECTJ = "1.9.5" + + /** sentry **/ + const val SENTRY_JVM_GRADLE = "4.14.1" + const val SENTRY_SPRING_BOOT = "7.9.0" } \ No newline at end of file From 2f46f48be9e01b3d3c606a1b58dcc68984c0c404 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 19 Dec 2024 00:41:43 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20Sentry=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=8D=BC=ED=8B=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/src/main/resources/application-sentry-local.yml | 6 ++++++ api/src/main/resources/application-sentry-prd.yml | 6 ++++++ api/src/main/resources/application.yml | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 api/src/main/resources/application-sentry-local.yml create mode 100644 api/src/main/resources/application-sentry-prd.yml diff --git a/api/src/main/resources/application-sentry-local.yml b/api/src/main/resources/application-sentry-local.yml new file mode 100644 index 000000000..448e9a241 --- /dev/null +++ b/api/src/main/resources/application-sentry-local.yml @@ -0,0 +1,6 @@ +sentry: + dsn: "" + exception-resolver-order: -2147483647 + max-request-body-size: always + send-default-pii: true + traces-sample-rate: 1.0 diff --git a/api/src/main/resources/application-sentry-prd.yml b/api/src/main/resources/application-sentry-prd.yml new file mode 100644 index 000000000..e3b367cd7 --- /dev/null +++ b/api/src/main/resources/application-sentry-prd.yml @@ -0,0 +1,6 @@ +sentry: + dsn: ${SENTRY_DSN} + exception-resolver-order: -2147483647 + max-request-body-size: always + send-default-pii: true + traces-sample-rate: 1.0 diff --git a/api/src/main/resources/application.yml b/api/src/main/resources/application.yml index c0d996c06..f100ba163 100644 --- a/api/src/main/resources/application.yml +++ b/api/src/main/resources/application.yml @@ -5,6 +5,8 @@ spring: profiles: group: local: + # infra + - sentry-local # module - security-local - web-local @@ -14,6 +16,8 @@ spring: # api - thread-local prd: + # infra + - sentry-prd # module - security-prd - web-prd From 7a4dc9dab36df673ac104b9c093cfe32a6927398 Mon Sep 17 00:00:00 2001 From: belljun3395 <195850@jnu.ac.kr> Date: Thu, 19 Dec 2024 00:42:25 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20RestControllerAdvice=EC=97=90=20Sen?= =?UTF-8?q?try.captureException=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/web/handler/ControllerExceptionHandler.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/main/kotlin/web/handler/ControllerExceptionHandler.kt b/web/src/main/kotlin/web/handler/ControllerExceptionHandler.kt index daa898657..80f3f6156 100644 --- a/web/src/main/kotlin/web/handler/ControllerExceptionHandler.kt +++ b/web/src/main/kotlin/web/handler/ControllerExceptionHandler.kt @@ -1,5 +1,6 @@ package web.handler +import io.sentry.Sentry import jakarta.servlet.http.HttpServletRequest import jakarta.validation.ConstraintViolationException import org.springframework.beans.TypeMismatchException @@ -28,6 +29,7 @@ class ControllerExceptionHandler( request: HttpServletRequest, ): ApiResponse { loggingHandler.writeLog(ex, request) + Sentry.captureException(ex) return ApiResponseGenerator.fail(ExceptionMessage.FAIL.message, HttpStatus.BAD_REQUEST) } @@ -47,6 +49,7 @@ class ControllerExceptionHandler( request: HttpServletRequest, ): ApiResponse { loggingHandler.writeLog(ex, request) + Sentry.captureException(ex) return handleRequestDetails(ex) } @@ -83,6 +86,7 @@ class ControllerExceptionHandler( request: HttpServletRequest, ): ApiResponse { loggingHandler.writeLog(ex, request) + Sentry.captureException(ex) return ApiResponseGenerator.fail( ExceptionMessage.FAIL.message, HttpStatus.INTERNAL_SERVER_ERROR, @@ -95,6 +99,7 @@ class ControllerExceptionHandler( request: HttpServletRequest, ): ApiResponse { loggingHandler.writeLog(ex, request) + Sentry.captureException(ex) return ApiResponseGenerator.fail( ExceptionMessage.ACCESS_DENIED.message, HttpStatus.FORBIDDEN, @@ -107,6 +112,7 @@ class ControllerExceptionHandler( request: HttpServletRequest, ): ApiResponse { loggingHandler.writeLog(ex, request) + Sentry.captureException(ex) return ApiResponseGenerator.fail( ExceptionMessage.FAIL.message, HttpStatus.INTERNAL_SERVER_ERROR,