[ASP.NET] Handle PlatformNotSupportedException when injecting headers into the request#8829
[ASP.NET] Handle PlatformNotSupportedException when injecting headers into the request#8829NachoEchevarria wants to merge 3 commits into
Conversation
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8829) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (73ms) : 68, 77
master - mean (70ms) : 68, 72
section Bailout
This PR (8829) - mean (77ms) : 73, 81
master - mean (74ms) : 72, 76
section CallTarget+Inlining+NGEN
This PR (8829) - mean (1,081ms) : 1034, 1129
master - mean (1,087ms) : 1042, 1132
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (113ms) : 108, 118
master - mean (109ms) : 106, 111
section Bailout
This PR (8829) - mean (111ms) : 107, 115
master - mean (110ms) : 107, 112
section CallTarget+Inlining+NGEN
This PR (8829) - mean (778ms) : 750, 805
master - mean (782ms) : 756, 808
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (96ms) : 94, 99
master - mean (101ms) : 96, 106
section Bailout
This PR (8829) - mean (98ms) : 96, 100
master - mean (99ms) : 94, 103
section CallTarget+Inlining+NGEN
This PR (8829) - mean (937ms) : 894, 980
master - mean (938ms) : 896, 980
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (100ms) : 95, 104
master - mean (95ms) : 92, 97
section Bailout
This PR (8829) - mean (97ms) : 94, 100
master - mean (99ms) : 93, 104
section CallTarget+Inlining+NGEN
This PR (8829) - mean (815ms) : 775, 855
master - mean (815ms) : 776, 854
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (201ms) : 193, 209
master - mean (204ms) : 200, 208
section Bailout
This PR (8829) - mean (206ms) : 199, 212
master - mean (209ms) : 205, 213
section CallTarget+Inlining+NGEN
This PR (8829) - mean (1,217ms) : 1162, 1272
master - mean (1,224ms) : 1178, 1270
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (289ms) : 283, 295
master - mean (295ms) : 289, 302
section Bailout
This PR (8829) - mean (290ms) : 285, 296
master - mean (295ms) : 291, 300
section CallTarget+Inlining+NGEN
This PR (8829) - mean (973ms) : 953, 993
master - mean (984ms) : 954, 1014
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (285ms) : 278, 292
master - mean (286ms) : 280, 293
section Bailout
This PR (8829) - mean (285ms) : 279, 291
master - mean (286ms) : 281, 290
section CallTarget+Inlining+NGEN
This PR (8829) - mean (1,167ms) : 1125, 1209
master - mean (1,175ms) : 1143, 1208
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (8829) - mean (281ms) : 274, 288
master - mean (283ms) : 276, 291
section Bailout
This PR (8829) - mean (280ms) : 274, 285
master - mean (283ms) : 277, 288
section CallTarget+Inlining+NGEN
This PR (8829) - mean (1,046ms) : 999, 1092
master - mean (1,049ms) : 1008, 1089
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BenchmarksBenchmark execution time: 2026-07-02 12:35:28 Comparing candidate commit fca8192 in PR branch Found 2 performance improvements and 0 performance regressions! Performance is the same for 70 metrics, 0 unstable metrics, 65 known flaky benchmarks, 61 flaky benchmarks without significant changes.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d14fb35380
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Despite the HttpRuntime.UsingIntegratedPipeline check, writing to the request headers | ||
| // can still fail in some hosting configurations (e.g. Sitefinity): "This operation requires IIS integrated pipeline mode". | ||
| // This must not abort the rest of the request instrumentation, so swallow it and disable for the rest of the application lifetime. | ||
| Log.Error(ex, "Unable to inject distributed tracing headers into the request. Disabling for the rest of the application lifetime."); |
There was a problem hiding this comment.
Use skip-telemetry logging for host limitations
In the Sitefinity/non-integrated-hosting scenario this catch is explicitly handling, the failure is an expected environmental limitation and the code disables only a best-effort header injection path. AGENTS.md:198-202 says expected environmental errors should use Log.ErrorSkipTelemetry; using Log.Error here still emits tracer telemetry once per process for affected apps, so this change doesn't fully avoid telemetry noise from the known host limitation.
Useful? React with 👍 / 👎.
| // in case the next processor cannot access the stored Scope | ||
| // (e.g. WCF being hosted in IIS) | ||
| if (HttpRuntime.UsingIntegratedPipeline) | ||
| if (HttpRuntime.UsingIntegratedPipeline && _canInjectContextIntoRequestHeaders) |
There was a problem hiding this comment.
If I understand correctly, the _canInjectContextIntoRequestHeaders and _canReadHttpResponseHeaders variables are actually just two halves of the same thing... If one doesn't work, the other won't, because fundamentally the problem is that even when we have an integrated pipeline, what matters is whether the current request is backed by a real IIS7 worker request, IIS7WorkerRequest. That's not the case in Sitefinity’s Project Manager mode. So if one fails, the other will too.
tl;dr; I think you can/should rename _canReadHttpResponseHeaders to _canAccessHttpResponseHeaders, and use that in both places instead of storing the extra _canInjectContextIntoRequestHeaders 🙂
That said, it's a very minor difference, so approving anyway 😃
There was a problem hiding this comment.
You are right, thanks! Done!
Summary of changes
Guard the distributed-tracing header injection into the incoming request in
TracingHttpModule.OnBeginRequestagainstPlatformNotSupportedException.Error tracking.
Reason for change
On .NET Framework ASP.NET, the module writes tracing headers back into the request header collection (so downstream processors like IIS-hosted WCF can read the context). In some hosting configurations (e.g. Sitefinity),
HttpHeaderCollection.SetthrowsPlatformNotSupportedException("This operation requires IIS integrated pipeline mode") even thoughHttpRuntime.UsingIntegratedPipelinereportstrue.Because the injection ran before
shouldDisposeScope = false, the exception bubbled to the outer catch, the scope was disposed, and the entireaspnet.requestspan was lost — and an error was logged/telemetered on every request.Implementation details
Wrap the injection in a targeted
try/catchand add a static_canInjectContextIntoRequestHeadersflag, mirroring the existing_canReadHttpResponseHeaderspattern. OnPlatformNotSupportedException, log once, disable injection for the rest of the application lifetime, and continue the request instrumentation so the span is still created. Other exceptions still propagate as before.Test coverage
Other details