Repository navigation
Add event-level task telemetry (build/tasks/details) #13609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f5853e
Draft of event-level telemetry
jankratochvilcz 81f2a06
Replace custom JSON serializer with JsonSerializer in TasksDetailsTel…
c4998c3
Refactor: split ProducesCorrectProperties into atomic tests, extract …
c60bcbe
Merge branch 'main' into jan/telemetry-sdk
JanProvaznik e52e46f
Merge remote-tracking branch 'origin/pr-13609' into jankratochvilcz-f…
jankratochvilcz 600e19e
Use source-generated JSON for task telemetry
jankratochvilcz 3d0127a
Isolate task telemetry event test from environment
jankratochvilcz e9785ab
Cover task telemetry exclusion behavior
jankratochvilcz c33f1cb
Stabilize task telemetry environment test
jankratochvilcz 9af9e1b
Clear cached task telemetry exclusion in test
jankratochvilcz 7293d6e
Read task telemetry exclusion dynamically
jankratochvilcz 032cb1b
Test task telemetry using process configuration
jankratochvilcz b217254
Remove environment-sensitive telemetry test
jankratochvilcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Build.Framework.Telemetry; | ||
| using static Microsoft.Build.Framework.Telemetry.TelemetryDataUtils; | ||
|
|
||
| namespace Microsoft.Build.TelemetryInfra; | ||
|
|
||
| /// <summary> | ||
| /// Serializes per-task execution details into a TelemetryEventArgs-compatible | ||
| /// (<see cref="System.Collections.Generic.IDictionary{TKey, TValue}"/> of strings) shape for the CLI/SDK telemetry path. | ||
| /// | ||
| /// Equivalent data is published to VS via <see cref="TelemetryDataUtils.AsActivityDataHolder"/>, where the | ||
| /// VS telemetry sink accepts arbitrary objects and serializes them itself. The CLI path requires strings | ||
| /// (see <see cref="Framework.TelemetryEventArgs"/>), so we serialize a JSON array here. | ||
|
baronfel marked this conversation as resolved.
Resolved
|
||
| /// </summary> | ||
| internal static class TasksDetailsTelemetry | ||
| { | ||
| /// <summary> | ||
| /// Event name for per-task execution details emitted via TelemetryEventArgs. | ||
| /// Uses a separate event name so per-task details are distinguishable from | ||
| /// the per-project aggregated "build/tasks" telemetry event. | ||
| /// </summary> | ||
| internal const string TasksDetailsEventName = "build/tasks/details"; | ||
|
|
||
| /// <summary> | ||
| /// Maximum number of individual task details to include in TelemetryEventArgs-based telemetry. | ||
| /// </summary> | ||
| private const int MaxTaskDetailsForTelemetryEvent = 100; | ||
|
|
||
| internal static Dictionary<string, string>? GetTasksDetailsProperties(this IWorkerNodeTelemetryData? telemetryData) | ||
| { | ||
| if (telemetryData is null || telemetryData.TasksExecutionData.Count == 0) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| List<TaskDetailInfo> allTasks = GetTasksDetails(telemetryData.TasksExecutionData); | ||
| List<TaskDetailInfo> topTasks = allTasks | ||
| .OrderByDescending(t => t.ExecutionsCount) | ||
| .Take(MaxTaskDetailsForTelemetryEvent) | ||
| .ToList(); | ||
|
baronfel marked this conversation as resolved.
Resolved
|
||
|
|
||
| return new Dictionary<string, string>(3) | ||
| { | ||
| ["TaskCount"] = topTasks.Count.ToString(CultureInfo.InvariantCulture), | ||
| ["TotalTaskCount"] = allTasks.Count.ToString(CultureInfo.InvariantCulture), | ||
| ["Tasks"] = JsonSerializer.Serialize(topTasks, TasksDetailsJsonContext.Default.ListTaskDetailInfo), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| [JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] | ||
| [JsonSerializable(typeof(List<TaskDetailInfo>))] | ||
| internal partial class TasksDetailsJsonContext : JsonSerializerContext; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.