-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(browser): Fix idle span ending #12306
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
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.
Good catch!
Any chance we can test this reliably? No worries if not or if it'd be too much work; was just wondering
size-limit report 📦
|
Yeah not 100% sure yet, none of our tests has caught this, I guess because it will only really be noticeable if one of the performance spans, for whatever reason, has an earlier start or end timestamp, which does not seem to happen all the time but sometimes 🤔 maybe I can simulate it somehow at least... |
03e6338
to
a4efccc
Compare
I adjusted a test to ensure this actually works (the test failed before)! |
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.
thx!
4732edf
to
f3666ed
Compare
I noticed here https://github.com/getsentry/sentry-javascript/pulls that some tests were becoming flaky. Investigating this some more, I figured out what was happening: 1. For idle spans, when the span is ended (in `on('spanEnded')`, which is triggered in `span.end()`), we call `onIdleSpanEnded` 2. In there, we call `beforeSpanEnd` 3. This is used by `browserTracingIntegration` to call `addPerformanceEntries(span)`, which adds performance spans to the idle span 4. After that, in `onIdleSpanEnded`, any spans having start/end timestamps outside of the idle span start/end timestamp will be discarded This lead to cases where performance spans were discarded because they were out of bounds of the idle span - which is not what we want! Now, this PR changes the timing of this a bit: Now, we actually patch `span.end` of the SentrySpan, to ensure that we can always run `beforeSpanEnd` with the correct timing, taking all spans that are added in `beforeSpanEnd` into account to adjust the start/end time of the idle span.
I noticed here https://github.com/getsentry/sentry-javascript/pulls that some tests were becoming flaky. Investigating this some more, I figured out what was happening:
on('spanEnded')
, which is triggered inspan.end()
), we callonIdleSpanEnded
beforeSpanEnd
browserTracingIntegration
to calladdPerformanceEntries(span)
, which adds performance spans to the idle spanonIdleSpanEnded
, any spans having start/end timestamps outside of the idle span start/end timestamp will be discardedThis lead to cases where performance spans were discarded because they were out of bounds of the idle span - which is not what we want!
Now, this PR changes the timing of this a bit:
Now, we actually patch
span.end
of the SentrySpan, to ensure that we can always runbeforeSpanEnd
with the correct timing, taking all spans that are added inbeforeSpanEnd
into account to adjust the start/end time of the idle span.