feat: Add SentryOptions.AutoSetScopeTransactions to auto-store transactions on the scope#5317
Draft
jamescrosswell wants to merge 1 commit into
Draft
feat: Add SentryOptions.AutoSetScopeTransactions to auto-store transactions on the scope#5317jamescrosswell wants to merge 1 commit into
jamescrosswell wants to merge 1 commit 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 13638 +26
+ Misses 3869 3866 -3
Partials 872 872 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
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