Dev adds Sentry tracing to Keycloak SPI after silent double JDBC query bug found in code review
A developer working on a custom Keycloak SPI provider discovered that the LegacyUserStorageProvider was making two separate JDBC calls per username-attribute lookup instead of one, doubling database load without raising any errors or returning wrong results. The bug was caught only through manual code review, prompting the developer to add Sentry instrumentation to prevent similar issues from going undetected in the future. Query methods in LegacyUserRepository were updated to open child spans tied to Keycloak's active request tracing, and SQLExceptions are now captured as Sentry events rather than silently disappearing into server logs. The integration is fully opt-in, activating only when a SENTRY_DSN environment variable is set, ensuring the provider does not send data to any external service without explicit user consent. The instrumentation is designed to surface slow or intermittent legacy database issues — such as queries behaving poorly for specific data shapes — before they manifest as user-facing login complaints.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in