-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/8.0] Fix metrics duration and http.route tag with exception handling #52790
[release/8.0] Fix metrics duration and http.route tag with exception handling #52790
Conversation
Hi @JamesNK. If this is not a tell-mode PR, please make sure to follow the instructions laid out in the servicing process document. |
Hi @JamesNK. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Hi @JamesNK. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
Approved over email. |
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
[release/8.0] Fix metrics duration and http.route tag with exception handling
The
http.server.request.duration
counter records information about every HTTP request. One piece of recorded information is thehttp.route
which is the matched route pattern. The route pattern is taken fromHttpContext
'sEndpoint
. This information is very useful because it allows someone to match requests with pages in their web app.There is an interaction between metrics and exception handling that causes
http.route
to be lost. It happens when:UseExceptionHandler
HttpContext
and re-executes the middleware pipeline <- problemhttp.server.request.duration
withouthttp.route
The exception handler clears the endpoint from the context and re-executes the middleware pipeline. There is no longer an endpoint on the context when
http.server.request.duration
is recorded and thehttp.route
value is lost.The fix is to stash the original endpoint to a known location (a stable key in
HttpContext.Items
) and then fall back to getting the endpoint from that location if the endpoint isn't set.HttpContext.Items
is used becauseIExceptionHandlerPathFeature
(which has anEndpoint
property with the original endpoint) isn't available at the hosting layer.Fixes #52648
Customer Impact
Has been reported by customers in the opentelemetry-dotnet repo and the aspnetcore repo.
Without this fix, customers using metrics would unexpectedly have no
http.route
value when a request throws an exception and exception handling runs. It would be non-obvious why this happens, and create confusion about where errors are occurring in their web app.Regression?
Risk
The change modifies code that runs when request metrics are recorded. It runs often, but the change is very simple (looking up a value in a dictionary, or setting a value in a dictionary when there is an error)
Verification
Manual test with this change correctly includes
http.route
value:Packaging changes reviewed?