feat(web): associate Sentry errors with users#1452
Conversation
|
@brendan-kellam your pull request is missing a changelog! |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughAdds Sentry user context tracking across client sessions and server authentication. A helper maps user data with optional PII, while client and server authentication flows synchronize Sentry with authenticated users or ChangesSentry user context
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant SessionProvider
participant SentryUserProvider
participant setSentryUser
participant Sentry
SessionProvider->>SentryUserProvider: provide session status and user
SentryUserProvider->>setSentryUser: update resolved user and PII flag
setSentryUser->>Sentry: set or clear user context
sequenceDiagram
participant Request
participant auth
participant getAuthContext
participant setSentryUser
participant Sentry
Request->>auth: resolve session
auth->>setSentryUser: pass session user or null and PII flag
Request->>getAuthContext: resolve authentication context
getAuthContext->>setSentryUser: pass authenticated user or null and PII flag
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 |
Move setSentryUser out of the memoized auth() resolver and into getAuthContext so it captures the resolved principal for all auth sources (session, OAuth Bearer, API key) rather than clearing the identity on API-key / Bearer requests where auth() returns null. Co-authored-by: Brendan Kellam <10233483+brendan-kellam@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/web/src/middleware/withAuth.ts`:
- Around line 87-94: Move the setSentryUser call in the withAuth middleware to
immediately after authResult resolves the principal and before the organization
lookup, preserving the existing PII flag and unauthenticated null behavior.
Ensure lookup failures are captured with the authenticated user context.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 69b9026b-7932-4238-b19a-aa4b1ec44c1e
📒 Files selected for processing (1)
packages/web/src/middleware/withAuth.ts
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.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b7ad88c. 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
Touches central auth resolution and may send user PII to Sentry when telemetry PII is enabled; behavior is additive and covered by tests.
Overview
Adds
setSentryUserso Sentry events can be tied to the current user: alwaysid, and email/name only whenSOURCEBOT_TELEMETRY_PII_COLLECTION_ENABLEDis on;nullclears context on sign-out.Client: new
SentryUserProviderin the root layout watches NextAuth session (skips while loading) and updates Sentry as auth changes.Server:
auth()sets context from the session user;getAuthContextsets it from the resolved user (session, API key, or OAuth) so server-side errors match the real caller.Unit tests cover PII on/off, clearing, provider loading behavior, and
getAuthContextwiring.Reviewed by Cursor Bugbot for commit 9aac610. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
idis set by default; email/username are included only when telemetry PII collection is enabled.