Skip to content

Commit a2318ff

Browse files
fix(unity): update SentryEvent to have IsCaptured to allow dropping screenshots of filtered events (#5162)
* Update SentryEvent to have WasCaptured on Unity * Format code * apply suggestions from code review --------- Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
1 parent e12435d commit a2318ff

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#if SENTRY_UNITY
2+
3+
namespace Sentry;
4+
5+
public sealed partial class SentryEvent
6+
{
7+
/// <summary>
8+
/// Indicates whether this event was actually captured and sent to Sentry.
9+
/// Used by the Unity SDK's async screenshot capture to avoid sending orphaned attachments.
10+
/// Defaults to false (safe: if unset, attachments are skipped rather than orphaned).
11+
/// </summary>
12+
internal bool IsCaptured { get; set; }
13+
}
14+
15+
#endif

src/Sentry/SentryClient.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,14 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope)
411411

412412
var attachments = hint.Attachments.ToList();
413413
var envelope = Envelope.FromEvent(processedEvent, _options.DiagnosticLogger, attachments, scope.SessionUpdate);
414-
return CaptureEnvelope(envelope) ? processedEvent.EventId : SentryId.Empty;
414+
if (CaptureEnvelope(envelope))
415+
{
416+
#if SENTRY_UNITY
417+
@event.IsCaptured = true; // See SentryEvent.Unity.cs for more details.
418+
#endif
419+
return processedEvent.EventId;
420+
}
421+
return SentryId.Empty;
415422
}
416423

417424
private IReadOnlyCollection<Exception>? ApplyExceptionFilters(Exception? exception)

src/Sentry/SentryEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Sentry;
1010
/// </summary>
1111
/// <seealso href="https://develop.sentry.dev/sdk/event-payloads/" />
1212
[DebuggerDisplay("{GetType().Name,nq}: {" + nameof(EventId) + ",nq}")]
13-
public sealed class SentryEvent : IEventLike, ISentryJsonSerializable
13+
public sealed partial class SentryEvent : IEventLike, ISentryJsonSerializable
1414
{
1515
private IDictionary<string, string>? _modules;
1616

0 commit comments

Comments
 (0)