feat: Allow IScopeObserver to observe trace#4026
Merged
jamescrosswell merged 10 commits intomainfrom Apr 2, 2025
Merged
Conversation
Contributor
|
bruno-garcia
reviewed
Mar 8, 2025
bitsandfoxes
commented
Mar 28, 2025
77cfd29 to
2df0cd9
Compare
bruno-garcia
approved these changes
Apr 1, 2025
Member
bruno-garcia
left a comment
There was a problem hiding this comment.
I'm approving to unblock but give @jamescrosswell and @aritchie a chance to review this if they have time in the next day or two unless you need this out there asap
|
|
||
| public void SetTrace(SentryId traceId, SpanId parentSpanId) | ||
| { | ||
| // TODO: This requires sentry-java 8.4.0 |
Member
There was a problem hiding this comment.
Do we need to follow up later with this once this is added to the Java and Apple SDKs?
If so ideally we create a ticket so folks here can add it later
This was referenced Sep 8, 2025
This was referenced Sep 15, 2025
This was referenced Oct 6, 2025
This was referenced Oct 20, 2025
This was referenced Nov 3, 2025
This was referenced Dec 8, 2025
This was referenced Dec 15, 2025
This was referenced Jan 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Currently, errors on different layers - i.e. Unity C# -> Java -> C/C++ are not connected via trace ID. The Java and the native SDK allow for Hybrid SDKs to
SetTrace(SentryId traceId, SpanId parentSpanId). From the Unity SDK's point of view, there is no mechanism right now that allows the .NET SDK to automatically propagate the trace to the native layers.Proposal
Since the trace is held on the scope's PropagationContext we can leverage the already existing TwP functionality. Additionally, we can use the
IScopeObserverto "observe" the relevantTraceIDandParentSpanID.Allow the Unity SDK to
SetTraceThere are multiple ways I can think of achieving this:
MakePropagationContextpublicAdd an accessors to theScopeto update the `PropagationContextAdd anInternalSentrySdkclass where we can putSetTrace(and other things that regular users are not supposed to go). We have similar solutions likePrivateSentrySDKOnlyfor Cocoa andInternalSentrySdkin Java.InternalsVisibletoSentry.Unity.Update the
IScopeObserverThis
IScopeObservercan then be implemented by the respective native scope observer on the Unity SDK.getsentry/sentry-unity#1997
This will also work for Android and iOS when building MAUI apps since. We'll just have to bump the native SDKs there.
Result
Unity SDK
The end result looks like this

.NET SDK
This also works on platforms where the .NET SDK brings support via
sentry-native.Since the SDK also has observers for iOS and Android, once those SDKs are updated, it'll work there as well.
Context
Relates to getsentry/sentry-unity#1997
Relevant change to
sentry-java: getsentry/sentry-java#4137Relevant change to
sentry-native: getsentry/sentry-native#1137