Fix mongo latest dep tests
ADD
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/DefaultConnectionPoolInstrumentation.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.mongo.v4_0;
+
+import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
+
+import com.mongodb.internal.async.SingleResultCallback;
+import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
+import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
+import io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge;
+import net.bytebuddy.asm.Advice;
+import net.bytebuddy.description.type.TypeDescription;
+import net.bytebuddy.matcher.ElementMatcher;
+
+public class DefaultConnectionPoolInstrumentation implements TypeInstrumentation {
+ @Override
+ public ElementMatcher<TypeDescription> typeMatcher() {
+ return named("com.mongodb.internal.connection.DefaultConnectionPool");
+ }
+
+ @Override
+ public void transform(TypeTransformer transformer) {
+ // instrumentation needed since 4.3.0-beta3
+ transformer.applyAdviceToMethod(
+ named("getAsync")
+ .and(takesArgument(0, named("com.mongodb.internal.async.SingleResultCallback"))),
+ this.getClass().getName() + "$SingleResultCallbackAdvice");
+ }
+
+ public static class SingleResultCallbackAdvice {
+
+ @Advice.OnMethodEnter(suppress = Throwable.class)
+ public static void wrapCallback(
+ @Advice.Argument(value = 0, readOnly = false) SingleResultCallback<Object> callback) {
+ callback = new SingleResultCallbackWrapper(Java8BytecodeBridge.currentContext(), callback);
+ }
+ }
+}

MODIFY
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoClientInstrumentationModule.java
instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/MongoClientInstrumentationModule.java
@@ -24,6 +24,7 @@ public class MongoClientInstrumentationModule extends InstrumentationModule {
return asList(
new MongoClientSettingsBuilderInstrumentation(),
new InternalStreamConnectionInstrumentation(),
- new BaseClusterInstrumentation());
+ new BaseClusterInstrumentation(),
+ new DefaultConnectionPoolInstrumentation());
}
}

Fix mongo latest dep tests (#3333)