SIGN IN SIGN UP

feat: include authenticated user-id on every JSON log line (#142)

* feat: include authenticated user-id on every JSON log line

Previously the user id was logged once by the OAuth provider on a
separate line ("User: (uuid) - name") while request_start/request_success
lines from FastMCP's StructuredLoggingMiddleware carried no user info,
making it impossible to correlate a request log with its user.

Add a UserContextFilter on the shared JSON log handlers that pulls the
current access token via FastMCP's get_access_token() and stamps user_id
(claims["sub"]) and display_name onto each record. JSONFormatter emits
these keys only when present, so startup logs and stdio mode stay clean.

Because the filter lives on the shared handler, it enriches all records
— including the framework's middleware lines — without subclassing or
forking FastMCP.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix: surface user-context enrichment failures in logs

The silent `except Exception: pass` in UserContextFilter discarded any
enrichment failure with no trace. Capture the exception type onto the
record (user_context_enrichment_error) and emit it from JSONFormatter
so failures leave a minimal signal in structured logs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
P
pratapalakshmi committed
2b5e9710f7701146c87310b2ad02cad951c04c5d
Parent: 838c572
Committed by GitHub <noreply@github.com> on 6/8/2026, 10:49:43 AM