@@ -66,26 +66,14 @@ public class MetricHelper
6666
6767 private AzurePSDataCollectionProfile _profile ;
6868
69- private static PSHost _host ;
70-
71- private static string _psVersion ;
72-
69+ [ Obsolete ( "Should use AzurePSCmdlet.PowerShellVersion" ) ]
7370 protected string PSVersion
7471 {
7572 get
7673 {
77- if ( _host != null )
78- {
79- _psVersion = _host . Version . ToString ( ) ;
80- }
81- else
82- {
83- _psVersion = DefaultPSVersion ;
84- }
85- return _psVersion ;
74+ return DefaultPSVersion ;
8675 }
8776 }
88-
8977 public string HashMacAddress
9078 {
9179 get
@@ -256,9 +244,9 @@ private void LoadTelemetryClientContext(AzurePSQoSEvent qos, TelemetryContext cl
256244 }
257245 }
258246
247+ [ Obsolete ( ) ]
259248 public void SetPSHost ( PSHost host )
260249 {
261- _host = host ;
262250 }
263251
264252 private void PopulatePropertiesFromQos ( AzurePSQoSEvent qos , IDictionary < string , string > eventProperties , bool populateException = false )
@@ -268,18 +256,22 @@ private void PopulatePropertiesFromQos(AzurePSQoSEvent qos, IDictionary<string,
268256 return ;
269257 }
270258
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" ) ;
272263 eventProperties . Add ( "Command" , qos . CommandName ) ;
273264 eventProperties . Add ( "IsSuccess" , qos . IsSuccess . ToString ( ) ) ;
274265 eventProperties . Add ( "ModuleName" , qos . ModuleName ) ;
275266 eventProperties . Add ( "ModuleVersion" , qos . ModuleVersion ) ;
276267 eventProperties . Add ( "HostVersion" , qos . HostVersion ) ;
268+ eventProperties . Add ( "HostName" , qos . PSHostName ) ;
277269 eventProperties . Add ( "OS" , Environment . OSVersion . ToString ( ) ) ;
278270 eventProperties . Add ( "CommandParameters" , qos . Parameters ) ;
279271 eventProperties . Add ( "x-ms-client-request-id" , qos . ClientRequestId ) ;
280272 eventProperties . Add ( "UserAgent" , qos . UserAgent ) ;
281273 eventProperties . Add ( "HashMacAddress" , HashMacAddress ) ;
282- eventProperties . Add ( "PowerShellVersion" , PSVersion ) ;
274+ eventProperties . Add ( "PowerShellVersion" , qos . PSVersion ) ;
283275 eventProperties . Add ( "Version" , qos . AzVersion ) ;
284276 eventProperties . Add ( "CommandParameterSetName" , qos . ParameterSetName ) ;
285277 eventProperties . Add ( "CommandInvocationName" , qos . InvocationName ) ;
@@ -538,7 +530,12 @@ public class AzurePSQoSEvent
538530 public string CommandName { get ; set ; }
539531 public string ModuleName { get ; set ; }
540532 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
541536 public string HostVersion { get ; set ; }
537+ //Host Name of PowerShell
538+ public string PSHostName { get ; set ; }
542539 public string AzVersion { get ; set ; }
543540 public string UserAgent { get ; set ; }
544541 public string Parameters { get ; set ; }
@@ -583,11 +580,12 @@ public void FinishQosEvent()
583580
584581 public override string ToString ( )
585582 {
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+
588586 if ( Exception != null )
589587 {
590- ret = $ "{ ret } ; Exception - { Exception . Message } ;";
588+ ret + = $ "; Exception: { Exception . Message } ;";
591589 }
592590 return ret ;
593591 }
0 commit comments