Skip to content

Commit

Permalink
Add the exact operation system version and environment to the telemet…
Browse files Browse the repository at this point in the history
…ry (#4104)

* Update TaskRunner.cs

* Update build-job.yml

* Added new variables to telemetry AgentName, MachineName, IsSelfHosted

Co-authored-by: Kirill Ivlev <102740624+kirill-ivlev@users.noreply.github.com>
  • Loading branch information
2 people authored and ivanduplenskikh committed Nov 8, 2023
1 parent 7989427 commit 23e79fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Agent.Worker/Build/BuildDirectoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private bool ShouldOverrideBuildDirectory(IList<RepositoryResource> repositories
{
if (repositories?.Count == 1 && repositories[0].Type == RepositoryTypes.Tfvc)
{
return settings.IsHosted;
return settings.IsMSHosted;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/Agent.Worker/JobRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public async Task<TaskResult> RunAsync(Pipelines.AgentJobRequestMessage message,
jobContext.SetVariable(Constants.Variables.Agent.HomeDirectory, HostContext.GetDirectory(WellKnownDirectory.Root), isFilePath: true);
jobContext.SetVariable(Constants.Variables.Agent.JobName, message.JobDisplayName);
jobContext.SetVariable(Constants.Variables.Agent.CloudId, settings.AgentCloudId);
jobContext.SetVariable(Constants.Variables.Agent.IsSelfHosted, settings.IsMSHosted ? "0" : "1");
jobContext.SetVariable(Constants.Variables.Agent.MachineName, Environment.MachineName);
jobContext.SetVariable(Constants.Variables.Agent.Name, settings.AgentName);
jobContext.SetVariable(Constants.Variables.Agent.OS, VarUtil.OS);
Expand Down
10 changes: 8 additions & 2 deletions src/Agent.Worker/TaskRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,24 @@ private void PublishTelemetry(Definition taskDefinition, HandlerData handlerData

var useNode10 = AgentKnobs.UseNode10.GetValue(ExecutionContext).AsString();
var expectedExecutionHandler = (taskDefinition.Data.Execution?.All != null) ? string.Join(", ", taskDefinition.Data.Execution.All) : "";
var systemVersion = PlatformUtil.GetSystemVersion();

Dictionary<string, string> telemetryData = new Dictionary<string, string>
{
{ "TaskName", Task.Reference.Name },
{ "TaskId", Task.Reference.Id.ToString() },
{ "Version", Task.Reference.Version },
{ "OS", PlatformUtil.HostOS.ToString() },
{ "OS", PlatformUtil.GetSystemId() ?? "" },
{ "OSVersion", systemVersion?.Name?.ToString() ?? "" },
{ "OSBuild", systemVersion?.Version?.ToString() ?? "" },
{ "ExpectedExecutionHandler", expectedExecutionHandler },
{ "RealExecutionHandler", handlerData.ToString() },
{ "UseNode10", useNode10 },
{ "JobId", ExecutionContext.Variables.System_JobId.ToString()},
{ "PlanId", ExecutionContext.Variables.Get("system.planId")}
{ "PlanId", ExecutionContext.Variables.Get(Constants.Variables.System.JobId)},
{ "AgentName", ExecutionContext.Variables.Get(Constants.Variables.Agent.Name)},
{ "MachineName", ExecutionContext.Variables.Get(Constants.Variables.Agent.MachineName)},
{ "IsSelfHosted", ExecutionContext.Variables.Get(Constants.Variables.Agent.IsSelfHosted)}
};

var cmd = new Command("telemetry", "publish");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public sealed class AgentSettings
public bool EnableServiceSidTypeUnrestricted { get; set; }

[IgnoreDataMember]
public bool IsHosted => AgentCloudId != null;
public bool IsMSHosted => AgentCloudId != null;

[DataMember(EmitDefaultValue = false)]
public string Fingerprint
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.VisualStudio.Services.Agent/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public static class Agent
public static readonly string Diagnostic = "agent.diagnostic";
public static readonly string HomeDirectory = "agent.homedirectory";
public static readonly string Id = "agent.id";
public static readonly string IsSelfHosted = "agent.isselfhosted";
public static readonly string GitUseSChannel = "agent.gituseschannel";
public static readonly string JobName = "agent.jobname";
public static readonly string JobStatus = "agent.jobstatus";
Expand Down Expand Up @@ -431,6 +432,7 @@ public static class System
public static readonly string PhaseAttempt = "system.phaseAttempt";
public static readonly string PhaseDisplayName = "system.phaseDisplayName";
public static readonly string PhaseName = "system.phaseName";
public static readonly string PlanId = "system.planId";
public static readonly string PreferGitFromPath = "system.prefergitfrompath";
public static readonly string PullRequestTargetBranchName = "system.pullrequest.targetbranch";
public static readonly string SelfManageGitCreds = "system.selfmanagegitcreds";
Expand Down Expand Up @@ -472,6 +474,7 @@ public static class Task
Agent.GitUseSChannel,
Agent.HomeDirectory,
Agent.Id,
Agent.IsSelfHosted,
Agent.JobName,
Agent.JobStatus,
Agent.MachineName,
Expand Down Expand Up @@ -571,6 +574,7 @@ public static class Task
System.PhaseAttempt,
System.PhaseDisplayName,
System.PhaseName,
System.PlanId,
System.PreferGitFromPath,
System.PullRequestTargetBranchName,
System.SelfManageGitCreds,
Expand Down

0 comments on commit 23e79fb

Please sign in to comment.