Log response headers
This commit is contained in:
parent
35f0c342b6
commit
2005ce3296
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@ -20,6 +21,9 @@ namespace PluralKit.Bot
|
|||||||
private readonly IMetrics _metrics;
|
private readonly IMetrics _metrics;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private bool ShouldLogHeader(string name) =>
|
||||||
|
name.StartsWith("x-ratelimit");
|
||||||
|
|
||||||
public DiscordRequestObserver(ILogger logger, IMetrics metrics)
|
public DiscordRequestObserver(ILogger logger, IMetrics metrics)
|
||||||
{
|
{
|
||||||
_metrics = metrics;
|
_metrics = metrics;
|
||||||
@ -78,9 +82,15 @@ namespace PluralKit.Bot
|
|||||||
var content = await response.Content.ReadAsStringAsync();
|
var content = await response.Content.ReadAsStringAsync();
|
||||||
LogContext.PushProperty("ResponseBody", content);
|
LogContext.PushProperty("ResponseBody", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var headers = response.Headers
|
||||||
|
.Where(header => ShouldLogHeader(header.Key.ToLowerInvariant()))
|
||||||
|
.ToDictionary(k => k.Key.ToLowerInvariant(),
|
||||||
|
v => string.Join(';', v.Value));
|
||||||
|
|
||||||
_logger
|
_logger
|
||||||
.ForContext("RequestUrlRoute", endpoint)
|
.ForContext("RequestUrlRoute", endpoint)
|
||||||
|
.ForContext("ResponseHeaders", headers)
|
||||||
.Debug(
|
.Debug(
|
||||||
"HTTP: {RequestMethod} {RequestUrl} -> {ResponseStatusCode} {ResponseStatusString} (in {RequestDurationMs:F1} ms)",
|
"HTTP: {RequestMethod} {RequestUrl} -> {ResponseStatusCode} {ResponseStatusString} (in {RequestDurationMs:F1} ms)",
|
||||||
response.RequestMessage.Method,
|
response.RequestMessage.Method,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user