From f5b27c4f701deb34c5e6b22781a029ca52a6f0ad Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 13:49:26 +0200 Subject: [PATCH 01/12] Making module indy ready --- .../vaadin/VaadinInstrumentationModule.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinInstrumentationModule.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinInstrumentationModule.java index c680f9739f14..3e249f65c145 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinInstrumentationModule.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinInstrumentationModule.java @@ -11,11 +11,13 @@ import com.google.auto.service.AutoService; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule; import java.util.List; import net.bytebuddy.matcher.ElementMatcher; @AutoService(InstrumentationModule.class) -public class VaadinInstrumentationModule extends InstrumentationModule { +public class VaadinInstrumentationModule extends InstrumentationModule + implements ExperimentalInstrumentationModule { public VaadinInstrumentationModule() { super("vaadin", "vaadin-14.2"); @@ -38,4 +40,9 @@ public List typeInstrumentations() { new RpcInvocationHandlerInstrumentation(), new ClientCallableRpcInstrumentation()); } + + @Override + public boolean isIndyReady() { + return true; + } } From 82f280783b161da5231552638c7dc8967e9b2524 Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 14:06:33 +0200 Subject: [PATCH 02/12] Migrating VaadinServiceInstrumentation --- .../vaadin/VaadinServiceInstrumentation.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java index 70ea46c3699b..98cd9ee44ff6 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java @@ -14,6 +14,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.annotation.Nullable; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -38,33 +39,50 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleRequestAdvice { - @Advice.OnMethodEnter(suppress = Throwable.class) - public static void onEnter( - @Advice.This VaadinService vaadinService, - @Advice.Origin("#m") String methodName, - @Advice.Local("otelRequest") VaadinServiceRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { + public static class HandleRequestAdviceScope { + private final VaadinServiceRequest request; + private final Context context; + private final Scope scope; + + private HandleRequestAdviceScope(VaadinServiceRequest request, Context context, Scope scope) { + this.request = request; + this.context = context; + this.scope = scope; + } + + @Nullable + public static HandleRequestAdviceScope start(Class serviceClass, String methodName) { + VaadinServiceRequest request = VaadinServiceRequest.create(serviceClass, methodName); + Context context = helper().startVaadinServiceSpan(request); + if (context == null) { + return null; + } + Scope scope = context.makeCurrent(); + return new HandleRequestAdviceScope(request, context, scope); + } + + public void end(@Nullable Throwable throwable) { + scope.close(); - request = VaadinServiceRequest.create(vaadinService.getClass(), methodName); - context = helper().startVaadinServiceSpan(request); - if (context != null) { - scope = context.makeCurrent(); + helper().endVaadinServiceSpan(context, request, throwable); } } + @Advice.OnMethodEnter(suppress = Throwable.class) + public static HandleRequestAdviceScope onEnter( + @Advice.This VaadinService vaadinService, @Advice.Origin("#m") String methodName) { + + return HandleRequestAdviceScope.start(vaadinService.getClass(), methodName); + } + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( - @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") VaadinServiceRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (scope == null) { + @Advice.Thrown @Nullable Throwable throwable, + @Advice.Enter @Nullable HandleRequestAdviceScope adviceScope) { + if (adviceScope == null) { return; } - scope.close(); - - helper().endVaadinServiceSpan(context, request, throwable); + adviceScope.end(throwable); } } } From 9f2e5334b28a8c227337aec7df9831e3e3102a4f Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:00:21 +0200 Subject: [PATCH 03/12] Migrating RequestHandlerInstrumentation --- .../vaadin/RequestHandlerInstrumentation.java | 54 ++++++++++++------- .../vaadin/VaadinServiceInstrumentation.java | 1 + 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java index e9fdc51d63a0..3096c08a0bc8 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.annotation.Nullable; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -45,35 +46,52 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleRequestAdvice { + public static class HandleRequestAdviceScope { + private final VaadinHandlerRequest request; + private final Context context; + private final Scope scope; - @Advice.OnMethodEnter(suppress = Throwable.class) - public static void onEnter( - @Advice.This RequestHandler requestHandler, - @Advice.Origin("#m") String methodName, - @Advice.Local("otelRequest") VaadinHandlerRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { + private HandleRequestAdviceScope(VaadinHandlerRequest request, Context context, Scope scope) { + this.request = request; + this.context = context; + this.scope = scope; + } + + @Nullable + public static HandleRequestAdviceScope start(Class handlerClass, String methodName) { + VaadinHandlerRequest request = VaadinHandlerRequest.create(handlerClass, methodName); + Context context = helper().startRequestHandlerSpan(request); + if (context == null) { + return null; + } + Scope scope = context.makeCurrent(); + return new HandleRequestAdviceScope(request, context, scope); + } + + public void end(@Nullable Throwable throwable, boolean handled) { + scope.close(); - request = VaadinHandlerRequest.create(requestHandler.getClass(), methodName); - context = helper().startRequestHandlerSpan(request); - if (context != null) { - scope = context.makeCurrent(); + helper().endRequestHandlerSpan(context, request, throwable, handled); } } + @Nullable + @Advice.OnMethodEnter(suppress = Throwable.class) + public static HandleRequestAdviceScope onEnter( + @Advice.This RequestHandler requestHandler, @Advice.Origin("#m") String methodName) { + + return HandleRequestAdviceScope.start(requestHandler.getClass(), methodName); + } + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Thrown Throwable throwable, @Advice.Return boolean handled, - @Advice.Local("otelRequest") VaadinHandlerRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (scope == null) { + @Advice.Enter @Nullable HandleRequestAdviceScope adviceScope) { + if (adviceScope == null) { return; } - scope.close(); - - helper().endRequestHandlerSpan(context, request, throwable, handled); + adviceScope.end(throwable, handled); } } } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java index 98cd9ee44ff6..3aa4c288854c 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java @@ -68,6 +68,7 @@ public void end(@Nullable Throwable throwable) { } } + @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) public static HandleRequestAdviceScope onEnter( @Advice.This VaadinService vaadinService, @Advice.Origin("#m") String methodName) { From 9e3537d48e40d8f2c9b86f3a934bca8d6772cd94 Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:14:04 +0200 Subject: [PATCH 04/12] Migrating RpcInvocationHandlerInstrumentation --- .../RpcInvocationHandlerInstrumentation.java | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java index b98eddbd2e11..54c5ff5accee 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java @@ -18,6 +18,7 @@ import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.annotation.Nullable; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -48,37 +49,55 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleAdvice { + public static class HandleAdviceScope { + private final VaadinRpcRequest request; + private final Context context; + private final Scope scope; + + private HandleAdviceScope(VaadinRpcRequest request, Context context, Scope scope) { + this.request = request; + this.context = context; + this.scope = scope; + } + + @Nullable + public static HandleAdviceScope start( + RpcInvocationHandler handler, String methodName, JsonObject jsonObject) { + Context parentContext = Java8BytecodeBridge.currentContext(); + VaadinRpcRequest request = VaadinRpcRequest.create(handler, methodName, jsonObject); + if (!rpcInstrumenter().shouldStart(parentContext, request)) { + return null; + } + + Context context = rpcInstrumenter().start(parentContext, request); + Scope scope = context.makeCurrent(); + return new HandleAdviceScope(request, context, scope); + } + + public void end(@Nullable Throwable throwable) { + scope.close(); + + rpcInstrumenter().end(context, request, null, throwable); + } + } + + @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) - public static void onEnter( + public static HandleAdviceScope onEnter( @Advice.This RpcInvocationHandler rpcInvocationHandler, @Advice.Origin("#m") String methodName, - @Advice.Argument(1) JsonObject jsonObject, - @Advice.Local("otelRequest") VaadinRpcRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - - Context parentContext = Java8BytecodeBridge.currentContext(); - request = VaadinRpcRequest.create(rpcInvocationHandler, methodName, jsonObject); - if (!rpcInstrumenter().shouldStart(parentContext, request)) { - return; - } - - context = rpcInstrumenter().start(parentContext, request); - scope = context.makeCurrent(); + @Advice.Argument(1) JsonObject jsonObject) { + return HandleAdviceScope.start(rpcInvocationHandler, methodName, jsonObject); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( - @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") VaadinRpcRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (scope == null) { + @Advice.Thrown @Nullable Throwable throwable, + @Advice.Enter @Nullable HandleAdviceScope adviceScope) { + if (adviceScope == null) { return; } - scope.close(); - - rpcInstrumenter().end(context, request, null, throwable); + adviceScope.end(throwable); } } } From 033901257def40856e9ccaff9b001b2e7df3659e Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:21:07 +0200 Subject: [PATCH 05/12] Migrating ClientCallableRpcInstrumentation --- .../ClientCallableRpcInstrumentation.java | 61 ++++++++++++------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java index 0adc11abb889..b0a0412f0b48 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java @@ -14,6 +14,7 @@ import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import javax.annotation.Nullable; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -41,36 +42,54 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class InvokeMethodAdvice { - @Advice.OnMethodEnter(suppress = Throwable.class) - public static void onEnter( - @Advice.Argument(1) Class componentClass, - @Advice.Argument(2) String methodName, - @Advice.Local("otelRequest") VaadinClientCallableRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { + public static class InvokeMethodAdviceScope { + private final VaadinClientCallableRequest request; + private final Context context; + private final Scope scope; - Context parentContext = Java8BytecodeBridge.currentContext(); - request = VaadinClientCallableRequest.create(componentClass, methodName); - if (!clientCallableInstrumenter().shouldStart(parentContext, request)) { - return; + private InvokeMethodAdviceScope( + VaadinClientCallableRequest request, Context context, Scope scope) { + this.request = request; + this.context = context; + this.scope = scope; + } + + @Nullable + public static InvokeMethodAdviceScope start(Class componentClass, String methodName) { + Context parentContext = Java8BytecodeBridge.currentContext(); + VaadinClientCallableRequest request = + VaadinClientCallableRequest.create(componentClass, methodName); + if (!clientCallableInstrumenter().shouldStart(parentContext, request)) { + return null; + } + + Context context = clientCallableInstrumenter().start(parentContext, request); + Scope scope = context.makeCurrent(); + return new InvokeMethodAdviceScope(request, context, scope); } - context = clientCallableInstrumenter().start(parentContext, request); - scope = context.makeCurrent(); + public void end(@Nullable Throwable throwable) { + scope.close(); + + clientCallableInstrumenter().end(context, request, null, throwable); + } + } + + @Nullable + @Advice.OnMethodEnter(suppress = Throwable.class) + public static InvokeMethodAdviceScope onEnter( + @Advice.Argument(1) Class componentClass, @Advice.Argument(2) String methodName) { + return InvokeMethodAdviceScope.start(componentClass, methodName); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( - @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") VaadinClientCallableRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (scope == null) { + @Advice.Thrown @Nullable Throwable throwable, + @Advice.Enter @Nullable InvokeMethodAdviceScope adviceScope) { + if (adviceScope == null) { return; } - scope.close(); - - clientCallableInstrumenter().end(context, request, null, throwable); + adviceScope.end(throwable); } } } From cd7c7b76a4d226d3729ce460d6fc9df8f23f9720 Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Thu, 25 Sep 2025 15:25:04 +0200 Subject: [PATCH 06/12] Using Context.current() --- .../vaadin/ClientCallableRpcInstrumentation.java | 3 +-- .../vaadin/RpcInvocationHandlerInstrumentation.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java index b0a0412f0b48..5ca1547d9996 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java @@ -11,7 +11,6 @@ import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import javax.annotation.Nullable; @@ -56,7 +55,7 @@ private InvokeMethodAdviceScope( @Nullable public static InvokeMethodAdviceScope start(Class componentClass, String methodName) { - Context parentContext = Java8BytecodeBridge.currentContext(); + Context parentContext = Context.current(); VaadinClientCallableRequest request = VaadinClientCallableRequest.create(componentClass, methodName); if (!clientCallableInstrumenter().shouldStart(parentContext, request)) { diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java index 54c5ff5accee..24f78feb5d6a 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java @@ -15,7 +15,6 @@ import elemental.json.JsonObject; import io.opentelemetry.context.Context; import io.opentelemetry.context.Scope; -import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; import javax.annotation.Nullable; @@ -63,7 +62,7 @@ private HandleAdviceScope(VaadinRpcRequest request, Context context, Scope scope @Nullable public static HandleAdviceScope start( RpcInvocationHandler handler, String methodName, JsonObject jsonObject) { - Context parentContext = Java8BytecodeBridge.currentContext(); + Context parentContext = Context.current(); VaadinRpcRequest request = VaadinRpcRequest.create(handler, methodName, jsonObject); if (!rpcInstrumenter().shouldStart(parentContext, request)) { return null; From 984f8d25c4af9facb449d2cbfc7cfc397ebe69aa Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:09:04 +0200 Subject: [PATCH 07/12] Renaming advice scope types --- .../vaadin/ClientCallableRpcInstrumentation.java | 15 +++++++-------- .../vaadin/RequestHandlerInstrumentation.java | 14 +++++++------- .../RpcInvocationHandlerInstrumentation.java | 14 +++++++------- .../vaadin/VaadinServiceInstrumentation.java | 14 +++++++------- 4 files changed, 28 insertions(+), 29 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java index 5ca1547d9996..05d634efb25f 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java @@ -41,20 +41,19 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class InvokeMethodAdvice { - public static class InvokeMethodAdviceScope { + public static class AdviceScope { private final VaadinClientCallableRequest request; private final Context context; private final Scope scope; - private InvokeMethodAdviceScope( - VaadinClientCallableRequest request, Context context, Scope scope) { + private AdviceScope(VaadinClientCallableRequest request, Context context, Scope scope) { this.request = request; this.context = context; this.scope = scope; } @Nullable - public static InvokeMethodAdviceScope start(Class componentClass, String methodName) { + public static AdviceScope start(Class componentClass, String methodName) { Context parentContext = Context.current(); VaadinClientCallableRequest request = VaadinClientCallableRequest.create(componentClass, methodName); @@ -64,7 +63,7 @@ public static InvokeMethodAdviceScope start(Class componentClass, String meth Context context = clientCallableInstrumenter().start(parentContext, request); Scope scope = context.makeCurrent(); - return new InvokeMethodAdviceScope(request, context, scope); + return new AdviceScope(request, context, scope); } public void end(@Nullable Throwable throwable) { @@ -76,15 +75,15 @@ public void end(@Nullable Throwable throwable) { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) - public static InvokeMethodAdviceScope onEnter( + public static AdviceScope onEnter( @Advice.Argument(1) Class componentClass, @Advice.Argument(2) String methodName) { - return InvokeMethodAdviceScope.start(componentClass, methodName); + return AdviceScope.start(componentClass, methodName); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Thrown @Nullable Throwable throwable, - @Advice.Enter @Nullable InvokeMethodAdviceScope adviceScope) { + @Advice.Enter @Nullable AdviceScope adviceScope) { if (adviceScope == null) { return; } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java index 3096c08a0bc8..b6c6ff9c7777 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java @@ -46,26 +46,26 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleRequestAdvice { - public static class HandleRequestAdviceScope { + public static class AdviceScope { private final VaadinHandlerRequest request; private final Context context; private final Scope scope; - private HandleRequestAdviceScope(VaadinHandlerRequest request, Context context, Scope scope) { + private AdviceScope(VaadinHandlerRequest request, Context context, Scope scope) { this.request = request; this.context = context; this.scope = scope; } @Nullable - public static HandleRequestAdviceScope start(Class handlerClass, String methodName) { + public static AdviceScope start(Class handlerClass, String methodName) { VaadinHandlerRequest request = VaadinHandlerRequest.create(handlerClass, methodName); Context context = helper().startRequestHandlerSpan(request); if (context == null) { return null; } Scope scope = context.makeCurrent(); - return new HandleRequestAdviceScope(request, context, scope); + return new AdviceScope(request, context, scope); } public void end(@Nullable Throwable throwable, boolean handled) { @@ -77,17 +77,17 @@ public void end(@Nullable Throwable throwable, boolean handled) { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) - public static HandleRequestAdviceScope onEnter( + public static AdviceScope onEnter( @Advice.This RequestHandler requestHandler, @Advice.Origin("#m") String methodName) { - return HandleRequestAdviceScope.start(requestHandler.getClass(), methodName); + return AdviceScope.start(requestHandler.getClass(), methodName); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Thrown Throwable throwable, @Advice.Return boolean handled, - @Advice.Enter @Nullable HandleRequestAdviceScope adviceScope) { + @Advice.Enter @Nullable AdviceScope adviceScope) { if (adviceScope == null) { return; } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java index 24f78feb5d6a..a0a8c47cd7fa 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java @@ -48,19 +48,19 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleAdvice { - public static class HandleAdviceScope { + public static class AdviceScope { private final VaadinRpcRequest request; private final Context context; private final Scope scope; - private HandleAdviceScope(VaadinRpcRequest request, Context context, Scope scope) { + private AdviceScope(VaadinRpcRequest request, Context context, Scope scope) { this.request = request; this.context = context; this.scope = scope; } @Nullable - public static HandleAdviceScope start( + public static AdviceScope start( RpcInvocationHandler handler, String methodName, JsonObject jsonObject) { Context parentContext = Context.current(); VaadinRpcRequest request = VaadinRpcRequest.create(handler, methodName, jsonObject); @@ -70,7 +70,7 @@ public static HandleAdviceScope start( Context context = rpcInstrumenter().start(parentContext, request); Scope scope = context.makeCurrent(); - return new HandleAdviceScope(request, context, scope); + return new AdviceScope(request, context, scope); } public void end(@Nullable Throwable throwable) { @@ -82,17 +82,17 @@ public void end(@Nullable Throwable throwable) { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) - public static HandleAdviceScope onEnter( + public static AdviceScope onEnter( @Advice.This RpcInvocationHandler rpcInvocationHandler, @Advice.Origin("#m") String methodName, @Advice.Argument(1) JsonObject jsonObject) { - return HandleAdviceScope.start(rpcInvocationHandler, methodName, jsonObject); + return AdviceScope.start(rpcInvocationHandler, methodName, jsonObject); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Thrown @Nullable Throwable throwable, - @Advice.Enter @Nullable HandleAdviceScope adviceScope) { + @Advice.Enter @Nullable AdviceScope adviceScope) { if (adviceScope == null) { return; } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java index 3aa4c288854c..ec94bf45649a 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java @@ -39,26 +39,26 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class HandleRequestAdvice { - public static class HandleRequestAdviceScope { + public static class AdviceScope { private final VaadinServiceRequest request; private final Context context; private final Scope scope; - private HandleRequestAdviceScope(VaadinServiceRequest request, Context context, Scope scope) { + private AdviceScope(VaadinServiceRequest request, Context context, Scope scope) { this.request = request; this.context = context; this.scope = scope; } @Nullable - public static HandleRequestAdviceScope start(Class serviceClass, String methodName) { + public static AdviceScope start(Class serviceClass, String methodName) { VaadinServiceRequest request = VaadinServiceRequest.create(serviceClass, methodName); Context context = helper().startVaadinServiceSpan(request); if (context == null) { return null; } Scope scope = context.makeCurrent(); - return new HandleRequestAdviceScope(request, context, scope); + return new AdviceScope(request, context, scope); } public void end(@Nullable Throwable throwable) { @@ -70,16 +70,16 @@ public void end(@Nullable Throwable throwable) { @Nullable @Advice.OnMethodEnter(suppress = Throwable.class) - public static HandleRequestAdviceScope onEnter( + public static AdviceScope onEnter( @Advice.This VaadinService vaadinService, @Advice.Origin("#m") String methodName) { - return HandleRequestAdviceScope.start(vaadinService.getClass(), methodName); + return AdviceScope.start(vaadinService.getClass(), methodName); } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Thrown @Nullable Throwable throwable, - @Advice.Enter @Nullable HandleRequestAdviceScope adviceScope) { + @Advice.Enter @Nullable AdviceScope adviceScope) { if (adviceScope == null) { return; } From 777f46be78fea906774c32ee2691f97e52118019 Mon Sep 17 00:00:00 2001 From: Cesar Munoz <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:12:00 +0200 Subject: [PATCH 08/12] Keeping null check consistency --- .../vaadin/ClientCallableRpcInstrumentation.java | 5 ++--- .../vaadin/RequestHandlerInstrumentation.java | 5 ++--- .../vaadin/RpcInvocationHandlerInstrumentation.java | 5 ++--- .../instrumentation/vaadin/VaadinServiceInstrumentation.java | 5 ++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java index 05d634efb25f..d230fcc2d5f6 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java @@ -84,10 +84,9 @@ public static AdviceScope onEnter( public static void onExit( @Advice.Thrown @Nullable Throwable throwable, @Advice.Enter @Nullable AdviceScope adviceScope) { - if (adviceScope == null) { - return; + if (adviceScope != null) { + adviceScope.end(throwable); } - adviceScope.end(throwable); } } } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java index b6c6ff9c7777..d88bbd2a6eea 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java @@ -88,10 +88,9 @@ public static void onExit( @Advice.Thrown Throwable throwable, @Advice.Return boolean handled, @Advice.Enter @Nullable AdviceScope adviceScope) { - if (adviceScope == null) { - return; + if (adviceScope != null) { + adviceScope.end(throwable, handled); } - adviceScope.end(throwable, handled); } } } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java index a0a8c47cd7fa..5c76e65a3765 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java @@ -93,10 +93,9 @@ public static AdviceScope onEnter( public static void onExit( @Advice.Thrown @Nullable Throwable throwable, @Advice.Enter @Nullable AdviceScope adviceScope) { - if (adviceScope == null) { - return; + if (adviceScope != null) { + adviceScope.end(throwable); } - adviceScope.end(throwable); } } } diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java index ec94bf45649a..e49a980af4b6 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java @@ -80,10 +80,9 @@ public static AdviceScope onEnter( public static void onExit( @Advice.Thrown @Nullable Throwable throwable, @Advice.Enter @Nullable AdviceScope adviceScope) { - if (adviceScope == null) { - return; + if (adviceScope != null) { + adviceScope.end(throwable); } - adviceScope.end(throwable); } } } From a4547c48723c6f13570ef53ab548cfe456c472de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:26:45 +0200 Subject: [PATCH 09/12] Update instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .../vaadin/ClientCallableRpcInstrumentation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java index d230fcc2d5f6..814c714a70bb 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/ClientCallableRpcInstrumentation.java @@ -62,8 +62,7 @@ public static AdviceScope start(Class componentClass, String methodName) { } Context context = clientCallableInstrumenter().start(parentContext, request); - Scope scope = context.makeCurrent(); - return new AdviceScope(request, context, scope); + return new AdviceScope(request, context, context.makeCurrent()); } public void end(@Nullable Throwable throwable) { From 3b6665f27e48223b6ce794ffb4056dbac49d8b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:26:52 +0200 Subject: [PATCH 10/12] Update instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .../instrumentation/vaadin/RequestHandlerInstrumentation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java index d88bbd2a6eea..3da01b53bc29 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RequestHandlerInstrumentation.java @@ -64,8 +64,7 @@ public static AdviceScope start(Class handlerClass, String methodName) { if (context == null) { return null; } - Scope scope = context.makeCurrent(); - return new AdviceScope(request, context, scope); + return new AdviceScope(request, context, context.makeCurrent()); } public void end(@Nullable Throwable throwable, boolean handled) { From af23b89d2a5763878e59225a52100610f962a6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:26:59 +0200 Subject: [PATCH 11/12] Update instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .../vaadin/RpcInvocationHandlerInstrumentation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java index 5c76e65a3765..cff3decb558c 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/RpcInvocationHandlerInstrumentation.java @@ -69,8 +69,7 @@ public static AdviceScope start( } Context context = rpcInstrumenter().start(parentContext, request); - Scope scope = context.makeCurrent(); - return new AdviceScope(request, context, scope); + return new AdviceScope(request, context, context.makeCurrent()); } public void end(@Nullable Throwable throwable) { From 03d69835d631733aef7de42f26e451d82232b63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar?= <56847527+LikeTheSalad@users.noreply.github.com> Date: Fri, 26 Sep 2025 16:27:05 +0200 Subject: [PATCH 12/12] Update instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .../instrumentation/vaadin/VaadinServiceInstrumentation.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java index e49a980af4b6..bbf6e7a16758 100644 --- a/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java +++ b/instrumentation/vaadin-14.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vaadin/VaadinServiceInstrumentation.java @@ -57,8 +57,7 @@ public static AdviceScope start(Class serviceClass, String methodName) { if (context == null) { return null; } - Scope scope = context.makeCurrent(); - return new AdviceScope(request, context, scope); + return new AdviceScope(request, context, context.makeCurrent()); } public void end(@Nullable Throwable throwable) {