-
-
Notifications
You must be signed in to change notification settings - Fork 808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Agent creation with common dependencies : LinkageError #1723
Comments
Instead of |
Nop it doesn't work, the error probably comes from the fact that I'm using |
Yes, indeed on a second look the problem is likely that you contain vertx in your agent and that the handler class is loaded twice. What you need to do: exclude the vertx dependencies from your agent, and avoid calling the vertx classes from it. You should only depend on it for compiling the advice and defining the helper classes. Resolving the advice is already handled by Byte Buddy, but in your transform method, you will also need to inject the helper class. You can do so by using a |
I think what I'm looking for is something resembling as a dynamic invocation mechanism as described in the AssignReturned chapter: https://www.elastic.co/fr/blog/embracing-invokedynamic-to-tame-class-loaders-in-java-agents . I already have the shared class loader part with :
but now when I run the agent in the application, I get a java.lang.NoClassDefFoundError problem when the application tries to create a class that implements Handler I think the answer is around Just to clarify, in the latest version of bytebuddy, is the
I'm afraid I'm trying to use it the wrong way. |
If you run with the latest version of Byte Buddy, you can add: |
I maybe find a solution:
Now I'm facing an other issue,
It's quite logical, given that I'm instrumenting with the agent jar which doesn't have the dependencies, so on retransformation the classes aren't inlined. Is there any way of defining a class loading strategy? I don't think that's the right method, I suppose it's better to create a strategy that injects the ClassLoader used in the Advice method into as sub ClassLoader, and avoid conflict I believe there is Here an example of my code : https://github.com/allemas/bytecodr-for-vertx/blob/main/vert-x-instrumentation/src/main/java/com/byteprofile/InstrumentFactory.java |
Did you try |
I've just realized that I wasn't in the latest version of Bytebuddy my bad. I've just added the method, it works better but I still have an exception.
Instrumentation is fine :
But I get an exception when the application executes the code:
However, in the class I display the classloader and it's really quarkus's :(
And I got
Thank you so much for taking the time to help me. I truly appreciate your input and effort in supporting my experiments. |
Of course. Quarkus is using Graal native image and class loaders behave a bit different there. Does this work without Quarkus? The injection targets the contextual class loader. |
Sorry for the delay! Yes, it seems to work as I expect. I guess with Quarkus we have a classloader issue, that when we execute the agent, the modified class is not dynamically loaded yet. |
Hello,
I'm trying to instrument the vert.x context to manually add the span trace as OpenTelemetry does.
I'm facing a classpath error that I can't fix correctly.
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'io.vertx.core.Handler com.byteprofile.bytecodr.agent.instrumentation.vertx.HandlerWrapper.wrap(io.vertx.core.Handler)' the class loader io.quarkus.bootstrap.runner.RunnerClassLoader @386f0da3 of the current class, io/vertx/ext/web/impl/RouteImpl, and the class loader 'app' for the method's defining class, com/byteprofile/bytecodr/agent/instrumentation/vertx/HandlerWrapper, have different Class objects for the type io/vertx/core/Handler used in the signature (io.vertx.ext.web.impl.RouteImpl is in unnamed module of loader io.quarkus.bootstrap.runner.RunnerClassLoader @386f0da3, parent loader 'app'; com.byteprofile.bytecodr.agent.instrumentation.vertx.HandlerWrapper is in unnamed module of loader 'app')
In the OTEL repository the
HandlerWrapper
implementHandler<T>
. who's a vertx dependency.I'm quite sure I should isolate classpath for agent and quarkus, is this really the right thing to do? Do you have some examples or pointers ?
Here my ByteBuddy agent, maybe I miss something ?
Thank you very much for your time
The text was updated successfully, but these errors were encountered: