How to programatically (java) prevent specific errors messages to be sent to Sentry? I want, for example, not send to Sentry errors with the word “some_error_message”.
I’m using Sentry 1.7.23, and my application runs over thorntail and it uses jdk 1.8.0_251.
@WebListener
public class MyContextListener implements ServletContextListener {
private static SentryClient sentryClient = SentryClientFactory.sentryClient();
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
Sentry.init();
String testStrings = "ipsis litteris;some_error_message";
String[] messagesToIgnore = StringUtils.split(testStrings, ';');
sentryClient.addShouldSendEventCallback(new ShouldSendEventCallback() {
@Override
public boolean shouldSend(Event event) {
for (Map.Entry<String, SentryInterface> interfaceEntry : event.getSentryInterfaces().entrySet()) {
if (interfaceEntry.getValue() instanceof ExceptionInterface) {
ExceptionInterface i = (ExceptionInterface) interfaceEntry.getValue();
for (SentryException sentryException : i.getExceptions()) {
for (String msgToIgnore : messagesToIgnore) {
if (StringUtils.contains(sentryException.getExceptionMessage(), msgToIgnore)) {
return false;
}
}
}
}
}
return true;
}
});
Sentry.setStoredClient(sentryClient);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}
Is a ServletContextListener the correct place to initialize Sentry? I’m asking this because, at some point during app execution, my sentryClient is lost and the messages are not filtered.
Also, is this the correct way to perform the filtering in this version?