22
22
using System ;
23
23
using System . Collections . Generic ;
24
24
using System . Diagnostics ;
25
+ using System . Management . Automation . Host ;
25
26
using System . Security . Cryptography ;
26
27
using System . Text ;
27
28
@@ -31,6 +32,7 @@ public class MetricHelper
31
32
{
32
33
protected INetworkHelper _networkHelper ;
33
34
private const int FlushTimeoutInMilli = 5000 ;
35
+ private const string DEFAULT_PSVERSION = "3.0.0.0" ;
34
36
35
37
/// <summary>
36
38
/// The collection of telemetry clients.
@@ -56,6 +58,26 @@ public class MetricHelper
56
58
57
59
private static string _hashMacAddress = string . Empty ;
58
60
61
+ private static PSHost _host ;
62
+
63
+ private static string _psVersion ;
64
+
65
+ protected string PSVersion
66
+ {
67
+ get
68
+ {
69
+ if ( _host != null )
70
+ {
71
+ _psVersion = _host . Version . ToString ( ) ;
72
+ }
73
+ else
74
+ {
75
+ _psVersion = DEFAULT_PSVERSION ;
76
+ }
77
+ return _psVersion ;
78
+ }
79
+ }
80
+
59
81
public string HashMacAddress
60
82
{
61
83
get
@@ -168,7 +190,7 @@ private void LogUsageEvent(AzurePSQoSEvent qos)
168
190
{
169
191
var pageViewTelemetry = new PageViewTelemetry
170
192
{
171
- Name = qos . CommandName ?? "empty ",
193
+ Name = "cmdletInvocation ",
172
194
Duration = qos . Duration ,
173
195
Timestamp = qos . StartTime
174
196
} ;
@@ -214,13 +236,19 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
214
236
}
215
237
}
216
238
239
+ public void SetPSHost ( PSHost host )
240
+ {
241
+ _host = host ;
242
+ }
243
+
217
244
private void PopulatePropertiesFromQos ( AzurePSQoSEvent qos , IDictionary < string , string > eventProperties )
218
245
{
219
246
if ( qos == null )
220
247
{
221
248
return ;
222
249
}
223
250
251
+ eventProperties . Add ( "Command" , qos . CommandName ) ;
224
252
eventProperties . Add ( "IsSuccess" , qos . IsSuccess . ToString ( ) ) ;
225
253
eventProperties . Add ( "ModuleName" , qos . ModuleName ) ;
226
254
eventProperties . Add ( "ModuleVersion" , qos . ModuleVersion ) ;
@@ -231,6 +259,8 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
231
259
eventProperties . Add ( "x-ms-client-request-id" , qos . ClientRequestId ) ;
232
260
eventProperties . Add ( "UserAgent" , AzurePowerShell . UserAgentValue . ToString ( ) ) ;
233
261
eventProperties . Add ( "HashMacAddress" , HashMacAddress ) ;
262
+ eventProperties . Add ( "PowerShellVersion" , PSVersion ) ;
263
+ eventProperties . Add ( "Version" , AzurePowerShell . AssemblyVersion ) ;
234
264
if ( qos . InputFromPipeline != null )
235
265
{
236
266
eventProperties . Add ( "InputFromPipeline" , qos . InputFromPipeline . Value . ToString ( ) ) ;
0 commit comments