Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
If a request reaches the end of the pipeline (e.g. isn't handled anywhere else) there is a default middleware that sends an empty 404 response.
aspnetcore/src/Http/Http/src/Builder/ApplicationBuilder.cs
Lines 138 to 141 in 0d52a44
Similarly MapFallback catches any request that didn't map to another route.
aspnetcore/src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs
Lines 388 to 391 in 0d52a44
Problem: There's no visibility in the system for tracking how many requests are missing routes and why. This information would be needed to identify bad links, misconfigured routes, and monitor the customer experience.
Describe the solution you'd like
- Add a meter/counter that tracks how many requests reach the 404 middleware.
- Add a meter/counter that tracks how many requests reach the fallback route. This may already be covered by Add Meter/Counters to track hits for each route/endpoint #46361
- Add an Info or Debug level log in each of these places that includes the following:
- Scheme, host, port, path base, path
- Method
- Protocol
- Use structured logging to allow low level filtering and avoid unnecessary allocations
- These should be under granular log prefixes for targeted enablement.
- Microsoft.AspNetCore.Routing.EndOfPipeline.UnexpectedRequest(scheme...
- Microsoft.AspNetCore.Routing.Fallback.HandledRequest(scheme...
Additional context
The counters would be used to monitor the volume of unexpected requests, and then the logs could be enabled to determine the specific request types.
Having sampling support in the loggers would also help deal with high volume output.