Skip to content

Emit an HTTP request-duration histogram metric from src/middleware/access-log.ts #668

Description

@Jagadeeshftw

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions