AZ-004 — Structured diagnostics

Status

Done

Context

Read README. request.log.error is currently ineffective as a logging foundation because buildApp uses Fastify() without logging. AZ-003 supplies optional correlation metadata and a frontend unexpected-error boundary. Configuration is validated in backend config.ts and composed in server.ts; Docker logs are the existing operational destination.

Goal

Make failures traceable using structured request/integration event conventions without leaking credentials, account information or token-bearing URLs.

Requirements

Non-goals

No Prometheus/Grafana/Sentry/OpenTelemetry stack, dashboards, analytics, persisted audit-log system, IP/email security history, new readiness contract, or frontend remote error service.

Implementation guidance

Use Fastify logger configuration and safe serializers, not calls to console.log in services. Test sinks parse actual JSON events and verify presence AND absence of sensitive sentinels across success/error/validation cases. Use deterministic injected clock/IDs only where needed for behavior tests. Docker signal smoke checks are targeted lifecycle tests; no blanket no-cache build. Respect TypeDoc's intentional public entry points when extending BuildAppOptions.

Acceptance criteria

Verification

pnpm quality
pnpm test
pnpm test:coverage
pnpm build
pnpm validate:docker

Add injection/logger-sink and frontend reporting tests. Check Compose backend stdout for JSON, request/status/duration/ID on a safe test request and failure, then perform a targeted container termination/restart check with no business data loss. Validate using an isolated local project; never exercise synthetic failures on hosted staging. No UI layout change is required, but any correlation detail shown by AZ-003 must wrap at 360px.

Documentation

Update development (levels, safe event examples, local log inspection), architecture (context and redaction), Docker (signal lifecycle), testing, OpenAPI (X-Request-ID), current-state/handover.

Dependencies

AZ-003; existing validated backend configuration, Fastify composition, frontend error conventions.