Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Fixes

- Don't start a redundant UI interaction transaction when a transaction is already bound to the Scope ([#5491](https://github.com/getsentry/sentry-java/issues/5491))
- Previously, `SentryGestureListener` always started a UI transaction and only afterwards skipped binding it to the Scope when a manually-bound transaction already existed, leaving the new transaction to be dropped as an idle transaction without children.
- Fix potential NPE within `Scope.endSession()` ([#5657](https://github.com/getsentry/sentry-java/pull/5657))

### Performance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,21 @@ private void startTracing(final @NotNull UiElement target, final @NotNull Gestur
}
}

// if there's already a transaction bound to the Scope (e.g. started manually by the user), we
// skip starting a new UI transaction: it would never be bound to the Scope in applyScope, would
// gather no children, and would be dropped as an idle transaction without children
final @Nullable ITransaction[] boundTransaction = {null};
scopes.configureScope(scope -> boundTransaction[0] = scope.getTransaction());
if (boundTransaction[0] != null) {
options
.getLogger()
.log(
SentryLevel.DEBUG,
"Transaction won't be created for view with id: %s since there's already a transaction bound to the Scope.",
viewIdentifier);
return;
}

// we can only bind to the scope if there's no running transaction
final String name = getActivityName(activity) + "." + viewIdentifier;
final String op = UI_ACTION + "." + getGestureType(eventType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ class SentryGestureListenerTracingTest {
sut.onSingleTapUp(fixture.event)
}

@Test
fun `when a transaction is already bound to the Scope, does not start a new UI transaction`() {
val sut = fixture.getSut<View>()
val boundTransaction = SentryTracer(TransactionContext("bound", "op"), fixture.scopes)
whenever(fixture.scope.transaction).thenReturn(boundTransaction)

sut.onSingleTapUp(fixture.event)

verify(fixture.scopes, never()).startTransaction(any(), any<TransactionOptions>())
assertEquals(false, boundTransaction.isFinished)
}

@Test
fun `stopTracing remove transaction from scope`() {
val sut = fixture.getSut<View>()
Expand Down