Skip to content

refactor: do not start redundant UI event transaction when one is already on Scope#5658

Open
mvanhorn wants to merge 1 commit into
getsentry:mainfrom
mvanhorn:refactor/5491-skip-redundant-ui-transaction
Open

refactor: do not start redundant UI event transaction when one is already on Scope#5658
mvanhorn wants to merge 1 commit into
getsentry:mainfrom
mvanhorn:refactor/5491-skip-redundant-ui-transaction

Conversation

@mvanhorn

Copy link
Copy Markdown

📜 Description

SentryGestureListener.startTracing always called scopes.startTransaction(...) for a UI interaction and only afterwards, in applyScope, 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 own activeTransaction (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

  • resolves: JAVA-541

💚 How did you test it?

Added a unit test in SentryGestureListenerTracingTest asserting that scopes.startTransaction is never invoked and the bound transaction is left untouched when a transaction is already on the Scope. Could not run ./gradlew :sentry-android-core:testDebugUnitTest locally because no Java runtime is available in this environment.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

AI was used for assistance.

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
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.

Do not start UI event transactions if there already is one on Scope

1 participant