Skip to content

Add LoggedRoute to all API routers missing canonical request logging #734

@bencap

Description

@bencap

Summary

Eleven API routers do not set route_class=LoggedRoute on their APIRouter instance. This means requests to those endpoints never emit a canonical api_request log line, creating silent observability gaps that make debugging, alerting, and auditing unreliable.

Problem

LoggedRoute (in src/mavedb/lib/logging/logged_route.py) does two things for every request:

  1. Stamps time_ns into the logging context at the start of the request.
  2. Schedules a BackgroundTask that calls log_request, which emits a structured canonical log line carrying log_type, response_code, duration_ns, X-Correlation-ID, and other context fields.

Routers that omit route_class=LoggedRoute produce no canonical log output. The following routers are currently missing it:

Router file Tag / prefix
routers/api_information.py GET /api/version
routers/controlled_keywords.py /controlled-keywords
routers/doi_identifiers.py /doi-identifiers
routers/hgvs.py /hgvs (transcript fetch, HGVS validation)
routers/licenses.py /licenses
routers/publication_identifiers.py /publication-identifiers
routers/raw_read_identifiers.py /raw-read-identifiers
routers/statistics.py /statistics
routers/target_gene_identifiers.py /target-gene-identifiers
routers/target_genes.py /me/target-genes/search and /target-genes/search
routers/taxonomies.py /taxonomies

Of particular note: target_genes.py contains an authenticated endpoint (/me/target-genes/search) where request logging is especially valuable for audit trails.

Proposed Behavior

Every APIRouter in src/mavedb/routers/ should declare route_class=LoggedRoute, so all endpoints emit consistent canonical log lines with timing, correlation IDs, and response codes.

Acceptance Criteria

  • All APIRouter instances in src/mavedb/routers/ include route_class=LoggedRoute.
  • LoggedRoute is imported from mavedb.lib.logging in each affected file.
  • Requests to every endpoint produce a canonical api_request log line containing at minimum log_type, response_code, duration_ns, and X-Correlation-ID.
  • No existing tests are broken by the change.

Implementation Notes

  • The fix is mechanical: add from mavedb.lib.logging import LoggedRoute and route_class=LoggedRoute to the APIRouter(...) call in each of the eleven files listed above.
  • The pattern used by every other router is consistent; use src/mavedb/routers/experiments.py as the reference implementation.
  • No behavior changes to existing endpoints are expected — LoggedRoute only adds a post-response background task.
  • Consider adding a test or a linting check (e.g., scanning all APIRouter instantiations in src/mavedb/routers/) to prevent the gap from reappearing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    app: backendTask implementation touches the backendtype: maintenanceMaintaining this project

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions