Correctly log errors from gateway event enrichers

This commit is contained in:
spiral 2021-07-28 02:09:52 -04:00
parent def39b7bc5
commit 43017c1522
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -179,6 +179,12 @@ namespace PluralKit.Bot
await using var serviceScope = _services.BeginLifetimeScope(); await using var serviceScope = _services.BeginLifetimeScope();
// Find an event handler that can handle the type of event (<T>) we're given
var handler = serviceScope.Resolve<IEventHandler<T>>();
var queue = serviceScope.ResolveOptional<HandlerQueue<T>>();
try
{
using var _ = LogContext.PushProperty("EventId", Guid.NewGuid()); using var _ = LogContext.PushProperty("EventId", Guid.NewGuid());
using var __ = LogContext.Push(serviceScope.Resolve<SerilogGatewayEnricherFactory>().GetEnricher(shard, evt)); using var __ = LogContext.Push(serviceScope.Resolve<SerilogGatewayEnricherFactory>().GetEnricher(shard, evt));
_logger.Verbose("Received gateway event: {@Event}", evt); _logger.Verbose("Received gateway event: {@Event}", evt);
@ -187,12 +193,6 @@ namespace PluralKit.Bot
var sentryEnricher = serviceScope.ResolveOptional<ISentryEnricher<T>>(); var sentryEnricher = serviceScope.ResolveOptional<ISentryEnricher<T>>();
sentryEnricher?.Enrich(serviceScope.Resolve<Scope>(), shard, evt); sentryEnricher?.Enrich(serviceScope.Resolve<Scope>(), shard, evt);
// Find an event handler that can handle the type of event (<T>) we're given
var handler = serviceScope.Resolve<IEventHandler<T>>();
var queue = serviceScope.ResolveOptional<HandlerQueue<T>>();
try
{
using var timer = _metrics.Measure.Timer.Time(BotMetrics.EventsHandled, using var timer = _metrics.Measure.Timer.Time(BotMetrics.EventsHandled,
new MetricTags("event", typeof(T).Name.Replace("Event", ""))); new MetricTags("event", typeof(T).Name.Replace("Event", "")));