Skip to content

Commit d180c19

Browse files
committed
add test for auto profiler config
1 parent c02c3dd commit d180c19

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

sentry-spring-boot-4/src/test/kotlin/io/sentry/spring/boot4/SentryAutoConfigurationTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import io.sentry.Breadcrumb
77
import io.sentry.EventProcessor
88
import io.sentry.FilterString
99
import io.sentry.Hint
10+
import io.sentry.IContinuousProfiler
11+
import io.sentry.IProfileConverter
1012
import io.sentry.IScopes
1113
import io.sentry.ITransportFactory
1214
import io.sentry.Integration
@@ -87,6 +89,7 @@ class SentryAutoConfigurationTest {
8789
AutoConfigurations.of(
8890
SentryAutoConfiguration::class.java,
8991
WebMvcAutoConfiguration::class.java,
92+
SentryProfilerAutoConfiguration::class.java,
9093
)
9194
)
9295

@@ -1037,6 +1040,39 @@ class SentryAutoConfigurationTest {
10371040
}
10381041
}
10391042

1043+
@Test
1044+
fun `when AgentMarker is on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are created and set on options`() {
1045+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1046+
contextRunner
1047+
.withPropertyValues(
1048+
"sentry.dsn=http://key@localhost/proj",
1049+
"sentry.traces-sample-rate=1.0",
1050+
"sentry.auto-init=false",
1051+
"debug=true",
1052+
)
1053+
.run {
1054+
assertThat(it).hasSingleBean(IContinuousProfiler::class.java)
1055+
assertThat(it).hasSingleBean(IProfileConverter::class.java)
1056+
}
1057+
}
1058+
1059+
@Test
1060+
fun `when AgentMarker is not on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are not created`() {
1061+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1062+
contextRunner
1063+
.withPropertyValues(
1064+
"sentry.dsn=http://key@localhost/proj",
1065+
"sentry.traces-sample-rate=1.0",
1066+
"sentry.profile-session-sample-rate=1.0",
1067+
"debug=true",
1068+
)
1069+
.withClassLoader(FilteredClassLoader(AgentMarker::class.java, OpenTelemetry::class.java))
1070+
.run {
1071+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
1072+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
1073+
}
1074+
}
1075+
10401076
@Configuration(proxyBeanMethods = false)
10411077
open class CustomSchedulerFactoryBeanCustomizerConfiguration {
10421078
class MyJobListener : JobListener {

sentry-spring-boot-jakarta/src/test/kotlin/io/sentry/spring/boot/jakarta/SentryAutoConfigurationTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import io.sentry.DataCategory
88
import io.sentry.EventProcessor
99
import io.sentry.FilterString
1010
import io.sentry.Hint
11+
import io.sentry.IContinuousProfiler
12+
import io.sentry.IProfileConverter
1113
import io.sentry.IScopes
1214
import io.sentry.ITransportFactory
1315
import io.sentry.Integration
@@ -91,6 +93,7 @@ class SentryAutoConfigurationTest {
9193
AutoConfigurations.of(
9294
SentryAutoConfiguration::class.java,
9395
WebMvcAutoConfiguration::class.java,
96+
SentryProfilerAutoConfiguration::class.java,
9497
)
9598
)
9699

@@ -1059,6 +1062,39 @@ class SentryAutoConfigurationTest {
10591062
}
10601063
}
10611064

1065+
@Test
1066+
fun `when AgentMarker is on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are created and set on options`() {
1067+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1068+
contextRunner
1069+
.withPropertyValues(
1070+
"sentry.dsn=http://key@localhost/proj",
1071+
"sentry.traces-sample-rate=1.0",
1072+
"sentry.auto-init=false",
1073+
"debug=true",
1074+
)
1075+
.run {
1076+
assertThat(it).hasSingleBean(IContinuousProfiler::class.java)
1077+
assertThat(it).hasSingleBean(IProfileConverter::class.java)
1078+
}
1079+
}
1080+
1081+
@Test
1082+
fun `when AgentMarker is not on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are not created`() {
1083+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1084+
contextRunner
1085+
.withPropertyValues(
1086+
"sentry.dsn=http://key@localhost/proj",
1087+
"sentry.traces-sample-rate=1.0",
1088+
"sentry.profile-session-sample-rate=1.0",
1089+
"debug=true",
1090+
)
1091+
.withClassLoader(FilteredClassLoader(AgentMarker::class.java, OpenTelemetry::class.java))
1092+
.run {
1093+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
1094+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
1095+
}
1096+
}
1097+
10621098
@Configuration(proxyBeanMethods = false)
10631099
open class CustomSchedulerFactoryBeanCustomizerConfiguration {
10641100
class MyJobListener : JobListener {

sentry-spring-boot/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import io.sentry.DataCategory
88
import io.sentry.EventProcessor
99
import io.sentry.FilterString
1010
import io.sentry.Hint
11+
import io.sentry.IContinuousProfiler
12+
import io.sentry.IProfileConverter
1113
import io.sentry.IScopes
1214
import io.sentry.ITransportFactory
1315
import io.sentry.Integration
@@ -90,6 +92,7 @@ class SentryAutoConfigurationTest {
9092
AutoConfigurations.of(
9193
SentryAutoConfiguration::class.java,
9294
WebMvcAutoConfiguration::class.java,
95+
SentryProfilerAutoConfiguration::class.java,
9396
)
9497
)
9598

@@ -910,6 +913,39 @@ class SentryAutoConfigurationTest {
910913
}
911914
}
912915

916+
@Test
917+
fun `when AgentMarker is on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are created and set on options`() {
918+
SentryIntegrationPackageStorage.getInstance().clearStorage()
919+
contextRunner
920+
.withPropertyValues(
921+
"sentry.dsn=http://key@localhost/proj",
922+
"sentry.traces-sample-rate=1.0",
923+
"sentry.auto-init=false",
924+
"debug=true",
925+
)
926+
.run {
927+
assertThat(it).hasSingleBean(IContinuousProfiler::class.java)
928+
assertThat(it).hasSingleBean(IProfileConverter::class.java)
929+
}
930+
}
931+
932+
@Test
933+
fun `when AgentMarker is not on the classpath and ContinuousProfiling is enabled IContinuousProfiler and IProfileConverter beans are not created`() {
934+
SentryIntegrationPackageStorage.getInstance().clearStorage()
935+
contextRunner
936+
.withPropertyValues(
937+
"sentry.dsn=http://key@localhost/proj",
938+
"sentry.traces-sample-rate=1.0",
939+
"sentry.profile-session-sample-rate=1.0",
940+
"debug=true",
941+
)
942+
.withClassLoader(FilteredClassLoader(AgentMarker::class.java, OpenTelemetry::class.java))
943+
.run {
944+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
945+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
946+
}
947+
}
948+
913949
@Test
914950
fun `creates quartz config`() {
915951
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {

0 commit comments

Comments
 (0)