Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ public void EnvironmentVariable(string name, string value)

public ProcessStartInfo GetProcessStartInfo()
{
EnvironmentVariable(TelemetrySessionIdEnvironmentVariableName, Telemetry.CurrentSessionId);
InitializeRequiredEnvironmentVariables();

return _forwardingAppWithoutLogging.GetProcessStartInfo();
}

private void InitializeRequiredEnvironmentVariables()
{
EnvironmentVariable(TelemetrySessionIdEnvironmentVariableName, Telemetry.CurrentSessionId);
}

/// <summary>
/// Test hook returning concatenated and escaped command line arguments that would be passed to MSBuild.
/// </summary>
Expand All @@ -94,6 +99,7 @@ public virtual int Execute()
}
else
{
InitializeRequiredEnvironmentVariables();
string[] arguments = _forwardingAppWithoutLogging.GetAllArguments();
if (PerformanceLogEventSource.Log.IsEnabled())
{
Expand Down
48 changes: 42 additions & 6 deletions src/Cli/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Microsoft.DotNet.Cli.Telemetry;
using Microsoft.DotNet.Configurer;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Tools.MSBuild
{
Expand All @@ -17,8 +19,10 @@ public sealed class MSBuildLogger : INodeLogger
private readonly IFirstTimeUseNoticeSentinel _sentinel =
new FirstTimeUseNoticeSentinel();
private readonly ITelemetry _telemetry;
private const string NewEventName = "msbuild";

internal const string TargetFrameworkTelemetryEventName = "targetframeworkeval";
internal const string BuildTelemetryEventName = "build";

internal const string SdkTaskBaseCatchExceptionTelemetryEventName = "taskBaseCatchException";
internal const string PublishPropertiesTelemetryEventName = "PublishProperties";
internal const string ReadyToRunTelemetryEventName = "ReadyToRun";
Expand Down Expand Up @@ -107,15 +111,47 @@ internal static void FormatAndSend(ITelemetry telemetry, TelemetryEventArgs args

telemetry.TrackEvent(newEventName, maskedProperties, measurements: null);
}
else if (args.EventName == BuildTelemetryEventName)
{
var newEventName = $"msbuild/{BuildTelemetryEventName}";
Dictionary<string, string> properties = new Dictionary<string, string>(args.Properties);
Dictionary<string, double> measurements = new Dictionary<string, double>();

string[] toBeHashed = new[] { "ProjectPath", "BuildTarget" };
foreach (var propertyToBeHashed in toBeHashed)
{
if (properties.TryGetValue(propertyToBeHashed, out string value))
{
properties[propertyToBeHashed] = Sha256Hasher.HashWithNormalizedCasing(value);
}
}

string[] toBeMeasured = new[] { "BuildDurationInMilliseconds", "InnerBuildDurationInMilliseconds" };
foreach (var propertyToBeMeasured in toBeMeasured)
{
if (properties.TryGetValue(propertyToBeMeasured, out string value))
{
properties.Remove(propertyToBeMeasured);
if (double.TryParse(value, CultureInfo.InvariantCulture, out double realValue))
{
measurements[propertyToBeMeasured] = realValue;
}
}
}

var passthroughEvents = new string[] {
SdkTaskBaseCatchExceptionTelemetryEventName,
telemetry.TrackEvent(newEventName, properties, measurements);
}
else
{
var passthroughEvents = new string[] {
SdkTaskBaseCatchExceptionTelemetryEventName,
PublishPropertiesTelemetryEventName,
ReadyToRunTelemetryEventName };

if (passthroughEvents.Contains(args.EventName))
{
telemetry.TrackEvent(args.EventName, args.Properties, measurements: null);
if (passthroughEvents.Contains(args.EventName))
{
telemetry.TrackEvent(args.EventName, args.Properties, measurements: null);
}
}
}

Expand Down