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
Prev Previous commit
Next Next commit
Renamed binder to MauiSessionReplayMaskControlsOfTypeBinder
  • Loading branch information
jamescrosswell committed Aug 21, 2025
commit f19a466fa5ce9c20c0ec54b20bc9eb70976bedcd
7 changes: 5 additions & 2 deletions samples/Sentry.Samples.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ public static MauiApp CreateMauiApp()
options.AddCommunityToolkitIntegration();

#if __ANDROID__
// Currently experimental support is only available on Android
// Currently, experimental support is only available on Android
options.Native.ExperimentalOptions.SessionReplay.OnErrorSampleRate = 1.0;
options.Native.ExperimentalOptions.SessionReplay.SessionSampleRate = 1.0;
// Mask all images and text by default. This can be overridden for individual view elements via the
// sentry:SessionReplay.Mask XML attribute (see MainPage.xaml for an example)
options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = true;
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = true;
// Alternatively the masking behaviour for entire classes of VisualElements can be configured here as
// Alternatively, the masking behaviour for entire classes of VisualElements can be configured here as
// an exception to the default behaviour.
// WARNING: In apps with complex user interfaces, consisting of hundreds of visual controls on a single
// page, this option may cause performance issues. In such cases, consider applying the
// sentry:SessionReplay.Mask="Unmask" attribute to individual controls instead.
options.Native.ExperimentalOptions.SessionReplay.UnmaskControlsOfType<Button>();
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder,
configureOptions?.Invoke(options);
#if __ANDROID__
var replayOptions = options.Native.ExperimentalOptions.SessionReplay;
if (replayOptions is { IsCustomMaskingEnabled: true, IsSessionReplayEnabled: true })
if (replayOptions is { IsSessionReplayEnabled: true, IsTypeMaskingUsed: true })
{
services.AddSingleton<IMauiElementEventBinder, MauiCustomSessionReplayMaskBinder>();
}
Expand Down
41 changes: 20 additions & 21 deletions src/Sentry/Platforms/Android/NativeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,40 +276,39 @@ public class NativeSentryReplayOptions
internal HashSet<Type> MaskedControls { get; } = [];
internal HashSet<Type> UnmaskedControls { get; } = [];

internal bool IsCustomMaskingEnabled { get; private set; }

internal bool IsSessionReplayEnabled => OnErrorSampleRate > 0.0 || SessionSampleRate > 0.0;

/// <summary>
/// Allows you to mask all controls of a particular type for session replay recordings.
/// </summary>
/// <typeparam name="T">The Type of control that should be masked</typeparam>
/// <remarks>
/// WARNING: In apps with complex user interfaces, consisting of hundreds of visual controls on a single
/// page, this option may cause performance issues. In such cases, consider applying SessionReplay.Mask
/// attributes to individual controls instead:
/// <code>sentry:SessionReplay.Mask="Mask"</code>
/// </remarks>
public void MaskControlsOfType<T>()
{
MaskedControls.Add(typeof(T));
}

public void UnmaskControlsOfType<T>()
{
UnmaskedControls.Add(typeof(T));
}

/// <summary>
/// <para>
/// The <see cref="MaskAllImages"/> and <see cref="MaskAllText"/> and <see cref="MaskControlsOfType"/>
/// options allow you to set the default masking behaviour for all visual elements of certain types.
/// </para>
/// <para>
/// This option enables the use of `sentry:SessionReplay.Mask` attributes to override the masking behaviour
/// of specific visual elemennts (for example masking a specific image even though images more generally are
/// not masked).
/// </para>
/// Allows you to unmask all controls of a particular type for session replay recordings.
/// </summary>
/// <typeparam name="T">The Type of control that should be unmasked</typeparam>
/// <remarks>
/// WARNING: In apps with complex user interfaces, consisting of hundreds of visual controls on a single
/// page, enabling this option may cause performance issues.
/// page, this option may cause performance issues. In such cases, consider applying SessionReplay.Mask
/// attributes to individual controls instead:
/// <code>sentry:SessionReplay.Mask="Unmask"</code>
/// </remarks>
/// </summary>
public NativeSentryReplayOptions EnableCustomSessionReplayMasks()
public void UnmaskControlsOfType<T>()
{
IsCustomMaskingEnabled = true;
return this;
UnmaskedControls.Add(typeof(T));
}

internal bool IsTypeMaskingUsed => MaskedControls.Count > 0 || UnmaskedControls.Count > 0;
}

/// <summary>
Expand Down
Loading