Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-315] Sentry 라이브러리 연동 (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
rilac1 authored May 1, 2024
1 parent 1837a66 commit 1755e7e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bootstrap/http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions bootstrap/http/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ spring:
springdoc:
swagger-ui:
enabled: true
sentry:
dsn: ${SENTRY_DSN}
environment: dev
---
spring:
config:
Expand All @@ -50,6 +53,9 @@ spring:
springdoc:
swagger-ui:
enabled: true
sentry:
dsn: ${SENTRY_DSN}
environment: prod
---
spring:
config:
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 1755e7e

Please sign in to comment.