Skip to content

feat: distributed tracing and structured logging (#38) - #141

Open
VECTORG99 wants to merge 1 commit into
mainfrom
feat/38-structured-logging
Open

feat: distributed tracing and structured logging (#38)#141
VECTORG99 wants to merge 1 commit into
mainfrom
feat/38-structured-logging

Conversation

@VECTORG99

Copy link
Copy Markdown
Collaborator

Distributed Tracing & Structured Logging (#38)

All 3 Python services now have structured logging with correlation ID propagation.

Changes

  • api/middleware/correlation_id.py (NEW) — Contextvars-based correlation ID propagation + CorrelationLogFilter
  • api/middleware/request_id.py — Uses set_correlation_id() from correlation_id module
  • api/logging_config.py — Added CorrelationLogFilter to stream and file handlers
  • api/main.py — Wired RequestIdMiddleware as outermost middleware
  • ai-service/logging_config.py (NEW) — Full structured logging (JSON+Dev formatters, correlation IDs, rotating file handler)
  • ai-service/main.py — Added setup_logging() on lifespan, CorrelationMiddleware for X-Request-ID
  • worker/logging_config.py — Added ContextVar CID infrastructure, CorrelationLogFilter, request_id field
  • worker/watchers/vault_watcher.py — Worker-level CID on startup, X-Request-ID on all HTTP calls
  • worker/tasks/joidy_daily_writer.py — Writer-level CID, X-Request-ID on all POST calls
  • api/routers/ai.py — Propagates X-Request-ID to ai-service on /classify and /usage

Tracing flow

Worker (generates worker-xxxx CID)
  → X-Request-ID → API (RequestIdMiddleware reads + sets contextvar)
    → log records include request_id field
    → X-Request-ID → AI-service (CorrelationMiddleware reads + sets contextvar)
      → log records include request_id field

Closes #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

infra: Trazabilidad Distribuida y Logging Estructurado (JSON)

1 participant