Update elasticsearch to new agent api
MODIFY
dd-java-agent/instrumentation/elasticsearch/rest-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/Elasticsearch5RestClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/rest-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/Elasticsearch5RestClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch5;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchRestClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -11,9 +13,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -59,25 +60,25 @@ public class Elasticsearch5RestClientInstrumentation extends Instrumenter.Defaul
public static class ElasticsearchRestClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final String method,
@Advice.Argument(1) final String endpoint,
@Advice.Argument(value = 5, readOnly = false) ResponseListener responseListener) {
- final Scope scope =
- GlobalTracer.get().buildSpan("elasticsearch.rest.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), method, endpoint);
+ final AgentSpan span = startSpan("elasticsearch.rest.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, method, endpoint);
- responseListener = new RestResponseListener(responseListener, scope.span());
- return scope;
+ responseListener = new RestResponseListener(responseListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/rest-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/RestResponseListener.java
dd-java-agent/instrumentation/elasticsearch/rest-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/RestResponseListener.java
@@ -2,16 +2,16 @@ package datadog.trace.instrumentation.elasticsearch5;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchRestClientDecorator.DECORATE;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;
public class RestResponseListener implements ResponseListener {
private final ResponseListener listener;
- private final Span span;
+ private final AgentSpan span;
- public RestResponseListener(final ResponseListener listener, final Span span) {
+ public RestResponseListener(final ResponseListener listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
}

MODIFY
dd-java-agent/instrumentation/elasticsearch/rest-6.4/src/main/java/datadog/trace/instrumentation/elasticsearch6_4/Elasticsearch6RestClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/rest-6.4/src/main/java/datadog/trace/instrumentation/elasticsearch6_4/Elasticsearch6RestClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch6_4;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchRestClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -11,9 +13,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -59,24 +60,24 @@ public class Elasticsearch6RestClientInstrumentation extends Instrumenter.Defaul
public static class ElasticsearchRestClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final Request request,
@Advice.Argument(value = 1, readOnly = false) ResponseListener responseListener) {
- final Scope scope =
- GlobalTracer.get().buildSpan("elasticsearch.rest.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), request.getMethod(), request.getEndpoint());
+ final AgentSpan span = startSpan("elasticsearch.rest.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, request.getMethod(), request.getEndpoint());
- responseListener = new RestResponseListener(responseListener, scope.span());
- return scope;
+ responseListener = new RestResponseListener(responseListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/rest-6.4/src/main/java/datadog/trace/instrumentation/elasticsearch6_4/RestResponseListener.java
dd-java-agent/instrumentation/elasticsearch/rest-6.4/src/main/java/datadog/trace/instrumentation/elasticsearch6_4/RestResponseListener.java
package datadog.trace.instrumentation.elasticsearch6_4;
+import datadog.trace.instrumentation.api.AgentSpan;
import datadog.trace.instrumentation.elasticsearch.ElasticsearchRestClientDecorator;
-import io.opentracing.Span;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseListener;
public class RestResponseListener implements ResponseListener {
private final ResponseListener listener;
- private final Span span;
+ private final AgentSpan span;
- public RestResponseListener(final ResponseListener listener, final Span span) {
+ public RestResponseListener(final ResponseListener listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
}

MODIFY
dd-java-agent/instrumentation/elasticsearch/src/main/java/datadog/trace/instrumentation/elasticsearch/ElasticsearchRestClientDecorator.java
dd-java-agent/instrumentation/elasticsearch/src/main/java/datadog/trace/instrumentation/elasticsearch/ElasticsearchRestClientDecorator.java
@@ -2,7 +2,7 @@ package datadog.trace.instrumentation.elasticsearch;
import datadog.trace.agent.decorator.DatabaseClientDecorator;
import datadog.trace.api.DDSpanTypes;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import org.elasticsearch.client.Response;
@@ -45,16 +45,16 @@ public class ElasticsearchRestClientDecorator extends DatabaseClientDecorator {
return null;
}
- public Span onRequest(final Span span, final String method, final String endpoint) {
- Tags.HTTP_METHOD.set(span, method);
- Tags.HTTP_URL.set(span, endpoint);
+ public AgentSpan onRequest(final AgentSpan span, final String method, final String endpoint) {
+ span.setTag(Tags.HTTP_METHOD.getKey(), method);
+ span.setTag(Tags.HTTP_URL.getKey(), endpoint);
return span;
}
- public Span onResponse(final Span span, final Response response) {
+ public AgentSpan onResponse(final AgentSpan span, final Response response) {
if (response != null && response.getHost() != null) {
- Tags.PEER_HOSTNAME.set(span, response.getHost().getHostName());
- Tags.PEER_PORT.set(span, response.getHost().getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), response.getHost().getHostName());
+ span.setTag(Tags.PEER_PORT.getKey(), response.getHost().getPort());
}
return span;
}

MODIFY
dd-java-agent/instrumentation/elasticsearch/src/main/java/datadog/trace/instrumentation/elasticsearch/ElasticsearchTransportClientDecorator.java
dd-java-agent/instrumentation/elasticsearch/src/main/java/datadog/trace/instrumentation/elasticsearch/ElasticsearchTransportClientDecorator.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.elasticsearch;
import datadog.trace.agent.decorator.DatabaseClientDecorator;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.api.DDTags;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
public class ElasticsearchTransportClientDecorator extends DatabaseClientDecorator {
public static final ElasticsearchTransportClientDecorator DECORATE =
@@ -44,7 +44,7 @@ public class ElasticsearchTransportClientDecorator extends DatabaseClientDecorat
return null;
}
- public Span onRequest(final Span span, final Class action, final Class request) {
+ public AgentSpan onRequest(final AgentSpan span, final Class action, final Class request) {
if (action != null) {
span.setTag(DDTags.RESOURCE_NAME, action.getSimpleName());
span.setTag("elasticsearch.action", action.getSimpleName());

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-2/src/main/java/datadog/trace/instrumentation/elasticsearch2/Elasticsearch2TransportClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/transport-2/src/main/java/datadog/trace/instrumentation/elasticsearch2/Elasticsearch2TransportClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch2;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -10,9 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -67,25 +68,26 @@ public class Elasticsearch2TransportClientInstrumentation extends Instrumenter.D
public static class ElasticsearchTransportClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final Action action,
@Advice.Argument(1) final ActionRequest actionRequest,
@Advice.Argument(value = 2, readOnly = false)
ActionListener<ActionResponse> actionListener) {
- final Scope scope = GlobalTracer.get().buildSpan("elasticsearch.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), action.getClass(), actionRequest.getClass());
+ final AgentSpan span = startSpan("elasticsearch.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, action.getClass(), actionRequest.getClass());
- actionListener = new TransportActionListener<>(actionRequest, actionListener, scope.span());
- return scope;
+ actionListener = new TransportActionListener<>(actionRequest, actionListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-2/src/main/java/datadog/trace/instrumentation/elasticsearch2/TransportActionListener.java
dd-java-agent/instrumentation/elasticsearch/transport-2/src/main/java/datadog/trace/instrumentation/elasticsearch2/TransportActionListener.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.elasticsearch2;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import com.google.common.base.Joiner;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
@@ -19,10 +19,10 @@ import org.elasticsearch.action.support.nodes.BaseNodesResponse;
public class TransportActionListener<T extends ActionResponse> implements ActionListener<T> {
private final ActionListener<T> listener;
- private final Span span;
+ private final AgentSpan span;
public TransportActionListener(
- final ActionRequest actionRequest, final ActionListener<T> listener, final Span span) {
+ final ActionRequest actionRequest, final ActionListener<T> listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
onRequest(actionRequest);
@@ -49,9 +49,9 @@ public class TransportActionListener<T extends ActionResponse> implements Action
@Override
public void onResponse(final T response) {
if (response.remoteAddress() != null) {
- Tags.PEER_HOSTNAME.set(span, response.remoteAddress().getHost());
- Tags.PEER_HOST_IPV4.set(span, response.remoteAddress().getAddress());
- Tags.PEER_PORT.set(span, response.remoteAddress().getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), response.remoteAddress().getHost());
+ span.setTag(Tags.PEER_HOST_IPV4.getKey(), response.remoteAddress().getAddress());
+ span.setTag(Tags.PEER_PORT.getKey(), response.remoteAddress().getPort());
}
if (response instanceof GetResponse) {

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-5.3/src/main/java/datadog/trace/instrumentation/elasticsearch5_3/Elasticsearch53TransportClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/transport-5.3/src/main/java/datadog/trace/instrumentation/elasticsearch5_3/Elasticsearch53TransportClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch5_3;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -10,9 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -68,25 +69,26 @@ public class Elasticsearch53TransportClientInstrumentation extends Instrumenter.
public static class ElasticsearchTransportClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final Action action,
@Advice.Argument(1) final ActionRequest actionRequest,
@Advice.Argument(value = 2, readOnly = false)
ActionListener<ActionResponse> actionListener) {
- final Scope scope = GlobalTracer.get().buildSpan("elasticsearch.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), action.getClass(), actionRequest.getClass());
+ final AgentSpan span = startSpan("elasticsearch.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, action.getClass(), actionRequest.getClass());
- actionListener = new TransportActionListener<>(actionRequest, actionListener, scope.span());
- return scope;
+ actionListener = new TransportActionListener<>(actionRequest, actionListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-5.3/src/main/java/datadog/trace/instrumentation/elasticsearch5_3/TransportActionListener.java
dd-java-agent/instrumentation/elasticsearch/transport-5.3/src/main/java/datadog/trace/instrumentation/elasticsearch5_3/TransportActionListener.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.elasticsearch5_3;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import com.google.common.base.Joiner;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
@@ -21,10 +21,10 @@ import org.elasticsearch.action.support.replication.ReplicationResponse;
public class TransportActionListener<T extends ActionResponse> implements ActionListener<T> {
private final ActionListener<T> listener;
- private final Span span;
+ private final AgentSpan span;
public TransportActionListener(
- final ActionRequest actionRequest, final ActionListener<T> listener, final Span span) {
+ final ActionRequest actionRequest, final ActionListener<T> listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
onRequest(actionRequest);
@@ -52,9 +52,9 @@ public class TransportActionListener<T extends ActionResponse> implements Action
@Override
public void onResponse(final T response) {
if (response.remoteAddress() != null) {
- Tags.PEER_HOSTNAME.set(span, response.remoteAddress().getHost());
- Tags.PEER_HOST_IPV4.set(span, response.remoteAddress().getAddress());
- Tags.PEER_PORT.set(span, response.remoteAddress().getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), response.remoteAddress().getHost());
+ span.setTag(Tags.PEER_HOST_IPV4.getKey(), response.remoteAddress().getAddress());
+ span.setTag(Tags.PEER_PORT.getKey(), response.remoteAddress().getPort());
}
if (response instanceof GetResponse) {

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/Elasticsearch5TransportClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/transport-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/Elasticsearch5TransportClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch5;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -10,9 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -67,25 +68,26 @@ public class Elasticsearch5TransportClientInstrumentation extends Instrumenter.D
public static class ElasticsearchTransportClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final Action action,
@Advice.Argument(1) final ActionRequest actionRequest,
@Advice.Argument(value = 2, readOnly = false)
ActionListener<ActionResponse> actionListener) {
- final Scope scope = GlobalTracer.get().buildSpan("elasticsearch.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), action.getClass(), actionRequest.getClass());
+ final AgentSpan span = startSpan("elasticsearch.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, action.getClass(), actionRequest.getClass());
- actionListener = new TransportActionListener<>(actionRequest, actionListener, scope.span());
- return scope;
+ actionListener = new TransportActionListener<>(actionRequest, actionListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/TransportActionListener.java
dd-java-agent/instrumentation/elasticsearch/transport-5/src/main/java/datadog/trace/instrumentation/elasticsearch5/TransportActionListener.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.elasticsearch5;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import com.google.common.base.Joiner;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
@@ -21,10 +21,10 @@ import org.elasticsearch.action.support.replication.ReplicationResponse;
public class TransportActionListener<T extends ActionResponse> implements ActionListener<T> {
private final ActionListener<T> listener;
- private final Span span;
+ private final AgentSpan span;
public TransportActionListener(
- final ActionRequest actionRequest, final ActionListener<T> listener, final Span span) {
+ final ActionRequest actionRequest, final ActionListener<T> listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
onRequest(actionRequest);
@@ -51,9 +51,9 @@ public class TransportActionListener<T extends ActionResponse> implements Action
@Override
public void onResponse(final T response) {
if (response.remoteAddress() != null) {
- Tags.PEER_HOSTNAME.set(span, response.remoteAddress().getHost());
- Tags.PEER_HOST_IPV4.set(span, response.remoteAddress().getAddress());
- Tags.PEER_PORT.set(span, response.remoteAddress().getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), response.remoteAddress().getHost());
+ span.setTag(Tags.PEER_HOST_IPV4.getKey(), response.remoteAddress().getAddress());
+ span.setTag(Tags.PEER_PORT.getKey(), response.remoteAddress().getPort());
}
if (response instanceof GetResponse) {

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-6/src/main/java/datadog/trace/instrumentation/elasticsearch6/Elasticsearch6TransportClientInstrumentation.java
dd-java-agent/instrumentation/elasticsearch/transport-6/src/main/java/datadog/trace/instrumentation/elasticsearch6/Elasticsearch6TransportClientInstrumentation.java
package datadog.trace.instrumentation.elasticsearch6;
+import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
+import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
@@ -10,9 +12,8 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.instrumentation.api.AgentScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
@@ -71,25 +72,26 @@ public class Elasticsearch6TransportClientInstrumentation extends Instrumenter.D
public static class Elasticsearch6TransportClientAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
- public static Scope startSpan(
+ public static AgentScope onEnter(
@Advice.Argument(0) final Action action,
@Advice.Argument(1) final ActionRequest actionRequest,
@Advice.Argument(value = 2, readOnly = false)
ActionListener<ActionResponse> actionListener) {
- final Scope scope = GlobalTracer.get().buildSpan("elasticsearch.query").startActive(false);
- DECORATE.afterStart(scope.span());
- DECORATE.onRequest(scope.span(), action.getClass(), actionRequest.getClass());
+ final AgentSpan span = startSpan("elasticsearch.query");
+ DECORATE.afterStart(span);
+ DECORATE.onRequest(span, action.getClass(), actionRequest.getClass());
- actionListener = new TransportActionListener<>(actionRequest, actionListener, scope.span());
- return scope;
+ actionListener = new TransportActionListener<>(actionRequest, actionListener, span);
+
+ return activateSpan(span, false);
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void stopSpan(
- @Advice.Enter final Scope scope, @Advice.Thrown final Throwable throwable) {
+ @Advice.Enter final AgentScope scope, @Advice.Thrown final Throwable throwable) {
if (throwable != null) {
- final Span span = scope.span();
+ final AgentSpan span = scope.span();
DECORATE.onError(span, throwable);
DECORATE.beforeFinish(span);
span.finish();

MODIFY
dd-java-agent/instrumentation/elasticsearch/transport-6/src/main/java/datadog/trace/instrumentation/elasticsearch6/TransportActionListener.java
dd-java-agent/instrumentation/elasticsearch/transport-6/src/main/java/datadog/trace/instrumentation/elasticsearch6/TransportActionListener.java
@@ -3,7 +3,7 @@ package datadog.trace.instrumentation.elasticsearch6;
import static datadog.trace.instrumentation.elasticsearch.ElasticsearchTransportClientDecorator.DECORATE;
import com.google.common.base.Joiner;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ActionRequest;
@@ -25,10 +25,10 @@ import org.elasticsearch.action.support.replication.ReplicationResponse;
public class TransportActionListener<T extends ActionResponse> implements ActionListener<T> {
private final ActionListener<T> listener;
- private final Span span;
+ private final AgentSpan span;
public TransportActionListener(
- final ActionRequest actionRequest, final ActionListener<T> listener, final Span span) {
+ final ActionRequest actionRequest, final ActionListener<T> listener, final AgentSpan span) {
this.listener = listener;
this.span = span;
onRequest(actionRequest);
@@ -56,9 +56,9 @@ public class TransportActionListener<T extends ActionResponse> implements Action
@Override
public void onResponse(final T response) {
if (response.remoteAddress() != null) {
- Tags.PEER_HOSTNAME.set(span, response.remoteAddress().address().getHostName());
- Tags.PEER_HOST_IPV4.set(span, response.remoteAddress().getAddress());
- Tags.PEER_PORT.set(span, response.remoteAddress().getPort());
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), response.remoteAddress().address().getHostName());
+ span.setTag(Tags.PEER_HOST_IPV4.getKey(), response.remoteAddress().getAddress());
+ span.setTag(Tags.PEER_PORT.getKey(), response.remoteAddress().getPort());
}
if (response instanceof GetResponse) {

Update elasticsearch to new agent api