Updates based on pull request comments
MODIFY
dd-java-agent/instrumentation/couchbase-2.0/couchbase-2.0.gradle
dd-java-agent/instrumentation/couchbase-2.0/couchbase-2.0.gradle
@@ -47,6 +47,7 @@ configurations {
testArtifacts
}
+// Create test artifacts so couchbase-2.6 can reuse tests
artifacts {
testArtifacts testJar
}

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
@@ -34,16 +34,10 @@ public class CouchbaseCoreInstrumentation extends Instrumenter.Default {
return named("com.couchbase.client.core.CouchbaseCore");
}
- @Override
- public String[] helperClassNames() {
- return new String[] {packageName + ".CouchbaseRequestState"};
- }
-
@Override
public Map<String, String> contextStore() {
return Collections.singletonMap(
- "com.couchbase.client.core.message.CouchbaseRequest",
- CouchbaseRequestState.class.getName());
+ "com.couchbase.client.core.message.CouchbaseRequest", Span.class.getName());
}
@Override
@@ -66,16 +60,14 @@ public class CouchbaseCoreInstrumentation extends Instrumenter.Default {
// 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, CouchbaseRequestState> contextStore =
- InstrumentationContext.get(CouchbaseRequest.class, CouchbaseRequestState.class);
-
- CouchbaseRequestState state = contextStore.get(request);
+ final ContextStore<CouchbaseRequest, Span> contextStore =
+ InstrumentationContext.get(CouchbaseRequest.class, Span.class);
- if (state == null) {
- final Span span = GlobalTracer.get().activeSpan();
+ Span span = contextStore.get(request);
- state = new CouchbaseRequestState(span);
- contextStore.put(request, state);
+ if (span == null) {
+ span = GlobalTracer.get().activeSpan();
+ contextStore.put(request, span);
if (request.operationId() != null) {
span.setTag("couchbase.operation_id", request.operationId());

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
@@ -34,16 +34,10 @@ public class CouchbaseNetworkInstrumentation extends Instrumenter.Default {
return safeHasSuperType(named("com.couchbase.client.core.endpoint.AbstractGenericHandler"));
}
- @Override
- public String[] helperClassNames() {
- return new String[] {packageName + ".CouchbaseRequestState"};
- }
-
@Override
public Map<String, String> contextStore() {
return Collections.singletonMap(
- "com.couchbase.client.core.message.CouchbaseRequest",
- CouchbaseRequestState.class.getName());
+ "com.couchbase.client.core.message.CouchbaseRequest", Span.class.getName());
}
@Override
@@ -51,12 +45,12 @@ public class CouchbaseNetworkInstrumentation extends Instrumenter.Default {
// encode(ChannelHandlerContext ctx, REQUEST msg, List<Object> out)
return singletonMap(
isMethod()
+ .and(named("encode"))
.and(takesArguments(3))
.and(
takesArgument(
0, named("com.couchbase.client.deps.io.netty.channel.ChannelHandlerContext")))
- .and(takesArgument(2, named("java.util.List")))
- .and(named("encode")),
+ .and(takesArgument(2, named("java.util.List"))),
CouchbaseNetworkAdvice.class.getName());
}
@@ -67,13 +61,11 @@ 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, CouchbaseRequestState> contextStore =
- InstrumentationContext.get(CouchbaseRequest.class, CouchbaseRequestState.class);
-
- final CouchbaseRequestState state = contextStore.get(request);
- if (state != null) {
- final Span span = state.getSpan();
+ final ContextStore<CouchbaseRequest, Span> contextStore =
+ InstrumentationContext.get(CouchbaseRequest.class, Span.class);
+ final Span span = contextStore.get(request);
+ if (span != null) {
Tags.PEER_HOSTNAME.set(span, remoteHostname);
final int splitIndex = remoteSocket.lastIndexOf(":");

DELETE
dd-java-agent/instrumentation/couchbase-2.6/src/main/java/datadog/trace/instrumentation/couchbase/client/CouchbaseRequestState.java
-package datadog.trace.instrumentation.couchbase.client;
-
-import io.opentracing.Span;
-import lombok.Data;
-import lombok.NonNull;
-
-@Data
-public class CouchbaseRequestState {
- @NonNull public Span span;
-}

Updates based on pull request comments