Elastic APM Agent with Docker

Kibana version: 7.3.2

Elasticsearch version: 7.3.2

APM Server version:7.3.2

APM Agent language and version: Java and 1.12.0

I am trying to integrate APM agent with a spring boot application and I could make it work using following command

-javaagent:/var/tmp/elastic-apm-agent-1.12.0.jar -Delastic.apm.service_name=apm-demo-service -Delastic.apm.server_url=http://apmserver:8200 -Delastic.apm.application_packages=com.myapp -Delastic.apm.hostname=myhost

When I do this, I see a log statement indicating that the apm server is up.

2020-02-05 00:24:42.648 [apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build_date": "2019-09-06T13:16:25Z", "build_sha": "ed1ac181088227b51686ac5affe8e4176a179ebf", "version": "7.3.2"}
2020-02-05 00:24:43.015 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.12.0 as apm-demo-service on Java 1.8.0_45 (Oracle Corporation) Windows 8.1 6.3

But my spring boot application runs as a docker container and when I update entrypoint to use same java agent, it does not work. I initially thought that its not getting the jar file and hence causing the data not to be pushed to APM server. But that was not the case. I realized that the console logs do not show anything from co.elastic package.

I am using --net=host and hence the apm server access is not an issue.

Question is - is there any specific configuration I need to do make javaagent work with docker? Is there any port that I need to expose? Are there any volumes that I need by default?

Did I get you right that it works as expected when run from your Windows host but you have problems when trying to use the agent with Docker?

Seems like the agent is not applied at all then. Could you share your Docker setup, especially your entrypoint.

No special configuration is necessary, apart from attaching adding the -javaagent flag and the agent configuration. It's recommended to use environment variables to configure the agent (for example in docker-compose.yaml).

This is a working example of using the Java agent with Docker.

Thanks for your reply. Yes, its not working with docker. I tried changing the path of the jar file and I was hoping I will get Error occurred during initialization of VM agent library failed to init: instrument error. But the container was started without any issues.

Here is entry point for docker image.

ENTRYPOINT java -javaagent:/var/tmp/elastic-apm-agent-1.12.0.jar -Delastic.apm.service_name=apm-demo-service -Delastic.apm.server_url=http://apmserver:8200 -Delastic.apm.application_packages=com.myapp -Delastic.apm.hostname=myhost -server -Djava.security.egd=file:/dev/./urandom -jar /opt/my-service/my-service.jar

Seems like the entrypoint is ignored then. Can you share more from that Dockerfile?

Try to make some obvious errors, like providing a wrong jar name and see if it still works.

Which base image is your image based on?

Entrypoint is not ignored, spring boot application runs fine. Only Javaagent is ignored :frowning:

Just to add, I am using https://forge.puppet.com/puppetlabs/docker for running docker container.

If I run the docker container with javaagent locally on my windows machine it works.

Looks like the problem is compatibility with puppet module.

Answering this myself. It came out to be problem container using JRE. After I switched to using JDK, it worked.

Thanks

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