Repository navigation
Description
Task
T-004a· Milestone M1 — Foundation · Size S · Priority P1 · Epic #1Implements NFR-OBS-001
Branch
feat/t-004a-structured-logging-structlog-json-console— one task = one branch = one PR (doc 32 §6)
Summary
Configure structlog per doc 34 §6 / doc 21 §5.1: JSON lines to stdout (or console in local dev), mandatory service/version fields, contextvars binding for campaign_id/run_id/worker_id/trace_id, and a redaction processor.
Context / motivation
Observability and debugging of a distributed loop (orchestrator + N workers) depends on consistent, machine-readable logs with ids.
Scope
In scope
backend/src/roboprobe/core/logging.py:configure_logging(settings: LoggingSettings, service: str, version: str) -> None,bind_context(**ids)context manager.- Redaction processor dropping/masking keys matching
token|password|secret|dsn|authorization. EVENTScatalogue constant mirroring doc 34 §6 (names only) + a test that every logged event name insrc/is in the catalogue (AST scan).
Implementation guidance
- Processors:
merge_contextvars,add_log_level,TimeStamper(fmt='iso', utc=True), redaction,JSONRendererorConsoleRendererdepending onlogging.format. Respectlogging.include_caller. No string interpolation in event names. - Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
logging.levellogging.formatlogging.include_caller
Acceptance criteria
- JSON log line contains
ts, level, logger, event, service, versionand bound ids. - Secrets are redacted in output (test with a fake token).
- Log schema test passes; event-catalogue test passes.
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/unit/core/test_logging.pycapturing output withstructlog.testing.capture_logsand stdout capture.
Dependencies
Blocked by: #19 (T-003a)
Blocks: #142 (T-080a)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/core/logging.pybackend/tests/unit/core/test_logging.py
Independent of T-004b.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-004a (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 34 §6 · doc 21 §5.1 · doc 21 §5
Requirements: NFR-OBS-001 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
/meta,/metrics, request logging #142