What problem could Sentry solve that it doesn't?
Current Issue
The Unity SDK currently provides two BeforeCapture callbacks that have limited functionality:
- Screenshots:
|
internal Func<bool>? BeforeCaptureScreenshotInternal => _beforeCaptureScreenshot; |
- ViewHierarchy:
|
internal Func<bool>? BeforeCaptureViewHierarchyInternal => _beforeCaptureViewHierarchy; |
Both callbacks share the same limitations:
- No arguments are passed to the callback function
- Only return a bool (capture or don't capture)
- Cannot access the current event context that triggered the capture
- Cannot modify the captured data
This design makes these callbacks minimally useful since users cannot make informed decisions about whether to capture data or modify it based on the actual content or event context.
Proposed Solutions
Screenshots: Change to BeforeSendScreenshot
Since screenshots are now being sent as standalone attachments (see #2240), the callback should be changed to BeforeSendScreenshot with the following improvements:
- Input: Pass the captured screenshot as Texture2D or byte[]
- Output: Allow returning modified byte[] or null to discard
- Benefits:
- Users can blur sensitive areas or redact PII
- Content-based filtering (skip blank/corrupted screenshots)
- Image processing (resize, compress, watermark)
ViewHierarchy: Change to BeforeAttachViewHierarchy
For view hierarchy capture, the callback should occur after capture but before attachment to allow data modification:
- Current flow: Capture → BeforeSend (modification is cumbersome)
|
hint.AddAttachment(CaptureViewHierarchy(), "view-hierarchy.json", AttachmentType.ViewHierarchy, "application/json"); |
- Proposed flow: Capture → BeforeAttachViewHierarchy → Add to hint
- Input: Pass the captured view hierarchy data as byte[]
- Output: Allow returning modified byte[] or null to discard
- Benefits:
- Easier data modification compared to processing in BeforeSend
- Can filter sensitive UI elements
- Can reduce hierarchy size based on content
What problem could Sentry solve that it doesn't?
Current Issue
The Unity SDK currently provides two BeforeCapture callbacks that have limited functionality:
sentry-unity/src/Sentry.Unity/SentryUnityOptions.cs
Line 234 in fcd5e99
sentry-unity/src/Sentry.Unity/SentryUnityOptions.cs
Line 250 in fcd5e99
Both callbacks share the same limitations:
This design makes these callbacks minimally useful since users cannot make informed decisions about whether to capture data or modify it based on the actual content or event context.
Proposed Solutions
Screenshots: Change to BeforeSendScreenshot
Since screenshots are now being sent as standalone attachments (see #2240), the callback should be changed to BeforeSendScreenshot with the following improvements:
ViewHierarchy: Change to BeforeAttachViewHierarchy
For view hierarchy capture, the callback should occur after capture but before attachment to allow data modification:
sentry-unity/src/Sentry.Unity/ViewHierarchyEventProcessor.cs
Line 35 in fcd5e99