Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR] Add redactClasses option #3546

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ sealed class ViewHierarchyNode(
}
}

private fun shouldRedact(view: View, options: SentryOptions): Boolean {
return options.experimental.sessionReplay.redactClasses.contains(view.javaClass.canonicalName)
}

fun fromView(view: View, parent: ViewHierarchyNode?, distance: Int, options: SentryOptions): ViewHierarchyNode {
val (isVisible, visibleRect) = view.isVisibleToUser()
when {
Expand Down Expand Up @@ -282,7 +286,7 @@ sealed class ViewHierarchyNode(
(parent?.elevation ?: 0f) + view.elevation,
distance = distance,
parent = parent,
shouldRedact = false,
shouldRedact = isVisible && shouldRedact(view, options),
isImportantForContentCapture = false, /* will be set by children */
isVisible = isVisible,
visibleRect = visibleRect
Expand Down
2 changes: 2 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2699,12 +2699,14 @@ public final class io/sentry/SentryReplayEvent$ReplayType$Deserializer : io/sent
public final class io/sentry/SentryReplayOptions {
public fun <init> ()V
public fun <init> (Ljava/lang/Double;Ljava/lang/Double;)V
public fun addClassToRedact (Ljava/lang/String;)V
public fun getErrorReplayDuration ()J
public fun getErrorSampleRate ()Ljava/lang/Double;
public fun getFrameRate ()I
public fun getQuality ()Lio/sentry/SentryReplayOptions$SentryReplayQuality;
public fun getRedactAllImages ()Z
public fun getRedactAllText ()Z
public fun getRedactClasses ()Ljava/util/Set;
public fun getSessionDuration ()J
public fun getSessionSampleRate ()Ljava/lang/Double;
public fun getSessionSegmentDuration ()J
Expand Down
18 changes: 18 additions & 0 deletions sentry/src/main/java/io/sentry/SentryReplayOptions.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.sentry;

import io.sentry.util.SampleRateUtils;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -64,6 +66,14 @@ public enum SentryReplayQuality {
*/
private boolean redactAllImages = true;

/**
* Redact all views with the specified class names. The class name is the fully qualified class
* name of the view, e.g. android.widget.TextView.
*
* <p>Default is empty.
*/
private Set<String> redactClasses = new CopyOnWriteArraySet<>();

/**
* Defines the quality of the session replay. The higher the quality, the more accurate the replay
* will be, but also more data to transfer and more CPU load, defaults to MEDIUM.
Expand Down Expand Up @@ -147,6 +157,14 @@ public void setRedactAllImages(final boolean redactAllImages) {
this.redactAllImages = redactAllImages;
}

public Set<String> getRedactClasses() {
return this.redactClasses;
}

public void addClassToRedact(final String className) {
this.redactClasses.add(className);
}

@ApiStatus.Internal
public @NotNull SentryReplayQuality getQuality() {
return quality;
Expand Down
Loading