From c86d4725c3aaef8ea115fece51172f820e7a909a Mon Sep 17 00:00:00 2001 From: "Aaron K. Clark" Date: Tue, 19 May 2026 07:07:42 -0500 Subject: [PATCH] chore(metrics): remove dead-code branch from the route-label derivation The Prometheus middleware derived its `route` label like this: ```js const route = (req.route && req.route.path) || (req.baseUrl && req.route && req.baseUrl + req.route.path) || ''; ``` The middle branch is unreachable: - If `req.route` is truthy and `req.route.path` is a non-empty string, the first branch wins. Express always sets `req.route.path` to the matched route pattern string, never an empty string. - If `req.route` is undefined (404 case), both first and second branches short-circuit on `req.route` falsy. So the `req.baseUrl + req.route.path` branch can never fire. Plus every route in this codebase is mounted at the top-level router with its full `/v1/...` path inline, so there is no `req.baseUrl` to prepend in the first place. Drop the dead branch and tighten the comment to match what the code actually does. No behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/middleware/metrics.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/middleware/metrics.js b/app/middleware/metrics.js index cb7d016..11e05d7 100644 --- a/app/middleware/metrics.js +++ b/app/middleware/metrics.js @@ -79,12 +79,13 @@ function metricsMiddleware(req, res, next) { res.on('finish', () => { const elapsedSec = Number(process.hrtime.bigint() - start) / 1e9; // After Express has matched, req.route?.path is the route - // pattern. For 404s req.route is undefined; bucket those - // into a single label so the metric doesn't grow per - // distinct mistyped URL. - const route = (req.route && req.route.path) - || (req.baseUrl && req.route && req.baseUrl + req.route.path) - || ''; + // pattern (e.g. `/v1/customer/:id`). For 404s req.route is + // undefined; bucket those into a single `` label so + // cardinality doesn't grow per distinct mistyped URL. Every + // route in this codebase is mounted at the top-level router + // with its full path, so the pattern already includes the + // /v1 prefix — there is no `req.baseUrl` to prepend. + const route = (req.route && req.route.path) || ''; const labels = { method: req.method, route,