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,8 @@ public class MetricHelper
31
32
{
32
33
protected INetworkHelper _networkHelper ;
33
34
private const int FlushTimeoutInMilli = 5000 ;
35
+ private const string DefaultPSVersion = "3.0.0.0" ;
36
+ private const string EventName = "cmdletInvocation" ;
34
37
35
38
/// <summary>
36
39
/// The collection of telemetry clients.
@@ -58,6 +61,26 @@ public class MetricHelper
58
61
59
62
private AzurePSDataCollectionProfile _profile ;
60
63
64
+ private static PSHost _host ;
65
+
66
+ private static string _psVersion ;
67
+
68
+ protected string PSVersion
69
+ {
70
+ get
71
+ {
72
+ if ( _host != null )
73
+ {
74
+ _psVersion = _host . Version . ToString ( ) ;
75
+ }
76
+ else
77
+ {
78
+ _psVersion = DefaultPSVersion ;
79
+ }
80
+ return _psVersion ;
81
+ }
82
+ }
83
+
61
84
public string HashMacAddress
62
85
{
63
86
get
@@ -171,7 +194,7 @@ private void LogUsageEvent(AzurePSQoSEvent qos)
171
194
{
172
195
var pageViewTelemetry = new PageViewTelemetry
173
196
{
174
- Name = qos . CommandName ?? "empty" ,
197
+ Name = EventName ,
175
198
Duration = qos . Duration ,
176
199
Timestamp = qos . StartTime
177
200
} ;
@@ -217,13 +240,19 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
217
240
}
218
241
}
219
242
243
+ public void SetPSHost ( PSHost host )
244
+ {
245
+ _host = host ;
246
+ }
247
+
220
248
private void PopulatePropertiesFromQos ( AzurePSQoSEvent qos , IDictionary < string , string > eventProperties )
221
249
{
222
250
if ( qos == null )
223
251
{
224
252
return ;
225
253
}
226
254
255
+ eventProperties . Add ( "Command" , qos . CommandName ) ;
227
256
eventProperties . Add ( "IsSuccess" , qos . IsSuccess . ToString ( ) ) ;
228
257
eventProperties . Add ( "ModuleName" , qos . ModuleName ) ;
229
258
eventProperties . Add ( "ModuleVersion" , qos . ModuleVersion ) ;
@@ -234,6 +263,8 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
234
263
eventProperties . Add ( "x-ms-client-request-id" , qos . ClientRequestId ) ;
235
264
eventProperties . Add ( "UserAgent" , AzurePowerShell . UserAgentValue . ToString ( ) ) ;
236
265
eventProperties . Add ( "HashMacAddress" , HashMacAddress ) ;
266
+ eventProperties . Add ( "PowerShellVersion" , PSVersion ) ;
267
+ eventProperties . Add ( "Version" , AzurePowerShell . AssemblyVersion ) ;
237
268
if ( qos . InputFromPipeline != null )
238
269
{
239
270
eventProperties . Add ( "InputFromPipeline" , qos . InputFromPipeline . Value . ToString ( ) ) ;
0 commit comments