Skip to content

Change BeforeCapture callbacks into BeforeSend #2252

@bitsandfoxes

Description

@bitsandfoxes

What problem could Sentry solve that it doesn't?

Current Issue

The Unity SDK currently provides two BeforeCapture callbacks that have limited functionality:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions