# Weird exceptions from apm agent

**URL:** <https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228>\
**Category:** APM\
**Tags:** java\
**Created:** [April 2, 2020, 2:20pm UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228 "2020-04-02T14:20:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciment](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ciment](https://discuss.elastic.co/u/ciment)\
**Post date:** [April 2, 2020, 2:20pm UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/1 "2020-04-02T14:20:01Z")

</div>

Hello,

I use ES 7.6.1. with APM Server 7.6.1 and apm-java agent 1.14.0.

In my jakarta application, when I`m fetching data from ES via RestHighLevelClient I get some exception to server.log

```
java.lang.ClassCastException: co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelperImpl cannot be cast to co.elastic.apm.agent.es.restclient.ElasticsearchRestClientInstrumentationHelper
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:234)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1514)
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:970)

```

or

```auto
java.lang.ClassCastException: co.elastic.apm.agent.httpclient.helper.RequestHeaderAccessor cannot be cast to co.elastic.apm.agent.impl.transaction.TextHeaderSetter
	at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:123)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:244)
	at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1514)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1484)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1454)
	at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:970)

```

Finally, I`m able to fetch data, but exceptions are little bit annoying.

How can I fix these problems?

---

<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 2, 2020, 2:38pm UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/2 "2020-04-02T14:38:06Z")

</div>

Hi, what version of RestHighLevelClient do you use?

---

<div class="post-metadata">

**Author:** ![ciment](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ciment](https://discuss.elastic.co/u/ciment)\
**Post date:** [April 2, 2020, 2:59pm UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/3 "2020-04-02T14:59:11Z")

</div>

also the same 7.6.1

---

<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 2, 2020, 5:34pm UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/4 "2020-04-02T17:34:41Z")

</div>

@ciment,  
I wrote application with spring boot and tested with that versions, but cannot reproduce problem.  
What application server do you use?  
Can you share example-application where the problem occurs?

---

<div class="post-metadata">

**Author:** ![ciment](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ciment](https://discuss.elastic.co/u/ciment)\
**Post date:** [April 3, 2020, 7:40am UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/5 "2020-04-03T07:40:11Z")

</div>

@nugusbayevkk

I use payara 5.201.

I found where the problem is. I use JRebel agent for hot redeploys. When I start payara with JRebel configuration, I see these exceptions. Without JRebel no exceptions.

Thanks @nugusbayevkk for your investigation. It helps me to find problem somewhere else.

---

<div class="post-metadata">

**Author:** ![ciment](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@ciment](https://discuss.elastic.co/u/ciment)\
**Post date:** [April 3, 2020, 7:57am UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/6 "2020-04-03T07:57:51Z")

</div>

I will forward the problem to JRebel developers...

---

<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 3, 2020, 8:57am UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/7 "2020-04-03T08:57:41Z")

</div>

Hi @ciment,

Our agent have to use some non-standard classloader delegation because some agent classes are loaded in bootstrap classloader (that does not know about application classes), and in order to access application classes like Servlets or other frameworks, some classes accessed by instrumented code need to be in application classloader. As a result, any other agent that re-transforms without applying this same strategy may trigger side effects like this.

---

<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 24, 2020, 4:57am UTC](https://discuss.elastic.co/t/weird-exceptions-from-apm-agent/226228/8 "2020-04-24T04:57:44Z")

</div>

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