Apm capture as error elasticsearch GET 404 on client


Recently we added APM to our application. I saw that APM capture as error all request to elasticsearch that give a 404 as response. To be exact, ResponseException.

I'm trying to avoid that because when I see APM errors and see so much errors I'm scared thinking something goes wrong.

I tried catching exception in client get request on java rest high client but none exception is throwed in code. Also, in documentation says that to check if document exists (found) use method isExists() that it's as we are doing.

String index = getResponse.getIndex();
String id = getResponse.getId();
/*Handle the scenario where the document was not found. Note that although the returned 
response has  `404`  status code, a valid  `GetResponse`  is returned rather than an exception thrown. 
Such response does not hold any source document and its  `isExists`  method returns  `false` */
if (getResponse.isExists()) {
    long version = getResponse.getVersion();
    String sourceAsString = getResponse.getSourceAsString();        
    Map<String, Object> sourceAsMap = getResponse.getSourceAsMap(); 
    byte[] sourceAsBytes = getResponse.getSourceAsBytes();          
} else {

I guess the only way to avoid that is with another request before get using exists API to check if document exists, but if there is any option to avoid capture that exception I prefer that.

So my question is: Is there any configuration to avoid capture this exception from apm java agent or in code?

Thanks in advance,

Hi @adrian-arapiles,

Agent instruments the HTTP request execution that is performed with Elasticsearch client library, thus there is an exception thrown when there is a 404. However, this exception is not visible to your code and silently discarded by the high level client library.

Thus, if I understand correctly what you want is to filter-out the 404 spans, or make them reported as normal so it does not create noise.

There isn't any way to do this at agent level, however, you can use an ingest pipeline on APM server to modify the spans when they are reported: https://www.elastic.co/guide/en/apm/server/current/configuring-ingest-node.html

Thanks @Sylvain_Juge.
That's exactly what I was asking for. I gonna try your advice.

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