Add structured logging and error safety to API endpoints #14

Closed
opened 2026-05-01 09:22:01 -07:00 by pyr0ball · 0 comments
Owner

Problem

API errors (e.g. 500 on mark-posted) are swallowed with no log output, making them invisible unless actively debugging with curl. There is no structured logging on any endpoint — failures disappear silently.

What happened

POST /api/v1/opportunities/{id}/mark-posted returned 500 due to NOT NULL constraint failed: posts.campaign_id. No log line was emitted. The only way to find the cause was direct DB inspection.

Desired behaviour

  • All unhandled exceptions logged with traceback via Python logging (not print)
  • FastAPI exception handler logs 4xx/5xx with request path, method, and error detail
  • Log file written to ~/.local/share/magpie/magpie.log (or configurable via env)
  • manage.sh logs tails the log file

Acceptance criteria

  • Structured logging configured at app startup (logging.basicConfig or equivalent)
  • FastAPI @app.exception_handler logs all 500s with traceback
  • manage.sh logs works and tails the right file
  • Existing endpoints emit at least one log line per meaningful operation (create, update, post, mark-posted)
## Problem API errors (e.g. 500 on `mark-posted`) are swallowed with no log output, making them invisible unless actively debugging with curl. There is no structured logging on any endpoint — failures disappear silently. ## What happened `POST /api/v1/opportunities/{id}/mark-posted` returned 500 due to `NOT NULL constraint failed: posts.campaign_id`. No log line was emitted. The only way to find the cause was direct DB inspection. ## Desired behaviour - All unhandled exceptions logged with traceback via Python `logging` (not print) - FastAPI exception handler logs 4xx/5xx with request path, method, and error detail - Log file written to `~/.local/share/magpie/magpie.log` (or configurable via env) - `manage.sh logs` tails the log file ## Acceptance criteria - [ ] Structured logging configured at app startup (`logging.basicConfig` or equivalent) - [ ] FastAPI `@app.exception_handler` logs all 500s with traceback - [ ] `manage.sh logs` works and tails the right file - [ ] Existing endpoints emit at least one log line per meaningful operation (create, update, post, mark-posted)
Sign in to join this conversation.
No labels
bug
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Circuit-Forge/magpie#14
No description provided.