Skip to content
Merged
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
Comment thread
epananth marked this conversation as resolved.
Outdated
}

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;
}
}
}
}