From d5c69d03757dc3465e8b41b40f4b80a57f21c9db Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 28 Mar 2019 09:26:39 +0000 Subject: [PATCH] Set sentry environment to be develop/nightly based on config file (#703) * Set sentry environment to be develop/nightly based on config file Also add details on sqlite version and database migration. The separate ReconfigureSentry class is required because ReconfigureLogging happens before the database has been resolved, so you can't access IMainDatabase there * Set environment to develop/nightly in frontend too --- appveyor-package.sh | 2 +- .../Middleware/createSentryMiddleware.js | 4 +- .../Instrumentation/Sentry/SentryTarget.cs | 8 +++- .../Instrumentation/ReconfigureLogging.cs | 4 -- .../Instrumentation/ReconfigureSentry.cs | 39 +++++++++++++++++++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 src/NzbDrone.Core/Instrumentation/ReconfigureSentry.cs diff --git a/appveyor-package.sh b/appveyor-package.sh index 406529733..57c61c63e 100755 --- a/appveyor-package.sh +++ b/appveyor-package.sh @@ -35,7 +35,7 @@ PublishSourceMaps() yarn sentry-cli releases new --finalize -p lidarr -p lidarr-ui -p lidarr-update "${APPVEYOR_BUILD_VERSION}-debug" yarn sentry-cli releases -p lidarr-ui files "${APPVEYOR_BUILD_VERSION}-debug" upload-sourcemaps _output/UI/ --rewrite yarn sentry-cli releases set-commits --auto "${APPVEYOR_BUILD_VERSION}-debug" - yarn sentry-cli releases deploys "${APPVEYOR_BUILD_VERSION}-debug" new -e production + yarn sentry-cli releases deploys "${APPVEYOR_BUILD_VERSION}-debug" new -e nightly fi } diff --git a/frontend/src/Store/Middleware/createSentryMiddleware.js b/frontend/src/Store/Middleware/createSentryMiddleware.js index 41109a0c7..27c8b5911 100644 --- a/frontend/src/Store/Middleware/createSentryMiddleware.js +++ b/frontend/src/Store/Middleware/createSentryMiddleware.js @@ -76,15 +76,15 @@ export default function createSentryMiddleware() { sentry.init({ dsn, - environment: isProduction ? 'production' : 'development', + environment: branch, release, sendDefaultPii: true, beforeSend: cleanseData }); sentry.configureScope((scope) => { - scope.setTag('branch', branch); scope.setTag('version', version); + scope.setTag('production', isProduction); }); return createMiddleware(); diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs index 02d226ad7..c6d861d4f 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs @@ -84,6 +84,9 @@ namespace NzbDrone.Common.Instrumentation.Sentry private bool _unauthorized; public bool FilterEvents { get; set; } + public string UpdateBranch { get; set; } + public Version DatabaseVersion { get; set; } + public int DatabaseMigration { get; set; } public SentryTarget(string dsn) { @@ -95,7 +98,6 @@ namespace NzbDrone.Common.Instrumentation.Sentry o.SendDefaultPii = true; o.Debug = false; o.DiagnosticsLevel = SentryLevel.Debug; - o.Environment = RuntimeInfo.IsProduction ? "production" : "development"; o.Release = BuildInfo.Release; o.BeforeSend = x => SentryCleanser.CleanseEvent(x); o.BeforeBreadcrumb = x => SentryCleanser.CleanseBreadcrumb(x); @@ -112,6 +114,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry scope.SetTag("culture", Thread.CurrentThread.CurrentCulture.Name); scope.SetTag("branch", BuildInfo.Branch); scope.SetTag("version", BuildInfo.Version.ToString()); + scope.SetTag("production", RuntimeInfo.IsProduction.ToString()); }); _debounce = new SentryDebounce(); @@ -247,6 +250,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry Level = LoggingLevelMap[logEvent.Level], Logger = logEvent.LoggerName, Message = logEvent.FormattedMessage, + Environment = UpdateBranch }; sentryEvent.SetExtras(extras); @@ -261,6 +265,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry sentryEvent.SetTag("os_name", osName); sentryEvent.SetTag("os_version", $"{osName} {osVersion}"); sentryEvent.SetTag("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}"); + sentryEvent.SetTag("sqlite_version", $"{DatabaseVersion}"); + sentryEvent.SetTag("database_migration", $"{DatabaseMigration}"); SentrySdk.CaptureEvent(sentryEvent); } diff --git a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs index e4cd4c927..9c99dfb02 100644 --- a/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs +++ b/src/NzbDrone.Core/Instrumentation/ReconfigureLogging.cs @@ -3,7 +3,6 @@ using System.Linq; using NLog; using NLog.Config; using NzbDrone.Common.Extensions; -using NzbDrone.Common.Instrumentation.Sentry; using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Messaging.Events; @@ -41,9 +40,6 @@ namespace NzbDrone.Core.Instrumentation SetMinimumLogLevel(rules, "appFileDebug", minimumLogLevel <= LogLevel.Debug ? LogLevel.Debug : LogLevel.Off); SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off); - // Sentry filtering - LogManager.Configuration.FindTargetByName("sentryTarget").FilterEvents = _configFileProvider.FilterSentryEvents; - LogManager.ReconfigExistingLoggers(); } diff --git a/src/NzbDrone.Core/Instrumentation/ReconfigureSentry.cs b/src/NzbDrone.Core/Instrumentation/ReconfigureSentry.cs new file mode 100644 index 000000000..1cd144ec0 --- /dev/null +++ b/src/NzbDrone.Core/Instrumentation/ReconfigureSentry.cs @@ -0,0 +1,39 @@ +using NLog; +using NzbDrone.Common.Instrumentation.Sentry; +using NzbDrone.Core.Configuration; +using NzbDrone.Core.Datastore; +using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.Messaging.Events; + +namespace NzbDrone.Core.Instrumentation +{ + public class ReconfigureSentry : IHandleAsync + { + private readonly IConfigFileProvider _configFileProvider; + private readonly IMainDatabase _database; + + public ReconfigureSentry(IConfigFileProvider configFileProvider, + IMainDatabase database) + { + _configFileProvider = configFileProvider; + _database = database; + } + + public void Reconfigure() + { + // Extended sentry config + var sentry = LogManager.Configuration.FindTargetByName("sentryTarget"); + sentry.FilterEvents = _configFileProvider.FilterSentryEvents; + sentry.UpdateBranch = _configFileProvider.Branch; + sentry.DatabaseVersion = _database.Version; + sentry.DatabaseMigration = _database.Migration; + + LogManager.ReconfigExistingLoggers(); + } + + public void HandleAsync(ApplicationStartedEvent message) + { + Reconfigure(); + } + } +} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 944db1eaf..4e06cad20 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -705,6 +705,7 @@ +