diff --git a/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs
index 5827d90e19b5..df48b61fcab0 100644
--- a/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs
+++ b/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs
@@ -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);
+ }
+
///
/// Test hook returning concatenated and escaped command line arguments that would be passed to MSBuild.
///
@@ -94,6 +99,7 @@ public virtual int Execute()
}
else
{
+ InitializeRequiredEnvironmentVariables();
string[] arguments = _forwardingAppWithoutLogging.GetAllArguments();
if (PerformanceLogEventSource.Log.IsEnabled())
{
diff --git a/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs b/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs
index 96100b024be2..04cf840e7a9d 100644
--- a/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs
+++ b/src/Cli/dotnet/commands/dotnet-msbuild/MSBuildLogger.cs
@@ -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
{
@@ -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";
@@ -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 properties = new Dictionary(args.Properties);
+ Dictionary measurements = new Dictionary();
+
+ 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);
+ }
}
}