Added a one hour debounce of reporting the same errors to sentry
This commit is contained in:
parent
76a7d4f866
commit
782efcfaf1
|
@ -0,0 +1,32 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
|
{
|
||||||
|
public class SentryDebounce
|
||||||
|
{
|
||||||
|
private readonly Dictionary<string, DateTime> _dictionary;
|
||||||
|
private static readonly TimeSpan TTL = TimeSpan.FromHours(1);
|
||||||
|
|
||||||
|
public SentryDebounce()
|
||||||
|
{
|
||||||
|
_dictionary = new Dictionary<string, DateTime>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Allowed(IEnumerable<string> fingerPrint)
|
||||||
|
{
|
||||||
|
var key = string.Join("|", fingerPrint);
|
||||||
|
|
||||||
|
DateTime expiry;
|
||||||
|
_dictionary.TryGetValue(key, out expiry);
|
||||||
|
|
||||||
|
if (expiry >= DateTime.Now)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_dictionary[key] = DateTime.Now + TTL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using NLog;
|
using NLog;
|
||||||
|
@ -12,7 +11,6 @@ using SharpRaven.Data;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
{
|
{
|
||||||
|
|
||||||
public class SentryUserFactory : ISentryUserFactory
|
public class SentryUserFactory : ISentryUserFactory
|
||||||
{
|
{
|
||||||
public SentryUser Create()
|
public SentryUser Create()
|
||||||
|
@ -21,6 +19,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Target("Sentry")]
|
[Target("Sentry")]
|
||||||
public class SentryTarget : TargetWithLayout
|
public class SentryTarget : TargetWithLayout
|
||||||
{
|
{
|
||||||
|
@ -39,6 +38,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
{LogLevel.Warn, ErrorLevel.Warning},
|
{LogLevel.Warn, ErrorLevel.Warning},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private readonly SentryDebounce _debounce;
|
||||||
|
|
||||||
public SentryTarget(string dsn)
|
public SentryTarget(string dsn)
|
||||||
{
|
{
|
||||||
_client = new RavenClient(new Dsn(dsn), new JsonPacketFactory(), new SentryRequestFactory(), new SentryUserFactory())
|
_client = new RavenClient(new Dsn(dsn), new JsonPacketFactory(), new SentryRequestFactory(), new SentryUserFactory())
|
||||||
|
@ -53,6 +54,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
_client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name);
|
_client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name);
|
||||||
_client.Tags.Add("branch", BuildInfo.Branch);
|
_client.Tags.Add("branch", BuildInfo.Branch);
|
||||||
_client.Tags.Add("version", BuildInfo.Version.ToString());
|
_client.Tags.Add("version", BuildInfo.Version.ToString());
|
||||||
|
|
||||||
|
_debounce = new SentryDebounce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +97,12 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fingerPrint = GetFingerPrint(logEvent);
|
||||||
|
if (!_debounce.Allowed(fingerPrint))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var extras = logEvent.Properties.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());
|
var extras = logEvent.Properties.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());
|
||||||
_client.Logger = logEvent.LoggerName;
|
_client.Logger = logEvent.LoggerName;
|
||||||
|
|
||||||
|
@ -105,7 +114,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
Extra = extras
|
Extra = extras
|
||||||
};
|
};
|
||||||
|
|
||||||
var fingerPrint = GetFingerPrint(logEvent);
|
|
||||||
fingerPrint.ForEach(c => sentryEvent.Fingerprint.Add(c));
|
fingerPrint.ForEach(c => sentryEvent.Fingerprint.Add(c));
|
||||||
|
|
||||||
sentryEvent.Tags.Add("os_name", Environment.GetEnvironmentVariable("OS_NAME"));
|
sentryEvent.Tags.Add("os_name", Environment.GetEnvironmentVariable("OS_NAME"));
|
||||||
|
|
|
@ -183,6 +183,7 @@
|
||||||
<Compile Include="Instrumentation\NzbDroneFileTarget.cs" />
|
<Compile Include="Instrumentation\NzbDroneFileTarget.cs" />
|
||||||
<Compile Include="Instrumentation\NzbDroneLogger.cs" />
|
<Compile Include="Instrumentation\NzbDroneLogger.cs" />
|
||||||
<Compile Include="Instrumentation\Sentry\PopulateStackTraceRenderer.cs" />
|
<Compile Include="Instrumentation\Sentry\PopulateStackTraceRenderer.cs" />
|
||||||
|
<Compile Include="Instrumentation\Sentry\SentryDebounce.cs" />
|
||||||
<Compile Include="Instrumentation\Sentry\SentryTarget.cs" />
|
<Compile Include="Instrumentation\Sentry\SentryTarget.cs" />
|
||||||
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
|
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
|
||||||
<Compile Include="Extensions\LevenstheinExtensions.cs" />
|
<Compile Include="Extensions\LevenstheinExtensions.cs" />
|
||||||
|
|
Loading…
Reference in New Issue