Skip to content

Commit

Permalink
Fix: SentryTransaction#finish should not clear another transaction fr…
Browse files Browse the repository at this point in the history
…om the scope (#1278)

Fixes #1269
  • Loading branch information
maciejwalkowiak authored Feb 19, 2021
1 parent 1e7be93 commit 86e9d16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Enchancement: Simplify Sentry configuration in Spring integration (#1259)
* Fix: Fix SentryTransaction#getStatus NPE (#1273)
* Enchancement: Optimize SentryTracingFilter when hub is disabled.
* Fix: SentryTransaction#finish should not clear another transaction from the scope (#1278)

Breaking Changes:
* Enchancement: SentryExceptionResolver should not send handled errors by default (#1248).
Expand Down
5 changes: 4 additions & 1 deletion sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ public void flush(long timeoutMillis) {
e);
} finally {
if (item != null) {
item.getScope().clearTransaction();
final Scope scope = item.getScope();
if (scope.getTransaction() == transaction) {
scope.clearTransaction();
}
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions sentry/src/test/java/io/sentry/HubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1028,18 +1028,38 @@ class HubTest {
}

@Test
fun `when captureTransaction, scope transaction is cleared`() {
fun `when transaction is set on scope, captureTransaction clears it from the scope`() {
val options = SentryOptions()
options.cacheDirPath = file.absolutePath
options.dsn = "https://[email protected]/proj"
options.setSerializer(mock())
val sut = Hub(options)

sut.captureTransaction(SentryTransaction("name", "op"), null)
val transaction = SentryTransaction(TransactionContext("name", "op", true), sut)
sut.configureScope { it.setTransaction(transaction) }
sut.captureTransaction(transaction, null)
sut.configureScope {
assertNull(it.transaction)
}
}

@Test
fun `when different transaction is set on scope, captureTransaction does not clear it from the scope`() {
val options = SentryOptions()
options.cacheDirPath = file.absolutePath
options.dsn = "https://[email protected]/proj"
options.setSerializer(mock())
val sut = Hub(options)

val transaction = SentryTransaction(TransactionContext("name", "op", true), sut)
val anotherTransaction = SentryTransaction(TransactionContext("name", "op", true), sut)
sut.configureScope { it.setTransaction(anotherTransaction) }
sut.captureTransaction(transaction, null)
sut.configureScope {
assertNotNull(it.transaction)
assertEquals(anotherTransaction, it.transaction)
}
}
//endregion

//region startTransaction tests
Expand Down

0 comments on commit 86e9d16

Please sign in to comment.