---
title: "Configuring Java APM Agent"
canonical: "https://thoughtdata.refined.site/space/TUD/55643651/Configuring%20Java%20APM%20Agent"
format: markdown
---
## Configuring Java APM Agent

Configuring java APM agent requires some pre-requisite knowledge about your application and is typically performed by application developers or administrators. Before you begin with java apm agent configuration you should be aware of the following information about your application

1. Applications can run multiple java processes and threads. You should be aware of the main java process which handles the user transactions which you would like to instrument for your APM
2. The path of the java process from where it runs on your server and
3. The configuration file which controls the startup script of the java process which you will instrument with java apm agent

You will be required to make following changes on your application server

1. Copy the java apm agent to the path from where your java process runs
2. Setup command line parameters to invoke the java apm agent when your application java process starts
3. Restart your application after configuration is completed

**Note:** if you are unsure of how to instrument your application with java apm agent or do not have above information contact ThoughtData's technical pre-sales team or technical support teams by sending an email to info@thoughtdata.com to assist with your configuration.

The below steps illustrates an sample example of how to instrument a tomcat based JIRA web application on a linux server. The path of the java process, application home path, the startup script name and its path can vary from your application. Perform the following steps to instrument a Tomcat based JIRA application with ThoughtData's java APM agent

Locate the path from where your java process runs

Run "**ps -aef | grep java**"

![image](media://ffd94e5c-aeba-4836-a1d3-c4f7577753ab)

 Locate the path of your java process

Locate the main path where your application files are installed. In the example above it will be **"/opt/atlassian/jira"**

Go to to the main bin folder of your application where all the application binaries are located. In the above example it will be "**cd**** /opt/atlassian/jira/bin**"

Note: Check the difference between the path from where your java process runs and your application binaries, they are not the same. In above example Java process runs from "/opt/atlassian/jira/jre/bin/java" and application main path will be "/opt/atlassian/jira/bin"

Copy the ThoughtData's APM agent package into your application main path. Package will be in the form of a Linux tar gzip file

Uncompress the tar file. Run "**tar -xvzf TD-java-apm-agent-version.X.tar.gz**". Name of the binary is for illustration only and can change in your case

Check that the 2 files highlighted below are copied into the folder as shown below.

![image](media://6145e50e-4e9c-43af-b09b-0544c314b180)

ThoughtData Java apm agent files

**elasticapm.properties **- this file controls the configuration of your ThoughtData java apm agent 

**td-apm-agent-1.X.Y.0.jar **- this file is the main java apm agent


Configure your java application startup script to include the ThoughtData APM agent jar file when it is started. In above application example the startup script which controls the java application process will be **"setenv.sh" **located under** /opt/atlassian/jira/bin **directory**.** The startup script can vary from application to application. For other tomcat based applications the startup script is controlled by **"catalina.properties" **located under** /opt/atlassian/jira/conf** directory. 

Edit the **"setenv.sh" **by running** "vi setenv.sh"**

Add a line to include the ThoughtData Java apm agent jar file in the java process during its startup. Provide the full path where the ThoughtData java apm agent jar is located and the full path of the elasticapm.properties file


![image](media://2d841c79-f98c-4bc4-bea7-b7dd55fcff45)

set the javaagent argument in the java startup script

Sample line to include in the startup script is provided below

***JVM_SUPPORT_RECOMMENDED_ARGS="-javaagent:/opt/atlassian/jira/bin/td-apm-agent-1.21.0.jar -Delastic.apm.service_name=jira-es1demo - Delastic.apm.config_file=/opt/atlassian/jira/bin/elasticapm.properties"***

***Note:**** The application path can be different in your case*

Save and exit the file by pressing "Esc" ":" "wq". Your application startup script configuration is now completed

Go to the directory containing **elasticapm.properties **using **"*****cd /opt/atlassian/jira/bin/ "***

Edit the **elasticapm.properties** file by running **"vi elasticapm.properties"**

Set the following configuration

|  |  |
| --- | --- |
| Option/Field | Description |
| stack_trace_limit | Default=1, Limits the stack trace collection to 1 per transaction. Changing this parameter to higher than default value will severely impact APM agent performance. |
| transaction_max_spans | Default=50, Limits the number of spans collected for a application transaction to configured number. Changing this parameter to higher than default value will severely impact APM agent performance. |
| recording | Default=true, Enables the APM agent, setting = false turns off the apm agent functionality on the application server |
| span_min_duration | Default=10ms, Limits the tracing to successful application transactions which had latency more than configured value. Changing this parameter to a number higher than default improves the APM agent performance and limits the data collection to only those transaction which had worst latency. It is advisable to study average acceptable transaction latency in your application and adjust the parameter accordingly to improve the performance of your apm agent. |
| metrics_interval | Default=15min, the frequency of pushing the collected APM metrics from java apm agent to Infrasense sensor. |
| central_config | Default=false, Changing to true will allow Infrasense to perform remote configuration changes to apm agent(not recommended) |
| ship_agent_logs | Default=false, Changing to true will send apm agent logs to Infrasense(not recommended) |
| server_url | Full URL of the Infrasense sensor. Replace the **<passive-infrasense-ip>** string with your actual IP address of your Infrasense sensor. By default Infrasense Sensor collects data from APM agent over HTTPs. If you choose to use HTTP on Infrasense side, change the url to just [**http://<passive-infrasense-ip>**](#) |
| verify_server_cert | Default=false, Enables the APM agent to communicate to the Infrasense sensor over HTTPs/SSL without validating the SSL certificate.Changing this parameter to **"true"** will require you to have a proper ssl certificate assigned to the Infrasense server |
| service_name | This property sets the name of the application. You can choose any name by which your to use for your application service. Replace the string <User-Defined-ServiceName> by the application name |

Sample configuration in **elasticapm.properties **is provided below

*stack_trace_limit=1*  
*
      transaction_max_spans=50*  
*
      span_min_duration=10ms*  
*
      recording=true*  
*
      metrics_interval=15m*  
*
      central_config=false*  
*
      ship_agent_logs=false*

*server_url=*[*https://172.22.48.2:443*](#)  
*
      verify_server_cert=false*

*service_name=Jira-app-production *

Save and exit the file by pressing "Esc" ":" "wq". Your java APM agent configuration is now completed

Restart your java based application, once these settings are completed.

This completes the configuration required on APM agent side, However you will need to start the APM server process on the Infrasense sensor side to complete the APM monitoring configuration.

Refer to [Configuring Infrasense sensor for APM agents](https://thoughtdata.atlassian.net/wiki/spaces/TUD/pages/55481377/Configuring+APM+server+in+Infrasense+for+APM+RUM+Agents) topic for more information to complete the steps in setting up your APM Monitoring in Enterprise360

**Advance Topic**

**Configuring multiple application java process with Java apm agents on same server**

If you have multiple java process running on same machine which handles user transactions and wish to instrument more than 1 java process with ThoughtData's java apm agent, the above configuration will remain the same. However, you will be required to repeat the steps of adding the Java apm agent and elasticapm properties to each startup script of every java process which you would like the APM agent to monitor. Also, if you wish to recognize each java process by a different application service name, you have to remove the service name parameter from elasticapm.properties file and add the same to java process startup script. Sample Example below

***JVM_SUPPORT_RECOMMENDED_ARGS="-javaagent:/opt/atlassian/jira/bin/td-apm-agent-1.21.0.jar -Delastic.apm.service_name=jira-es1demo - Delastic.apm.config_file=/opt/atlassian/jira/bin/elasticapm.properties" -Delastic.apm.service_name=<unique-application-name>*** 

Replace the <unique-application-name> with your actual application service name for each java process.