Skip to content

Apply review feedback: use class reference and add unit tests#203

Merged
buckett merged 2 commits intoAB#111014from
copilot/sub-pr-202
Feb 17, 2026
Merged

Apply review feedback: use class reference and add unit tests#203
buckett merged 2 commits intoAB#111014from
copilot/sub-pr-202

Conversation

Copy link

Copilot AI commented Feb 17, 2026

Applies review feedback from PR #202 to improve maintainability and test coverage of the Sentry logging filter configuration.

Changes:

  • Replace hard-coded logger string with DefaultHandlerExceptionResolver.class.getName() to prevent typos and stay in sync with refactoring
  • Extract filtering logic into static filterEvent() method for testability
  • Add unit tests covering filtered events (excluded logger), pass-through events (other loggers), and null logger handling
@Configuration
public class SentryLoggingFilterConfiguration {
    private static final String EXCLUDED_LOGGER =
            DefaultHandlerExceptionResolver.class.getName();

    static SentryEvent filterEvent(SentryEvent event) {
        if (EXCLUDED_LOGGER.equals(event.getLogger())) {
            return null;  // Drop excluded events
        }
        return event;
    }

    @Bean
    public SentryOptions.BeforeSendCallback sentryBeforeSendCallback() {
        return (event, hint) -> filterEvent(event);
    }
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: buckett <5921+buckett@users.noreply.github.com>
Copilot AI changed the title [WIP] Add Sentry filter to ignore DefaultHandlerExceptionResolver logs Apply review feedback: use class reference and add unit tests Feb 17, 2026
Copilot AI requested a review from buckett February 17, 2026 12:08
@buckett buckett marked this pull request as ready for review February 17, 2026 12:10
Copilot AI review requested due to automatic review settings February 17, 2026 12:10
@buckett buckett merged commit d62e2ad into AB#111014 Feb 17, 2026
@buckett buckett deleted the copilot/sub-pr-202 branch February 17, 2026 12:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves the Sentry “before send” filtering configuration by making the excluded logger reference refactor-safe and by extracting the filter logic into a testable method, with unit tests added to validate the behavior.

Changes:

  • Replaced a hard-coded excluded logger string with DefaultHandlerExceptionResolver.class.getName().
  • Extracted filtering logic into a static filterEvent(SentryEvent) helper for reuse/testability.
  • Added JUnit tests covering excluded logger, non-excluded logger, and null logger cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/java/uk/ac/ox/ctl/SentryLoggingFilterConfiguration.java Uses a class-based logger name and routes callback logic through a testable filterEvent() method.
src/test/java/uk/ac/ox/ctl/SentryLoggingFilterConfigurationTest.java Adds unit coverage for filtered vs pass-through behavior (including null logger).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +30
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");
}
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.
Comment on lines +33 to +40
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");
}
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants