# How to understand Java Agent source

**URL:** <https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302>\
**Category:** APM\
**Tags:** java\
**Created:** [April 3, 2020, 1:48am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302 "2020-04-03T01:48:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyhong](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@hyhong](https://discuss.elastic.co/u/hyhong)\
**Post date:** [April 3, 2020, 1:48am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/1 "2020-04-03T01:48:37Z")

</div>

I want to customer a ICE java agent plugin,but I don't understand the source of java agent. Example HelperClassManager,ElasticApmInstrumentation,can someone provider an document about how to use this.Thank you.

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [April 3, 2020, 10:28am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/2 "2020-04-03T10:28:18Z")

</div>

Hy @hyhong,  
you can find cookbook [here](https://www.elastic.co/blog/a-cookbook-for-contributing-a-plugin-to-the-elastic-apm-java-agent)

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [April 3, 2020, 10:42am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/3 "2020-04-03T10:42:33Z")

</div>

or you can use [Public api](https://www.elastic.co/guide/en/apm/agent/java/current/public-api.html) with which you can create own transactions and spans.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [April 6, 2020, 9:09am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/4 "2020-04-06T09:09:05Z")

</div>

Hi @hyhong and @nugusbayevkk,

By default, agent is loaded in `bootstrap` classloader, which means for example that it can't access application classes like `Servlet`.

The `HelperClassManager` allows to load agent classes in a child classloader that does not have this limitation. While we don't have exhaustive documentation for its usage, you can definitely see how it's being used in other plugins, for example, the `grpc-plugin` could be a good example, [https://github.com/elastic/apm-agent-java/tree/master/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper](https://github.com/elastic/apm-agent-java/tree/master/apm-agent-plugins/apm-grpc/apm-grpc-plugin/src/main/java/co/elastic/apm/agent/grpc/helper), thus doing something similar (including interface+implementation).

Also, we are currently working on a newer and simpler way to write plugins without the need to have such complex classloader delegation, thus hopefully it should be easier in a few weeks.

---

<div class="post-metadata">

**Author:** ![hyhong](https://avatars.discourse-cdn.com/v4/letter/h/3bc359/32.png) [@hyhong](https://discuss.elastic.co/u/hyhong)\
**Post date:** [April 6, 2020, 12:19pm UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/5 "2020-04-06T12:19:37Z")

</div>

Ok，Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 27, 2020, 8:19am UTC](https://discuss.elastic.co/t/how-to-understand-java-agent-source/226302/6 "2020-04-27T08:19:43Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
