Skip to content

Commit

Permalink
chore: Sentry 필터링 적용 (#777)
Browse files Browse the repository at this point in the history
* chore: 불필요한 예외 캡쳐 대상에서 제외

* chore: warn 레벨부터 캡쳐

* chore: 액추에이터 엔드포인트 이벤트 전송 제외

* docs: 주석 수정
  • Loading branch information
uwoobeat authored Sep 18, 2024
1 parent e60e0d9 commit add30b8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
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;

@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

0 comments on commit add30b8

Please sign in to comment.