diff --git a/PluralKit.Bot/Init.cs b/PluralKit.Bot/Init.cs index d305224f..70c4a753 100644 --- a/PluralKit.Bot/Init.cs +++ b/PluralKit.Bot/Init.cs @@ -12,6 +12,8 @@ using Myriad.Rest; using PluralKit.Core; +using Sentry; + using Serilog; using Serilog.Core; @@ -36,7 +38,15 @@ namespace PluralKit.Bot var logger = services.Resolve().ForContext(); // Initialize Sentry SDK, and make sure it gets dropped at the end - using var _ = Sentry.SentrySdk.Init(services.Resolve().SentryUrl); + var sentryDsn = services.Resolve().SentryUrl; + if (sentryDsn != null) + { + using var _ = Sentry.SentrySdk.Init((opts) => + { + opts.Dsn = new Dsn(sentryDsn); + opts.Release = BuildInfoService.FullVersion; + }); + } // "Connect to the database" (ie. set off database migrations and ensure state) logger.Information("Connecting to database"); diff --git a/PluralKit.Core/PluralKit.Core.csproj b/PluralKit.Core/PluralKit.Core.csproj index c7633f61..1ff7c389 100644 --- a/PluralKit.Core/PluralKit.Core.csproj +++ b/PluralKit.Core/PluralKit.Core.csproj @@ -52,7 +52,7 @@ - + diff --git a/PluralKit.Core/Services/BuildInfoService.cs b/PluralKit.Core/Services/BuildInfoService.cs index ee32c8b0..1d0a8fef 100644 --- a/PluralKit.Core/Services/BuildInfoService.cs +++ b/PluralKit.Core/Services/BuildInfoService.cs @@ -1,5 +1,4 @@ using System.IO; -using System.Reflection; using System.Threading.Tasks; namespace PluralKit.Core @@ -7,18 +6,26 @@ namespace PluralKit.Core public static class BuildInfoService { public static string Version { get; private set; } + public static string FullVersion { get; private set; } public static async Task LoadVersion() { using (var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version")) { // if this happens, something broke - if (stream == null) Version = "(unknown version) "; - else using (var reader = new StreamReader(stream)) Version = await reader.ReadToEndAsync(); + if (stream == null) FullVersion = "(unknown version) "; + else using (var reader = new StreamReader(stream)) FullVersion = await reader.ReadToEndAsync(); } // cheap hack to remove newline - Version = Version.Remove(Version.Length - 1); + FullVersion = FullVersion.Remove(FullVersion.Length - 1); + + // show only short commit hash to users + Version = FullVersion.Remove(7); + + // fix "dirty" git message + if (FullVersion.EndsWith("-dirty")) + Version += "-dirty"; } } } \ No newline at end of file