Skip to content

Make OpenTelemetry resource enrichment composable - #11526

Merged
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
dev/amauryleve/split-telemetry-resources
Sep 25, 2026
Merged

Amaury Levé (Evangelink) merged 3 commits into
mainfrom
dev/amauryleve/split-telemetry-resources

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Summary

Applications using Aspire ServiceDefaults or another application-owned OpenTelemetry setup already define their service, host, OS, and process identity. The existing aggregate MTP resource helper also defines those attributes, making it difficult to add only test and CI provenance without relying on resource ordering.

This follow-up to #11521 adds two focused composition paths:

  • AddTestingPlatformTestResource() adds test-specific resource identity, currently test.assembly.name.
  • AddTestingPlatformCiResource() adds the existing cicd.* and vcs.* provider mappings, including repository URL credential stripping.

Neither focused helper changes service.*, host.*, os.*, or process.*. The shipped AddTestingPlatformResource() remains the standalone aggregate convenience path and preserves its existing service identity, generated instance ID, host/OS/process, test assembly, and CI/VCS behavior.

The package documentation now recommends the focused helpers for Aspire ServiceDefaults, HostApplicationBuilder, and other application-owned resource configurations. Public/internal API baselines and direct regression, isolation, mapping, and precedence tests are included.

Related to #11505.

Validation

  • .\build.cmd -bl -projects test\UnitTests\Microsoft.Testing.Extensions.UnitTests\Microsoft.Testing.Extensions.UnitTests.csproj
  • Targeted OpenTelemetryProviderExtensionsTests and TestingPlatformResourceDetectorTests: 50/50 passed on net8.0
  • Targeted OpenTelemetryProviderExtensionsTests and TestingPlatformResourceDetectorTests: 50/50 passed on net9.0
  • .\build.cmd -bl -projects src\Platform\Microsoft.Testing.Extensions.OpenTelemetry\Microsoft.Testing.Extensions.OpenTelemetry.csproj (netstandard2.0, net8.0, net9.0)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 25, 2026 10:39
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 25, 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

🟢 Approval recommended

The focused helpers preserve existing aggregate behavior and are adequately documented, API-tracked, and tested.

Review effort: Balanced
Findings: None

What changed in this PR

Adds composable OpenTelemetry resource enrichment while preserving the aggregate helper’s existing behavior.

Changes:

  • Adds focused test and CI resource helpers.
  • Updates API baselines and package documentation.
  • Adds regression, isolation, provider-mapping, and precedence tests.
Review coverage Reviewed API compatibility, resource behavior, credential stripping, environment isolation, documentation, and test coverage.
File Description
OpenTelemetryProviderExtensions.cs Adds focused resource extension methods.
TestingPlatformResourceDetector.cs Separates test and CI attribute generation.
PublicAPI.Unshipped.txt Tracks new public APIs.
InternalAPI.Unshipped.txt Tracks new internal detector methods.
PACKAGE.md Documents composable usage.
OpenTelemetryProviderExtensionsTests.cs Tests behavior, isolation, mappings, and precedence.

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

@github-actions github-actions Bot 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.

🧵 Parallel-safety audit — PR #11526

Parallelization — one row per test assembly audited:

Test assembly Scope Workers Analyzer coverage
Microsoft.Testing.Extensions.UnitTests MethodLevel ([assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)]) CPU count coverable once the parallel-safety analyzers ship (attribute-based opt-in)

Findings: A (global-state) 0 · B (paths) 0 · C (declaration) 0 · D (over-serialization) 0 — by severity: Critical 0 · High 0 · Warning 0 · Info 0.

The only changed test file is test/UnitTests/Microsoft.Testing.Extensions.UnitTests/OpenTelemetryProviderExtensionsTests.cs, which adds several new [TestMethod]s exercising the new AddTestingPlatformTestResource() / AddTestingPlatformCiResource() composition helpers, plus a new synchronous WithEnvironment(Dictionary<string, string?>, Action) helper mirroring the pre-existing WithEnvironmentAsync.

Reviewed for parallel-safety under MethodLevel:

  • Category A (env var mutation). Every new test that mutates real environment variables (AddTestingPlatformResource_PreservesAggregateResourceBehavior, AddTestingPlatformTestResource_AddsOnlyTestSpecificAttributes, AddTestingPlatformCiResource_EmitsExistingProviderMappingsWithoutApplicationOrTestIdentity, FocusedResourceHelpers_PreserveApplicationOwnedIdentity) carries a method-level [ResourceLock(WellKnownResources.EnvironmentVariables)], consistent with the existing pattern used elsewhere in this class and in AzureFoundryChatClientProviderTests / TestingPlatformResourceDetectorTests.
  • Restoration paired with the lock. The new WithEnvironment helper snapshots every name in ObservedEnvironmentVariables (which the PR correctly extends with the new CI/service env-var names the detector now reads), clears them, runs the body, and restores the snapshot in a finally — matching the async twin. No leaked mutation across serialized tests.
  • Category C (declaration reconciliation). The production code these tests exercise (TestingPlatformResourceDetector.cs, OpenTelemetryProviderExtensions.cs) only reads via Environment.GetEnvironmentVariable/Environment.MachineName/Environment.ProcessId — all covered by the single WellKnownResources.EnvironmentVariables key used consistently across the file and the rest of the assembly. No under-declaration, no key near-miss (no custom string keys were introduced).
  • Category D. No [DoNotParallelize] was added by this PR (the pre-existing one on the end-to-end TracerProvider test is untouched), and no class-level lock over-serializes — everything is method-level and narrowly scoped.

Nothing in this diff introduces a parallel-safety hazard. No findings to report.

Advisory only — heuristic, non-blocking. Re-run with /parallel-audit. This audit answers "is it parallel-safe?"; for testability, smells, or flakiness see the detect-static-dependencies / test-smell-detection / test-anti-patterns analyses.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • github.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "github.com"

See Network Configuration for more information.

🤖 Automated content by GitHub Copilot. Generated by the Parallel-safety audit on PR (on open / sync) workflow. · copilot · auto · 112.1 AIC · ⌖ 8.78 AIC · ⊞ 24.9K · ◷

@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 25, 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 25, 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 25, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Sep 25, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 25, 2026 11:46
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 25, 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 new public API naming is inconsistent and the activity-parenting contract documentation is now inaccurate.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Use CI capitalization in public API name

src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​OpenTelemetryProviderExtensions.cs:161

The repository consistently spells the two-letter CI acronym in identifiers (CIConditionAttribute, CIEnvironmentDetector, TryGetCIConditionMode). Shipping AddTestingPlatformCiResource would permanently add an inconsistent public API name; rename it to AddTestingPlatformCIResource and update its baseline, tests, and documentation before release.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 25, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Sep 25, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 25, 2026 12:02
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Sep 25, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 25, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Sep 25, 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 package readme’s repository-relative sample link will be broken when rendered on nuget.org.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Use an absolute GitHub URL for the NuGet sample link

src/​Platform/​Microsoft.Testing.Extensions.OpenTelemetry/​PACKAGE.md:69

PACKAGE.md is rendered as the NuGet package readme, so this repository-relative target resolves under nuget.org rather than GitHub and the published sample link will be broken. Use an absolute GitHub URL, consistent with the other package readmes.

@Evangelink
Amaury Levé (Evangelink) merged commit cde5f9a into main Sep 25, 2026
41 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/split-telemetry-resources branch September 25, 2026 13:13
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Sep 25, 2026
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