Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Sentry/Platforms/Unity/SentryEvent.Unity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if SENTRY_UNITY

namespace Sentry;

public sealed partial class SentryEvent
{
/// <summary>
Comment thread
JoshuaMoelans marked this conversation as resolved.
/// 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).
/// </summary>
internal bool IsCaptured { get; set; }
}

#endif
9 changes: 8 additions & 1 deletion src/Sentry/SentryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +416 to +418
Copy link
Copy Markdown
Member

@Flash0ver Flash0ver Apr 27, 2026

Choose a reason for hiding this comment

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

@jamescrosswell is this "pattern" alright?

(adding a member via src/Sentry/Platforms/Unity/SentryEvent.Unity.cs partial type,
and using it here conditionally)

Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell Apr 27, 2026

Choose a reason for hiding this comment

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

It's nice and simple. The only alternative I can think of is that Unity could register a UnityEventProcessor that did this... I'm not sure that's easier to read/maintain though unless Unity starts to do quite complex special processing of these events.

Copy link
Copy Markdown
Member

@Flash0ver Flash0ver Apr 28, 2026

Choose a reason for hiding this comment

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

I'm not quite positive that this would work reliably, as there might be

  • other Event-Processors dropping the Event
  • a user's Before-Send dropping the Event
  • Sampling of the Event
  • the Backpressure-Monitor influencing the Sampling decision
  • or the Background-Worker's queue being full

sentry-unity might provide it's own ISentryClient though, which is

  • wrapping the default sentry-unity SentryClient
  • wrapping a potential user client (SentrySdk.BindClient(ISentryClient))
  • attaching "fused" data to SentryEvent

So that it's a 100 % sentry-unity-owned solution.

See also getsentry/sentry-unity#2642: "Future Ideas"

return processedEvent.EventId;
}
return SentryId.Empty;
}

private IReadOnlyCollection<Exception>? ApplyExceptionFilters(Exception? exception)
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/SentryEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Sentry;
/// </summary>
/// <seealso href="https://develop.sentry.dev/sdk/event-payloads/" />
[DebuggerDisplay("{GetType().Name,nq}: {" + nameof(EventId) + ",nq}")]
public sealed class SentryEvent : IEventLike, ISentryJsonSerializable
public sealed partial class SentryEvent : IEventLike, ISentryJsonSerializable
{
private IDictionary<string, string>? _modules;

Expand Down
Loading