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

feat(replay): Add flush method to integration #6776

Merged
merged 1 commit into from
Jan 19, 2023
Merged

Conversation

mydea
Copy link
Member

@mydea mydea commented Jan 16, 2023

This exposes a flush method on the integration class, which can be used to flush any pending replay recording data immediately.

This has been requested a few times, and while this PR does not really add a first-class solution for this problem, it at least makes it possible to solve it manually. In combination with replaysOnErrorSampleRate: 1 we can ensure that we always capture up to 60s of replay data. Then, clients may trigger replay.flush() at any time (e.g. when the user clicks a "submit error" button or similar), sending the buffered replay data.

note: I went with flush vs. flushImmediate, as I'd say that is an internal concern of the replay container class - from a users perspective, flush makes sense here IMHO?

ref #6537
ref #6420

@mydea mydea requested review from billyvg and Lms24 January 16, 2023 08:19
@mydea mydea self-assigned this Jan 16, 2023
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.84 KB (0%)
@sentry/browser - ES5 CDN Bundle (minified) 61.46 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.61 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 55 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 20.37 KB (0%)
@sentry/browser - Webpack (minified) 66.54 KB (0%)
@sentry/react - Webpack (gzipped + minified) 20.4 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 47.63 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 26.82 KB (+0.02% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 25.25 KB (0%)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 43.36 KB (-0.8% 🔽)
@sentry/replay - Webpack (gzipped + minified) 38.58 KB (-0.94% 🔽)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

From a technical PoV, this looks good. We should just be aware that we're expanding public API and users can now interfere with flushing (see my comment). However, there seems to be a legitimate use case for this so I think it's fine.

Comment on lines +192 to +194
if (!this._replay || !this._replay.isEnabled()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

l: Just wondering if we should check for isPaused() here as well... technically, recording could be paused b/c of rate limiting and we wouldn't want to flush in this case. But overall, I think chances are pretty low that this would actually happen. And even if it does, the consequences wouldn't be bad, as we're already handling rate limit responses while being rate-limited. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought the same. I'd say it is OK, as (theoretically) when paused the event buffer has to be empty always, so it wouldn't even attempt to send anything. I'd say it is OK to leave it like this?

Copy link
Member

Choose a reason for hiding this comment

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

when paused the event buffer has to be empty always

Not necessarily, pause just stops DOM recording, we could have events from window.performance, but in that case, might be ok to try to flush.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm yeah, true, I'd say that is not incorrect to flush the stuff that has not been sent yet due to being paused?

Comment on lines +192 to +194
if (!this._replay || !this._replay.isEnabled()) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

when paused the event buffer has to be empty always

Not necessarily, pause just stops DOM recording, we could have events from window.performance, but in that case, might be ok to try to flush.

return;
}

return this._replay.flushImmediate();
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it better to only allow users to use debounced flush to reduce risk of being flooded with flushes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, this would kind of defeat the purpose (a bit) of this - as e.g. if a user clicks a button, we trigger debounced flush, the user closes the window --> we may not have sent the stuff yet. IMHO it's OK to put this burden on the SDK users - it's up to them to only use this sparingly?

Copy link
Member

Choose a reason for hiding this comment

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

I'm good with that

@mydea mydea merged commit 5f26034 into master Jan 19, 2023
@mydea mydea deleted the fn/replay-flush branch January 19, 2023 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants