- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 225
feat: BeforeCaptureScreenshot option #3661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 
 | 
a97e7a3    to
    c453695      
    Compare
  
    There was a problem hiding this 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.
| @romtsn how do we deal with this on Android for example? | 
| Looks like we tried binding from Android but we never added Attachment on the .NET hint: 
 | 
| From in this PR: This: 
 
 But unfortunately no docs anywhere to be found | 
There was a problem hiding this 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.
Co-authored-by: James Crosswell <[email protected]>
| 
 we've added this callback because  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 | 
…/getsentry/sentry-dotnet into feat/programmatic_sc_attachement
…oreCaptureScreenshotInternal invocation Co-authored-by: James Crosswell <[email protected]>
There was a problem hiding this 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.
Co-authored-by: James Crosswell <[email protected]>
Co-authored-by: James Crosswell <[email protected]>
537b91e    to
    4517762      
    Compare
  
    | UpdateThe callback works similarly to the Android SDK. It returns a boolean that determines whether to ignore the capture. 
 (details) | 
There was a problem hiding this 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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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!



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