Skip to content

Commit c3c36b6

Browse files
committed
add condition on JavaContinuousProfiler to be on the classpath to invoke ProfilerAutoConfig
1 parent f04bdbc commit c3c36b6

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

sentry-spring-boot-4/src/main/java/io/sentry/spring/boot4/SentryProfilerAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import org.springframework.context.annotation.Import;
88

99
@Configuration(proxyBeanMethods = false)
10-
@ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"})
10+
@ConditionalOnClass(
11+
name = {
12+
"io.sentry.opentelemetry.agent.AgentMarker",
13+
"io.sentry.asyncprofiler.profiling.JavaContinuousProfiler"
14+
})
1115
@Open
1216
@Import(SentryProfilerConfiguration.class)
1317
public class SentryProfilerAutoConfiguration {}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,22 @@ class SentryAutoConfigurationTest {
11331133
}
11341134
}
11351135

1136+
@Test
1137+
fun `when JavaContinuousProfiler is not on the classpath and ContinuousProfiling is enabled IProfileConverter beans are not created`() {
1138+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1139+
contextRunner
1140+
.withPropertyValues(
1141+
"sentry.dsn=http://key@localhost/proj",
1142+
"sentry.profile-session-sample-rate=1.0",
1143+
"debug=true",
1144+
)
1145+
.withClassLoader(FilteredClassLoader(JavaContinuousProfiler::class.java))
1146+
.run {
1147+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
1148+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
1149+
}
1150+
}
1151+
11361152
@Configuration(proxyBeanMethods = false)
11371153
open class CustomSchedulerFactoryBeanCustomizerConfiguration {
11381154
class MyJobListener : JobListener {

sentry-spring-boot-jakarta/src/main/java/io/sentry/spring/boot/jakarta/SentryProfilerAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import org.springframework.context.annotation.Import;
88

99
@Configuration(proxyBeanMethods = false)
10-
@ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"})
10+
@ConditionalOnClass(
11+
name = {
12+
"io.sentry.opentelemetry.agent.AgentMarker",
13+
"io.sentry.asyncprofiler.profiling.JavaContinuousProfiler"
14+
})
1115
@Open
1216
@Import(SentryProfilerConfiguration.class)
1317
public class SentryProfilerAutoConfiguration {}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,22 @@ class SentryAutoConfigurationTest {
11551155
}
11561156
}
11571157

1158+
@Test
1159+
fun `when JavaContinuousProfiler is not on the classpath and ContinuousProfiling is enabled IProfileConverter beans are not created`() {
1160+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1161+
contextRunner
1162+
.withPropertyValues(
1163+
"sentry.dsn=http://key@localhost/proj",
1164+
"sentry.profile-session-sample-rate=1.0",
1165+
"debug=true",
1166+
)
1167+
.withClassLoader(FilteredClassLoader(JavaContinuousProfiler::class.java))
1168+
.run {
1169+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
1170+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
1171+
}
1172+
}
1173+
11581174
@Configuration(proxyBeanMethods = false)
11591175
open class CustomSchedulerFactoryBeanCustomizerConfiguration {
11601176
class MyJobListener : JobListener {

sentry-spring-boot/src/main/java/io/sentry/spring/boot/SentryProfilerAutoConfiguration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import org.springframework.context.annotation.Import;
88

99
@Configuration(proxyBeanMethods = false)
10-
@ConditionalOnClass(name = {"io.sentry.opentelemetry.agent.AgentMarker"})
10+
@ConditionalOnClass(
11+
name = {
12+
"io.sentry.opentelemetry.agent.AgentMarker",
13+
"io.sentry.asyncprofiler.profiling.JavaContinuousProfiler"
14+
})
1115
@Open
1216
@Import(SentryProfilerConfiguration.class)
1317
public class SentryProfilerAutoConfiguration {}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,22 @@ class SentryAutoConfigurationTest {
10061006
}
10071007
}
10081008

1009+
@Test
1010+
fun `when JavaContinuousProfiler is not on the classpath and ContinuousProfiling is enabled IProfileConverter beans are not created`() {
1011+
SentryIntegrationPackageStorage.getInstance().clearStorage()
1012+
contextRunner
1013+
.withPropertyValues(
1014+
"sentry.dsn=http://key@localhost/proj",
1015+
"sentry.profile-session-sample-rate=1.0",
1016+
"debug=true",
1017+
)
1018+
.withClassLoader(FilteredClassLoader(JavaContinuousProfiler::class.java))
1019+
.run {
1020+
assertThat(it).doesNotHaveBean(IContinuousProfiler::class.java)
1021+
assertThat(it).doesNotHaveBean(IProfileConverter::class.java)
1022+
}
1023+
}
1024+
10091025
@Test
10101026
fun `creates quartz config`() {
10111027
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj").run {

0 commit comments

Comments
 (0)