fix(middleware): use parametrised route pattern in request completion logger (#668) - #673
Merged
Chucks1093 merged 1 commit intoJul 27, 2026
Conversation
… logger (accesslayerorg#668) Replace req.path with req.baseUrl + req.route.path in the request completion logger so log entries contain the parametrised Express route pattern (e.g. /api/v1/creators/:id) instead of the raw URL path with high-cardinality identifiers. Falls back to req.baseUrl + req.path when no route matches (404s).
|
@khaylebfortune Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Closed
4 tasks
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.
Summary
Closes #668
The request completion logger middleware was emitting the raw
req.path(e.g./creators/GABC123DEF456) in log entries, creating high-cardinality log keys that make it impossible to aggregate by route. This PR changes the route field to use the parametrised Express route pattern (e.g./api/v1/creators/:id) viareq.baseUrl + req.route.path, enabling route-level request rate and p95 latency calculations from logs.Changes
src/middlewares/request-completion-logger.middleware.ts— Replacedreq.pathwith the parametrised route pattern (req.baseUrl + req.route.path). Falls back toreq.baseUrl + req.pathwhen no route matches (e.g. 404s). Renamed the log payload field frompathtoroute.How It Works
Express sets
req.routewhen a route handler is matched. By the time thefinishevent fires,req.routeis available for all matched routes. For unmatched routes (404s), the fallback preserves the raw path so those requests are still logged.Log Output Example
{ "level": "info", "request_id": "abc-123", "method": "GET", "route": "/api/v1/creators/:id", "status_code": 200, "response_time_ms": 42, "msg": "Request completed" }Acceptance Criteria
process.hrtimefrom middleware entry tofinishevent)