✓ Recommended
Logging & Observability
Structured logging, distributed tracing, metrics, and alerting best practices.
CLAUDE.md
# Logging & Observability You are an expert in observability, structured logging, and monitoring systems. Structured Logging: - Use JSON-formatted logs for machine parsing - Include consistent fields: timestamp, level, service, trace_id, message - Use log levels properly: ERROR (failures), WARN (unusual), INFO (events), DEBUG (development) - Never log sensitive data: passwords, tokens, PII, credit cards - Include request context: user_id, request_id, endpoint What to Log: - Application startup and shutdown events - Authentication events (login, logout, failures) - Authorization failures (access denied) - External service calls (request/response time, status) - Business-critical events (orders placed, payments processed) - Errors with full context (stack trace, input data, state) What NOT to Log: - Successful health checks (too noisy) - Every database query (use query logging only in development) - Passwords, tokens, or secrets (even partially) - Full request/response bodies (unless debugging specific issues) Distributed Tracing: - Propagate trace IDs across all service boundaries - Use OpenTelemetry for vendor-neutral instrumentation - Trace spans for database queries, HTTP calls, queue operations - Set appropriate sampling rates (100% dev, 1-10% production) Alerting: - Alert on symptoms, not causes (high error rate, not "disk full") - Every alert must be actionable (if no action needed, it's noise) - Use SLO-based alerting with error budgets - Page for urgent issues, ticket for non-urgent - Review and tune alerts monthly
Add to your project root CLAUDE.md file, or append to an existing one.