mirror of
https://github.com/actions/runner.git
synced 2025-12-10 12:36:23 +00:00
Add request-id to http eventsource trace. (#3740)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user