From 73fb8d87a072921dfe0246a07709eb970eda8b81 Mon Sep 17 00:00:00 2001 From: Matthew Buckett Date: Tue, 17 Feb 2026 11:55:14 +0000 Subject: [PATCH 1/3] AB#111014 Ignore the DefaultHandlerExceptionResolver for sentry This prevents the DefaultHandlerExceptionResolver from sending it's log lines to sentry, they are still logged in the application logs (in case we hit problems and they provide something useful). --- .../ctl/SentryLoggingFilterConfiguration.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java diff --git a/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java b/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java new file mode 100644 index 0000000..a2edacf --- /dev/null +++ b/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java @@ -0,0 +1,27 @@ +package uk.ac.ox.ctl; + +import io.sentry.Hint; +import io.sentry.SentryEvent; +import io.sentry.SentryOptions; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SentryLoggingFilterConfiguration { + + private static final String EXCLUDED_LOGGER = + "org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver"; + + @Bean + public SentryOptions.BeforeSendCallback sentryBeforeSendCallback() { + return new SentryOptions.BeforeSendCallback() { + @Override + public SentryEvent execute(SentryEvent event, Hint hint) { + if (EXCLUDED_LOGGER.equals(event.getLogger())) { + return null; + } + return event; + } + }; + } +} From 0e38fd0c79f536fe6e3d7a29b47702eb6d92f08b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 12:01:06 +0000 Subject: [PATCH 2/3] Initial plan From 4249804e7853cdee9739e82c8eddbd3613e54354 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 12:04:45 +0000 Subject: [PATCH 3/3] Apply review feedback: use class name and add unit tests Co-authored-by: buckett <5921+buckett@users.noreply.github.com> --- .../ctl/SentryLoggingFilterConfiguration.java | 15 ++++--- .../SentryLoggingFilterConfigurationTest.java | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/test/java/uk/ac/ox/ctl/SentryLoggingFilterConfigurationTest.java diff --git a/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java b/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java index a2edacf..28747c3 100644 --- a/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java +++ b/src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java @@ -5,22 +5,27 @@ import io.sentry.SentryOptions; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; @Configuration public class SentryLoggingFilterConfiguration { private static final String EXCLUDED_LOGGER = - "org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver"; + DefaultHandlerExceptionResolver.class.getName(); + + static SentryEvent filterEvent(SentryEvent event) { + if (EXCLUDED_LOGGER.equals(event.getLogger())) { + return null; + } + return event; + } @Bean public SentryOptions.BeforeSendCallback sentryBeforeSendCallback() { return new SentryOptions.BeforeSendCallback() { @Override public SentryEvent execute(SentryEvent event, Hint hint) { - if (EXCLUDED_LOGGER.equals(event.getLogger())) { - return null; - } - return event; + return filterEvent(event); } }; } diff --git a/src/test/java/uk/ac/ox/ctl/SentryLoggingFilterConfigurationTest.java b/src/test/java/uk/ac/ox/ctl/SentryLoggingFilterConfigurationTest.java new file mode 100644 index 0000000..b873010 --- /dev/null +++ b/src/test/java/uk/ac/ox/ctl/SentryLoggingFilterConfigurationTest.java @@ -0,0 +1,41 @@ +package uk.ac.ox.ctl; + +import io.sentry.SentryEvent; +import org.junit.jupiter.api.Test; +import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +class SentryLoggingFilterConfigurationTest { + + @Test + void filterEvent_shouldReturnNull_whenLoggerIsDefaultHandlerExceptionResolver() { + SentryEvent event = new SentryEvent(); + event.setLogger(DefaultHandlerExceptionResolver.class.getName()); + + SentryEvent result = SentryLoggingFilterConfiguration.filterEvent(event); + + assertNull(result, "Event should be filtered (null) when logger is DefaultHandlerExceptionResolver"); + } + + @Test + void filterEvent_shouldReturnEvent_whenLoggerIsNotExcluded() { + SentryEvent event = new SentryEvent(); + event.setLogger("com.example.SomeOtherLogger"); + + SentryEvent result = SentryLoggingFilterConfiguration.filterEvent(event); + + assertNotNull(result, "Event should not be filtered when logger is not excluded"); + } + + @Test + void filterEvent_shouldReturnEvent_whenLoggerIsNull() { + SentryEvent event = new SentryEvent(); + event.setLogger(null); + + SentryEvent result = SentryLoggingFilterConfiguration.filterEvent(event); + + assertNotNull(result, "Event should not be filtered when logger is null"); + } +}