Skip to content

Commit

Permalink
chore: Sentry 에러 모니터링 적용 (#707)
Browse files Browse the repository at this point in the history
* chore: sentry 플러그인 추가

* chore: Sentry 프로파일 추가

* chore: 도커 이미지 태그를 환경변수로 받아서 매핑

* chore: 도커 이미지 태그를 센트리 포맷에 맞춰서 바인딩

* style: spotless 적용

* chore: 로그백 센트리 디펜던시 추가

* chore: 사용자 정보 로깅 추가

* feat: 메서드 이름 변경 및 출력문 제거
  • Loading branch information
uwoobeat authored Aug 29, 2024
1 parent 8b779f8 commit 9723ee0
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'io.spring.dependency-management' version '1.1.4'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'com.diffplug.spotless' version '6.23.3'
id "io.sentry.jvm.gradle" version "4.11.0"
}

group = 'com.gdschongik'
Expand Down Expand Up @@ -95,6 +96,9 @@ dependencies {

// Github
implementation 'org.kohsuke:github-api:1.323'

// Sentry
implementation 'io.sentry:sentry-logback:7.14.0'
}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- .env
environment:
- TZ=Asia/Seoul
- DOCKER_IMAGE_TAG=${IMAGE_FULL_URL}
redis:
image: "redis:alpine"
container_name: redis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.global.property.BasicAuthProperty;
import com.gdschongik.gdsc.global.property.DiscordProperty;
import com.gdschongik.gdsc.global.property.DockerProperty;
import com.gdschongik.gdsc.global.property.EmailProperty;
import com.gdschongik.gdsc.global.property.GithubProperty;
import com.gdschongik.gdsc.global.property.JwtProperty;
Expand All @@ -17,7 +18,8 @@
DiscordProperty.class,
EmailProperty.class,
PaymentProperty.class,
GithubProperty.class
GithubProperty.class,
DockerProperty.class
})
@Configuration
public class PropertyConfig {}
38 changes: 38 additions & 0 deletions src/main/java/com/gdschongik/gdsc/global/config/SentryConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.gdschongik.gdsc.global.config;

import com.gdschongik.gdsc.global.property.DockerProperty;
import io.sentry.Sentry;
import io.sentry.SentryOptions;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
public class SentryConfig {

private final DockerProperty dockerProperty;

@Bean
Sentry.OptionsConfiguration<SentryOptions> customOptionsConfiguration() {
return options -> {
options.setRelease(convertTagToRelease(dockerProperty.getTag()));
};
}

// gdscrepo/gdsc-server:v1.0.0 -> [email protected]
// gdscrepo/gdsc-server:ffffff -> gdsc-server@ffffff
private String convertTagToRelease(String tag) {
if (tag.isBlank()) {
return "gdsc-server";
}

String imageWithVersion = tag.split("/")[1]; // gdsc-server:v1.0.0
String[] split = imageWithVersion.split(":"); // [gdsc-server, v1.0.0]
String version = split[1]; // v1.0.0 or ffffff (commit hash)
if (version.startsWith("v")) {
version = version.substring(1); // 1.0.0
}
return split[0] + "@" + version; // [email protected]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gdschongik.gdsc.global.property;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@RequiredArgsConstructor
@ConfigurationProperties(prefix = "docker")
public class DockerProperty {
private final String tag;
}
17 changes: 17 additions & 0 deletions src/main/resources/application-sentry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
config:
activate:
on-profile: "sentry"

sentry:
dsn: ${SENTRY_DSN:}
traces-sample-rate: 1.0
exception-resolver-order: -2147483647
environment: ${spring.profiles.active:local}
send-default-pii: true
logging:
minimum-event-level: info
minimum-breadcrumb-level: debug

docker:
tag: ${DOCKER_IMAGE_TAG:}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spring:
- email
- payment
- github
- sentry

logging:
level:
Expand Down

0 comments on commit 9723ee0

Please sign in to comment.