Add metrics for error/event rates
This commit is contained in:
parent
0ac180c4e6
commit
6fb979e74d
@ -117,8 +117,12 @@ namespace PluralKit.Bot
|
|||||||
// 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 timer = _metrics.Measure.Timer.Time(BotMetrics.EventsHandled,
|
||||||
|
new MetricTags("event", typeof(T).Name.Replace("EventArgs", "")));
|
||||||
|
|
||||||
// Delegate to the queue to see if it wants to handle this event
|
// Delegate to the queue to see if it wants to handle this event
|
||||||
// the TryHandle call returns true if it's handled the event
|
// the TryHandle call returns true if it's handled the event
|
||||||
// Usually it won't, so just pass it on to the main handler
|
// Usually it won't, so just pass it on to the main handler
|
||||||
@ -135,6 +139,8 @@ namespace PluralKit.Bot
|
|||||||
private async Task HandleError<T>(IEventHandler<T> handler, T evt, ILifetimeScope serviceScope, Exception exc)
|
private async Task HandleError<T>(IEventHandler<T> handler, T evt, ILifetimeScope serviceScope, Exception exc)
|
||||||
where T: DiscordEventArgs
|
where T: DiscordEventArgs
|
||||||
{
|
{
|
||||||
|
_metrics.Measure.Meter.Mark(BotMetrics.BotErrors, exc.GetType().FullName);
|
||||||
|
|
||||||
// Make this beforehand so we can access the event ID for logging
|
// Make this beforehand so we can access the event ID for logging
|
||||||
var sentryEvent = new SentryEvent(exc);
|
var sentryEvent = new SentryEvent(exc);
|
||||||
|
|
||||||
|
@ -22,5 +22,7 @@ namespace PluralKit.Bot
|
|||||||
public static TimerOptions MessageContextQueryTime => new TimerOptions { Name = "Message context query duration", Context = "Bot", RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, MeasurementUnit = Unit.Calls };
|
public static TimerOptions MessageContextQueryTime => new TimerOptions { Name = "Message context query duration", Context = "Bot", RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, MeasurementUnit = Unit.Calls };
|
||||||
public static TimerOptions ProxyMembersQueryTime => new TimerOptions { Name = "Proxy member query duration", Context = "Bot", RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, MeasurementUnit = Unit.Calls };
|
public static TimerOptions ProxyMembersQueryTime => new TimerOptions { Name = "Proxy member query duration", Context = "Bot", RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, MeasurementUnit = Unit.Calls };
|
||||||
public static TimerOptions DiscordApiRequests => new TimerOptions { Name = "Discord API requests", MeasurementUnit = Unit.Requests, Context = "Bot"};
|
public static TimerOptions DiscordApiRequests => new TimerOptions { Name = "Discord API requests", MeasurementUnit = Unit.Requests, Context = "Bot"};
|
||||||
|
public static MeterOptions BotErrors => new MeterOptions { Name = "Bot errors", MeasurementUnit = Unit.Errors, RateUnit = TimeUnit.Seconds, Context = "Bot"};
|
||||||
|
public static TimerOptions EventsHandled => new TimerOptions { Name = "Events handled", MeasurementUnit = Unit.Errors, RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, Context = "Bot"};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user