Skip to content

fix(browser): Ensure user id is consistently added to sessions#19341

Open
Lms24 wants to merge 8 commits intodevelopfrom
lms/fix-browser-session-user
Open

fix(browser): Ensure user id is consistently added to sessions#19341
Lms24 wants to merge 8 commits intodevelopfrom
lms/fix-browser-session-user

Conversation

@Lms24
Copy link
Member

@Lms24 Lms24 commented Feb 16, 2026

This PR fixes multiple bugs and problems around browser sessions, mostly related to user id assignment:

  1. When calling Sentry.setUser() on static pages (i.e. no soft navigations), the user id would never be added to sessions. This is because in static pages, we don't send an "exited" session update. The fix: We send a session update whenever the user is set on the isolationScope (see comment about limitations)

  2. When calling Sentry.setUser() in a single page application (i.e. with soft navigations), we would update the initial session with the user data when starting a new session for a new navigation. However, we did not include the user id on the new session, because the getCurrentScope().getUser() || getIsolationScope().getUser() check was flawed. The fix: we use our getCombinedScopeData helper to get the "correct" (read, consistently like in other telemetry items) user.

  3. It seems like we had an incorrect check that would skip creating a new sessions for the first soft navigation after the pageload (in the default 'route') session lifecycle. The fix: We no longer check for from being undefined.

In addition, I also added a new waitForSession helper and refactored most session integration tests to use this helper. This allows us to more granularly listen to multiple session envelopes simultaneously without running into collision risks.

As a result of these fixes, session counts could increase as a whole but also metrics like "crash free users" will likely change. I added a note to the changelog calling this out.

Waiting on https://github.com/getsentry/sentry-docs/pull/16428/changes for final changelog note modification

closes #19317

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

Codecov Results 📊

415 passed | ⏭️ 179 skipped | Total: 594 | Pass Rate: 69.87% | Execution Time: 9m 44s

All tests are passing successfully.


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.61 kB +0.2% +50 B 🔺
@sentry/browser - with treeshaking flags 24.12 kB +0.17% +40 B 🔺
@sentry/browser (incl. Tracing) 42.42 kB +0.14% +57 B 🔺
@sentry/browser (incl. Tracing, Profiling) 47.08 kB +0.11% +50 B 🔺
@sentry/browser (incl. Tracing, Replay) 81.24 kB +0.07% +56 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.86 kB +0.09% +57 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 85.93 kB +0.08% +66 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 98.09 kB +0.07% +60 B 🔺
@sentry/browser (incl. Feedback) 42.33 kB +0.11% +43 B 🔺
@sentry/browser (incl. sendFeedback) 30.28 kB +0.17% +49 B 🔺
@sentry/browser (incl. FeedbackAsync) 35.28 kB +0.16% +56 B 🔺
@sentry/browser (incl. Metrics) 26.78 kB +0.16% +41 B 🔺
@sentry/browser (incl. Logs) 26.92 kB +0.16% +42 B 🔺
@sentry/browser (incl. Metrics & Logs) 27.6 kB +0.16% +42 B 🔺
@sentry/react 27.37 kB +0.14% +37 B 🔺
@sentry/react (incl. Tracing) 44.76 kB +0.09% +38 B 🔺
@sentry/vue 30.06 kB +0.18% +54 B 🔺
@sentry/vue (incl. Tracing) 44.26 kB +0.11% +47 B 🔺
@sentry/svelte 25.64 kB +0.24% +59 B 🔺
CDN Bundle 28.16 kB +0.17% +46 B 🔺
CDN Bundle (incl. Tracing) 43.25 kB +0.11% +47 B 🔺
CDN Bundle (incl. Logs, Metrics) 29 kB +0.16% +45 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 44.09 kB +0.13% +55 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 68.08 kB +0.09% +55 B 🔺
CDN Bundle (incl. Tracing, Replay) 80.12 kB +0.07% +50 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.99 kB +0.06% +47 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 85.56 kB +0.08% +61 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.46 kB +0.07% +60 B 🔺
CDN Bundle - uncompressed 82.33 kB +0.15% +118 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 128.05 kB +0.1% +118 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.17 kB +0.14% +118 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.88 kB +0.1% +118 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.83 kB +0.06% +118 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.93 kB +0.05% +118 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.75 kB +0.05% +118 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.73 kB +0.05% +118 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.54 kB +0.05% +118 B 🔺
@sentry/nextjs (client) 47.12 kB +0.11% +50 B 🔺
@sentry/sveltekit (client) 42.88 kB +0.16% +68 B 🔺
@sentry/node-core 52.16 kB +0.05% +23 B 🔺
@sentry/node 166.53 kB +0.01% +8 B 🔺
@sentry/node - without tracing 93.95 kB +0.02% +11 B 🔺
@sentry/aws-serverless 109.45 kB +0.01% +5 B 🔺

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 9,456 - 9,044 +5%
GET With Sentry 1,659 18% 1,596 +4%
GET With Sentry (error only) 6,107 65% 6,140 -1%
POST Baseline 1,205 - 1,189 +1%
POST With Sentry 593 49% 592 +0%
POST With Sentry (error only) 1,057 88% 1,058 -0%
MYSQL Baseline 3,235 - 3,237 -0%
MYSQL With Sentry 491 15% 416 +18%
MYSQL With Sentry (error only) 2,643 82% 2,643 -

View base workflow run

@Lms24 Lms24 changed the title fix(browser): Update session after Sentry.setUser calls fix(browser): Ensure user id is consistently added to sessions Feb 16, 2026
CHANGELOG.md Outdated

While we're at it, if you're using Sentry in a Single Page App or meta framework, you might want to give the new `'page'` session lifecycle a try!
This new mode no longer creates a session per soft navigation but continues the initial session until the next hard page refresh.
Check out the [docs](TODO LINK) to learn more!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Just a reminder to not forget to set the link in the docs

Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@Lms24 Lms24 force-pushed the lms/fix-browser-session-user branch from eb2a670 to 5a94cad Compare February 18, 2026 09:43
Lms24 added a commit to getsentry/sentry-docs that referenced this pull request Feb 18, 2026
…ntegration` (#16428)

<!-- Use this checklist to make sure your PR is ready for merge. You may
delete any sections you don't need. -->

## DESCRIBE YOUR PR

Adds docs for getsentry/sentry-javascript#18997.
I'd like to merge this before
getsentry/sentry-javascript#19341 since it calls
out this page in the changelog.

## IS YOUR CHANGE URGENT?  

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [ ] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

## LEGAL BOILERPLATE

<!-- Sentry employees and contractors can delete or ignore this section.
-->

Look, I get it. The entity doing business as "Sentry" was incorporated
in the State of Delaware in 2015 as Functional Software, Inc. and is
gonna need some rights from me in order to utilize my contributions in
this here PR. So here's the deal: I retain all rights, title and
interest in and to my contributions, and by keeping this boilerplate
intact I confirm that Sentry can use, modify, copy, and redistribute my
contributions, under Sentry's choice of terms.

## EXTRA RESOURCES

- [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
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.

User information no available in the release session

3 participants