Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix instrumentation for latest axis2 #13490

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id("otel.javaagent-testing")
}

dependencies {
val axis2Version = "1.6.0"
testLibrary("org.apache.axis2:axis2-jaxws:$axis2Version")
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")

testImplementation(project(":instrumentation:jaxws:jaxws-2.0-common-testing"))

testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent"))

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent"))

testImplementation("javax.xml.bind:jaxb-api:2.2.11")
testImplementation("com.sun.xml.bind:jaxb-core:2.2.11")
testImplementation("com.sun.xml.bind:jaxb-impl:2.2.11")

testImplementation("com.sun.xml.ws:jaxws-rt:2.2.8")
testImplementation("com.sun.xml.ws:jaxws-tools:2.2.8")

latestDepTestLibrary("org.apache.axis2:axis2-jaxws:1.+") // see jaxws-3.0-axis2-1.6-testing module
latestDepTestLibrary("org.apache.axis2:axis2-transport-http:1.+") // see jaxws-3.0-axis2-1.6-testing module
latestDepTestLibrary("org.apache.axis2:axis2-transport-local:1.+") // see jaxws-3.0-axis2-1.6-testing module
}

configurations.configureEach {
if (name.contains("test")) {
// axis has a dependency on servlet2 api, get rid of it - otherwise the servlet3 instrumentation
// will fail during tests
exclude("javax.servlet", "servlet-api")
}
}

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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,11 @@ muzzle {
}
}

configurations.configureEach {
if (name.contains("test")) {
// axis has a dependency on servlet2 api, get rid of it - otherwise the servlet3 instrumentation
// will fail during tests
exclude("javax.servlet", "servlet-api")
}
}

dependencies {
bootstrap(project(":instrumentation:servlet:servlet-common:bootstrap"))

val axis2Version = "1.6.0"
library("org.apache.axis2:axis2-jaxws:$axis2Version")
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")

testImplementation(project(":instrumentation:jaxws:jaxws-2.0-common-testing"))

testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent"))

testImplementation("javax.xml.bind:jaxb-api:2.2.11")
testImplementation("com.sun.xml.bind:jaxb-core:2.2.11")
testImplementation("com.sun.xml.bind:jaxb-impl:2.2.11")

testImplementation("com.sun.xml.ws:jaxws-rt:2.2.8")
testImplementation("com.sun.xml.ws:jaxws-tools:2.2.8")
}
library("org.apache.axis2:axis2-jaxws:1.6.0")

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")
compileOnly(project(":muzzle"))
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath;
import javax.servlet.http.HttpServletRequest;
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;
import org.apache.axis2.jaxws.core.MessageContext;

public final class Axis2ServerSpanNaming {
private static final Class<?> JAVAX_REQUEST = loadClass("javax.servlet.http.HttpServletRequest");
private static final Class<?> JAKARTA_REQUEST =
loadClass("jakarta.servlet.http.HttpServletRequest");

public static void updateServerSpan(Context context, Axis2Request axis2Request) {
Span serverSpan = LocalRootSpan.fromContextOrNull(context);
Expand All @@ -22,17 +25,34 @@ public static void updateServerSpan(Context context, Axis2Request axis2Request)

String spanName = axis2Request.spanName();
MessageContext message = axis2Request.message();
HttpServletRequest request =
(HttpServletRequest) message.getMEPContext().get("transport.http.servletRequest");
Object request = message.getMEPContext().get("transport.http.servletRequest");
if (request != null) {
String servletPath = request.getServletPath();
if (!servletPath.isEmpty()) {
String servletPath = getServletPath(request);
if (servletPath != null && !servletPath.isEmpty()) {
spanName = servletPath + "/" + spanName;
}
}

serverSpan.updateName(ServletContextPath.prepend(context, spanName));
}

private static Class<?> loadClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException exception) {
return null;
}
}

@NoMuzzle
private static String getServletPath(Object request) {
if (JAVAX_REQUEST != null && JAVAX_REQUEST.isInstance(request)) {
return ((javax.servlet.http.HttpServletRequest) request).getServletPath();
} else if (JAKARTA_REQUEST != null && JAKARTA_REQUEST.isInstance(request)) {
return ((jakarta.servlet.http.HttpServletRequest) request).getServletPath();
}
return null;
}

private Axis2ServerSpanNaming() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id("otel.javaagent-testing")
}

dependencies {
val axis2Version = "2.0.0"
testLibrary("org.apache.axis2:axis2-jaxws:$axis2Version") {
exclude(group = "org.eclipse.jetty.ee9")
}
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")

testImplementation(project(":instrumentation:jaxws:jaxws-3.0-common-testing"))

testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-axis2-1.6: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 {
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.axis2;

import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.AbstractJaxWs3Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

class Axis2JaxWs2Test extends AbstractJaxWs3Test {
static {
try {
updateConfiguration();
} catch (IOException exception) {
throw new IllegalStateException(exception);
}
}

private static void updateConfiguration() throws IOException {
// read default configuration file inside axis2 jar
String configuration =
IOUtils.toString(
Axis2JaxWs2Test.class.getClassLoader().getResourceAsStream("axis2.xml"),
StandardCharsets.UTF_8);

// customize deployer so axis2 can find our services
configuration =
configuration.replace(
"org.apache.axis2.jaxws.framework.JAXWSDeployer", CustomJaxWsDeployer.class.getName());
configuration =
configuration.replace(
"<!--<parameter name=\"servicePath\">services</parameter>-->",
"<parameter name=\"servicePath\">ws</parameter>");
configuration =
configuration.replace(
"<parameter name=\"useGeneratedWSDLinJAXWS\">false</parameter>",
"<parameter name=\"useGeneratedWSDLinJAXWS\">true</parameter>");
configuration = configuration.replace("<module ref=\"addressing\"/>", "");

File configurationDirectory = new File("build/axis-conf/");
configurationDirectory.mkdirs();
FileUtils.writeStringToFile(
new File(configurationDirectory, "axis2.xml"), configuration, StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.axis2;

import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloService;
import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloServiceImpl;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.axis2.jaxws.framework.JAXWSDeployer;

// used in axis2.xml
public class CustomJaxWsDeployer extends JAXWSDeployer {

@Override
protected void deployServicesInWARClassPath() {
this.axisConfig.getParameter("artifactsDIR").setValue(new File("build/axis2/"));
super.deployServicesInWARClassPath();
}

@Override
@SuppressWarnings("NonApiType") // errorprone bug that it doesn't recognize this is an override
protected ArrayList<String> getClassesInWebInfDirectory(File file) {
// help axis find our webservice classes
return new ArrayList<>(
Arrays.asList(HelloService.class.getName(), HelloServiceImpl.class.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
axis requires WEB-INF/classes to exist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
axis requires WEB-INF/lib to exist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<init-param>
<param-name>axis2.xml.path</param-name>
<!-- this configuration file is generated by test -->
<param-value>build/axis-conf/axis2.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>

</web-app>
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,5 @@ otelJava {
}

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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ otelJava {

tasks.withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED")
jvmArgs("--add-exports=java.xml/com.sun.org.apache.xerces.internal.jaxp=ALL-UNNAMED")
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ include(":instrumentation:jaxrs-client:jaxrs-client-2.0-testing")
include(":instrumentation:jaxws:jaxws-2.0:javaagent")
include(":instrumentation:jaxws:jaxws-2.0-arquillian-testing")
include(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent")
include(":instrumentation:jaxws:jaxws-2.0-axis2-1.6-testing")
include(":instrumentation:jaxws:jaxws-2.0-common-testing")
include(":instrumentation:jaxws:jaxws-2.0-metro-2.2-testing")
include(":instrumentation:jaxws:jaxws-2.0-tomee-testing")
include(":instrumentation:jaxws:jaxws-2.0-wildfly-testing")
include(":instrumentation:jaxws:jaxws-3.0-axis2-1.6-testing")
include(":instrumentation:jaxws:jaxws-3.0-common-testing")
include(":instrumentation:jaxws:jaxws-3.0-cxf-4.0-testing")
include(":instrumentation:jaxws:jaxws-3.0-metro-2.2-testing")
Expand Down
Loading