From e27826955e6d8e27308811c2c048c12517f04c84 Mon Sep 17 00:00:00 2001 From: Ske Date: Thu, 27 Aug 2020 16:26:37 +0200 Subject: [PATCH] Properly tag request logs in metrics --- PluralKit.Bot/Tracing/DiscordRequestObserver.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Tracing/DiscordRequestObserver.cs b/PluralKit.Bot/Tracing/DiscordRequestObserver.cs index 644cd730..621a5cb9 100644 --- a/PluralKit.Bot/Tracing/DiscordRequestObserver.cs +++ b/PluralKit.Bot/Tracing/DiscordRequestObserver.cs @@ -56,6 +56,9 @@ namespace PluralKit.Bot if (response.RequestMessage.RequestUri.Host != "discord.com") return; + var routePath = NormalizeRoutePath(response.RequestMessage.RequestUri.LocalPath.Replace("/api/v7", "")); + var route = $"{response.RequestMessage.Method} {routePath}"; + using (LogContext.PushProperty("Elastic", "yes?")) { if ((int) response.StatusCode >= 400 && (int) response.StatusCode < 500) @@ -64,8 +67,6 @@ namespace PluralKit.Bot LogContext.PushProperty("ResponseBody", content); } - var routePath = NormalizeRoutePath(response.RequestMessage.RequestUri.LocalPath.Replace("/api/v7", "")); - var route = $"{response.RequestMessage.Method} {routePath}"; LogContext.PushProperty("RequestUrlRoute", route); _logger.Information( @@ -77,8 +78,11 @@ namespace PluralKit.Bot activity.Duration.TotalMilliseconds); } - var timer = _metrics.Provider.Timer.Instance(BotMetrics.DiscordApiRequests); - timer.Record(activity.Duration.Ticks / 10, TimeUnit.Microseconds, ((int) response.StatusCode).ToString()); + var timer = _metrics.Provider.Timer.Instance(BotMetrics.DiscordApiRequests, new MetricTags( + new[] {"endpoint", "status_code"}, + new[] {route, ((int) response.StatusCode).ToString()} + )); + timer.Record(activity.Duration.Ticks / 10, TimeUnit.Microseconds); } public void OnNext(KeyValuePair value)