Include routing information for middleware
See original GitHub issueIs there a way to obtain which route the request is taking in middleware? Right now, the only available thing is request.url.path
, which doesn’t give me a nice name for metrics.
I see in https://github.com/steinnes/timing-asgi/blob/master/timing_asgi/integrations/starlette.py that it basically just loops through all the routes to obtain the matching one. Is there a better way to do it?
Looping in that manner also runs into an issue where if there are multiple matching routes, like
/resource/default/1
/resource/1/1
it can’t find the right one since they both match.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:11
- Comments:22 (6 by maintainers)
Top Results From Across the Web
Using middleware - Express.js
Express is a routing and middleware web framework that has minimal functionality of its own: An Express application is essentially a series of...
Read more >Routing Middleware - Slim Framework
The routing has been implemented as middleware. We are still using FastRoute as the default router but it is not tightly coupled to...
Read more >Accessing route values in endpoint middleware in ASP.NET ...
In this post I describe how you can access the route values from middleware when using endpoint routing in ASP.NET Core 3.0.
Read more >Middleware - Laravel - The PHP Framework For Web Artisans
Sometimes you may want to group several middleware under a single key to make them easier to assign to routes. You may accomplish...
Read more >Getting route data in your ASP.NET Core middleware - RIMdev
UseEndpointRouting () // Registering this prior to your middleware unlocks the ✨. ... Add(nameof(Post), post); } } await next(context); } } ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sure thing
and then I use it like this:
@adriangb It does make sense, but doesn’t really work well for APM agents (Which is the use case for @billcrook and I).
We’re trying to name our APM traces using the route name instead of the URL, since the latter has cardinality problems. (And routes are a better way to group traces than URL anyway)
We want minimal work on the part of the user – add our middleware, and we do all the work for you, creating traces for each transaction that comes through your app.
Currently this require us to iterate over the routes to get the route name, as I mentioned before. It has minor performance implications, besides being a bit hacky.
I’ll understand if this is a situation where our use case isn’t one you want to support, but unfortunately requiring the user to add a middleware to each route is probably a worse solution than the iterating we’re doing.
I can’t speak to whether your solution would work for @cypai.