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,20 +179,20 @@ namespace PluralKit.Bot
await using var serviceScope = _services.BeginLifetimeScope(); await using var serviceScope = _services.BeginLifetimeScope();
using var _ = LogContext.PushProperty("EventId", Guid.NewGuid());
using var __ = LogContext.Push(serviceScope.Resolve<SerilogGatewayEnricherFactory>().GetEnricher(shard, evt));
_logger.Verbose("Received gateway event: {@Event}", evt);
// Also, find a Sentry enricher for the event type (if one is present), and ask it to put some event data in the Sentry scope
var sentryEnricher = serviceScope.ResolveOptional<ISentryEnricher<T>>();
sentryEnricher?.Enrich(serviceScope.Resolve<Scope>(), shard, evt);
// Find an event handler that can handle the type of event (<T>) we're given // Find an event handler that can handle the type of event (<T>) we're given
var handler = serviceScope.Resolve<IEventHandler<T>>(); var handler = serviceScope.Resolve<IEventHandler<T>>();
var queue = serviceScope.ResolveOptional<HandlerQueue<T>>(); var queue = serviceScope.ResolveOptional<HandlerQueue<T>>();
try try
{ {
using var _ = LogContext.PushProperty("EventId", Guid.NewGuid());
using var __ = LogContext.Push(serviceScope.Resolve<SerilogGatewayEnricherFactory>().GetEnricher(shard, evt));
_logger.Verbose("Received gateway event: {@Event}", evt);
// Also, find a Sentry enricher for the event type (if one is present), and ask it to put some event data in the Sentry scope
var sentryEnricher = serviceScope.ResolveOptional<ISentryEnricher<T>>();
sentryEnricher?.Enrich(serviceScope.Resolve<Scope>(), shard, evt);
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", "")));