How to collect `log.error`(slf4j) into the Elastic APM "Error" app?

If you are asking about a problem you are experiencing, please use the following template, as it will help us help you. If you have a different problem, please delete all of this text :slight_smile:

TIP 1: select at least one tag that further categorizes your topic. For example server for APM Server related questions, java for questions regarding the Elastic APM Java agent, or ui for questions about the APM App within Kibana.

TIP 2: Check out the troubleshooting guide first. Not only will it help you to resolve common problems faster but it also explains in more detail which information we need before we can properly help you.

Kibana version: 7.9

Elasticsearch version: 7.9

APM Server version: 7.9

APM Agent language and version: 1.x

Browser version: N/A

Original install method (e.g. download page, yum, deb, from source, etc.) and version: kubernetes/docker

Fresh install or upgraded from other version? N/A

Is there anything special in your setup? For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.

I setup by JAVA_TOOL_OPTIONS environment variable, with values such as -javaagent:/elastic/apm/agent/elastic-apm-agent.jar.

Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):

Thanks for the product! I wonder how to collect log.error(slf4j) into the Elastic APM "Error" app? For example, I know that, when I throw new RuntimeException("hello"), the elastic APM will notice it, and I can see it in the APM "Errors" app in Kibana. However, when I do something like log.error("ouch apple={}", apple, e);, how can I see it in APM "Errors" app?

Steps to reproduce:

  1. N/A

Errors in browser console (if relevant): N/A

Provide logs and/or server output (if relevant): N/A

As far as I remember, this usage of the logger doesn't treat e as a Throwable, but as a parameter, assuming that the first argument is a parametrized message (ignored in this case because there is only one parameter in the provided message). Therefore, the agent doesn't treat it as a Throwable either.
If you use log.error("ouch apple=apple", e), you should get an error reported for that.

Nice catch! I did not thought of that. After reading the code I do see so. Thanks!

@Eyal_Koren By the way, I wonder whether log.warn("str", e) will also be captured by elastic APM or not? Thanks!

No, if a user doesn't consider something as error, we wouldn't want to do that.

Hmm though sounds not that helpful to my case, thanks!

Well, sorry about that...
In case you are not familiar, we have a public API that allows you to extend automatic tracing based on your specific needs, including the ability to capture an Exception in the correct span/transaction context.

Hmm thanks all the same!

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