Skip to content

fix: integrate Uvicorn access logging with structlog and add access.log sink #560

@Aureliolo

Description

@Aureliolo

Summary

Uvicorn's default access logger (uvicorn.access) writes unstructured INFO: 172.18.0.4:35196 - "GET /api/v1/health HTTP/1.1" 200 OK lines to stdout, completely bypassing the structlog pipeline. Meanwhile, RequestLoggingMiddleware already logs the same requests as structured events (api.request.started/api.request.completed with method, path, status_code, duration_ms, request_id). This creates duplicate logging -- every HTTP request appears twice.

Scope

  1. Disable Uvicorn's access log: Pass access_log=False to uvicorn.run() in server.py. The structlog RequestLoggingMiddleware already covers the same data with richer fields.

  2. Route Uvicorn's own messages through structlog: Pass log_config=None to uvicorn.run() to disable Uvicorn's default logging dict config. Then configure uvicorn and uvicorn.error stdlib loggers to propagate through the structlog handler chain (so Uvicorn startup/shutdown messages get structured formatting).

  3. Add access.log sink: New 8th sink in DEFAULT_SINKS -- DEBUG level, JSON format, routes synthorg.api. logger prefix. Provides a dedicated HTTP access log file separate from the catch-all logs.

  4. Update _SINK_ROUTING in sinks.py to include "access.log": ("synthorg.api.",).

Dependencies

  • Depends on bootstrap_logging being wired in (the logging bootstrap issue)

Acceptance Criteria

  • No more duplicate INFO: ... "GET ... HTTP/1.1" 200 OK lines in logs
  • Uvicorn startup/shutdown messages (Started server process, Application startup complete) flow through structlog with structured formatting
  • access.log file receives all synthorg.api.* events
  • RequestLoggingMiddleware remains the single source of truth for HTTP access logging
  • Docker CMD does not need to change (uvicorn args are set in server.py / create_app)

Metadata

Metadata

Assignees

No one assigned

    Labels

    prio:mediumShould do, but not blockingscope:smallLess than 1 day of workspec:architectureDESIGN_SPEC Section 15 - Technical Architecturetype:fixBug fixes and corrections

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions