Skip to content

Conversation

@bricefriha
Copy link
Contributor

Relevant to #3353, I added a option to have a callback just before attaching a screenshot.

Note

I didn't had a closing keyword to this PR, as I don't believe that change alone fixes the core issue. However this change was demanded

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 4ac2276

@bricefriha
Copy link
Contributor Author

bricefriha commented Oct 7, 2024

I did add a change log, maybe I did it wrong 🤔
image

update

it was an indentation issue, my bad

@bricefriha bricefriha force-pushed the feat/programmatic_sc_attachement branch from a97e7a3 to c453695 Compare October 7, 2024 12:59
Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

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

Fwiw, PR titles we loosely follow a feat:, fix:, chore: convention. No need to add the issue number.

@bricefriha bricefriha changed the title #3353 Feat: BeforeCaptureScreenshot option feat: BeforeCaptureScreenshot option Oct 7, 2024
@bruno-garcia
Copy link
Member

@romtsn how do we deal with this on Android for example?

@bruno-garcia
Copy link
Member

Looks like we tried binding from Android but we never added Attachment on the .NET hint:

//dotnetHint.Screenshot = (javaHint.Screenshot is { } screenshot) ? screenshot.ToAttachment() : null;

@bruno-garcia
Copy link
Member

From in this PR:

This:

Hints provide two specific functions:

They allow you to add or remove attachments during any of the mentioned callbacks. (Resolves #1469)

But unfortunately no docs anywhere to be found

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

The code looks good. I made a few styling suggestions.

I'm not entirely sure what this new option allows SDK users to do that they can't already do with SentryOptions.SetBeforeSend... The Android docs state:

Because capturing screenshots can be a resource-intensive operation on Android, it's limited to one screenshot every 2 seconds using a debouncing mechanism. This behavior can be overruled if you supply a BeforeCaptureCallback for screenshots in the SentryAndroidOptions.

The BeforeCaptureCallback also allows you to customize the behavior based on event data, so you can decide when to capture a screenshot and when not to. For example, you can decide to only capture screenshots of crashed and fatal events:

But it doesn't look like in the .NET implementation we're using the result of this callback in any way to determine whether a screenshot is added or not in SentryMauiScreenshotProcessor.cs.

I think it'd be worth adding an example of the new API to one of our samples, demonstrating how you can do something with it that can't already be achieved using SetBeforeSend. That'd be a good sanity check for us, as maintainers (to ensure we're building something meaningful), and would help demonstrate the value of the new functionality to SDK users.

@romtsn
Copy link
Member

romtsn commented Oct 8, 2024

@romtsn how do we deal with this on Android for example?

we've added this callback because BeforeSend is already too late to determine whether we want to capture a screenshot or not, at that point the screenshot is already there and the performance cost is already paid. The callback is mainly targeting users who want to avoid capturing screenshots e.g. for errors (default behavior), and only do it for crashes.

FWIW, our callback does not return an event but a boolean that defines whether the screenshot should be captured or not, see: https://github.com/getsentry/sentry-java/blob/b5b093e5f805d0d02c7be344403804e7a7605398/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java#L77-L88

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

Just a couple of notes about comments but otherwise looks good, as long as CI is happy 👍🏻

It would be good to add some docs on this to the Sentry Docs as well.

@jamescrosswell jamescrosswell self-requested a review October 21, 2024 00:24
@bricefriha bricefriha force-pushed the feat/programmatic_sc_attachement branch from 537b91e to 4517762 Compare October 21, 2024 06:14
@bricefriha
Copy link
Contributor Author

bricefriha commented Oct 21, 2024

Update

The callback works similarly to the Android SDK. It returns a boolean that determines whether to ignore the capture.

MAUI Sdk Android Sdk
image image

(details)

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

Functionally, looks good. I think just tweak the tests...

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

LGTM!

@bruno-garcia bruno-garcia enabled auto-merge (squash) October 23, 2024 13:20
Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

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

Looks great to me!

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.

7 participants