diff --git a/src/Sentry/Platforms/Unity/SentryEvent.Unity.cs b/src/Sentry/Platforms/Unity/SentryEvent.Unity.cs new file mode 100644 index 0000000000..efbb5b2f34 --- /dev/null +++ b/src/Sentry/Platforms/Unity/SentryEvent.Unity.cs @@ -0,0 +1,15 @@ +#if SENTRY_UNITY + +namespace Sentry; + +public sealed partial class SentryEvent +{ + /// + /// Indicates whether this event was actually captured and sent to Sentry. + /// Used by the Unity SDK's async screenshot capture to avoid sending orphaned attachments. + /// Defaults to false (safe: if unset, attachments are skipped rather than orphaned). + /// + internal bool IsCaptured { get; set; } +} + +#endif diff --git a/src/Sentry/SentryClient.cs b/src/Sentry/SentryClient.cs index d86aa75401..74f961081d 100644 --- a/src/Sentry/SentryClient.cs +++ b/src/Sentry/SentryClient.cs @@ -411,7 +411,14 @@ private SentryId DoSendEvent(SentryEvent @event, SentryHint? hint, Scope? scope) var attachments = hint.Attachments.ToList(); var envelope = Envelope.FromEvent(processedEvent, _options.DiagnosticLogger, attachments, scope.SessionUpdate); - return CaptureEnvelope(envelope) ? processedEvent.EventId : SentryId.Empty; + if (CaptureEnvelope(envelope)) + { +#if SENTRY_UNITY + @event.IsCaptured = true; // See SentryEvent.Unity.cs for more details. +#endif + return processedEvent.EventId; + } + return SentryId.Empty; } private IReadOnlyCollection? ApplyExceptionFilters(Exception? exception) diff --git a/src/Sentry/SentryEvent.cs b/src/Sentry/SentryEvent.cs index c26937cbfc..3a84fa3969 100644 --- a/src/Sentry/SentryEvent.cs +++ b/src/Sentry/SentryEvent.cs @@ -10,7 +10,7 @@ namespace Sentry; /// /// [DebuggerDisplay("{GetType().Name,nq}: {" + nameof(EventId) + ",nq}")] -public sealed class SentryEvent : IEventLike, ISentryJsonSerializable +public sealed partial class SentryEvent : IEventLike, ISentryJsonSerializable { private IDictionary? _modules;