-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
@@ -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, |
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.
Can we add a comment to here? As well as a test?
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.
Yup good call - done with 195a309
size-limit report 📦
|
): 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) { |
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.
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 😅
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.