Skip to content

feat: Add SentryOptions.AutoSetScopeTransactions to auto-store transactions on the scope#5317

Draft
jamescrosswell wants to merge 1 commit into
mainfrom
feat/2399-auto-set-scope-transactions
Draft

feat: Add SentryOptions.AutoSetScopeTransactions to auto-store transactions on the scope#5317
jamescrosswell wants to merge 1 commit into
mainfrom
feat/2399-auto-set-scope-transactions

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Closes #2399
Closes #5313

What

This is a QOL improvement that adds an opt-in SentryOptions.AutoSetScopeTransactions option (defaults to false). When enabled, StartTransaction automatically stores the started transaction on the current scope, so APIs like SentrySdk.GetSpan() / StartChild() work without the user having to manually call SentrySdk.ConfigureScope(scope => scope.Transaction = transaction).

Since SentryOptions.AutoSetScopeTransactions defaults to false this is opt-in and non-breaking. We could potentially change the default in future major releases though.

Per-call override (internal)

StartSpan/StartTransaction gain an internal bool? autoSetScopeTransaction override that wins over the global option, so integrations can control this independently of the user's setting. The MAUI CommunityToolkit binder uses it to ensure we don't store the transaction on the (global, AsyncLocal-backed) scope even when a user enables the AutoSetScopeTransactions option globally.

Note

This changes the MAUI CommunityToolkit binder to finally match its own comment - see #5313

…ctions on the scope

When enabled (opt-in, defaults to false), Hub.StartTransaction automatically
stores the started transaction on the current scope, but only when the scope
does not already have a transaction set - so a transaction set manually or by
another integration is never overwritten. No explicit clearing is needed:
TransactionTracer.Finish already calls Scope.ResetTransaction, which only clears
the scope transaction when it still references that exact instance.

Also adds an internal per-call override (StartSpan/StartTransaction) so
integrations can opt in/out independently of the global option. The MAUI
CommunityToolkit binder uses it to keep its existing behaviour of not storing
the transaction on the (global, AsyncLocal-backed) scope.

Closes #2399

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.21%. Comparing base (f01f273) to head (31d722f).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry/Scope.cs 85.71% 0 Missing and 2 partials ⚠️
...olkit.Mvvm/MauiCommunityToolkitMvvmEventsBinder.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5317      +/-   ##
==========================================
+ Coverage   74.16%   74.21%   +0.04%     
==========================================
  Files         508      508              
  Lines       18353    18376      +23     
  Branches     3586     3589       +3     
==========================================
+ Hits        13612    13638      +26     
+ Misses       3869     3866       -3     
  Partials      872      872              

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant