-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add Meter/Counters to track hits for each route/endpoint #46361
Comments
ObservableCounter puts you in control of all the hot-path code. Whether it winds up being more efficient depends on whether your implementation to track updates can beat the performance of the default implementations provided by other listeners like OpenTelemetry or dotnet-counters. My suggestion is not to bother unless either:
Writing to an instrument nobody is listening to is allocation-free as long as the ASP.NET code isn't doing allocations to prepare the arguments to the call. If you would need to do allocations to prepare arguments you can always check Instrument.Enabled in advance and early-out if nobody is listening.
Is this uniformity like "lets figure out all the ASP.NET metrics we want to add and make a big spec" or "lets make sure we are using uniform naming conventions across all .NET library telemetry", or something else? In terms of feedback and some of the questions above about what data to return, I think that depends a lot on what the customer use-cases are. Right now it sounded like customers said they wanted to see certain data so we have a feature to capture that data. If the customer requests weren't specific about what data to capture either we need to ask for clarification, or, usually more helpful, we need to get a good understanding of what they are trying to accomplish so that we can propose what data is useful for that task. For example if devs want to understand why URLs aren't going to their intended routes then they probably are going to want to see the complete unmatched URL somewhere. If they want to understand which endpoints to spend their development effort improving, then they probably want whatever data makes it easy to identify specific endpoints. |
All of the above. Once the pattern lands in a single component, it'll be copied to other components. Let's make sure we answer all of the hard questions with this first one, so that the next 10 we add are easy 😄. |
If you want hard question, I'm puzzled to define our strategy for metering with respect to third-party efforts like OpenTelemetry that had started subscribing to our diagnostic source events & producing metrics on their own here |
Time machines, priorities and timing:
It's easy to see why we're in the current state we're in if you know the history. |
Granted, and I respect that evolution. So at this moment we have meter support and we could produce such metrics out of the box. And I think we should. I mean it's practical that at the moment OpenTelemetry has our requestIn/requestOut story covered, but that's for largely historical reasons. |
Ok, good. I thought there might not be consensus on this yet. In which case looking at what is being done exactly in OpenTelemetry+Prometheus is a good start. AspNetCore can and should emit more metrics of course but the alfa & omega metric is a metric for incoming requests. |
@davidfowl @reyang I know this request is only for tracking the request hit count, but I am expecting once this is available there will be requests to also capture the latency and success/failure of the request. If that's the case then should we consider having the AspNetCore metering auto instrumentation directly in .NET instead of having 2 solutions (one in .NET and one in OpenTelemetry .NET)? |
An example from OT: It tracks protocol, scheme, method, status code, host&port, and route pattern |
For reference here are couple of AspNetCore metrics from Prometheus. In addition to that one major incoming request duration metric, Prometheus has an inflight metric which is useful to detect problems of hanged requests. |
The end goal is to have AspNetCore well instrumented, so users can turn on certain telemetry if they want to pay the corresponding cost (and those who don't need such telemetry don't have to pay for the cost). OpenTelemetry instrumentation for AspNetCore might still exist in order to support older versions of AspNetCore which does not have the built-in instrumentation + is still under Microsoft's officially support (eventually it'll disappear). This is actually the same across all programming languages and libraries, open-telemetry/opentelemetry-dotnet-contrib#788 is one example. |
Agree, and the final convergence point should be considered when designing the solution in .NET. |
Thanks for contacting us. We're moving this issue to the |
Meter/Counters Not Thread-safe. Don't use this. |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Customers have asked to know how much traffic is going to specific routes/endpoints, especially routes they've added to catch misdirected traffic (e.g. favicon.ico when the site has none). These are used to guide investigations and development efforts.
Describe the solution you'd like
We can use System.Diagnostics.Metrics.Meter to make counters per route or endpoint. and then monitor those using dotnet-counters.
Here's a simple example I tried in the EndpointRoutingMiddleware.
Then
dotnet-counters monitor --name MinimalSample Microsoft.AspNetCore.Routing
Produces:
Which kind of counter?
What kind of data?
405 HTTP Method Not Supported
. Is it granular enough? Probably, people can be more specific with their route definitions if they want more granular counters.Where does the counter go?
Additional context
No response
The text was updated successfully, but these errors were encountered: