Jersey client 1.9 cleanup
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
-ext {
- jerseyClientVersion = '1.19.1'
-}
-
muzzle {
pass {
- group = "javax.ws.rs"
- module = "javax.ws.rs-api"
- versions = "[1.0,2.0)"
+ group = "com.sun.jersey"
+ module = "jersey-client"
+ versions = "[1.9,)"
+ // We can't assert inverse because 1.1.5.2 was a weird release that also works.
+ }
+ fail {
+ group = "com.sun.jersey"
+ module = "jersey-client"
+ versions = "[1.2,1.9)"
}
-// pass {
-// // We want to support the dropwizard clients too.
-// group = 'io.dropwizard'
-// module = 'dropwizard-client'
-// versions = "[0.8.0,)"
-// assertInverse = true
-// }
}
apply from: "${rootDir}/gradle/java.gradle"
@@ -28,9 +23,7 @@ testSets {
}
dependencies {
- compileOnly group: 'com.sun.jersey', name: 'jersey-client', version: jerseyClientVersion
- //compileOnly group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.0.1'
- //compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.2'
+ compileOnly group: 'com.sun.jersey', name: 'jersey-client', version: '1.9'
compile deps.bytebuddy
compile deps.opentracing
@@ -40,18 +33,8 @@ dependencies {
compile project(':dd-java-agent:agent-tooling')
testCompile project(':dd-java-agent:testing')
- testCompile project(':dd-java-agent:instrumentation:java-concurrent')
-
- testCompile group: 'com.sun.jersey', name: 'jersey-client', version: jerseyClientVersion
-
-// testCompile group: 'org.apache.cxf', name: 'cxf-rt-rs-client', version: '3.1.0'
- // Doesn't work with CXF 3.0.x because their context is wrong:
- // https://github.com/apache/cxf/commit/335c7bad2436f08d6d54180212df5a52157c9f21
-// testCompile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.3'
+ testCompile group: 'com.sun.jersey', name: 'jersey-client', version: '1.9'
-// latestDepTestCompile group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.27'
- 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'
+ latestDepTestCompile group: 'com.sun.jersey', name: 'jersey-client', version: '+'
}

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
@@ -15,6 +15,7 @@ import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.DDTags;
import io.opentracing.Scope;
import io.opentracing.Span;
+import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.util.GlobalTracer;
import java.util.Map;
@@ -48,7 +49,6 @@ 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(
@@ -61,54 +61,41 @@ public final class JaxRsClientV1Instrumentation extends Instrumenter.Default {
public static class HandleAdvice {
@Advice.OnMethodEnter
- public static void onEnter(
+ public static Scope onEnter(
@Advice.Argument(value = 0) final ClientRequest request,
@Advice.This final ClientHandler thisObj) {
// 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");
+ final boolean isRootClientHandler = null == request.getProperties().get("dd.span");
if (isRootClientHandler) {
+ final Tracer tracer = GlobalTracer.get();
final Span span =
- GlobalTracer.get()
+ tracer
.buildSpan("jax-rs.client.call")
.withTag(DDTags.RESOURCE_NAME, request.getMethod() + " jax-rs.client.call")
.start();
- try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
DECORATE.afterStart(span);
DECORATE.onRequest(span, request);
-
- GlobalTracer.get()
- .inject(
- span.context(),
- Format.Builtin.HTTP_HEADERS,
- new InjectAdapter(request.getHeaders()));
-
request.getProperties().put("dd.span", span);
- request.getProperties().put("dd.root.handler.hash", thisObj.hashCode());
- }
+
+ tracer.inject(
+ span.context(), Format.Builtin.HTTP_HEADERS, new InjectAdapter(request.getHeaders()));
+ return tracer.scopeManager().activate(span, true);
}
+ return null;
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
- @Advice.Argument(value = 0) final ClientRequest request,
+ @Advice.Enter final Scope scope,
@Advice.Return final ClientResponse response,
- @Advice.This final ClientHandler thisObj,
- @Advice.Thrown final Throwable throwable
- ) {
-
- Span span = (Span) request.getProperties().get("dd.span");
- if (null == span) {
- return;
- }
-
- request.getProperties().get("dd.root.handler.hash");
-
- if (thisObj.hashCode() == (Integer) request.getProperties().get("dd.root.handler.hash")) {
- // this is the root span, closing all the things
+ @Advice.Thrown final Throwable throwable) {
+ if (null != scope) {
+ final Span span = scope.span();
DECORATE.onResponse(span, response);
+ DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
- span.finish();
+ scope.close();
}
}
}

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
import com.sun.jersey.api.client.Client
import com.sun.jersey.api.client.ClientResponse
-import com.sun.jersey.client.impl.ClientRequestImpl
+import com.sun.jersey.api.client.filter.CsrfProtectionFilter
+import com.sun.jersey.api.client.filter.GZIPContentEncodingFilter
+import com.sun.jersey.api.client.filter.LoggingFilter
import datadog.trace.agent.test.base.HttpClientTest
import datadog.trace.instrumentation.jaxrs.v1.JaxRsClientV1Decorator
+import spock.lang.Shared
class JaxRsClientV1Test extends HttpClientTest<JaxRsClientV1Decorator> {
+ @Shared
+ Client client = Client.create()
+
+ def setupSpec() {
+ // Add filters to ensure spans aren't duplicated.
+ client.addFilter(new LoggingFilter())
+ client.addFilter(new GZIPContentEncodingFilter())
+ client.addFilter(new CsrfProtectionFilter())
+ }
+
@Override
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
- Client client = Client.create()
- def resource = client.resource(uri)
+ def resource = client.resource(uri).requestBuilder
headers.each { resource.header(it.key, it.value) }
- def body = BODY_METHODS.contains(method) ? new ClientRequestImpl(uri, method) : null
+ def body = BODY_METHODS.contains(method) ? "" : null
ClientResponse response = resource.method(method, ClientResponse.class, body)
callback?.call()

MODIFY
dd-java-agent/instrumentation/jax-rs-client/src/main/java/datadog/trace/instrumentation/jaxrs/ClientTracingFilter.java
dd-java-agent/instrumentation/jax-rs-client/src/main/java/datadog/trace/instrumentation/jaxrs/ClientTracingFilter.java
@@ -31,8 +31,6 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
DECORATE.afterStart(span);
DECORATE.onRequest(span, requestContext);
- log.debug("{} - client span started", span);
-
GlobalTracer.get()
.inject(
span.context(),
@@ -52,7 +50,6 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
DECORATE.onResponse(span, responseContext);
DECORATE.beforeFinish(span);
span.finish();
- log.debug("{} - client spanObj finished", spanObj);
}
}
}

Jersey client 1.9 cleanup