diff --git a/Myriad/Rest/BaseRestClient.cs b/Myriad/Rest/BaseRestClient.cs index 68ecc9d6..f9f04000 100644 --- a/Myriad/Rest/BaseRestClient.cs +++ b/Myriad/Rest/BaseRestClient.cs @@ -209,12 +209,11 @@ namespace Myriad.Rest await HandleApiError(response, ignoreNotFound); - if (OnResponseEvent != null) - OnResponseEvent.Invoke(null, ( - GetEndpointMetricsName(response.RequestMessage!), - (int)response.StatusCode, - stopwatch.ElapsedTicks - )); + OnResponseEvent?.Invoke(null, ( + GetEndpointMetricsName(response.RequestMessage!), + (int)response.StatusCode, + stopwatch.ElapsedTicks + )); return response; }, diff --git a/Myriad/Rest/DiscordApiClient.cs b/Myriad/Rest/DiscordApiClient.cs index 3082574b..601a1309 100644 --- a/Myriad/Rest/DiscordApiClient.cs +++ b/Myriad/Rest/DiscordApiClient.cs @@ -19,7 +19,7 @@ namespace Myriad.Rest public DiscordApiClient(string token, ILogger logger, string? baseUrl = null) { _client = new BaseRestClient(UserAgent, token, logger, baseUrl ?? DefaultApiBaseUrl); - _client.OnResponseEvent += OnResponseEvent; + _client.OnResponseEvent += (_, ev) => OnResponseEvent?.Invoke(null, ev); } public EventHandler<(string, int, long)> OnResponseEvent; diff --git a/PluralKit.Bot/Modules.cs b/PluralKit.Bot/Modules.cs index 7c54ef4a..c348c1ad 100644 --- a/PluralKit.Bot/Modules.cs +++ b/PluralKit.Bot/Modules.cs @@ -52,10 +52,12 @@ namespace PluralKit.Bot c.Resolve<BotConfig>().DiscordBaseUrl ); + var metrics = c.Resolve<IMetrics>(); + client.OnResponseEvent += ((_, ev) => { var (endpoint, statusCode, ticks) = ev; - var timer = c.Resolve<IMetrics>().Provider.Timer.Instance(BotMetrics.DiscordApiRequests, new MetricTags( + var timer = metrics.Provider.Timer.Instance(BotMetrics.DiscordApiRequests, new MetricTags( new[] { "endpoint", "status_code" }, new[] { endpoint, statusCode.ToString() } ));