Add a diagnostic source event that fires when a route is matched - #11685
Merged
Merged
Conversation
- Usually more information becomes available about a request once route is matched. This event shoud allow diagnositc systems to enlighten the typical "begin request" metadata to include more information about the matched route and more importantly the selected endpoint and associated metadata.
davidfowl
requested review from
Tratcher,
analogrelay and
jkotalik
as code owners
June 28, 2019 17:34
campersau
reviewed
Jun 28, 2019
Co-Authored-By: campersau <buchholz.bastian@googlemail.com>
Contributor
What's a route |
rynowak
reviewed
Jun 28, 2019
rynowak
reviewed
Jun 28, 2019
rynowak
reviewed
Jun 28, 2019
Member
Author
|
Man this broke a bunch of tests 😂 |
JamesNK
reviewed
Jun 28, 2019
Member
|
@davidfowl Is this PR what you refer to here: grpc/grpc-dotnet#341 (comment) So would the idea be that a diagnostic framework could listen for this event, get the endpoint, then inspect the endpoint metadata to figure out that it is a gRPC/MVC/SignalR request? |
lmolkova
reviewed
Jun 28, 2019
lmolkova
reviewed
Jun 28, 2019
| if (_diagnosticListener.IsEnabled() && _diagnosticListener.IsEnabled(DiagnosticsRouteMatchedKey)) | ||
| { | ||
| // We're just going to send the HttpContext since it has all of the relevant information | ||
| _diagnosticListener.Write(DiagnosticsRouteMatchedKey, httpContext); |
There was a problem hiding this comment.
- Is it correct that this event will fire for both: WebApi and MVC?
- How do we get route from HttpContext?
httpContext.GetEndpoint()? - AppInsights uses https://github.com/aspnet/Mvc/blob/master/src/Microsoft.AspNetCore.Mvc.Core/MvcCoreDiagnosticSourceExtensions.cs events to know about routing today. Should we stop listening to those?
Member
There was a problem hiding this comment.
- It will fire for any framework that matches using endpoint routing. Today that means MVC, razor pages, gRPC, SignalR. Likely community frameworks will use it as well. On the endpoint there will be metadata that will let you figure out what the route is to. MVC for example will put the ActionDescriptor in the endpoint metadata. gRPC adds its own metadata, etc.
- Yes
- It should still be used for legacy apps. You should be able to listen for both side-by-side. I can't imagine why an ASP.NET Core app would use both old and new routing.
lmolkova
approved these changes
Jun 28, 2019
Member
Author
|
This comment was made automatically. If there is a problem contact aspnetcore-build@microsoft.com. I've triaged the above build. I've created/commented on the following issue(s) |
rynowak
approved these changes
Jul 1, 2019
JamesNK
approved these changes
Jul 1, 2019
Member
Author
|
Hmm preview7 or 8... |
Member
Author
|
7 |
ghost
deleted the
davidfowl/diagnostic-events
branch
July 1, 2019 07:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc @lmolkova @SergeyKanzhelev
I'd expect open telemetry to use this to determine what type of request is being routed instead of the specific MVC event:
https://github.com/open-telemetry/opentelemetry-dotnet/blob/3538e05f0eed9df008d30e82a70bef11bd579bb5/src/OpenTelemetry.Collector.AspNetCore/Implementation/HttpInListener.cs#L108-L137
You could also imagine crawling through the endpoint metadata to light up more information about the request (like the gRPC method or controller method that got selected).