Skip to content

Commit

Permalink
feat: Sentry를 연동한다
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb committed Jan 10, 2024
1 parent 2bb4b0e commit 731fdd6
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id 'org.springframework.boot' apply false
id 'io.spring.dependency-management'
id 'org.sonarqube'
id 'io.sentry.jvm.gradle'
}

apply from: "gradle/spring.gradle"
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ sonarVersion=4.4.1.3373
mysqlConnectorVersion=8.0.33
### MOCK_WEB_SERVER ###
mockWebServerVersion=4.12.0
### SENTRY ###
sentryVersion=4.1.1
10 changes: 10 additions & 0 deletions gradle/apm.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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

org = "teum-teum"
projectName = "java-spring-boot"
authToken = System.getenv("SENTRY_AUTH_TOKEN")
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pluginManagement {
id 'org.springframework.boot' version "${springBootVersion}"
id 'io.spring.dependency-management' version "${springDependencyManagementVersion}"
id 'org.sonarqube' version "${sonarVersion}"
id 'io.sentry.jvm.gradle' version "${sentryVersion}"
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/net/teumteum/core/advice/GlobalExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.teumteum.core.advice;

import io.sentry.Sentry;
import net.teumteum.core.error.ErrorResponse;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ErrorResponse handleException(Exception exception) {
Sentry.captureException(exception);
return ErrorResponse.of(exception);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.teumteum.meeting.controller;

import io.sentry.Sentry;
import lombok.RequiredArgsConstructor;
import net.teumteum.core.error.ErrorResponse;
import net.teumteum.core.security.service.SecurityService;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void deleteParticipant(@PathVariable("meetingId") Long meetingId) {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(IllegalArgumentException.class)
public ErrorResponse handleIllegalArgumentException(IllegalArgumentException illegalArgumentException) {
Sentry.captureException(illegalArgumentException);
return ErrorResponse.of(illegalArgumentException);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.teumteum.user.controller;

import io.sentry.Sentry;
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -75,6 +76,7 @@ public InterestQuestionResponse getInterestQuestion(@RequestParam("user-id") Lis
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(IllegalArgumentException.class)
public ErrorResponse handleIllegalArgumentException(IllegalArgumentException illegalArgumentException) {
Sentry.captureException(illegalArgumentException);
return ErrorResponse.of(illegalArgumentException);
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ management:

### GPT ###
gpt:
token:
token:

### SENTRY ###
sentry:
dsn: https://59e89fa57d11ed7a7887bcf404179150@o4506545306271744.ingest.sentry.io/4506545307320320
traces-sample-rate: 1.0

## LOGGING
logging:
Expand Down

0 comments on commit 731fdd6

Please sign in to comment.