Skip to content
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

fix(tracing-internal): Only collect request/response spans when browser performance timing is available #10207

Merged
merged 3 commits into from Jan 17, 2024

Conversation

lforst
Copy link
Member

@lforst lforst commented Jan 16, 2024

I found that Relay was dropping pageload transactions from my Next.js test app pretty consistently so in my debugging journey I discovered that the reason was that we were sending spans with start timestamps larger than the end timestamps.

Root cause was that we assumed that the responseEnd property on the navigation performance entry is always present. It is, however, when the response hasn't finished yet, it is 0.

As a fallback behaviour, this PR changes the logic so we will only collect these performance entry spans when the responseEnd logic is available.

We should probably delay finishing of the pageload transaction until domContentLoded fired or the timeout is reached...

Copy link
Contributor

github-actions bot commented Jan 16, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.28 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.6 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.24 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.63 KB (+0.03% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.13 KB (0%)
@sentry/browser - Webpack (gzipped) 22.48 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 74.9 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 66.53 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.37 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.13 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 209.58 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 97.63 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 72.23 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35.41 KB (+0.02% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.99 KB (+0.02% 🔺)
@sentry/react - Webpack (gzipped) 22.52 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.61 KB (+0.01% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.74 KB (+0.02% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.11 KB (0%)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

I'm not sure I understand why Relay drops an entire transaction because of a "bad" span but guarding for this makes sense IMO.

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

Can we add a test so we don't regress in the future?

// It is possible that we are collecting these metrics when the page hasn't finished loading yet, for example when the HTML slowly streams in.
// In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
// In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect
// these spans when the responseEnd value is available. Relay would drop the entire transaction if it contained faulty spans.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// these spans when the responseEnd value is available. Relay would drop the entire transaction if it contained faulty spans.
// these spans when the responseEnd value is available. The backend would drop the entire transaction if it contained faulty spans.

Maybe a bit more generic, for outside readers :)

// In this case, ie. when the document request hasn't finished yet, `entry.responseEnd` will be 0.
// In order not to produce faulty spans, where the end timestamp is before the start timestamp, we will only collect
// these spans when the responseEnd value is available. Relay would drop the entire transaction if it contained faulty spans.
if (entry.responseEnd !== 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (entry.responseEnd !== 0) {
if (entry.responseEnd) {

save a few bytes and should be equally correct here?

@lforst lforst merged commit 03a3d93 into develop Jan 17, 2024
96 checks passed
@lforst lforst deleted the lforst-fix-dropped-txns branch January 17, 2024 11:44
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.

None yet

4 participants