From 72e2107b5e50a1c1e2b7555215e5829f615f5db5 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Mon, 25 Jul 2022 16:02:54 -0400 Subject: [PATCH] Change the auth challenge 401 to be verbose trace. (#2021) --- .../Common/Diagnostics/VssHttpEventSource.cs | 27 +++++++++++++++++-- .../Common/Common/VssHttpMessageHandler.cs | 9 ++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs b/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs index d2b0c513e..6d75e381f 100644 --- a/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs +++ b/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs @@ -351,6 +351,18 @@ namespace GitHub.Services.Common.Diagnostics } } + [NonEvent] + public void AuthenticationFailedOnFirstRequest( + VssTraceActivity activity, + HttpResponseMessage response) + { + if (IsEnabled()) + { + SetActivityId(activity); + WriteMessageEvent((Int32)response.StatusCode, response.Headers.ToString(), this.AuthenticationFailedOnFirstRequest); + } + } + [NonEvent] public void IssuedTokenProviderCreated( VssTraceActivity activity, @@ -451,7 +463,7 @@ namespace GitHub.Services.Common.Diagnostics [NonEvent] public void IssuedTokenInvalidated( VssTraceActivity activity, - IssuedTokenProvider provider, + IssuedTokenProvider provider, IssuedToken token) { if (IsEnabled()) @@ -813,7 +825,7 @@ namespace GitHub.Services.Common.Diagnostics [Event(31, Keywords = Keywords.Authentication, Level = EventLevel.Warning, Task = Tasks.Authentication, Opcode = EventOpcode.Info, Message = "Retrieving an AAD auth token took a long time ({0} seconds)")] public void AuthorizationDelayed(string timespan) { - if(IsEnabled(EventLevel.Warning, Keywords.Authentication)) + if (IsEnabled(EventLevel.Warning, Keywords.Authentication)) { WriteEvent(31, timespan); } @@ -828,6 +840,17 @@ namespace GitHub.Services.Common.Diagnostics } } + [Event(33, Keywords = Keywords.Authentication, Level = EventLevel.Verbose, Task = Tasks.HttpRequest, Message = "Authentication failed on first request with status code {0}.%n{1}")] + private void AuthenticationFailedOnFirstRequest( + Int32 statusCode, + String headers) + { + if (IsEnabled(EventLevel.Verbose, Keywords.Authentication)) + { + WriteEvent(33, statusCode, headers); + } + } + /// /// Sets the activity ID of the current thread. /// diff --git a/src/Sdk/Common/Common/VssHttpMessageHandler.cs b/src/Sdk/Common/Common/VssHttpMessageHandler.cs index 84ac561a1..b40f7ea21 100644 --- a/src/Sdk/Common/Common/VssHttpMessageHandler.cs +++ b/src/Sdk/Common/Common/VssHttpMessageHandler.cs @@ -251,7 +251,14 @@ namespace GitHub.Services.Common // Invalidate the token and ensure that we have the correct token provider for the challenge // which we just received - VssHttpEventSource.Log.AuthenticationFailed(traceActivity, response); + if (retries < m_maxAuthRetries) + { + VssHttpEventSource.Log.AuthenticationFailed(traceActivity, response); + } + else + { + VssHttpEventSource.Log.AuthenticationFailedOnFirstRequest(traceActivity, response); + } if (provider != null) {