-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(browser): Start a navigation span for bfcache restores #23748
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import { | |
| import { _INTERNAL_ensureBrowserSpanStreaming, startIdleSpan, startInactiveSpan } from '@sentry/core/browser'; | ||
| import { | ||
| addHistoryInstrumentationHandler, | ||
| BROWSER_NAVIGATION_TYPE_ATTRIBUTE, | ||
| addPerformanceEntries, | ||
| getLocationHref, | ||
| isBotUserAgent, | ||
|
|
@@ -672,6 +673,41 @@ export const browserTracingIntegration = ((options: Partial<BrowserTracingOption | |
| { url: to, isRedirect: navigationIsRedirect }, | ||
| ); | ||
| }); | ||
|
|
||
| // A bfcache restore resurrects the frozen document, so there is no document load and no | ||
| // usable history event: `popstate` either doesn't fire or is swallowed because the URL is | ||
| // unchanged from when the page was frozen. Without a span of its own, everything after the | ||
| // restore joins the trace the page had before it was frozen, separated by however long it | ||
| // sat in the cache. | ||
| WINDOW.addEventListener?.('pageshow', (event: PageTransitionEvent) => { | ||
| if (!event.persisted) { | ||
| return; | ||
| } | ||
|
|
||
| // A navigation has happened, so the pageload guard in the history handler above must not | ||
| // suppress the next one. | ||
| startingUrl = undefined; | ||
|
|
||
| startBrowserTracingNavigationSpan( | ||
| client, | ||
| { | ||
| // Deliberately no `startTime`: the span starts now, at the restore. The | ||
| // `PerformanceNavigationTiming` entry still describes the original document load and | ||
| // would date the span to before the page was frozen. | ||
| name: hasSpanStreamingEnabled(client) | ||
| ? NAVIGATION_SPAN_NAME_FALLBACK | ||
| : WINDOW.location?.pathname || '/', | ||
| attributes: { | ||
| [SENTRY_SEGMENT_NAME_SOURCE]: 'url', | ||
| [SENTRY_ORIGIN]: 'auto.navigation.browser.bfcache', | ||
| // A bfcache restore is near-instant, so these spans would otherwise drag | ||
| // navigation duration percentiles down with no way to tell them apart. | ||
|
Comment on lines
+694
to
+704
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Multiple Sentry client initializations lead to duplicate Suggested FixTo prevent duplicate listeners, add a guard within the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||
| [BROWSER_NAVIGATION_TYPE_ATTRIBUTE]: 'bfcache', | ||
| }, | ||
| }, | ||
| { url: WINDOW.location?.href }, | ||
| ); | ||
| }); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.