Skip to content

Commit 6353ac8

Browse files
authored
Add orchestrationId to useragent for better correlation. (#2568)
* Add orchestrationId to useragent for better correlation. * .
1 parent ad9a4a4 commit 6353ac8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Runner.Common/Constants.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace GitHub.Runner.Common
44
{
@@ -261,6 +261,7 @@ public static class System
261261
public static readonly string AccessToken = "system.accessToken";
262262
public static readonly string Culture = "system.culture";
263263
public static readonly string PhaseDisplayName = "system.phaseDisplayName";
264+
public static readonly string OrchestrationId = "system.orchestrationId";
264265
}
265266
}
266267

src/Runner.Worker/JobRunner.cs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Net.Http;
6+
using System.Net.Http.Headers;
67
using System.Text;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -42,6 +43,13 @@ public async Task<TaskResult> RunAsync(AgentJobRequestMessage message, Cancellat
4243
DateTime jobStartTimeUtc = DateTime.UtcNow;
4344
IRunnerService server = null;
4445

46+
// add orchestration id to useragent for better correlation.
47+
if (message.Variables.TryGetValue(Constants.Variables.System.OrchestrationId, out VariableValue orchestrationId) &&
48+
!string.IsNullOrEmpty(orchestrationId.Value))
49+
{
50+
HostContext.UserAgents.Add(new ProductInfoHeaderValue("OrchestrationId", orchestrationId.Value));
51+
}
52+
4553
ServiceEndpoint systemConnection = message.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase));
4654
if (MessageUtil.IsRunServiceJob(message.MessageType))
4755
{

0 commit comments

Comments
 (0)