-
Notifications
You must be signed in to change notification settings - Fork 773
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
[ASP.NET Core] Fix missing http.route for requests outside of MVC #4104
[ASP.NET Core] Fix missing http.route for requests outside of MVC #4104
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4104 +/- ##
==========================================
+ Coverage 85.14% 85.24% +0.10%
==========================================
Files 318 315 -3
Lines 12620 12541 -79
==========================================
- Hits 10745 10691 -54
+ Misses 1875 1850 -25
|
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
Show resolved
Hide resolved
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
…ub.com/vishweshbankwar/opentelemetry-dotnet into vibankwa/fix-route-template-aspnetcore
src/OpenTelemetry.Instrumentation.AspNetCore/AspNetCoreInstrumentation.cs
Outdated
Show resolved
Hide resolved
src/OpenTelemetry.Instrumentation.AspNetCore/Implementation/HttpInListener.cs
Outdated
Show resolved
Hide resolved
…ub.com/vishweshbankwar/opentelemetry-dotnet into vibankwa/fix-route-template-aspnetcore
var route = (context.GetEndpoint() as RouteEndpoint)?.RoutePattern.RawText; | ||
if (!string.IsNullOrEmpty(route)) | ||
{ | ||
activity.DisplayName = 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.
I've tried things out on an MVC app before and after this PR. I think we need to consider the test matrix a bit before going forward with this PR.
Below is abbreviated output from the console exporter highlighting the important differences. Three endpoints are exercised:
Two things of note:
- Note that the display name of the Activity is now the same for every endpoint.
- Now that the
http.route
attribute is set, it too is the same for all of the endpoints - I'm not sure if this is a simply a limitation due to the type of routing I'm using, or if there's a way we can get the actual controller/action of the route in thehttp.route
.
Before
Activity.DisplayName: /
Activity.Tags:
http.target: /
http.url: http://localhost:5199/
Activity.DisplayName: /Home/Index
Activity.Tags:
http.target: /Home/Index
http.url: http://localhost:5199/Home/Index
Activity.DisplayName: /Home/Privacy
Activity.Tags:
http.target: /Home/Privacy
http.url: http://localhost:5199/Home/Privacy
After
Activity.DisplayName: {controller=Home}/{action=Index}/{id?}
Activity.Tags:
http.target: /
http.url: http://localhost:5199/
http.route: {controller=Home}/{action=Index}/{id?}
Activity.DisplayName: {controller=Home}/{action=Index}/{id?}
Activity.Tags:
http.target: /Home/Index
http.url: http://localhost:5199/Home/Index
http.route: {controller=Home}/{action=Index}/{id?}
Activity.DisplayName: {controller=Home}/{action=Index}/{id?}
Activity.Tags:
http.target: /Home/Privacy
http.url: http://localhost:5199/Home/Privacy
http.route: {controller=Home}/{action=Index}/{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.
Just a quick brainstorm of the various routing use cases we might need coverage for.
- Conventional routing
- Attribute-based routing
- Minimal API
- Verb templates
- There may be other things that may or may not be relevant to us. Like Areas
I'm not suggesting we need coverage for all these things in this PR, but given that routing is so complex, I think it'd be nice to be able to have a table to be able to point to that makes it clear what to expect when using different styles of routing. Something like:
Activity.DisplayName | Span http.route | Metric http.route | |
---|---|---|---|
Conventional routing | ... | ... | ... |
Attribute-based routing | ... | ... | ... |
... | ... | ... | ... |
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.
@alanwest - Have updated PR description. I think the case you had #4104 (comment) is conventional routing
We could have these added to test
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.
With this PR if /Home/Privacy
maps to {controller=Home}/{action=Index}/{id?}
with conventional routing, then I think we should resolve this before merging.
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.
It looks like you have expected behavior.
I haven't run your tests, but I guess you're getting one route for http://localhost:5199/ and http://localhost:5199/Home/Index and http://localhost:5199/Home/Privacy because they all match to the same conventional route. That's how conventional routing works: an app centrally specifies just a few route patterns, then those patterns match to multiple controllers and actions.
The pattern {controller=Home}/{action=Index}/{id?}
will take any URL with 0-3 segments, e.g. /
, /Home/Index
, /Home/Privacy
, and match the controller/action to controllers and actions in your app.
You could add some customization like replacing controller
, action
and page
parameters with values from RouteData
. That might be more useful, but it wouldn't be the original template anymore.
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 and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Fix #3461 #2986 #3771
Changes
The change updates the logic to get route information for a request using Endpoint details available during OnStopEvent. The current way of getting route information does not work for requests outside of MVC e.g. Minimal APIs where the
Microsoft.AspNetCore.Mvc.BeforeAction
event itself is not triggered. This results in missinghttp.route
tag on exported activities with DisplayName set to request path (high cardinality). This fix is working for both MVC versus Non-MVC for apps targetingnet6.0
andnet7.0
.For applications targeting
netstandard2.0
andnetstandard2.1
applications we would continue to subscribe toMicrosoft.AspNetCore.Mvc.BeforeAction
for route information.Follow up: #4104 (comment)
Before
After
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes