-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35989 from mskacelik/otel-quartz-implementation
Scheduler: OTel Instrumentation feature improvements and refactoring
- Loading branch information
Showing
39 changed files
with
1,329 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...n/java/io/quarkus/opentelemetry/deployment/scheduler/OpenTelemetrySchedulerProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.quarkus.opentelemetry.deployment.scheduler; | ||
|
||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.Capability; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.opentelemetry.deployment.OpenTelemetryEnabled; | ||
import io.quarkus.opentelemetry.runtime.scheduler.OpenTelemetryJobInstrumenter; | ||
|
||
public class OpenTelemetrySchedulerProcessor { | ||
|
||
@BuildStep(onlyIf = OpenTelemetryEnabled.class) | ||
void registerJobInstrumenter(Capabilities capabilities, BuildProducer<AdditionalBeanBuildItem> beans) { | ||
if (capabilities.isPresent(Capability.SCHEDULER)) { | ||
beans.produce(new AdditionalBeanBuildItem(OpenTelemetryJobInstrumenter.class)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...rc/main/java/io/quarkus/opentelemetry/runtime/scheduler/OpenTelemetryJobInstrumenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.opentelemetry.runtime.scheduler; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.instrumentation.api.instrumenter.ErrorCauseExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; | ||
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; | ||
import io.quarkus.scheduler.spi.JobInstrumenter; | ||
|
||
@Singleton | ||
public class OpenTelemetryJobInstrumenter implements JobInstrumenter { | ||
|
||
private final Instrumenter<JobInstrumentationContext, Void> instrumenter; | ||
|
||
public OpenTelemetryJobInstrumenter(OpenTelemetry openTelemetry) { | ||
InstrumenterBuilder<JobInstrumentationContext, Void> instrumenterBuilder = Instrumenter.builder( | ||
openTelemetry, "io.quarkus.opentelemetry", | ||
new SpanNameExtractor<JobInstrumentationContext>() { | ||
@Override | ||
public String extract(JobInstrumentationContext context) { | ||
return context.getSpanName(); | ||
} | ||
}); | ||
instrumenterBuilder.setErrorCauseExtractor(new ErrorCauseExtractor() { | ||
@Override | ||
public Throwable extract(Throwable throwable) { | ||
return throwable; | ||
} | ||
}); | ||
this.instrumenter = instrumenterBuilder.buildInstrumenter(); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> instrument(JobInstrumentationContext instrumentationContext) { | ||
Context parentCtx = Context.current(); | ||
Context context = instrumenter.start(parentCtx, instrumentationContext); | ||
try (Scope scope = context.makeCurrent()) { | ||
return instrumentationContext | ||
.executeJob() | ||
.whenComplete( | ||
(result, throwable) -> instrumenter.end(context, instrumentationContext, null, throwable)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
extensions/quartz/runtime/src/main/java/io/quarkus/quartz/runtime/InstrumentedJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.quarkus.quartz.runtime; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.quartz.Job; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
import org.quartz.JobKey; | ||
|
||
import io.quarkus.scheduler.spi.JobInstrumenter; | ||
import io.quarkus.scheduler.spi.JobInstrumenter.JobInstrumentationContext; | ||
|
||
/** | ||
* | ||
* @see JobInstrumenter | ||
*/ | ||
class InstrumentedJob implements Job { | ||
|
||
private final Job delegate; | ||
private final JobInstrumenter instrumenter; | ||
|
||
InstrumentedJob(Job delegate, JobInstrumenter instrumenter) { | ||
this.delegate = delegate; | ||
this.instrumenter = instrumenter; | ||
} | ||
|
||
@Override | ||
public void execute(JobExecutionContext context) throws JobExecutionException { | ||
instrumenter.instrument(new JobInstrumentationContext() { | ||
|
||
@Override | ||
public CompletionStage<Void> executeJob() { | ||
try { | ||
delegate.execute(context); | ||
return CompletableFuture.completedFuture(null); | ||
} catch (Exception e) { | ||
return CompletableFuture.failedFuture(e); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public String getSpanName() { | ||
JobKey key = context.getJobDetail().getKey(); | ||
return key.getGroup() + '.' + key.getName(); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...heduler/common/src/main/java/io/quarkus/scheduler/common/runtime/InstrumentedInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.scheduler.common.runtime; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import io.quarkus.scheduler.ScheduledExecution; | ||
import io.quarkus.scheduler.spi.JobInstrumenter; | ||
import io.quarkus.scheduler.spi.JobInstrumenter.JobInstrumentationContext; | ||
|
||
/** | ||
* | ||
* @see JobInstrumenter | ||
*/ | ||
public class InstrumentedInvoker extends DelegateInvoker { | ||
|
||
private final JobInstrumenter instrumenter; | ||
|
||
public InstrumentedInvoker(ScheduledInvoker delegate, JobInstrumenter instrumenter) { | ||
super(delegate); | ||
this.instrumenter = instrumenter; | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> invoke(ScheduledExecution execution) throws Exception { | ||
return instrumenter.instrument(new JobInstrumentationContext() { | ||
|
||
@Override | ||
public CompletionStage<Void> executeJob() { | ||
try { | ||
return delegate.invoke(execution); | ||
} catch (Exception e) { | ||
return CompletableFuture.failedFuture(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getSpanName() { | ||
return execution.getTrigger().getId(); | ||
} | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.