addon-observability-python-structlog
SKILL.md
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.
Weekly Installs
1
Repository
ajrlewis/ai-skillsFirst Seen
4 days ago
Security Audits
Installed on
amp1
cline1
opencode1
cursor1
kimi-cli1
codex1