From 875366a00f7888c2de304aca54c97e15de2032b9 Mon Sep 17 00:00:00 2001 From: "Scott Beddall (from Dev Box)" Date: Fri, 9 Feb 2024 11:13:44 -0800 Subject: [PATCH] log the x-recording-id during LogRequestDetails from HandleRequestPlayback and HandleRequestRecord --- .../Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs | 12 ++++++++---- .../Azure.Sdk.Tools.TestProxy/RecordingHandler.cs | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs index a6f41f12a1e..c37ba2a8098 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs @@ -178,12 +178,14 @@ public static void LogAdminRequestDetails(ILogger loggerInstance, HttpRequest re /// /// The http request which needs to be detailed. /// The set of sanitizers to apply before logging. + /// By default, only headers that are used in matching are included in the log set. Use this to override the behavior without affecting other usages + /// of CreateNoBodyRecordEntry (which is used in core functionality) /// The log line. - public static void LogRequestDetails(HttpRequest req, IEnumerable sanitizers) + public static void LogRequestDetails(HttpRequest req, IEnumerable sanitizers, List additionalLoggedHeaders = null) { if (CheckLogLevel(LogLevel.Debug)) { - Logger.LogDebug(_generateLogLine(req, sanitizers)); + Logger.LogDebug(_generateLogLine(req, sanitizers, additionalLoggedHeaders)); } } @@ -193,10 +195,12 @@ public static void LogRequestDetails(HttpRequest req, IEnumerable /// The request /// The set of sanitizers to apply before logging. + /// By default, only headers that are used in matching are included in the log set. Use this to override the behavior without affecting other usages + /// of CreateNoBodyRecordEntry (which is used in core functionality) /// The log line. - private static string _generateLogLine(HttpRequest req, IEnumerable sanitizers) + private static string _generateLogLine(HttpRequest req, IEnumerable sanitizers, List additionalLoggedHeaders = null) { - RecordEntry entry = RecordingHandler.CreateNoBodyRecordEntry(req); + RecordEntry entry = RecordingHandler.CreateNoBodyRecordEntry(req, additionalLoggedHeaders); if (sanitizers != null) { diff --git a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs index 0beb7fca889..96531205480 100644 --- a/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs +++ b/tools/test-proxy/Azure.Sdk.Tools.TestProxy/RecordingHandler.cs @@ -456,7 +456,7 @@ public async Task HandlePlaybackRequest(string recordingId, HttpRequest incoming var sanitizers = session.AdditionalSanitizers.Count > 0 ? Sanitizers.Concat(session.AdditionalSanitizers) : Sanitizers; - DebugLogger.LogRequestDetails(incomingRequest, sanitizers); + DebugLogger.LogRequestDetails(incomingRequest, sanitizers, new List() { recordingId }); var entry = (await CreateEntryAsync(incomingRequest).ConfigureAwait(false)).Item1; @@ -563,15 +563,16 @@ public async Task WriteBodyBytes(byte[] bodyData, int playbackResponseTime, Http return (entry, bytes); } - public static RecordEntry CreateNoBodyRecordEntry(HttpRequest request) + public static RecordEntry CreateNoBodyRecordEntry(HttpRequest request, List additionalHeaders = null) { + if (additionalHeaders == null) additionalHeaders = new List(); var entry = new RecordEntry(); entry.RequestUri = GetRequestUri(request).AbsoluteUri; entry.RequestMethod = new RequestMethod(request.Method); foreach (var header in request.Headers) { - if (IncludeHeader(header.Key)) + if (IncludeHeader(header.Key) || additionalHeaders.Contains(header.Key)) { entry.Request.Headers.Add(header.Key, header.Value.ToArray()); }