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
pull/710/head
ta264 6 years ago committed by GitHub
parent 054d1600a2
commit d5c69d0375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 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 -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 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 fi
} }

@ -76,15 +76,15 @@ export default function createSentryMiddleware() {
sentry.init({ sentry.init({
dsn, dsn,
environment: isProduction ? 'production' : 'development', environment: branch,
release, release,
sendDefaultPii: true, sendDefaultPii: true,
beforeSend: cleanseData beforeSend: cleanseData
}); });
sentry.configureScope((scope) => { sentry.configureScope((scope) => {
scope.setTag('branch', branch);
scope.setTag('version', version); scope.setTag('version', version);
scope.setTag('production', isProduction);
}); });
return createMiddleware(); return createMiddleware();

@ -84,6 +84,9 @@ namespace NzbDrone.Common.Instrumentation.Sentry
private bool _unauthorized; private bool _unauthorized;
public bool FilterEvents { get; set; } public bool FilterEvents { get; set; }
public string UpdateBranch { get; set; }
public Version DatabaseVersion { get; set; }
public int DatabaseMigration { get; set; }
public SentryTarget(string dsn) public SentryTarget(string dsn)
{ {
@ -95,7 +98,6 @@ namespace NzbDrone.Common.Instrumentation.Sentry
o.SendDefaultPii = true; o.SendDefaultPii = true;
o.Debug = false; o.Debug = false;
o.DiagnosticsLevel = SentryLevel.Debug; o.DiagnosticsLevel = SentryLevel.Debug;
o.Environment = RuntimeInfo.IsProduction ? "production" : "development";
o.Release = BuildInfo.Release; o.Release = BuildInfo.Release;
o.BeforeSend = x => SentryCleanser.CleanseEvent(x); o.BeforeSend = x => SentryCleanser.CleanseEvent(x);
o.BeforeBreadcrumb = x => SentryCleanser.CleanseBreadcrumb(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("culture", Thread.CurrentThread.CurrentCulture.Name);
scope.SetTag("branch", BuildInfo.Branch); scope.SetTag("branch", BuildInfo.Branch);
scope.SetTag("version", BuildInfo.Version.ToString()); scope.SetTag("version", BuildInfo.Version.ToString());
scope.SetTag("production", RuntimeInfo.IsProduction.ToString());
}); });
_debounce = new SentryDebounce(); _debounce = new SentryDebounce();
@ -247,6 +250,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry
Level = LoggingLevelMap[logEvent.Level], Level = LoggingLevelMap[logEvent.Level],
Logger = logEvent.LoggerName, Logger = logEvent.LoggerName,
Message = logEvent.FormattedMessage, Message = logEvent.FormattedMessage,
Environment = UpdateBranch
}; };
sentryEvent.SetExtras(extras); sentryEvent.SetExtras(extras);
@ -261,6 +265,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry
sentryEvent.SetTag("os_name", osName); sentryEvent.SetTag("os_name", osName);
sentryEvent.SetTag("os_version", $"{osName} {osVersion}"); sentryEvent.SetTag("os_version", $"{osName} {osVersion}");
sentryEvent.SetTag("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}"); sentryEvent.SetTag("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}");
sentryEvent.SetTag("sqlite_version", $"{DatabaseVersion}");
sentryEvent.SetTag("database_migration", $"{DatabaseMigration}");
SentrySdk.CaptureEvent(sentryEvent); SentrySdk.CaptureEvent(sentryEvent);
} }

@ -3,7 +3,6 @@ using System.Linq;
using NLog; using NLog;
using NLog.Config; using NLog.Config;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Common.Instrumentation.Sentry;
using NzbDrone.Core.Configuration; using NzbDrone.Core.Configuration;
using NzbDrone.Core.Configuration.Events; using NzbDrone.Core.Configuration.Events;
using NzbDrone.Core.Messaging.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, "appFileDebug", minimumLogLevel <= LogLevel.Debug ? LogLevel.Debug : LogLevel.Off);
SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off); SetMinimumLogLevel(rules, "appFileTrace", minimumLogLevel <= LogLevel.Trace ? LogLevel.Trace : LogLevel.Off);
// Sentry filtering
LogManager.Configuration.FindTargetByName<SentryTarget>("sentryTarget").FilterEvents = _configFileProvider.FilterSentryEvents;
LogManager.ReconfigExistingLoggers(); LogManager.ReconfigExistingLoggers();
} }

@ -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<ApplicationStartedEvent>
{
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>("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();
}
}
}

@ -705,6 +705,7 @@
<Compile Include="Instrumentation\LogRepository.cs" /> <Compile Include="Instrumentation\LogRepository.cs" />
<Compile Include="Instrumentation\LogService.cs" /> <Compile Include="Instrumentation\LogService.cs" />
<Compile Include="Instrumentation\ReconfigureLogging.cs" /> <Compile Include="Instrumentation\ReconfigureLogging.cs" />
<Compile Include="Instrumentation\ReconfigureSentry.cs" />
<Compile Include="Instrumentation\SlowRunningAsyncTargetWrapper.cs" /> <Compile Include="Instrumentation\SlowRunningAsyncTargetWrapper.cs" />
<Compile Include="Jobs\ScheduledTaskRepository.cs" /> <Compile Include="Jobs\ScheduledTaskRepository.cs" />
<Compile Include="Jobs\ScheduledTask.cs" /> <Compile Include="Jobs\ScheduledTask.cs" />

Loading…
Cancel
Save