diff --git a/instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/DefaultConnectionPoolInstrumentation.java b/instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/DefaultConnectionPoolInstrumentation.java index 7b65e6ed7b82..bd68297dedfa 100644 --- a/instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/DefaultConnectionPoolInstrumentation.java +++ b/instrumentation/mongo/mongo-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/mongo/v4_0/DefaultConnectionPoolInstrumentation.java @@ -29,6 +29,13 @@ public void transform(TypeTransformer transformer) { named("getAsync") .and(takesArgument(0, named("com.mongodb.internal.async.SingleResultCallback"))), this.getClass().getName() + "$SingleResultCallbackAdvice"); + + // instrumentation needed since 4.10.x + transformer.applyAdviceToMethod( + named("getAsync") + .and(takesArgument(0, named("com.mongodb.internal.connection.OperationContext"))) + .and(takesArgument(1, named("com.mongodb.internal.async.SingleResultCallback"))), + this.getClass().getName() + "$OperationContextWithSingleResultCallbackAdvice"); } @SuppressWarnings("unused") @@ -40,4 +47,13 @@ public static void wrapCallback( callback = new SingleResultCallbackWrapper(Java8BytecodeBridge.currentContext(), callback); } } + + @SuppressWarnings("unused") + public static class OperationContextWithSingleResultCallbackAdvice { + @Advice.OnMethodEnter(suppress = Throwable.class) + public static void wrapCallback( + @Advice.Argument(value = 1, readOnly = false) SingleResultCallback callback) { + callback = new SingleResultCallbackWrapper(Java8BytecodeBridge.currentContext(), callback); + } + } }