I want to register the business logic classes used by the extension module with the bootstrap class loader. #12046
-
I'm experiencing a similar issue. Even after registering the helper class, there is an issue where the extension class loader and the application class loader are different, causing the newly added values to not be read after object creation. It seems like I need to load my custom Java code into the bootstrap class loader. Is there another way to do this? I found that the AgentInstaller.setBootstrapPackages method is available in the opentelemetry-java-instrumentation source code. Is this the correct way to load classes from a package into the bootstrap class loader? Also, I noticed that the Constants.BOOTSTRAP_PACKAGE_PREFIXES class defines properties like io.opentelemetry.javaagent.bootstrap. If this is correct, could you please explain how to use it? Alternatively, I want to call the Instrumentation.appendToBootstrapClassLoaderSearch method to directly register a JAR file with the bootstrap class loader. Is there a way to obtain the Instrumentation object when writing an extension module? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Not really. This method is useful when there are class loaders that don't delegate all requests to boot loader (e.g. OSGI) Using this method ensures that boot delegation will happen for given packages. This method on its own does not add anything to boot loader.
There is https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/InstrumentationHolder.java but it is a private api that can be removed in future versions without prior notice. Alternatively instead of an extension you could build a custom distro where you can more easily add classes to boot loader. We have some plans for reworking the extension mechanism that, when ready, should allow extension to more easily call into agent code. |
Beta Was this translation helpful? Give feedback.
-
@laurit got it. I tried using the InstrumentationHolder.getInstrumentation().appendToBootstrapClassLoaderSearch to add it, but it doesn't seem to be recognized correctly. Is this a ByteBuddy recognition issue?? If you save the data to a specific class in typeTransformer.applyAdviceToMethod and then declare it in the method annotated with @Advice.onMethodEnter, it seems that the MethodParameterRepository or UtilCache, etc classes cannot be found.
I'll look for a better solution and wait. I hope the plan you mentioned will be implemented soon. |
Beta Was this translation helpful? Give feedback.
When implementing only the extension module, I encountered a class loader issue. Since the problem couldn't be resolved, I cloned the project from https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/distro and resolved the issue by restructuring the agent.jar file