From 6a00e0db90e1aa92c18c35ff71b931906a4325ee Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 21 Jan 2023 17:16:54 -0600 Subject: [PATCH] Filter useless PG Errors from coming to Sentry --- .../Instrumentation/Sentry/SentryTarget.cs | 22 +++++++++++++++++++ src/NzbDrone.Common/Prowlarr.Common.csproj | 1 + 2 files changed, 23 insertions(+) diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs index 2ba30e338..5515b335c 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs @@ -8,6 +8,7 @@ using System.Threading; using NLog; using NLog.Common; using NLog.Targets; +using Npgsql; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; using Sentry; @@ -34,6 +35,14 @@ namespace NzbDrone.Common.Instrumentation.Sentry SQLiteErrorCode.Auth }; + private static readonly HashSet FilteredPostgresErrorCodes = new HashSet + { + PostgresErrorCodes.OutOfMemory, + PostgresErrorCodes.TooManyConnections, + PostgresErrorCodes.DiskFull, + PostgresErrorCodes.ProgramLimitExceeded + }; + // use string and not Type so we don't need a reference to the project // where these are defined private static readonly HashSet FilteredExceptionTypeNames = new HashSet @@ -239,6 +248,19 @@ namespace NzbDrone.Common.Instrumentation.Sentry return false; } + var pgEx = logEvent.Exception as PostgresException; + if (pgEx != null && FilteredPostgresErrorCodes.Contains(pgEx.SqlState)) + { + return false; + } + + // We don't care about transient network and timeout errors + var npgEx = logEvent.Exception as NpgsqlException; + if (npgEx != null && npgEx.IsTransient) + { + return false; + } + if (FilteredExceptionTypeNames.Contains(logEvent.Exception.GetType().Name)) { return false; diff --git a/src/NzbDrone.Common/Prowlarr.Common.csproj b/src/NzbDrone.Common/Prowlarr.Common.csproj index 66ea583ee..02bfadf2f 100644 --- a/src/NzbDrone.Common/Prowlarr.Common.csproj +++ b/src/NzbDrone.Common/Prowlarr.Common.csproj @@ -10,6 +10,7 @@ +