Skip to content

Conversation

@jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Apr 17, 2025

Summary

Previously the SessionReplay options for Android supported either Masking everything or masking nothing:

options.Native.ExperimentalOptions.SessionReplay.MaskAllImages = true;
options.Native.ExperimentalOptions.SessionReplay.MaskAllText = true;

This PR adds the ability to override those "default" masking settings one or more view elements.

Overriding mask settings for specific MAUI components

SDK users would do this first by adding a reference to the Sentry namespace (which gives access to Sentry specific XAML elements):

xmlns:sentry="http://schemas.sentry.io/maui"

And then by specifying the sentry:SessionReplay.Mask for any view elements they want to explicitly mask or unmask:

<Image
Source="dotnet_bot.png"
sentry:SessionReplay.Mask="Unmask"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />

Overriding mask settings for types of MAUI components

// Alternatively the masking behaviour for entire classes of VisualElements can be configured here as
// an exception to the default behaviour.
options.Native.ExperimentalOptions.SessionReplay.UnmaskControlsOfType<Button>();

Tests

I added a couple of almost inconsequential unit tests. It's very difficult to test these behaviours however since ultimately we're setting properties on native (Android) view elements. Create those view elements requires an IMauiContext which really needs the view element to sit in an actual MAUI application running on Android.

I couldn't think of a practical way to access or leverage the MAUI context that would exist in our Sentry.Maui.Device.TestApp.csproj (I think that's gets created magically by xharness). If anyone who's more experienced with MAUI than me has any ideas about how this could be better tested, maybe we can add better test coverage in the future.

@jamescrosswell jamescrosswell changed the title feat: Support custom masking for SessionReplay in MAUI Android apps Custom SessionReplay masks in MAUI Android apps Apr 17, 2025
@jamescrosswell jamescrosswell marked this pull request as ready for review April 22, 2025 06:04
/// <summary>
/// Controls the masking behaviour of the Session Replay feature.
/// </summary>
public enum SessionReplayMaskMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is the term "mask mode" (or "masking mode") established through other SDKs, or is this enum a .NET-only concept to "type-ify" the strings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The later - I made it up to limit the number of possibilities presented by the tooling when writing XAML.

Copy link
Member

@Flash0ver Flash0ver Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we have already established prior art for the enum and it's name.

@jamescrosswell
Copy link
Collaborator Author

jamescrosswell commented Apr 23, 2025

Make the event handlers a static method, not an anonymous one.

Thanks @aritchie - new code uses static handlers. To avoid capturing the newvalue variable I had to define two separate handlers and wire up the appropriate handler depending on the mask setting... but the result is static handlers per your recommendation.

@jamescrosswell jamescrosswell requested a review from aritchie April 24, 2025 06:46
Copy link
Contributor

@aritchie aritchie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - ship it!

@jamescrosswell jamescrosswell merged commit 85c56e2 into main Apr 27, 2025
30 checks passed
@jamescrosswell jamescrosswell deleted the replay-masking branch April 27, 2025 03:15
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the same API work in iOS once we add there?

@jamescrosswell
Copy link
Collaborator Author

can the same API work in iOS once we add there?

It depends on how masking is done in iOS. I'm not expecting it to work on iOS though. The Java implementation seems quite android specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants