Update couchbase-2.6 to new agent api
MODIFY
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseCoreInstrumentation.java
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseCoreInstrumentation.java
package datadog.trace.instrumentation.couchbase.client;
+import static datadog.trace.instrumentation.api.AgentTracer.activeScope;
+import static datadog.trace.instrumentation.api.AgentTracer.activeSpan;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -11,9 +13,8 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
-import io.opentracing.Scope;
-import io.opentracing.Span;
-import io.opentracing.util.GlobalTracer;
+import datadog.trace.context.TraceScope;
+import datadog.trace.instrumentation.api.AgentSpan;
import java.util.Collections;
import java.util.Map;
import net.bytebuddy.asm.Advice;
@@ -36,7 +37,7 @@ public class CouchbaseCoreInstrumentation extends Instrumenter.Default {
@Override
public Map<String, String> contextStore() {
return Collections.singletonMap(
- "com.couchbase.client.core.message.CouchbaseRequest", Span.class.getName());
+ "com.couchbase.client.core.message.CouchbaseRequest", AgentSpan.class.getName());
}
@Override
@@ -54,18 +55,18 @@ public class CouchbaseCoreInstrumentation extends Instrumenter.Default {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void addOperationIdToSpan(@Advice.Argument(0) final CouchbaseRequest request) {
- final Scope scope = GlobalTracer.get().scopeManager().active();
+ final TraceScope scope = activeScope();
if (scope != null) {
// The scope from the initial rxJava subscribe is not available to the networking layer
// To transfer the span, the span is added to the context store
- final ContextStore<CouchbaseRequest, Span> contextStore =
- InstrumentationContext.get(CouchbaseRequest.class, Span.class);
+ final ContextStore<CouchbaseRequest, AgentSpan> contextStore =
+ InstrumentationContext.get(CouchbaseRequest.class, AgentSpan.class);
- Span span = contextStore.get(request);
+ AgentSpan span = contextStore.get(request);
if (span == null) {
- span = GlobalTracer.get().activeSpan();
+ span = activeSpan();
contextStore.put(request, span);
if (request.operationId() != null) {

MODIFY
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseNetworkInstrumentation.java
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseNetworkInstrumentation.java
@@ -13,7 +13,7 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.bootstrap.ContextStore;
import datadog.trace.bootstrap.InstrumentationContext;
-import io.opentracing.Span;
+import datadog.trace.instrumentation.api.AgentSpan;
import io.opentracing.tag.Tags;
import java.util.Collections;
import java.util.Map;
@@ -37,7 +37,7 @@ public class CouchbaseNetworkInstrumentation extends Instrumenter.Default {
@Override
public Map<String, String> contextStore() {
return Collections.singletonMap(
- "com.couchbase.client.core.message.CouchbaseRequest", Span.class.getName());
+ "com.couchbase.client.core.message.CouchbaseRequest", AgentSpan.class.getName());
}
@Override
@@ -61,17 +61,18 @@ public class CouchbaseNetworkInstrumentation extends Instrumenter.Default {
@Advice.FieldValue("remoteSocket") final String remoteSocket,
@Advice.FieldValue("localSocket") final String localSocket,
@Advice.Argument(1) final CouchbaseRequest request) {
- final ContextStore<CouchbaseRequest, Span> contextStore =
- InstrumentationContext.get(CouchbaseRequest.class, Span.class);
+ final ContextStore<CouchbaseRequest, AgentSpan> contextStore =
+ InstrumentationContext.get(CouchbaseRequest.class, AgentSpan.class);
- final Span span = contextStore.get(request);
+ final AgentSpan span = contextStore.get(request);
if (span != null) {
- Tags.PEER_HOSTNAME.set(span, remoteHostname);
+ span.setTag(Tags.PEER_HOSTNAME.getKey(), remoteHostname);
if (remoteSocket != null) {
final int splitIndex = remoteSocket.lastIndexOf(":");
if (splitIndex != -1) {
- Tags.PEER_PORT.set(span, Integer.valueOf(remoteSocket.substring(splitIndex + 1)));
+ span.setTag(
+ Tags.PEER_PORT.getKey(), Integer.parseInt(remoteSocket.substring(splitIndex + 1)));
}
}

Update couchbase-2.6 to new agent api