@@ -13,10 +13,19 @@ public class AzTrace
13
13
/// </summary>
14
14
internal static string InstallationId { get ; private set ; }
15
15
16
+ /// <summary>
17
+ /// OS platform the application is running on.
18
+ /// </summary>
19
+ internal static string OSPlatform { get ; private set ; }
20
+
16
21
internal static void Initialize ( )
17
22
{
18
- InstallationId = null ;
23
+ InstallationId = GetInstallationId ( ) ;
24
+ OSPlatform = GetOSPlatform ( ) ;
25
+ }
19
26
27
+ private static string GetInstallationId ( )
28
+ {
20
29
string azCLIProfilePath , azPSHProfilePath ;
21
30
string azureConfigDir = Environment . GetEnvironmentVariable ( "AZURE_CONFIG_DIR" ) ;
22
31
string userProfile = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
@@ -38,20 +47,41 @@ internal static void Initialize()
38
47
{
39
48
using var stream = File . OpenRead ( azCLIProfilePath ) ;
40
49
var jsonElement = JsonSerializer . Deserialize < JsonElement > ( stream ) ;
41
- InstallationId = jsonElement . GetProperty ( "installationId" ) . GetString ( ) ;
50
+ return jsonElement . GetProperty ( "installationId" ) . GetString ( ) ;
42
51
}
43
52
else if ( File . Exists ( azPSHProfilePath ) )
44
53
{
45
54
using var stream = File . OpenRead ( azPSHProfilePath ) ;
46
55
var jsonElement = JsonSerializer . Deserialize < JsonElement > ( stream ) ;
47
- InstallationId = jsonElement . GetProperty ( "Settings" ) . GetProperty ( nameof ( InstallationId ) ) . GetString ( ) ;
56
+ return jsonElement . GetProperty ( "Settings" ) . GetProperty ( nameof ( InstallationId ) ) . GetString ( ) ;
48
57
}
49
58
}
50
59
catch
51
60
{
52
61
// Something wrong when reading the config file.
53
- InstallationId = null ;
54
62
}
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" ;
55
85
}
56
86
57
87
/// <summary>
@@ -199,6 +229,7 @@ private void LogTelemetry(AzTrace trace, Exception exception)
199
229
[ "EventType" ] = trace . EventType ,
200
230
[ "ShellCommand" ] = trace . ShellCommand ,
201
231
[ "Details" ] = GetDetailedMessage ( trace . Details ) ,
232
+ [ "OSPlatform" ] = AzTrace . OSPlatform
202
233
} ;
203
234
204
235
if ( exception is null )
0 commit comments