Better Sentry Filtering for AggregateException children

pull/7481/head
Qstick 2 years ago
parent 57cb63fb18
commit cc6ca0b067

@ -20,7 +20,21 @@ namespace NzbDrone.Common.Test.InstrumentationTests
private static Exception[] FilteredExceptions = new Exception[] 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] [SetUp]
@ -63,6 +77,14 @@ namespace NzbDrone.Common.Test.InstrumentationTests
_subject.IsSentryMessage(log).Should().BeFalse(); _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] [Test]
[TestCaseSource("FilteredExceptions")] [TestCaseSource("FilteredExceptions")]
public void should_not_filter_event_for_filtered_exception_types_if_filtering_disabled(Exception ex) public void should_not_filter_event_for_filtered_exception_types_if_filtering_disabled(Exception ex)

@ -229,21 +229,48 @@ namespace NzbDrone.Common.Instrumentation.Sentry
{ {
if (FilterEvents) if (FilterEvents)
{ {
var sqlEx = logEvent.Exception as SQLiteException; var exceptions = new List<Exception>();
if (sqlEx != null && FilteredSQLiteErrors.Contains(sqlEx.ResultCode))
var aggEx = logEvent.Exception as AggregateException;
if (aggEx != null && aggEx.InnerExceptions.Count > 0)
{ {
return false; exceptions.AddRange(aggEx.InnerExceptions);
} }
else
if (FilteredExceptionTypeNames.Contains(logEvent.Exception.GetType().Name))
{ {
return false; exceptions.Add(logEvent.Exception);
} }
if (FilteredExceptionMessages.Any(x => logEvent.Exception.Message.Contains(x))) // 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;
}
} }
// The exception or aggregate exception children were not sentry exceptions
return false;
} }
return true; return true;

Loading…
Cancel
Save