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(replay): Ensure handleRecordingEmit aborts when event is not added #8938

Merged
merged 1 commit into from Sep 11, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Sep 4, 2023

I noticed that in handleRecordingEmit, due to the async nature of addEvent it could happen that an event is actually not added (because it is discarded due to timestamp etc.). But we are still updating the initial session timestamp ([Replay] Updating session start time to earliest event in buffer to...), as we don't actually abort there.

This PR changes this to actually abort handleRecordingEmit in this case. I added an addEventSync method for this that just returns true/false instead of a promise, which should not change anything there as we haven't been waiting for the result of the promise anyhow.

@mydea mydea requested a review from billyvg September 4, 2023 11:57
@mydea mydea self-assigned this Sep 4, 2023
// Skip all further steps
if (!addEventSync(replay, event, isCheckout)) {
// Return true to skip scheduling a debounced flush
return true;
Copy link
Member Author

Choose a reason for hiding this comment

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

This API for addUpdate is always confusing for me, I always have to double check what I should return to do what 😅 Nothing to do but maybe we can find a clearer API for this at some point.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 4, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.34 KB (-0.04% 🔽)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.29 KB (+0.06% 🔺)
@sentry/browser - Webpack (gzipped) 21.89 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 70.04 KB (-0.08% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.4 KB (-0.07% 🔽)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.47 KB (-0.06% 🔽)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 221.29 KB (-0.11% 🔽)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 85.82 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 60.67 KB (+0.02% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.28 KB (-0.06% 🔽)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.36 KB (-0.04% 🔽)
@sentry/react - Webpack (gzipped) 21.92 KB (+0.07% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.22 KB (-0.04% 🔽)
@sentry/nextjs Client - Webpack (gzipped) 50.85 KB (+0.04% 🔺)

@@ -816,73 +816,6 @@ describe('Integration | errorSampleRate', () => {
expect(replay).not.toHaveLastSentReplay();
});

it('does not stop replay based on earliest event in buffer', async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed this test as honestly I am not 100% sure what it is trying to prove/achieve 😅 it failed here due to timing issues, I first tried to change the timing etc. but ended up not really testing that much meaningful stuff.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's testing that old contents in the buffer do not stop the replay recording

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's OK to delete this test as this is not really so relevant nowadays I think - as generally the earliest event in the buffer will be the initial timestamp that we check against...? Also this is not related to error sampled sessions anymore, at this point where a session may be stopped it is already a "session" session. Or do you want to keep this test around somehow?

Copy link
Member

Choose a reason for hiding this comment

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

Was trying to explain the intention behind it -- I'm okay w/ removing it!

@@ -816,73 +816,6 @@ describe('Integration | errorSampleRate', () => {
expect(replay).not.toHaveLastSentReplay();
});

it('does not stop replay based on earliest event in buffer', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

I think it's testing that old contents in the buffer do not stop the replay recording

@@ -81,6 +88,33 @@ export async function addEvent(
}
}

function shouldAddEvent(replay: ReplayContainer, event: RecordingEvent): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Might be good to have a unit test for this

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added tests for this!

@mydea mydea force-pushed the fn/stop-addEvent branch 2 times, most recently from b828899 to 460595a Compare September 11, 2023 07:51
@mydea mydea merged commit a2ba075 into develop Sep 11, 2023
72 checks passed
@mydea mydea deleted the fn/stop-addEvent branch September 11, 2023 10:56
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.

None yet

2 participants