Skip to content

Commit fdb3a03

Browse files
adinauerclaude
andcommitted
fix(spring-jakarta): Initialize Sentry in SentryProducerInterceptorTest
TransactionContext constructor requires ScopesAdapter.getOptions() to be non-null for thread checker access. Add initForTest/close to ensure Sentry is properly initialized during tests. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 915e42b commit fdb3a03

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/kafka/SentryProducerInterceptorTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package io.sentry.spring.jakarta.kafka
22

33
import io.sentry.IScopes
4+
import io.sentry.Sentry
45
import io.sentry.SentryOptions
56
import io.sentry.SentryTraceHeader
67
import io.sentry.SentryTracer
78
import io.sentry.TransactionContext
9+
import io.sentry.test.initForTest
810
import java.nio.charset.StandardCharsets
11+
import kotlin.test.AfterTest
912
import kotlin.test.BeforeTest
1013
import kotlin.test.Test
1114
import kotlin.test.assertEquals
@@ -25,6 +28,7 @@ class SentryProducerInterceptorTest {
2528

2629
@BeforeTest
2730
fun setup() {
31+
initForTest { it.dsn = "https://key@sentry.io/proj" }
2832
scopes = mock()
2933
options =
3034
SentryOptions().apply {
@@ -34,6 +38,11 @@ class SentryProducerInterceptorTest {
3438
whenever(scopes.options).thenReturn(options)
3539
}
3640

41+
@AfterTest
42+
fun teardown() {
43+
Sentry.close()
44+
}
45+
3746
private fun createTransaction(): SentryTracer {
3847
val tx = SentryTracer(TransactionContext("tx", "op"), scopes)
3948
whenever(scopes.span).thenReturn(tx)

0 commit comments

Comments
 (0)