Java APM Instrumentation

Hi Team,

As our client is running java based web application with tomcat server we need to instrument java APM. without modfiying the code or creating a jar files. is it possible any other way if yes give me some information of setting up java apm. the client will not provide us the jar for the agent setup for manual java agent flag installation.

Thanks in Advance.

1 Like

Hi @Yogesh_AS ,

You can find Java agent documentation here: Introduction | APM Java Agent Reference [1.x] | Elastic

With tomcat, the option that I find the most convenient is to:

  • download the agent jar and store it in a folder of your choice near the ${CATALINA_HOME}
  • create or edit the ${CATALINA_HOME}/bin/setenv.sh to set the CATALINA_OPTS to include -javaagent:... option

With the agent, you won't have to modify the application code, the only addition to the tomcat server deployment is the agent jar.

Of course, I assume you are running on *nix here, but you can easily adapt this to Windows as well if needed.

Hi Sylvain,

We're in the process of onboarding a Java application, which is an executable (exe) based Java application, and it contains multiple JAR files. How can we determine which specific JAR file needs to be included in the command? I'm new to Java-based applications and not very familiar with their architecture, so any guidance would be greatly appreciated.

java -javaagent:/path/to/elastic-apm-agent-.jar
-Delastic.apm.service_name=my-service-name
-Delastic.apm.secret_token=
-Delastic.apm.server_url=http://localhost:8200
-Delastic.apm.environment=my-environment
-Delastic.apm.application_packages=org.example
-jar my-service-name.jar

The /path/to/elastic-apm-agent-.jar in the example here needs to be replaced with the latest copy of the Java agent available here in maven central.

In order to set the -javaagent and other JVM arguments, you will need to investigate how to set that for your application, if it's just using java command as in the example above that should be quite easy, but if there is a wrapper script or even an .exe to launch it then you might need to investigate other options, as a hint usually searching for "how to configure heap size with -Xmx" on your application is usually a good way to find how to provide JVM arguments.