Skip to content

Commit a619788

Browse files
authored
POTEL 54 - Cleanup (#3861)
* Auto config for Spring Boot combined with OTel but without agent * try to cleanup otel classloader * make agent, no agent and agent without auto init work for spring boot * Fix ignored instrumentation for OTel without agent; separate sample for no agent * fix test result upload on CI * automatically detect otel and use OtelSpanFactory * POTEL 54 cleanup
1 parent b795cb4 commit a619788

File tree

7 files changed

+93
-85
lines changed

7 files changed

+93
-85
lines changed

buildSrc/src/main/java/Config.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ object Config {
9494
val springBoot3StarterSecurity = "org.springframework.boot:spring-boot-starter-security:$springBoot3Version"
9595
val springBoot3StarterJdbc = "org.springframework.boot:spring-boot-starter-jdbc:$springBoot3Version"
9696
val springBoot3StarterActuator = "org.springframework.boot:spring-boot-starter-actuator:$springBoot3Version"
97-
val springBoot3StarterOpenTelemetry = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter:${OpenTelemetry.otelJavaagentVersion}"
97+
val springBoot3StarterOpenTelemetry = "io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter:${OpenTelemetry.otelInstrumentationVersion}"
9898

9999
val springWeb = "org.springframework:spring-webmvc"
100100
val springWebflux = "org.springframework:spring-webflux"
@@ -158,17 +158,18 @@ object Config {
158158
object OpenTelemetry {
159159
val otelVersion = "1.41.0"
160160
val otelAlphaVersion = "$otelVersion-alpha"
161-
val otelJavaagentVersion = "2.7.0"
162-
val otelJavaagentAlphaVersion = "$otelJavaagentVersion-alpha"
161+
val otelInstrumentationVersion = "2.7.0"
162+
val otelInstrumentationAlphaVersion = "$otelInstrumentationVersion-alpha"
163163
val otelSemanticConvetionsVersion = "1.25.0-alpha" // check https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/dependencyManagement/build.gradle.kts#L49 for release version above to find a compatible version
164164

165165
val otelSdk = "io.opentelemetry:opentelemetry-sdk:$otelVersion"
166166
val otelSemconv = "io.opentelemetry.semconv:opentelemetry-semconv:$otelSemanticConvetionsVersion"
167167
val otelSemconvIncubating = "io.opentelemetry.semconv:opentelemetry-semconv-incubating:$otelSemanticConvetionsVersion"
168-
val otelJavaAgent = "io.opentelemetry.javaagent:opentelemetry-javaagent:$otelJavaagentVersion"
169-
val otelJavaAgentExtensionApi = "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:$otelJavaagentAlphaVersion"
170-
val otelJavaAgentTooling = "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:$otelJavaagentAlphaVersion"
168+
val otelJavaAgent = "io.opentelemetry.javaagent:opentelemetry-javaagent:$otelInstrumentationVersion"
169+
val otelJavaAgentExtensionApi = "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:$otelInstrumentationAlphaVersion"
170+
val otelJavaAgentTooling = "io.opentelemetry.javaagent:opentelemetry-javaagent-tooling:$otelInstrumentationAlphaVersion"
171171
val otelExtensionAutoconfigureSpi = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:$otelVersion"
172+
val otelExtensionAutoconfigure = "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:$otelVersion"
172173
}
173174
}
174175

sentry-opentelemetry/sentry-opentelemetry-agent/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@ tasks {
151151
attributes.put("Can-Redefine-Classes", "true")
152152
attributes.put("Can-Retransform-Classes", "true")
153153
attributes.put("Implementation-Vendor", "Sentry")
154-
attributes.put("Implementation-Version", "sentry-${project.version}-otel-${Config.Libs.OpenTelemetry.otelJavaagentVersion}")
154+
attributes.put("Implementation-Version", "sentry-${project.version}-otel-${Config.Libs.OpenTelemetry.otelInstrumentationVersion}")
155155
attributes.put("Sentry-Version-Name", project.version)
156156
attributes.put("Sentry-Opentelemetry-SDK-Name", Config.Sentry.SENTRY_OPENTELEMETRY_AGENT_SDK_NAME)
157157
attributes.put("Sentry-Opentelemetry-Version-Name", Config.Libs.OpenTelemetry.otelVersion)
158-
attributes.put("Sentry-Opentelemetry-Javaagent-Version-Name", Config.Libs.OpenTelemetry.otelJavaagentVersion)
158+
attributes.put("Sentry-Opentelemetry-Javaagent-Version-Name", Config.Libs.OpenTelemetry.otelInstrumentationVersion)
159159
}
160160
}
161161

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/java/io/sentry/samples/spring/boot/jakarta/CustomJob.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.sentry.spring.jakarta.tracing.SentryTransaction;
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
7+
import org.springframework.scheduling.annotation.Scheduled;
78
import org.springframework.stereotype.Component;
89

910
/**
@@ -17,7 +18,7 @@ public class CustomJob {
1718
private static final Logger LOGGER = LoggerFactory.getLogger(CustomJob.class);
1819

1920
@SentryCheckIn("monitor_slug_1")
20-
// @Scheduled(fixedRate = 3 * 60 * 1000L)
21+
@Scheduled(fixedRate = 3 * 60 * 1000L)
2122
void execute() throws InterruptedException {
2223
LOGGER.info("Executing scheduled job");
2324
Thread.sleep(2000L);

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/java/io/sentry/samples/spring/boot/jakarta/PersonController.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public PersonController(PersonService personService, OpenTelemetry openTelemetry
3131
@GetMapping("{id}")
3232
@WithSpan("personSpanThroughOtelAnnotation")
3333
Person person(@PathVariable Long id) {
34-
ISpan annotationSpan = Sentry.getSpan();
35-
System.out.println(annotationSpan);
3634
Span span =
3735
openTelemetry
3836
.getTracer("tracerForSpringBootDemo")

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry-noagent/src/main/java/io/sentry/samples/spring/boot/jakarta/SentryDemoApplication.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package io.sentry.samples.spring.boot.jakarta;
22

3+
import static io.sentry.quartz.SentryJobListener.SENTRY_SLUG_KEY;
4+
35
import io.opentelemetry.api.OpenTelemetry;
46
import io.opentelemetry.api.trace.Tracer;
7+
import io.sentry.samples.spring.boot.jakarta.quartz.SampleJob;
8+
import java.util.Collections;
9+
import org.quartz.JobDetail;
10+
import org.quartz.SimpleTrigger;
511
import org.springframework.boot.SpringApplication;
612
import org.springframework.boot.autoconfigure.SpringBootApplication;
713
import org.springframework.boot.web.client.RestTemplateBuilder;
814
import org.springframework.context.annotation.Bean;
915
import org.springframework.scheduling.annotation.EnableScheduling;
16+
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
17+
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
18+
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
1019
import org.springframework.web.client.RestClient;
1120
import org.springframework.web.client.RestTemplate;
1221
import org.springframework.web.reactive.function.client.WebClient;
@@ -33,41 +42,34 @@ RestClient restClient(RestClient.Builder builder) {
3342
return builder.build();
3443
}
3544

36-
// @Bean
37-
// public JobDetailFactoryBean jobDetail() {
38-
// JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
39-
// jobDetailFactory.setJobClass(SampleJob.class);
40-
// jobDetailFactory.setDurability(true);
41-
// jobDetailFactory.setJobDataAsMap(
42-
// Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_job_detail"));
43-
// return jobDetailFactory;
44-
// }
45-
//
46-
// @Bean
47-
// public SimpleTriggerFactoryBean trigger(JobDetail job) {
48-
// SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
49-
// trigger.setJobDetail(job);
50-
// trigger.setRepeatInterval(2 * 60 * 1000); // every two minutes
51-
// trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
52-
// trigger.setJobDataAsMap(
53-
// Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_simple_trigger"));
54-
// return trigger;
55-
// }
56-
//
57-
// @Bean
58-
// public CronTriggerFactoryBean cronTrigger(JobDetail job) {
59-
// CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
60-
// trigger.setJobDetail(job);
61-
// trigger.setCronExpression("0 0/5 * ? * *"); // every five minutes
62-
// return trigger;
63-
// }
45+
@Bean
46+
public JobDetailFactoryBean jobDetail() {
47+
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
48+
jobDetailFactory.setJobClass(SampleJob.class);
49+
jobDetailFactory.setDurability(true);
50+
jobDetailFactory.setJobDataAsMap(
51+
Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_job_detail"));
52+
return jobDetailFactory;
53+
}
54+
55+
@Bean
56+
public SimpleTriggerFactoryBean trigger(JobDetail job) {
57+
SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
58+
trigger.setJobDetail(job);
59+
trigger.setRepeatInterval(2 * 60 * 1000); // every two minutes
60+
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
61+
trigger.setJobDataAsMap(
62+
Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_simple_trigger"));
63+
return trigger;
64+
}
6465

65-
// @Bean
66-
// public Tracer getTracer(OpenTelemetry openTelemetry) {
67-
// GlobalOpenTelemetry.set(openTelemetry);
68-
// return openTelemetry.getTracer("tracerForSpringBootDemo");
69-
//// return GlobalOpenTelemetry.getTracer("tracerForSpringBootDemo");
70-
// }
66+
@Bean
67+
public CronTriggerFactoryBean cronTrigger(JobDetail job) {
68+
CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
69+
trigger.setJobDetail(job);
70+
trigger.setCronExpression("0 0/5 * ? * *"); // every five minutes
71+
return trigger;
72+
}
7173

7274
@Bean
7375
public Tracer tracer(OpenTelemetry openTelemetry) {

sentry-samples/sentry-samples-spring-boot-jakarta-opentelemetry/src/main/java/io/sentry/samples/spring/boot/jakarta/SentryDemoApplication.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package io.sentry.samples.spring.boot.jakarta;
22

3+
import static io.sentry.quartz.SentryJobListener.SENTRY_SLUG_KEY;
4+
35
import io.opentelemetry.api.GlobalOpenTelemetry;
46
import io.opentelemetry.api.trace.Tracer;
7+
import io.sentry.samples.spring.boot.jakarta.quartz.SampleJob;
8+
import java.util.Collections;
9+
import org.quartz.JobDetail;
10+
import org.quartz.SimpleTrigger;
511
import org.springframework.boot.SpringApplication;
612
import org.springframework.boot.autoconfigure.SpringBootApplication;
713
import org.springframework.boot.web.client.RestTemplateBuilder;
814
import org.springframework.context.annotation.Bean;
915
import org.springframework.scheduling.annotation.EnableScheduling;
16+
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
17+
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
18+
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
1019
import org.springframework.web.client.RestClient;
1120
import org.springframework.web.client.RestTemplate;
1221
import org.springframework.web.reactive.function.client.WebClient;
@@ -33,41 +42,34 @@ RestClient restClient(RestClient.Builder builder) {
3342
return builder.build();
3443
}
3544

36-
// @Bean
37-
// public JobDetailFactoryBean jobDetail() {
38-
// JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
39-
// jobDetailFactory.setJobClass(SampleJob.class);
40-
// jobDetailFactory.setDurability(true);
41-
// jobDetailFactory.setJobDataAsMap(
42-
// Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_job_detail"));
43-
// return jobDetailFactory;
44-
// }
45-
//
46-
// @Bean
47-
// public SimpleTriggerFactoryBean trigger(JobDetail job) {
48-
// SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
49-
// trigger.setJobDetail(job);
50-
// trigger.setRepeatInterval(2 * 60 * 1000); // every two minutes
51-
// trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
52-
// trigger.setJobDataAsMap(
53-
// Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_simple_trigger"));
54-
// return trigger;
55-
// }
56-
//
57-
// @Bean
58-
// public CronTriggerFactoryBean cronTrigger(JobDetail job) {
59-
// CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
60-
// trigger.setJobDetail(job);
61-
// trigger.setCronExpression("0 0/5 * ? * *"); // every five minutes
62-
// return trigger;
63-
// }
45+
@Bean
46+
public JobDetailFactoryBean jobDetail() {
47+
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
48+
jobDetailFactory.setJobClass(SampleJob.class);
49+
jobDetailFactory.setDurability(true);
50+
jobDetailFactory.setJobDataAsMap(
51+
Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_job_detail"));
52+
return jobDetailFactory;
53+
}
54+
55+
@Bean
56+
public SimpleTriggerFactoryBean trigger(JobDetail job) {
57+
SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
58+
trigger.setJobDetail(job);
59+
trigger.setRepeatInterval(2 * 60 * 1000); // every two minutes
60+
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
61+
trigger.setJobDataAsMap(
62+
Collections.singletonMap(SENTRY_SLUG_KEY, "monitor_slug_simple_trigger"));
63+
return trigger;
64+
}
6465

65-
// @Bean
66-
// public Tracer getTracer(OpenTelemetry openTelemetry) {
67-
// GlobalOpenTelemetry.set(openTelemetry);
68-
// return openTelemetry.getTracer("tracerForSpringBootDemo");
69-
//// return GlobalOpenTelemetry.getTracer("tracerForSpringBootDemo");
70-
// }
66+
@Bean
67+
public CronTriggerFactoryBean cronTrigger(JobDetail job) {
68+
CronTriggerFactoryBean trigger = new CronTriggerFactoryBean();
69+
trigger.setJobDetail(job);
70+
trigger.setCronExpression("0 0/5 * ? * *"); // every five minutes
71+
return trigger;
72+
}
7173

7274
@Bean
7375
public Tracer tracer() {

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ class SentryAutoConfigurationTest {
748748
SentryIntegrationPackageStorage.getInstance().clearStorage()
749749
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.auto-init=false")
750750
.run {
751-
println(SentryIntegrationPackageStorage.getInstance().integrations)
752751
assertTrue(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryAgentWithoutAutoInit"))
753752
}
754753
}
@@ -758,7 +757,6 @@ class SentryAutoConfigurationTest {
758757
SentryIntegrationPackageStorage.getInstance().clearStorage()
759758
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
760759
.run {
761-
println(SentryIntegrationPackageStorage.getInstance().integrations)
762760
assertFalse(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryAgentWithoutAutoInit"))
763761
}
764762
}
@@ -769,7 +767,6 @@ class SentryAutoConfigurationTest {
769767
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.auto-init=false")
770768
.withClassLoader(FilteredClassLoader(AgentMarker::class.java))
771769
.run {
772-
println(SentryIntegrationPackageStorage.getInstance().integrations)
773770
assertFalse(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryAgentWithoutAutoInit"))
774771
}
775772
}
@@ -781,7 +778,6 @@ class SentryAutoConfigurationTest {
781778
.withClassLoader(FilteredClassLoader(AgentMarker::class.java))
782779
.withUserConfiguration(OtelBeanConfig::class.java)
783780
.run {
784-
println(SentryIntegrationPackageStorage.getInstance().integrations)
785781
assertTrue(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryNoAgent"))
786782
}
787783
}
@@ -792,7 +788,6 @@ class SentryAutoConfigurationTest {
792788
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
793789
.withClassLoader(FilteredClassLoader(AgentMarker::class.java, OpenTelemetry::class.java))
794790
.run {
795-
println(SentryIntegrationPackageStorage.getInstance().integrations)
796791
assertFalse(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryNoAgent"))
797792
}
798793
}
@@ -804,11 +799,20 @@ class SentryAutoConfigurationTest {
804799
.withClassLoader(FilteredClassLoader(AgentMarker::class.java, SentryAutoConfigurationCustomizerProvider::class.java))
805800
.withUserConfiguration(OtelBeanConfig::class.java)
806801
.run {
807-
println(SentryIntegrationPackageStorage.getInstance().integrations)
808802
assertFalse(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryNoAgent"))
809803
}
810804
}
811805

806+
@Test
807+
fun `when AgentMarker is not on the classpath and auto init on, does not run SentryOpenTelemetryAgentWithoutAutoInitConfiguration`() {
808+
SentryIntegrationPackageStorage.getInstance().clearStorage()
809+
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj")
810+
.withClassLoader(FilteredClassLoader(AgentMarker::class.java))
811+
.run {
812+
assertFalse(SentryIntegrationPackageStorage.getInstance().integrations.contains("SpringBoot3OpenTelemetryAgentWithoutAutoInit"))
813+
}
814+
}
815+
812816
@Test
813817
fun `creates quartz config`() {
814818
contextRunner.withPropertyValues("sentry.dsn=http://key@localhost/proj", "sentry.enable-automatic-checkins=true")

0 commit comments

Comments
 (0)