Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Sentry 필터링 적용 #777

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String> KEYWORDS_TO_IGNORE = List.of(ACTUATOR_KEYWORD);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

올바른 예외 클래스 사용 필요

NoResourceFoundException 클래스는 존재하지 않을 수 있습니다. Spring MVC에서는 존재하지 않는 엔드포인트에 대한 예외로 NoHandlerFoundException을 사용합니다. 이 클래스로 수정하는 것을 권장합니다.

수정 사항 제안:

-import org.springframework.web.servlet.resource.NoResourceFoundException;
+import org.springframework.web.servlet.NoHandlerFoundException;

예외 목록에서의 변경:

-private final List<Class<? extends Throwable>> exceptionsToIgnore = List.of(
-        NoResourceFoundException.class, // 존재하지 않는 엔드포인트로 요청이 들어왔을 때
+private final List<Class<? extends Throwable>> exceptionsToIgnore = List.of(
+        NoHandlerFoundException.class, // 존재하지 않는 엔드포인트로 요청이 들어왔을 때
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import org.springframework.web.servlet.resource.NoResourceFoundException;
import org.springframework.web.servlet.NoHandlerFoundException;


@Configuration
@RequiredArgsConstructor
public class SentryConfig {

private final DockerProperty dockerProperty;

private final List<Class<? extends Throwable>> exceptionsToIgnore = List.of(
NoResourceFoundException.class, // 존재하지 않는 정적 리소스 요청
MethodArgumentNotValidException.class // @Valid 검증 실패
);

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

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application-sentry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down