From b6dd46a2ff1772e1598f235d14b5e871a3f17579 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 4 Jul 2023 15:01:48 +0300 Subject: [PATCH] Refactor OpenTelemetry extension to be more modular with respect to RR This is done using Quarkus' conditional extension dependencies feature --- bom/application/pom.xml | 15 +++++ .../deployment/pom.xml | 48 ++++++++++++++++ ...penTelemetryResteasyReactiveProcessor.java | 24 ++++++++ .../opentelemetry-resteasy-reactive/pom.xml | 22 +++++++ .../runtime/pom.xml | 57 +++++++++++++++++++ .../OpenTelemetryReactiveServerFilter.java | 9 +-- .../resources/META-INF/quarkus-extension.yaml | 5 ++ .../opentelemetry/deployment-spi/pom.xml | 23 ++++++++ .../OpenTelemetryTracerEnabledBuildItem.java | 10 ++++ extensions/opentelemetry/deployment/pom.xml | 2 +- .../deployment/tracing/TracerProcessor.java | 6 ++ .../InstrumentationProcessor.java | 18 ------ extensions/opentelemetry/pom.xml | 1 + extensions/opentelemetry/runtime/pom.xml | 5 ++ extensions/pom.xml | 1 + 15 files changed, 220 insertions(+), 26 deletions(-) create mode 100644 extensions/opentelemetry-resteasy-reactive/deployment/pom.xml create mode 100644 extensions/opentelemetry-resteasy-reactive/deployment/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/deployment/OpenTelemetryResteasyReactiveProcessor.java create mode 100644 extensions/opentelemetry-resteasy-reactive/pom.xml create mode 100644 extensions/opentelemetry-resteasy-reactive/runtime/pom.xml rename extensions/{opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/resteasy => opentelemetry-resteasy-reactive/runtime/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/runtime}/OpenTelemetryReactiveServerFilter.java (74%) create mode 100644 extensions/opentelemetry-resteasy-reactive/runtime/src/main/resources/META-INF/quarkus-extension.yaml create mode 100644 extensions/opentelemetry/deployment-spi/pom.xml create mode 100644 extensions/opentelemetry/deployment-spi/src/main/java/io/quarkus/opentelemetry/deployment/spi/OpenTelemetryTracerEnabledBuildItem.java diff --git a/bom/application/pom.xml b/bom/application/pom.xml index 74587f9b939d2f..2798fa0d2f4d9e 100644 --- a/bom/application/pom.xml +++ b/bom/application/pom.xml @@ -2918,6 +2918,11 @@ quarkus-micrometer-registry-prometheus ${project.version} + + io.quarkus + quarkus-opentelemetry-deployment-spi + ${project.version} + io.quarkus quarkus-opentelemetry-deployment @@ -2928,6 +2933,16 @@ quarkus-opentelemetry ${project.version} + + io.quarkus + quarkus-opentelemetry-resteasy-reactive-deployment + ${project.version} + + + io.quarkus + quarkus-opentelemetry-resteasy-reactive + ${project.version} + io.quarkus diff --git a/extensions/opentelemetry-resteasy-reactive/deployment/pom.xml b/extensions/opentelemetry-resteasy-reactive/deployment/pom.xml new file mode 100644 index 00000000000000..09385c488999a4 --- /dev/null +++ b/extensions/opentelemetry-resteasy-reactive/deployment/pom.xml @@ -0,0 +1,48 @@ + + + + quarkus-opentelemetry-resteasy-reactive-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-opentelemetry-resteasy-reactive-deployment + Quarkus - OpenTelemetry - RESTEasy Reactive - Deployment + + + + io.quarkus + quarkus-opentelemetry-resteasy-reactive + + + io.quarkus + quarkus-opentelemetry-deployment-spi + + + io.quarkus + quarkus-resteasy-reactive-deployment + + + + + + + maven-compiler-plugin + + + + io.quarkus + quarkus-extension-processor + ${project.version} + + + + + + + + + diff --git a/extensions/opentelemetry-resteasy-reactive/deployment/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/deployment/OpenTelemetryResteasyReactiveProcessor.java b/extensions/opentelemetry-resteasy-reactive/deployment/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/deployment/OpenTelemetryResteasyReactiveProcessor.java new file mode 100644 index 00000000000000..fb3527753bb20a --- /dev/null +++ b/extensions/opentelemetry-resteasy-reactive/deployment/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/deployment/OpenTelemetryResteasyReactiveProcessor.java @@ -0,0 +1,24 @@ +package io.quarkus.opentelemetry.resteasy.reactive.deployment; + +import java.util.Optional; + +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.opentelemetry.deployment.spi.OpenTelemetryTracerEnabledBuildItem; +import io.quarkus.opentelemetry.resteasy.reactive.runtime.OpenTelemetryReactiveServerFilter; +import io.quarkus.resteasy.reactive.spi.CustomContainerRequestFilterBuildItem; + +public class OpenTelemetryResteasyReactiveProcessor { + + @BuildStep + void registerResteasyReactiveProvider(Optional openTelemetryTracerEnabledBuildItem, + BuildProducer containerRequestFilterBuildItemBuildProducer) { + + if (openTelemetryTracerEnabledBuildItem.isEmpty()) { + return; + } + + containerRequestFilterBuildItemBuildProducer + .produce(new CustomContainerRequestFilterBuildItem(OpenTelemetryReactiveServerFilter.class.getName())); + } +} diff --git a/extensions/opentelemetry-resteasy-reactive/pom.xml b/extensions/opentelemetry-resteasy-reactive/pom.xml new file mode 100644 index 00000000000000..c5b3f7a4e66254 --- /dev/null +++ b/extensions/opentelemetry-resteasy-reactive/pom.xml @@ -0,0 +1,22 @@ + + + + quarkus-extensions-parent + io.quarkus + 999-SNAPSHOT + ../pom.xml + + 4.0.0 + + quarkus-opentelemetry-resteasy-reactive-parent + Quarkus - OpenTelemetry = RESTEasy Reactive + pom + + deployment + runtime + + + + diff --git a/extensions/opentelemetry-resteasy-reactive/runtime/pom.xml b/extensions/opentelemetry-resteasy-reactive/runtime/pom.xml new file mode 100644 index 00000000000000..d25a001e6cd992 --- /dev/null +++ b/extensions/opentelemetry-resteasy-reactive/runtime/pom.xml @@ -0,0 +1,57 @@ + + + + quarkus-opentelemetry-resteasy-reactive-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-opentelemetry-resteasy-reactive + Quarkus - OpenTelemetry - RESTEasy Reactive - Runtime + + + + io.quarkus + quarkus-resteasy-reactive + + + io.opentelemetry + opentelemetry-api + + + io.opentelemetry + opentelemetry-semconv + + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-api + + + + + + + io.quarkus + quarkus-extension-maven-plugin + + + process-resources + + extension-descriptor + + + + io.quarkus:quarkus-resteasy-reactive + + + + + + + + + + diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/resteasy/OpenTelemetryReactiveServerFilter.java b/extensions/opentelemetry-resteasy-reactive/runtime/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/runtime/OpenTelemetryReactiveServerFilter.java similarity index 74% rename from extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/resteasy/OpenTelemetryReactiveServerFilter.java rename to extensions/opentelemetry-resteasy-reactive/runtime/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/runtime/OpenTelemetryReactiveServerFilter.java index ddf382a32f6483..35dd4500261aea 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/resteasy/OpenTelemetryReactiveServerFilter.java +++ b/extensions/opentelemetry-resteasy-reactive/runtime/src/main/java/io/quarkus/opentelemetry/resteasy/reactive/runtime/OpenTelemetryReactiveServerFilter.java @@ -1,6 +1,4 @@ -package io.quarkus.opentelemetry.runtime.tracing.intrumentation.resteasy; - -import java.io.IOException; +package io.quarkus.opentelemetry.resteasy.reactive.runtime; import org.jboss.resteasy.reactive.server.ServerRequestFilter; import org.jboss.resteasy.reactive.server.SimpleResourceInfo; @@ -9,13 +7,10 @@ import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -/** - * Handles RESTEasy Reactive (via Vert.x) - */ public class OpenTelemetryReactiveServerFilter { @ServerRequestFilter - public void filter(SimpleResourceInfo resourceInfo) throws IOException { + public void filter(SimpleResourceInfo resourceInfo) { Span localRootSpan = LocalRootSpan.current(); localRootSpan.setAttribute(SemanticAttributes.CODE_NAMESPACE, resourceInfo.getResourceClass().getName()); diff --git a/extensions/opentelemetry-resteasy-reactive/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/opentelemetry-resteasy-reactive/runtime/src/main/resources/META-INF/quarkus-extension.yaml new file mode 100644 index 00000000000000..278520859ab0c8 --- /dev/null +++ b/extensions/opentelemetry-resteasy-reactive/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -0,0 +1,5 @@ +--- +artifact: ${project.groupId}:${project.artifactId}:${project.version} +name: "OpenTelemetry RESTEasy Reactive" +metadata: + unlisted: true diff --git a/extensions/opentelemetry/deployment-spi/pom.xml b/extensions/opentelemetry/deployment-spi/pom.xml new file mode 100644 index 00000000000000..d80d1dac808523 --- /dev/null +++ b/extensions/opentelemetry/deployment-spi/pom.xml @@ -0,0 +1,23 @@ + + + + quarkus-opentelemetry-parent + io.quarkus + 999-SNAPSHOT + + 4.0.0 + + quarkus-opentelemetry-deployment-spi + Quarkus - OpenTelemetry - Deployment- SPI + + + + io.quarkus + quarkus-core-deployment + + + + + diff --git a/extensions/opentelemetry/deployment-spi/src/main/java/io/quarkus/opentelemetry/deployment/spi/OpenTelemetryTracerEnabledBuildItem.java b/extensions/opentelemetry/deployment-spi/src/main/java/io/quarkus/opentelemetry/deployment/spi/OpenTelemetryTracerEnabledBuildItem.java new file mode 100644 index 00000000000000..1cef20dc0609c1 --- /dev/null +++ b/extensions/opentelemetry/deployment-spi/src/main/java/io/quarkus/opentelemetry/deployment/spi/OpenTelemetryTracerEnabledBuildItem.java @@ -0,0 +1,10 @@ +package io.quarkus.opentelemetry.deployment.spi; + +import io.quarkus.builder.item.SimpleBuildItem; + +/** + * A build item that can be used by extensions to determine whether the OpenTelemetry tracer is enabled + */ +public final class OpenTelemetryTracerEnabledBuildItem extends SimpleBuildItem { + +} diff --git a/extensions/opentelemetry/deployment/pom.xml b/extensions/opentelemetry/deployment/pom.xml index 88a08f63390cb1..4b0fa780bebf41 100644 --- a/extensions/opentelemetry/deployment/pom.xml +++ b/extensions/opentelemetry/deployment/pom.xml @@ -19,7 +19,7 @@ io.quarkus - quarkus-core-deployment + quarkus-opentelemetry-deployment-spi io.quarkus diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java index c958840b8e702d..430834e61843aa 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/TracerProcessor.java @@ -34,6 +34,7 @@ import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.ApplicationInfoBuildItem; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.opentelemetry.deployment.spi.OpenTelemetryTracerEnabledBuildItem; import io.quarkus.opentelemetry.runtime.tracing.TracerRecorder; import io.quarkus.opentelemetry.runtime.tracing.cdi.TracerProducer; import io.quarkus.runtime.configuration.ConfigurationException; @@ -49,6 +50,11 @@ public class TracerProcessor { private static final DotName SPAN_PROCESSOR = DotName.createSimple(SpanProcessor.class.getName()); private static final DotName TEXT_MAP_PROPAGATOR = DotName.createSimple(TextMapPropagator.class.getName()); + @BuildStep + OpenTelemetryTracerEnabledBuildItem tracerEnabled() { + return new OpenTelemetryTracerEnabledBuildItem(); + } + @BuildStep UnremovableBeanBuildItem ensureProducersAreRetained( CombinedIndexBuildItem indexBuildItem, diff --git a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java index b73e6ab0cc1fce..6b5b3515019614 100644 --- a/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java +++ b/extensions/opentelemetry/deployment/src/main/java/io/quarkus/opentelemetry/deployment/tracing/instrumentation/InstrumentationProcessor.java @@ -26,9 +26,7 @@ import io.quarkus.opentelemetry.runtime.tracing.intrumentation.reactivemessaging.ReactiveMessagingTracingDecorator; import io.quarkus.opentelemetry.runtime.tracing.intrumentation.restclient.OpenTelemetryClientFilter; import io.quarkus.opentelemetry.runtime.tracing.intrumentation.resteasy.OpenTelemetryClassicServerFilter; -import io.quarkus.opentelemetry.runtime.tracing.intrumentation.resteasy.OpenTelemetryReactiveServerFilter; import io.quarkus.resteasy.common.spi.ResteasyJaxrsProviderBuildItem; -import io.quarkus.resteasy.reactive.spi.CustomContainerRequestFilterBuildItem; import io.quarkus.vertx.core.deployment.VertxOptionsConsumerBuildItem; import io.vertx.core.VertxOptions; @@ -124,20 +122,4 @@ void registerResteasyClassicAndOrResteasyReactiveProvider( .produce(new ResteasyJaxrsProviderBuildItem(OpenTelemetryClassicServerFilter.class.getName())); } - @BuildStep - void registerResteasyReactiveProvider( - Capabilities capabilities, - BuildProducer containerRequestFilterBuildItemBuildProducer) { - - boolean isResteasyReactiveAvailable = capabilities.isPresent(Capability.RESTEASY_REACTIVE); - - if (!isResteasyReactiveAvailable) { - // if RestEasy is not available then no need to continue - return; - } - - containerRequestFilterBuildItemBuildProducer - .produce(new CustomContainerRequestFilterBuildItem(OpenTelemetryReactiveServerFilter.class.getName())); - } - } diff --git a/extensions/opentelemetry/pom.xml b/extensions/opentelemetry/pom.xml index 2097eb3a0dcd1e..0e76921ed8ac58 100644 --- a/extensions/opentelemetry/pom.xml +++ b/extensions/opentelemetry/pom.xml @@ -15,6 +15,7 @@ pom deployment + deployment-spi runtime diff --git a/extensions/opentelemetry/runtime/pom.xml b/extensions/opentelemetry/runtime/pom.xml index bf52aa37b6cf68..d0004f4443a81c 100644 --- a/extensions/opentelemetry/runtime/pom.xml +++ b/extensions/opentelemetry/runtime/pom.xml @@ -34,6 +34,11 @@ io.smallrye.common smallrye-common-vertx-context + + io.quarkus + quarkus-opentelemetry-resteasy-reactive + true + io.quarkus.resteasy.reactive resteasy-reactive diff --git a/extensions/pom.xml b/extensions/pom.xml index e4c9d03f36e7d9..574bd4cc78fc56 100644 --- a/extensions/pom.xml +++ b/extensions/pom.xml @@ -52,6 +52,7 @@ micrometer micrometer-registry-prometheus opentelemetry + opentelemetry-resteasy-reactive info