Skip to content

feat(obs): request correlation IDs across API and workers (E4)#56

Merged
CognitiveCodeAI merged 1 commit into
mainfrom
feat/e4-correlation-ids
Jun 8, 2026
Merged

feat(obs): request correlation IDs across API and workers (E4)#56
CognitiveCodeAI merged 1 commit into
mainfrom
feat/e4-correlation-ids

Conversation

@CognitiveCodeAI

Copy link
Copy Markdown
Owner

E4 — request correlation IDs (audit M-7)

Part of the remediation (#25). Ties a single request's logs together across the API and the Celery work it enqueues.

  • app/observability/request_id.py — request-id contextvar + helpers + a logging filter, and install_request_id_logging() that injects [req:<id>] into existing handlers' formatters (no duplicate handlers).
  • main.py — HTTP middleware binds a request id (from X-Request-Id or a fresh one), echoes it on the response, and installs the log format on startup.
  • app/observability/tasking.pyenqueue(), a drop-in for task.delay() that propagates the id via Celery task headers.
  • app/worker.pytask_prerun re-binds the propagated id (fresh fallback); after_setup_logger formats worker logs identically.
  • All task enqueues now go through enqueue().

Validation

Live: response carries X-Request-Id; a supplied id is echoed back; uvicorn access logs show [req:<id>] with no duplication. tests/test_request_id.py. Full default suite: 304 passed.

Scope decision

The monitor state was not moved to Redis. The monitor is a single daemon process (not per-API-worker), so its atomic file store is correct — a Redis migration would add complexity without benefit. (Documented rather than done; the M-6 "multi-worker" concern doesn't apply to a single-daemon design.)

Closes #23

Audit M-7: no request id tied API logs to the Celery work they enqueue.

- app/observability/request_id.py: a request-id contextvar, helpers, a
  logging filter, and install_request_id_logging() that injects
  [req:<id>] into existing handlers' formatters (no duplicate handlers).
- main.py: HTTP middleware binds a request id (from X-Request-Id or fresh),
  echoes it on the response, and installs the log format on startup.
- app/observability/tasking.py: enqueue() — drop-in for task.delay() that
  propagates the id via Celery task headers.
- app/worker.py: task_prerun re-binds the propagated id (fresh fallback);
  after_setup_logger formats worker logs the same way.
- All task enqueues (ingest x2, embed, index, reconcile) now use enqueue().

Live-validated: response carries X-Request-Id; a supplied id is echoed;
uvicorn access logs show [req:<id>] with no duplication. Tests:
tests/test_request_id.py. Full default suite: 304 passed.

Scope note: monitor state was NOT moved to Redis — the monitor is a single
daemon process (not per-worker), so its atomic file store is correct; a
Redis migration would add complexity without benefit.

Closes #23
@CognitiveCodeAI CognitiveCodeAI added this to the Phase 3 – Modernize milestone Jun 8, 2026
@CognitiveCodeAI CognitiveCodeAI added WS-E Workstream E: Modernize architecture reliability Reliability, resilience, or operational correctness labels Jun 8, 2026
@CognitiveCodeAI CognitiveCodeAI merged commit 86ad5c2 into main Jun 8, 2026
4 checks passed
@CognitiveCodeAI CognitiveCodeAI deleted the feat/e4-correlation-ids branch June 8, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reliability Reliability, resilience, or operational correctness WS-E Workstream E: Modernize architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E4] Move monitor state to Redis and add correlation/request IDs

1 participant