Skip to content

feat(v9/browser): Detect redirects when emitting navigation spans #16875

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

Closed
wants to merge 1 commit into from

Conversation

mydea
Copy link
Member

@mydea mydea commented Jul 10, 2025

Backport of #16324

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](https://github.com/user-attachments/assets/5f30210b-5ad0-44d9-ad49-bb00354b5fe5)

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

```js
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.

---------

Co-authored-by: Sigrid Huemer <[email protected]>
@mydea mydea requested a review from Lms24 July 10, 2025 08:40
@mydea mydea self-assigned this Jul 10, 2025
@mydea mydea changed the base branch from develop to v9 July 10, 2025 08:40
@mydea
Copy link
Member Author

mydea commented Jul 10, 2025

closing as we'll still publish from develop for now, nothing breaking yet!

@mydea mydea closed this Jul 10, 2025
@mydea mydea deleted the fn/backport-redirects branch July 10, 2025 11:05
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.

1 participant