-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: Sort breadcrumbs on timestamp before rendering #8397
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
Conversation
|
Awesome, not sure what percentage of events will be effected, but this seems much more correct. How well does this deal with undefined timestamps - is there a risk that any of the major sdks are sending differently formed data for this key here? or do we normalize them on the server? the percy snapshot breadcrumbs have been re-ordered - the exceptions seem to all get moved to the top. is this just a problem with that hardcoded mock data we should fix? |
|
I somehow don't have access to Percy to verify this. I checked components that render breadcrumbs and they don't handle missing data, so I assumed they have to be unified at one point if we already allowed that. We might have to double-check it. @dcramer can you give me Percy access? |
benvinegar
left a comment
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.
.sort needs to return -1, 0, or 1.
| // reverse array to get consistent idx between collapsed/expanded state | ||
| // (indexes begin and increment from last breadcrumb) | ||
| return crumbs | ||
| .sort((a, b) => a.timestamp > b.timestamp) |
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.
The results in Percy suggest this isn't sorting correctly.
.sort should return -1, 0, or 1. Is it possible this is the cause?
eca60ee to
aedcab8
Compare
aedcab8 to
07c3730
Compare
|
@MaxBittker about undefined timestamps, it cannot happen, we have a check for this - sentry/src/sentry/interfaces/breadcrumbs.py Lines 66 to 75 in 96bc1c6
@benvinegar The issue, however, is much more complicated than this and took me a while to find the main cause. The first crumb, which is the main exception is simply created not on the same day. Issue flow:
tl;dr (as I believe it works): created sample event uses fixed timestamp, where breadcrumbs are updated based on the current date (which can be seen on Percy's screenshots) Also, how about doing this operation in the interface instead of UI? sentry/src/sentry/interfaces/breadcrumbs.py Lines 53 to 63 in 96bc1c6
|
|
I'm still super -1 on this. What if we only sort a certain subset of breadcrumbs? JavaScript time is fundamentally nonmonotonic and local so breadcrumbs are likely to be fucked whenever the system time readjusts or we get to a timezone change. |
mitsuhiko
left a comment
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.
I really do not want to do this. We could offer it as an option (toggle between order of submission / timestamp) optionally.
|
I'm totally fine keeping it in |
It's not that it coerces to 1/0. My understanding is that 1 and 0 is not enough to produce stable results depending on the browser's internal sorting algorithm, which is not standardized. More here: https://stackoverflow.com/questions/234683/javascript-array-sort-implementation/234777#234777 For example, this occurs in Chrome right now: [5, 8, 7, 1, 2, 3, 4, 6, 9, 10, 11, 12, 13].sort(function(a, b) {
return a > b; // true/false ... 1/0
});
// => [4, 5, 3, 1, 2, 6, 7, 8, 9, 10, 11, 12, 13] // not sorted |
|
Not relevant anymore due to v4 SDK. |
Reference: https://forum.sentry.io/t/bad-sorting-of-manual-breadcrumbs/3630
At first, I fixed it in the JS SDK getsentry/sentry-javascript#1308, however, after rethinking it, I believe we should do this here, so it's fixed for every SDK instead.
It's out of order, because
timestampis one of the parameters that can be passed tocaptureBreadcrumb, yet we push them at the end of the breadcrumbs array as they happen.