Skip to content

Commit

Permalink
Refactor OpenTelemetry extension to be more modular with respect to RR
Browse files Browse the repository at this point in the history
This is done using Quarkus' conditional extension dependencies feature
  • Loading branch information
geoand committed Jul 4, 2023
1 parent 7f97418 commit b6dd46a
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 26 deletions.
15 changes: 15 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,11 @@
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-deployment-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-deployment</artifactId>
Expand All @@ -2928,6 +2933,16 @@
<artifactId>quarkus-opentelemetry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-resteasy-reactive-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-resteasy-reactive</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
Expand Down
48 changes: 48 additions & 0 deletions extensions/opentelemetry-resteasy-reactive/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-opentelemetry-resteasy-reactive-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-opentelemetry-resteasy-reactive-deployment</artifactId>
<name>Quarkus - OpenTelemetry - RESTEasy Reactive - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-deployment-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -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> openTelemetryTracerEnabledBuildItem,
BuildProducer<CustomContainerRequestFilterBuildItem> containerRequestFilterBuildItemBuildProducer) {

if (openTelemetryTracerEnabledBuildItem.isEmpty()) {
return;
}

containerRequestFilterBuildItemBuildProducer
.produce(new CustomContainerRequestFilterBuildItem(OpenTelemetryReactiveServerFilter.class.getName()));
}
}
22 changes: 22 additions & 0 deletions extensions/opentelemetry-resteasy-reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-opentelemetry-resteasy-reactive-parent</artifactId>
<name>Quarkus - OpenTelemetry = RESTEasy Reactive</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>


</project>
57 changes: 57 additions & 0 deletions extensions/opentelemetry-resteasy-reactive/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-opentelemetry-resteasy-reactive-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-opentelemetry-resteasy-reactive</artifactId>
<name>Quarkus - OpenTelemetry - RESTEasy Reactive - Runtime</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<dependencyCondition>
<artifact>io.quarkus:quarkus-resteasy-reactive</artifact>
</dependencyCondition>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
artifact: ${project.groupId}:${project.artifactId}:${project.version}
name: "OpenTelemetry RESTEasy Reactive"
metadata:
unlisted: true
23 changes: 23 additions & 0 deletions extensions/opentelemetry/deployment-spi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-opentelemetry-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-opentelemetry-deployment-spi</artifactId>
<name>Quarkus - OpenTelemetry - Deployment- SPI</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
@@ -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 {

}
2 changes: 1 addition & 1 deletion extensions/opentelemetry/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
<artifactId>quarkus-opentelemetry-deployment-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -124,20 +122,4 @@ void registerResteasyClassicAndOrResteasyReactiveProvider(
.produce(new ResteasyJaxrsProviderBuildItem(OpenTelemetryClassicServerFilter.class.getName()));
}

@BuildStep
void registerResteasyReactiveProvider(
Capabilities capabilities,
BuildProducer<CustomContainerRequestFilterBuildItem> 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()));
}

}
1 change: 1 addition & 0 deletions extensions/opentelemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>deployment-spi</module>
<module>runtime</module>
</modules>
</project>
5 changes: 5 additions & 0 deletions extensions/opentelemetry/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-vertx-context</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-resteasy-reactive</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.quarkus.resteasy.reactive</groupId>
<artifactId>resteasy-reactive</artifactId>
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<module>micrometer</module>
<module>micrometer-registry-prometheus</module>
<module>opentelemetry</module>
<module>opentelemetry-resteasy-reactive</module>
<module>info</module>

<!-- REST services -->
Expand Down

0 comments on commit b6dd46a

Please sign in to comment.