Update jax-rs-client-2.0 to new agent api
MODIFY
dd-java-agent/instrumentation/jax-rs-client-2.0/connection-error-handling-jersey/src/main/java/datadog/trace/instrumentation/connection_error/jersey/JerseyClientConnectionErrorInstrumentation.java
dd-java-agent/instrumentation/jax-rs-client-2.0/connection-error-handling-jersey/src/main/java/datadog/trace/instrumentation/connection_error/jersey/JerseyClientConnectionErrorInstrumentation.java
package datadog.trace.instrumentation.connection_error.jersey;
-import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -8,11 +7,8 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.jaxrs.ClientTracingFilter;
-import io.opentracing.Span;
-import io.opentracing.log.Fields;
-import io.opentracing.tag.Tags;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -66,10 +62,10 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
@Advice.Thrown final Throwable throwable) {
if (throwable != null) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(throwable);
span.finish();
}
}
@@ -119,10 +115,10 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
return wrapped.get();
} catch (final ExecutionException e) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(Fields.ERROR_OBJECT, e.getCause()));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(e.getCause());
span.finish();
}
throw e;
@@ -136,10 +132,10 @@ public final class JerseyClientConnectionErrorInstrumentation extends Instrument
return wrapped.get(timeout, unit);
} catch (final ExecutionException e) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(Fields.ERROR_OBJECT, e.getCause()));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(e.getCause());
span.finish();
}
throw e;

MODIFY
dd-java-agent/instrumentation/jax-rs-client-2.0/connection-error-handling-resteasy/src/main/java/datadog/trace/instrumentation/connection_error/resteasy/ResteasyClientConnectionErrorInstrumentation.java
dd-java-agent/instrumentation/jax-rs-client-2.0/connection-error-handling-resteasy/src/main/java/datadog/trace/instrumentation/connection_error/resteasy/ResteasyClientConnectionErrorInstrumentation.java
package datadog.trace.instrumentation.connection_error.resteasy;
-import static io.opentracing.log.Fields.ERROR_OBJECT;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -8,11 +7,8 @@ import static net.bytebuddy.matcher.ElementMatchers.returns;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.jaxrs.ClientTracingFilter;
-import io.opentracing.Span;
-import io.opentracing.log.Fields;
-import io.opentracing.tag.Tags;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@@ -66,10 +62,10 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
@Advice.Thrown final Throwable throwable) {
if (throwable != null) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(ERROR_OBJECT, throwable));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(throwable);
span.finish();
}
}
@@ -119,10 +115,10 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
return wrapped.get();
} catch (final ExecutionException e) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(Fields.ERROR_OBJECT, e.getCause()));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(e.getCause());
span.finish();
}
throw e;
@@ -136,10 +132,10 @@ public final class ResteasyClientConnectionErrorInstrumentation extends Instrume
return wrapped.get(timeout, unit);
} catch (final ExecutionException e) {
final Object prop = context.getProperty(ClientTracingFilter.SPAN_PROPERTY_NAME);
- if (prop instanceof Span) {
- final Span span = (Span) prop;
- Tags.ERROR.set(span, true);
- span.log(Collections.singletonMap(Fields.ERROR_OBJECT, e.getCause()));
+ if (prop instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) prop;
+ span.setError(true);
+ span.addThrowable(e.getCause());
span.finish();
}
throw e;

MODIFY
dd-java-agent/instrumentation/jax-rs-client-2.0/src/main/java/datadog/trace/instrumentation/jaxrs/ClientTracingFilter.java
dd-java-agent/instrumentation/jax-rs-client-2.0/src/main/java/datadog/trace/instrumentation/jaxrs/ClientTracingFilter.java
package datadog.trace.instrumentation.jaxrs;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.propagate;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
+import static datadog.trace.instrumentation.jaxrs.InjectAdapter.SETTER;
import static datadog.trace.instrumentation.jaxrs.JaxRsClientDecorator.DECORATE;
import datadog.trace.api.DDTags;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.propagation.Format;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.client.ClientRequestContext;
@@ -22,20 +24,14 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
@Override
public void filter(final ClientRequestContext requestContext) {
- final Span span =
- GlobalTracer.get()
- .buildSpan("jax-rs.client.call")
- .withTag(DDTags.RESOURCE_NAME, requestContext.getMethod() + " jax-rs.client.call")
- .start();
- try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
+ final AgentSpan span =
+ startSpan("jax-rs.client.call")
+ .setTag(DDTags.RESOURCE_NAME, requestContext.getMethod() + " jax-rs.client.call");
+ try (final AgentScope scope = activateSpan(span, false)) {
DECORATE.afterStart(span);
DECORATE.onRequest(span, requestContext);
- GlobalTracer.get()
- .inject(
- span.context(),
- Format.Builtin.HTTP_HEADERS,
- new InjectAdapter(requestContext.getHeaders()));
+ propagate().inject(span, requestContext, SETTER);
requestContext.setProperty(SPAN_PROPERTY_NAME, span);
}
@@ -45,8 +41,8 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
public void filter(
final ClientRequestContext requestContext, final ClientResponseContext responseContext) {
final Object spanObj = requestContext.getProperty(SPAN_PROPERTY_NAME);
- if (spanObj instanceof Span) {
- final Span span = (Span) spanObj;
+ if (spanObj instanceof AgentSpan) {
+ final AgentSpan span = (AgentSpan) spanObj;
DECORATE.onResponse(span, responseContext);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/jax-rs-client-2.0/src/main/java/datadog/trace/instrumentation/jaxrs/InjectAdapter.java
dd-java-agent/instrumentation/jax-rs-client-2.0/src/main/java/datadog/trace/instrumentation/jaxrs/InjectAdapter.java
package datadog.trace.instrumentation.jaxrs;
-import io.opentracing.propagation.TextMap;
-import java.util.Iterator;
-import java.util.Map;
-import javax.ws.rs.core.MultivaluedMap;
+import datadog.trace.instrumentation.api.AgentPropagation;
+import javax.ws.rs.client.ClientRequestContext;
-public final class InjectAdapter implements TextMap {
- private final MultivaluedMap<String, Object> map;
+public final class InjectAdapter implements AgentPropagation.Setter<ClientRequestContext> {
- public InjectAdapter(final MultivaluedMap<String, Object> map) {
- this.map = map;
- }
-
- @Override
- public Iterator<Map.Entry<String, String>> iterator() {
- throw new UnsupportedOperationException(
- "InjectAdapter should only be used with Tracer.inject()");
- }
+ public static final InjectAdapter SETTER = new InjectAdapter();
@Override
- public void put(final String key, final String value) {
+ public void set(final ClientRequestContext carrier, final String key, final String value) {
// Don't allow duplicates.
- map.putSingle(key, value);
+ carrier.getHeaders().putSingle(key, value);
}
}

Update jax-rs-client-2.0 to new agent api