Skip to content

fix(unity): update SentryEvent to have IsCaptured to allow dropping screenshots of filtered events#5162

Open
JoshuaMoelans wants to merge 4 commits intomainfrom
joshua/fix/unity_screenshot_handling
Open

fix(unity): update SentryEvent to have IsCaptured to allow dropping screenshots of filtered events#5162
JoshuaMoelans wants to merge 4 commits intomainfrom
joshua/fix/unity_screenshot_handling

Conversation

@JoshuaMoelans
Copy link
Copy Markdown
Member

As suggested in getsentry/sentry-unity#2642 , we add a flag so we can read from it during the CaptureScreenshotCoroutine. We gate it behind #if SENTRY_UNITY to not expose it for the other .NET SDK consumers.


As described in the 'Future Ideas' section of the unity PR, at some point we might want to provide sentry-unity with a wrapper ISentryClient which can overwrite methods, to avoid needing changes in .NET for unity specific stuff like we need to do in this PR.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.06%. Comparing base (cd3f966) to head (75f83b8).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5162   +/-   ##
=======================================
  Coverage   74.05%   74.06%           
=======================================
  Files         501      501           
  Lines       18111    18113    +2     
  Branches     3521     3521           
=======================================
+ Hits        13413    13415    +2     
  Misses       3838     3838           
  Partials      860      860           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/Sentry/SentryClient.cs Outdated
Comment thread src/Sentry/SentryClient.cs Outdated
if (CaptureEnvelope(envelope))
{
#if SENTRY_UNITY
@event.WasCaptured = true; // See SentryEvent.unity.cs for more details.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thought: alternative

As an alternative, we could use our "Fused-Data" infrastructure, based on ConditionalWeakTable<,>.

e.g.

/* here */
@event.SetFused(new EnvelopeCaptureStatus(true));

/* in sentry-dotnet's ScreenshotEventProcessor */
if (a.GetFused<EnvelopeCaptureStatus>() is { IsCaptured: true })
{
    // Data found in CWT ... process and capture screenshot
}
else
{
    // no Data found in CWT ... stop processing the screenshot
}

/* new file in src/Sentry/Platforms/Unity/ */
#if SENTRY_UNITY

namespace Sentry.Internal;

internal sealed class EnvelopeCaptureStatus
{
    public EnvelopeCaptureStatus(bool isCaptured)
    {
        IsCaptured = isCaptured;
    }

    public bool IsCaptured { get; }
}

#endif

But to be fair ... now after manifesting this thought,
the "physical" property is just as good,
since it's internal and Unity-only anyway,
and also more navigable within an IDE.

I'd still like to hear feedback, though 😉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm yeah that is an option, but I'm a bit more drawn towards the (maybe less elegant-) simpler "physical" property solution for now. Since it doesn't introduce any potential future breakage of a public API, it'll be easy to replace it with something better at relatively low maintenance cost in the meantime.

Comment thread src/Sentry/Platforms/Unity/SentryEvent.Unity.cs
Comment thread src/Sentry/Platforms/Unity/SentryEvent.Unity.cs Outdated
@Flash0ver Flash0ver marked this pull request as ready for review April 23, 2026 15:35
@JoshuaMoelans JoshuaMoelans changed the title fix(unity): update SentryEvent to have WasCaptured to allow dropping screenshots of filtered events fix(unity): update SentryEvent to have IsCaptured to allow dropping screenshots of filtered events Apr 24, 2026
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.

3 participants