-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for cxf 4.0 jaxws (#12077)
- Loading branch information
Showing
23 changed files
with
165 additions
and
46 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
...ent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.java
This file was deleted.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/build.gradle.kts
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,27 @@ | ||
plugins { | ||
id("otel.javaagent-testing") | ||
} | ||
|
||
dependencies { | ||
testLibrary("org.apache.cxf:cxf-rt-frontend-jaxws:4.0.0") | ||
testLibrary("org.apache.cxf:cxf-rt-transports-http:4.0.0") | ||
|
||
testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0") | ||
testImplementation(project(":instrumentation:jaxws:jaxws-3.0-common-testing")) | ||
|
||
testInstrumentation(project(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent")) | ||
|
||
testInstrumentation(project(":instrumentation:servlet:servlet-5.0:javaagent")) | ||
testInstrumentation(project(":instrumentation:jetty:jetty-11.0:javaagent")) | ||
} | ||
|
||
otelJava { | ||
minJavaVersionSupported.set(JavaVersion.VERSION_17) | ||
} | ||
|
||
tasks.withType<Test>().configureEach { | ||
// required on jdk17 | ||
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") | ||
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") | ||
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true") | ||
} |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/TestWsServlet.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,37 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import hello.HelloServiceImpl | ||
import io.opentelemetry.api.trace.Span | ||
import io.opentelemetry.context.Context | ||
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan | ||
import org.apache.cxf.jaxws.EndpointImpl | ||
import org.apache.cxf.message.Message | ||
import org.apache.cxf.phase.AbstractPhaseInterceptor | ||
import org.apache.cxf.phase.Phase | ||
import org.apache.cxf.transport.servlet.CXFNonSpringServlet | ||
|
||
import jakarta.servlet.ServletConfig | ||
|
||
class TestWsServlet extends CXFNonSpringServlet { | ||
@Override | ||
void loadBus(ServletConfig servletConfig) { | ||
super.loadBus(servletConfig) | ||
|
||
// publish test webservice | ||
Object implementor = new HelloServiceImpl() | ||
EndpointImpl endpoint = new EndpointImpl(bus, implementor) | ||
endpoint.publish("/HelloService") | ||
endpoint.getOutInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.SETUP) { | ||
@Override | ||
void handleMessage(Message message) { | ||
Context context = Context.current() | ||
if (LocalRootSpan.fromContext(context) != Span.fromContext(context)) { | ||
throw new IllegalStateException("handler span should be ended before outgoing interceptors") | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions
66
...ent/src/main/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfServerSpanNaming.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,66 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.cxf; | ||
|
||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; | ||
import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath; | ||
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle; | ||
|
||
public final class CxfServerSpanNaming { | ||
private static final Class<?> JAVAX_SERVLET_REQUEST = | ||
loadClass("javax.servlet.http.HttpServletRequest"); | ||
private static final Class<?> JAKARTA_SERVLET_REQUEST = | ||
loadClass("jakarta.servlet.http.HttpServletRequest"); | ||
|
||
private static Class<?> loadClass(String className) { | ||
try { | ||
return Class.forName(className); | ||
} catch (ClassNotFoundException exception) { | ||
return null; | ||
} | ||
} | ||
|
||
public static void updateServerSpanName(Context context, CxfRequest cxfRequest) { | ||
String spanName = cxfRequest.spanName(); | ||
if (spanName == null) { | ||
return; | ||
} | ||
|
||
Span serverSpan = LocalRootSpan.fromContextOrNull(context); | ||
if (serverSpan == null) { | ||
return; | ||
} | ||
|
||
Object request = cxfRequest.message().get("HTTP.REQUEST"); | ||
if (request != null) { | ||
String servletPath = null; | ||
if (JAVAX_SERVLET_REQUEST != null && JAVAX_SERVLET_REQUEST.isInstance(request)) { | ||
servletPath = getJavaxServletPath(request); | ||
} else if (JAKARTA_SERVLET_REQUEST != null && JAKARTA_SERVLET_REQUEST.isInstance(request)) { | ||
servletPath = getJakartaServletPath(request); | ||
} | ||
if (servletPath != null && !servletPath.isEmpty()) { | ||
spanName = servletPath + "/" + spanName; | ||
} | ||
} | ||
|
||
serverSpan.updateName(ServletContextPath.prepend(context, spanName)); | ||
} | ||
|
||
@NoMuzzle | ||
private static String getJavaxServletPath(Object request) { | ||
return ((javax.servlet.http.HttpServletRequest) request).getServletPath(); | ||
} | ||
|
||
@NoMuzzle | ||
private static String getJakartaServletPath(Object request) { | ||
return ((jakarta.servlet.http.HttpServletRequest) request).getServletPath(); | ||
} | ||
|
||
private CxfServerSpanNaming() {} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/CxfJaxWsTest.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,7 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
class CxfJaxWsTest extends AbstractJaxWsTest { | ||
} |
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/resources/test-app/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,17 @@ | ||
<?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>wsServlet</servlet-name> | ||
<servlet-class>TestWsServlet</servlet-class> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>wsServlet</servlet-name> | ||
<url-pattern>/ws/*</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