Skip to content

Commit

Permalink
- Set path template onto Vertx Context
Browse files Browse the repository at this point in the history
- Update span name with path template for OpenTelemetry
- Remove SPI module of `resteasy-observability` and move class into deployment module instead
  • Loading branch information
kenfinnigan committed Jun 9, 2021
1 parent fea9a08 commit 141a21a
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 65 deletions.
13 changes: 13 additions & 0 deletions devtools/bom-descriptor-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute-deployment</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion extensions/micrometer/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<quarkus.log.level>DEBUG</quarkus.log.level>
<quarkus.log.level>INFO</quarkus.log.level>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
quarkus.log.category."io.quarkus.micrometer".level=DEBUG
quarkus.log.category."io.quarkus.resteasy.observability".level=DEBUG
#quarkus.log.category."io.quarkus.micrometer".level=DEBUG
quarkus.log.category."io.quarkus.bootstrap".level=INFO
quarkus.log.category."io.quarkus.arc".level=DEBUG
#quarkus.log.category."io.quarkus.arc".level=DEBUG
quarkus.log.category."io.netty".level=INFO
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_FLAVOR;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_HOST;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_METHOD;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_ROUTE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_SCHEME;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_STATUS_CODE;
import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.HTTP_TARGET;
Expand Down Expand Up @@ -142,6 +143,13 @@ public <R> void sendResponse(
return;
}

// Update Span name if parameterized path present
String pathTemplate = context.getLocal("UrlPathTemplate");
if (pathTemplate != null && !pathTemplate.isEmpty()) {
span.updateName(pathTemplate.substring(1));
span.setAttribute(HTTP_ROUTE, pathTemplate);
}

((ContextInternal) context).dispatch(() -> {
if (failure != null) {
span.setStatus(StatusCode.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-deployment</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions extensions/resteasy-classic/resteasy-common/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
</dependency>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-spi</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
import io.quarkus.resteasy.common.deployment.ResteasyCommonProcessor.ResteasyCommonConfig;
import io.quarkus.resteasy.common.runtime.QuarkusInjectorFactory;
import io.quarkus.resteasy.common.spi.ResteasyDotNames;
import io.quarkus.resteasy.observability.spi.RestApplicationPathBuildItem;
import io.quarkus.resteasy.observability.deployment.RestApplicationPathBuildItem;
import io.quarkus.resteasy.server.common.runtime.QuarkusResteasyDeployment;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceDefiningAnnotationBuildItem;
import io.quarkus.resteasy.server.common.spi.AdditionalJaxRsResourceMethodAnnotationsBuildItem;
Expand Down
4 changes: 2 additions & 2 deletions extensions/resteasy-observability/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-spi</artifactId>
<artifactId>quarkus-resteasy-observability</artifactId>
</dependency>

<!-- test -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.resteasy.observability.spi;
package io.quarkus.resteasy.observability.deployment;

import io.quarkus.builder.item.SimpleBuildItem;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.resteasy.observability.runtime.deployment;
package io.quarkus.resteasy.observability.deployment;

import java.util.Optional;
import java.util.regex.Pattern;
Expand All @@ -13,10 +13,14 @@
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
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.deployment.metrics.MetricsCapabilityBuildItem;
import io.quarkus.resteasy.observability.runtime.QuarkusRestPathTemplate;
import io.quarkus.resteasy.observability.runtime.QuarkusRestPathTemplateInterceptor;
import io.quarkus.resteasy.observability.spi.RestApplicationPathBuildItem;
import io.quarkus.runtime.metrics.MetricsFactory;

public class RestPathAnnotationProcessor {

Expand All @@ -29,19 +33,30 @@ public class RestPathAnnotationProcessor {
public static final Pattern MULTIPLE_SLASH_PATTERN = Pattern.compile("//+");

@BuildStep()
AdditionalBeanBuildItem registerBeanClasses() {
AdditionalBeanBuildItem registerBeanClasses(Capabilities capabilities,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
if (notRequired(capabilities, metricsCapability)) {
return null;
}

return AdditionalBeanBuildItem.builder()
.setUnremovable()
.addBeanClass(TEMPLATE_PATH.toString())
.addBeanClass(TEMPLATE_PATH_INTERCEPTOR.toString())
.build();
}

@BuildStep
AnnotationsTransformerBuildItem findRestPaths(
void findRestPaths(
Capabilities capabilities, Optional<MetricsCapabilityBuildItem> metricsCapability,
BuildProducer<AnnotationsTransformerBuildItem> transformers,
Optional<RestApplicationPathBuildItem> restApplicationPath) {

return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
if (notRequired(capabilities, metricsCapability)) {
// Don't create transformer if Micrometer or OpenTelemetry are not present
return;
}

transformers.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public boolean appliesTo(AnnotationTarget.Kind kind) {
return kind == AnnotationTarget.Kind.METHOD;
Expand Down Expand Up @@ -78,7 +93,7 @@ public void transform(TransformationContext ctx) {
.add(TEMPLATE_PATH, AnnotationValue.createStringValue("value", templatePath))
.done();
}
});
}));
}

String slashify(String path) {
Expand All @@ -97,4 +112,10 @@ String slashify(String path) {
}
return '/' + path;
}

private boolean notRequired(Capabilities capabilities,
Optional<MetricsCapabilityBuildItem> metricsCapability) {
return !(metricsCapability.isPresent() && metricsCapability.get().metricsSupported(MetricsFactory.MICROMETER))
&& capabilities.isMissing(Capability.OPENTELEMETRY_TRACER);
}
}
1 change: 0 additions & 1 deletion extensions/resteasy-observability/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<packaging>pom</packaging>

<modules>
<module>spi</module>
<module>runtime</module>
<module>deployment</module>
</modules>
Expand Down
4 changes: 4 additions & 0 deletions extensions/resteasy-observability/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http</artifactId>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import javax.enterprise.util.Nonbinding;
import javax.interceptor.InterceptorBinding;

@Inherited
@InterceptorBinding
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface QuarkusRestPathTemplate {
@Nonbinding
String value() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jboss.logging.Logger;

import io.quarkus.arc.ArcInvocationContext;
import io.vertx.core.Vertx;

@SuppressWarnings("unused")
@QuarkusRestPathTemplate
Expand All @@ -22,21 +23,22 @@ public class QuarkusRestPathTemplateInterceptor {
@AroundInvoke
Object restMethodInvoke(InvocationContext context) throws Exception {
QuarkusRestPathTemplate annotation = getAnnotation(context);
log.infof("QuarkusRestPathTemplate annotated method invoked with %s", annotation);
log.debugf("QuarkusRestPathTemplate annotated method invoked with %s", annotation);

if (annotation != null) {

Vertx.currentContext().putLocal("UrlPathTemplate", annotation.value());
}
return context.proceed();
}

@SuppressWarnings("unchecked")
static QuarkusRestPathTemplate getAnnotation(InvocationContext context) {
Set<Annotation> annotations = (Set<Annotation>) context.getContextData()
.get(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);

for (Annotation a : annotations) {
if (QuarkusRestPathTemplate.class.isInstance(a)) {
return QuarkusRestPathTemplate.class.cast(a);
if (a instanceof QuarkusRestPathTemplate) {
return (QuarkusRestPathTemplate) a;
}
}
return null;
Expand Down
24 changes: 0 additions & 24 deletions extensions/resteasy-observability/spi/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonp-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-deployment</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonp</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-observability-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import io.quarkus.gizmo.ClassCreator;
import io.quarkus.gizmo.MethodCreator;
import io.quarkus.netty.deployment.MinNettyAllocatorMaxOrderBuildItem;
import io.quarkus.resteasy.observability.spi.RestApplicationPathBuildItem;
import io.quarkus.resteasy.observability.deployment.RestApplicationPathBuildItem;
import io.quarkus.resteasy.reactive.common.deployment.ApplicationResultBuildItem;
import io.quarkus.resteasy.reactive.common.deployment.FactoryUtils;
import io.quarkus.resteasy.reactive.common.deployment.QuarkusFactoryCreator;
Expand Down
Loading

0 comments on commit 141a21a

Please sign in to comment.