feat: Add SentryOptions.AutoSetScopeTransactions to auto-store transactions on the scope - #5317
jamescrosswell wants to merge 2 commits into
Conversation
…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 Report❌ Patch coverage is
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 13637 +25
+ Misses 3869 3867 -2
Partials 872 872 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: James Crosswell <jamescrosswell@users.noreply.github.com>
|
I'm not entirely convinced of this option. This requires such a detailed mental model of the way the SDK handles Spans and Transactions that I don't think this would actually help an actual user. |
Probably more like 2-3 years but yes, it does feel like we're getting closer. I guess we close as won't do for now then and rely on the move to span first to resolve this. We may still require some notion of |
Closes #2399
Closes #5313
What
This is a QOL improvement that adds an opt-in
SentryOptions.AutoSetScopeTransactionsoption (defaults tofalse). When enabled,StartTransactionautomatically stores the started transaction on the current scope, so APIs likeSentrySdk.GetSpan()/StartChild()work without the user having to manually callSentrySdk.ConfigureScope(scope => scope.Transaction = transaction).Since
SentryOptions.AutoSetScopeTransactionsdefaults tofalsethis is opt-in and non-breaking. We could potentially change the default in future major releases though.Per-call override (internal)
StartSpan/StartTransactiongain an internalbool? autoSetScopeTransactionoverride 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 theAutoSetScopeTransactionsoption globally.Note
This changes the MAUI CommunityToolkit binder to finally match its own comment - see #5313