-
Notifications
You must be signed in to change notification settings - Fork 357
[Instrumentation.AspNetCore] Fix http.route for HTTP server spans #3338
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
base: main
Are you sure you want to change the base?
Conversation
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
54c0044 to
d3ab87a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3338 +/- ##
==========================================
+ Coverage 68.61% 68.77% +0.16%
==========================================
Files 431 422 -9
Lines 16429 16410 -19
==========================================
+ Hits 11272 11286 +14
+ Misses 5157 5124 -33
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/RouteAttributeHelper.cs
Outdated
Show resolved
Hide resolved
test/OpenTelemetry.Instrumentation.AspNetCore.Tests/RouteTests/RoutingTestResult.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/RouteAttributeHelper.cs
Outdated
Show resolved
Hide resolved
|
I'll recheck http route tests readme and update the changelog. So after that, this change should be ready to go. |
# Conflicts: # src/OpenTelemetry.Instrumentation.AspNetCore/CHANGELOG.md
| | :broken_heart: | ConventionalRouting | [Non-default action with query string](#metrics__conventionalrouting-non-default-action-with-query-string) | | ||
| | :green_heart: | ConventionalRouting | [Not Found (404)](#metrics__conventionalrouting-not-found-404) | | ||
| | :green_heart: | ConventionalRouting | [Route template with parameter constraint](#metrics__conventionalrouting-route-template-with-parameter-constraint) | | ||
| | :broken_heart: | ConventionalRouting | [Route template with parameter constraint](#metrics__conventionalrouting-route-template-with-parameter-constraint) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some green_heart to broken_heart changes across all net targets. Is it intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you can recheck some ideal route changes. It's caused because of the different ideal route (cleaned constraints, excess symbols like '/', removing optionals if not present, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't introduce more broken_hearts. If you're making a behavior change that you think is correct then the test harness should be adjusted to produce a green_heart. The main thing these markdown files were meant to highlight is remaining gaps we should aim to get fixed.
For code that we do not control, my hope was that we could push on the ASP.NET team to consider making changes.
Also behavior must remain identical (even if the behavior is not ideal) between the attributes added to metrics and those added to spans. Is this still true with this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way that hearts will remain the same, when the expectation was also wrong.
New expectations are in line with AspNet package, spec and consistent output.
There is also no way that spans and metrics can have identical behaviour. Since one part is what we control and another is uncontrollable. I don't know what is more ideal, either ASP.NET Core has to adapt faster or SDK apis are extended for packages around API to be able to override the src behaviour.
| * Add support for .NET 10.0. | ||
| ([#2822](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/2822)) | ||
|
|
||
| * Fixes an issue where `http.route` attribute reported only a plain route |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http.route for spans? I think you are not touching metrics for most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, needs some rewording, so that only spans were affected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
|
I have some conversation with @alanwest last week. Some notes:
|
| } | ||
| } | ||
|
|
||
| private static string GetRoutePattern(RoutePattern routePattern, RouteValueDictionary routeValues) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a very large suite of unit tests to ensure every possible route is correctly converted into a string.
| if (routePattern.RequiredValues.TryGetValue(parameterPart.Name, out var parameterValue) && parameterValue != null) | ||
| { | ||
| sb.Append(parameterValue); | ||
| sb.Append('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not look for separator part for adding separator?
| (parameterPart.IsOptional && routeValues.ContainsKey(parameterPart.Name))) | ||
| { | ||
| sb.Append('{'); | ||
| sb.Append(parameterPart.Name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if there are default values? Or it is catch all? Or has constraints? Or has optional path extension.
There are also complex segments. Are those being handled correctly? See https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-9.0#complex-segments
Maybe these scenarios are already handled correctly, but unit tests to verify are important.
| "expectedHttpRoute": "{area:exists}/ControllerForMyArea/NonDefault/{id?}" | ||
| "currentHttpRoute": null, | ||
| "currentMetricRoute": "{area:exists}/{controller=ControllerForMyArea}/{action=Default}/{id?}", | ||
| "expectedHttpRoute": "MyArea/ControllerForMyArea/NonDefault" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't you just modifying area, controller and page? Isn't the expected route "MyArea/ControllerForMyArea/NonDefault/{id?}". Or is it removed because it's optional?
I don't think removing it has any value. It's still a dynamic placeholder in the route and should be present according to the spec.
| } | ||
| } | ||
|
|
||
| private static string GetRoutePattern(RoutePattern routePattern, RouteValueDictionary routeValues) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated, but I think an empty string route should resolve to /. An empty string by itself is confusing. We're already doing that with http.route tag in metrics based on customer feedback.
|
Metric tags are accessible via https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.features.ihttpmetricstagsfeature?view=aspnetcore-9.0 on HttpContext. You could get and modify We'll do work to HTTP semantic convention activity attributes in .NET 11. If what you're doing here is the correct way to represent |
| "currentHttpRoute": null, | ||
| "expectedHttpRoute": "/MinimalApiUsingMapGroup/" | ||
| "currentMetricRoute": "/MinimalApiUsingMapGroup/", | ||
| "expectedHttpRoute": "MinimalApiUsingMapGroup" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove preceeding /?
| } | ||
| } | ||
|
|
||
| private static string GetRoutePattern(RoutePattern routePattern, RouteValueDictionary routeValues) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always runs, right? Should it only run if the route needs to change? i.e. there are area/controller/action/page attributes and a value is present in the requests route values collection.
| "currentHttpRoute": null, | ||
| "expectedHttpRoute": "SomePath/{id}/{num:int}" | ||
| "currentMetricRoute": "SomePath/{id}/{num:int}", | ||
| "expectedHttpRoute": "SomePath/{id}/{num}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The route constraint is being lost
| "currentHttpRoute": null, | ||
| "expectedHttpRoute": "/MinimalApi/{id}" | ||
| "currentMetricRoute": "/MinimalApi/{id}", | ||
| "expectedHttpRoute": "MinimalApi/{id}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a minimal api route has a parameter called action? Will it be rewritten? There is nothing stopping a minimal API having a parameter with that name and it isn't a static part of the route.
Follow up to #3160
Changes
Normalizes route template according to spec.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes