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.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
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)