Sentry will now back-off if it's API key is revoked.

This commit is contained in:
Keivan Beigi 2017-01-06 11:53:46 -08:00
parent 0bdc137093
commit ed2e4d0f1d
3 changed files with 31 additions and 3 deletions

View File

@ -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";
}

View File

@ -29,5 +29,10 @@ namespace NzbDrone.Common.Instrumentation.Sentry
_cache.Set(key, true, _ttl);
return true;
}
public void Clear()
{
_cache.Clear();
}
}
}

View File

@ -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<string> GetFingerPrint(LogEventInfo logEvent)
{
var fingerPrint = new List<string>
@ -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);
}
}
}