From 38bd5b33fae31029c0d79f70de503e27c723185d Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 19 May 2026 16:45:57 +0000 Subject: [PATCH] Stop shipping the Request object as a log-record attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exception/405/host-validation log calls put the raw `Request` object into `extra`. plain.connect's OTel `LoggingHandler` copies every non-standard LogRecord attribute into OTel log attributes, and a `Request` is not a valid attribute type — so `opentelemetry.attributes` emits an "Invalid type Request for attribute value" warning on every such record. Nothing reads `record.request`; the adjacent `path` key already carries the useful context. https://claude.ai/code/session_014onNMrdDjC8tete8jMbCDA --- plain/plain/internal/middleware/hosts.py | 2 +- plain/plain/logs/exceptions.py | 2 +- plain/plain/views/base.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plain/plain/internal/middleware/hosts.py b/plain/plain/internal/middleware/hosts.py index 8a8cae38ac..f6184fd3ce 100644 --- a/plain/plain/internal/middleware/hosts.py +++ b/plain/plain/internal/middleware/hosts.py @@ -38,7 +38,7 @@ def before_request(self, request: Request) -> Response | None: logger.warning( msg, - extra={"status_code": 400, "request": request}, + extra={"status_code": 400}, ) return Response(status_code=400) diff --git a/plain/plain/logs/exceptions.py b/plain/plain/logs/exceptions.py index 2e434bd69a..651d96084c 100644 --- a/plain/plain/logs/exceptions.py +++ b/plain/plain/logs/exceptions.py @@ -46,7 +46,7 @@ def log_exception(request: Request, exc: Exception) -> None: if isinstance(exc, NotFoundError404): return - base = {"path": request.path, "request": request} + base = {"path": request.path} if isinstance(exc, SuspiciousOperationError400): security_logger = logging.getLogger(f"plain.security.{type(exc).__name__}") diff --git a/plain/plain/views/base.py b/plain/plain/views/base.py index 3e3923196a..c2598d0059 100644 --- a/plain/plain/views/base.py +++ b/plain/plain/views/base.py @@ -123,7 +123,6 @@ def get_response(self) -> Response: "method": self.request.method, "path": self.request.path, "status_code": 405, - "request": self.request, }, ) response: Response = NotAllowedResponse(self._allowed_methods())