Skip to content

Commit df491eb

Browse files
committed
[feat] sentry 추가
1 parent 2a16bf1 commit df491eb

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ dependencies {
4040
//swagger-ui
4141
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
4242

43+
//sentry
44+
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:7.14.0'
4345
}
4446

4547
tasks.named('test') {

docker-compose-dev.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ services:
1212
- SPRING_DATASOURCE_URL=jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}/${DB_NAME}?useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Seoul&allowPublicKeyRetrieval=true&tinyInt1isBit=false
1313
- SPRING_DATASOURCE_USERNAME=${MYSQL_USERNAME}
1414
- SPRING_DATASOURCE_PASSWORD=${MYSQL_PASSWORD}
15+
- SENTRY_DSN=${SENTRY_DSN}
1516
depends_on:
1617
- mysql
1718
networks:

src/main/java/com/moplus/moplus_server/MoplusServerApplication.java

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.moplus.moplus_server;
22

3+
import io.sentry.Sentry;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.moplus.moplus_server.global.config.sentry;
2+
3+
import io.sentry.Sentry;
4+
import io.sentry.SentryOptions;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
@Configuration
10+
public class SentryConfig {
11+
12+
@Value("${sentry.dsn}")
13+
private String dsn;
14+
15+
@Bean
16+
public Sentry.OptionsConfiguration<SentryOptions> sentryOptions() {
17+
return options -> {
18+
options.setDsn(dsn);
19+
options.setSampleRate(1.0); // 모든 이벤트를 100% 수집
20+
options.setDebug(true); // 디버그 모드 활성화
21+
options.setBeforeSend((event, hint) -> {
22+
return event;
23+
});
24+
};
25+
}
26+
}

src/main/java/com/moplus/moplus_server/global/error/GlobalExceptionHandler.java

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.moplus.moplus_server.global.error.exception.BusinessException;
44
import com.moplus.moplus_server.global.error.exception.ErrorCode;
55
import com.moplus.moplus_server.global.error.exception.NotFoundException;
6+
import io.sentry.Sentry;
67
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.http.HttpStatus;
89
import org.springframework.http.ResponseEntity;
@@ -20,6 +21,8 @@ protected ResponseEntity<ErrorResponse> handleBusinessException(final BusinessEx
2021
log.error("handleBusinessException", exception);
2122
final ErrorCode errorCode = exception.getErrorCode();
2223
final ErrorResponse response = ErrorResponse.from(errorCode);
24+
Sentry.captureException(exception);
25+
2326
return new ResponseEntity<>(response, errorCode.getStatus());
2427
}
2528

@@ -33,6 +36,7 @@ protected ResponseEntity<ErrorResponse> handleEntityNotFoundException(final NotF
3336
log.error("handleEntityNotFoundException", exception);
3437
final ErrorCode errorCode = exception.getErrorCode();
3538
final ErrorResponse response = ErrorResponse.from(exception.getErrorCode());
39+
Sentry.captureException(exception);
3640
return new ResponseEntity<>(response, errorCode.getStatus());
3741
}
3842

@@ -41,6 +45,7 @@ protected ResponseEntity<ErrorResponse> handleEntityNotFoundException(final NotF
4145
protected ResponseEntity<ErrorResponse> handleException(final Exception exception) {
4246
log.error(exception.getMessage(), exception);
4347
final ErrorResponse response = ErrorResponse.from(ErrorCode.INTERNAL_SERVER_ERROR);
48+
Sentry.captureException(exception);
4449
return new ResponseEntity<>(response, response.getStatus());
4550
}
4651
}

src/main/resources/application.yml

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ spring:
44
group:
55
local: "local, datasource"
66
dev: "dev, datasource"
7+
8+
sentry:
9+
dsn: ${SENTRY_DSN}
10+
enable-tracing: true
11+
tracesSampleRate: 1.0
12+
debug: true
13+
environment: local

0 commit comments

Comments
 (0)