Skip to content

Create canonical MSTest execution spans - #11596

Merged
Amaury Levé (Evangelink) merged 9 commits into
mainfrom
dev/amauryleve/canonical-mstest-execution-spans
Sep 29, 2026
Merged

Amaury Levé (Evangelink) merged 9 commits into
mainfrom
dev/amauryleve/canonical-mstest-execution-spans

Conversation

@Evangelink

@Evangelink Amaury Levé (Evangelink) commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

MSTest user code currently runs outside the MTP test-result activity, so automatic HTTP, SQL, EF, WCF, and custom activities cannot naturally become children of the test span. The separate execution and result activities can also represent one logical test twice in the trace.

This change creates one MTP-owned canonical activity per participating native MSTest execution. MSTest publishes the in-progress update before activating the canonical activity, enters it only after restoring its fixture ExecutionContext, and restores the previous ambient activity without stopping it. The MTP result pipeline enriches and stops that same activity exactly once using the producer execution-end timestamp, so message-publication and asynchronous result-queue delays do not inflate test duration.

The package-consuming topology acceptance verifies parallel HTTP and custom activities are naturally parented to the correct canonical test span, parallel tests remain isolated, retries and folded/unfolded data rows retain distinct occurrence identity, skipped results are enriched, and no duplicate MSTest.TestMethod activity is exported. Standard ambient Activity.Current behavior provides the same parentage mechanism for SQL, EF, WCF, and other compliant instrumentation.

Architecture decisions

  • An opaque, process-local occurrence token correlates execution and result processing without depending on asynchronous message-bus Activity.Current state.
  • Activity reservations are published first and activated afterward, so blocking in-progress consumers do not contribute to the test span duration.
  • Optional internal capability interfaces negotiate canonical activity ownership without changing the existing required IPlatformOpenTelemetryService.StartActivity signature or adding OpenTelemetry SDK ownership to the dependency-free platform core.
  • Sampled-out or no-listener reservations retain lifecycle bookkeeping without creating a duplicate fallback span.
  • Old, tokenless, nonparticipating, or .NET Framework AppDomain-isolated executions preserve the existing MTP result span plus optional ActivityLink correlation from Correlate test result spans with execution activities #11529.
  • Result tags, aggregate multi-result status, retries, data rows, skips, parallel execution, cleanup, and producer timestamps are applied to the canonical span before it is stopped exactly once.
  • Result end timestamps captured before activity activation are normalized to the activation start before enrichment and duration calculation.

Validation

  • build.cmd -pack -bl completed successfully and produced shipping packages before publication and after each lifecycle review fix.
  • All-TFM targeted builds completed with binlogs for Microsoft.Testing.Platform, Microsoft.Testing.Extensions.OpenTelemetry, MSTestAdapter.PlatformServices, and MSTest.TestAdapter, including .NET Framework, Windows, and UAP targets where applicable.
  • Initial focused validation passed 5,204/5,204 tests across 17 runs:
    • MTP OpenTelemetry result-handler and execution-broker tests on net8.0, net9.0, and net462.
    • OpenTelemetry extension service tests on net8.0, net9.0, net462, and net472.
    • Complete platform-services unit suites on net8.0, net9.0, net462, and net48.
    • Complete adapter unit suites on net8.0, net9.0, net462, and net48.
    • Real-MSTest package-consuming canonical topology acceptance on net8.0 and net9.0.
    • Existing nonparticipating-framework ActivityLink fallback acceptance.
  • Current-head validation passed 4,945/4,945 rebuilt targeted tests across 13 runs: execution-broker tests on net8.0/net9.0/net462, complete platform-services and adapter matrices on net8.0/net9.0/net462/net48, canonical acceptance on net8.0/net9.0, and fallback acceptance.
  • The packed builds validated public/internal API baselines; git diff --check, changed-C# UTF-8 BOM verification, focused-scope inspection, and TestFx code-review passes were clean.

Bounded limitations

  • Canonical span reuse requires explicit framework participation and an in-process execution path. Default .NET Framework AppDomain isolation cannot carry the process-local lease, so those runs intentionally retain sibling result spans with fallback correlation.
  • The acceptance test directly exercises custom ActivitySource and HttpClient instrumentation. SQL, EF, WCF, and similar integrations rely on the same standard ambient Activity.Current contract but are not each package-integrated in this PR.
  • This does not create or own an application TracerProvider, MeterProvider, exporter, or hosted entrypoint; application/provider ownership remains unchanged.
  • When sampling or listeners suppress activity creation, lifecycle reservations still prevent duplicate fallback activities, but naturally no canonical span is exported.

Related to #11505

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 28, 2026 09:49
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 28, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Canonical spans currently include potentially unbounded message-publication latency before test execution starts.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Introduces canonical MSTest execution spans so user instrumentation is naturally parented and results are correlated across asynchronous processing.

Changes:

  • Adds an execution-activity broker and reservation lifecycle.
  • Makes canonical activities ambient during MSTest execution.
  • Adds telemetry topology, aggregation, concurrency, and integration coverage.

Confidence at a glance

🟡 Execution and telemetry lifecycle

One duration-boundary defect was identified: activity timing currently includes in-progress message publication latency.

File Description
test/​UnitTests/​MSTestAdapter.UnitTests/​MSTestTestNodeConverterTests.cs Tests multi-result reservation propagation.
test/​UnitTests/​MSTestAdapter.PlatformServices.UnitTests/​Execution/​TestMethodRunnerTests.cs Tests lease entry with restored context.
test/​UnitTests/​Microsoft.Testing.Platform.UnitTests/​Telemetry/​TestExecutionActivityBrokerTests.cs Covers broker lifecycle and aggregation.
test/​UnitTests/​Microsoft.Testing.Platform.UnitTests/​Telemetry/​OpenTelemetryResultHandlerTests.cs Covers canonical result enrichment.
test/​UnitTests/​Microsoft.Testing.Extensions.UnitTests/​OpenTelemetryPlatformServiceTests.cs Tests non-ambient activity behavior.
test/​IntegrationTests/​MSTest.Acceptance.IntegrationTests/​OpenTelemetryActivityTopologyTests.cs Validates end-to-end span topology.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​TestExecutionActivityProperty.cs Carries reservations through test updates.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​TestExecutionActivityBroker.cs Manages canonical activity lifecycles.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​OpenTelemetryResultHandler.Tags.cs Shares activity naming and initial tags.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​OpenTelemetryResultHandler.ResultHandling.cs Enriches canonical activities with results.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​OpenTelemetryResultHandler.Notifications.cs Tracks canonical activity notifications.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​OpenTelemetryResultHandler.cs Tracks active canonical reservations.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​IPlatformTestExecutionActivity.cs Defines execution activity operations.
src/​Platform/​Microsoft.Testing.Platform/​Telemetry/​IPlatformOpenTelemetryServiceWithTestExecutionActivities.cs Defines canonical activity creation.
src/​Platform/​Microsoft.Testing.Platform/​Services/​TestApplicationResult.cs Owns and disposes activity brokers.
src/​Platform/​Microsoft.Testing.Platform/​InternalAPI/​InternalAPI.Unshipped.txt Tracks new platform internal APIs.
src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​PACKAGE.md Documents canonical topology behavior.
src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​OpenTelemetryPlatformService.cs Creates non-ambient execution activities.
src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​InternalAPI/​InternalAPI.Unshipped.txt Tracks extension internal APIs.
src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​ActivityWrapper.cs Adds activity scopes and explicit stopping.
src/​Adapter/​MSTestAdapter.PlatformServices/​Telemetry/​MSTestInstrumentation.cs Documents canonical fixture parenting.
src/​Adapter/​MSTestAdapter.PlatformServices/​ObjectModel/​UnitTestElement.cs Stores process-local execution leases.
src/​Adapter/​MSTestAdapter.PlatformServices/​InternalAPI/​InternalAPI.Unshipped.txt Tracks platform-services internal APIs.
src/​Adapter/​MSTestAdapter.PlatformServices/​Interfaces/​ITestExecutionActivityLease.cs Defines MSTest’s lease contract.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​UnitTestRunner.RunSingleTest.cs Passes leases into method execution.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestMethodRunner.Execution.cs Makes activities ambient around user code.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestMethodRunner.cs Suppresses duplicate method spans.
src/​Adapter/​MSTestAdapter.PlatformServices/​Execution/​TestExecutionManager.Runner.cs Records canonical execution completion.
src/​Adapter/​MSTest.TestAdapter/​TestingPlatformAdapter/​MtpTestResultRecorder.cs Reserves and correlates execution activities.
src/​Adapter/​MSTest.TestAdapter/​TestingPlatformAdapter/​MSTestTestFramework.cs Connects the broker to MSTest recording.
src/​Adapter/​MSTest.TestAdapter/​TestingPlatformAdapter/​MSTestPlatformActivity.cs Parents fixture spans to ambient tests.
src/​Adapter/​MSTest.TestAdapter/​InternalAPI/​uwp/​InternalAPI.Unshipped.txt Tracks the UWP internal constructor.
src/​Adapter/​MSTest.TestAdapter/​InternalAPI/​InternalAPI.Unshipped.txt Tracks the adapter internal constructor.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions

This comment has been minimized.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 28, 2026 12:00
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026

Copilot AI commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Build the repository

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Pre-activation end timestamps can produce invalid durations, and canonical activity propagation fails across default .NET Framework AppDomains.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (1)

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 28, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 29, 2026 06:40
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 29, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The UWP API baseline is incomplete, and the duration acceptance assertion does not independently verify queue-delay behavior.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)

Copilot AI review requested due to automatic review settings September 29, 2026 06:50
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 29, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The UWP internal API baseline omits the new seven-parameter recorder constructor, risking an RS0016 build failure.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity

Open (2)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 29, 2026 07:04
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 29, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The cross-assembly activity lifecycle, cancellation, and ExecutionContext interactions warrant final human review despite comprehensive coverage.

Review effort: Balanced
Findings: None

Resolved since last review (2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants