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

Add instrumentation for jax-ws frameworks #2314

Merged
merged 5 commits into from
Feb 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply from: "$rootDir/gradle/instrumentation.gradle"

muzzle {
pass {
group = "org.apache.axis2"
module = "axis2-jaxws"
versions = "[1.6.0,)"
assertInverse = true
skipVersions += ['1.2', '1.3']
}
}

configurations {
// axis has a dependency on servlet api, get rid of it
all*.exclude group: 'javax.servlet', module: 'servlet-api'
}

dependencies {
implementation project(':instrumentation:jaxws:jaxws-2.0-axis2-1.6:library')

def axis2Version = '1.6.0'
library group: 'org.apache.axis2', name: 'axis2-jaxws', version: axis2Version
testLibrary group: 'org.apache.axis2', name: 'axis2-transport-http', version: axis2Version
testLibrary group: 'org.apache.axis2', name: 'axis2-transport-local', version: axis2Version

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

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

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

testImplementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.11'
testImplementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.2.11'
testImplementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.11'

testImplementation group: 'com.sun.xml.ws', name: 'jaxws-rt', version: '2.2.8'
testImplementation group: 'com.sun.xml.ws', name: 'jaxws-tools', version: '2.2.8'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.axis2;

import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.Collections;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class Axis2InstrumentationModule extends InstrumentationModule {
public Axis2InstrumentationModule() {
super("axis2", "axis2-1.6");
}

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
// class added in 1.6.0
return hasClassesNamed("org.apache.axis2.jaxws.api.MessageAccessor");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new InvocationListenerRegistryTypeInstrumentation());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.axis2;

import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isTypeInitializer;
import static net.bytebuddy.matcher.ElementMatchers.named;

import io.opentelemetry.instrumentation.axis2.TracingInvocationListenerFactory;
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;
import org.apache.axis2.jaxws.registry.InvocationListenerRegistry;

public class InvocationListenerRegistryTypeInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher<? super TypeDescription> typeMatcher() {
return named("org.apache.axis2.jaxws.registry.InvocationListenerRegistry");
}

@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
isTypeInitializer(),
InvocationListenerRegistryTypeInstrumentation.class.getName() + "$ClassInitializerAdvice");
}

public static class ClassInitializerAdvice {

@Advice.OnMethodExit(suppress = Throwable.class)
public static void onExit() {
InvocationListenerRegistry.addFactory(new TracingInvocationListenerFactory());
}
}
}
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 Axis2JaxWsTest extends AbstractJaxWsTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package test;

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 ArrayList<String> getClassesInWebInfDirectory(File file) {
// help axis find our webservice classes
return new ArrayList<>(Arrays.asList("hello.HelloService", "hello.HelloServiceImpl"));
}
}