Revert "Use line number instead of message for sentry fingerprint"
This reverts commit 5f339c0a92
.
# Conflicts:
# src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs
This commit is contained in:
parent
73840dcacc
commit
cd7e208efa
|
@ -33,8 +33,6 @@ namespace NzbDrone.Common.Instrumentation
|
|||
|
||||
GlobalExceptionHandlers.Register();
|
||||
|
||||
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("populatestacktrace", typeof(PopulateStackTraceRenderer));
|
||||
|
||||
var appFolderInfo = new AppFolderInfo(startupContext);
|
||||
|
||||
if (Debugger.IsAttached)
|
||||
|
@ -108,11 +106,10 @@ namespace NzbDrone.Common.Instrumentation
|
|||
var target = new SentryTarget(dsn)
|
||||
{
|
||||
Name = "sentryTarget",
|
||||
Layout = "${message}${populatestacktrace}"
|
||||
Layout = "${message}"
|
||||
};
|
||||
|
||||
var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Error, target);
|
||||
|
||||
LogManager.Configuration.AddTarget("sentryTarget", target);
|
||||
LogManager.Configuration.LoggingRules.Add(loggingRule);
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
using System.Text;
|
||||
using NLog;
|
||||
using NLog.Config;
|
||||
using NLog.Internal;
|
||||
using NLog.LayoutRenderers;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
[ThreadAgnostic]
|
||||
[LayoutRenderer("populatestacktrace")]
|
||||
public class PopulateStackTraceRenderer : LayoutRenderer, IUsesStackTrace
|
||||
{
|
||||
StackTraceUsage IUsesStackTrace.StackTraceUsage => StackTraceUsage.WithSource;
|
||||
|
||||
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
|
||||
{
|
||||
// This is only used to populate the stacktrace. doesn't actually render anything.
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,31 +1,32 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
public class SentryDebounce
|
||||
{
|
||||
private readonly Dictionary<string, DateTime> _dictionary;
|
||||
private static readonly TimeSpan TTL = TimeSpan.FromHours(1);
|
||||
private readonly TimeSpan _ttl;
|
||||
private readonly Cached<bool> _cache;
|
||||
|
||||
public SentryDebounce()
|
||||
{
|
||||
_dictionary = new Dictionary<string, DateTime>();
|
||||
_cache = new Cached<bool>();
|
||||
_ttl = RuntimeInfo.IsProduction ? TimeSpan.FromHours(1) : TimeSpan.FromSeconds(10);
|
||||
}
|
||||
|
||||
public bool Allowed(IEnumerable<string> fingerPrint)
|
||||
{
|
||||
var key = string.Join("|", fingerPrint);
|
||||
var exists = _cache.Find(key);
|
||||
|
||||
DateTime expiry;
|
||||
_dictionary.TryGetValue(key, out expiry);
|
||||
|
||||
if (expiry >= DateTime.Now)
|
||||
if (exists)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_dictionary[key] = DateTime.Now + TTL;
|
||||
_cache.Set(key, true, _ttl);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,35 +58,32 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
|||
_debounce = new SentryDebounce();
|
||||
}
|
||||
|
||||
|
||||
private List<string> GetFingerPrint(LogEventInfo logEvent)
|
||||
private static List<string> GetFingerPrint(LogEventInfo logEvent)
|
||||
{
|
||||
var fingerPrint = new List<string>
|
||||
{
|
||||
logEvent.Level.Ordinal.ToString(),
|
||||
logEvent.LoggerName
|
||||
};
|
||||
|
||||
var lineNumber = "";
|
||||
var ex = logEvent.Exception;
|
||||
|
||||
if (logEvent.StackTrace != null)
|
||||
if (ex != null)
|
||||
{
|
||||
var stackFrame = logEvent.StackTrace.GetFrame(logEvent.UserStackFrameNumber);
|
||||
if (stackFrame != null)
|
||||
var exception = ex.GetType().Name;
|
||||
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
lineNumber = $"#{stackFrame.GetFileLineNumber()}";
|
||||
exception += ex.InnerException.GetType().Name;
|
||||
}
|
||||
}
|
||||
|
||||
fingerPrint.Add(logEvent.LoggerName + lineNumber);
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
fingerPrint.Add(logEvent.Exception.GetType().Name);
|
||||
fingerPrint.Add(exception);
|
||||
}
|
||||
|
||||
return fingerPrint;
|
||||
}
|
||||
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
try
|
||||
|
@ -111,11 +108,20 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
|||
{
|
||||
Level = LoggingLevelMap[logEvent.Level],
|
||||
Message = sentryMessage,
|
||||
Extra = extras
|
||||
Extra = extras,
|
||||
Fingerprint =
|
||||
{
|
||||
logEvent.Level.ToString(),
|
||||
logEvent.LoggerName,
|
||||
logEvent.Message
|
||||
}
|
||||
};
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
sentryEvent.Fingerprint.Add(logEvent.Exception.GetType().FullName);
|
||||
}
|
||||
|
||||
fingerPrint.ForEach(c => sentryEvent.Fingerprint.Add(c));
|
||||
|
||||
sentryEvent.Tags.Add("os_name", Environment.GetEnvironmentVariable("OS_NAME"));
|
||||
sentryEvent.Tags.Add("os_version", Environment.GetEnvironmentVariable("OS_VERSION"));
|
||||
|
|
|
@ -182,7 +182,6 @@
|
|||
<Compile Include="Instrumentation\LogEventExtensions.cs" />
|
||||
<Compile Include="Instrumentation\NzbDroneFileTarget.cs" />
|
||||
<Compile Include="Instrumentation\NzbDroneLogger.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\PopulateStackTraceRenderer.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SentryDebounce.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SentryTarget.cs" />
|
||||
<Compile Include="Instrumentation\VersionLayoutRenderer.cs" />
|
||||
|
|
Loading…
Reference in New Issue