Skip to content

Commit

Permalink
Rename IsSentryMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-epure-sonarsource committed Aug 19, 2023
1 parent f60b273 commit 9c7c775
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,37 @@ private LogEventInfo GivenLogEvent(LogLevel level, Exception ex, string message)
[TestCaseSource("AllLevels")]
public void log_without_error_is_not_sentry_event(LogLevel level)
{
_subject.IsSentryMessage(GivenLogEvent(level, null, "test")).Should().BeFalse();
_subject.IsTrulySentryMessage(GivenLogEvent(level, null, "test")).Should().BeFalse();
}

[Test]
[TestCaseSource("SentryLevels")]
public void error_or_worse_with_exception_is_sentry_event(LogLevel level)
{
_subject.IsSentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeTrue();
_subject.IsTrulySentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeTrue();
}

[Test]
[TestCaseSource("OtherLevels")]
public void less_than_error_with_exception_is_not_sentry_event(LogLevel level)
{
_subject.IsSentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeFalse();
_subject.IsTrulySentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeFalse();
}

[Test]
[TestCaseSource("FilteredExceptions")]
public void should_filter_event_for_filtered_exception_types(Exception ex)
{
var log = GivenLogEvent(LogLevel.Error, ex, "test");
_subject.IsSentryMessage(log).Should().BeFalse();
_subject.IsTrulySentryMessage(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();
_subject.IsTrulySentryMessage(log).Should().BeTrue();
}

[Test]
Expand All @@ -94,23 +94,23 @@ public void should_not_filter_event_for_filtered_exception_types_if_filtering_di
{
_subject.FilterEvents = false;
var log = GivenLogEvent(LogLevel.Error, ex, "test");
_subject.IsSentryMessage(log).Should().BeTrue();
_subject.IsTrulySentryMessage(log).Should().BeTrue();
}

[Test]
[TestCaseSource(typeof(SentryTarget), "FilteredExceptionMessages")]
public void should_filter_event_for_filtered_exception_messages(string message)
{
var log = GivenLogEvent(LogLevel.Error, new Exception("aaaaaaa" + message + "bbbbbbb"), "test");
_subject.IsSentryMessage(log).Should().BeFalse();
_subject.IsTrulySentryMessage(log).Should().BeFalse();
}

[TestCase("A message that isn't filtered")]
[TestCase("Error")]
public void should_not_filter_event_for_exception_messages_that_are_not_filtered(string message)
{
var log = GivenLogEvent(LogLevel.Error, new Exception(message), "test");
_subject.IsSentryMessage(log).Should().BeTrue();
_subject.IsTrulySentryMessage(log).Should().BeTrue();
}
}
}
4 changes: 2 additions & 2 deletions src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private static List<string> GetFingerPrint(LogEventInfo logEvent)
return fingerPrint;
}

public bool IsSentryMessage(LogEventInfo logEvent)
public bool IsTrulySentryMessage(LogEventInfo logEvent)
{
if (logEvent.Properties.ContainsKey("Sentry"))
{
Expand Down Expand Up @@ -314,7 +314,7 @@ protected override void Write(LogEventInfo logEvent)
SentrySdk.AddBreadcrumb(logEvent.FormattedMessage, logEvent.LoggerName, level: BreadcrumbLevelMap[logEvent.Level]);

// don't report non-critical events without exceptions
if (!IsSentryMessage(logEvent))
if (!IsTrulySentryMessage(logEvent))
{
return;
}
Expand Down

0 comments on commit 9c7c775

Please sign in to comment.