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(metrics): use web-vitals ttfb calculation #11185

Merged
merged 9 commits into from
Mar 21, 2024
Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 18, 2024

Kevan first took a stab at this with #10970.

Recommend reading through https://web.dev/articles/ttfb before review.

In https://www.notion.so/sentry/TTFB-vital-is-0-for-navigation-events-2337114dd75542569eb70255a467aba6 we identified that ttfb was being incorrectly calculated in certain scenarios. This was because we were calculating ttfb relative to transaction start time, before it has been adjusted by browser related spans about request/response ( remember browser tracing adjusts the start timestamp of a pageload transaction after adding certain request/response related spans).

This meant that Math.max(responseStartTimestamp - transactionStartTime, 0) would just end up being 0 most of the time because using transactionStartTime was not correct.

To fix this, we avoid trying to rely on our transactionStartTime timestamp at all, but instead using the web vitals version helper for this.

When this gets merged in, I'll backport it to v7. I'm doing this in v8 first because I don't want to deal with the merge conflict that comes when we eventually migrate this code from tracing internal into the browser package.

As a next step, we should seriously think about getting rid of all of our vendored code and just rely on the web vitals library - it's a huge pain to maintain this, and I'm sure there are some insidious bugs sneaking about.

@AbhiPrasad AbhiPrasad requested a review from a team March 18, 2024 21:55
@AbhiPrasad AbhiPrasad self-assigned this Mar 18, 2024
@AbhiPrasad AbhiPrasad requested review from stephanie-anderson and lforst and removed request for a team March 18, 2024 21:55
@AbhiPrasad AbhiPrasad requested review from Lms24 and s1gr1d March 18, 2024 21:58
@AbhiPrasad
Copy link
Member Author

Opened #11186 as a follow up to this

Copy link
Contributor

github-actions bot commented Mar 18, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) 80.9 KB (added)
@sentry/browser (incl. Tracing, Replay) 72.24 KB (added)
@sentry/browser (incl. Tracing, Replay with Canvas) 76.04 KB (added)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 65.81 KB (added)
@sentry/browser (incl. Tracing) 36.83 KB (added)
@sentry/browser (incl. browserTracingIntegration) 36.83 KB (added)
@sentry/browser (incl. feedbackIntegration) 31.35 KB (added)
@sentry/browser (incl. feedbackModalIntegration) 31.47 KB (added)
@sentry/browser (incl. feedbackScreenshotIntegration) 31.48 KB (added)
@sentry/browser (incl. sendFeedback) 27.43 KB (added)
@sentry/browser 22.6 KB (added)
CDN Bundle (incl. Tracing, Replay, Feedback) 75.21 KB (added)
CDN Bundle (incl. Tracing, Replay) 70.05 KB (added)
CDN Bundle (incl. Tracing) 36.41 KB (added)
CDN Bundle 23.97 KB (added)
CDN Bundle (incl. Tracing, Replay) - uncompressed 220.04 KB (added)
CDN Bundle (incl. Tracing) - uncompressed 109.98 KB (added)
CDN Bundle - uncompressed 71 KB (added)
@sentry/react (incl. Tracing, Replay) 72.22 KB (added)
@sentry/react 22.63 KB (added)

@AbhiPrasad AbhiPrasad mentioned this pull request Mar 18, 2024
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.

Thanks for the detailed writeup! The fix makes sense to me and iiuc should even increase accuracy (?).

RE vendoring vs using the library: Given that this library seems to be well maintained I agree, it's probably less overhead to rely on it directly. One thing we should check is if we removed unnecessary code or anything similar to reduce bundle size. In that case, I think, keeping the vendored version would make more sense.

@AbhiPrasad AbhiPrasad merged commit f078a3b into develop Mar 21, 2024
92 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-ttfb-tracing-fix branch March 21, 2024 17:17
AbhiPrasad added a commit that referenced this pull request Mar 21, 2024
c298lee pushed a commit that referenced this pull request Mar 22, 2024
Recommend reading through https://web.dev/articles/ttfb before review.

In
https://www.notion.so/sentry/TTFB-vital-is-0-for-navigation-events-2337114dd75542569eb70255a467aba6
we identified that ttfb was being incorrectly calculated in certain
scenarios. This was because we were calculating `ttfb` relative to
transaction start time, **before** it has been adjusted by `browser`
related spans about request/response ( remember browser tracing adjusts
the start timestamp of a pageload transaction after adding certain
request/response related spans).

This meant that `Math.max(responseStartTimestamp - transactionStartTime,
0)` would just end up being `0` most of the time because using
`transactionStartTime` was not correct.

To fix this, we avoid trying to rely on our `transactionStartTime`
timestamp at all, but instead using the web vitals version helper for
this.

When this gets merged in, I'll backport it to v7. I'm doing this in v8
first because I don't want to deal with the merge conflict that comes
when we eventually migrate this code from tracing internal into the
browser package.

As a next step, we should seriously think about getting rid of all of
our vendored code and just rely on the web vitals library - it's a huge
pain to maintain this, and I'm sure there are some insidious bugs
sneaking about.
cadesalaberry pushed a commit to cadesalaberry/sentry-javascript that referenced this pull request Apr 19, 2024
Recommend reading through https://web.dev/articles/ttfb before review.

In
https://www.notion.so/sentry/TTFB-vital-is-0-for-navigation-events-2337114dd75542569eb70255a467aba6
we identified that ttfb was being incorrectly calculated in certain
scenarios. This was because we were calculating `ttfb` relative to
transaction start time, **before** it has been adjusted by `browser`
related spans about request/response ( remember browser tracing adjusts
the start timestamp of a pageload transaction after adding certain
request/response related spans).

This meant that `Math.max(responseStartTimestamp - transactionStartTime,
0)` would just end up being `0` most of the time because using
`transactionStartTime` was not correct.

To fix this, we avoid trying to rely on our `transactionStartTime`
timestamp at all, but instead using the web vitals version helper for
this.

When this gets merged in, I'll backport it to v7. I'm doing this in v8
first because I don't want to deal with the merge conflict that comes
when we eventually migrate this code from tracing internal into the
browser package.

As a next step, we should seriously think about getting rid of all of
our vendored code and just rely on the web vitals library - it's a huge
pain to maintain this, and I'm sure there are some insidious bugs
sneaking about.
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.

2 participants