Skip to content
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
15 changes: 10 additions & 5 deletions src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
Comment on lines +23 to +30
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

These tests only assert the result is non-null, but the method name implies the original event is passed through unchanged. Consider asserting the returned value is the same instance to better protect the intended behavior.

Copilot uses AI. Check for mistakes.

@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");
}
Comment on lines +33 to +40
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

This test asserts non-null, but if the intended behavior is to pass the same event through when logger is null, assert the returned value is the same instance for a stronger regression check.

Copilot uses AI. Check for mistakes.
}