Using Custom Masking for Session Replay
Learn how to mask parts of your app's data in Session Replay.
Before publising an App with Session Replay enabled, make sure to test it thoroughly to ensure that no sensitive data is exposed.
If you choose to use custom masking in your Session Replays, you may accidentally expose sensitive customer data. Be sure to double-check what you choose to expose.
By default, our Session Replay SDK masks all text content, images, and user input. This helps ensure that no sensitive data will be exposed. You can also manually choose which parts of your app's data you want to mask by using the different options listed below.
You can choose which type of view you want to mask or unmask by using the maskedViewClasses or unmaskedViewClasses options.
Let's say you have a custom view that you want to mask and a UILabel subclass (which normally would be masked) that you don't want to mask. You can set the options like this:
options.experimental.sessionReplay.maskedViewClasses = [MyCustomView.self]
options.experimental.sessionReplay.unmaskedViewClasses = [MyCustomLabel.self]
You can also choose to mask or unmask a specific view instance by using the replay API (SentrySDK.replay) or view extensions like this:
SentrySDK.replay.maskView(view: view)
SentrySDK.replay.unmaskView(view: label)
or
view.sentryReplayMask()
label.sentryReplayUnmask()
Because of the way SwiftUI is transformed into UIKit, it will often be over-masked. A modifier like background uses the same element as an Image. In order to control the SwiftUI masking process, you need to use the sentryReplayUnmask and/or sentryReplayMask modifiers.
In this example we want to show the message, but not the user name.
@Binding var user: String
var body: some View {
VStack {
Text("Hello")
.sentryReplayUnmask()
Text("\(user)")
}
}
In this example, we need to unmask the VStack because its background element will be masked by default. To hide the username, we need to mask it.
@Binding var user: String
var body: some View {
VStack {
Text("Hello")
Text("\(user)")
.sentryReplayMask()
}
.background(.blue)
.sentryReplayUnmask()
}
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").