diff --git a/CHANGELOG.md b/CHANGELOG.md index 044e94dcdb..9e2655c8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fix: Make the ANR Atomic flags immutable * Enchancement: Integration interface better compatibility with Kotlin null-safety * Enchancement: Simplify Sentry configuration in Spring integration (#1259) +* Fix: Fix SentryTransaction#getStatus NPE (#1273) * Enchancement: Optimize SentryTracingFilter when hub is disabled. Breaking Changes: diff --git a/sentry/src/main/java/io/sentry/SentryTransaction.java b/sentry/src/main/java/io/sentry/SentryTransaction.java index 45e3356599..7cff259a63 100644 --- a/sentry/src/main/java/io/sentry/SentryTransaction.java +++ b/sentry/src/main/java/io/sentry/SentryTransaction.java @@ -238,7 +238,7 @@ Date getTimestamp() { @Override @Nullable public SpanStatus getStatus() { - return this.getContexts().getTrace().getStatus(); + return context.getStatus(); } @Override diff --git a/sentry/src/test/java/io/sentry/SentryTransactionTest.kt b/sentry/src/test/java/io/sentry/SentryTransactionTest.kt index 7309a9275b..9a6440ccfb 100644 --- a/sentry/src/test/java/io/sentry/SentryTransactionTest.kt +++ b/sentry/src/test/java/io/sentry/SentryTransactionTest.kt @@ -167,4 +167,17 @@ class SentryTransactionTest { transaction.name = "new name" assertEquals("new name", transaction.transaction) } + + @Test + fun `when transaction is not finished, status is null`() { + val transaction = SentryTransaction("name", "op") + assertNull(transaction.status) + } + + @Test + fun `when transaction is not finished, status can be read`() { + val transaction = SentryTransaction("name", "op") + transaction.status = SpanStatus.ABORTED + assertEquals(SpanStatus.ABORTED, transaction.status) + } }