Skip to content

Commit

Permalink
add JavaDoc, update CHANGELOG.md, don't consider event.exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
lcian committed Jan 24, 2025
1 parent 598770d commit 8c7a7e5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Add `options.ignoredErrors` to filter out errors that match a certain String or Regex ([#4083](https://github.com/getsentry/sentry-java/pull/4083))
- The matching is attempted on `event.message`, `event.formatted`, and `{event.throwable.class.name}: {event.throwable.message}`
- Can be set in `sentry.properties`, e.g. `ignored-errors=Some error,Another .*`
- Can be set in environment variables, e.g. `SENTRY_IGNORED_ERRORS=Some error,Another .*`
- For Spring Boot, it can be set in `application.properties`, e.g. `sentry.ignored-errors=Some error,Another .*`
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/SentryClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private boolean shouldApplyScopeData(final @NotNull CheckIn event, final @NotNul
.getLogger()
.log(
SentryLevel.DEBUG,
"Event was dropped as the error %s is ignored",
"Event was dropped as it matched a string/pattern in ignoredErrors",
event.getMessage());
options
.getClientReportRecorder()
Expand Down
23 changes: 23 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1578,10 +1578,26 @@ boolean containsIgnoredExceptionForType(final @NotNull Throwable throwable) {
return this.ignoredExceptionsForType.contains(throwable.getClass());
}

/**
* Returns the list of strings/regex patterns that `event.message`, `event.formatted`, and
* `{event.throwable.class.name}: {event.throwable.message}` are checked against to determine if
* an event shall be sent to Sentry or ignored.
*
* @return the list of strings/regex patterns that `event.message`, `event.formatted`, and
* `{event.throwable.class.name}: {event.throwable.message}` are checked against to determine
* if an event shall be sent to Sentry or ignored
*/
public @Nullable List<FilterString> getIgnoredErrors() {
return ignoredErrors;
}

/**
* Sets the list of strings/regex patterns that `event.message`, `event.formatted`, and
* `{event.throwable.class.name}: {event.throwable.message}` are checked against to determine if
* an event shall be sent to Sentry or ignored.
*
* @param ignoredErrors the list of strings/regex patterns
*/
public void setIgnoredErrors(final @Nullable List<String> ignoredErrors) {
if (ignoredErrors == null) {
this.ignoredErrors = null;
Expand All @@ -1597,6 +1613,13 @@ public void setIgnoredErrors(final @Nullable List<String> ignoredErrors) {
}
}

/**
* Adds an item to the list of strings/regex patterns that `event.message`, `event.formatted`, and
* `{event.throwable.class.name}: {event.throwable.message}` are checked against to determine if
* an event shall be sent to Sentry or ignored.
*
* @param pattern the string/regex pattern
*/
public void addIgnoredError(final @NotNull String pattern) {
if (ignoredErrors == null) {
ignoredErrors = new ArrayList<>();
Expand Down
12 changes: 0 additions & 12 deletions sentry/src/main/java/io/sentry/util/ErrorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.sentry.FilterString;
import io.sentry.SentryEvent;
import io.sentry.protocol.Message;
import io.sentry.protocol.SentryException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -34,17 +33,6 @@ public static boolean isIgnored(
possibleMessages.add(formattedMessage);
}
}
final @Nullable List<SentryException> exceptions = event.getExceptions();
if (exceptions != null && !exceptions.isEmpty()) {
for (final @Nullable SentryException exception : exceptions) {
if (exception != null) {
final @Nullable String value = exception.getValue();
if (value != null) {
possibleMessages.add(value);
}
}
}
}
final @Nullable Throwable throwable = event.getThrowable();
if (throwable != null) {
possibleMessages.add(throwable.toString());
Expand Down

0 comments on commit 8c7a7e5

Please sign in to comment.