diff --git a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs index 22466a9f..d68111c2 100644 --- a/shell/agents/Microsoft.Azure.Agent/Telemetry.cs +++ b/shell/agents/Microsoft.Azure.Agent/Telemetry.cs @@ -13,10 +13,19 @@ public class AzTrace /// internal static string InstallationId { get; private set; } + /// + /// OS platform the application is running on. + /// + internal static string OSPlatform { get; private set; } + internal static void Initialize() { - InstallationId = null; + InstallationId = GetInstallationId(); + OSPlatform = GetOSPlatform(); + } + private static string GetInstallationId() + { string azCLIProfilePath, azPSHProfilePath; string azureConfigDir = Environment.GetEnvironmentVariable("AZURE_CONFIG_DIR"); string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); @@ -38,20 +47,41 @@ internal static void Initialize() { using var stream = File.OpenRead(azCLIProfilePath); var jsonElement = JsonSerializer.Deserialize(stream); - InstallationId = jsonElement.GetProperty("installationId").GetString(); + return jsonElement.GetProperty("installationId").GetString(); } else if (File.Exists(azPSHProfilePath)) { using var stream = File.OpenRead(azPSHProfilePath); var jsonElement = JsonSerializer.Deserialize(stream); - InstallationId = jsonElement.GetProperty("Settings").GetProperty(nameof(InstallationId)).GetString(); + return jsonElement.GetProperty("Settings").GetProperty(nameof(InstallationId)).GetString(); } } catch { // Something wrong when reading the config file. - InstallationId = null; } + + return null; + } + + private static string GetOSPlatform() + { + if (OperatingSystem.IsWindows()) + { + return "Windows"; + } + + if (OperatingSystem.IsLinux()) + { + return "Linux"; + } + + if (OperatingSystem.IsMacOS()) + { + return "macOS"; + } + + return "Unknown"; } /// @@ -199,6 +229,7 @@ private void LogTelemetry(AzTrace trace, Exception exception) ["EventType"] = trace.EventType, ["ShellCommand"] = trace.ShellCommand, ["Details"] = GetDetailedMessage(trace.Details), + ["OSPlatform"] = AzTrace.OSPlatform }; if (exception is null)