From 6c807d800ece5b8ae9e658f7680a7a7726d0b64a Mon Sep 17 00:00:00 2001 From: Todd Martin <106564991+trmartin4@users.noreply.github.com> Date: Wed, 9 Oct 2024 10:08:00 -0400 Subject: [PATCH] [PM-13317] Add client version log scope (#4869) * Add client version log scope * Removed extra dependency. --- .../Utilities/RequestLoggingMiddleware.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/SharedWeb/Utilities/RequestLoggingMiddleware.cs b/src/SharedWeb/Utilities/RequestLoggingMiddleware.cs index 4fb0e8f92..77efdbfcf 100644 --- a/src/SharedWeb/Utilities/RequestLoggingMiddleware.cs +++ b/src/SharedWeb/Utilities/RequestLoggingMiddleware.cs @@ -38,7 +38,8 @@ public sealed class RequestLoggingMiddleware new RequestLogScope(context.GetIpAddress(_globalSettings), GetHeaderValue(context, "user-agent"), GetHeaderValue(context, "device-type"), - GetHeaderValue(context, "device-type")))) + GetHeaderValue(context, "device-type"), + GetHeaderValue(context, "bitwarden-client-version")))) { return _next(context); } @@ -59,12 +60,13 @@ public sealed class RequestLoggingMiddleware { private string? _cachedToString; - public RequestLogScope(string? ipAddress, string? userAgent, string? deviceType, string? origin) + public RequestLogScope(string? ipAddress, string? userAgent, string? deviceType, string? origin, string? clientVersion) { IpAddress = ipAddress; UserAgent = userAgent; DeviceType = deviceType; Origin = origin; + ClientVersion = clientVersion; } public KeyValuePair this[int index] @@ -87,17 +89,22 @@ public sealed class RequestLoggingMiddleware { return new KeyValuePair(nameof(Origin), Origin); } + else if (index == 4) + { + return new KeyValuePair(nameof(ClientVersion), ClientVersion); + } throw new ArgumentOutOfRangeException(nameof(index)); } } - public int Count => 4; + public int Count => 5; public string? IpAddress { get; } public string? UserAgent { get; } public string? DeviceType { get; } public string? Origin { get; } + public string? ClientVersion { get; } public IEnumerator> GetEnumerator() { @@ -110,7 +117,7 @@ public sealed class RequestLoggingMiddleware public override string ToString() { - _cachedToString ??= $"IpAddress:{IpAddress} UserAgent:{UserAgent} DeviceType:{DeviceType} Origin:{Origin}"; + _cachedToString ??= $"IpAddress:{IpAddress} UserAgent:{UserAgent} DeviceType:{DeviceType} Origin:{Origin} ClientVersion:{ClientVersion}"; return _cachedToString; } }