addon-observability-python-structlog
Add-on: Python Observability with structlog
Use this skill when a Python runtime needs package-backed structured logging.
This is the default implementation add-on for Python when addon-observability-telemetry is in scope.
Compatibility
- Best fit for
architect-python-uv-fastapi-sqlalchemy. - Also valid for
architect-python-uv-batchand Python worker-style projects. - Pairs cleanly with
addon-observability-telemetry, which defines the higher-level telemetry contract.
Inputs
Collect:
TELEMETRY_MODE:logs-only|logs+metrics|logs+metrics+traces.LOG_FORMAT:json|logfmt.PII_REDACTION:strict|standard.PYTHON_OBSERVABILITY_PROFILE:api|worker.LOG_BACKEND: defaultstructlog; only useloguruwhen the user explicitly requests it and the tradeoff is documented.
Integration Workflow
- Add package-backed logging dependencies:
uv add structlog
- If
TELEMETRY_MODEincludes metrics or traces, add the relevant OpenTelemetry packages instead of inventing custom counters or span helpers.
- Add Python observability artifacts:
src/{{MODULE_NAME}}/observability/logging.py
src/{{MODULE_NAME}}/observability/context.py
logging.pyshould configurestructlogprocessors, output rendering, and redaction hooks.context.pyshould bind correlation IDs or run IDs using context-local state; do not create a custom logger implementation.
- Bind runtime context:
- For FastAPI, add request middleware that creates or propagates a correlation ID and binds it before request handling.
- For workers, bind a run ID or job ID at the command entrypoint before pipeline execution starts.
- Standardize event shape:
- emit stable event names
- include
correlation_id - include explicit error codes for expected failures
- keep exception details structured and redacted
Guardrails
- Prefer
structlogas the default production path for Python services. - Do not build a custom logger around
print()or bare stdlib logging as the primary implementation. - Do not emit raw secrets, auth headers, or full unredacted payloads.
- Keep the local module limited to
structlogconfiguration, processors, and context binding. - If the user explicitly chooses
loguru, document why it was chosen overstructlogand keep the same redaction and correlation requirements.
Validation Checklist
rg -n "import structlog|from structlog" src
rg -n "correlation_id|run_id" src
rg -n "print\\(" src || true
Manual checks:
- request or run logs include a correlation identifier
- log output is structured and machine-parseable
- the code configures
structloginstead of implementing logging from scratch
Decision Justification Rule
- Every non-trivial decision must include a concrete justification.
- Capture the alternatives considered and why they were rejected.
- State tradeoffs and residual risks for the chosen option.
- If justification is missing, treat the task as incomplete and surface it as a blocker.
More from ajrlewis/ai-skills
architect-python-uv-fastapi-sqlalchemy
Use when scaffolding production-ready FastAPI services with uv, SQLAlchemy, Alembic, Postgres, Docker, and CI gates.
11addon-rag-ingestion-pipeline
Use when adding multi-format RAG ingest, chunk, embed, and retrieval pipelines; pair with architect-python-uv-batch or architect-python-uv-fastapi-sqlalchemy.
11addon-docling-legal-chunk-embed
Use when you need legal PDF to markdown extraction plus clause chunking and embedding prep; pair with addon-rag-ingestion-pipeline and architect-python-uv-batch.
10addon-llm-ancient-greek-translation
Use when adding Koine or Attic Greek translation to Next.js content flows; pair with ui-editorial-writing-surface and addon-nostr-nip23-longform.
10architect-python-uv-batch
Use when scaffolding production-ready Python uv batch or worker projects with Docker required by default.
10addon-human-pr-review-gate
Use when agent-generated code must pass a human PR review gate with trusted checks and merge blocks; pair with addon-decision-justification-ledger and architect-stack-selector.
9