Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Next Next commit
Only detect custom session replay masks when necessary
Resolves #4439
  • Loading branch information
jamescrosswell committed Aug 14, 2025
commit b8bd70cd9b9a02434f2f901b38a8581c79642c63
19 changes: 17 additions & 2 deletions src/Sentry.Maui/Internal/MauiVisualElementEventsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,37 @@ namespace Sentry.Maui.Internal;
internal class MauiVisualElementEventsBinder : IMauiElementEventBinder
{
private readonly SentryMauiOptions _options;
private readonly bool _isEnabled;

public MauiVisualElementEventsBinder(IOptions<SentryMauiOptions> options)
{
_options = options.Value;
#if __ANDROID__
var replayOptions = _options.Native.ExperimentalOptions.SessionReplay;
_isEnabled = (replayOptions.SessionSampleRate > 0.0 || replayOptions.OnErrorSampleRate > 0.0)
&& replayOptions is not { MaskAllImages: true, MaskAllText: true }
&& !replayOptions.DisableCustomSessionReplayMasks;
#else
_isEnabled = false; // Session replay is only supported on Android for now
#endif
}

/// <inheritdoc />
public void Bind(VisualElement element, Action<BreadcrumbEvent> _)
{
element.Loaded += OnElementLoaded;
if (_isEnabled)
{
element.Loaded += OnElementLoaded;
}
}

/// <inheritdoc />
public void UnBind(VisualElement element)
{
element.Loaded -= OnElementLoaded;
if (_isEnabled)
{
element.Loaded -= OnElementLoaded;
}
}

internal void OnElementLoaded(object? sender, EventArgs _)
Expand Down
24 changes: 24 additions & 0 deletions src/Sentry/Platforms/Android/NativeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,30 @@ public class NativeSentryReplayOptions
public double? SessionSampleRate { get; set; }
public bool MaskAllImages { get; set; } = true;
public bool MaskAllText { get; set; } = true;

/// <summary>
/// <para>
/// Apps with complex user interfaces, consisting of hundreds of visual controls on a single page, may experience
/// performance issues due to the overhead of detecting custom masking of visual elements for Session Replays.
/// </para>
/// <para>
/// In such cases you have a few different options:
/// <list type="bullet">
/// <item>
/// <description>Disable Session Replays entirely</description>
/// </item>
/// <item>
/// <description>Mask all text and all images</description>
/// </item>
/// <item>
/// <description>Disable custom session replay masks (so nothing gets masked)</description>
/// </item>
/// </list>
/// Set this option to <c>true</c> to disable custom session replay masks.
/// </para>
/// </summary>
public bool DisableCustomSessionReplayMasks { get; set; } = false;

internal HashSet<Type> MaskedControls { get; } = [];
internal HashSet<Type> UnmaskedControls { get; } = [];

Expand Down