From 0fe60e734417a47c4b47c3250135e3f6c54275a1 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 16 Jan 2023 09:16:18 +0100 Subject: [PATCH] feat(replay): Add `flush` method to integration --- packages/replay/README.md | 6 ++++++ packages/replay/src/integration.ts | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/replay/README.md b/packages/replay/README.md index 3057992e1a88..44411c052415 100644 --- a/packages/replay/README.md +++ b/packages/replay/README.md @@ -233,3 +233,9 @@ However, please note that it is _possible_ that the error count reported on the does not match the actual errors that have been captured. The reason for that is that errors _can_ be lost, e.g. a network request fails, or similar. This should not happen to often, but be aware that it is theoretically possible. + +## Manually sending replay data + +You can use `replay.flush()` to immediately send all currently captured replay data. +This can be combined with `replaysOnErrorSampleRate: 1` +in order to be able to send the last 60 seconds of replay data on-demand. diff --git a/packages/replay/src/integration.ts b/packages/replay/src/integration.ts index 274ec6147e34..cfc2f10a4c02 100644 --- a/packages/replay/src/integration.ts +++ b/packages/replay/src/integration.ts @@ -185,6 +185,17 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`, this._replay.stop(); } + /** + * Immediately send all pending events. + */ + public flush(): Promise | void { + if (!this._replay || !this._replay.isEnabled()) { + return; + } + + return this._replay.flushImmediate(); + } + /** Setup the integration. */ private _setup(): void { // Client is not available in constructor, so we need to wait until setupOnce