feat: add git commit hash to Serilog context

This commit is contained in:
spiral 2022-01-24 08:13:59 -05:00
parent 2e387ecee9
commit c38ca2e7fa
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
4 changed files with 9 additions and 6 deletions

View File

@ -115,7 +115,7 @@ public class Startup
// add X-PluralKit-Version header // add X-PluralKit-Version header
app.Use((ctx, next) => app.Use((ctx, next) =>
{ {
ctx.Response.Headers.Add("X-PluralKit-Version", BuildInfoService.Version); ctx.Response.Headers.Add("X-PluralKit-Version", BuildInfoService.FullVersion);
return next(); return next();
}); });

View File

@ -16,20 +16,20 @@ namespace PluralKit.Bot;
public class Init public class Init
{ {
private static Task Main(string[] args) private static async Task Main(string[] args)
{ {
// Load configuration and run global init stuff // Load configuration and run global init stuff
var config = InitUtils.BuildConfiguration(args).Build(); var config = InitUtils.BuildConfiguration(args).Build();
InitUtils.InitStatic(); InitUtils.InitStatic();
// init version service
await BuildInfoService.LoadVersion();
// Set up DI container and modules // Set up DI container and modules
var services = BuildContainer(config); var services = BuildContainer(config);
return RunWrapper(services, async ct => await RunWrapper(services, async ct =>
{ {
// init version service
await BuildInfoService.LoadVersion();
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

View File

@ -52,6 +52,7 @@ public class LoggingModule: Module
var logCfg = _cfg var logCfg = _cfg
.Enrich.FromLogContext() .Enrich.FromLogContext()
.Enrich.WithProperty("GitCommitHash", BuildInfoService.FullVersion)
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb) .ConfigureForNodaTime(DateTimeZoneProviders.Tzdb)
.Enrich.WithProperty("Component", _component) .Enrich.WithProperty("Component", _component)
.MinimumLevel.Is(config.ConsoleLogLevel) .MinimumLevel.Is(config.ConsoleLogLevel)

View File

@ -16,6 +16,8 @@ internal class Startup
var config = InitUtils.BuildConfiguration(args).Build(); var config = InitUtils.BuildConfiguration(args).Build();
InitUtils.InitStatic(); InitUtils.InitStatic();
await BuildInfoService.LoadVersion();
var services = BuildContainer(config); var services = BuildContainer(config);
services.Resolve<TaskHandler>().Run(); services.Resolve<TaskHandler>().Run();