-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Change stop()
to flush and remove current session
#7741
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): Change stop()
to flush and remove current session
#7741
Conversation
`stop()` will now flush the eventBuffer before clearing it, as well as removing the session from Session Storage. Due to the flushing, `stop()` is now async. Ref: #7738
size-limit report 📦
|
packages/replay/src/integration.ts
Outdated
@@ -207,12 +207,12 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`, | |||
* Currently, this needs to be manually called (e.g. for tests). Sentry SDK | |||
* does not support a teardown | |||
*/ | |||
public stop(): void { | |||
public async stop(): Promise<void> { |
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.
No need to make this async
, as this will just create a new promise!
packages/replay/src/replay.ts
Outdated
// Set this property so that it ignores `_isEnabled` = false | ||
// We can't move `_isEnabled` after awaiting a flush, otherwise we can | ||
// enter into an infinite loop when `stop()` is called while flushing. | ||
this._shouldFinalFlush = true; |
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.
Hmm, I don't really like this flag - I would prefer we find a way to solve this by e.g. passing an argument to flushImmediate()
or making a separate function for this type of flushing to ensure this. Seems prone to run out of sync, be accidentally true/false when we don't mean it to, etc.
One option I could see is to just do:
this._isEnabled = false;
this._removeListeners();
this._flushAfterStop();
function _flushAfterStop() {
this._debouncedFlush().cancel();
this._flush({ force: true });
}
Or something along these lines? IMHO as we are stopping here anyhow, we don't necessarily need to run the debounced flush here at all, allowing us to separate this a bit better?
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.
updated, instead of creating a private method, I just kept the flush calls inline as it isn't used elsewhere.
packages/replay/src/types.ts
Outdated
@@ -474,6 +474,15 @@ export interface ReplayContainer { | |||
setInitialState(): void; | |||
} | |||
|
|||
export interface ReplayFlushOptions { |
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.
l: Do we need to export this here, or can we just inline this into the one place where it is used? Maybe actually gives more context seeing it there?
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.
Done here: fd448a6
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.
Very nice! 🚢
@@ -807,7 +820,7 @@ export class ReplayContainer implements ReplayContainerInterface { | |||
// This means we retried 3 times and all of them failed, | |||
// or we ran into a problem we don't want to retry, like rate limiting. | |||
// In this case, we want to completely stop the replay - otherwise, we may get inconsistent segments | |||
this.stop('sendReplay'); | |||
void this.stop('sendReplay'); |
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.
Just noticed this @mydea -- I think this is ok since stop()
will attempt the flush, fail, and when it retries, this._isEnabled
is false
, so will fail.
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 think it should be fine since this._isEnabled = false
should be set "synchronously" in the async stop function. So I would expect this to be false already in the next code line, basically.
stop()
will now flush the eventBuffer before clearing it, as well as removing the session from Session Storage. Due to the flushing,stop()
is now async.Closes: #7738