Merge pull request #2858 from eerhardt/telemetry-perf-improvements

Address telemetry PR feedback
This commit is contained in:
Eric Erhardt 2016-05-10 22:19:07 -05:00
commit ad3a178849

View file

@ -13,15 +13,12 @@ namespace Microsoft.DotNet.Cli
{ {
public class Telemetry : ITelemetry public class Telemetry : ITelemetry
{ {
private bool _isInitialized = false;
private TelemetryClient _client = null; private TelemetryClient _client = null;
private Dictionary<string, string> _commonProperties = null; private Dictionary<string, string> _commonProperties = null;
private Dictionary<string, double> _commonMeasurements = null; private Dictionary<string, double> _commonMeasurements = null;
private Task _trackEventTask = null; private Task _trackEventTask = null;
private string _telemetryProfile;
private const string InstrumentationKey = "74cc1c9e-3e6e-4d05-b3fc-dde9101d0254"; private const string InstrumentationKey = "74cc1c9e-3e6e-4d05-b3fc-dde9101d0254";
private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT"; private const string TelemetryOptout = "DOTNET_CLI_TELEMETRY_OPTOUT";
private const string TelemetryProfileEnvironmentVariable = "DOTNET_CLI_TELEMETRY_PROFILE"; private const string TelemetryProfileEnvironmentVariable = "DOTNET_CLI_TELEMETRY_PROFILE";
@ -42,8 +39,6 @@ namespace Microsoft.DotNet.Cli
return; return;
} }
_telemetryProfile = Environment.GetEnvironmentVariable(TelemetryProfileEnvironmentVariable);
//initialize in task to offload to parallel thread //initialize in task to offload to parallel thread
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry()); _trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
} }
@ -76,13 +71,12 @@ namespace Microsoft.DotNet.Cli
_commonProperties.Add(OSPlatform, RuntimeEnvironment.OperatingSystemPlatform.ToString()); _commonProperties.Add(OSPlatform, RuntimeEnvironment.OperatingSystemPlatform.ToString());
_commonProperties.Add(RuntimeId, RuntimeEnvironment.GetRuntimeIdentifier()); _commonProperties.Add(RuntimeId, RuntimeEnvironment.GetRuntimeIdentifier());
_commonProperties.Add(ProductVersion, Product.Version); _commonProperties.Add(ProductVersion, Product.Version);
_commonProperties.Add(TelemetryProfile, _telemetryProfile); _commonProperties.Add(TelemetryProfile, Environment.GetEnvironmentVariable(TelemetryProfileEnvironmentVariable));
_commonMeasurements = new Dictionary<string, double>(); _commonMeasurements = new Dictionary<string, double>();
_isInitialized = true;
} }
catch (Exception) catch (Exception)
{ {
_isInitialized = false; _client = null;
// we dont want to fail the tool if telemetry fails. // we dont want to fail the tool if telemetry fails.
Debug.Fail("Exception during telemetry initialization"); Debug.Fail("Exception during telemetry initialization");
} }
@ -90,7 +84,7 @@ namespace Microsoft.DotNet.Cli
private void TrackEventTask(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements) private void TrackEventTask(string eventName, IDictionary<string, string> properties, IDictionary<string, double> measurements)
{ {
if (!_isInitialized) if (_client == null)
{ {
return; return;
} }