From 6353ac84d7a900ae3de499e1e697db4c372da6d1 Mon Sep 17 00:00:00 2001 From: Tingluo Huang Date: Wed, 26 Apr 2023 15:15:19 -0400 Subject: [PATCH] Add orchestrationId to useragent for better correlation. (#2568) * Add orchestrationId to useragent for better correlation. * . --- src/Runner.Common/Constants.cs | 3 ++- src/Runner.Worker/JobRunner.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Runner.Common/Constants.cs b/src/Runner.Common/Constants.cs index 86599ada0..ceddd4211 100644 --- a/src/Runner.Common/Constants.cs +++ b/src/Runner.Common/Constants.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace GitHub.Runner.Common { @@ -261,6 +261,7 @@ namespace GitHub.Runner.Common public static readonly string AccessToken = "system.accessToken"; public static readonly string Culture = "system.culture"; public static readonly string PhaseDisplayName = "system.phaseDisplayName"; + public static readonly string OrchestrationId = "system.orchestrationId"; } } diff --git a/src/Runner.Worker/JobRunner.cs b/src/Runner.Worker/JobRunner.cs index 3911bd340..77a93bf9d 100644 --- a/src/Runner.Worker/JobRunner.cs +++ b/src/Runner.Worker/JobRunner.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -42,6 +43,13 @@ namespace GitHub.Runner.Worker DateTime jobStartTimeUtc = DateTime.UtcNow; IRunnerService server = null; + // add orchestration id to useragent for better correlation. + if (message.Variables.TryGetValue(Constants.Variables.System.OrchestrationId, out VariableValue orchestrationId) && + !string.IsNullOrEmpty(orchestrationId.Value)) + { + HostContext.UserAgents.Add(new ProductInfoHeaderValue("OrchestrationId", orchestrationId.Value)); + } + ServiceEndpoint systemConnection = message.Resources.Endpoints.Single(x => string.Equals(x.Name, WellKnownServiceEndpointNames.SystemVssConnection, StringComparison.OrdinalIgnoreCase)); if (MessageUtil.IsRunServiceJob(message.MessageType)) {