Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SentryTransactionAdvice should operate on the new scope. #1389

Merged
merged 3 commits into from
Apr 12, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Enhancement: Make NoOpHub public (#1379)
* Fix: Do not bind transactions to scope by default. (#1376)
* Fix: fix Hub thread safety (#1388)
* Fix: SentryTransactionAdvice should operate on the new scope (#1389)

# 4.4.0-alpha.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ public Object invoke(final @NotNull MethodInvocation invocation) throws Throwabl
} else {
operation = "bean";
}
hub.pushScope();
final ITransaction transaction = hub.startTransaction(name, operation, true);
try {
return invocation.proceed();
} finally {
transaction.finish();
hub.popScope();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.nhaarman.mockitokotlin2.any
import com.nhaarman.mockitokotlin2.check
import com.nhaarman.mockitokotlin2.eq
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.reset
import com.nhaarman.mockitokotlin2.times
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
Expand Down Expand Up @@ -42,6 +43,7 @@ class SentryTransactionAdviceTest {

@BeforeTest
fun setup() {
reset(hub)
whenever(hub.startTransaction(any<String>(), any(), eq(true))).thenAnswer { io.sentry.SentryTracer(TransactionContext(it.arguments[0] as String, it.arguments[1] as String), hub) }
}

Expand Down Expand Up @@ -94,6 +96,18 @@ class SentryTransactionAdviceTest {
})
}

@Test
fun `pushes the scope when advice starts`() {
classAnnotatedSampleService.hello()
verify(hub).pushScope()
}

@Test
fun `pops the scope when advice finishes`() {
classAnnotatedSampleService.hello()
verify(hub).popScope()
}

@Configuration
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Import(SentryTracingConfiguration::class)
Expand Down