Skip to content

Commit cae0eea

Browse files
authored
Do not overwrite UI transaction status if set by the user (#2852)
1 parent 1faf168 commit cae0eea

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Breaking changes:
99

1010
### Fixes
1111

12+
- Do not overwrite UI transaction status if set by the user ([#2852](https://github.com/getsentry/sentry-java/pull/2852))
13+
1214
Breaking changes:
1315
- Move enableNdk from SentryOptions to SentryAndroidOptions ([#2793](https://github.com/getsentry/sentry-java/pull/2793))
1416

sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,13 @@ private void startTracing(final @NotNull UiElement target, final @NotNull String
255255

256256
void stopTracing(final @NotNull SpanStatus status) {
257257
if (activeTransaction != null) {
258-
activeTransaction.finish(status);
258+
final SpanStatus currentStatus = activeTransaction.getStatus();
259+
// status might be set by other integrations, let's not overwrite it
260+
if (currentStatus == null) {
261+
activeTransaction.finish(status);
262+
} else {
263+
activeTransaction.finish();
264+
}
259265
}
260266
hub.configureScope(
261267
scope -> {

sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import io.sentry.Scope
1414
import io.sentry.ScopeCallback
1515
import io.sentry.SentryTracer
1616
import io.sentry.SpanStatus
17+
import io.sentry.SpanStatus.OUT_OF_RANGE
1718
import io.sentry.TransactionContext
1819
import io.sentry.TransactionOptions
1920
import io.sentry.android.core.SentryAndroidOptions
@@ -323,6 +324,17 @@ class SentryGestureListenerTracingTest {
323324
verify(fixture.transaction).scheduleFinish()
324325
}
325326

327+
@Test
328+
fun `preserves existing transaction status`() {
329+
val sut = fixture.getSut<View>()
330+
331+
sut.onSingleTapUp(fixture.event)
332+
333+
fixture.transaction.status = OUT_OF_RANGE
334+
sut.stopTracing(SpanStatus.CANCELLED)
335+
assertEquals(OUT_OF_RANGE, fixture.transaction.status)
336+
}
337+
326338
internal open class ScrollableListView : AbsListView(mock()) {
327339
override fun getAdapter(): ListAdapter = mock()
328340
override fun setSelection(position: Int) = Unit

0 commit comments

Comments
 (0)