@@ -13,6 +13,8 @@ import io.sentry.IProfileConverter
1313import io.sentry.IScopes
1414import io.sentry.ITransportFactory
1515import io.sentry.Integration
16+ import io.sentry.NoOpContinuousProfiler
17+ import io.sentry.NoOpProfileConverter
1618import io.sentry.NoOpTransportFactory
1719import io.sentry.ProfileLifecycle
1820import io.sentry.SamplingContext
@@ -22,6 +24,8 @@ import io.sentry.SentryIntegrationPackageStorage
2224import io.sentry.SentryLevel
2325import io.sentry.SentryLogEvent
2426import io.sentry.SentryOptions
27+ import io.sentry.asyncprofiler.profiling.JavaContinuousProfiler
28+ import io.sentry.asyncprofiler.provider.AsyncProfilerProfileConverterProvider
2529import io.sentry.checkEvent
2630import io.sentry.clientreport.DiscardReason
2731import io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider
@@ -51,6 +55,7 @@ import kotlin.test.assertFalse
5155import kotlin.test.assertTrue
5256import org.aspectj.lang.ProceedingJoinPoint
5357import org.assertj.core.api.Assertions.assertThat
58+ import org.mockito.internal.util.MockUtil.isMock
5459import org.mockito.kotlin.any
5560import org.mockito.kotlin.anyOrNull
5661import org.mockito.kotlin.mock
@@ -1068,13 +1073,69 @@ class SentryAutoConfigurationTest {
10681073 contextRunner
10691074 .withPropertyValues(
10701075 " sentry.dsn=http://key@localhost/proj" ,
1071- " sentry.traces-sample-rate=1.0" ,
1076+ " sentry.profile-session-sample-rate=1.0" ,
1077+ )
1078+ .run {
1079+ assertThat(it).hasSingleBean(IContinuousProfiler ::class .java)
1080+ assertThat(it).hasSingleBean(IProfileConverter ::class .java)
1081+ assertThat(it)
1082+ .getBean(IProfileConverter ::class .java)
1083+ .isInstanceOf(
1084+ AsyncProfilerProfileConverterProvider .AsyncProfilerProfileConverter ::class .java
1085+ )
1086+ assertThat(it)
1087+ .getBean(IContinuousProfiler ::class .java)
1088+ .isInstanceOf(JavaContinuousProfiler ::class .java)
1089+ assertThat(it)
1090+ .getBean(IProfileConverter ::class .java)
1091+ .isSameAs(Sentry .getGlobalScope().options.profilerConverter)
1092+ assertThat(it)
1093+ .getBean(IContinuousProfiler ::class .java)
1094+ .isSameAs(Sentry .getGlobalScope().options.continuousProfiler)
1095+ }
1096+ }
1097+
1098+ @Test
1099+ fun `when AgentMarker is on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter exist beans are taken from options` () {
1100+ SentryIntegrationPackageStorage .getInstance().clearStorage()
1101+
1102+ contextRunner
1103+ .withPropertyValues(
1104+ " sentry.dsn=http://key@localhost/proj" ,
1105+ " sentry.profile-session-sample-rate=1.0" ,
10721106 " sentry.auto-init=false" ,
10731107 " debug=true" ,
10741108 )
1109+ .withUserConfiguration(CustomProfilerOptionsConfigurationConfiguration ::class .java)
10751110 .run {
1111+ val profiler = it.getBean(IContinuousProfiler ::class .java)
1112+ assertTrue(isMock(profiler))
10761113 assertThat(it).hasSingleBean(IContinuousProfiler ::class .java)
10771114 assertThat(it).hasSingleBean(IProfileConverter ::class .java)
1115+ assertThat(it)
1116+ .getBean(IProfileConverter ::class .java)
1117+ .isSameAs(Sentry .getGlobalScope().options.profilerConverter)
1118+ assertThat(it)
1119+ .getBean(IContinuousProfiler ::class .java)
1120+ .isSameAs(Sentry .getGlobalScope().options.continuousProfiler)
1121+ }
1122+ }
1123+
1124+ @Test
1125+ fun `when AgentMarker is on the classpath and ContinuousProfiling is disabled NoOp Beans are created` () {
1126+ SentryIntegrationPackageStorage .getInstance().clearStorage()
1127+
1128+ contextRunner
1129+ .withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.auto-init=false" )
1130+ .run {
1131+ assertThat(it).hasSingleBean(IContinuousProfiler ::class .java)
1132+ assertThat(it).hasSingleBean(IProfileConverter ::class .java)
1133+ assertThat(it)
1134+ .getBean(IProfileConverter ::class .java)
1135+ .isInstanceOf(NoOpProfileConverter ::class .java)
1136+ assertThat(it)
1137+ .getBean(IContinuousProfiler ::class .java)
1138+ .isInstanceOf(NoOpContinuousProfiler ::class .java)
10781139 }
10791140 }
10801141
@@ -1084,7 +1145,6 @@ class SentryAutoConfigurationTest {
10841145 contextRunner
10851146 .withPropertyValues(
10861147 " sentry.dsn=http://key@localhost/proj" ,
1087- " sentry.traces-sample-rate=1.0" ,
10881148 " sentry.profile-session-sample-rate=1.0" ,
10891149 " debug=true" ,
10901150 )
@@ -1140,6 +1200,17 @@ class SentryAutoConfigurationTest {
11401200 @Bean open fun sentryOptionsConfiguration () = Sentry .OptionsConfiguration <SentryOptions > {}
11411201 }
11421202
1203+ @Configuration(proxyBeanMethods = false )
1204+ open class CustomProfilerOptionsConfigurationConfiguration {
1205+ private val profiler = mock<IContinuousProfiler >()
1206+
1207+ @Bean
1208+ open fun customOptionsConfiguration () =
1209+ Sentry .OptionsConfiguration <SentryOptions > { it.setContinuousProfiler(profiler) }
1210+
1211+ @Bean open fun beforeSendCallback () = CustomBeforeSendCallback ()
1212+ }
1213+
11431214 @Configuration(proxyBeanMethods = false )
11441215 open class MockTransportConfiguration {
11451216
0 commit comments