Using custom redact for Session Replay

Learn how to choose which part of your app's data to redact in Session Replay.

Using custom redaction for Session Replay can expose sensitive data. Make sure to double-check every part of your app's data that you choose to redact or not.

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. However, you can choose which parts of your app's data to redact or not by using some different options.

You can choose which type of view you want to redact or ignore by using the redactViewClasses or ignoreViewClasses options.

Let's say you have a custom view that you want to redact and a UILabel subclass (which normally would be redacted) that you want to ignore. You can set the options like this:

Copied
  options.experimental.sessionReplay.redactViewClasses = [MyCustomView.self]
  options.experimental.sessionReplay.ignoreViewClasses = [MyCustomLabel.self]

You can also choose to redact or ignore a specific view instance by using the replay API or view extensions like this:

Copied
  SentrySDK.replay.redactView(view: view)
  SentrySDK.replay.ignoreView(view: label)

or

Copied
  view.sentryReplayRedact()
  label.sentryReplayIgnore()

Because of the way SwiftUI is transformed into UIKit, it will often be over-redacted. A modifier like background uses the same element as an Image. In order to control the SwiftUI redact process, you first need to disable the default redaction options:

Copied
    options.experimental.sessionReplay.redactAllText = false
    options.experimental.sessionReplay.redactAllImages = false

Then you can manually choose which View you want to redact with the replayRedact modifier

Copied
    var body: some View {
        Text("Hello, World!")
            .sentryReplayRedact()
    }

Dissabling the default redaction options will expose all text and images in the session replay. Make sure to redact them manually.

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").