Skip to content

[Instrumentation.AspNet] Preserve baggage across request steps - #5948

Open
Kielek wants to merge 3 commits into
open-telemetry:mainfrom
Kielek:codex/aspnet-baggage-context-compatibility
Open

Kielek wants to merge 3 commits into
open-telemetry:mainfrom
Kielek:codex/aspnet-baggage-context-compatibility

Conversation

@Kielek

@Kielek Kielek commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Follow up to open-telemetry/opentelemetry-dotnet#8042

If we have agreement on open-telemetry/opentelemetry-dotnet#8042, this PR can land even now without releases in the upstream.

Changes was tested locally with local build and also with 1.20.1. All works as expected.

Changes

TelemetryHttpModule now saves the current Baggage value after each request
step, including when the step throws, and restores it when ASP.NET loses the
execution context. This preserves additions, updates, and clearing with the
isolated baggage writes proposed in
open-telemetry/opentelemetry-dotnet#8042.
Previously the module retained the request-start holder, which becomes stale
when writes replace that holder.

Restoration detaches any inherited holder before assigning Baggage.Current,
so older API versions also preserve the other execution context's baggage.
Trace-only propagation and completed requests retain their existing behavior.
The change uses existing APIs and works with the published API without a
dependency version bump.

Validation

  • Added ten regressions covering updates, clearing, exceptional and repeated
    steps, other inherited contexts, trace-only propagation, and request completion.
  • Before correction, the module suite with the proposed safe API had eight
    expected failures, including an existing regression.
  • Both affected suites pass against published API 1.20.1 and the local core PR
    build with safe and legacy flow: 132 passed and 2 skipped per configuration.
  • Release ASP.NET component build, formatting, Markdown lint, whitespace and
    source sanity checks pass. Formatting reports workspace-loading warnings.
  • Tests exercise the managed callback with simulated context loss; no
    end-to-end IIS/native-thread-switch run is claimed.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, successful build/tests, etc.)
  • Tests added/updated
  • CHANGELOG.md file(s) updated for non-trivial changes
  • Changes in public API reviewed (if applicable)
  • AI usage disclosure:
    • No AI used
    • AI-assisted
    • Bulk AI-generated
  • I have the experience and knowledge necessary to understand, review, and validate all content in this PR1

Note

This PR description was assisted with OpenAI Codex.

Footnotes

  1. Yes, I can answer maintainer questions about the content of this PR without using AI. ↩

Save the current baggage value after each request step and restore it after
execution context loss. Detach inherited holders before restoring baggage
so older API versions cannot change another operation's baggage.

Compatibility follow-up for open-telemetry/opentelemetry-dotnet#8042.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-YXEDG1G8.
@github-actions github-actions Bot added the comp:instrumentation.aspnet.telemetryhttpmodule Things related to OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule label Nov 10, 2026
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-11-10 08:06 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Replace the temporary changelog reference with contrib PR open-telemetry#5948.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-YXEDG1G8.
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.76%. Comparing base (594d017) to head (e4a47fe).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #5948   +/-   ##
=======================================
  Coverage   79.75%   79.76%           
=======================================
  Files         520      520           
  Lines       22786    22793    +7     
  Branches     3677     3678    +1     
=======================================
+ Hits        18174    18181    +7     
  Misses       3915     3915           
  Partials      697      697           
Flag Coverage Δ
unittests-Instrumentation.AspNet 85.02% <100.00%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ation.AspNet.TelemetryHttpModule/ActivityHelper.cs 91.66% <100.00%> (+0.49%) ⬆️
....AspNet.TelemetryHttpModule/TelemetryHttpModule.cs 60.00% <100.00%> (+2.85%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Kielek Kielek added the keep-open Prevents issues and pull requests being closed as stale label Nov 10, 2026
@Kielek
Kielek marked this pull request as ready for review November 10, 2026 06:34
@Kielek
Kielek requested a review from a team as a code owner November 10, 2026 06:34

This branch has not been deployed

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

Labels

comp:instrumentation.aspnet.telemetryhttpmodule Things related to OpenTelemetry.Instrumentation.AspNet.TelemetryHttpModule keep-open Prevents issues and pull requests being closed as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants