Skip to content

Conversation

@bitsandfoxes
Copy link
Contributor

Problem Description

When a transaction gets finished it also resets itself on the scope. This triggers a "manual" scope sync to the native layer. After finishing a transaction the PropagationContext get renewed to keep new events from having an old trace context.
The SDK syncs the trace in immediate succession, overwriting itself every time.

Context

The logs are taken from a Unity game but should apply to anywhere there is a transaction that gets finished

Sentry: (Info) Finishing 'app.start' transaction. 
Sentry: (Debug) Attempting to finish Transaction d84ad5b1214e4d44. 
Sentry: (Debug) Finished Transaction d84ad5b1214e4d44. 
Sentry: (Debug) macOS Scope Sync - Setting Trace traceId:d968c8c94a7241e8b9873018d1302e4a spanId:5eba0d6fe7261f58 
Sentry: (Debug) macOS Scope Sync - Setting Trace traceId:bd2de9eb0db946819f59251e313c6471 spanId:e0b7994a40178a9c 

After a transaction gets finished it gets reset on the Scope and afterwards the PropagationContext gets regenerated so that new events don't have a trace context older than the just finished transaction. We even point this out in the comments.

There are two places the transaction gets reset on the scope:

  • UnsampledTransaction
    // Clear the transaction from the scope and regenerate the Propagation Context, so new events don't have a
    // trace context that is "older" than the transaction that just finished
    _hub.ConfigureScope(static (scope, transactionTracer) =>
    {
    scope.ResetTransaction(transactionTracer);
    scope.SetPropagationContext(new SentryPropagationContext());
    }, this);
  • TransactionTracer
    // Clear the transaction from the scope and regenerate the Propagation Context
    // We do this so new events don't have a trace context that is "older" than the transaction that just finished
    _hub.ConfigureScope(static (scope, transactionTracer) =>
    {
    scope.ResetTransaction(transactionTracer);
    scope.SetPropagationContext(new SentryPropagationContext());
    }, this);

Proposal

The SDK does not need to manually restore the trace context on the native layer, as it gets overwritten basically in the next line.

@codecov
Copy link

codecov bot commented Oct 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (version6@a213de0). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             version6    #4623   +/-   ##
===========================================
  Coverage            ?   73.08%           
===========================================
  Files               ?      479           
  Lines               ?    17381           
  Branches            ?     3430           
===========================================
  Hits                ?    12703           
  Misses              ?     3819           
  Partials            ?      859           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@jamescrosswell jamescrosswell left a comment

Choose a reason for hiding this comment

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

Nice! Thanks @bitsandfoxes ❤️

@jamescrosswell jamescrosswell merged commit 7b1b32e into version6 Oct 12, 2025
30 checks passed
@jamescrosswell jamescrosswell deleted the fix/do-not-sync-transaction-reset-v6 branch October 12, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants