Skip to content
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
39 changes: 35 additions & 4 deletions shell/agents/Microsoft.Azure.Agent/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ public class AzTrace
/// </summary>
internal static string InstallationId { get; private set; }

/// <summary>
/// OS platform the application is running on.
/// </summary>
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);
Expand All @@ -38,20 +47,41 @@ internal static void Initialize()
{
using var stream = File.OpenRead(azCLIProfilePath);
var jsonElement = JsonSerializer.Deserialize<JsonElement>(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<JsonElement>(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";
}

/// <summary>
Expand Down Expand Up @@ -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)
Expand Down