Skip to content

Commit 505a657

Browse files
committed
fix
1 parent 3f7a0e9 commit 505a657

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseInstrumentationModule.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public boolean isIndyReady() {
5252

5353
@Override
5454
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
55-
// core-io 1.0.0 (java-client 2.0.0) includes CouchbaseAsyncBucket; 1.6.0 (java-client 2.6.0)
56-
// adds CertAuthenticator, so exclude the newer line handled by couchbase-2.6.
55+
// core-io 1.x (java-client 2.x) exposes CouchbaseAsyncBucket, removed in the 3.x line.
5756
return hasClassesNamed("com.couchbase.client.java.CouchbaseAsyncBucket")
58-
.and(not(hasClassesNamed("com.couchbase.client.java.auth.CertAuthenticator")));
57+
// core-io 2.1.0 (java-client 3.1.0) introduces TracingIdentifiers; let 3.x modules handle those.
58+
.and(not(hasClassesNamed("com.couchbase.client.core.cnc.TracingIdentifiers")));
5959
}
6060
}

instrumentation/couchbase/couchbase-2.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_6/CouchbaseInstrumentationModule.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
99
import static java.util.Arrays.asList;
10+
import static net.bytebuddy.matcher.ElementMatchers.not;
1011

1112
import com.google.auto.service.AutoService;
1213
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1314
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1415
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
16+
import java.lang.reflect.Method;
1517
import java.util.List;
1618
import net.bytebuddy.matcher.ElementMatcher;
1719

@@ -25,10 +27,11 @@ public CouchbaseInstrumentationModule() {
2527

2628
@Override
2729
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
28-
// core-io 1.0.0 (java-client 2.0.0) exposes CouchbaseAsyncBucket and 1.6.0 (java-client 2.6.0)
29-
// adds CertAuthenticator, capturing the updated authentication stack.
30-
return hasClassesNamed("com.couchbase.client.java.CouchbaseAsyncBucket")
31-
.and(hasClassesNamed("com.couchbase.client.java.auth.CertAuthenticator"));
30+
// core-io 1.6.0 (java-client 2.6.0) introduces BucketClosedException, the lower bound here.
31+
return hasClassesNamed("com.couchbase.client.core.BucketClosedException")
32+
.and(classLoaderHasOperationId())
33+
// core-io 2.1.0 (java-client 3.1.0) adds TracingIdentifiers, handled by the 3.x modules.
34+
.and(not(hasClassesNamed("com.couchbase.client.core.cnc.TracingIdentifiers")));
3235
}
3336

3437
@Override
@@ -45,4 +48,26 @@ public String getModuleGroup() {
4548
public boolean isIndyReady() {
4649
return true;
4750
}
51+
52+
private static ElementMatcher.Junction<ClassLoader> classLoaderHasOperationId() {
53+
return new ElementMatcher.Junction.AbstractBase<ClassLoader>() {
54+
@Override
55+
public boolean matches(ClassLoader classLoader) {
56+
try {
57+
Class<?> requestClass =
58+
classLoader.loadClass("com.couchbase.client.core.message.CouchbaseRequest");
59+
for (Method method : requestClass.getMethods()) {
60+
if (method.getName().equals("operationId")
61+
&& method.getParameterCount() == 0
62+
&& method.getReturnType() == String.class) {
63+
return true;
64+
}
65+
}
66+
} catch (Throwable ignored) {
67+
// fall through and signal that the method is not available
68+
}
69+
return false;
70+
}
71+
};
72+
}
4873
}

instrumentation/couchbase/couchbase-3.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v3_1/CouchbaseInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
3131
// instrumenting it instead of each individual JVM artifact if this becomes unmaintainable.
3232
return hasClassesNamed("com.couchbase.client.core.cnc.TracingIdentifiers")
3333
// core-io 2.1.6 (java-client 3.1.6) adds AbstractManagerSupport, so exclude it here.
34-
.and(not(hasClassesNamed("com.couchbase.client.core.manager.AbstractManagerSupport")));
34+
.and(not(hasClassesNamed("com.couchbase.client.core.manager.AbstractManagerSupport")))
35+
// core-io 2.2.0 (java-client 3.2.0) adds RequestSpan$StatusCode, which the 3.2 module owns.
36+
.and(not(hasClassesNamed("com.couchbase.client.core.cnc.RequestSpan$StatusCode")))
37+
// core-io 2.4.0 (java-client 3.4.0) adds CoreTransactionRequest, which the 3.4 module owns.
38+
.and(
39+
not(
40+
hasClassesNamed(
41+
"com.couchbase.client.core.transaction.components.CoreTransactionRequest")));
3542
}
3643

3744
@Override

0 commit comments

Comments
 (0)