From 013269ab2cea740ffff0fc26059d5fd68220c689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A7=E6=80=9D?= Date: Tue, 20 Aug 2024 20:31:18 +0800 Subject: [PATCH 1/2] support mongo 4.10.x connection pool instrumentation --- .../DefaultConnectionPoolInstrumentation.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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..6eaee107a728 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,8 +29,16 @@ 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") public static class SingleResultCallbackAdvice { @@ -40,4 +48,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); + } + } } From dacd69a8e13f1370bd1c7c9817efa05d1e416a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=A7=E6=80=9D?= Date: Tue, 20 Aug 2024 21:53:43 +0800 Subject: [PATCH 2/2] spotless apply --- .../mongo/v4_0/DefaultConnectionPoolInstrumentation.java | 1 - 1 file changed, 1 deletion(-) 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 6eaee107a728..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 @@ -38,7 +38,6 @@ public void transform(TypeTransformer transformer) { this.getClass().getName() + "$OperationContextWithSingleResultCallbackAdvice"); } - @SuppressWarnings("unused") public static class SingleResultCallbackAdvice {