JSON-structured logging patterns with correlation IDs, log levels, and contextual metadata for the FastAPI backend (structlog) and Next.js frontend (Logger class). Enforces consistent observability across the stack.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
JSON-structured logging patterns with correlation IDs, log levels, and contextual metadata for the FastAPI backend (structlog) and Next.js frontend (Logger class). Enforces consistent observability across the stack.
Consistent, machine-readable logging across the full stack. The backend uses structlog with JSON output; the frontend uses a custom Logger class. This skill codifies conventions for both and adds correlation IDs, log context, and level guidelines.
Description
Enforces JSON-structured logging with correlation IDs, consistent log levels, and contextual metadata across the FastAPI backend (structlog) and Next.js frontend (Logger class). Covers sensitive data redaction, request tracing, and observability best practices.
When to Apply
Positive Triggers
Adding logging to new modules or API endpoints
Reviewing existing log statements for consistency
Implementing request tracing or correlation IDs
Debugging production issues via log analysis
Setting up log aggregation or monitoring pipelines
User mentions: "logging", "logs", "observability", "tracing", "monitoring", "debug"
from src.utils import get_logger
logger = get_logger(__name__)
# Logger name becomes the "logger" field in JSON output# e.g., "logger": "src.api.routes.documents"
Correlation IDs
Add a middleware that generates a correlation ID per request and binds it to structlog context:
import uuid
import structlog
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
classCorrelationIdMiddleware(BaseHTTPMiddleware):
"""Attach a correlation ID to every request for log tracing."""asyncdefdispatch(self, request: Request, call_next):
correlation_id = request.headers.get(
"X-Correlation-ID",
str(uuid.uuid4())
)
# Bind to structlog context (available to all loggers in this request)
structlog.contextvars.clear_contextvars()
structlog.contextvars.bind_contextvars(
correlation_id=correlation_id,
)
response = await call_next(request)
response.headers["X-Correlation-ID"] = correlation_id
return response
Register in apps/backend/src/api/main.py:
from .middleware.correlation import CorrelationIdMiddleware
app.add_middleware(CorrelationIdMiddleware)