1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-28 08:58:41 +02:00

Updated way Sentry gets configured and enabled.

This commit is contained in:
Taloth Saldono 2019-08-24 21:43:45 +02:00
parent e126c45fb3
commit b1eec16333
19 changed files with 175 additions and 94 deletions

View File

@ -198,25 +198,25 @@ PackageMono()
# See: https://github.com/mono/mono/blob/master/tools/nuget-hash-extractor/download.sh
# That list defines assemblies that are prohibited from being loaded from the appdir, instead loading from mono GAC.
# We have debian dependencies to get these installed
for assembly in System.IO.Compression System.Runtime.InteropServices.RuntimeInformation System.Net.Http
# We have debian dependencies to get these installed or facades from mono 5.10+
for assembly in System.IO.Compression System.Runtime.InteropServices.RuntimeInformation System.Net.Http System.Globalization.Extensions System.Text.Encoding.CodePages System.Threading.Overlapped
do
if [ -e $outputFolderLinux/$assembly.dll ] ; then
echo "Remove $assembly.dll (uses win32 interop)"
rm $outputFolderLinux/$assembly.dll
fi
done
# These assemblies have facades in mono-devel, but we don't have them.
for assembly in System.Globalization.Extensions System.Text.Encoding.CodePages System.Threading.Overlapped
do
if [ -e $outputFolderLinux/$assembly.dll ] ; then
echo "Warn: Facade $assembly.dll (uses win32 interop)"
rm $outputFolderLinux/$assembly.dll
#exit 1
if [ -e $outputFolderLinux/$assembly.dll ]; then
if [ -e $sourceFolder/Libraries/Mono/$assembly.dll ]; then
echo "Copy Mono-specific facade $assembly.dll (uses win32 interop)"
cp $sourceFolder/Libraries/Mono/$assembly.dll $outputFolderLinux/$assembly.dll
else
echo "Remove $assembly.dll (uses win32 interop)"
rm $outputFolderLinux/$assembly.dll
fi
fi
done
# Remove Http binding redirect by renaming it
# We don't need this anymore once our minimum mono version is 5.10
sed -i "s/System.Net.Http/System.Net.Http.Mono/g" $outputFolderLinux/Sonarr.Console.exe.config
echo "Renaming Sonarr.Console.exe to Sonarr.exe"
rm $outputFolderLinux/Sonarr.exe*
for file in $outputFolderLinux/Sonarr.Console.exe*; do

View File

@ -16,7 +16,7 @@ Architecture: all
Provides: nzbdrone
Conflicts: nzbdrone
Replaces: nzbdrone
Depends: adduser, libsqlite3-0 (>= 3.7), libmediainfo0v5 (>= 0.7.52) | libmediainfo0 (>= 0.7.52), mono-runtime (>= 5.4), libmono-system-runtime-interopservices-runtimeinformation4.0-cil (>= 4.0.0~alpha1), libmono-system-net-http4.0-cil (>= 4.0.0~alpha1), ${cli:Depends}, ${misc:Depends}
Depends: adduser, libsqlite3-0 (>= 3.7), libmediainfo0v5 (>= 0.7.52) | libmediainfo0 (>= 0.7.52), mono-runtime (>= 5.4), libmono-system-net-http4.0-cil (>= 4.0.0~alpha1), ${cli:Depends}, ${misc:Depends}
Recommends: libmediainfo0v5 (>= 18.03) | libmediainfo0 (>= 18.03)
Suggests: sqlite3 (>= 3.7), mediainfo (>= 0.7.52)
Description: Internet PVR

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
Copied from mono/4.5/Facades of the mono 5.4 release.
These are the mono version of the dotnet Core TypeForwardedTo assemblies.
Using these assemblies is no longer necessary once we reach mono 5.18 as minimum version

View File

@ -82,9 +82,6 @@ public OsInfo(IEnumerable<IOsVersionAdapter> versionAdapters, Logger logger)
Name = Os.ToString();
FullName = Name;
}
Environment.SetEnvironmentVariable("OS_NAME", Name);
Environment.SetEnvironmentVariable("OS_VERSION", Version);
}
}

View File

@ -35,7 +35,16 @@ public RuntimeInfo(IServiceProvider serviceProvider, Logger logger)
static RuntimeInfo()
{
IsProduction = InternalIsProduction();
var officialBuild = InternalIsOfficialBuild();
// An build running inside of the testing environment. (Analytics disabled)
IsTesting = InternalIsTesting();
// An official build running outside of the testing environment. (Analytics configurable)
IsProduction = !IsTesting && officialBuild;
// An unofficial build running outside of the testing environment. (Analytics enabled)
IsDevelopment = !IsTesting && !officialBuild && !InternalIsDebug();
}
public DateTime StartTime
@ -104,23 +113,21 @@ public RuntimeMode Mode
public bool RestartPending { get; set; }
public string ExecutingApplication { get; }
public static bool IsTesting { get; }
public static bool IsProduction { get; }
public static bool IsDevelopment { get; }
private static bool InternalIsProduction()
private static bool InternalIsTesting()
{
if (BuildInfo.IsDebug || Debugger.IsAttached) return false;
//Official builds will never have such a high revision
if (BuildInfo.Version.Revision > 10000) return false;
try
{
var lowerProcessName = Process.GetCurrentProcess().ProcessName.ToLower();
if (lowerProcessName.Contains("vshost")) return false;
if (lowerProcessName.Contains("nunit")) return false;
if (lowerProcessName.Contains("jetbrain")) return false;
if (lowerProcessName.Contains("resharper")) return false;
if (lowerProcessName.Contains("vshost")) return true;
if (lowerProcessName.Contains("nunit")) return true;
if (lowerProcessName.Contains("jetbrain")) return true;
if (lowerProcessName.Contains("resharper")) return true;
}
catch
{
@ -130,7 +137,7 @@ private static bool InternalIsProduction()
try
{
var currentAssemblyLocation = typeof(RuntimeInfo).Assembly.Location;
if (currentAssemblyLocation.ToLower().Contains("_output")) return false;
if (currentAssemblyLocation.ToLower().Contains("_output")) return true;
}
catch
{
@ -138,9 +145,24 @@ private static bool InternalIsProduction()
}
var lowerCurrentDir = Directory.GetCurrentDirectory().ToLower();
if (lowerCurrentDir.Contains("teamcity")) return false;
if (lowerCurrentDir.Contains("buildagent")) return false;
if (lowerCurrentDir.Contains("_output")) return false;
if (lowerCurrentDir.Contains("teamcity")) return true;
if (lowerCurrentDir.Contains("buildagent")) return true;
if (lowerCurrentDir.Contains("_output")) return true;
return false;
}
private static bool InternalIsDebug()
{
if (BuildInfo.IsDebug || Debugger.IsAttached) return true;
return false;
}
private static bool InternalIsOfficialBuild()
{
//Official builds will never have such a high revision
if (BuildInfo.Version.Major >= 10 || BuildInfo.Version.Revision > 10000) return false;
return true;
}

View File

@ -0,0 +1,28 @@
using System.Linq;
using NLog;
using NLog.Fluent;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Common.Instrumentation.Sentry;
namespace NzbDrone.Common.Instrumentation
{
public class InitializeLogger
{
private readonly IOsInfo _osInfo;
public InitializeLogger(IOsInfo osInfo)
{
_osInfo = osInfo;
}
public void Initialize()
{
var sentryTarget = LogManager.Configuration.AllTargets.OfType<SentryTarget>().FirstOrDefault();
if (sentryTarget != null)
{
sentryTarget.UpdateScope(_osInfo);
}
}
}
}

View File

@ -60,18 +60,6 @@ public static void Register(IStartupContext startupContext, bool updateApp, bool
LogManager.ReconfigExistingLoggers();
}
public static void UnRegisterRemoteLoggers()
{
var sentryRules = LogManager.Configuration.LoggingRules.Where(r => r.Targets.Any(t => t.Name == "sentryTarget"));
foreach (var rules in sentryRules)
{
rules.Targets.Clear();
}
LogManager.ReconfigExistingLoggers();
}
private static void RegisterLogEntries()
{
var target = new LogentriesTarget();
@ -92,15 +80,15 @@ private static void RegisterSentry(bool updateClient)
if (updateClient)
{
dsn = RuntimeInfo.IsProduction
? "https://b85aa82c65b84b0e99e3b7c281438357:392b5bc007974147a922c5d841c47cf9@sentry.sonarr.tv/11"
: "https://6168f0946aba4e60ac23e469ac08eac5:bd59e8454ccc454ea27a90cff1f814ca@sentry.sonarr.tv/9";
? "https://80777986b95f44a1a90d1eb2f3af1e36@sentry.sonarr.tv/11"
: "https://6168f0946aba4e60ac23e469ac08eac5@sentry.sonarr.tv/9";
}
else
{
dsn = RuntimeInfo.IsProduction
? "https://a013727b8d224e719894e1e13ff4966b:c95ca1f9ca02418d829db10c2938baf4@sentry.sonarr.tv/8"
: "https://4ee3580e01d8407c96a7430fbc953512:5f2d07227a0b4fde99dea07041a3ff93@sentry.sonarr.tv/10";
? "https://e2adcbe52caf46aeaebb6b1dcdfe10a1@sentry.sonarr.tv/8"
: "https://4ee3580e01d8407c96a7430fbc953512@sentry.sonarr.tv/10";
}
Target target;
@ -114,6 +102,7 @@ private static void RegisterSentry(bool updateClient)
}
catch (Exception ex)
{
Console.WriteLine("Failed to load dependency, may need an OS update: " + ex.ToString());
LogManager.GetLogger(nameof(NzbDroneLogger)).Debug(ex, "Failed to load dependency, may need an OS update");
// We still need the logging rules, so use a null target.

View File

@ -1,14 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Data.SQLite;
using NLog;
using NLog.Common;
using NLog.Targets;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using Sentry;
using Sentry.Protocol;
@ -75,6 +77,7 @@ public class SentryTarget : TargetWithLayout
{LogLevel.Warn, BreadcrumbLevel.Warning},
};
private readonly DateTime _startTime = DateTime.UtcNow;
private readonly IDisposable _sdk;
private bool _disposed;
@ -82,10 +85,11 @@ public class SentryTarget : TargetWithLayout
private bool _unauthorized;
public bool FilterEvents { get; set; }
public string UpdateBranch { get; set; }
public Version DatabaseVersion { get; set; }
public int DatabaseMigration { get; set; }
public bool SentryEnabled { get; set; }
public SentryTarget(string dsn)
{
_sdk = SentrySdk.Init(o =>
@ -93,34 +97,71 @@ public SentryTarget(string dsn)
o.Dsn = new Dsn(dsn);
o.AttachStacktrace = true;
o.MaxBreadcrumbs = 200;
o.SendDefaultPii = true;
o.SendDefaultPii = false;
o.AttachStacktrace = true;
o.Debug = false;
o.DiagnosticsLevel = SentryLevel.Debug;
o.Release = BuildInfo.Release;
if (PlatformInfo.IsMono)
{
// Mono 6.0 broke GzipStream.WriteAsync
// TODO: Check specific version
o.RequestBodyCompressionLevel = System.IO.Compression.CompressionLevel.NoCompression;
}
o.BeforeSend = x => SentryCleanser.CleanseEvent(x);
o.BeforeBreadcrumb = x => SentryCleanser.CleanseBreadcrumb(x);
o.Environment = BuildInfo.Branch;
});
SentrySdk.ConfigureScope(scope =>
{
scope.User = new User {
Username = HashUtil.AnonymousToken()
};
scope.SetTag("osfamily", OsInfo.Os.ToString());
scope.SetTag("runtime", PlatformInfo.PlatformName);
scope.SetTag("culture", Thread.CurrentThread.CurrentCulture.Name);
scope.SetTag("branch", BuildInfo.Branch);
scope.SetTag("version", BuildInfo.Version.ToString());
scope.SetTag("production", RuntimeInfo.IsProduction.ToString());
});
InitializeScope();
_debounce = new SentryDebounce();
// initialize to true and reconfigure later
// Otherwise it will default to false and any errors occuring
// before config file gets read will not be filtered
FilterEvents = true;
SentryEnabled = true;
}
public void InitializeScope()
{
SentrySdk.ConfigureScope(scope =>
{
scope.User = new User
{
Id = HashUtil.AnonymousToken()
};
scope.Contexts.App.Name = BuildInfo.AppName;
scope.Contexts.App.Version = BuildInfo.Version.ToString();
scope.Contexts.App.StartTime = _startTime;
scope.Contexts.App.Hash = HashUtil.AnonymousToken();
scope.Contexts.App.Build = BuildInfo.Release; // Git commit cache?
scope.SetTag("culture", Thread.CurrentThread.CurrentCulture.Name);
scope.SetTag("branch", BuildInfo.Branch);
if (DatabaseVersion != default(Version))
{
scope.SetTag("sqlite_version", $"{DatabaseVersion}");
}
});
}
public void UpdateScope(IOsInfo osInfo)
{
SentrySdk.ConfigureScope(scope =>
{
if (osInfo.Name != null && PlatformInfo.IsMono)
{
// Sentry auto-detection of non-Windows platforms isn't that accurate on certain devices.
scope.Contexts.OperatingSystem.Name = osInfo.Name.FirstCharToUpper();
scope.Contexts.OperatingSystem.RawDescription = osInfo.FullName;
scope.Contexts.OperatingSystem.Version = osInfo.Version.ToString();
}
});
}
private void OnError(Exception ex)
@ -246,27 +287,12 @@ protected override void Write(LogEventInfo logEvent)
{
Level = LoggingLevelMap[logEvent.Level],
Logger = logEvent.LoggerName,
Message = logEvent.FormattedMessage,
Environment = UpdateBranch
Message = logEvent.FormattedMessage
};
sentryEvent.SetExtras(extras);
sentryEvent.SetFingerprint(fingerPrint);
// this can't be in the constructor as at that point OsInfo won't have
// populated these values yet
var osName = Environment.GetEnvironmentVariable("OS_NAME");
var osVersion = Environment.GetEnvironmentVariable("OS_VERSION");
var runTimeVersion = Environment.GetEnvironmentVariable("RUNTIME_VERSION");
sentryEvent.SetTag("os_name", osName);
sentryEvent.SetTag("os_version", $"{osName} {osVersion}");
sentryEvent.SetTag("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}");
if (DatabaseVersion != default(Version))
{
sentryEvent.SetTag("sqlite_version", $"{DatabaseVersion}");
}
SentrySdk.CaptureEvent(sentryEvent);
}
catch (Exception e)

View File

@ -363,11 +363,6 @@ public void HandleAsync(ApplicationStartedEvent message)
{
EnsureDefaultConfigFile();
DeleteOldValues();
if (!AnalyticsEnabled)
{
NzbDroneLogger.UnRegisterRemoteLoggers();
}
}
public void Execute(ResetApiKeyCommand message)

View File

@ -2,7 +2,9 @@
using System.Linq;
using NLog;
using NLog.Config;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Sentry;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Messaging.Events;
@ -40,6 +42,9 @@ public void Reconfigure()
SetMinimumLogLevel(rules, "appFileDebug", minimumLogLevel <= LogLevel.Debug ? LogLevel.Debug : LogLevel.Off);
SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off);
//Sentry
ReconfigureSentry();
LogManager.ReconfigExistingLoggers();
}
@ -67,6 +72,15 @@ private void SetMinimumLogLevel(LoggingRule rule, LogLevel minimumLogLevel)
}
}
private void ReconfigureSentry()
{
var sentryTarget = LogManager.Configuration.AllTargets.OfType<SentryTarget>().FirstOrDefault();
if (sentryTarget != null)
{
sentryTarget.SentryEnabled = RuntimeInfo.IsProduction && _configFileProvider.AnalyticsEnabled || RuntimeInfo.IsDevelopment;
}
}
private List<LogLevel> GetLogLevels()
{
return new List<LogLevel>

View File

@ -247,6 +247,8 @@ private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tv
{
_logger.Debug()
.Message("Found matching series by TVDB ID {0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle)
.Property("TvdbId", tvdbId)
.Property("ParsedEpisodeInfo", parsedEpisodeInfo)
.WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Write();
@ -256,8 +258,10 @@ private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tv
if (tvRageId > 0 && tvRageId == searchCriteria.Series.TvRageId)
{
_logger.Debug()
.Message("Found matching series by TVRage ID {0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle)
.WriteSentryWarn("TvRageIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Message("Found matching series by TVRage ID {0}, an alias may be need for: {1}", tvRageId, parsedEpisodeInfo.SeriesTitle)
.Property("TvRageId", tvRageId)
.Property("ParsedEpisodeInfo", parsedEpisodeInfo)
.WriteSentryWarn("TvRageIdMatch", tvRageId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Write();
return searchCriteria.Series;
@ -279,6 +283,8 @@ private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tv
{
_logger.Debug()
.Message("Found matching series by TVDB ID {0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle)
.Property("TvdbId", tvdbId)
.Property("ParsedEpisodeInfo", parsedEpisodeInfo)
.WriteSentryWarn("TvdbIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Write();
}
@ -292,7 +298,9 @@ private Series GetSeries(ParsedEpisodeInfo parsedEpisodeInfo, int tvdbId, int tv
{
_logger.Debug()
.Message("Found matching series by TVRage ID {0}, an alias may be need for: {1}", tvdbId, parsedEpisodeInfo.SeriesTitle)
.WriteSentryWarn("TvRageIdMatch", tvdbId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Property("TvRageId", tvRageId)
.Property("ParsedEpisodeInfo", parsedEpisodeInfo)
.WriteSentryWarn("TvRageIdMatch", tvRageId.ToString(), parsedEpisodeInfo.SeriesTitle)
.Write();
}
}

View File

@ -32,6 +32,7 @@ public static void Start(StartupContext startupContext, IUserAlert userAlert, Ac
LongPathSupport.Enable();
_container = MainAppContainerBuilder.BuildContainer(startupContext);
_container.Resolve<InitializeLogger>().Initialize();
_container.Resolve<IAppFolderFactory>().Register();
_container.Resolve<IProvidePidFile>().Write();

View File

@ -30,7 +30,6 @@ public MonoPlatformInfo(Logger logger)
if (versionMatch.Success)
{
runTimeVersion = new Version(versionMatch.Groups["version"].Value);
Environment.SetEnvironmentVariable("RUNTIME_VERSION", runTimeVersion.ToString());
}
}
}

View File

@ -35,7 +35,7 @@ public static void Main(string[] args)
Logger.Info("Starting Sonarr Update Client");
_container = UpdateContainerBuilder.Build(startupContext);
_container.Resolve<InitializeLogger>().Initialize();
_container.Resolve<UpdateApp>().Start(args);
Logger.Info("Update completed successfully");

View File

@ -13,7 +13,6 @@ public DotNetPlatformInfo(Logger logger)
{
_logger = logger;
var version = GetFrameworkVersion();
Environment.SetEnvironmentVariable("RUNTIME_VERSION", version.ToString());
Version = version;
}