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();
|
GlobalExceptionHandlers.Register();
|
||||||
|
|
||||||
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("populatestacktrace", typeof(PopulateStackTraceRenderer));
|
|
||||||
|
|
||||||
var appFolderInfo = new AppFolderInfo(startupContext);
|
var appFolderInfo = new AppFolderInfo(startupContext);
|
||||||
|
|
||||||
if (Debugger.IsAttached)
|
if (Debugger.IsAttached)
|
||||||
|
@ -108,11 +106,10 @@ namespace NzbDrone.Common.Instrumentation
|
||||||
var target = new SentryTarget(dsn)
|
var target = new SentryTarget(dsn)
|
||||||
{
|
{
|
||||||
Name = "sentryTarget",
|
Name = "sentryTarget",
|
||||||
Layout = "${message}${populatestacktrace}"
|
Layout = "${message}"
|
||||||
};
|
};
|
||||||
|
|
||||||
var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Error, target);
|
var loggingRule = new LoggingRule("*", updateClient ? LogLevel.Trace : LogLevel.Error, target);
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("sentryTarget", target);
|
LogManager.Configuration.AddTarget("sentryTarget", target);
|
||||||
LogManager.Configuration.LoggingRules.Add(loggingRule);
|
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using NzbDrone.Common.Cache;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
{
|
{
|
||||||
public class SentryDebounce
|
public class SentryDebounce
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, DateTime> _dictionary;
|
private readonly TimeSpan _ttl;
|
||||||
private static readonly TimeSpan TTL = TimeSpan.FromHours(1);
|
private readonly Cached<bool> _cache;
|
||||||
|
|
||||||
public SentryDebounce()
|
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)
|
public bool Allowed(IEnumerable<string> fingerPrint)
|
||||||
{
|
{
|
||||||
var key = string.Join("|", fingerPrint);
|
var key = string.Join("|", fingerPrint);
|
||||||
|
var exists = _cache.Find(key);
|
||||||
|
|
||||||
DateTime expiry;
|
if (exists)
|
||||||
_dictionary.TryGetValue(key, out expiry);
|
|
||||||
|
|
||||||
if (expiry >= DateTime.Now)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_dictionary[key] = DateTime.Now + TTL;
|
_cache.Set(key, true, _ttl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,35 +58,32 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
_debounce = new SentryDebounce();
|
_debounce = new SentryDebounce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<string> GetFingerPrint(LogEventInfo logEvent)
|
||||||
private List<string> GetFingerPrint(LogEventInfo logEvent)
|
|
||||||
{
|
{
|
||||||
var fingerPrint = new List<string>
|
var fingerPrint = new List<string>
|
||||||
{
|
{
|
||||||
logEvent.Level.Ordinal.ToString(),
|
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);
|
var exception = ex.GetType().Name;
|
||||||
if (stackFrame != null)
|
|
||||||
|
if (ex.InnerException != null)
|
||||||
{
|
{
|
||||||
lineNumber = $"#{stackFrame.GetFileLineNumber()}";
|
exception += ex.InnerException.GetType().Name;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fingerPrint.Add(logEvent.LoggerName + lineNumber);
|
fingerPrint.Add(exception);
|
||||||
|
|
||||||
if (logEvent.Exception != null)
|
|
||||||
{
|
|
||||||
fingerPrint.Add(logEvent.Exception.GetType().Name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fingerPrint;
|
return fingerPrint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected override void Write(LogEventInfo logEvent)
|
protected override void Write(LogEventInfo logEvent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -111,11 +108,20 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||||
{
|
{
|
||||||
Level = LoggingLevelMap[logEvent.Level],
|
Level = LoggingLevelMap[logEvent.Level],
|
||||||
Message = sentryMessage,
|
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_name", Environment.GetEnvironmentVariable("OS_NAME"));
|
||||||
sentryEvent.Tags.Add("os_version", Environment.GetEnvironmentVariable("OS_VERSION"));
|
sentryEvent.Tags.Add("os_version", Environment.GetEnvironmentVariable("OS_VERSION"));
|
||||||
|
|
|
@ -182,7 +182,6 @@
|
||||||
<Compile Include="Instrumentation\LogEventExtensions.cs" />
|
<Compile Include="Instrumentation\LogEventExtensions.cs" />
|
||||||
<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\SentryDebounce.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" />
|
||||||
|
|
Loading…
Reference in New Issue