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 93% 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..b2c24aa615e9 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 @@ -82,7 +82,10 @@ public static SpanWithScope createOrUpdateAbortSpan( Span parent = BaseTracer.getCurrentServerSpan(); Span span = TRACER.getCurrentSpan(); - if (span == null) { + // in case of impl -> default order: span == parent (never null!) and no span is created + // in case of default -> impl order: span is always created by default, updated here + // TODO: how to fix that properly? + if (span == null || span == parent) { span = TRACER.startSpan(resourceClass, method); return new SpanWithScope(span, currentContextWith(span)); } else { 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 100% 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 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 100% 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 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 100% 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 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..b699ac8aa7bd 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 @@ -12,7 +12,17 @@ muzzle { 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' + library 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' + + latestDepTestLibrary group: 'io.dropwizard', name: 'dropwizard-testing', version: '1.+' } 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..46359f6f2456 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 @@ -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/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..c7910cf50b5c 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 @@ -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/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 74d650e2fcbc..c254dee12ea1 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 { @@ -190,42 +183,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 99% 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 index 1202f3ff7f9a..0a02adf7b96d 100644 --- 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 @@ -14,6 +14,7 @@ * limitations under the License. */ + import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.ERROR import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.EXCEPTION import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM 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 2dd34ac42d06..54e8047a41f8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -100,10 +100,11 @@ include ':instrumentation:java-concurrent' include ':instrumentation:java-concurrent:kotlin-testing' include ':instrumentation:java-concurrent:scala-testing' 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'