diff --git a/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs b/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs index 6d75e381f..4d232c9e1 100644 --- a/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs +++ b/src/Sdk/Common/Common/Diagnostics/VssHttpEventSource.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics.Tracing; using System.Globalization; +using System.Linq; using System.Net; using System.Net.Http; using System.Net.Sockets; @@ -335,7 +336,25 @@ namespace GitHub.Services.Common.Diagnostics if (IsEnabled()) { SetActivityId(activity); - HttpRequestStop(response.RequestMessage.GetHttpMethod(), response.RequestMessage.RequestUri.AbsoluteUri, (Int32)response.StatusCode); + var requestId = "NoExpectedHeader"; + if (response.Headers != null) + { + if (response.Headers.TryGetValues("x-github-request-id", out var headerValues) && headerValues != null) + { + requestId = headerValues.FirstOrDefault(); + } + else if (response.Headers.TryGetValues("x-vss-e2eid", out headerValues) && headerValues != null) + { + requestId = headerValues.FirstOrDefault(); + } + + if (string.IsNullOrEmpty(requestId)) + { + requestId = "NoExpectedHeader"; + } + } + + HttpRequestStop(response.RequestMessage.GetHttpMethod(), response.RequestMessage.RequestUri.AbsoluteUri, (Int32)response.StatusCode, requestId); } } @@ -747,15 +766,16 @@ namespace GitHub.Services.Common.Diagnostics } } - [Event(24, Level = EventLevel.Verbose, Task = Tasks.HttpRequest, Opcode = EventOpcode.Stop, Message = "Finished {0} request to {1} with status code {2}")] + [Event(24, Level = EventLevel.Verbose, Task = Tasks.HttpRequest, Opcode = EventOpcode.Stop, Message = "Finished {0} request to {1} with status code {2} ({3})")] private void HttpRequestStop( VssHttpMethod method, String url, - Int32 statusCode) + Int32 statusCode, + String requestId) { if (IsEnabled()) { - WriteEvent(24, (Int32)method, url, statusCode); + WriteEvent(24, (Int32)method, url, statusCode, requestId); } }