diff --git a/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs b/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs index 531515bce440..d6175487222e 100644 --- a/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs +++ b/src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs @@ -22,6 +22,7 @@ public sealed class MSBuildLogger : INodeLogger // These two events are aggregated and sent at the end of the build. internal const string TaskFactoryTelemetryAggregatedEventName = "build/tasks/taskfactory"; internal const string TasksTelemetryAggregatedEventName = "build/tasks"; + internal const string TasksDetailsTelemetryEventName = "build/tasks/details"; internal const string SdkTaskBaseCatchExceptionTelemetryEventName = "taskBaseCatchException"; internal const string PublishPropertiesTelemetryEventName = "PublishProperties"; @@ -206,6 +207,11 @@ internal static void FormatAndSend(ITelemetryClient? telemetry, TelemetryEventAr toBeHashed: ["RuleId", "CheckFriendlyName"] ); break; + case TasksDetailsTelemetryEventName: + TrackEvent(telemetry, $"msbuild/{TasksDetailsTelemetryEventName}", args.Properties, + toBeHashed: [] + ); + break; // Pass through events that don't need special handling case SdkTaskBaseCatchExceptionTelemetryEventName: case PublishPropertiesTelemetryEventName: diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs index 962ffff87b80..bbd49c1b314f 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs @@ -215,5 +215,30 @@ public void ItIgnoresNonIntegerPropertiesDuringAggregation() fakeTelemetry.LogEntry.Properties.Should().NotContainKey("InvalidProperty"); fakeTelemetry.LogEntry.Properties.Should().NotContainKey("InvalidProperty2"); } + + [TestMethod] + public void ItForwardsTaskDetailsEvent() + { + var fakeTelemetry = new FakeTelemetry(); + var telemetryEventArgs = new TelemetryEventArgs + { + EventName = MSBuildLogger.TasksDetailsTelemetryEventName, + Properties = new Dictionary + { + { "Tasks", "[{\"Name\":\"Copy\",\"ExecutionsCount\":10}]" }, + { "TaskCount", "1" }, + { "TotalTaskCount", "1" } + } + }; + + MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs); + + fakeTelemetry.LogEntry.Should().NotBeNull(); + fakeTelemetry.LogEntry.EventName.Should().Be($"msbuild/{MSBuildLogger.TasksDetailsTelemetryEventName}"); + fakeTelemetry.LogEntry.Properties.Keys.Count.Should().Be(3); + fakeTelemetry.LogEntry.Properties["Tasks"].Should().Be("[{\"Name\":\"Copy\",\"ExecutionsCount\":10}]"); + fakeTelemetry.LogEntry.Properties["TaskCount"].Should().Be("1"); + fakeTelemetry.LogEntry.Properties["TotalTaskCount"].Should().Be("1"); + } } }