getsentry / sentry-dotnet

Sentry SDK for .NET
https://docs.sentry.io/platforms/dotnet
MIT License
568 stars 202 forks source link

[MAUI] Make it possible to programmatically decide whether to attach a screenshot or not #3353

Open vecalion opened 1 month ago

vecalion commented 1 month ago

Problem Statement

Something like BeforeCaptureCallback in the Android version (https://docs.sentry.io/platforms/android/enriching-events/screenshots/).

There are two reasons why I'm interested in this feature: 1) Screenshots of some parts of the app may contain private information that is not supposed to be seen by the team monitoring issues in Sentry. 2) There is no need to have screenshots for handled exceptions because in our case, they don't add any new information. However, since they are quite heavy, they generate a lot of unnecessary traffic for users.

Solution Brainstorm

No response

jamescrosswell commented 1 month ago

Hi @vecalion ,

If you don't want screenshots at all, it is possible to turn these off in the options when initialising the SDK.

Alternatively, the screenshots for an event are available (and can be altered) via the Hint parameter in the SetBeforeSend callback:

                options.AttachScreenshot = true;
                options.SetBeforeSend((@event, hint) =>
                {
                    hint.Attachments.Clear();
                    return @event;
                });
bitsandfoxes commented 1 month ago

Thanks for the workarounds @jamescrosswell. If we wanted to prevent the overhead of actually creating the screenshot and only then make a decision to discard it I think we need to add a BeforeCaptureScreenshot callback to the options and invoke it here: https://github.com/getsentry/sentry-dotnet/blob/9884fdc7ec13caae0c5c9029dfec2258293eb429/src/Sentry.Maui/Internal/SentryMauiScreenshotProcessor.cs#L19-L23