From 8c7a7e507ba4a08325c0bf6fd0cf4f880163fd8d Mon Sep 17 00:00:00 2001 From: lcian Date: Fri, 24 Jan 2025 10:46:51 +0100 Subject: [PATCH] add JavaDoc, update CHANGELOG.md, don't consider `event.exceptions` --- CHANGELOG.md | 1 + .../src/main/java/io/sentry/SentryClient.java | 2 +- .../main/java/io/sentry/SentryOptions.java | 23 +++++++++++++++++++ .../main/java/io/sentry/util/ErrorUtils.java | 12 ---------- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 75f12eda14..7e8a44bbbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 .*` diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index 74f057d230..277be87aee 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -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() diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 91c159e6f6..2617cd3dfa 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -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 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 ignoredErrors) { if (ignoredErrors == null) { this.ignoredErrors = null; @@ -1597,6 +1613,13 @@ public void setIgnoredErrors(final @Nullable List 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<>(); diff --git a/sentry/src/main/java/io/sentry/util/ErrorUtils.java b/sentry/src/main/java/io/sentry/util/ErrorUtils.java index c485cbbd76..cb8b3dbce9 100644 --- a/sentry/src/main/java/io/sentry/util/ErrorUtils.java +++ b/sentry/src/main/java/io/sentry/util/ErrorUtils.java @@ -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; @@ -34,17 +33,6 @@ public static boolean isIgnored( possibleMessages.add(formattedMessage); } } - final @Nullable List 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());