Skip to content

Commit 907b270

Browse files
authored
Add the OS Platform information in telemetry (#278)
1 parent 417ceb0 commit 907b270

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

shell/agents/Microsoft.Azure.Agent/Telemetry.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ public class AzTrace
1313
/// </summary>
1414
internal static string InstallationId { get; private set; }
1515

16+
/// <summary>
17+
/// OS platform the application is running on.
18+
/// </summary>
19+
internal static string OSPlatform { get; private set; }
20+
1621
internal static void Initialize()
1722
{
18-
InstallationId = null;
23+
InstallationId = GetInstallationId();
24+
OSPlatform = GetOSPlatform();
25+
}
1926

27+
private static string GetInstallationId()
28+
{
2029
string azCLIProfilePath, azPSHProfilePath;
2130
string azureConfigDir = Environment.GetEnvironmentVariable("AZURE_CONFIG_DIR");
2231
string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
@@ -38,20 +47,41 @@ internal static void Initialize()
3847
{
3948
using var stream = File.OpenRead(azCLIProfilePath);
4049
var jsonElement = JsonSerializer.Deserialize<JsonElement>(stream);
41-
InstallationId = jsonElement.GetProperty("installationId").GetString();
50+
return jsonElement.GetProperty("installationId").GetString();
4251
}
4352
else if (File.Exists(azPSHProfilePath))
4453
{
4554
using var stream = File.OpenRead(azPSHProfilePath);
4655
var jsonElement = JsonSerializer.Deserialize<JsonElement>(stream);
47-
InstallationId = jsonElement.GetProperty("Settings").GetProperty(nameof(InstallationId)).GetString();
56+
return jsonElement.GetProperty("Settings").GetProperty(nameof(InstallationId)).GetString();
4857
}
4958
}
5059
catch
5160
{
5261
// Something wrong when reading the config file.
53-
InstallationId = null;
5462
}
63+
64+
return null;
65+
}
66+
67+
private static string GetOSPlatform()
68+
{
69+
if (OperatingSystem.IsWindows())
70+
{
71+
return "Windows";
72+
}
73+
74+
if (OperatingSystem.IsLinux())
75+
{
76+
return "Linux";
77+
}
78+
79+
if (OperatingSystem.IsMacOS())
80+
{
81+
return "macOS";
82+
}
83+
84+
return "Unknown";
5585
}
5686

5787
/// <summary>
@@ -199,6 +229,7 @@ private void LogTelemetry(AzTrace trace, Exception exception)
199229
["EventType"] = trace.EventType,
200230
["ShellCommand"] = trace.ShellCommand,
201231
["Details"] = GetDetailedMessage(trace.Details),
232+
["OSPlatform"] = AzTrace.OSPlatform
202233
};
203234

204235
if (exception is null)

0 commit comments

Comments
 (0)