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): Don't send negative ttfb #10286

Merged
merged 3 commits into from
Jan 23, 2024
Merged

fix(tracing): Don't send negative ttfb #10286

merged 3 commits into from
Jan 23, 2024

Conversation

AbhiPrasad
Copy link
Member

As per https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStart, responseStart can be 0 if the request is coming straight from the cache. This might lead us to calculate a negative ttfb.

To account for these scenarios, use Math.max to make sure we always set to 0 in the case of a negative value.

@AbhiPrasad AbhiPrasad requested review from edwardgou-sentry, a team, anonrig and mydea and removed request for a team January 22, 2024 15:12
@@ -245,7 +245,7 @@ export function addPerformanceEntries(transaction: Transaction): void {
if (typeof responseStartTimestamp === 'number' && transactionStartTime) {
DEBUG_BUILD && logger.log('[Measurements] Adding TTFB');
_measurements['ttfb'] = {
value: (responseStartTimestamp - transactionStartTime) * 1000,
value: Math.max(responseStartTimestamp - transactionStartTime, 0) * 1000,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment to here? As well as a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup good call - done with 195a309

Copy link
Contributor

github-actions bot commented Jan 22, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.71 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.96 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 72.85 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.6 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.97 KB (+0.05% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.18 KB (0%)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.19 KB (0%)
@sentry/browser - Webpack (gzipped) 22.53 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 75.37 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.01 KB (+0.03% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 32.84 KB (+0.05% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.35 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 211.08 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 99.07 KB (+0.04% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 72.87 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 35.94 KB (+0.05% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 69.37 KB (+0.03% 🔺)
@sentry/react - Webpack (gzipped) 22.58 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.98 KB (+0.02% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 50.27 KB (+0.03% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.14 KB (0%)

@AbhiPrasad AbhiPrasad enabled auto-merge (squash) January 23, 2024 14:42
): void {
// Generate TTFB (Time to First Byte), which measured as the time between the beginning of the transaction and the
// start of the response in milliseconds
if (typeof responseStartTimestamp === 'number' && transactionStartTime) {
Copy link
Member

Choose a reason for hiding this comment

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

l: We can maybe save a few bytes by checking typeof responseStartTime !== 'number' above and returning early, as we now repeat this below as well. but maybe also doesn't make any difference 😅

@AbhiPrasad AbhiPrasad merged commit c017181 into develop Jan 23, 2024
92 checks passed
@AbhiPrasad AbhiPrasad deleted the abhi-ttfb-negative branch January 23, 2024 16:04
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.

5 participants