diff --git a/admin/src/main/resources/application.yml b/admin/src/main/resources/application.yml index d6657dc1..b0b7ec80 100644 --- a/admin/src/main/resources/application.yml +++ b/admin/src/main/resources/application.yml @@ -34,6 +34,9 @@ springdoc: enabled: true override-with-generic-response: false +app: + module-name: admin + --- spring: config: diff --git a/apis/src/main/kotlin/org/yapp/apis/config/InfraConfig.kt b/apis/src/main/kotlin/org/yapp/apis/config/InfraConfig.kt index feba8433..55a765ad 100644 --- a/apis/src/main/kotlin/org/yapp/apis/config/InfraConfig.kt +++ b/apis/src/main/kotlin/org/yapp/apis/config/InfraConfig.kt @@ -13,7 +13,8 @@ import org.yapp.infra.InfraBaseConfigGroup InfraBaseConfigGroup.REST_CLIENT, InfraBaseConfigGroup.QUERY_DSL, InfraBaseConfigGroup.PAGE, - InfraBaseConfigGroup.AOP + InfraBaseConfigGroup.AOP, + InfraBaseConfigGroup.SENTRY ] ) class InfraConfig diff --git a/apis/src/main/resources/application.yml b/apis/src/main/resources/application.yml index aefd8261..235eeb20 100644 --- a/apis/src/main/resources/application.yml +++ b/apis/src/main/resources/application.yml @@ -42,6 +42,9 @@ springdoc: enabled: true override-with-generic-response: false +app: + module-name: apis + --- spring: config: diff --git a/batch/src/main/resources/application.yml b/batch/src/main/resources/application.yml index a81c9f46..35307531 100644 --- a/batch/src/main/resources/application.yml +++ b/batch/src/main/resources/application.yml @@ -23,6 +23,9 @@ spring: max-file-size: 10MB max-request-size: 30MB +app: + module-name: batch + --- spring: config: diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 8e2f999a..d5e946b6 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -70,4 +70,9 @@ object Dependencies { object Prometheus { const val MICROMETER_PROMETHEUS_REGISTRY = "io.micrometer:micrometer-registry-prometheus" } + + object Sentry { + const val SPRING_BOOT_STARTER = "io.sentry:sentry-spring-boot-starter-jakarta:8.22.0" + const val LOG4J2 = "io.sentry:sentry-log4j2:8.22.0" + } } diff --git a/infra/build.gradle.kts b/infra/build.gradle.kts index 9e63dd68..68634557 100644 --- a/infra/build.gradle.kts +++ b/infra/build.gradle.kts @@ -17,6 +17,9 @@ dependencies { implementation(Dependencies.QueryDsl.JPA) + implementation(Dependencies.Sentry.SPRING_BOOT_STARTER) + implementation(Dependencies.Sentry.LOG4J2) + kapt(Dependencies.QueryDsl.APT) testImplementation(Dependencies.Spring.BOOT_STARTER_TEST) diff --git a/infra/src/main/kotlin/org/yapp/infra/InfraBaseConfigGroup.kt b/infra/src/main/kotlin/org/yapp/infra/InfraBaseConfigGroup.kt index b1550582..6ab276e8 100644 --- a/infra/src/main/kotlin/org/yapp/infra/InfraBaseConfigGroup.kt +++ b/infra/src/main/kotlin/org/yapp/infra/InfraBaseConfigGroup.kt @@ -7,6 +7,7 @@ import org.yapp.infra.config.internal.async.AsyncConfig import org.yapp.infra.config.internal.jpa.JpaConfig import org.yapp.infra.config.internal.page.PageConfig import org.yapp.infra.config.internal.querydsl.QuerydslConfig +import org.yapp.infra.config.external.sentry.SentryConfig enum class InfraBaseConfigGroup( val configClass: Class @@ -17,5 +18,6 @@ enum class InfraBaseConfigGroup( REDIS(RedisConfig::class.java), REST_CLIENT(RestClientConfig::class.java), QUERY_DSL(QuerydslConfig::class.java), - AOP(AopConfig::class.java) + AOP(AopConfig::class.java), + SENTRY(SentryConfig::class.java) } diff --git a/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryConfig.kt b/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryConfig.kt new file mode 100644 index 00000000..82f74d52 --- /dev/null +++ b/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryConfig.kt @@ -0,0 +1,35 @@ +package org.yapp.infra.config.external.sentry + +import io.sentry.Sentry +import io.sentry.SentryOptions +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.yapp.infra.InfraBaseConfig + +@Configuration +@EnableConfigurationProperties(SentryProperties::class) +class SentryConfig( + private val sentryProperties: SentryProperties, + @Value("\${app.module-name}") + private val moduleName: String +) : InfraBaseConfig { + + @Bean + fun sentryOptionsCustomizer(): Sentry.OptionsConfiguration { + return Sentry.OptionsConfiguration { options: SentryOptions -> + if (sentryProperties.dsn.isBlank()) { + options.isEnabled = false + return@OptionsConfiguration + } + + options.dsn = sentryProperties.dsn + options.environment = sentryProperties.environment + options.serverName = sentryProperties.serverName + options.setTag("module", moduleName) + } + } +} + + diff --git a/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryProperties.kt b/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryProperties.kt new file mode 100644 index 00000000..cd1be01f --- /dev/null +++ b/infra/src/main/kotlin/org/yapp/infra/config/external/sentry/SentryProperties.kt @@ -0,0 +1,10 @@ +package org.yapp.infra.config.external.sentry + +import org.springframework.boot.context.properties.ConfigurationProperties + +@ConfigurationProperties(prefix = "sentry") +data class SentryProperties( + val dsn: String, + val environment: String, + val serverName: String, +) diff --git a/infra/src/main/resources/application-crosscutting.yml b/infra/src/main/resources/application-crosscutting.yml index 3c08e84c..de22b8b4 100644 --- a/infra/src/main/resources/application-crosscutting.yml +++ b/infra/src/main/resources/application-crosscutting.yml @@ -10,6 +10,18 @@ logging: controller: enabled: true +sentry: + dsn: ${SENTRY_DSN} + environment: ${SENTRY_ENVIRONMENT} + server-name: ${SENTRY_SERVER_NAME} + traces-sample-rate: 1.0 + send-default-pii: true + logs: + enabled: true + logging: + minimum-event-level: error + minimum-breadcrumb-level: info + --- spring: config: @@ -25,3 +37,15 @@ logging: max-log-length: 500 controller: enabled: true + +sentry: + dsn: + environment: test + server-name: reed-test + traces-sample-rate: 1.0 + send-default-pii: true + logs: + enabled: true + logging: + minimum-event-level: error + minimum-breadcrumb-level: info diff --git a/infra/src/main/resources/log4j2-spring.xml b/infra/src/main/resources/log4j2-spring.xml index b17c0030..df3ccf6b 100644 --- a/infra/src/main/resources/log4j2-spring.xml +++ b/infra/src/main/resources/log4j2-spring.xml @@ -2,14 +2,7 @@ - - - %d{yyyy-MM-dd HH:mm:ss.SSSSSS} %-5level [%thread] [%X{traceId}] [%X{userId}] [%X{clientIp}] [%X{requestInfo}] %logger{36} - %msg%n - - - - %d{yyyy-MM-dd HH:mm:ss.SSSSSS} %highlight{%-5level}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{[%thread]}{cyan} %style{[%X{traceId}]}{green} %style{[%X{userId}]}{magenta} %style{[%X{clientIp}]}{blue} %style{[%X{requestInfo}]}{yellow} %style{%logger{36}}{bright,white} - %msg%n - + %d{yyyy-MM-dd HH:mm:ss.SSSSSS} %highlight{%-5level}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{[%thread]}{cyan} %style{[%X{traceId}]}{green} %style{[%X{userId}]}{magenta} %style{[%X{clientIp}]}{blue} %style{[%X{requestInfo}]}{yellow} %style{%logger{36}}{bright,white} - %msg%n @@ -18,29 +11,21 @@ - - - - - - - - - + + - + - +