fix(tracing): Don't send negative ttfb#10286
Merged
AbhiPrasad merged 3 commits intodevelopfrom Jan 23, 2024
Merged
Conversation
anonrig
reviewed
Jan 22, 2024
| DEBUG_BUILD && logger.log('[Measurements] Adding TTFB'); | ||
| _measurements['ttfb'] = { | ||
| value: (responseStartTimestamp - transactionStartTime) * 1000, | ||
| value: Math.max(responseStartTimestamp - transactionStartTime, 0) * 1000, |
Contributor
There was a problem hiding this comment.
Can we add a comment to here? As well as a test?
Contributor
size-limit report 📦
|
edwardgou-sentry
approved these changes
Jan 22, 2024
anonrig
approved these changes
Jan 22, 2024
Lms24
approved these changes
Jan 23, 2024
mydea
reviewed
Jan 23, 2024
| ): 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) { |
Member
There was a problem hiding this comment.
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 😅
mydea
approved these changes
Jan 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As per https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/responseStart,
responseStartcan 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.maxto make sure we always set to 0 in the case of a negative value.