-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JAX-RS ApplicationPath annotation (#2824)
- Loading branch information
Showing
52 changed files
with
845 additions
and
89 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...entation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/jaxrs-2.0-arquillian-testing.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
ext { | ||
skipPublish = true | ||
} | ||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
// add repo for org.gradle:gradle-tooling-api which org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-gradle-depchain depends on | ||
repositories { | ||
maven { url 'https://repo.gradle.org/gradle/libs-releases' } | ||
} | ||
|
||
dependencies { | ||
compileOnly "javax:javaee-api:7.0" | ||
|
||
api project(':testing-common') | ||
implementation deps.opentelemetryApi | ||
|
||
def arquillianVersion = '1.4.0.Final' | ||
implementation "org.jboss.arquillian.junit:arquillian-junit-container:${arquillianVersion}" | ||
implementation "org.jboss.arquillian.protocol:arquillian-protocol-servlet:${arquillianVersion}" | ||
implementation 'org.jboss.arquillian.spock:arquillian-spock-container:1.0.0.CR1' | ||
api "org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-gradle-depchain:3.1.3" | ||
} |
82 changes: 82 additions & 0 deletions
82
...on/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/main/groovy/ArquillianRestTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import static io.opentelemetry.api.trace.SpanKind.SERVER | ||
|
||
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification | ||
import io.opentelemetry.instrumentation.test.utils.OkHttpUtils | ||
import okhttp3.HttpUrl | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import org.jboss.arquillian.container.test.api.Deployment | ||
import org.jboss.arquillian.container.test.api.RunAsClient | ||
import org.jboss.arquillian.spock.ArquillianSputnik | ||
import org.jboss.arquillian.test.api.ArquillianResource | ||
import org.jboss.shrinkwrap.api.ShrinkWrap | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset | ||
import org.jboss.shrinkwrap.api.spec.WebArchive | ||
import org.junit.runner.RunWith | ||
import spock.lang.Unroll | ||
import test.CdiRestResource | ||
import test.EjbRestResource | ||
import test.RestApplication | ||
|
||
@RunWith(ArquillianSputnik) | ||
@RunAsClient | ||
abstract class ArquillianRestTest extends AgentInstrumentationSpecification { | ||
|
||
static OkHttpClient client = OkHttpUtils.client() | ||
|
||
@ArquillianResource | ||
static URI url | ||
|
||
@Deployment | ||
static WebArchive createDeployment() { | ||
return ShrinkWrap.create(WebArchive) | ||
.addClass(RestApplication) | ||
.addClass(CdiRestResource) | ||
.addClass(EjbRestResource) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") | ||
} | ||
|
||
def getContextRoot() { | ||
return url.getPath() | ||
} | ||
|
||
@Unroll | ||
def "test #path"() { | ||
when: | ||
Request request = new Request.Builder().url(HttpUrl.get(url.resolve(path))).build() | ||
Response response = client.newCall(request).execute() | ||
|
||
then: | ||
response.withCloseable { | ||
assert response.code() == 200 | ||
assert response.body().string() == "hello" | ||
true | ||
} | ||
|
||
and: | ||
assertTraces(1) { | ||
trace(0, 2) { | ||
span(0) { | ||
name getContextRoot() + path | ||
kind SERVER | ||
hasNoParent() | ||
} | ||
span(1) { | ||
name className + ".hello" | ||
childOf span(0) | ||
} | ||
} | ||
} | ||
|
||
where: | ||
path | className | ||
"rest-app/cdiHello" | "CdiRestResource" | ||
"rest-app/ejbHello" | "EjbRestResource" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...umentation/jaxrs/jaxrs-2.0/jaxrs-2.0-arquillian-testing/src/test/resources/arquillian.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<arquillian xmlns="http://jboss.org/schema/arquillian" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation=" | ||
http://jboss.org/schema/arquillian | ||
http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> | ||
|
||
<defaultProtocol type="Servlet 3.0" /> | ||
|
||
<container qualifier="wildfly-embedded" default="true"> | ||
<configuration> | ||
<property name="jbossHome">build/server/wildfly-18.0.0.Final</property> | ||
<property name="modulePath">build/server/wildfly-18.0.0.Final/modules</property> | ||
</configuration> | ||
</container> | ||
</arquillian> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../opentelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfRsHttpListenerInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; | ||
|
||
import static java.util.Collections.singletonMap; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.api.jaxrs.JaxrsContextPath; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
// TomEE specific instrumentation | ||
public class CxfRsHttpListenerInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.apache.openejb.server.cxf.rs.CxfRsHttpListener"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return singletonMap( | ||
isMethod().and(named("doInvoke")), | ||
CxfRsHttpListenerInstrumentation.class.getName() + "$InvokeAdvice"); | ||
} | ||
|
||
public static class InvokeAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.FieldValue("pattern") String pattern, @Advice.Local("otelScope") Scope scope) { | ||
Context context = JaxrsContextPath.init(Java8BytecodeBridge.currentContext(), pattern); | ||
if (context != null) { | ||
scope = context.makeCurrent(); | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void stopSpan(@Advice.Local("otelScope") Scope scope) { | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...entelemetry/javaagent/instrumentation/jaxrs/v2_0/CxfServletControllerInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.jaxrs.v2_0; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge; | ||
import io.opentelemetry.javaagent.instrumentation.api.jaxrs.JaxrsContextPath; | ||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import javax.servlet.http.HttpServletRequest; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class CxfServletControllerInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.apache.cxf.transport.servlet.ServletController"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return Collections.singletonMap( | ||
isMethod() | ||
.and(isPublic()) | ||
.and(named("invokeDestination")) | ||
.and(takesArgument(0, named("javax.servlet.http.HttpServletRequest"))), | ||
CxfServletControllerInstrumentation.class.getName() + "$InvokeAdvice"); | ||
} | ||
|
||
public static class InvokeAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.Argument(0) HttpServletRequest httpServletRequest, | ||
@Advice.Local("otelScope") Scope scope) { | ||
Context context = | ||
JaxrsContextPath.init( | ||
Java8BytecodeBridge.currentContext(), httpServletRequest.getServletPath()); | ||
if (context != null) { | ||
scope = context.makeCurrent(); | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void stopSpan(@Advice.Local("otelScope") Scope scope) { | ||
if (scope != null) { | ||
scope.close(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/groovy/CxfJettyHttpServerTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
class CxfJettyHttpServerTest extends JaxRsJettyHttpServerTest { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-cxf-3.2/javaagent/src/test/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app version="3.0" metadata-complete="false" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://java.sun.com/xml/ns/javaee" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> | ||
|
||
<servlet> | ||
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name> | ||
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class> | ||
<init-param> | ||
<param-name>javax.ws.rs.Application</param-name> | ||
<param-value>test.JaxRsApplicationPathTestApplication</param-value> | ||
</init-param> | ||
<async-supported>true</async-supported> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>CXFNonSpringJaxrsServlet</servlet-name> | ||
<url-pattern>/rest-app/*</url-pattern> | ||
</servlet-mapping> | ||
</web-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.