11package io.sentry.spring.boot
22
33import com.acme.MainBootClass
4+ import io.opentelemetry.api.OpenTelemetry
45import io.sentry.AsyncHttpTransportFactory
56import io.sentry.Breadcrumb
67import io.sentry.EventProcessor
@@ -12,10 +13,12 @@ import io.sentry.NoOpTransportFactory
1213import io.sentry.SamplingContext
1314import io.sentry.Sentry
1415import io.sentry.SentryEvent
16+ import io.sentry.SentryIntegrationPackageStorage
1517import io.sentry.SentryLevel
1618import io.sentry.SentryOptions
1719import io.sentry.checkEvent
18- import io.sentry.opentelemetry.OpenTelemetryLinkErrorEventProcessor
20+ import io.sentry.opentelemetry.SentryAutoConfigurationCustomizerProvider
21+ import io.sentry.opentelemetry.agent.AgentMarker
1922import io.sentry.protocol.SentryTransaction
2023import io.sentry.protocol.User
2124import io.sentry.quartz.SentryJobListener
@@ -727,43 +730,72 @@ class SentryAutoConfigurationTest {
727730 }
728731
729732 @Test
730- fun `when OpenTelemetryLinkErrorEventProcessor is on the classpath and auto init off, creates OpenTelemetryLinkErrorEventProcessor` () {
733+ fun `when AgentMarker is on the classpath and auto init off, runs SentryOpenTelemetryAgentWithoutAutoInitConfiguration` () {
734+ SentryIntegrationPackageStorage .getInstance().clearStorage()
731735 contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.auto-init=false" )
732736 .run {
733- assertThat(it).hasSingleBean(OpenTelemetryLinkErrorEventProcessor ::class .java)
734- val options = it.getBean(SentryOptions ::class .java)
735- assertThat(options.eventProcessors).anyMatch { processor -> processor.javaClass == OpenTelemetryLinkErrorEventProcessor ::class .java }
737+ assertTrue(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryAgentWithoutAutoInit" ))
736738 }
737739 }
738740
739741 @Test
740- fun `when OpenTelemetryLinkErrorEventProcessor is on the classpath but auto init on, does not create OpenTelemetryLinkErrorEventProcessor` () {
741- contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.auto-init=true" )
742+ fun `when AgentMarker is on the classpath and auto init on, does not run SentryOpenTelemetryAgentWithoutAutoInitConfiguration` () {
743+ SentryIntegrationPackageStorage .getInstance().clearStorage()
744+ contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
742745 .run {
743- assertThat(it).doesNotHaveBean(OpenTelemetryLinkErrorEventProcessor ::class .java)
744- val options = it.getBean(SentryOptions ::class .java)
745- assertThat(options.eventProcessors).noneMatch { processor -> processor.javaClass == OpenTelemetryLinkErrorEventProcessor ::class .java }
746+ assertFalse(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryAgentWithoutAutoInit" ))
746747 }
747748 }
748749
749750 @Test
750- fun `when OpenTelemetryLinkErrorEventProcessor is on the classpath but auto init default, does not create OpenTelemetryLinkErrorEventProcessor` () {
751+ fun `when AgentMarker is not on the classpath and auto init off, does not run SentryOpenTelemetryAgentWithoutAutoInitConfiguration` () {
752+ SentryIntegrationPackageStorage .getInstance().clearStorage()
753+ contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.auto-init=false" )
754+ .withClassLoader(FilteredClassLoader (AgentMarker ::class .java))
755+ .run {
756+ assertFalse(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryAgentWithoutAutoInit" ))
757+ }
758+ }
759+
760+ @Test
761+ fun `when AgentMarker is not on the classpath but OpenTelemetry is, runs SpringBoot3OpenTelemetryNoAgent` () {
762+ SentryIntegrationPackageStorage .getInstance().clearStorage()
751763 contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
764+ .withClassLoader(FilteredClassLoader (AgentMarker ::class .java))
765+ .withUserConfiguration(OtelBeanConfig ::class .java)
752766 .run {
753- assertThat(it).doesNotHaveBean(OpenTelemetryLinkErrorEventProcessor ::class .java)
754- val options = it.getBean(SentryOptions ::class .java)
755- assertThat(options.eventProcessors).noneMatch { processor -> processor.javaClass == OpenTelemetryLinkErrorEventProcessor ::class .java }
767+ assertTrue(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryNoAgent" ))
756768 }
757769 }
758770
759771 @Test
760- fun `when OpenTelemetryLinkErrorEventProcessor is not on the classpath, does not create OpenTelemetryLinkErrorEventProcessor` () {
761- contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" , " sentry.auto-init=false" )
762- .withClassLoader(FilteredClassLoader (OpenTelemetryLinkErrorEventProcessor ::class .java))
772+ fun `when AgentMarker and OpenTelemetry are not on the classpath, does not run SpringBoot3OpenTelemetryNoAgent` () {
773+ SentryIntegrationPackageStorage .getInstance().clearStorage()
774+ contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
775+ .withClassLoader(FilteredClassLoader (AgentMarker ::class .java, OpenTelemetry ::class .java))
763776 .run {
764- assertThat(it).doesNotHaveBean(OpenTelemetryLinkErrorEventProcessor ::class .java)
765- val options = it.getBean(SentryOptions ::class .java)
766- assertThat(options.eventProcessors).noneMatch { processor -> processor.javaClass == OpenTelemetryLinkErrorEventProcessor ::class .java }
777+ assertFalse(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryNoAgent" ))
778+ }
779+ }
780+
781+ @Test
782+ fun `when AgentMarker and SentryAutoConfigurationCustomizerProvider are not on the classpath, does not run SpringBoot3OpenTelemetryNoAgent` () {
783+ SentryIntegrationPackageStorage .getInstance().clearStorage()
784+ contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
785+ .withClassLoader(FilteredClassLoader (AgentMarker ::class .java, SentryAutoConfigurationCustomizerProvider ::class .java))
786+ .withUserConfiguration(OtelBeanConfig ::class .java)
787+ .run {
788+ assertFalse(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryNoAgent" ))
789+ }
790+ }
791+
792+ @Test
793+ fun `when AgentMarker is not on the classpath and auto init on, does not run SentryOpenTelemetryAgentWithoutAutoInitConfiguration` () {
794+ SentryIntegrationPackageStorage .getInstance().clearStorage()
795+ contextRunner.withPropertyValues(" sentry.dsn=http://key@localhost/proj" )
796+ .withClassLoader(FilteredClassLoader (AgentMarker ::class .java))
797+ .run {
798+ assertFalse(SentryIntegrationPackageStorage .getInstance().integrations.contains(" SpringBoot3OpenTelemetryAgentWithoutAutoInit" ))
767799 }
768800 }
769801
@@ -1013,6 +1045,16 @@ class SentryAutoConfigurationTest {
10131045 override fun sample (samplingContext : SamplingContext ) = 1.0
10141046 }
10151047
1048+ /* *
1049+ * this should be taken care of by the otel spring starter in a real application
1050+ */
1051+ @Configuration
1052+ open class OtelBeanConfig {
1053+
1054+ @Bean
1055+ open fun openTelemetry () = OpenTelemetry .noop()
1056+ }
1057+
10161058 open class CustomSentryUserProvider : SentryUserProvider {
10171059 override fun provideUser (): User ? {
10181060 val user = User ()
0 commit comments