Skip to content

Commit 11bff06

Browse files
authored
Merge branch 'feat/otel-span-strongref' into feat/agentless-spring-module
2 parents 63080b1 + 8833fc9 commit 11bff06

File tree

28 files changed

+222
-111
lines changed

28 files changed

+222
-111
lines changed

sentry-android-core/src/test/java/io/sentry/android/core/InternalSentrySdkTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class InternalSentrySdkTest {
5555
lateinit var options: SentryOptions
5656

5757
fun init(context: Context) {
58-
SentryAndroid.init(context) { options ->
58+
initForTest(context) { options ->
5959
this@Fixture.options = options
6060
options.dsn = "https://key@host/proj"
6161
options.setTransportFactory { _, _ ->

sentry-android-core/src/test/java/io/sentry/android/core/SentryAndroidTest.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import io.sentry.Hint
1515
import io.sentry.ILogger
1616
import io.sentry.ISentryClient
1717
import io.sentry.Sentry
18+
import io.sentry.Sentry.OptionsConfiguration
1819
import io.sentry.SentryEnvelope
1920
import io.sentry.SentryLevel
2021
import io.sentry.SentryLevel.DEBUG
@@ -40,6 +41,8 @@ import io.sentry.cache.PersistingScopeObserver
4041
import io.sentry.cache.PersistingScopeObserver.BREADCRUMBS_FILENAME
4142
import io.sentry.cache.PersistingScopeObserver.SCOPE_CACHE
4243
import io.sentry.cache.PersistingScopeObserver.TRANSACTION_FILENAME
44+
import io.sentry.test.applyTestOptions
45+
import io.sentry.test.initForTest
4346
import io.sentry.transport.NoOpEnvelopeCache
4447
import io.sentry.util.StringUtils
4548
import org.awaitility.kotlin.await
@@ -100,9 +103,9 @@ class SentryAndroidTest {
100103
}
101104
val mockContext = context ?: ContextUtilsTestHelper.mockMetaData(metaData = metadata)
102105
when {
103-
logger != null -> SentryAndroid.init(mockContext, logger)
104-
options != null -> SentryAndroid.init(mockContext, options)
105-
else -> SentryAndroid.init(mockContext)
106+
logger != null -> initForTest(mockContext, logger)
107+
options != null -> initForTest(mockContext, options)
108+
else -> initForTest(mockContext)
106109
}
107110
}
108111

@@ -290,7 +293,7 @@ class SentryAndroidTest {
290293

291294
val mockContext = ContextUtilsTestHelper.createMockContext(true)
292295
val cacheDirPath = Files.createTempDirectory("new_cache").absolutePathString()
293-
SentryAndroid.init(mockContext) {
296+
initForTest(mockContext) {
294297
it.dsn = "https://[email protected]/123"
295298
it.cacheDirPath = cacheDirPath
296299
options = it
@@ -354,7 +357,7 @@ class SentryAndroidTest {
354357
@Test
355358
fun `When initializing Sentry a callback is added to application by appStartMetrics`() {
356359
val mockContext = ContextUtilsTestHelper.createMockContext(true)
357-
SentryAndroid.init(mockContext) {
360+
initForTest(mockContext) {
358361
it.dsn = "https://[email protected]/123"
359362
}
360363
verify(mockContext.applicationContext as Application).registerActivityLifecycleCallbacks(eq(AppStartMetrics.getInstance()))
@@ -368,7 +371,7 @@ class SentryAndroidTest {
368371
Mockito.mockStatic(ContextUtils::class.java, Mockito.CALLS_REAL_METHODS).use { mockedContextUtils ->
369372
mockedContextUtils.`when`<Any> { ContextUtils.isForegroundImportance() }
370373
.thenReturn(inForeground)
371-
SentryAndroid.init(context) { options ->
374+
initForTest(context) { options ->
372375
options.release = "prod"
373376
options.dsn = "https://[email protected]/123"
374377
options.isEnableAutoSessionTracking = true
@@ -558,3 +561,18 @@ class SentryAndroidTest {
558561
override fun discard(envelope: SentryEnvelope) = Unit
559562
}
560563
}
564+
565+
fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration<SentryAndroidOptions>) {
566+
SentryAndroid.init(context) {
567+
applyTestOptions(it)
568+
optionsConfiguration.configure(it)
569+
}
570+
}
571+
572+
fun initForTest(context: Context, logger: ILogger) {
573+
SentryAndroid.init(context, logger)
574+
}
575+
576+
fun initForTest(context: Context) {
577+
SentryAndroid.init(context)
578+
}

sentry-android-core/src/test/java/io/sentry/android/core/SentryLogcatAdapterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class SentryLogcatAdapterTest {
3030
}
3131
val mockContext = ContextUtilsTestHelper.mockMetaData(metaData = metadata)
3232
when {
33-
options != null -> SentryAndroid.init(mockContext, options)
34-
else -> SentryAndroid.init(mockContext)
33+
options != null -> initForTest(mockContext, options)
34+
else -> initForTest(mockContext)
3535
}
3636
}
3737
}

sentry-android-core/src/test/java/io/sentry/android/core/SessionTrackingIntegrationTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class SessionTrackingIntegrationTest {
4444
@Test
4545
fun `session tracking works properly with multiple backgrounds and foregrounds`() {
4646
lateinit var options: SentryAndroidOptions
47-
SentryAndroid.init(context) {
47+
initForTest(context) {
4848
it.dsn = "https://[email protected]/proj"
4949
it.release = "[email protected]"
5050
it.environment = "production"

sentry-android-integration-tests/sentry-uitest-android-benchmark/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ dependencies {
9999
errorprone(Config.CompileOnly.errorprone)
100100
errorprone(Config.CompileOnly.errorProneNullAway)
101101

102+
androidTestImplementation(projects.sentryTestSupport)
102103
androidTestImplementation(Config.TestLibs.kotlinTestJunit)
103104
androidTestImplementation(Config.TestLibs.espressoCore)
104105
androidTestImplementation(Config.TestLibs.androidxTestCoreKtx)

sentry-android-integration-tests/sentry-uitest-android-benchmark/src/androidTest/java/io/sentry/uitest/android/benchmark/SentryBenchmarkTest.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.sentry.uitest.android.benchmark
22

3+
import android.content.Context
34
import android.os.Bundle
45
import androidx.lifecycle.Lifecycle
56
import androidx.test.core.app.launchActivity
@@ -12,8 +13,11 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
1213
import androidx.test.runner.AndroidJUnitRunner
1314
import io.sentry.ITransaction
1415
import io.sentry.Sentry
16+
import io.sentry.Sentry.OptionsConfiguration
1517
import io.sentry.SentryOptions
1618
import io.sentry.android.core.SentryAndroid
19+
import io.sentry.android.core.SentryAndroidOptions
20+
import io.sentry.test.applyTestOptions
1721
import io.sentry.uitest.android.benchmark.util.BenchmarkOperation
1822
import org.junit.runner.RunWith
1923
import kotlin.test.AfterTest
@@ -62,7 +66,7 @@ class SentryBenchmarkTest : BaseBenchmarkTest() {
6266
choreographer,
6367
before = {
6468
runner.runOnMainSync {
65-
SentryAndroid.init(context) { options: SentryOptions ->
69+
initForTest(context) { options: SentryOptions ->
6670
options.dsn = "https://key@uri/1234567"
6771
options.tracesSampleRate = 1.0
6872
options.profilesSampleRate = 1.0
@@ -127,3 +131,10 @@ class SentryBenchmarkTest : BaseBenchmarkTest() {
127131
}
128132
}
129133
}
134+
135+
fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration<SentryAndroidOptions>) {
136+
SentryAndroid.init(context) {
137+
applyTestOptions(it)
138+
optionsConfiguration.configure(it)
139+
}
140+
}

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/BaseUiTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import androidx.test.espresso.idling.CountingIdlingResource
99
import androidx.test.platform.app.InstrumentationRegistry
1010
import androidx.test.runner.AndroidJUnitRunner
1111
import io.sentry.Sentry
12+
import io.sentry.Sentry.OptionsConfiguration
1213
import io.sentry.android.core.SentryAndroid
1314
import io.sentry.android.core.SentryAndroidOptions
15+
import io.sentry.test.applyTestOptions
16+
import io.sentry.test.initForTest
1417
import io.sentry.uitest.android.mockservers.MockRelay
1518
import java.io.FileInputStream
1619
import java.util.concurrent.TimeUnit
@@ -84,7 +87,7 @@ abstract class BaseUiTest {
8487
if (relayWaitForRequests) {
8588
IdlingRegistry.getInstance().register(relayIdlingResource)
8689
}
87-
SentryAndroid.init(context) {
90+
initForTest(context) {
8891
it.dsn = mockDsn
8992
it.isDebug = true
9093
// We don't use test orchestrator, due to problems with Saucelabs.
@@ -111,3 +114,10 @@ fun classExists(className: String): Boolean {
111114
}
112115
return false
113116
}
117+
118+
fun initForTest(context: Context, optionsConfiguration: OptionsConfiguration<SentryAndroidOptions>) {
119+
SentryAndroid.init(context) {
120+
applyTestOptions(it)
121+
optionsConfiguration.configure(it)
122+
}
123+
}

sentry-android-replay/src/test/java/io/sentry/android/replay/AnrWithReplayIntegrationTest.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.sentry.SentryReplayEvent
1616
import io.sentry.SentryReplayEvent.ReplayType
1717
import io.sentry.SystemOutLogger
1818
import io.sentry.android.core.SentryAndroid
19+
import io.sentry.android.core.SentryAndroidOptions
1920
import io.sentry.android.core.performance.AppStartMetrics
2021
import io.sentry.android.replay.ReplayCache.Companion.ONGOING_SEGMENT
2122
import io.sentry.android.replay.ReplayCache.Companion.SEGMENT_KEY_BIT_RATE
@@ -32,6 +33,7 @@ import io.sentry.protocol.Contexts
3233
import io.sentry.protocol.SentryId
3334
import io.sentry.rrweb.RRWebMetaEvent
3435
import io.sentry.rrweb.RRWebVideoEvent
36+
import io.sentry.test.applyTestOptions
3537
import org.awaitility.kotlin.await
3638
import org.awaitility.kotlin.withAlias
3739
import org.junit.Rule
@@ -146,7 +148,7 @@ class AnrWithReplayIntegrationTest {
146148
val replayId1 = SentryId()
147149
val replayId2 = SentryId()
148150

149-
SentryAndroid.init(context) {
151+
initForTest(context) {
150152
it.dsn = "https://[email protected]/123"
151153
it.cacheDirPath = cacheDir
152154
it.isDebug = true
@@ -216,3 +218,10 @@ class AnrWithReplayIntegrationTest {
216218
.untilTrue(asserted)
217219
}
218220
}
221+
222+
fun initForTest(context: Context, optionsConfiguration: Sentry.OptionsConfiguration<SentryAndroidOptions>) {
223+
SentryAndroid.init(context) {
224+
applyTestOptions(it)
225+
optionsConfiguration.configure(it)
226+
}
227+
}

sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.sentry.Sentry
55
import io.sentry.SentryLevel
66
import io.sentry.SentryOptions
77
import io.sentry.checkEvent
8+
import io.sentry.test.initForTest
89
import io.sentry.transport.ITransport
910
import org.mockito.kotlin.anyOrNull
1011
import org.mockito.kotlin.mock
@@ -60,7 +61,7 @@ class SentryHandlerTest {
6061
@Test
6162
fun `does not initialize Sentry if Sentry is already enabled with higher prio`() {
6263
val transport = mock<ITransport>()
63-
Sentry.init {
64+
initForTest {
6465
it.dsn = "http://key@localhost/proj"
6566
it.environment = "manual-environment"
6667
it.setTransportFactory { _, _ -> transport }

sentry-kotlin-extensions/src/test/java/io/sentry/kotlin/SentryContextTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.sentry.kotlin
22

33
import io.sentry.ScopeType
44
import io.sentry.Sentry
5+
import io.sentry.test.initForTest
56
import kotlinx.coroutines.CoroutineName
67
import kotlinx.coroutines.joinAll
78
import kotlinx.coroutines.launch
@@ -22,7 +23,7 @@ class SentryContextTest {
2223

2324
@BeforeTest
2425
fun init() {
25-
Sentry.init("https://[email protected]/123")
26+
initForTest("https://[email protected]/123")
2627
}
2728

2829
@AfterTest

sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter
66
import io.sentry.Sentry
77
import io.sentry.SentryLevel
88
import io.sentry.checkEvent
9+
import io.sentry.test.initForTest
910
import io.sentry.transport.ITransport
1011
import org.apache.logging.log4j.Level
1112
import org.apache.logging.log4j.LogManager
@@ -84,7 +85,7 @@ class SentryAppenderTest {
8485

8586
@Test
8687
fun `does not initialize Sentry if Sentry is already enabled with higher prio`() {
87-
Sentry.init {
88+
initForTest {
8889
it.dsn = "http://key@localhost/proj"
8990
it.environment = "manual-environment"
9091
it.setTransportFactory(fixture.transportFactory)

sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.sentry.Sentry
1313
import io.sentry.SentryLevel
1414
import io.sentry.SentryOptions
1515
import io.sentry.checkEvent
16+
import io.sentry.test.initForTest
1617
import io.sentry.transport.ITransport
1718
import org.mockito.kotlin.any
1819
import org.mockito.kotlin.anyOrNull
@@ -96,7 +97,7 @@ class SentryAppenderTest {
9697
it.setTag("only-present-if-logger-init-was-run", "another-value")
9798
}
9899
)
99-
Sentry.init {
100+
initForTest {
100101
it.dsn = "http://key@localhost/proj"
101102
it.environment = "manual-environment"
102103
it.setTransportFactory(fixture.transportFactory)

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/SentryTaskDecoratorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.spring.jakarta
22

33
import io.sentry.Sentry
4+
import io.sentry.test.initForTest
45
import java.util.concurrent.ExecutorService
56
import java.util.concurrent.Executors
67
import kotlin.test.AfterTest
@@ -26,7 +27,7 @@ class SentryTaskDecoratorTest {
2627

2728
@Test
2829
fun `scopes is reset to its state within the thread after decoration is done`() {
29-
Sentry.init {
30+
initForTest {
3031
it.dsn = dsn
3132
}
3233

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryScheduleHookTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.spring.jakarta.webflux
22

33
import io.sentry.Sentry
4+
import io.sentry.test.initForTest
45
import java.util.concurrent.ExecutorService
56
import java.util.concurrent.Executors
67
import kotlin.test.AfterTest
@@ -27,7 +28,7 @@ class SentryScheduleHookTest {
2728

2829
@Test
2930
fun `scopes is reset to its state within the thread after hook is done`() {
30-
Sentry.init {
31+
initForTest {
3132
it.dsn = dsn
3233
}
3334

sentry-spring-jakarta/src/test/kotlin/io/sentry/spring/jakarta/webflux/SentryWebfluxIntegrationTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter
66
import io.sentry.Sentry
77
import io.sentry.checkEvent
88
import io.sentry.checkTransaction
9+
import io.sentry.test.initForTest
910
import io.sentry.transport.ITransport
1011
import org.assertj.core.api.Assertions.assertThat
1112
import org.awaitility.kotlin.await
@@ -175,7 +176,7 @@ open class App {
175176

176177
@Bean
177178
open fun sentryInitializer(transportFactory: ITransportFactory) = ApplicationRunner {
178-
Sentry.init {
179+
initForTest {
179180
it.dsn = "http://key@localhost/proj"
180181
it.setDebug(true)
181182
it.setTransportFactory(transportFactory)

sentry-spring/src/test/kotlin/io/sentry/spring/SentryTaskDecoratorTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.spring
22

33
import io.sentry.Sentry
4+
import io.sentry.test.initForTest
45
import java.util.concurrent.ExecutorService
56
import java.util.concurrent.Executors
67
import kotlin.test.AfterTest
@@ -26,7 +27,7 @@ class SentryTaskDecoratorTest {
2627

2728
@Test
2829
fun `scopes is reset to its state within the thread after decoration is done`() {
29-
Sentry.init {
30+
initForTest {
3031
it.dsn = dsn
3132
}
3233

sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryScheduleHookTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.spring.webflux
22

33
import io.sentry.Sentry
4+
import io.sentry.test.initForTest
45
import java.util.concurrent.ExecutorService
56
import java.util.concurrent.Executors
67
import kotlin.test.AfterTest
@@ -27,7 +28,7 @@ class SentryScheduleHookTest {
2728

2829
@Test
2930
fun `scopes is reset to its state within the thread after hook is done`() {
30-
Sentry.init {
31+
initForTest {
3132
it.dsn = dsn
3233
}
3334

sentry-spring/src/test/kotlin/io/sentry/spring/webflux/SentryWebfluxIntegrationTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.sentry.ScopesAdapter
66
import io.sentry.Sentry
77
import io.sentry.checkEvent
88
import io.sentry.checkTransaction
9+
import io.sentry.test.initForTest
910
import io.sentry.transport.ITransport
1011
import org.assertj.core.api.Assertions.assertThat
1112
import org.awaitility.kotlin.await
@@ -175,7 +176,7 @@ open class App {
175176

176177
@Bean
177178
open fun sentryInitializer(transportFactory: ITransportFactory) = ApplicationRunner {
178-
Sentry.init {
179+
initForTest {
179180
it.dsn = "http://key@localhost/proj"
180181
it.setDebug(true)
181182
it.setTransportFactory(transportFactory)

0 commit comments

Comments
 (0)