Set Up Session Replay
Learn how to enable Session Replay in your mobile app.
Flutter Session Replay is available on iOS and Android.
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, 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.
Make sure your Sentry Flutter SDK version is at least 8.9.0, which is required for Session Replay. You can update your pubspec.yaml
to the matching version:
dependencies:
sentry_flutter: ^8.9.0
To set up the integration, add the following to your Sentry initialization:
await SentryFlutter.init((options) {
...
options.replay.sessionSampleRate = 1.0;
options.replay.onErrorSampleRate = 1.0;
});
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
.
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:
sessionSampleRate
- The sample rate for replays that begin recording immediately and last the entirety of a user's session.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.
By default, the SDK is recording and aggressively redacting (masking) all Text
, EditableText
, and Image
widgets for Session Replay
. To modify or disable this behavior, use the options.experimental.privacy
parameter.
Modifying this parameter will also affect masking
for Screenshots
.
Masking in the Sentry Flutter SDK is based on Widget types, e.g. Image
, not the string representation of the type (i.e. we check whether a widgetInstance
should be masked by checking if (widgetInstance is Image)
instead of if (widgetInstance.runtimeType == 'Image')
). This means we can ensure masking works regardless of obfuscation in release builds and also works for subclasses. However, it also means we can only automatically mask widgets that are part of the Flutter SDK itself.
We cannot mask widgets defined in various 3rd-party packages (because the type is not known in the Sentry Flutter SDK), even though many should be masked.
Therefore, you need to consider the widgets your application uses and ensure they're masked correctly with custom masking rules. Examples of widgets that usually should be masked include (but are not limited to): VideoPlayer, WebView, Chart, etc.
You can tune this and add custom masking rules to fit your needs by adjusting the configuration in options.experimental.privacy
. For example, you can explicitly mask or unmask widgets by type, or you can even have a callback to decide whether a specific widget instance should be masked:
options.privacy.mask<IconButton>();
options.privacy.unmask<Image>();
options.privacy.maskCallback<Text>(
(Element element, Text widget) =>
(widget.data?.contains('secret') ?? false)
? SentryMaskingDecision.mask
: SentryMaskingDecision.continueProcessing);
Mask all text content. Draws a rectangle of text bounds with text color on top. Currently, only Text
and EditableText
Widgets are masked.
Mask content of all images. Draws a rectangle of image bounds with image's dominant color on top. Currently, only Image
widgets are masked.
Mask asset images coming from the root asset bundle.
Mask given widget type T
(or subclasses of T
) in the screenshot. Note: masking rules are called in the order they're added so if a previous rule already makes a decision, this rule won't be called.
You can find more details in the documentation for each method.
If you find that data isn't being masked with the default settings, please let us know by creating a GitHub issue.
To disable masking for Screenshots
and Session Replay
(not to be used on applications with sensitive data):
options.experimental.privacy.maskAllText = false;
options.experimental.privacy.maskAllImages = false;
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.
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").