1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-10-05 15:47:20 +02:00

Better Sentry Filtering for AggregateException children

This commit is contained in:
Qstick 2022-08-12 23:33:27 -05:00
parent 57cb63fb18
commit cc6ca0b067
2 changed files with 59 additions and 10 deletions

View File

@ -20,7 +20,21 @@ public class SentryTargetFixture : TestBase
private static Exception[] FilteredExceptions = new Exception[]
{
new UnauthorizedAccessException()
new UnauthorizedAccessException(),
new AggregateException(new Exception[]
{
new UnauthorizedAccessException(),
new UnauthorizedAccessException()
})
};
private static Exception[] NonFilteredExceptions = new Exception[]
{
new AggregateException(new Exception[]
{
new UnauthorizedAccessException(),
new NotImplementedException()
})
};
[SetUp]
@ -63,6 +77,14 @@ public void should_filter_event_for_filtered_exception_types(Exception ex)
_subject.IsSentryMessage(log).Should().BeFalse();
}
[Test]
[TestCaseSource("NonFilteredExceptions")]
public void should_not_filter_event_for_filtered_exception_types(Exception ex)
{
var log = GivenLogEvent(LogLevel.Error, ex, "test");
_subject.IsSentryMessage(log).Should().BeTrue();
}
[Test]
[TestCaseSource("FilteredExceptions")]
public void should_not_filter_event_for_filtered_exception_types_if_filtering_disabled(Exception ex)

View File

@ -229,21 +229,48 @@ public bool IsSentryMessage(LogEventInfo logEvent)
{
if (FilterEvents)
{
var sqlEx = logEvent.Exception as SQLiteException;
if (sqlEx != null && FilteredSQLiteErrors.Contains(sqlEx.ResultCode))
var exceptions = new List<Exception>();
var aggEx = logEvent.Exception as AggregateException;
if (aggEx != null && aggEx.InnerExceptions.Count > 0)
{
return false;
exceptions.AddRange(aggEx.InnerExceptions);
}
else
{
exceptions.Add(logEvent.Exception);
}
if (FilteredExceptionTypeNames.Contains(logEvent.Exception.GetType().Name))
// If any are sentry then send to sentry
foreach (var ex in exceptions)
{
return false;
var isSentry = true;
var sqlEx = ex as SQLiteException;
if (sqlEx != null && !FilteredSQLiteErrors.Contains(sqlEx.ResultCode))
{
isSentry = false;
}
if (FilteredExceptionTypeNames.Contains(ex.GetType().Name))
{
isSentry = false;
}
if (FilteredExceptionMessages.Any(x => ex.Message.Contains(x)))
{
isSentry = false;
}
if (isSentry)
{
return true;
}
}
if (FilteredExceptionMessages.Any(x => logEvent.Exception.Message.Contains(x)))
{
return false;
}
// The exception or aggregate exception children were not sentry exceptions
return false;
}
return true;