# Set Up Session Replay | Sentry for Flutter

Flutter Session Replay is available on **iOS** and **Android**.

[Session Replay](https://docs.sentry.io/product/explore/session-replay.md) 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, our Session Replay SDK masks all text content, images, and user input, giving you heightened confidence that no sensitive data will leave the device. To learn more, see [product docs](https://docs.sentry.io/product/explore/session-replay.md).

## [Pre-requisites](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#pre-requisites)

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

```yaml
dependencies:
  sentry_flutter: ^9.0.0
```

## [Setup](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#setup)

To set up replay, enable it by setting a non-zero sample rate and wrapping your root widget with `SentryWidget`:

```dart
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](https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/SentryReplayOptions-class.html), which is part of [SentryFlutterOptions](https://pub.dev/documentation/sentry_flutter/latest/sentry_flutter/SentryFlutterOptions-class.html).

## [Verify](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#verify)

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`.

## [User Session](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#user-session)

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](https://docs.sentry.io/platforms/dart/guides/flutter/configuration/releases.md#sessions) to extend or shorten the duration of a single replay, depending on your needs.

### [Replay Captures on Errors Only](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#replay-captures-on-errors-only)

If you prefer not to record an entire session, you can elect to capture a replay only if an error occurs. In this case, the integration will buffer up to one minute worth of events prior to the error being thrown. It will continue to record the session, following the rules above regarding session life and activity. Read the [sampling](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#sampling) section for configuration options.

## [Sampling](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#sampling)

Sampling allows you to control how much of your website'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. This type of replay will record up to a minute of events prior to the error 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.

## [PII & Privacy Considerations](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#pii--privacy-considerations)

Personally identifiable information (PII), and privacy are important considerations when enabling Session Replay. The Sentry Flutter SDK aggressively masks all `Text`, `EditableText`, `RichText` and `Image` widgets by default.

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](https://pub.dev/packages/flutter_map) 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.](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay/privacy.md)

## [Error Linking](https://docs.sentry.io/platforms/dart/guides/flutter/session-replay.md#error-linking)

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.
