feat(web): associate Sentry errors with users#1452
Conversation
|
@brendan-kellam your pull request is missing a changelog! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughAdds Sentry user-context synchronization to client session handling and server authentication, with configurable PII collection. New helper and provider tests cover loading, authenticated, unauthenticated, and PII-enabled behavior. ChangesSentry user context
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SessionProvider
participant SentryUserProvider
participant setSentryUser
participant Sentry
SessionProvider->>SentryUserProvider: provide resolved session state
SentryUserProvider->>setSentryUser: pass user and PII setting
setSentryUser->>Sentry: set or clear user context
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 49d0429. Configure here.
| setSentryUser( | ||
| session?.user ?? null, | ||
| env.SOURCEBOT_TELEMETRY_PII_COLLECTION_ENABLED === 'true', | ||
| ); |
There was a problem hiding this comment.
API auth skips Sentry user
Medium Severity
Server-side setSentryUser runs only inside the NextAuth auth() wrapper. getAuthenticatedUser always calls auth() first, so API key and OAuth Bearer requests clear the Sentry user to null and never re-associate after the real principal is resolved. Server errors on those paths (for example MCP and chat via withOptionalAuth + sew) stay anonymous in Sentry.
Reviewed by Cursor Bugbot for commit 49d0429. Configure here.


Summary
Testing
yarn workspace @sourcebot/web test(1,074 tests passed)yarn workspace @sourcebot/web lint(passes with 4 pre-existing warnings)Note
Medium Risk
Extends the auth session path and sends user identifiers (and optionally PII) to Sentry; behavior is gated by an existing env flag and covered by unit tests.
Overview
Sentry events can now be tied to the signed-in user on both the browser and server.
A shared
setSentryUserhelper callsSentry.setUserwith user id only by default, and adds email/name whenSOURCEBOT_TELEMETRY_PII_COLLECTION_ENABLEDis true; it clears the user when the session is absent.On the client,
SentryUserProvider(mounted in the root layout insideSessionProvider) waits until NextAuth finishes loading, then updates Sentry as login state changes. On the server, the cachedauth()resolver sets the Sentry user after each session lookup so request-scoped errors get the same identity.Reviewed by Cursor Bugbot for commit 49d0429. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Tests