Skip to content

How to share an instance between the Java Agent and the target Application #7042

Answered by laurit
adinauer asked this question in Q&A
Discussion options

You must be logged in to vote

Application and extension are loaded in different class loaders, you can not directly read a field in application code from an extension. To share an object you'll have to place it in a class loader that is visible to both the application and the extension, that would be the boot loader. Unfortunately this currently can't be easily done with an extension. There is a sample for it in the custom distro, see https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/examples/distro/bootstrap/src/main/java/com/example/javaagent/bootstrap. Alternatively if the application class that you wish to access is accessible though system class loader you could use Class.forName with…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by adinauer
Comment options

You must be logged in to vote
1 reply
@jianwu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants