Skip to content

Commit 837e911

Browse files
[SR] Add redactClasses option (#3546)
Co-authored-by: Roman Zavarnitsyn <[email protected]>
1 parent 615bb0e commit 837e911

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

sentry-android-replay/src/main/java/io/sentry/android/replay/viewhierarchy/ViewHierarchyNode.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ sealed class ViewHierarchyNode(
232232
}
233233
}
234234

235+
private fun shouldRedact(view: View, options: SentryOptions): Boolean {
236+
return options.experimental.sessionReplay.redactClasses.contains(view.javaClass.canonicalName)
237+
}
238+
235239
fun fromView(view: View, parent: ViewHierarchyNode?, distance: Int, options: SentryOptions): ViewHierarchyNode {
236240
val (isVisible, visibleRect) = view.isVisibleToUser()
237241
when {
@@ -282,7 +286,7 @@ sealed class ViewHierarchyNode(
282286
(parent?.elevation ?: 0f) + view.elevation,
283287
distance = distance,
284288
parent = parent,
285-
shouldRedact = false,
289+
shouldRedact = isVisible && shouldRedact(view, options),
286290
isImportantForContentCapture = false, /* will be set by children */
287291
isVisible = isVisible,
288292
visibleRect = visibleRect

sentry/api/sentry.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,12 +2699,14 @@ public final class io/sentry/SentryReplayEvent$ReplayType$Deserializer : io/sent
26992699
public final class io/sentry/SentryReplayOptions {
27002700
public fun <init> ()V
27012701
public fun <init> (Ljava/lang/Double;Ljava/lang/Double;)V
2702+
public fun addClassToRedact (Ljava/lang/String;)V
27022703
public fun getErrorReplayDuration ()J
27032704
public fun getErrorSampleRate ()Ljava/lang/Double;
27042705
public fun getFrameRate ()I
27052706
public fun getQuality ()Lio/sentry/SentryReplayOptions$SentryReplayQuality;
27062707
public fun getRedactAllImages ()Z
27072708
public fun getRedactAllText ()Z
2709+
public fun getRedactClasses ()Ljava/util/Set;
27082710
public fun getSessionDuration ()J
27092711
public fun getSessionSampleRate ()Ljava/lang/Double;
27102712
public fun getSessionSegmentDuration ()J

sentry/src/main/java/io/sentry/SentryReplayOptions.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.sentry;
22

33
import io.sentry.util.SampleRateUtils;
4+
import java.util.Set;
5+
import java.util.concurrent.CopyOnWriteArraySet;
46
import org.jetbrains.annotations.ApiStatus;
57
import org.jetbrains.annotations.NotNull;
68
import org.jetbrains.annotations.Nullable;
@@ -64,6 +66,14 @@ public enum SentryReplayQuality {
6466
*/
6567
private boolean redactAllImages = true;
6668

69+
/**
70+
* Redact all views with the specified class names. The class name is the fully qualified class
71+
* name of the view, e.g. android.widget.TextView.
72+
*
73+
* <p>Default is empty.
74+
*/
75+
private Set<String> redactClasses = new CopyOnWriteArraySet<>();
76+
6777
/**
6878
* Defines the quality of the session replay. The higher the quality, the more accurate the replay
6979
* will be, but also more data to transfer and more CPU load, defaults to MEDIUM.
@@ -147,6 +157,14 @@ public void setRedactAllImages(final boolean redactAllImages) {
147157
this.redactAllImages = redactAllImages;
148158
}
149159

160+
public Set<String> getRedactClasses() {
161+
return this.redactClasses;
162+
}
163+
164+
public void addClassToRedact(final String className) {
165+
this.redactClasses.add(className);
166+
}
167+
150168
@ApiStatus.Internal
151169
public @NotNull SentryReplayQuality getQuality() {
152170
return quality;

0 commit comments

Comments
 (0)