Fix MSBuild telemetry when the server is enabled - #55582
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
|
Azure Pipelines: Successfully started running 1 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR addresses missing msbuild/* telemetry when the MSBuild server is enabled by ensuring the CLI telemetry pipeline is correctly initialized and that MSBuild events run under an internal Activity within the persistent server process.
Changes:
- Initialize/reuse
TelemetryClientfromMSBuildLoggerand create an internal MSBuildActivityspanning each build. - Improve disk-log flushing behavior to avoid duplicating previously-written spans across consecutive server builds.
- Add tests covering MSBuild-server telemetry persistence and per-build activity ownership.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/TelemetryTests/TelemetryClientTests.cs | Adds an integration-style test that runs two consecutive builds with MSBuild server enabled and asserts telemetry is captured. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs | Adds a unit test asserting MSBuildLogger creates an internal activity per build and restores the parent activity afterward. |
| src/Cli/dotnet/Telemetry/TelemetryDiskLogger.cs | Changes WriteLog to return success/failure so callers can conditionally drain in-memory activities after a successful write. |
| src/Cli/dotnet/Telemetry/TelemetryClient.cs | Tracks initialization state and drains written activities from the in-memory exporter after successful disk writes; adds a hook to wait for pending TrackEvent tasks. |
| src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs | Initializes telemetry in the MSBuild server process, creates/stops an internal build activity, and drains pending telemetry + disk-log flushing on shutdown. |
Suppressed comments (1)
src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs:290
- Shutdown stops the current activity before waiting for pending telemetry tasks. If any TrackEvent tasks are still queued, stopping first risks losing events for exporters that snapshot at Activity.Stop(). Waiting before stopping is safer.
public void Shutdown()
{
StopActivity();
if (_telemetry is TelemetryClient telemetryClient)
Forward the current W3C trace context to MSBuild and refresh the parent for each persistent-server build. Extend focused coverage to verify propagated and exported parent relationships. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
|
This PR has been labeled with
|
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
|
This PR restores delivery and correlation for the existing documented |
Use shorter, active sentences and consistent lifecycle terms across contributor guidance and XML documentation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
Force the integration test to invoke the built dotnet CLI so Full Framework test lanes do not bypass the telemetry logger through Visual Studio MSBuild. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: f900a161-9261-47ee-823b-369cb6ee3cb7
Fixes #55578
Summary
MSBuildLoggerruns in the persistent MSBuild serverBuildStarted, set its result atBuildFinished, and drain pending telemetry during logger shutdownTesting
TelemetryClientTests,GivenMSBuildLogger, and propagation suite (24 tests)11.0.100-devredist SDK and Aspire Dashboard; each trace contained a nested internalmsbuildspan withOkstatus and the expected MSBuild telemetry events