Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#441] 센트리 적용을 위한 설정 #462

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/resources/application-sentry-local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sentry:
dsn: ""
exception-resolver-order: -2147483647
max-request-body-size: always
send-default-pii: true
traces-sample-rate: 1.0
6 changes: 6 additions & 0 deletions api/src/main/resources/application-sentry-prd.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ spring:
profiles:
group:
local:
# infra
- sentry-local
# module
- security-local
- web-local
Expand All @@ -14,6 +16,8 @@ spring:
# api
- thread-local
prd:
# infra
- sentry-prd
# module
- security-prd
- web-prd
Expand Down
40 changes: 40 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions buildSrc/src/main/kotlin/DependencyVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 6 additions & 0 deletions web/src/main/kotlin/web/handler/ControllerExceptionHandler.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,6 +29,7 @@ class ControllerExceptionHandler(
request: HttpServletRequest,
): ApiResponse<ApiResponse.FailureBody> {
loggingHandler.writeLog(ex, request)
Sentry.captureException(ex)
return ApiResponseGenerator.fail(ExceptionMessage.FAIL.message, HttpStatus.BAD_REQUEST)
}

Expand All @@ -47,6 +49,7 @@ class ControllerExceptionHandler(
request: HttpServletRequest,
): ApiResponse<ApiResponse.FailureBody> {
loggingHandler.writeLog(ex, request)
Sentry.captureException(ex)
return handleRequestDetails(ex)
}

Expand Down Expand Up @@ -83,6 +86,7 @@ class ControllerExceptionHandler(
request: HttpServletRequest,
): ApiResponse<ApiResponse.FailureBody> {
loggingHandler.writeLog(ex, request)
Sentry.captureException(ex)
return ApiResponseGenerator.fail(
ExceptionMessage.FAIL.message,
HttpStatus.INTERNAL_SERVER_ERROR,
Expand All @@ -95,6 +99,7 @@ class ControllerExceptionHandler(
request: HttpServletRequest,
): ApiResponse<ApiResponse.FailureBody> {
loggingHandler.writeLog(ex, request)
Sentry.captureException(ex)
return ApiResponseGenerator.fail(
ExceptionMessage.ACCESS_DENIED.message,
HttpStatus.FORBIDDEN,
Expand All @@ -107,6 +112,7 @@ class ControllerExceptionHandler(
request: HttpServletRequest,
): ApiResponse<ApiResponse.FailureBody> {
loggingHandler.writeLog(ex, request)
Sentry.captureException(ex)
return ApiResponseGenerator.fail(
ExceptionMessage.FAIL.message,
HttpStatus.INTERNAL_SERVER_ERROR,
Expand Down
Loading