From a210992bfce12ad2987ef9595b673ac004f38a38 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Thu, 17 Sep 2026 01:44:29 +0200 Subject: [PATCH] feat: client log with request ids, joined to the server's The browser now keeps its half of the one event shape logs.py defines: lib/log.ts is a levelled, redacted, bounded (2000 events) in-memory ring with the server's level names and severity numbers. Nothing leaves the browser yet; sending is the consented diagnostics level (S5). - lib/http.ts `send` is the one fetch: every request carries an X-Request-Id and becomes one http.request event. The server echoes the matched route template in X-Route (only for a matched route, so a raw path with a value in it is never sent back); without one the client templates the path itself. req, beacon, the upload XHR, the public watch page and the legal pages all go through it. - Hooks: app start snapshot, uncaught errors and rejections, History push/replace/popstate (a scroll-only replace is not an event; parameter values only at DEBUG, typed search only at TRACE), notifications, the error dialog, the crash boundary, failed queries and mutations (key head only), and the messages socket (lifecycle, frame types at DEBUG). - Redaction is one contract: backend/tests/fixtures/log_redaction_cases.json runs against both redact() implementations. - Lint: fetch, XMLHttpRequest and WebSocket each belong to one logging module, console to none; a contract test proves the rules fire. Fixes a socket takeover: the close of a socket released by the last subscriber cleared the newer socket a quick re-subscribe had opened and scheduled a third, leaving two live sockets that delivered every message twice (measured in Chromium: 3 created / 2 live before, 2 / 1 after). --- CLAUDE.md | 2 + backend/app/logs.py | 21 +- .../tests/fixtures/log_redaction_cases.json | 92 ++++++++ backend/tests/test_logs.py | 21 ++ frontend/eslint.config.js | 47 ++++ frontend/src/components/ErrorBoundary.tsx | 9 +- frontend/src/components/WatchPage.tsx | 5 +- .../components/clientLogWiring.dom.test.tsx | 82 +++++++ frontend/src/components/legal/LegalLayout.tsx | 5 +- frontend/src/lib/api/core.ts | 40 +++- frontend/src/lib/errorDialog.ts | 7 +- frontend/src/lib/http.test.ts | 74 +++++++ frontend/src/lib/http.ts | 99 +++++++++ frontend/src/lib/log.contract.test.ts | 32 +++ frontend/src/lib/log.test.ts | 72 ++++++ frontend/src/lib/log.ts | 206 ++++++++++++++++++ frontend/src/lib/logHooks.dom.test.ts | 109 +++++++++ frontend/src/lib/logHooks.ts | 106 +++++++++ frontend/src/lib/messagesSocket.test.ts | 74 +++++++ frontend/src/lib/messagesSocket.ts | 43 +++- .../src/lib/networkBoundary.contract.test.ts | 47 ++++ frontend/src/lib/notifications.ts | 15 ++ frontend/src/lib/queryClient.ts | 29 ++- frontend/src/main.tsx | 4 + 24 files changed, 1207 insertions(+), 34 deletions(-) create mode 100644 backend/tests/fixtures/log_redaction_cases.json create mode 100644 frontend/src/components/clientLogWiring.dom.test.tsx create mode 100644 frontend/src/lib/http.test.ts create mode 100644 frontend/src/lib/http.ts create mode 100644 frontend/src/lib/log.contract.test.ts create mode 100644 frontend/src/lib/log.test.ts create mode 100644 frontend/src/lib/log.ts create mode 100644 frontend/src/lib/logHooks.dom.test.ts create mode 100644 frontend/src/lib/logHooks.ts create mode 100644 frontend/src/lib/messagesSocket.test.ts create mode 100644 frontend/src/lib/networkBoundary.contract.test.ts diff --git a/CLAUDE.md b/CLAUDE.md index 7a95b229..83604e3a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -95,6 +95,8 @@ CQRS, a repository/DI framework, a router library, a generic CRUD-router factory | FE control | the chip/segmented primitives (`Select` only for >6 options) | a native `