-
Notifications
You must be signed in to change notification settings - Fork 35
Discard classes as patterns #248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
richardelms
wants to merge
10
commits into
integration/uplift-2025
Choose a base branch
from
discardClassesAsPatterns
base: integration/uplift-2025
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82df229
initial change
richardelms aed4bf7
tests
richardelms 27a926f
syntax fix
richardelms 67a925b
Update features/fixtures/scenarios/src/main/java/com/bugsnag/mazerunn…
richardelms 374cd91
review changes
richardelms 96b9733
Merge branch 'discardClassesAsPatterns' of github.com:bugsnag/bugsnag…
richardelms 859b52c
remove md file
richardelms d0a8b22
convert away from blob
richardelms fd79d6d
full pattern support
richardelms d40d29c
refac
richardelms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
bugsnag/src/test/java/com/bugsnag/ConfigurationDiscardClassesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package com.bugsnag; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Test for Configuration.shouldIgnoreClass with regex pattern matching | ||
| */ | ||
| public class ConfigurationDiscardClassesTest { | ||
|
|
||
| private Configuration config; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| config = new Configuration("test-api-key"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExactMatch() { | ||
| config.setDiscardClasses(new Pattern[] {Pattern.compile("com.example.CustomException")}); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("com.example.CustomException")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.OtherException")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testWildcardMatch() { | ||
| config.setDiscardClasses(new Pattern[] {Pattern.compile("com\\.example\\..*")}); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("com.example.CustomException")); | ||
| assertTrue(config.shouldIgnoreClass("com.example.OtherException")); | ||
| assertTrue(config.shouldIgnoreClass("com.example.")); | ||
| assertFalse(config.shouldIgnoreClass("com.other.Exception")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMultipleWildcards() { | ||
| config.setDiscardClasses(new Pattern[] {Pattern.compile("com\\..*\\.Exception")}); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("com.example.Exception")); | ||
| assertTrue(config.shouldIgnoreClass("com.other.Exception")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.CustomException")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQuestionMarkWildcard() { | ||
| config.setDiscardClasses(new Pattern[] {Pattern.compile("com\\.example\\.Exception.")}); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("com.example.Exception1")); | ||
| assertTrue(config.shouldIgnoreClass("com.example.ExceptionX")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.Exception")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.Exception12")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMultiplePatterns() { | ||
| config.setDiscardClasses(new Pattern[] { | ||
| Pattern.compile("java\\.io\\..*"), | ||
| Pattern.compile("com\\.example\\.CustomException"), | ||
| Pattern.compile("org\\..*\\.SpecialException") | ||
| }); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("java.io.IOException")); | ||
| assertTrue(config.shouldIgnoreClass("java.io.FileNotFoundException")); | ||
| assertTrue(config.shouldIgnoreClass("com.example.CustomException")); | ||
| assertTrue(config.shouldIgnoreClass("org.apache.SpecialException")); | ||
| assertTrue(config.shouldIgnoreClass("org.springframework.SpecialException")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.OtherException")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetDiscardClassesReturnsOriginalPatterns() { | ||
| Pattern[] patterns = new Pattern[] { | ||
| Pattern.compile("com\\.example\\..*"), | ||
| Pattern.compile("java\\.io\\.IOException") | ||
| }; | ||
| config.setDiscardClasses(patterns); | ||
|
|
||
| Pattern[] retrieved = config.getDiscardClasses(); | ||
| assertEquals(2, retrieved.length); | ||
|
|
||
| // Check that patterns are returned | ||
| boolean hasWildcard = false; | ||
| boolean hasExact = false; | ||
| for (Pattern pattern : retrieved) { | ||
| if (pattern.pattern().equals("com\\.example\\..*")) { | ||
| hasWildcard = true; | ||
| } | ||
| if (pattern.pattern().equals("java\\.io\\.IOException")) { | ||
| hasExact = true; | ||
| } | ||
| } | ||
| assertTrue(hasWildcard); | ||
| assertTrue(hasExact); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEmptyAndNullPatterns() { | ||
| config.setDiscardClasses(new Pattern[] {}); | ||
| assertFalse(config.shouldIgnoreClass("com.example.Exception")); | ||
|
|
||
| config.setDiscardClasses(null); | ||
| assertFalse(config.shouldIgnoreClass("com.example.Exception")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSpecialCharactersAreEscaped() { | ||
| // In regex, $ is a special character (end of line), so it needs to be escaped | ||
| config.setDiscardClasses(new Pattern[] {Pattern.compile("com\\.example\\.Exception\\$Inner")}); | ||
|
|
||
| assertTrue(config.shouldIgnoreClass("com.example.Exception$Inner")); | ||
| assertFalse(config.shouldIgnoreClass("com.example.ExceptionXInner")); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
features/fixtures/logback/ignored_class_wildcard_config.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <configuration> | ||
| <include resource="org/springframework/boot/logging/logback/base.xml" /> | ||
|
|
||
| <appender name="BUGSNAG" class="com.bugsnag.BugsnagAppender"> | ||
| <apiKey>a35a2a72bd230ac0aa0f52715bbdc6aa</apiKey> | ||
| <releaseStage>production</releaseStage> | ||
| <appVersion>1.0.0</appVersion> | ||
|
|
||
| <discardClass>java\.lang\..*</discardClass> | ||
|
|
||
| <endpoint>http://localhost:9339/notify</endpoint> | ||
| </appender> | ||
|
|
||
| <root level="INFO"> | ||
| <appender-ref ref="BUGSNAG"/> | ||
| </root> | ||
| </configuration> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear why we have the
discardClassStringPatternshere at all. It's written to, but we never seem to read from it?