diff --git a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs index 7a05776ae..60373b991 100644 --- a/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs +++ b/src/NzbDrone.Common/Instrumentation/NzbDroneLogger.cs @@ -99,7 +99,7 @@ namespace NzbDrone.Common.Instrumentation else { dsn = RuntimeInfo.IsProduction - ? "https://fed3f47e8bea4527831e96edfa02d495:8ed11e4878614d8e87b1e1b15d890dc9@sentry.sonarr.tv/8" + ? "https://3e8a38b1a4df4de8b0453a724f5a1139:5a708dd75c724b32ae5128b6a895650f@sentry.sonarr.tv/8" : "https://4ee3580e01d8407c96a7430fbc953512:5f2d07227a0b4fde99dea07041a3ff93@sentry.sonarr.tv/10"; } diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryDebounce.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryDebounce.cs index 5517b2dc2..942f3934a 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryDebounce.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryDebounce.cs @@ -29,5 +29,10 @@ namespace NzbDrone.Common.Instrumentation.Sentry _cache.Set(key, true, _ttl); return true; } + + public void Clear() + { + _cache.Clear(); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs index 8e3f7b6f7..6ec6fd1e4 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Threading; using NLog; using NLog.Common; @@ -27,6 +28,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry }; private readonly SentryDebounce _debounce; + private bool _unauthorized; + public SentryTarget(string dsn) { @@ -37,6 +40,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry Release = BuildInfo.Release }; + _client.ErrorOnCapture = OnError; + _client.Tags.Add("osfamily", OsInfo.Os.ToString()); _client.Tags.Add("runtime", PlatformInfo.Platform.ToString().ToLower()); _client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name); @@ -46,6 +51,24 @@ namespace NzbDrone.Common.Instrumentation.Sentry _debounce = new SentryDebounce(); } + private void OnError(Exception ex) + { + var webException = ex as WebException; + + if (webException != null) + { + var response = webException.Response as HttpWebResponse; + var statusCode = response?.StatusCode; + if (statusCode == HttpStatusCode.Unauthorized) + { + _unauthorized = true; + _debounce.Clear(); + } + } + + InternalLogger.Error(ex, "Unable to send error to Sentry"); + } + private static List GetFingerPrint(LogEventInfo logEvent) { var fingerPrint = new List @@ -77,7 +100,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry try { // don't report non-critical events without exceptions - if (logEvent.Exception == null) + if (logEvent.Exception == null || _unauthorized) { return; } @@ -121,7 +144,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry } catch (Exception e) { - InternalLogger.Error(e, "Unable to send Sentry request"); + OnError(e); } } }