feat: show full commit version hash in sentry logs

This commit is contained in:
spiral 2021-11-07 03:09:45 -05:00
parent 037f54b41a
commit d19f6456a7
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
3 changed files with 23 additions and 6 deletions

View File

@ -12,6 +12,8 @@ using Myriad.Rest;
using PluralKit.Core; using PluralKit.Core;
using Sentry;
using Serilog; using Serilog;
using Serilog.Core; using Serilog.Core;
@ -36,7 +38,15 @@ namespace PluralKit.Bot
var logger = services.Resolve<ILogger>().ForContext<Init>(); var logger = services.Resolve<ILogger>().ForContext<Init>();
// Initialize Sentry SDK, and make sure it gets dropped at the end // Initialize Sentry SDK, and make sure it gets dropped at the end
using var _ = Sentry.SentrySdk.Init(services.Resolve<CoreConfig>().SentryUrl); var sentryDsn = services.Resolve<CoreConfig>().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) // "Connect to the database" (ie. set off database migrations and ensure state)
logger.Information("Connecting to database"); logger.Information("Connecting to database");

View File

@ -52,7 +52,7 @@
</ItemGroup> </ItemGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation"> <Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git describe --long --always --dirty --exclude=* --abbrev=7 > ../.version" IgnoreExitCode="False"> <Exec Command="git describe --long --always --dirty --exclude=* > ../.version" IgnoreExitCode="False">
</Exec> </Exec>
</Target> </Target>

View File

@ -1,5 +1,4 @@
using System.IO; using System.IO;
using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace PluralKit.Core namespace PluralKit.Core
@ -7,18 +6,26 @@ namespace PluralKit.Core
public static class BuildInfoService public static class BuildInfoService
{ {
public static string Version { get; private set; } public static string Version { get; private set; }
public static string FullVersion { get; private set; }
public static async Task LoadVersion() public static async Task LoadVersion()
{ {
using (var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version")) using (var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version"))
{ {
// if this happens, something broke // if this happens, something broke
if (stream == null) Version = "(unknown version) "; if (stream == null) FullVersion = "(unknown version) ";
else using (var reader = new StreamReader(stream)) Version = await reader.ReadToEndAsync(); else using (var reader = new StreamReader(stream)) FullVersion = await reader.ReadToEndAsync();
} }
// cheap hack to remove newline // 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";
} }
} }
} }