@@ -66,26 +66,14 @@ public class MetricHelper
66
66
67
67
private AzurePSDataCollectionProfile _profile ;
68
68
69
- private static PSHost _host ;
70
-
71
- private static string _psVersion ;
72
-
69
+ [ Obsolete ( "Should use AzurePSCmdlet.PowerShellVersion" ) ]
73
70
protected string PSVersion
74
71
{
75
72
get
76
73
{
77
- if ( _host != null )
78
- {
79
- _psVersion = _host . Version . ToString ( ) ;
80
- }
81
- else
82
- {
83
- _psVersion = DefaultPSVersion ;
84
- }
85
- return _psVersion ;
74
+ return DefaultPSVersion ;
86
75
}
87
76
}
88
-
89
77
public string HashMacAddress
90
78
{
91
79
get
@@ -256,9 +244,9 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
256
244
}
257
245
}
258
246
247
+ [ Obsolete ( ) ]
259
248
public void SetPSHost ( PSHost host )
260
249
{
261
- _host = host ;
262
250
}
263
251
264
252
private void PopulatePropertiesFromQos ( AzurePSQoSEvent qos , IDictionary < string , string > eventProperties , bool populateException = false )
@@ -268,18 +256,22 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
268
256
return ;
269
257
}
270
258
271
- eventProperties . Add ( "telemetry-version" , "1" ) ;
259
+ // Breaking change of telemetry
260
+ // * 2, change host version to real PowerShell version. Original version was PowerShell host version which is not always the same as PS version
261
+ // and can be customized.
262
+ eventProperties . Add ( "telemetry-version" , "2" ) ;
272
263
eventProperties . Add ( "Command" , qos . CommandName ) ;
273
264
eventProperties . Add ( "IsSuccess" , qos . IsSuccess . ToString ( ) ) ;
274
265
eventProperties . Add ( "ModuleName" , qos . ModuleName ) ;
275
266
eventProperties . Add ( "ModuleVersion" , qos . ModuleVersion ) ;
276
267
eventProperties . Add ( "HostVersion" , qos . HostVersion ) ;
268
+ eventProperties . Add ( "HostName" , qos . PSHostName ) ;
277
269
eventProperties . Add ( "OS" , Environment . OSVersion . ToString ( ) ) ;
278
270
eventProperties . Add ( "CommandParameters" , qos . Parameters ) ;
279
271
eventProperties . Add ( "x-ms-client-request-id" , qos . ClientRequestId ) ;
280
272
eventProperties . Add ( "UserAgent" , qos . UserAgent ) ;
281
273
eventProperties . Add ( "HashMacAddress" , HashMacAddress ) ;
282
- eventProperties . Add ( "PowerShellVersion" , PSVersion ) ;
274
+ eventProperties . Add ( "PowerShellVersion" , qos . PSVersion ) ;
283
275
eventProperties . Add ( "Version" , qos . AzVersion ) ;
284
276
eventProperties . Add ( "CommandParameterSetName" , qos . ParameterSetName ) ;
285
277
eventProperties . Add ( "CommandInvocationName" , qos . InvocationName ) ;
@@ -538,7 +530,12 @@ public class AzurePSQoSEvent
538
530
public string CommandName { get ; set ; }
539
531
public string ModuleName { get ; set ; }
540
532
public string ModuleVersion { get ; set ; }
533
+ //Version of PowerShell runspace ($Host.Runspace.Version)
534
+ public string PSVersion { get ; set ; }
535
+ //Host version of PowerShell ($Host.Version) which can be customized by PowerShell wrapper
541
536
public string HostVersion { get ; set ; }
537
+ //Host Name of PowerShell
538
+ public string PSHostName { get ; set ; }
542
539
public string AzVersion { get ; set ; }
543
540
public string UserAgent { get ; set ; }
544
541
public string Parameters { get ; set ; }
@@ -583,11 +580,12 @@ public void FinishQosEvent()
583
580
584
581
public override string ToString ( )
585
582
{
586
- string ret = string . Format (
587
- "AzureQoSEvent: CommandName - {0}; IsSuccess - {1}; Duration - {2}" , CommandName , IsSuccess , Duration ) ;
583
+ string ret = $ "AzureQoSEvent: Module: { ModuleName } :{ ModuleVersion } ; CommandName: { CommandName } ; PSVersion: { PSVersion } ";
584
+ ret += $ "; IsSuccess: { IsSuccess } ; Duration: { Duration } ";
585
+
588
586
if ( Exception != null )
589
587
{
590
- ret = $ "{ ret } ; Exception - { Exception . Message } ;";
588
+ ret + = $ "; Exception: { Exception . Message } ;";
591
589
}
592
590
return ret ;
593
591
}
0 commit comments