-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Ensure pageload & navigation spans have correct data #16279
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 3 commits
8102ffc
5cd662a
694883d
cee11ea
dcd9311
d12215d
6139d08
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 |
---|---|---|
|
@@ -33,7 +33,7 @@ import { | |
startTrackingWebVitals, | ||
} from '@sentry-internal/browser-utils'; | ||
import { DEBUG_BUILD } from '../debug-build'; | ||
import { WINDOW } from '../helpers'; | ||
import { getHttpRequestData, WINDOW } from '../helpers'; | ||
import { registerBackgroundTabDetection } from './backgroundtab'; | ||
import { linkTraces } from './linkedTraces'; | ||
import { defaultRequestInstrumentationOptions, instrumentOutgoingRequests } from './request'; | ||
|
@@ -355,11 +355,21 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio | |
sampled: spanIsSampled(idleSpan), | ||
dsc: getDynamicSamplingContextFromSpan(span), | ||
}); | ||
|
||
scope.setSDKProcessingMetadata({ | ||
normalizedRequest: undefined, | ||
}); | ||
}, | ||
}); | ||
|
||
setActiveIdleSpan(client, idleSpan); | ||
|
||
// We store the normalized request data on the scope, so we get the request data at time of span creation | ||
// otherwise, the URL etc. may already be of the following navigation, and we'd report the wrong URL | ||
getCurrentScope().setSDKProcessingMetadata({ | ||
normalizedRequest: getHttpRequestData(), | ||
}); | ||
|
||
function emitFinish(): void { | ||
if (optionalWindowDocument && ['interactive', 'complete'].includes(optionalWindowDocument.readyState)) { | ||
client.emit('idleSpanEnableAutoFinish', idleSpan); | ||
|
@@ -459,16 +469,18 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio | |
return; | ||
} | ||
|
||
if (from !== to) { | ||
startingUrl = undefined; | ||
startingUrl = undefined; | ||
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. m/q: why did we remove the 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. sorry, forgot to mention this - we actually have the same check in the history handler code, where we do not even trigger the handler in this case! 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. nice, good catch! |
||
|
||
// We wait a tick here to ensure that WINDOW.location.pathname is updated | ||
setTimeout(() => { | ||
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. m: I'm a bit worried about delaying the span start for a tick. I guess this comes down to the router or user implementation but what if users synchronously push a new state and e.g. make a 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. hmm, valid. one thing that would work as expected is if we just would use the |
||
startBrowserTracingNavigationSpan(client, { | ||
name: WINDOW.location.pathname, | ||
attributes: { | ||
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url', | ||
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser', | ||
}, | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m/q: maybe I'm missing some timing information but isn't there a good chance that setting the
normalizedRequest
toundefined
in 360 applies to the same scope where we previously set it (370)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argh, actually that does not work I just noticed, it fixed one test but broke another one - as this resets the request before we even process the transaction 😬 need to do this in a different way... basically the problem was apparent in some e2e tests. I think it becomes problematic in certain cases, e.g. nextjs pages router, where routing instrumentation triggers navigation spans before the url is updated 🤔