Reputation: 1353
I need to prevent sending some events by condition. (health check)
I'm using spring libraries:
implementation "io.sentry:sentry-spring-boot-starter:5.4.1"
implementation "io.sentry:sentry-logback:5.4.1"
It works, sentry has a lot of transactions etc. The configuration is:
sentry:
dsn: https://....ingest.sentry.io/....
traces-sample-rate: 1.0
I'm going to prevent some events which has health check data using event processor: https://docs.sentry.io/platforms/java/guides/spring-boot/advanced-usage/#registering-custom-event-processor
@Component
public class SentryCallbackExtension implements EventProcessor {
@Value("${app.sentry.exclude.transactions}")
private List<String> excludes;
@Override
public @Nullable SentryEvent process(@NotNull SentryEvent event, @Nullable Object hint) {
return StringUtils.containsAnyIgnoreCase(
event.getTransaction(), excludes.toArray(new String[0])
) ? null : event;
}
}
Configuration for this block is:
app:
sentry:
exclude:
transactions: "/actuator/health"
And it doesn't work. There are a lot of health check events in sentry service.
Upvotes: 2
Views: 1083
Reputation: 1353
I used TracesSamplerCallback (https://docs.sentry.io/platforms/java/guides/spring-boot/configuration/filtering/#using-sampling-to-filter-transaction-events) and it helps. It can prevent all events/transactions (not only custom from application).
@Component
public class SentryTraceSamplerCallback implements TracesSamplerCallback {
/**
* Excludes transaction paths
*/
@Value("${tn.sentry.exclude.transactions}")
private List<String> excludes;
@Override
@SuppressWarnings("ConstantConditions")
public @Nullable Double sample(@NotNull SamplingContext context) {
HttpServletRequest request = (HttpServletRequest) context.getCustomSamplingContext().get("request");
String url = request.getRequestURI();
return StringUtils.containsAnyIgnoreCase(url, this.excludes.toArray(String[]::new)) ? 0.0D : 1.0D;
}
}
Upvotes: 3
Reputation: 12932
EventProcessor
interface has two methods:
SentryEvent process(SentryEvent event, Object hint)
- for processing eventsSentryTransaction process(SentryTransaction transaction, Object hint)
- for processing transactionsSince you want to filter out transactions created from requests to the health endpoint, you need to implement the second method that takes SentryTransaction
as the first parameter.
Upvotes: 0