Description
src/middleware/access-log.ts records method, path, status, and duration as a structured log line per request (via redactSensitiveParams and res.finish), but that duration is only ever visible by grepping logs — there is no aggregate, queryable latency distribution. Once a metrics registry exists, emit the same per-request duration as a labeled histogram (method, route, status class) so p50/p95/p99 latency can be graphed directly.
Requirements and context
- Add a
http_request_duration_seconds histogram recorded from the existing res.finish handler in src/middleware/access-log.ts, reusing the duration already computed for the log line rather than measuring twice
- Label by normalized route (not raw path, to avoid unbounded cardinality from path params) and status code class (
2xx/4xx/5xx)
- Keep the existing structured log line and PII redaction behavior completely unchanged
- Must be secure, tested, and documented
- Should be efficient and easy to review
Suggested execution
Fork the repo and create a branch
git checkout -b feature/access-log-duration-metric
Implement changes
- Update/Write:
src/middleware/access-log.ts
- Add/Update tests:
src/middleware/access-log.test.ts
- Add documentation:
docs/middleware/access-log.md
- Include clear code comments and TS types
- Validate security assumptions
Test and commit
- Run tests:
pnpm test
- Cover edge cases
- Include test output and security notes
Example commit message
feat: emit request-duration histogram from access log
Guidelines
- Minimum 95 percent test coverage
- Clear documentation
- Timeframe: 96 hours
Description
src/middleware/access-log.tsrecords method, path, status, and duration as a structured log line per request (viaredactSensitiveParamsandres.finish), but that duration is only ever visible by grepping logs — there is no aggregate, queryable latency distribution. Once a metrics registry exists, emit the same per-request duration as a labeled histogram (method, route, status class) so p50/p95/p99 latency can be graphed directly.Requirements and context
http_request_duration_secondshistogram recorded from the existingres.finishhandler insrc/middleware/access-log.ts, reusing the duration already computed for the log line rather than measuring twice2xx/4xx/5xx)Suggested execution
Fork the repo and create a branch
Implement changes
src/middleware/access-log.tssrc/middleware/access-log.test.tsdocs/middleware/access-log.mdTest and commit
pnpm testExample commit message
Guidelines