diff --git a/src/main/java/com/gdschongik/gdsc/global/common/constant/SentryConstant.java b/src/main/java/com/gdschongik/gdsc/global/common/constant/SentryConstant.java new file mode 100644 index 000000000..ff46df3d1 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/global/common/constant/SentryConstant.java @@ -0,0 +1,12 @@ +package com.gdschongik.gdsc.global.common.constant; + +import java.util.List; + +public class SentryConstant { + + private SentryConstant() {} + + public static final String ACTUATOR_KEYWORD = "actuator"; + + public static final List KEYWORDS_TO_IGNORE = List.of(ACTUATOR_KEYWORD); +} diff --git a/src/main/java/com/gdschongik/gdsc/global/config/SentryConfig.java b/src/main/java/com/gdschongik/gdsc/global/config/SentryConfig.java index 7860fe1d7..e9d65580a 100644 --- a/src/main/java/com/gdschongik/gdsc/global/config/SentryConfig.java +++ b/src/main/java/com/gdschongik/gdsc/global/config/SentryConfig.java @@ -3,9 +3,12 @@ import com.gdschongik.gdsc.global.property.DockerProperty; import io.sentry.Sentry; import io.sentry.SentryOptions; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.servlet.resource.NoResourceFoundException; @Configuration @RequiredArgsConstructor @@ -13,10 +16,16 @@ public class SentryConfig { private final DockerProperty dockerProperty; + private final List> exceptionsToIgnore = List.of( + NoResourceFoundException.class, // 존재하지 않는 정적 리소스 요청 + MethodArgumentNotValidException.class // @Valid 검증 실패 + ); + @Bean Sentry.OptionsConfiguration customOptionsConfiguration() { return options -> { options.setRelease(convertTagToRelease(dockerProperty.getTag())); + exceptionsToIgnore.forEach(options::addIgnoredExceptionForType); }; } diff --git a/src/main/java/com/gdschongik/gdsc/infra/sentry/CustomBeforeSendTransactionCallback.java b/src/main/java/com/gdschongik/gdsc/infra/sentry/CustomBeforeSendTransactionCallback.java new file mode 100644 index 000000000..3f9958404 --- /dev/null +++ b/src/main/java/com/gdschongik/gdsc/infra/sentry/CustomBeforeSendTransactionCallback.java @@ -0,0 +1,28 @@ +package com.gdschongik.gdsc.infra.sentry; + +import static com.gdschongik.gdsc.global.common.constant.SentryConstant.*; + +import io.sentry.Hint; +import io.sentry.SentryOptions; +import io.sentry.protocol.SentryTransaction; +import org.jetbrains.annotations.NotNull; +import org.springframework.stereotype.Component; + +@Component +public class CustomBeforeSendTransactionCallback implements SentryOptions.BeforeSendTransactionCallback { + + @Override + public SentryTransaction execute(@NotNull SentryTransaction transaction, @NotNull Hint hint) { + String transactionEndpoint = transaction.getTransaction(); + + if (transactionEndpoint == null) { + return transaction; + } + + if (KEYWORDS_TO_IGNORE.stream().anyMatch(transactionEndpoint::contains)) { + return null; + } + + return transaction; + } +} diff --git a/src/main/resources/application-sentry.yml b/src/main/resources/application-sentry.yml index c25bb6390..1c199cb5d 100644 --- a/src/main/resources/application-sentry.yml +++ b/src/main/resources/application-sentry.yml @@ -10,7 +10,7 @@ sentry: environment: ${spring.profiles.active:local} send-default-pii: true logging: - minimum-event-level: info + minimum-event-level: warn minimum-breadcrumb-level: debug docker: