Skip to content

Commit cbff2cf

Browse files
authored
feat: Sentry와 SpringBoot 로깅 프레임워크(log4j2) 연동 (#115)
* [BOOK-295] chore: buildSrc - Sentry 관련 의존성 추가 * [BOOK-295] feat: apis, infra - InfraConfig에 센트리 활성화 및 환경변수 주입 클래스 구현 * [BOOK-295] feat: infra - log4j2-spring.xml에 SentryAppender 추가 * [BOOK-295] chore: yml 파일에 관련 환경변수 세팅 및 모듈 별로 센트리 에러를 감지하도록 구현 * [BOOK-295] refactor: RollingFile 옵션 제거 * [BOOK-295] chore: Sentry Appender에 level 옵션 제거 * [BOOK-295] refactor: 코드레빗 리뷰 반영
1 parent b603502 commit cbff2cf

File tree

11 files changed

+96
-22
lines changed

11 files changed

+96
-22
lines changed

admin/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ springdoc:
3434
enabled: true
3535
override-with-generic-response: false
3636

37+
app:
38+
module-name: admin
39+
3740
---
3841
spring:
3942
config:

apis/src/main/kotlin/org/yapp/apis/config/InfraConfig.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import org.yapp.infra.InfraBaseConfigGroup
1313
InfraBaseConfigGroup.REST_CLIENT,
1414
InfraBaseConfigGroup.QUERY_DSL,
1515
InfraBaseConfigGroup.PAGE,
16-
InfraBaseConfigGroup.AOP
16+
InfraBaseConfigGroup.AOP,
17+
InfraBaseConfigGroup.SENTRY
1718
]
1819
)
1920
class InfraConfig

apis/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ springdoc:
4242
enabled: true
4343
override-with-generic-response: false
4444

45+
app:
46+
module-name: apis
47+
4548
---
4649
spring:
4750
config:

batch/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ spring:
2323
max-file-size: 10MB
2424
max-request-size: 30MB
2525

26+
app:
27+
module-name: batch
28+
2629
---
2730
spring:
2831
config:

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ object Dependencies {
7070
object Prometheus {
7171
const val MICROMETER_PROMETHEUS_REGISTRY = "io.micrometer:micrometer-registry-prometheus"
7272
}
73+
74+
object Sentry {
75+
const val SPRING_BOOT_STARTER = "io.sentry:sentry-spring-boot-starter-jakarta:8.22.0"
76+
const val LOG4J2 = "io.sentry:sentry-log4j2:8.22.0"
77+
}
7378
}

infra/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ dependencies {
1717

1818
implementation(Dependencies.QueryDsl.JPA)
1919

20+
implementation(Dependencies.Sentry.SPRING_BOOT_STARTER)
21+
implementation(Dependencies.Sentry.LOG4J2)
22+
2023
kapt(Dependencies.QueryDsl.APT)
2124

2225
testImplementation(Dependencies.Spring.BOOT_STARTER_TEST)

infra/src/main/kotlin/org/yapp/infra/InfraBaseConfigGroup.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.yapp.infra.config.internal.async.AsyncConfig
77
import org.yapp.infra.config.internal.jpa.JpaConfig
88
import org.yapp.infra.config.internal.page.PageConfig
99
import org.yapp.infra.config.internal.querydsl.QuerydslConfig
10+
import org.yapp.infra.config.external.sentry.SentryConfig
1011

1112
enum class InfraBaseConfigGroup(
1213
val configClass: Class<out InfraBaseConfig>
@@ -17,5 +18,6 @@ enum class InfraBaseConfigGroup(
1718
REDIS(RedisConfig::class.java),
1819
REST_CLIENT(RestClientConfig::class.java),
1920
QUERY_DSL(QuerydslConfig::class.java),
20-
AOP(AopConfig::class.java)
21+
AOP(AopConfig::class.java),
22+
SENTRY(SentryConfig::class.java)
2123
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.yapp.infra.config.external.sentry
2+
3+
import io.sentry.Sentry
4+
import io.sentry.SentryOptions
5+
import org.springframework.beans.factory.annotation.Value
6+
import org.springframework.boot.context.properties.EnableConfigurationProperties
7+
import org.springframework.context.annotation.Bean
8+
import org.springframework.context.annotation.Configuration
9+
import org.yapp.infra.InfraBaseConfig
10+
11+
@Configuration
12+
@EnableConfigurationProperties(SentryProperties::class)
13+
class SentryConfig(
14+
private val sentryProperties: SentryProperties,
15+
@Value("\${app.module-name}")
16+
private val moduleName: String
17+
) : InfraBaseConfig {
18+
19+
@Bean
20+
fun sentryOptionsCustomizer(): Sentry.OptionsConfiguration<SentryOptions> {
21+
return Sentry.OptionsConfiguration { options: SentryOptions ->
22+
if (sentryProperties.dsn.isBlank()) {
23+
options.isEnabled = false
24+
return@OptionsConfiguration
25+
}
26+
27+
options.dsn = sentryProperties.dsn
28+
options.environment = sentryProperties.environment
29+
options.serverName = sentryProperties.serverName
30+
options.setTag("module", moduleName)
31+
}
32+
}
33+
}
34+
35+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.yapp.infra.config.external.sentry
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties
4+
5+
@ConfigurationProperties(prefix = "sentry")
6+
data class SentryProperties(
7+
val dsn: String,
8+
val environment: String,
9+
val serverName: String,
10+
)

infra/src/main/resources/application-crosscutting.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ logging:
1010
controller:
1111
enabled: true
1212

13+
sentry:
14+
dsn: ${SENTRY_DSN}
15+
environment: ${SENTRY_ENVIRONMENT}
16+
server-name: ${SENTRY_SERVER_NAME}
17+
traces-sample-rate: 1.0
18+
send-default-pii: true
19+
logs:
20+
enabled: true
21+
logging:
22+
minimum-event-level: error
23+
minimum-breadcrumb-level: info
24+
1325
---
1426
spring:
1527
config:
@@ -25,3 +37,15 @@ logging:
2537
max-log-length: 500
2638
controller:
2739
enabled: true
40+
41+
sentry:
42+
dsn:
43+
environment: test
44+
server-name: reed-test
45+
traces-sample-rate: 1.0
46+
send-default-pii: true
47+
logs:
48+
enabled: true
49+
logging:
50+
minimum-event-level: error
51+
minimum-breadcrumb-level: info

0 commit comments

Comments
 (0)