Skip to content

Commit

Permalink
log the x-recording-id during LogRequestDetails from HandleRequestPla…
Browse files Browse the repository at this point in the history
…yback and HandleRequestRecord
  • Loading branch information
scbedd committed Feb 9, 2024
1 parent bb5aa51 commit 875366a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 8 additions & 4 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Common/DebugLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ public static void LogAdminRequestDetails(ILogger loggerInstance, HttpRequest re
/// </summary>
/// <param name="req">The http request which needs to be detailed.</param>
/// <param name="sanitizers">The set of sanitizers to apply before logging.</param>
/// <param name="additionalLoggedHeaders">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)</param>
/// <returns>The log line.</returns>
public static void LogRequestDetails(HttpRequest req, IEnumerable<RecordedTestSanitizer> sanitizers)
public static void LogRequestDetails(HttpRequest req, IEnumerable<RecordedTestSanitizer> sanitizers, List<string> additionalLoggedHeaders = null)
{
if (CheckLogLevel(LogLevel.Debug))
{
Logger.LogDebug(_generateLogLine(req, sanitizers));
Logger.LogDebug(_generateLogLine(req, sanitizers, additionalLoggedHeaders));
}
}

Expand All @@ -193,10 +195,12 @@ public static void LogRequestDetails(HttpRequest req, IEnumerable<RecordedTestSa
/// </summary>
/// <param name="req">The request</param>
/// <param name="sanitizers">The set of sanitizers to apply before logging.</param>
/// <param name="additionalLoggedHeaders">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)</param>
/// <returns>The log line.</returns>
private static string _generateLogLine(HttpRequest req, IEnumerable<RecordedTestSanitizer> sanitizers)
private static string _generateLogLine(HttpRequest req, IEnumerable<RecordedTestSanitizer> sanitizers, List<string> additionalLoggedHeaders = null)
{
RecordEntry entry = RecordingHandler.CreateNoBodyRecordEntry(req);
RecordEntry entry = RecordingHandler.CreateNoBodyRecordEntry(req, additionalLoggedHeaders);

if (sanitizers != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>() { recordingId });

var entry = (await CreateEntryAsync(incomingRequest).ConfigureAwait(false)).Item1;

Expand Down Expand Up @@ -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<string> additionalHeaders = null)
{
if (additionalHeaders == null) additionalHeaders = new List<string>();
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());
}
Expand Down

0 comments on commit 875366a

Please sign in to comment.