refactor: do not start redundant UI event transaction when one is already on Scope#5658
Open
mvanhorn wants to merge 1 commit into
Open
refactor: do not start redundant UI event transaction when one is already on Scope#5658mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
SentryGestureListener.startTracing always started a UI transaction and only later, in applyScope, declined to bind it when the Scope already held a manually-bound transaction. The unbound UI transaction then gathered no children and was dropped as an idle transaction. Now we read the Scope's bound transaction first and return early without starting a new one when it is present. Fixes getsentry#5491
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.
📜 Description
SentryGestureListener.startTracingalways calledscopes.startTransaction(...)for a UI interaction and only afterwards, inapplyScope, declined to bind the new transaction to the Scope when one was already bound there. The unbound UI transaction then gathered no children and was dropped as an idle transaction without children.This change reads the Scope's currently bound transaction before building the
TransactionOptions. If a transaction is already bound, it logs a debug message and returns early without starting a new UI transaction. The existing handling for the listener's ownactiveTransaction(reschedule-finish and stop-previous) is unchanged, so only the externally-bound case short-circuits.💡 Motivation and Context
When a user-bound transaction is active, the SDK created and immediately discarded a UI transaction on every interaction. Not starting it avoids that wasted work. See
sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java.Fixes #5491
💚 How did you test it?
Added a unit test in
SentryGestureListenerTracingTestasserting thatscopes.startTransactionis never invoked and the bound transaction is left untouched when a transaction is already on the Scope. Could not run./gradlew :sentry-android-core:testDebugUnitTestlocally because no Java runtime is available in this environment.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
AI was used for assistance.