From c67e466e70cad3a136f9e09b282bbe034f0ab108 Mon Sep 17 00:00:00 2001 From: mateuszrzeszutek Date: Fri, 21 Aug 2020 18:20:04 +0200 Subject: [PATCH 1/3] Support RESTeasy 4.0 version in unit tests * Split jaxrs-2.0 into jaxrs-2.0-common and jaxrs-2.0-testing (similar to e.g. play) * Support newest RESTEasy version in unit tests --- .../dropwizard-testing.gradle | 5 +- .../jaxrs-2.0-common/jaxrs-2.0-common.gradle | 18 +++++ ...AbstractRequestContextInstrumentation.java | 27 +++----- ...ContainerRequestFilterInstrumentation.java | 0 .../DefaultRequestContextInstrumentation.java | 39 +++++------ .../v2_0/JaxRsAnnotationsInstrumentation.java | 29 ++++---- .../jaxrs/v2_0/JaxRsAnnotationsTracer.java | 5 ++ .../JaxRsAsyncResponseInstrumentation.java | 0 .../jaxrs-2.0-jersey-2.0.gradle | 12 +++- .../JerseyRequestContextInstrumentation.java | 26 ++++--- ...JerseyAnnotationInstrumentationTest.groovy | 18 +++++ .../src/test/groovy/JerseyFilterTest.groovy | 44 ++++++++++++ .../test/groovy/JerseyHttpServerTest.groovy | 44 ++++++++++++ .../jaxrs-2.0-resteasy-3.0.gradle | 19 ++++- ...steasy30RequestContextInstrumentation.java | 27 +++++--- ...steasyAnnotationInstrumentationTest.groovy | 18 +++++ .../src/test/groovy/ResteasyFilterTest.groovy | 54 +++++++++++++++ .../test/groovy/ResteasyHttpServerTest.groovy | 35 ++++++++++ .../jaxrs-2.0-resteasy-3.1.gradle | 21 +++++- ...steasy31RequestContextInstrumentation.java | 26 ++++--- ...steasyAnnotationInstrumentationTest.groovy | 18 +++++ .../src/test/groovy/ResteasyFilterTest.groovy | 54 +++++++++++++++ .../test/groovy/ResteasyHttpServerTest.groovy | 35 ++++++++++ .../jaxrs-2.0-testing.gradle | 16 +++++ ...axRsAnnotationsInstrumentationTest.groovy} | 2 +- .../src/main}/groovy/JaxRsFilterTest.groovy | 69 ++----------------- .../main}/groovy/JaxRsHttpServerTest.groovy | 45 ------------ .../src/main}/groovy/JaxRsTestResource.groovy | 0 .../src/main/java}/JavaInterfaces.java | 0 .../src/main}/java/Resource.java | 0 .../jaxrs/jaxrs-2.0/jaxrs-2.0.gradle | 62 ----------------- settings.gradle | 3 +- 32 files changed, 507 insertions(+), 264 deletions(-) create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/jaxrs-2.0-common.gradle rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java (81%) rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/ContainerRequestFilterInstrumentation.java (100%) rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java (71%) rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java (89%) rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java (98%) rename instrumentation/jaxrs/jaxrs-2.0/{ => jaxrs-2.0-common}/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java (100%) create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyAnnotationInstrumentationTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyFilterTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyHttpServerTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyFilterTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyHttpServerTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyFilterTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyHttpServerTest.groovy create mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/jaxrs-2.0-testing.gradle rename instrumentation/jaxrs/jaxrs-2.0/{src/test/groovy/JaxRsAnnotations2InstrumentationTest.groovy => jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy} (98%) rename instrumentation/jaxrs/jaxrs-2.0/{src/test => jaxrs-2.0-testing/src/main}/groovy/JaxRsFilterTest.groovy (72%) rename instrumentation/jaxrs/jaxrs-2.0/{src/test => jaxrs-2.0-testing/src/main}/groovy/JaxRsHttpServerTest.groovy (81%) rename instrumentation/jaxrs/jaxrs-2.0/{src/test => jaxrs-2.0-testing/src/main}/groovy/JaxRsTestResource.groovy (100%) rename instrumentation/jaxrs/jaxrs-2.0/{src/test/groovy => jaxrs-2.0-testing/src/main/java}/JavaInterfaces.java (100%) rename instrumentation/jaxrs/jaxrs-2.0/{src/test => jaxrs-2.0-testing/src/main}/java/Resource.java (100%) delete mode 100644 instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0.gradle diff --git a/instrumentation/dropwizard-testing/dropwizard-testing.gradle b/instrumentation/dropwizard-testing/dropwizard-testing.gradle index 5d0892b4bfbc..3417fa241b8e 100644 --- a/instrumentation/dropwizard-testing/dropwizard-testing.gradle +++ b/instrumentation/dropwizard-testing/dropwizard-testing.gradle @@ -4,14 +4,11 @@ ext { apply from: "$rootDir/gradle/instrumentation.gradle" dependencies { - testImplementation project(':instrumentation:jaxrs:jaxrs-2.0') + testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0') testImplementation project(':instrumentation:servlet:servlet-3.0') // First version with DropwizardTestSupport: testImplementation group: 'io.dropwizard', name: 'dropwizard-testing', version: '0.8.0' testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3' testImplementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner', version: '2.9.10' - - // Anything 1.0+ fails with a java.lang.NoClassDefFoundError: org/eclipse/jetty/server/RequestLog -// latestDepTestLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '1.+' } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/jaxrs-2.0-common.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/jaxrs-2.0-common.gradle new file mode 100644 index 000000000000..83b2eb2a8c9e --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/jaxrs-2.0-common.gradle @@ -0,0 +1,18 @@ +apply from: "$rootDir/gradle/instrumentation.gradle" + +muzzle { + fail { + group = "javax.ws.rs" + module = "jsr311-api" + versions = "[,]" + } + pass { + group = "javax.ws.rs" + module = "javax.ws.rs-api" + versions = "[,]" + } +} + +dependencies { + compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java similarity index 81% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java index b6a10c08ed6c..b31ed7c6c224 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java @@ -19,15 +19,14 @@ import static io.opentelemetry.instrumentation.auto.jaxrs.v2_0.JaxRsAnnotationsTracer.TRACER; import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed; import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.implementsInterface; -import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; +import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; import io.opentelemetry.javaagent.tooling.Instrumenter; import io.opentelemetry.trace.Span; import java.lang.reflect.Method; @@ -74,39 +73,35 @@ public Map, String> transfor } public static class RequestFilterHelper { - public static SpanWithScope createOrUpdateAbortSpan( + public static Span createOrUpdateAbortSpan( ContainerRequestContext context, Class resourceClass, Method method) { if (method != null && resourceClass != null) { context.setProperty(JaxRsAnnotationsTracer.ABORT_HANDLED, true); - Span parent = BaseTracer.getCurrentServerSpan(); - Span span = TRACER.getCurrentSpan(); + Span serverSpan = BaseTracer.getCurrentServerSpan(); + Span currentSpan = TRACER.getCurrentSpan(); - if (span == null) { - span = TRACER.startSpan(resourceClass, method); - return new SpanWithScope(span, currentContextWith(span)); + if (currentSpan == null || currentSpan == serverSpan) { + return TRACER.startSpan(resourceClass, method); } else { - TRACER.updateSpanNames(span, parent, resourceClass, method); - return null; + TRACER.updateSpanNames(currentSpan, serverSpan, resourceClass, method); } - } else { - return null; } + return null; } - public static void closeSpanAndScope(SpanWithScope spanWithScope, Throwable throwable) { - if (spanWithScope == null) { + public static void closeSpanAndScope(Span span, Scope scope, Throwable throwable) { + if (span == null || scope == null) { return; } - Span span = spanWithScope.getSpan(); if (throwable != null) { TRACER.endExceptionally(span, throwable); } else { TRACER.end(span); } - spanWithScope.closeScope(); + scope.close(); } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/ContainerRequestFilterInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/ContainerRequestFilterInstrumentation.java similarity index 100% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/ContainerRequestFilterInstrumentation.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/ContainerRequestFilterInstrumentation.java diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java similarity index 71% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java index 3e0a4f7a3a8d..13bfc241ae19 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java @@ -17,15 +17,15 @@ package io.opentelemetry.instrumentation.auto.jaxrs.v2_0; import static io.opentelemetry.instrumentation.auto.jaxrs.v2_0.JaxRsAnnotationsTracer.TRACER; -import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; import com.google.auto.service.AutoService; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; +import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.tooling.Instrumenter; import io.opentelemetry.trace.Span; import java.lang.reflect.Method; import javax.ws.rs.container.ContainerRequestContext; import net.bytebuddy.asm.Advice; +import net.bytebuddy.asm.Advice.Local; /** * Default context instrumentation. @@ -40,10 +40,13 @@ public class DefaultRequestContextInstrumentation extends AbstractRequestContextInstrumentation { public static class ContainerRequestContextAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope createGenericSpan(@Advice.This ContainerRequestContext context) { - + public static void createGenericSpan( + @Advice.This ContainerRequestContext context, + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope) { if (context.getProperty(JaxRsAnnotationsTracer.ABORT_HANDLED) == null) { - Class filterClass = (Class) context.getProperty(JaxRsAnnotationsTracer.ABORT_FILTER_CLASS); + Class filterClass = + (Class) context.getProperty(JaxRsAnnotationsTracer.ABORT_FILTER_CLASS); Method method = null; try { method = filterClass.getMethod("filter", ContainerRequestContext.class); @@ -52,29 +55,19 @@ public static SpanWithScope createGenericSpan(@Advice.This ContainerRequestConte // can only be aborted inside the filter method } - Span span = TRACER.startSpan(filterClass, method); - - return new SpanWithScope(span, currentContextWith(span)); + span = RequestFilterHelper.createOrUpdateAbortSpan(context, filterClass, method); + if (span != null) { + scope = TRACER.startScope(span); + } } - - return null; } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( - @Advice.Enter SpanWithScope spanWithScope, @Advice.Thrown Throwable throwable) { - if (spanWithScope == null) { - return; - } - - Span span = spanWithScope.getSpan(); - if (throwable != null) { - TRACER.endExceptionally(span, throwable); - } else { - TRACER.end(span); - } - - spanWithScope.closeScope(); + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope, + @Advice.Thrown Throwable throwable) { + RequestFilterHelper.closeSpanAndScope(span, scope, throwable); } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java similarity index 89% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java index 82e706b2974a..580fe5c6f498 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsInstrumentation.java @@ -21,7 +21,6 @@ import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.hasSuperMethod; import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.AgentElementMatchers.safeHasSuperType; import static io.opentelemetry.javaagent.tooling.matcher.NameMatchers.namedOneOf; -import static io.opentelemetry.trace.TracingContextUtils.currentContextWith; import static java.util.Collections.singletonMap; import static net.bytebuddy.matcher.ElementMatchers.declaresMethod; import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith; @@ -29,10 +28,10 @@ import static net.bytebuddy.matcher.ElementMatchers.named; import com.google.auto.service.AutoService; +import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.auto.api.CallDepthThreadLocalMap; import io.opentelemetry.instrumentation.auto.api.ContextStore; import io.opentelemetry.instrumentation.auto.api.InstrumentationContext; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; import io.opentelemetry.javaagent.tooling.Instrumenter; import io.opentelemetry.trace.Span; import java.lang.reflect.Method; @@ -101,11 +100,13 @@ public Map, String> transfor public static class JaxRsAnnotationsAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope nameSpan( + public static void nameSpan( @Advice.This Object target, @Advice.Origin Method method, @Advice.AllArguments Object[] args, - @Advice.Local("asyncResponse") AsyncResponse asyncResponse) { + @Advice.Local("otelSpan") Span span, + @Advice.Local("otelScope") Scope scope, + @Advice.Local("otelAsyncResponse") AsyncResponse asyncResponse) { ContextStore contextStore = null; for (Object arg : args) { if (arg instanceof AsyncResponse) { @@ -118,39 +119,39 @@ public static SpanWithScope nameSpan( * could work around this by using a list instead, but we likely don't want the extra * span anyway. */ - return null; + return; } break; } } if (CallDepthThreadLocalMap.incrementCallDepth(Path.class) > 0) { - return null; + return; } - Span span = TRACER.startSpan(target.getClass(), method); + span = TRACER.startSpan(target.getClass(), method); if (contextStore != null && asyncResponse != null) { contextStore.put(asyncResponse, span); } - return new SpanWithScope(span, currentContextWith(span)); + scope = TRACER.startScope(span); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( - @Advice.Enter SpanWithScope spanWithScope, @Advice.Thrown Throwable throwable, - @Advice.Local("asyncResponse") AsyncResponse asyncResponse) { - if (spanWithScope == null) { + @Advice.Local("otelSpan") Span span, + @Advice.Local("otelScope") Scope scope, + @Advice.Local("otelAsyncResponse") AsyncResponse asyncResponse) { + if (span == null || scope == null) { return; } CallDepthThreadLocalMap.reset(Path.class); - Span span = spanWithScope.getSpan(); if (throwable != null) { TRACER.endExceptionally(span, throwable); - spanWithScope.closeScope(); + scope.close(); return; } @@ -161,7 +162,7 @@ public static void stopSpan( if (asyncResponse == null || !asyncResponse.isSuspended()) { TRACER.end(span); } - spanWithScope.closeScope(); + scope.close(); // else span finished by AsyncResponseAdvice } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java similarity index 98% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java index 16d0bc7686dc..11135c8d751e 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAnnotationsTracer.java @@ -18,6 +18,7 @@ import static io.opentelemetry.instrumentation.auto.api.WeakMap.Provider.newWeakMap; +import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.tracer.BaseTracer; import io.opentelemetry.instrumentation.auto.api.WeakMap; import io.opentelemetry.javaagent.tooling.ClassHierarchyIterable; @@ -59,6 +60,10 @@ public void updateSpanNames(Span span, Span serverSpan, Class target, Method } } + public Scope startScope(Span span) { + return tracer.withSpan(span); + } + private void updateSpanName(Span span, String spanName) { if (!spanName.isEmpty()) { span.updateName(spanName); diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java similarity index 100% rename from instrumentation/jaxrs/jaxrs-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JaxRsAsyncResponseInstrumentation.java diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/jaxrs-2.0-jersey-2.0.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/jaxrs-2.0-jersey-2.0.gradle index af1a9e9386e2..942441aa2675 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/jaxrs-2.0-jersey-2.0.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/jaxrs-2.0-jersey-2.0.gradle @@ -2,7 +2,7 @@ apply from: "$rootDir/gradle/instrumentation.gradle" muzzle { // Cant assert fails because muzzle assumes all instrumentations will fail - // Instrumentations in jaxrs-2.0 will pass + // Instrumentations in jaxrs-2.0-common will pass pass { group = "org.glassfish.jersey.core" module = "jersey-server" @@ -14,5 +14,13 @@ dependencies { compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' compileOnly group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.0' - implementation project(':instrumentation:jaxrs:jaxrs-2.0') + implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common') + + testImplementation project(':instrumentation:servlet:servlet-3.0') + testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing') + + // First version with DropwizardTestSupport: + testLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '0.8.0' + testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3' + testImplementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner', version: '2.9.10' } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JerseyRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JerseyRequestContextInstrumentation.java index b0d66ec30053..4f7c17081fc5 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JerseyRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/JerseyRequestContextInstrumentation.java @@ -16,14 +16,18 @@ package io.opentelemetry.instrumentation.auto.jaxrs.v2_0; +import static io.opentelemetry.instrumentation.auto.jaxrs.v2_0.JaxRsAnnotationsTracer.TRACER; + import com.google.auto.service.AutoService; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; +import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.tooling.Instrumenter; +import io.opentelemetry.trace.Span; import java.lang.reflect.Method; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.UriInfo; import net.bytebuddy.asm.Advice; +import net.bytebuddy.asm.Advice.Local; /** * Jersey specific context instrumentation. @@ -38,7 +42,10 @@ public class JerseyRequestContextInstrumentation extends AbstractRequestContextInstrumentation { public static class ContainerRequestContextAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope decorateAbortSpan(@Advice.This ContainerRequestContext context) { + public static void decorateAbortSpan( + @Advice.This ContainerRequestContext context, + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope) { UriInfo uriInfo = context.getUriInfo(); if (context.getProperty(JaxRsAnnotationsTracer.ABORT_HANDLED) == null @@ -46,18 +53,21 @@ public static SpanWithScope decorateAbortSpan(@Advice.This ContainerRequestConte ResourceInfo resourceInfo = (ResourceInfo) uriInfo; Method method = resourceInfo.getResourceMethod(); - Class resourceClass = resourceInfo.getResourceClass(); + Class resourceClass = resourceInfo.getResourceClass(); - return RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + span = RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + if (span != null) { + scope = TRACER.startScope(span); + } } - - return null; } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( - @Advice.Enter SpanWithScope scope, @Advice.Thrown Throwable throwable) { - RequestFilterHelper.closeSpanAndScope(scope, throwable); + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope, + @Advice.Thrown Throwable throwable) { + RequestFilterHelper.closeSpanAndScope(span, scope, throwable); } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyAnnotationInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyAnnotationInstrumentationTest.groovy new file mode 100644 index 000000000000..a43f8601d7bd --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyAnnotationInstrumentationTest.groovy @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class JerseyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest { +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyFilterTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyFilterTest.groovy new file mode 100644 index 000000000000..b2045de633a7 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyFilterTest.groovy @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import static Resource.Test1 +import static Resource.Test2 +import static Resource.Test3 + +import io.dropwizard.testing.junit.ResourceTestRule +import javax.ws.rs.client.Entity +import javax.ws.rs.core.Response +import org.junit.ClassRule +import spock.lang.Shared + +class JerseyFilterTest extends JaxRsFilterTest { + @Shared + @ClassRule + ResourceTestRule resources = ResourceTestRule.builder() + .addResource(new Test1()) + .addResource(new Test2()) + .addResource(new Test3()) + .addProvider(simpleRequestFilter) + .addProvider(prematchRequestFilter) + .build() + + @Override + def makeRequest(String url) { + Response response = resources.client().target(url).request().post(Entity.text("")) + + return [response.readEntity(String), response.statusInfo.statusCode] + } +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyHttpServerTest.groovy new file mode 100644 index 000000000000..3d6080abf066 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-jersey-2.0/src/test/groovy/JerseyHttpServerTest.groovy @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import io.dropwizard.jetty.NonblockingServletHolder +import org.eclipse.jetty.server.Server +import org.eclipse.jetty.servlet.ServletContextHandler +import org.glassfish.jersey.server.ResourceConfig +import org.glassfish.jersey.servlet.ServletContainer + +class JerseyHttpServerTest extends JaxRsHttpServerTest { + + @Override + Server startServer(int port) { + def servlet = new ServletContainer(ResourceConfig.forApplicationClass(JaxRsTestApplication)) + + def handler = new ServletContextHandler(ServletContextHandler.SESSIONS) + handler.setContextPath("/") + handler.addServlet(new NonblockingServletHolder(servlet), "/*") + + def server = new Server(port) + server.setHandler(handler) + server.start() + + return server + } + + @Override + void stopServer(Server httpServer) { + httpServer.stop() + } +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/jaxrs-2.0-resteasy-3.0.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/jaxrs-2.0-resteasy-3.0.gradle index 33cbf29e51dd..ed606aab846c 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/jaxrs-2.0-resteasy-3.0.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/jaxrs-2.0-resteasy-3.0.gradle @@ -2,7 +2,7 @@ apply from: "$rootDir/gradle/instrumentation.gradle" muzzle { // Cant assert fails because muzzle assumes all instrumentations will fail - // Instrumentations in jaxrs-2.0 will pass + // Instrumentations in jaxrs-2.0-common will pass // Resteasy changes a class's package in 3.1.0 then moves it back in 3.5.0 and then moves it forward again in 4.0.0 // so the jaxrs-2.0-resteasy-3.0 module applies to [3.0, 3.1) and [3.5, 4.0) @@ -22,7 +22,20 @@ muzzle { dependencies { compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' - compileOnly group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.0.0.Final' + library group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.0.0.Final' - implementation project(':instrumentation:jaxrs:jaxrs-2.0') + implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common') + + testImplementation project(':instrumentation:servlet:servlet-3.0') + testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing') + + testLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.0.4.Final') { + exclude group: 'org.jboss.resteasy', module: 'resteasy-client' + } + testLibrary group: 'io.undertow', name: 'undertow-servlet', version: '1.0.0.Final' + + latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.+' + latestDepTestLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.+') { + exclude group: 'org.jboss.resteasy', module: 'resteasy-client' + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy30RequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy30RequestContextInstrumentation.java index 6e97a34e75a5..75c2478d88f6 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy30RequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy30RequestContextInstrumentation.java @@ -16,12 +16,16 @@ package io.opentelemetry.instrumentation.auto.jaxrs.v2_0; +import static io.opentelemetry.instrumentation.auto.jaxrs.v2_0.JaxRsAnnotationsTracer.TRACER; + import com.google.auto.service.AutoService; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; +import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.tooling.Instrumenter; +import io.opentelemetry.trace.Span; import java.lang.reflect.Method; import javax.ws.rs.container.ContainerRequestContext; import net.bytebuddy.asm.Advice; +import net.bytebuddy.asm.Advice.Local; import org.jboss.resteasy.core.ResourceMethodInvoker; import org.jboss.resteasy.core.interception.PostMatchContainerRequestContext; @@ -38,27 +42,32 @@ @AutoService(Instrumenter.class) public class Resteasy30RequestContextInstrumentation extends AbstractRequestContextInstrumentation { public static class ContainerRequestContextAdvice { - @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope decorateAbortSpan(@Advice.This ContainerRequestContext context) { + public static void decorateAbortSpan( + @Advice.This ContainerRequestContext context, + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope) { if (context.getProperty(JaxRsAnnotationsTracer.ABORT_HANDLED) == null && context instanceof PostMatchContainerRequestContext) { ResourceMethodInvoker resourceMethodInvoker = ((PostMatchContainerRequestContext) context).getResourceMethod(); Method method = resourceMethodInvoker.getMethod(); - Class resourceClass = resourceMethodInvoker.getResourceClass(); + Class resourceClass = resourceMethodInvoker.getResourceClass(); - return RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + span = RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + if (span != null) { + scope = TRACER.startScope(span); + } } - - return null; } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( - @Advice.Enter SpanWithScope scope, @Advice.Thrown Throwable throwable) { - RequestFilterHelper.closeSpanAndScope(scope, throwable); + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope, + @Advice.Thrown Throwable throwable) { + RequestFilterHelper.closeSpanAndScope(span, scope, throwable); } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy new file mode 100644 index 000000000000..c6eed10edce6 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class ResteasyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest { +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyFilterTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyFilterTest.groovy new file mode 100644 index 000000000000..740917653224 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyFilterTest.groovy @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import static Resource.Test1 +import static Resource.Test2 +import static Resource.Test3 + +import javax.ws.rs.core.MediaType +import org.jboss.resteasy.mock.MockDispatcherFactory +import org.jboss.resteasy.mock.MockHttpRequest +import org.jboss.resteasy.mock.MockHttpResponse +import spock.lang.Shared + +class ResteasyFilterTest extends JaxRsFilterTest { + @Shared + def dispatcher + + def setupSpec() { + dispatcher = MockDispatcherFactory.createDispatcher() + def registry = dispatcher.getRegistry() + registry.addSingletonResource(new Test1()) + registry.addSingletonResource(new Test2()) + registry.addSingletonResource(new Test3()) + + dispatcher.getProviderFactory().register(simpleRequestFilter) + dispatcher.getProviderFactory().register(prematchRequestFilter) + } + + @Override + def makeRequest(String url) { + MockHttpRequest request = MockHttpRequest.post(url) + request.contentType(MediaType.TEXT_PLAIN_TYPE) + request.content(new byte[0]) + + MockHttpResponse response = new MockHttpResponse() + dispatcher.invoke(request, response) + + return [response.contentAsString, response.status] + } + +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyHttpServerTest.groovy new file mode 100644 index 000000000000..b445811af41a --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.0/src/test/groovy/ResteasyHttpServerTest.groovy @@ -0,0 +1,35 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import io.undertow.Undertow +import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer + +class ResteasyHttpServerTest extends JaxRsHttpServerTest { + + @Override + UndertowJaxrsServer startServer(int port) { + def server = new UndertowJaxrsServer() + server.deploy(JaxRsTestApplication) + server.start(Undertow.builder() + .addHttpListener(port, "localhost")) + return server + } + + @Override + void stopServer(UndertowJaxrsServer server) { + server.stop() + } +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle index c8b1c1210a1e..d2d5387fea0b 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle @@ -2,7 +2,7 @@ apply from: "$rootDir/gradle/instrumentation.gradle" muzzle { // Cant assert fails because muzzle assumes all instrumentations will fail - // Instrumentations in jaxrs-2.0 will pass + // Instrumentations in jaxrs-2.0-common will pass // Resteasy changes a class's package in 3.1.0 then moves it back in 3.5.0 and then moves it forward again in 4.0.0 // so the jaxrs-2.0-resteasy-3.0 module applies to [3.0, 3.1) and [3.5, 4.0) @@ -22,7 +22,22 @@ muzzle { dependencies { compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' - compileOnly group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final' + library group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final' - implementation project(':instrumentation:jaxrs:jaxrs-2.0') + implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common') + + testImplementation project(':instrumentation:servlet:servlet-3.0') + testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing') + + testLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.1.0.Final') { + exclude group: 'org.jboss.resteasy', module: 'resteasy-client' + } + + latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-core', version: '+' +} + +if (findProperty('testLatestDeps')) { + configurations { + testImplementation.exclude group: 'org.jboss.resteasy', module: 'resteasy-jaxrs' + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy31RequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy31RequestContextInstrumentation.java index d6254c83018d..deb2e816bb49 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy31RequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/Resteasy31RequestContextInstrumentation.java @@ -16,12 +16,16 @@ package io.opentelemetry.instrumentation.auto.jaxrs.v2_0; +import static io.opentelemetry.instrumentation.auto.jaxrs.v2_0.JaxRsAnnotationsTracer.TRACER; + import com.google.auto.service.AutoService; -import io.opentelemetry.instrumentation.auto.api.SpanWithScope; +import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.tooling.Instrumenter; +import io.opentelemetry.trace.Span; import java.lang.reflect.Method; import javax.ws.rs.container.ContainerRequestContext; import net.bytebuddy.asm.Advice; +import net.bytebuddy.asm.Advice.Local; import org.jboss.resteasy.core.ResourceMethodInvoker; import org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext; @@ -39,25 +43,31 @@ public class Resteasy31RequestContextInstrumentation extends AbstractRequestContextInstrumentation { public static class ContainerRequestContextAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) - public static SpanWithScope decorateAbortSpan(@Advice.This ContainerRequestContext context) { + public static void decorateAbortSpan( + @Advice.This ContainerRequestContext context, + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope) { if (context.getProperty(JaxRsAnnotationsTracer.ABORT_HANDLED) == null && context instanceof PostMatchContainerRequestContext) { ResourceMethodInvoker resourceMethodInvoker = ((PostMatchContainerRequestContext) context).getResourceMethod(); Method method = resourceMethodInvoker.getMethod(); - Class resourceClass = resourceMethodInvoker.getResourceClass(); + Class resourceClass = resourceMethodInvoker.getResourceClass(); - return RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + span = RequestFilterHelper.createOrUpdateAbortSpan(context, resourceClass, method); + if (span != null) { + scope = TRACER.startScope(span); + } } - - return null; } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( - @Advice.Enter SpanWithScope scope, @Advice.Thrown Throwable throwable) { - RequestFilterHelper.closeSpanAndScope(scope, throwable); + @Local("otelSpan") Span span, + @Local("otelScope") Scope scope, + @Advice.Thrown Throwable throwable) { + RequestFilterHelper.closeSpanAndScope(span, scope, throwable); } } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy new file mode 100644 index 000000000000..c6eed10edce6 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyAnnotationInstrumentationTest.groovy @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class ResteasyAnnotationInstrumentationTest extends JaxRsAnnotationsInstrumentationTest { +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyFilterTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyFilterTest.groovy new file mode 100644 index 000000000000..740917653224 --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyFilterTest.groovy @@ -0,0 +1,54 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import static Resource.Test1 +import static Resource.Test2 +import static Resource.Test3 + +import javax.ws.rs.core.MediaType +import org.jboss.resteasy.mock.MockDispatcherFactory +import org.jboss.resteasy.mock.MockHttpRequest +import org.jboss.resteasy.mock.MockHttpResponse +import spock.lang.Shared + +class ResteasyFilterTest extends JaxRsFilterTest { + @Shared + def dispatcher + + def setupSpec() { + dispatcher = MockDispatcherFactory.createDispatcher() + def registry = dispatcher.getRegistry() + registry.addSingletonResource(new Test1()) + registry.addSingletonResource(new Test2()) + registry.addSingletonResource(new Test3()) + + dispatcher.getProviderFactory().register(simpleRequestFilter) + dispatcher.getProviderFactory().register(prematchRequestFilter) + } + + @Override + def makeRequest(String url) { + MockHttpRequest request = MockHttpRequest.post(url) + request.contentType(MediaType.TEXT_PLAIN_TYPE) + request.content(new byte[0]) + + MockHttpResponse response = new MockHttpResponse() + dispatcher.invoke(request, response) + + return [response.contentAsString, response.status] + } + +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyHttpServerTest.groovy new file mode 100644 index 000000000000..b445811af41a --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/src/test/groovy/ResteasyHttpServerTest.groovy @@ -0,0 +1,35 @@ +/* + * Copyright The OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import io.undertow.Undertow +import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer + +class ResteasyHttpServerTest extends JaxRsHttpServerTest { + + @Override + UndertowJaxrsServer startServer(int port) { + def server = new UndertowJaxrsServer() + server.deploy(JaxRsTestApplication) + server.start(Undertow.builder() + .addHttpListener(port, "localhost")) + return server + } + + @Override + void stopServer(UndertowJaxrsServer server) { + server.stop() + } +} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/jaxrs-2.0-testing.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/jaxrs-2.0-testing.gradle new file mode 100644 index 000000000000..4202f3ea7fdd --- /dev/null +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/jaxrs-2.0-testing.gradle @@ -0,0 +1,16 @@ +apply from: "$rootDir/gradle/java.gradle" + +dependencies { + api project(':testing-common') + api group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' + + implementation deps.groovy + implementation deps.opentelemetryApi + implementation deps.spock + implementation deps.slf4j + implementation deps.testLogging + + implementation project(':auto-api') + implementation project(':instrumentation-api') + implementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common') +} diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsAnnotations2InstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy similarity index 98% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsAnnotations2InstrumentationTest.groovy rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy index d3148c4da15c..bc283b2b41e3 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsAnnotations2InstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy @@ -28,7 +28,7 @@ import javax.ws.rs.POST import javax.ws.rs.PUT import javax.ws.rs.Path -class JaxRsAnnotations2InstrumentationTest extends AgentTestRunner { +abstract class JaxRsAnnotationsInstrumentationTest extends AgentTestRunner { def "instrumentation can be used as root span and resource is set to METHOD PATH"() { setup: diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsFilterTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsFilterTest.groovy similarity index 72% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsFilterTest.groovy rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsFilterTest.groovy index add761d60391..5703d389571d 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsFilterTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsFilterTest.groovy @@ -17,20 +17,13 @@ import static io.opentelemetry.auto.test.utils.TraceUtils.runUnderServerTrace import static io.opentelemetry.trace.Span.Kind.INTERNAL -import io.dropwizard.testing.junit.ResourceTestRule import io.opentelemetry.auto.test.AgentTestRunner -import javax.ws.rs.client.Entity import javax.ws.rs.container.ContainerRequestContext import javax.ws.rs.container.ContainerRequestFilter import javax.ws.rs.container.PreMatching import javax.ws.rs.core.MediaType import javax.ws.rs.core.Response import javax.ws.rs.ext.Provider -import org.jboss.resteasy.core.Dispatcher -import org.jboss.resteasy.mock.MockDispatcherFactory -import org.jboss.resteasy.mock.MockHttpRequest -import org.jboss.resteasy.mock.MockHttpResponse -import org.junit.ClassRule import spock.lang.Shared import spock.lang.Unroll @@ -52,12 +45,9 @@ abstract class JaxRsFilterTest extends AgentTestRunner { def abort = abortNormal || abortPrematch when: - def responseText - def responseStatus - // start a trace because the test doesn't go through any servlet or other instrumentation. - runUnderServerTrace("test.span") { - (responseText, responseStatus) = makeRequest(resource) + def (responseText, responseStatus) = runUnderServerTrace("test.span") { + makeRequest(resource) } then: @@ -109,12 +99,9 @@ abstract class JaxRsFilterTest extends AgentTestRunner { prematchRequestFilter.abort = false when: - def responseText - def responseStatus - // start a trace because the test doesn't go through any servlet or other instrumentation. - runUnderServerTrace("test.span") { - (responseText, responseStatus) = makeRequest(resource) + def (responseText, responseStatus) = runUnderServerTrace("test.span") { + makeRequest(resource) } then: @@ -176,51 +163,3 @@ abstract class JaxRsFilterTest extends AgentTestRunner { } } } - -class JerseyFilterTest extends JaxRsFilterTest { - @Shared - @ClassRule - ResourceTestRule resources = ResourceTestRule.builder() - .addResource(new Resource.Test1()) - .addResource(new Resource.Test2()) - .addResource(new Resource.Test3()) - .addProvider(simpleRequestFilter) - .addProvider(prematchRequestFilter) - .build() - - @Override - def makeRequest(String url) { - Response response = resources.client().target(url).request().post(Entity.text("")) - - return [response.readEntity(String), response.statusInfo.statusCode] - } -} - -class ResteasyFilterTest extends JaxRsFilterTest { - @Shared - Dispatcher dispatcher - - def setupSpec() { - dispatcher = MockDispatcherFactory.createDispatcher() - def registry = dispatcher.getRegistry() - registry.addSingletonResource(new Resource.Test1()) - registry.addSingletonResource(new Resource.Test2()) - registry.addSingletonResource(new Resource.Test3()) - - dispatcher.getProviderFactory().register(simpleRequestFilter) - dispatcher.getProviderFactory().register(prematchRequestFilter) - } - - @Override - def makeRequest(String url) { - MockHttpRequest request = MockHttpRequest.post(url) - request.contentType(MediaType.TEXT_PLAIN_TYPE) - request.content(new byte[0]) - - MockHttpResponse response = new MockHttpResponse() - dispatcher.invoke(request, response) - - return [response.contentAsString, response.status] - } - -} diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy similarity index 81% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsHttpServerTest.groovy rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy index 4fd78ff685a7..8ebb9086d3e8 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsHttpServerTest.groovy @@ -20,19 +20,12 @@ import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCC import static io.opentelemetry.trace.Span.Kind.INTERNAL import static io.opentelemetry.trace.Span.Kind.SERVER -import io.dropwizard.jetty.NonblockingServletHolder import io.opentelemetry.auto.test.asserts.TraceAssert import io.opentelemetry.auto.test.base.HttpServerTest import io.opentelemetry.instrumentation.api.MoreAttributes import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.trace.attributes.SemanticAttributes -import io.undertow.Undertow import okhttp3.HttpUrl -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.servlet.ServletContextHandler -import org.glassfish.jersey.server.ResourceConfig -import org.glassfish.jersey.servlet.ServletContainer -import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer import spock.lang.Unroll abstract class JaxRsHttpServerTest extends HttpServerTest { @@ -184,42 +177,4 @@ abstract class JaxRsHttpServerTest extends HttpServerTest { } } -class ResteasyHttpServerTest extends JaxRsHttpServerTest { - @Override - UndertowJaxrsServer startServer(int port) { - def server = new UndertowJaxrsServer() - server.deploy(JaxRsTestApplication) - server.start(Undertow.builder() - .addHttpListener(port, "localhost")) - return server - } - - @Override - void stopServer(UndertowJaxrsServer server) { - server.stop() - } -} - -class JerseyHttpServerTest extends JaxRsHttpServerTest { - - @Override - Server startServer(int port) { - def servlet = new ServletContainer(ResourceConfig.forApplicationClass(JaxRsTestApplication)) - - def handler = new ServletContextHandler(ServletContextHandler.SESSIONS) - handler.setContextPath("/") - handler.addServlet(new NonblockingServletHolder(servlet), "/*") - - def server = new Server(port) - server.setHandler(handler) - server.start() - - return server - } - - @Override - void stopServer(Server httpServer) { - httpServer.stop() - } -} \ No newline at end of file diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsTestResource.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsTestResource.groovy similarity index 100% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JaxRsTestResource.groovy rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsTestResource.groovy diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JavaInterfaces.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java similarity index 100% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/groovy/JavaInterfaces.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java diff --git a/instrumentation/jaxrs/jaxrs-2.0/src/test/java/Resource.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/Resource.java similarity index 100% rename from instrumentation/jaxrs/jaxrs-2.0/src/test/java/Resource.java rename to instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/Resource.java diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0.gradle deleted file mode 100644 index b7453ef1c521..000000000000 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0.gradle +++ /dev/null @@ -1,62 +0,0 @@ -apply from: "$rootDir/gradle/instrumentation.gradle" -apply plugin: 'org.unbroken-dome.test-sets' - -muzzle { - fail { - group = "javax.ws.rs" - module = "jsr311-api" - versions = "[,]" - } - pass { - group = "javax.ws.rs" - module = "javax.ws.rs-api" - versions = "[,]" - } -} - -testSets { - resteasy31Test { - dirName = 'test' - } -} - -dependencies { - compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0' - - testImplementation project(':instrumentation:servlet:servlet-3.0') - testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0') - testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.0') - testImplementation project(':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.1') - - // Jersey - // First version with DropwizardTestSupport: - testLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '0.8.0' - testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3' - testImplementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner', version: '2.9.10' - - latestDepTestLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '1.+' - - // Resteasy - testLibrary group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.0.0.Final' - testImplementation(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.0.4.Final') { - exclude group: 'org.jboss.resteasy', module: 'resteasy-client' - } - testImplementation group: 'io.undertow', name: 'undertow-servlet', version: '1.0.0.Final' - - resteasy31TestImplementation(group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.0.Final') - resteasy31TestImplementation(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.1.0.Final') { - exclude group: 'org.jboss.resteasy', module: 'resteasy-client' - } - - latestDepTestLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '3.+') { - exclude group: 'org.jboss.resteasy', module: 'resteasy-client' - } - - // TODO: resteasy 4.+ has changed artifact name to resteasy-core -// latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-core', version: '+' -// latestDepTestLibrary(group: 'org.jboss.resteasy', name: 'resteasy-undertow', version: '+') { -// exclude group: 'org.jboss.resteasy', module: 'resteasy-client' -// } -} - -test.dependsOn resteasy31Test diff --git a/settings.gradle b/settings.gradle index e7982c81b2b8..b8e36ea34a7b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -99,10 +99,11 @@ include ':instrumentation:java-classloader:tomcat-testing' include ':instrumentation:java-concurrent' include ':instrumentation:java-httpclient' include ':instrumentation:jaxrs:jaxrs-1.0' -include ':instrumentation:jaxrs:jaxrs-2.0' +include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-common' include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-jersey-2.0' include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.0' include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-resteasy-3.1' +include ':instrumentation:jaxrs:jaxrs-2.0:jaxrs-2.0-testing' include ':instrumentation:jaxrs-client:jaxrs-client-1.1' include ':instrumentation:jaxrs-client:jaxrs-client-2.0' include ':instrumentation:jaxrs-client:jaxrs-client-2.0:jaxrs-client-2.0-jersey-2.0' From 6639baeed1c064d5dc72d0cb66e197ba5d5d5ef8 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Thu, 10 Sep 2020 11:09:58 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Trask Stalnaker --- .../jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle index d2d5387fea0b..2c66e006c49d 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-resteasy-3.1/jaxrs-2.0-resteasy-3.1.gradle @@ -33,11 +33,13 @@ dependencies { exclude group: 'org.jboss.resteasy', module: 'resteasy-client' } + // artifact name changed from 'resteasy-jaxrs' to 'resteasy-core' starting from version 4.0.0 latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-core', version: '+' } if (findProperty('testLatestDeps')) { configurations { + // artifact name changed from 'resteasy-jaxrs' to 'resteasy-core' starting from version 4.0.0 testImplementation.exclude group: 'org.jboss.resteasy', module: 'resteasy-jaxrs' } } From ef99c2bd596f67e8755d1bd9b9c6fbaf2bcedd61 Mon Sep 17 00:00:00 2001 From: mateuszrzeszutek Date: Thu, 10 Sep 2020 11:20:41 +0200 Subject: [PATCH 3/3] Support RESTeasy 4.0 version in unit tests - code review follow-up --- .../jaxrs/v2_0/AbstractRequestContextInstrumentation.java | 4 ++++ .../jaxrs/v2_0/DefaultRequestContextInstrumentation.java | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java index b31ed7c6c224..534419f24bc8 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/AbstractRequestContextInstrumentation.java @@ -81,6 +81,10 @@ public static Span createOrUpdateAbortSpan( Span serverSpan = BaseTracer.getCurrentServerSpan(); Span currentSpan = TRACER.getCurrentSpan(); + // if there's no current span or it's the same as the server (servlet) span we need to start + // a JAX-RS one + // in other case, DefaultRequestContextInstrumentation must have already run so it's enough + // to just update the names if (currentSpan == null || currentSpan == serverSpan) { return TRACER.startSpan(resourceClass, method); } else { diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java index 13bfc241ae19..051d545abb4e 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/src/main/java/io/opentelemetry/instrumentation/auto/jaxrs/v2_0/DefaultRequestContextInstrumentation.java @@ -55,10 +55,8 @@ public static void createGenericSpan( // can only be aborted inside the filter method } - span = RequestFilterHelper.createOrUpdateAbortSpan(context, filterClass, method); - if (span != null) { - scope = TRACER.startScope(span); - } + span = TRACER.startSpan(filterClass, method); + scope = TRACER.startScope(span); } }