+
+
+ io.quarkus
+ quarkus-scheduler-parent
+ 999-SNAPSHOT
+
+ 4.0.0
+
+ quarkus-scheduler-spi
+ Quarkus - Scheduler - SPI
+
+
+
+ io.quarkus
+ quarkus-scheduler-api
+
+
+
diff --git a/extensions/scheduler/spi/src/main/java/io/quarkus/scheduler/spi/JobInstrumenter.java b/extensions/scheduler/spi/src/main/java/io/quarkus/scheduler/spi/JobInstrumenter.java
new file mode 100644
index 0000000000000..d6df78b5691c8
--- /dev/null
+++ b/extensions/scheduler/spi/src/main/java/io/quarkus/scheduler/spi/JobInstrumenter.java
@@ -0,0 +1,23 @@
+package io.quarkus.scheduler.spi;
+
+import java.util.concurrent.CompletionStage;
+
+/**
+ * Instruments a scheduled job.
+ *
+ * Telemetry extensions can provide exactly one CDI bean of this type. The scope must be either {@link jakarta.inject.Singleton}
+ * or {@link jakarta.enterprise.context.ApplicationScoped}.
+ */
+public interface JobInstrumenter {
+
+ CompletionStage instrument(JobInstrumentationContext context);
+
+ interface JobInstrumentationContext {
+
+ String getSpanName();
+
+ CompletionStage executeJob();
+
+ }
+
+}
diff --git a/integration-tests/opentelemetry-quartz/pom.xml b/integration-tests/opentelemetry-quartz/pom.xml
new file mode 100644
index 0000000000000..006bac75a7f1f
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/pom.xml
@@ -0,0 +1,144 @@
+
+
+
+ quarkus-integration-tests-parent
+ io.quarkus
+ 999-SNAPSHOT
+
+ 4.0.0
+
+ quarkus-integration-test-opentelemetry-quartz
+ Quarkus - Integration Tests - OpenTelemetry Quartz
+
+
+
+ io.quarkus
+ quarkus-arc
+
+
+ io.quarkus
+ quarkus-resteasy-reactive
+
+
+ io.quarkus
+ quarkus-quartz
+
+
+ io.quarkus
+ quarkus-opentelemetry
+
+
+ io.quarkus
+ quarkus-resteasy-reactive-jackson
+
+
+
+
+ io.opentelemetry
+ opentelemetry-sdk-testing
+
+
+
+
+ io.quarkus
+ quarkus-junit5
+ test
+
+
+ io.rest-assured
+ rest-assured
+ test
+
+
+ org.awaitility
+ awaitility
+ test
+
+
+
+ io.quarkus
+ quarkus-arc-deployment
+ ${project.version}
+ pom
+ test
+
+
+ *
+ *
+
+
+
+
+ io.quarkus
+ quarkus-quartz-deployment
+ ${project.version}
+ pom
+ test
+
+
+ *
+ *
+
+
+
+
+ io.quarkus
+ quarkus-resteasy-reactive-deployment
+ ${project.version}
+ pom
+ test
+
+
+ *
+ *
+
+
+
+
+ io.quarkus
+ quarkus-opentelemetry-deployment
+ ${project.version}
+ pom
+ test
+
+
+ *
+ *
+
+
+
+
+ io.quarkus
+ quarkus-resteasy-reactive-jackson-deployment
+ ${project.version}
+ pom
+ test
+
+
+ *
+ *
+
+
+
+
+
+
+
+
+ io.quarkus
+ quarkus-maven-plugin
+
+
+
+ build
+
+
+
+
+
+
+
+
+
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/CountResource.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/CountResource.java
new file mode 100644
index 0000000000000..dd6f36e860655
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/CountResource.java
@@ -0,0 +1,40 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import jakarta.inject.Inject;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.core.MediaType;
+
+@Path("/scheduler/count")
+public class CountResource {
+
+ @Inject
+ Counter counter;
+
+ @Inject
+ ManualScheduledCounter manualScheduledCounter;
+
+ @Inject
+ JobDefinitionCounter jobDefinitionCounter;
+
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public Integer getCount() {
+ return counter.get();
+ }
+
+ @GET
+ @Path("manual")
+ @Produces(MediaType.TEXT_PLAIN)
+ public Integer getManualCount() {
+ return manualScheduledCounter.get();
+ }
+
+ @GET
+ @Path("job-definition")
+ @Produces(MediaType.TEXT_PLAIN)
+ public Integer getJobDefinitionCount() {
+ return jobDefinitionCounter.get();
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/Counter.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/Counter.java
new file mode 100644
index 0000000000000..0199a8fb362a5
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/Counter.java
@@ -0,0 +1,30 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+
+import io.quarkus.scheduler.Scheduled;
+
+@ApplicationScoped
+public class Counter {
+
+ AtomicInteger counter;
+
+ @PostConstruct
+ void init() {
+ counter = new AtomicInteger();
+ }
+
+ public int get() {
+ return counter.get();
+ }
+
+ @Scheduled(cron = "*/1 * * * * ?", identity = "myCounter")
+ void increment() throws InterruptedException {
+ Thread.sleep(100l);
+ counter.incrementAndGet();
+ }
+
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ExporterResource.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ExporterResource.java
new file mode 100644
index 0000000000000..5f6407cc16167
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ExporterResource.java
@@ -0,0 +1,38 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Produces;
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.Path;
+
+import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
+import io.opentelemetry.sdk.trace.data.SpanData;
+
+@Path("")
+public class ExporterResource {
+ @Inject
+ InMemorySpanExporter inMemorySpanExporter;
+
+ @GET
+ @Path("/export")
+ public List export() { // only export scheduled spans
+ return inMemorySpanExporter.getFinishedSpanItems()
+ .stream()
+ .filter(sd -> !sd.getName().contains("export") && !sd.getName().contains("GET"))
+ .collect(Collectors.toList());
+ }
+
+ @ApplicationScoped
+ static class InMemorySpanExporterProducer {
+ @Produces
+ @Singleton
+ InMemorySpanExporter inMemorySpanExporter() {
+ return InMemorySpanExporter.create();
+ }
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedBasicScheduler.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedBasicScheduler.java
new file mode 100644
index 0000000000000..9450827e7e328
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedBasicScheduler.java
@@ -0,0 +1,17 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+import io.quarkus.scheduler.Scheduled;
+
+@ApplicationScoped
+public class FailedBasicScheduler {
+
+ @Scheduled(cron = "*/1 * * * * ?", identity = "myFailedBasicScheduler")
+ void init() throws InterruptedException {
+ Thread.sleep(100l);
+ throw new RuntimeException("error occurred in myFailedBasicScheduler.");
+
+ }
+
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedJobDefinitionScheduler.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedJobDefinitionScheduler.java
new file mode 100644
index 0000000000000..705b5c357c9aa
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedJobDefinitionScheduler.java
@@ -0,0 +1,29 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import io.quarkus.quartz.QuartzScheduler;
+import io.quarkus.runtime.Startup;
+
+@ApplicationScoped
+@Startup
+public class FailedJobDefinitionScheduler {
+
+ @Inject
+ QuartzScheduler scheduler;
+
+ @PostConstruct
+ void init() {
+ scheduler.newJob("myFailedJobDefinition").setCron("*/1 * * * * ?").setTask(ex -> {
+ try {
+ Thread.sleep(100l);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ throw new RuntimeException("error occurred in myFailedJobDefinition.");
+ }).schedule();
+ }
+
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedManualScheduler.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedManualScheduler.java
new file mode 100644
index 0000000000000..21dc72c5f5adf
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/FailedManualScheduler.java
@@ -0,0 +1,52 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import org.quartz.Job;
+import org.quartz.JobBuilder;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleScheduleBuilder;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
+
+import io.quarkus.runtime.Startup;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@Startup
+@ApplicationScoped
+public class FailedManualScheduler {
+ @Inject
+ org.quartz.Scheduler quartz;
+
+ @PostConstruct
+ void init() throws SchedulerException {
+ JobDetail job = JobBuilder.newJob(CountingJob.class).withIdentity("myFailedManualJob", "myFailedGroup").build();
+ Trigger trigger = TriggerBuilder
+ .newTrigger()
+ .withIdentity("myFailedTrigger", "myFailedGroup")
+ .startNow()
+ .withSchedule(SimpleScheduleBuilder
+ .simpleSchedule()
+ .repeatForever()
+ .withIntervalInSeconds(1))
+ .build();
+ quartz.scheduleJob(job, trigger);
+ }
+
+ @RegisterForReflection
+ public static class CountingJob implements Job {
+ @Override
+ public void execute(JobExecutionContext jobExecutionContext) {
+ try {
+ Thread.sleep(100l);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ throw new RuntimeException("error occurred in myFailedManualJob.");
+ }
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/JobDefinitionCounter.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/JobDefinitionCounter.java
new file mode 100644
index 0000000000000..70d1038080df3
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/JobDefinitionCounter.java
@@ -0,0 +1,37 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import io.quarkus.quartz.QuartzScheduler;
+import io.quarkus.runtime.Startup;
+
+@ApplicationScoped
+@Startup
+public class JobDefinitionCounter {
+
+ @Inject
+ QuartzScheduler scheduler;
+
+ AtomicInteger counter;
+
+ @PostConstruct
+ void init() {
+ counter = new AtomicInteger();
+ scheduler.newJob("myJobDefinition").setCron("*/1 * * * * ?").setTask(ex -> {
+ try {
+ Thread.sleep(100l);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ counter.incrementAndGet();
+ }).schedule();
+ }
+
+ public int get() {
+ return counter.get();
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ManualScheduledCounter.java b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ManualScheduledCounter.java
new file mode 100644
index 0000000000000..00aca09f07c11
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/java/io/quarkus/it/opentelemetry/quartz/ManualScheduledCounter.java
@@ -0,0 +1,59 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import jakarta.annotation.PostConstruct;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import org.quartz.Job;
+import org.quartz.JobBuilder;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleScheduleBuilder;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
+
+import io.quarkus.runtime.Startup;
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+@Startup
+@ApplicationScoped
+public class ManualScheduledCounter {
+ @Inject
+ org.quartz.Scheduler quartz;
+ private static AtomicInteger counter = new AtomicInteger();
+
+ public int get() {
+ return counter.get();
+ }
+
+ @PostConstruct
+ void init() throws SchedulerException {
+ JobDetail job = JobBuilder.newJob(CountingJob.class).withIdentity("myManualJob", "myGroup").build();
+ Trigger trigger = TriggerBuilder
+ .newTrigger()
+ .withIdentity("myTrigger", "myGroup")
+ .startNow()
+ .withSchedule(SimpleScheduleBuilder
+ .simpleSchedule()
+ .repeatForever()
+ .withIntervalInSeconds(1))
+ .build();
+ quartz.scheduleJob(job, trigger);
+ }
+
+ @RegisterForReflection
+ public static class CountingJob implements Job {
+ @Override
+ public void execute(JobExecutionContext jobExecutionContext) {
+ try {
+ Thread.sleep(100l);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ counter.incrementAndGet();
+ }
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/main/resources/application.properties b/integration-tests/opentelemetry-quartz/src/main/resources/application.properties
new file mode 100644
index 0000000000000..b32b9f635240d
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/main/resources/application.properties
@@ -0,0 +1,5 @@
+# speed up build
+quarkus.otel.bsp.schedule.delay=100
+quarkus.otel.bsp.export.timeout=5s
+
+quarkus.scheduler.tracing.enabled=true
\ No newline at end of file
diff --git a/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzIT.java b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzIT.java
new file mode 100644
index 0000000000000..e938a8d4f73c7
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzIT.java
@@ -0,0 +1,16 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import org.junit.jupiter.api.Test;
+
+import io.quarkus.test.junit.DisabledOnIntegrationTest;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+public class OpenTelemetryQuartzIT extends OpenTelemetryQuartzTest {
+ @Test
+ @DisabledOnIntegrationTest("native mode testing span does not have a field 'exception' (only in integration-test, not in quarkus app)")
+ @Override
+ public void quartzSpanTest() {
+ super.quartzSpanTest();
+ }
+}
diff --git a/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java
new file mode 100644
index 0000000000000..7f3897f6c3671
--- /dev/null
+++ b/integration-tests/opentelemetry-quartz/src/test/java/io/quarkus/it/opentelemetry/quartz/OpenTelemetryQuartzTest.java
@@ -0,0 +1,104 @@
+package io.quarkus.it.opentelemetry.quartz;
+
+import static io.restassured.RestAssured.get;
+import static io.restassured.RestAssured.given;
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.time.Duration;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import io.opentelemetry.api.trace.SpanKind;
+import io.opentelemetry.api.trace.StatusCode;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.common.mapper.TypeRef;
+import io.restassured.response.Response;
+
+@QuarkusTest
+public class OpenTelemetryQuartzTest {
+
+ private static long DURATION_IN_NANOSECONDS = 100_000_000; // Thread.sleep(100l) for each job
+
+ @Test
+ public void quartzSpanTest() {
+ // ensure that scheduled job is called
+ assertCounter("/scheduler/count", 1, Duration.ofSeconds(1));
+ // assert programmatically scheduled job is called
+ assertCounter("/scheduler/count/manual", 1, Duration.ofSeconds(1));
+ // assert JobDefinition type scheduler
+ assertCounter("/scheduler/count/job-definition", 1, Duration.ofSeconds(1));
+
+ // ------- SPAN ASSERTS -------
+ List