This commit is contained in:
Andras Schmelczer 2026-05-31 09:39:34 +01:00
parent ad7968dadd
commit 5bf8e752e7
22 changed files with 81 additions and 112 deletions

View file

@ -9,6 +9,8 @@ from hashlib import sha256
import structlog
from fastapi import Request, Response
from .auth import extract_bearer_token
def configure_logging() -> None:
"""Configure structlog for JSON output."""
@ -38,12 +40,8 @@ async def request_logging_middleware(request: Request, call_next) -> Response:
structlog.contextvars.bind_contextvars(request_id=request_id)
# Extract user_id from Authorization header for logging (no DB call here)
auth = request.headers.get("Authorization") or request.headers.get("authorization")
user_id: str | None = None
if auth:
parts = auth.split()
if len(parts) == 2 and parts[0].lower() == "bearer":
user_id = token_log_id(parts[1])
token = extract_bearer_token(request)
user_id = token_log_id(token) if token else None
start = time.monotonic()
response = await call_next(request)