fix: Don't set current thread when one is already there #4681
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Problem
The Sentry SDK for Unity receives stringified stack traces directly from Unity's logging system for error events (see getsentry/sentry-unity#2377). After parsing these stack traces, the Unity SDK sets them on the event as the current thread before passing the event to the .NET SDK for processing.
However,
MainSentryEventProcessoris unconditionally adding a new "current thread" (withCurrent = true) wheneverAttachStacktracewas enabled and no exception stack trace was present.sentry-dotnet/src/Sentry/Internal/MainSentryEventProcessor.cs
Lines 94 to 101 in 396a7ec
This resulted in events having two threads marked as current - the one from Unity with the correct stack trace, and a duplicate one captured by the .NET SDK.
Proposal
Just skip automatic current thread creation if the event already contains a thread with
Current = true. This is not even related to theAttachStackTraceoption as there only ever is one current thread anyway.#skip-changelog