Skip to content

feat(browser): Detect redirects when emitting navigation spans #16324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

mydea
Copy link
Member

@mydea mydea commented May 19, 2025

Closes #15286

This PR adds a new option to browserTracingIntegration, detectRedirects, which is enabled by default. If this is enabled, the integration will try to detect if a navigation is actually a redirect based on a simple heuristic, and in this case, will not end the ongoing pageload/navigation, but instead let it run and create a navigation.redirect zero-duration span instead.

An example trace for this would be: https://sentry-sdks.sentry.io/explore/discover/trace/95280de69dc844448d39de7458eab527/?dataset=transactions&eventId=8a1150fd1dc846e4ac8420ccf03ad0ee&field=title&field=project&field=user.display&field=timestamp&name=All%20Errors&project=4504956726345728&query=&queryDataset=transaction-like&sort=-timestamp&source=discover&statsPeriod=5m&timestamp=1747646096&yAxis=count%28%29
image

Where the respective index route that triggered this has this code:

setTimeout(() => {
  window.history.pushState({}, "", "/test-sub-page");
  fetch('https://example.com')
}, 100);

The used heuristic is:

  • If the ongoing pageload/navigation was started less than 300ms ago...
  • ... and no click has happened in this time...
  • ... then we consider the navigation a redirect

this limit was chosen somewhat arbitrarily, open for other suggestions too.

While this logic will not be 100% bullet proof, it should be reliable enough and likely better than what we have today. Users can opt-out of this logic via browserTracingIntegration({ detectRedirects: false }), if needed.

@mydea mydea requested review from bcoe, Lms24 and s1gr1d May 19, 2025 09:21
@mydea mydea self-assigned this May 19, 2025
Copy link
Contributor

github-actions bot commented May 19, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 24.04 kB +0.01% +1 B 🔺
@sentry/browser - with treeshaking flags 23.7 kB +0.01% +1 B 🔺
@sentry/browser (incl. Tracing) 38.66 kB +0.53% +200 B 🔺
@sentry/browser (incl. Tracing, Replay) 76.78 kB +0.25% +191 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 69.78 kB +0.25% +170 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 81.56 kB +0.26% +204 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 93.67 kB +0.22% +204 B 🔺
@sentry/browser (incl. Feedback) 40.83 kB - -
@sentry/browser (incl. sendFeedback) 28.79 kB - -
@sentry/browser (incl. FeedbackAsync) 33.66 kB -0.01% -1 B 🔽
@sentry/react 25.86 kB - -
⛔️ @sentry/react (incl. Tracing) (max: 40.5 kB) 40.69 kB +0.52% +208 B 🔺
@sentry/vue 28.44 kB -0.01% -1 B 🔽
@sentry/vue (incl. Tracing) 40.49 kB +0.51% +202 B 🔺
@sentry/svelte 24.07 kB -0.01% -1 B 🔽
CDN Bundle 25.25 kB -0.01% -1 B 🔽
CDN Bundle (incl. Tracing) 38.72 kB +0.47% +180 B 🔺
CDN Bundle (incl. Tracing, Replay) 74.52 kB +0.27% +200 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 79.97 kB +0.26% +200 B 🔺
CDN Bundle - uncompressed 73.68 kB - -
CDN Bundle (incl. Tracing) - uncompressed 114.5 kB +0.38% +427 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 228.47 kB +0.19% +427 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 241.3 kB +0.18% +427 B 🔺
@sentry/nextjs (client) 42.3 kB +0.51% +213 B 🔺
⛔️ @sentry/sveltekit (client) (max: 39 kB) 39.16 kB +0.54% +210 B 🔺
@sentry/node 158.16 kB +0.01% +1 B 🔺
@sentry/node - without tracing 98.07 kB - -
@sentry/aws-serverless 123.41 kB -0.01% -1 B 🔽

View base workflow run

Copy link

codecov bot commented May 19, 2025

❌ Unsupported file format

Upload processing failed due to unsupported file format. Please review the parser error message:

Error parsing JUnit XML in /home/runner/work/sentry-javascript/sentry-javascript/packages/solidstart/vitest.junit.xml at 18:17

Caused by:
    RuntimeError: Error parsing XML
    
    Caused by:
        0: ill-formed document: expected `</testsuites>`, but `</testsuite>` was found
        1: expected `</testsuites>`, but `</testsuite>` was found

For more help, visit our troubleshooting guide.

@mydea mydea force-pushed the fn/detect-pageload-redirects branch from c78e93b to ccbd697 Compare May 19, 2025 14:33
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.

Distinguish redirects from user-initiated nagivations
1 participant