Repository navigation
Add end-to-end MSBuild telemetry coverage and fix spans - #55752
Merged
Merged
Conversation
Exercise real OTLP export across server, in-process, fallback, and opt-out hosts. Keep MSBuild activities alive through final telemetry, preserve providers across persistent server builds, and create fallback activities for standalone events. Co-authored-by: Copilot <[email protected]> Copilot-Session: 46416155-3020-40a9-b340-40f426b38bc3
JanProvaznik
requested review from
a team,
lbussell and
mthalman
as code owners
August 12, 2026 17:05
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an end-to-end OTLP (HTTP/protobuf) telemetry test harness and adjusts MSBuild logger / telemetry plumbing so MSBuild-server builds reliably export the final build event. This strengthens telemetry correctness across the SDK’s different MSBuild hosting modes (in-proc, server cold/hot, fallback, opt-out).
Changes:
- Introduces a hermetic OTLP loopback receiver plus a host-matrix test to validate real export for MSBuild build telemetry.
- Keeps the MSBuild build activity open until
MSBuildLogger.Shutdown()and force-flushes providers per logger instance (without shutting down providers in a persistent server). - Ensures
TelemetryClientcan create a fallback activity when tracking events without an ambientActivity.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/TelemetryTests/TelemetryHostMatrixTests.cs | Adds end-to-end matrix coverage for telemetry export across MSBuild host modes (cold/hot server, in-proc, fallback, opt-out). |
| test/dotnet.Tests/TelemetryTests/TelemetryCollector.cs | Implements an in-proc OTLP HTTP/protobuf receiver and minimal OTLP span-event parser for tests. |
| test/dotnet.Tests/TelemetryTests/TelemetryClientTests.cs | Adds unit coverage for “no ambient activity” event tracking behavior. |
| test/dotnet.Tests/CommandTests/MSBuild/GivenMSBuildLogger.cs | Updates logger tests to assert activity lifetime extends through Shutdown(). |
| src/Cli/dotnet/Telemetry/TelemetryClient.cs | Adds provider force-flush + process-exit shutdown registration and creates a fallback activity when needed. |
| src/Cli/dotnet/Commands/MSBuild/MSBuildLogger.cs | Defers activity completion until logger shutdown and switches to force-flush for persistent-server safety. |
| src/Cli/AGENTS.md | Documents the updated MSBuild logger activity lifecycle guidance. |
| documentation/project-docs/telemetry.md | Updates telemetry docs to reflect the new lifecycle and host-matrix E2E tests. |
Remove ambient server overrides for default-host rows and tolerate listener disposal races during collector shutdown. Co-authored-by: Copilot <[email protected]> Copilot-Session: 46416155-3020-40a9-b340-40f426b38bc3
Member
Author
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
JanProvaznik
marked this pull request as draft
August 13, 2026 07:49
Replace the custom OTLP receiver with the pinned Aspire dashboard and query its telemetry API. Keep the host matrix sensitive to the original MSBuild activity regression by leaving standalone fallback behavior out of this PR. Co-authored-by: Copilot <[email protected]> Copilot-Session: 46416155-3020-40a9-b340-40f426b38bc3
Keep the runtime-acquired Aspire CLI dependency visible in test project configuration and pass it to the fixture through assembly metadata. Co-authored-by: Copilot <[email protected]> Copilot-Session: 46416155-3020-40a9-b340-40f426b38bc3
Declare the Aspire CLI pin with the repository's other test dependency versions and keep the test project responsible only for exposing it to the fixture. Co-authored-by: Copilot <[email protected]> Copilot-Session: 46416155-3020-40a9-b340-40f426b38bc3
JanProvaznik
marked this pull request as ready for review
August 13, 2026 11:32
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
JanProvaznik
marked this pull request as draft
August 13, 2026 12:56
baronfel
reviewed
Aug 13, 2026
|
|
||
| namespace Microsoft.DotNet.Tests.TelemetryTests; | ||
|
|
||
| [TestClass] |
Member
There was a problem hiding this comment.
@Evangelink I'd like to come back to these tests after getting guidance/docs from you and see if we can 'manage' an aspire CLI otel instance as a shared resource with nice setup/teardown hooks.
baronfel
approved these changes
Aug 13, 2026
baronfel
marked this pull request as ready for review
August 13, 2026 14:03
|
Azure Pipelines: Successfully started running 2 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds end-to-end telemetry tests that use Aspire Dashboard as the OTLP collector. It also fixes a lifecycle bug that the tests found in the current .NET 11 SDK.
The test installs Aspire CLI 13.4.6 from the feeds in
NuGet.config, starts the dashboard on free loopback ports, runs the SDK under test, and reads the exported events from/api/telemetry/spans.Why the current SDK loses server build telemetry
MSBuildLoggerstarts an activity when a build starts. The current code stops that activity when MSBuild raisesBuildFinished.MSBuild sends the final
msbuild/buildtelemetry event afterBuildFinished. At that point the server process has no current activity.TelemetryClientusesActivity.Current?.AddEvent(...), so it silently drops the event.An in-process build does not show the same failure because stopping the MSBuild activity restores the surrounding CLI activity. The late event can attach to that activity.
Fix
Keep the MSBuild activity open until logger
Shutdown, after MSBuild has sent the final event.For a persistent MSBuild server, force-flush telemetry after each build but keep the process-wide provider alive. Shut the provider down only when the server process exits. This allows later builds in the same server process to export telemetry.
End-to-end validation
I verified the problem independently with the current daily SDK
11.0.100-rc.1.26411.119(7cdb217445) and Aspire Dashboard 13.4.6.dotnet/cli/msbuild/buildMSBUILDUSESERVER=0)All builds succeeded. The CLI control events reached the same dashboard, so the exporter and connection were working. Only the server-hosted MSBuild telemetry was missing.
The new
TelemetryCollectorFixtureperforms the same path in tests:The fixture matrix passes with the fix for:
I also tested the regression directly. I temporarily restored the old behavior that stops the activity at
BuildFinished, rebuilt and deployeddotnet.dll, and reran the fixture matrix. Only the cold and hot server rows failed. Their CLI control events were still present. After restoring this fix, all five rows passed again.Part of #55749. This PR covers items 1 and 2. The item 3 contract snapshot and contributor gate remain a separate follow-up, as allowed by the issue.