Skip to content

Add username tracking to query events and history#31

Open
martypitt wants to merge 2 commits intodevelopfrom
claude/capture-user-query-summary-aEF4x
Open

Add username tracking to query events and history#31
martypitt wants to merge 2 commits intodevelopfrom
claude/capture-user-query-summary-aEF4x

Conversation

@martypitt
Copy link
Contributor

Summary

This change adds username tracking to query events and persists it throughout the query lifecycle and history records. The username is now captured when a query starts and stored in the query history database.

Key Changes

  • QueryEventConsumer interface: Added optional username parameter to captureQueryStart() method
  • QueryStartEvent data class: Added username field to capture the user who initiated the query
  • QueryLifecycleEventObserver: Now accepts and propagates username through the query lifecycle
  • QueryService: Extracts username from vyneUser and passes it when creating query events and observers
  • PersistingQueryEventConsumer: Updated to accept and forward username to QueryStartEvent
  • QuerySummary entity: Added username column to persist username in query history
  • Database migration: Added V20260224__add_username_to_query_summary.sql to create the username column
  • QueryResultEventMapper: Updated to map username from QueryStartEvent to QuerySummary
  • AnalyticsEventWriterProvider: Updated ShutdownDecorator to forward username parameter

Implementation Details

  • Username is extracted from the vyneUser?.username property in QueryService
  • The username parameter is optional (nullable) to maintain backward compatibility
  • Username flows through the entire query event pipeline: QueryService → QueryLifecycleEventObserver → QueryEventConsumer → QuerySummary persistence
  • Database schema is updated to support storing username for audit and analytics purposes

https://claude.ai/code/session_01K9g4NeErui15PAMCfuzno4

Adds username to the QuerySummary entity so the user who submitted a
query is persisted to the history database. The username is extracted
from the JWT via VyneUser.username, which works for both UI sessions
(logged-in user) and saved endpoint invocations (JWT-identified user).
Unauthenticated mode is handled gracefully by leaving username null.

Changes:
- Add username field to QueryStartEvent and propagate through captureQueryStart
- Add username field to QuerySummary JPA entity (column: username)
- Update QueryLifecycleEventObserver to carry username and pass it to captureQueryStart
- Update QueryService to pass vyneUser?.username at both the normal path
  (via QueryLifecycleEventObserver) and the compilation-exception path
- Update PersistingQueryEventConsumer and ShutdownDecorator captureQueryStart overrides
- Update QueryResultEventMapper to map username from QueryStartEvent to QuerySummary
- Add Flyway migration V20260224 to add nullable username VARCHAR(255) column

https://claude.ai/code/session_01K9g4NeErui15PAMCfuzno4
Unit tests in QueryLifecycleEventObserverTest verify that username is
forwarded to QueryStartEvent (with and without auth). Integration tests
in QuerySummaryOnlyPersistenceTest verify end-to-end that the username
from a JWT preferred_username claim is persisted to the QUERY_SUMMARY
table, and is null when the query is submitted unauthenticated.

Uses the existing JWSBuilder/RsaJwk infrastructure already present in
BaseQueryServiceTest, with a local helper that sets preferred_username
for a predictable assertion target.

https://claude.ai/code/session_01K9g4NeErui15PAMCfuzno4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants