Skip to content

fix(browser): Default pageload span start time to timeOrigin - #23502

Merged
Lms24 merged 2 commits into
developfrom
fix/pageload-span-time-origin
Aug 24, 2026
Merged

fix(browser): Default pageload span start time to timeOrigin#23502
Lms24 merged 2 commits into
developfrom
fix/pageload-span-time-origin

Conversation

@Lms24

@Lms24 Lms24 commented Aug 24, 2026

Copy link
Copy Markdown
Member

This PR makes startBrowserTracingPageLoadSpan default startTime to browserPerformanceTimeOrigin() when the caller doesn't pass one. Only browser, astro and the two Next.js routers passed it, so pageload spans from the react-router, TanStack Router, SvelteKit, Ember and Remix instrumentations started whenever Sentry.initwhich was too late.

Important: Pageload durations for the affected framework integrations will visibly increase after this fix but IMHO this is a correctness fix that leads to more honest pageload times. Furthermore, pageload durations shouldn't be trusted too much anyway given the idle/debouncing time behaviour

Known affected SDKs: react-router, TanStack Router, SvelteKit, Ember, and Remix instrumentations started whenever

Concrete changes:

  • Default startTime to the time origin in startBrowserTracingPageLoadSpan
  • Emit the augmented options on the startPageLoadSpan hook so beforeStartSpan and hook listeners see the real start time
  • Remove the now redundant startTime overrides from browser, astro and both Next.js routing instrumentations

Fixes #23469

@Lms24 Lms24 self-assigned this Aug 24, 2026
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.3 kB - -
@sentry/browser - with treeshaking flags 28.47 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.81 kB - -
@sentry/browser (incl. Tracing) 48.62 kB +0.02% +6 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 48.64 kB +0.02% +5 B 🔺
@sentry/browser (incl. Tracing, Profiling) 51.52 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay) 88.02 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.43 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 92.75 kB +0.01% +3 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 105.45 kB +0.01% +3 B 🔺
@sentry/browser (incl. Feedback) 47.65 kB - -
@sentry/browser (incl. sendFeedback) 35.13 kB - -
@sentry/browser (incl. FeedbackAsync) 40.28 kB - -
@sentry/browser (incl. Metrics) 31.24 kB - -
@sentry/browser (incl. Logs) 31.52 kB - -
@sentry/browser (incl. Metrics & Logs) 32.15 kB - -
@sentry/react 32.09 kB - -
@sentry/react (incl. Tracing) 50.82 kB +0.02% +8 B 🔺
@sentry/vue 35.34 kB - -
@sentry/vue (incl. Tracing) 50.61 kB +0.02% +7 B 🔺
@sentry/svelte 30.33 kB - -
CDN Bundle 31.61 kB - -
CDN Bundle (incl. Tracing) 48.96 kB -0.01% -1 B 🔽
CDN Bundle (incl. Logs, Metrics) 33.8 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.87 kB -0.01% -1 B 🔽
CDN Bundle (incl. Replay, Logs, Metrics) 74.31 kB - -
CDN Bundle (incl. Tracing, Replay) 86.52 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.37 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 92.24 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.18 kB +0.01% +1 B 🔺
CDN Bundle - uncompressed 93.84 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.84 kB +0.02% +20 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 100.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.53 kB +0.02% +20 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.08 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.11 kB +0.01% +20 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.78 kB +0.01% +20 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.8 kB +0.01% +20 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.47 kB +0.01% +20 B 🔺
@sentry/nextjs (client) 53.35 kB -0.02% -10 B 🔽
@sentry/sveltekit (client) 49.04 kB +0.02% +6 B 🔺
@sentry/core/server 65.56 kB - -
@sentry/core/browser 51.78 kB - -
@sentry/node 117.47 kB +0.02% +22 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.18 kB - -
@sentry/node - without tracing 82.02 kB +0.04% +25 B 🔺
@sentry/aws-serverless 91.44 kB +0.03% +20 B 🔺
@sentry/cloudflare (withSentry) - minified 194.61 kB - -
@sentry/cloudflare (withSentry) 481.16 kB - -

View base workflow run

Fixes #23469

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the fix/pageload-span-time-origin branch from d23b79a to cb43562 Compare August 24, 2026 11:51
@Lms24
Lms24 marked this pull request as ready for review August 24, 2026 11:52
@Lms24
Lms24 requested review from a team as code owners August 24, 2026 11:52
@Lms24
Lms24 requested review from chargome, logaretm, msonnb and nicohrubec and removed request for a team August 24, 2026 11:52

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cb43562. Configure here.

Comment thread packages/browser/src/tracing/browserTracingIntegration.ts Outdated

@nicohrubec nicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

const origin = browserPerformanceTimeOrigin();
startBrowserTracingPageLoadSpan(client, {
// With span streaming, span names have to be low cardinality, and there is no route
// information available here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: The isRedirect() check fails because it uses a fixed 1.5s threshold against the page's load time, not accounting for SDK initialization delays, breaking redirect detection.
Severity: HIGH

Suggested Fix

Update the isRedirect() function to account for the change in the pageload span's start_timestamp. The logic should be revised to correctly identify early-lifecycle redirects, potentially by comparing against the SDK initialization time rather than the page's origin time, or by using a different mechanism to track the first navigation event after initialization.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/browser/src/tracing/browserTracingIntegration.ts#L641

Potential issue: The logic for detecting redirects in `isRedirect()` is flawed due to a
timing mismatch introduced in the pull request. The pageload span's `start_timestamp` is
now correctly set to the page's actual load time (`browserPerformanceTimeOrigin()`), but
the redirect check still compares the current time against this timestamp using a fixed
1.5-second threshold. In production, the SDK often initializes more than 1.5 seconds
after the page begins to load. This delay causes the check `now - startTimestamp >
REDIRECT_THRESHOLD` to incorrectly evaluate to true, effectively disabling redirect
detection for any navigation that occurs after this brief window. This results in the
creation of new, separate root transactions instead of correctly grouping redirects as
child spans of the initial pageload.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

given we're fixing a bug here, this is pre-existing behaviour and should already be adjusted to what we expect here. I think 1.5s is okay here but we might wanna increase if this ever becomes an issue

@Lms24
Lms24 merged commit 435c5b3 into develop Aug 24, 2026
200 of 202 checks passed
@Lms24
Lms24 deleted the fix/pageload-span-time-origin branch August 24, 2026 12:31
JPeer264 pushed a commit that referenced this pull request Aug 25, 2026
This PR makes `startBrowserTracingPageLoadSpan` default `startTime` to
`browserPerformanceTimeOrigin()` when the caller doesn't pass one. Only
`browser`, `astro` and the two Next.js routers passed it, so pageload
spans from the react-router, TanStack Router, SvelteKit, Ember and Remix
instrumentations started whenever `Sentry.init`which was too late.

Important: Pageload durations for the affected framework integrations
will visibly increase after this fix but IMHO this is a correctness fix
that leads to more honest pageload times. Furthermore, pageload
durations shouldn't be trusted too much anyway given the idle/debouncing
time behaviour

Known affected SDKs: react-router, TanStack Router, SvelteKit, Ember,
and Remix instrumentations started whenever

Concrete changes:

- Default `startTime` to the time origin in
`startBrowserTracingPageLoadSpan`
- Emit the augmented options on the `startPageLoadSpan` hook so
`beforeStartSpan` and hook listeners see the real start time
- Remove the now redundant `startTime` overrides from `browser`, `astro`
and both Next.js routing instrumentations

Fixes #23469
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.

Framework routing integrations start the pageload span at Sentry.init instead of timeOrigin

2 participants