diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d05f1bfc..2376590a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ Breaking changes: ### Fixes +- Do not overwrite UI transaction status if set by the user ([#2852](https://github.com/getsentry/sentry-java/pull/2852)) + Breaking changes: - Move enableNdk from SentryOptions to SentryAndroidOptions ([#2793](https://github.com/getsentry/sentry-java/pull/2793)) diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java index 3dda6183cd..17b62eb319 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java @@ -255,7 +255,13 @@ private void startTracing(final @NotNull UiElement target, final @NotNull String void stopTracing(final @NotNull SpanStatus status) { if (activeTransaction != null) { - activeTransaction.finish(status); + final SpanStatus currentStatus = activeTransaction.getStatus(); + // status might be set by other integrations, let's not overwrite it + if (currentStatus == null) { + activeTransaction.finish(status); + } else { + activeTransaction.finish(); + } } hub.configureScope( scope -> { diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt index 5f216a660a..41776e495a 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/internal/gestures/SentryGestureListenerTracingTest.kt @@ -14,6 +14,7 @@ import io.sentry.Scope import io.sentry.ScopeCallback import io.sentry.SentryTracer import io.sentry.SpanStatus +import io.sentry.SpanStatus.OUT_OF_RANGE import io.sentry.TransactionContext import io.sentry.TransactionOptions import io.sentry.android.core.SentryAndroidOptions @@ -323,6 +324,17 @@ class SentryGestureListenerTracingTest { verify(fixture.transaction).scheduleFinish() } + @Test + fun `preserves existing transaction status`() { + val sut = fixture.getSut() + + sut.onSingleTapUp(fixture.event) + + fixture.transaction.status = OUT_OF_RANGE + sut.stopTracing(SpanStatus.CANCELLED) + assertEquals(OUT_OF_RANGE, fixture.transaction.status) + } + internal open class ScrollableListView : AbsListView(mock()) { override fun getAdapter(): ListAdapter = mock() override fun setSelection(position: Int) = Unit