Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable or disable telemetry #7638

Merged
19 commits merged into from
Jul 20, 2021
25 changes: 17 additions & 8 deletions src/Microsoft.DotNet.SignTool/src/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,35 @@ internal class Telemetry
{ "BUILD_SOURCEVERSION", Environment.GetEnvironmentVariable("BUILD_SOURCEVERSION") }
};

private readonly bool _disableTelemetry ;

public Telemetry()
{
_metrics = new Dictionary<string, double>();
_disableTelemetry = (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SIGNTOOL_DISABLE_TELEMETRY"))
&& string.Equals(Environment.GetEnvironmentVariable("SIGNTOOL_DISABLE_TELEMETRY"),"true"));
epananth marked this conversation as resolved.
Show resolved Hide resolved
}

internal void AddMetric(string name, double value)
{
_metrics.Add(name, value);
if (!_disableTelemetry)
{
_metrics.Add(name, value);
}
}

internal void SendEvents()
{
// set APPINSIGHTS_INSTRUMENTATIONKEY environment variable to begin tracking telemetry
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();

TelemetryClient telemetryClient = new TelemetryClient(configuration);
if (!_disableTelemetry)
{
// set APPINSIGHTS_INSTRUMENTATIONKEY environment variable to begin tracking telemetry
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();
TelemetryClient telemetryClient = new TelemetryClient(configuration);

telemetryClient.TrackEvent(s_sendEventName, properties: s_properties, metrics: _metrics);
telemetryClient.Flush();
_metrics = null;
telemetryClient.TrackEvent(s_sendEventName, properties: s_properties, metrics: _metrics);
telemetryClient.Flush();
_metrics = null;
}
}
}
}