@@ -57,11 +57,32 @@ public void Initialize(IConfiguration config, ILoggerFactory loggerFactory)
5757 CurrentSessionId = Guid . NewGuid ( ) . ToString ( ) ;
5858
5959 string productVersion = typeof ( Telemetry ) . Assembly . GetName ( ) . Version . ToString ( ) ;
60- //initialize in task to offload to parallel thread
61- this . _trackEventTask = Task . Factory . StartNew ( ( ) => this . InitializeTelemetry ( productVersion ) ) ;
60+ // initialize in task to offload to parallel thread
61+ this . _trackEventTask = Task . Factory . StartNew ( ( ) => this . InitializeTelemetry ( productVersion , config ) ) ;
6262 this . _initialized = true ;
6363 }
6464
65+ private void InitializeTelemetry ( string productVersion , IConfiguration config )
66+ {
67+ try
68+ {
69+ var telemetryConfig = new TelemetryConfiguration ( InstrumentationKey ) ;
70+ this . _client = new TelemetryClient ( telemetryConfig ) ;
71+ this . _client . Context . Session . Id = CurrentSessionId ;
72+ this . _client . Context . Device . OperatingSystem = RuntimeInformation . OSDescription ;
73+
74+ this . _commonProperties = new TelemetryCommonProperties ( productVersion , this . _client , config ) . GetTelemetryCommonProperties ( ) ;
75+ this . _commonMeasurements = new Dictionary < string , double > ( ) ;
76+ }
77+ catch ( Exception e )
78+ {
79+ this . _client . TrackException ( e ) ;
80+ this . _client = null ;
81+ // we don't want to fail the tool if telemetry fails.
82+ Debug . Fail ( e . ToString ( ) ) ;
83+ }
84+ }
85+
6586 public bool Enabled { get ; private set ; }
6687
6788 public void TrackEvent ( TelemetryEventName eventName , IDictionary < string , string > properties = null ,
@@ -177,27 +198,6 @@ public void TrackError(TelemetryErrorName errorName, Exception ex, IDictionary<s
177198 }
178199 }
179200
180- private void InitializeTelemetry ( string productVersion )
181- {
182- try
183- {
184- var config = new TelemetryConfiguration ( InstrumentationKey ) ;
185- this . _client = new TelemetryClient ( config ) ;
186- this . _client . Context . Session . Id = CurrentSessionId ;
187- this . _client . Context . Device . OperatingSystem = RuntimeInformation . OSDescription ;
188-
189- this . _commonProperties = new TelemetryCommonProperties ( productVersion , this . _client ) . GetTelemetryCommonProperties ( ) ;
190- this . _commonMeasurements = new Dictionary < string , double > ( ) ;
191- }
192- catch ( Exception e )
193- {
194- this . _client . TrackException ( e ) ;
195- this . _client = null ;
196- // we don't want to fail the tool if telemetry fails.
197- Debug . Fail ( e . ToString ( ) ) ;
198- }
199- }
200-
201201 private void TrackEventTask (
202202 string eventName ,
203203 IDictionary < string , string > properties ,
0 commit comments