Some refactoring in tests
MODIFY
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/jax-rs-client-1.gradle
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/jax-rs-client-1.gradle
@@ -51,7 +51,7 @@ dependencies {
// testCompile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
// latestDepTestCompile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.27'
- latestDepTestCompile group: 'com.sun.jersey', name: 'jersey-client', version: jerseyClientVersion
+ latestDepTestCompile group: 'com.sun.jersey', name: 'jersey-client', version: '1.19.4'
// latestDepTestCompile group: 'org.apache.cxf', name: 'cxf-rt-rs-client', version: '3.2.6'
// latestDepTestCompile group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.0.26.Final'
}

MODIFY
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/InjectAdapter.java
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/InjectAdapter.java
package datadog.trace.instrumentation.jaxrs.v1;
import io.opentracing.propagation.TextMap;
-
-import javax.ws.rs.core.MultivaluedMap;
import java.util.Iterator;
import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
public final class InjectAdapter implements TextMap {
private final MultivaluedMap<String, Object> map;

MODIFY
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/JaxRsClientV1Decorator.java
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/JaxRsClientV1Decorator.java
@@ -3,11 +3,9 @@ package datadog.trace.instrumentation.jaxrs.v1;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import datadog.trace.agent.decorator.HttpClientDecorator;
-
import java.net.URI;
-public class JaxRsClientV1Decorator
- extends HttpClientDecorator<ClientRequest, ClientResponse> {
+public class JaxRsClientV1Decorator extends HttpClientDecorator<ClientRequest, ClientResponse> {
public static final JaxRsClientV1Decorator DECORATE = new JaxRsClientV1Decorator();
@Override

MODIFY
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/JaxRsClientV1Instrumentation.java
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/main/java/datadog/trace/instrumentation/jaxrs/v1/JaxRsClientV1Instrumentation.java
package datadog.trace.instrumentation.jaxrs.v1;
import static datadog.trace.agent.tooling.ByteBuddyElementMatchers.safeHasSuperType;
+import static datadog.trace.instrumentation.jaxrs.v1.JaxRsClientV1Decorator.DECORATE;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.returns;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
-import static datadog.trace.instrumentation.jaxrs.v1.JaxRsClientV1Decorator.DECORATE;
+
import com.google.auto.service.AutoService;
import com.sun.jersey.api.client.ClientHandler;
import com.sun.jersey.api.client.ClientRequest;
@@ -15,13 +17,11 @@ import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.propagation.Format;
import io.opentracing.util.GlobalTracer;
+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 static java.util.Collections.singletonMap;
-
-import java.util.Map;
@AutoService(Instrumenter.class)
public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
@@ -50,18 +50,22 @@ public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
+ System.out.println("######### REGISTERING");
return singletonMap(
named("handle")
- .and(takesArgument(2, named("com.sun.jersey.api.client.ClientRequest")))
- .and(returns(named("com.sun.jersey.api.client.ClientResponse"))),
- HandleAdvice.class.getName()
- );
+ .and(takesArgument(0, safeHasSuperType(named("com.sun.jersey.api.client.ClientRequest"))))
+ .and(returns(safeHasSuperType(named("com.sun.jersey.api.client.ClientResponse")))),
+ HandleAdvice.class.getName());
}
public static class HandleAdvice {
@Advice.OnMethodEnter
- public static void onEnter(@Advice.Argument(value = 1) final ClientRequest request, ClientHandler thisObj) {
+ public static void onEnter(
+ @Advice.Argument(value = 0) final ClientRequest request,
+ @Advice.This final ClientHandler thisObj) {
+
+ System.out.println("############ ON HANDLE ENTER");
// WARNING: this might be a chain...so we only have to trace the first in the chain.
boolean isRootClientHandler = null == request.getProperties().get("dd.span");
@@ -88,7 +92,13 @@ public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
}
@Advice.OnMethodExit
- public static void onExit(@Advice.Argument(value = 1) final ClientRequest request, ClientResponse response, ClientHandler thisObj) {
+ public static void onExit(
+ @Advice.Argument(value = 0) final ClientRequest request,
+ @Advice.Return final ClientResponse response,
+ @Advice.This final ClientHandler thisObj) {
+
+ System.out.println("############ ON HANDLE ENTER");
+
Span span = (Span) request.getProperties().get("dd.span");
if (null == span) {
return;

MODIFY
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/test/groovy/JaxRsClientV1Test.groovy
dd-java-agent/instrumentation/jax-rs-client/jax-rs-client-1/src/test/groovy/JaxRsClientV1Test.groovy
@@ -4,16 +4,16 @@ import com.sun.jersey.client.impl.ClientRequestImpl
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.instrumentation.jaxrs.v1.JaxRsClientV1Decorator
-abstract class JaxRsClientV1Test extends HttpClientTest<JaxRsClientV1Decorator> {
+class JaxRsClientV1Test extends HttpClientTest<JaxRsClientV1Decorator> {
@Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
-
Client client = Client.create()
def resource = client.resource(uri)
headers.each { resource.header(it.key, it.value) }
def body = BODY_METHODS.contains(method) ? new ClientRequestImpl(uri, method) : null
- ClientResponse response = resource.method(method, body)
+ ClientResponse response = resource.method(method, ClientResponse.class, body)
+ println "################## RESPOSNE #####################" + response
callback?.call()
return response.status

Some refactoring in tests