Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding registry key for VS telemetry to identify if Agent is installed on the same machine as VS #5102

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/Agent.Listener/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
using System.Security.AccessControl;
using System.Security.Principal;
using Newtonsoft.Json;
using Microsoft.Win32;
using Microsoft.VisualStudio.Services.Agent.Listener.Telemetry;

namespace Microsoft.VisualStudio.Services.Agent.Listener.Configuration
@@ -42,6 +43,9 @@ public sealed class ConfigurationManager : AgentService, IConfigurationManager
private ILocationServer _locationServer;
private ServerUtil _serverUtil;

private const string VsTelemetryRegPath = @"SOFTWARE\Microsoft\VisualStudio\Telemetry\PersistentPropertyBag\c57a9efce9b74de382d905a89852db71";
private const string VsTelemetryRegKey = "IsPipelineAgent";

public override void Initialize(IHostContext hostContext)
{
ArgUtil.NotNull(hostContext, nameof(hostContext));
@@ -421,6 +425,12 @@ public async Task ConfigureAsync(CommandSettings command)
serviceControlManager.GenerateScripts(agentSettings);
}

if(PlatformUtil.RunningOnWindows)
{
// add vstelemetry registrykey
this.AddVSTelemetryRegKey();
}

try
{
var telemetryData = new Dictionary<string, string>
@@ -577,6 +587,12 @@ public async Task UnconfigureAsync(CommandSettings command)
// delete agent runtime option
_store.DeleteAgentRuntimeOptions();

if(PlatformUtil.RunningOnWindows)
{
// delete vstelemetry registrykey
this.DeleteVSTelemetryRegKey();
}

_store.DeleteSettings();
_term.WriteLine(StringUtil.Loc("Success") + currentAction);
}
@@ -855,6 +871,48 @@ private void WriteSection(string message)
_term.WriteLine();
}

[SupportedOSPlatform("windows")]
private void AddVSTelemetryRegKey()
{
try
{
//create the VsTelemetryRegKey under currentuser/VsTelemetryRegPath and set value to true
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(VsTelemetryRegPath, writable: true))
{
if (key != null && key.GetValue(VsTelemetryRegKey) == null)
{
key.SetValue(VsTelemetryRegKey, "s:true", RegistryValueKind.String);
}
}
}
catch (Exception)
{
// ignore failure as this is not critical to agent functionality
Trace.Info("Error while adding VSTelemetry regkey");
}
}

[SupportedOSPlatform("windows")]
private void DeleteVSTelemetryRegKey()
{
try
{
// delete the VsTelemetryRegKey under currentuser/VsTelemetryRegPath
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(VsTelemetryRegPath, writable: true))
{
if (key != null && key.GetValue(VsTelemetryRegKey) != null)
{
key.DeleteValue(VsTelemetryRegKey);
}
}
}
catch (Exception)
{
// ignore failure as this is not critical to agent functionality
Trace.Info("Error while deleting VSTelemetry regkey");
}
}

[SupportedOSPlatform("windows")]
private void CheckAgentRootDirectorySecure()
{