Set Up Session Replay for Flutter

Learn how to enable Session Replay in your mobile app.

Session Replay helps you get to the root cause of an error or latency issue faster by providing you with a reproduction of what was happening in the user's device before, during, and after the issue. You can rewind and replay your application's state and see key user interactions, like taps, swipes, network requests, and console entries, in a single UI.

By default, the SDK masks text, user input, and non-asset images. Images bundled as assets are not masked unless you set options.privacy.maskAssetImages = true. Review privacy settings for SensitiveContent and custom widgets.

Make sure your Sentry Flutter SDK version is at least 9.0.0 (or 10.3.0 for web), which is required for Session Replay. You can update your pubspec.yaml to the matching version:

Copied
dependencies:
  sentry_flutter: ^10.4.0

To record replays automatically, set a non-zero sample rate and wrap your root widget with SentryWidget. For on-demand recording, see Manual Control.

Copied
await SentryFlutter.init(
  (options) {
    options.dsn = '___DSN___';
    options.replay.sessionSampleRate = 1.0;
    options.replay.onErrorSampleRate = 1.0;
  },
  appRunner: () => runApp(
    SentryWidget(
      child: MyApp(),
    ),
  ),
);

For more details on the available properties, see the SentryReplayOptions, which is part of SentryFlutterOptions.

While you're testing, we recommend that you set sessionSampleRate to 1.0. This ensures that every user session will be sent to Sentry.

Once testing is complete, we recommend lowering this value in production. We still recommend keeping onErrorSampleRate set to 1.0.

Available since: v10.3.0

Session Replay for Flutter Web is experimental and off by default. Its API and behavior may change in a minor release. It uses the same widget-level masking as mobile.

To enable it, set enableWebReplay in addition to a non-zero sample rate:

Copied
await SentryFlutter.init(
  (options) {
    options.dsn = '___DSN___';
    options.replay.enableWebReplay = true;
    options.replay.sessionSampleRate = 1.0;
    options.replay.onErrorSampleRate = 1.0;
  },
  appRunner: () => runApp(
    SentryWidget(
      child: MyApp(),
    ),
  ),
);

Keep in mind:

  • Web replay only starts when enableWebReplay is true and sessionSampleRate or onErrorSampleRate is above 0. Otherwise the Replay JavaScript bundle isn't loaded and nothing is recorded, so apps that don't use Replay don't download it.
  • Recording requires the CanvasKit or Skwasm renderer. With any other renderer, nothing is recorded.
  • SentryFlutter.replay.pause() and resume() do nothing on web. start(), startBuffering(), stop() and flush() work as described in Manual Control, with one difference: on web, Replay must also be enabled through a non-zero sample rate. Unlike on mobile, setting both sample rates to 0.0 and starting manually does nothing on web. If you only want manual recording, set a very low rate such as 0.0001.
  • The replay quality maps to a capture scale of 0.5x (low), 0.7x (medium), and 1.0x (high).
  • Click breadcrumbs the JavaScript SDK generates for the Flutter view (body > flutter-view) are dropped from replays, because they can't say what was tapped. The Flutter flutter.ui.click breadcrumb is used instead.

A user session starts when the Sentry SDK is initialized or when the application enters the foreground. The session will capture screen transitions, navigations, touches and other events until the application is sent to the background. If the application is brought back to the foreground within 30 seconds (default), the same replay_id will be used and the session will continue.

The session will be terminated if the application has spent in the background more than 30 seconds or when the maximum duration of 60 minutes is reached. You can adjust the session tracking interval to extend or shorten the duration of a single replay, depending on your needs. Note that if the application exits abnormally while running in the background, the session will also be terminated.

If you prefer not to record an entire session, you can elect to capture a replay only when an error occurs or when your app captures feedback. In this case, the integration will buffer up to 30 seconds worth of events prior to the trigger. It will continue to record the session, following the rules above regarding session life and activity. For the built-in SentryFeedbackForm, the buffer is sent when the form opens, so the replay shows what happened before the user started entering feedback. Read the sampling section for configuration options.

Sampling allows you to control how much of your app's traffic will result in a Session Replay. There are two sample rates you can adjust to get the replays relevant to you:

  1. sessionSampleRate - The sample rate for replays that begin recording immediately and last the entirety of a user's session.
  2. onErrorSampleRate - The sample rate for replays that are recorded when an error happens or when feedback is captured. This type of replay will record up to 30 seconds of events prior to the trigger and continue recording until the session ends.

Sampling starts as soon as a session begins. The sessionSampleRate is then evaluated. If the session is sampled, replay recording will start immediately. If not, onErrorSampleRate will be evaluated. If the session is sampled at this point, the replay will be buffered and will only be uploaded to Sentry if an error occurs, your app calls Sentry.captureFeedback(), or the built-in feedback form opens.

Available since: v10.0.0

Use SentryFlutter.replay to control recording for opt-in flows or specific parts of your app. These methods support Android and iOS, and web with the experimental web replay option enabled. pause() and resume() do nothing on web. The methods do nothing on other platforms or before SentryFlutter.init().

To record only when your app explicitly requests it, set both sample rates to zero during initialization. Keep the SentryWidget wrapper from Setup: manual recording still needs it to capture your Flutter UI.

Copied
await SentryFlutter.init(
  (options) {
    options.dsn = '___DSN___';
    options.replay.sessionSampleRate = 0.0;
    options.replay.onErrorSampleRate = 0.0;
  },
  appRunner: () => runApp(SentryWidget(child: MyApp())),
);

After initialization, start recording when the user opts in or enters the workflow you want to capture:

Copied
await SentryFlutter.replay.start();

Explicit starts bypass automatic session sampling. Setting the sample rates to zero does not disable the manual API. Calling start() while a replay is already active does nothing.

To capture the lead-up to a specific action without uploading an entire session, start a rolling buffer of up to 30 seconds:

Copied
await SentryFlutter.replay.startBuffering();

Call flush() when your app decides to send the buffer:

Copied
await SentryFlutter.replay.flush();

Flushing sends the buffer and continues recording in session mode. An error can also trigger this transition when selected by onErrorSampleRate. With onErrorSampleRate set to 0.0, errors do not send the buffer automatically; call flush() explicitly.

Call pause() before showing sensitive content and resume() after hiding it. The paused interval excludes Replay screenshots and touches, and resuming continues the same replay.

Copied
await SentryFlutter.replay.pause();
try {
  await showSensitiveScreen();
} finally {
  await SentryFlutter.replay.resume();
}

Here, showSensitiveScreen() represents your app's navigation flow and should complete after the sensitive screen closes. Continue to configure masking rules for recorded content. Pausing Replay does not disable other SDK features, such as error reporting.

Call stop() to end the current replay. Starting again creates a new replay with a new replay ID:

Copied
await SentryFlutter.replay.stop();
// Start a separate replay when your app needs to record again.
await SentryFlutter.replay.start();

Use flush() to send pending data while continuing to record. In session mode, it sends pending data; in buffer mode, it sends the buffer and switches to session mode. If no replay is active, flush() starts a new session, so it is not a shutdown operation.

All manual control methods return Future<void>. Await calls in order, especially when stopping and starting another replay. Native recording and uploading continue asynchronously; completion of the future is not confirmation that Sentry has received the replay. Manual replays remain subject to server-side rate limits.

Personally identifiable information (PII), and privacy are important considerations when enabling Session Replay. The Sentry Flutter SDK masks text, user input, and non-asset images by default. Asset images require options.privacy.maskAssetImages = true.

While we have default privacy considerations in place, there are additional settings you might need to configure to fully mask your app's content. We cannot detect the usage of third party widgets such as FlutterMap so you need to manually configure the privacy configuration to mask the content of these widgets. To learn more about session replay privacy, read our docs.

Errors that happen while a replay is running will be linked to the replay, making it possible to jump between related issues and replays. However, it's possible that in some cases the error count reported on the Replays Details page won't match the actual errors that have been captured. That's because errors can be lost, and while this is uncommon, there are a few reasons why it could happen:

  • The replay was rate-limited and couldn't be accepted.
  • The replay was deleted by a member of your org.
  • There were network errors and the replay wasn't saved.
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").