Setup the agent with Application Serversedit

Different application servers have different ways of setting the -javaagent flag and system properties.

Note that system properties are only one way of configuring the agent but setting the -javaagent flag is required in each case. See Configuration to learn about how to configure the agent with a configuration file or environment variables.

Generic Setupedit

Start your application (for example a Spring Boot application or other embedded servers) and add the -javaagent JVM flag. Use the -D prefix to configure the agent using system properties.

java -javaagent:/path/to/elastic-apm-agent-<version>.jar -Delastic.apm.service_name=my-cool-service -Delastic.apm.application_packages=org.example,org.another.example -Delastic.apm.server_urls=http://localhost:8200 -jar my-application.jar

Apache Tomcatedit

Unixedit

Create bin/setenv.sh (or modify if the file already exists). Make sure to make the file executable, for example chmod +x bin/setenv.sh

Add the following line:

setenv.sh. 

export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/elastic-apm-agent-<version>.jar"
export CATALINA_OPTS="$CATALINA_OPTS -Delastic.apm.service_name=my-cool-service"
export CATALINA_OPTS="$CATALINA_OPTS -Delastic.apm.application_packages=org.example,org.another.example"
export CATALINA_OPTS="$CATALINA_OPTS -Delastic.apm.server_urls=http://localhost:8200"

Windowsedit

Create bin\setenv.bat (or modify if the file already exists).

setenv.bat. 

set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:C:/path/to/elastic-apm-agent-<version>.jar
set CATALINA_OPTS=%CATALINA_OPTS% -Delastic.apm.service_name=my-cool-service
set CATALINA_OPTS=%CATALINA_OPTS% -Delastic.apm.application_packages=org.example,org.another.example
set CATALINA_OPTS=%CATALINA_OPTS% -Delastic.apm.server_urls=http://localhost:8200

Jettyedit

Option 1: edit jetty.sh

jetty.sh. 

export JAVA_OPTIONS="${JAVA_OPTIONS} -javaagent:/path/to/elastic-apm-agent-<version>.jar"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Delastic.apm.service_name=my-cool-service"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Delastic.apm.application_packages=org.example,org.another.example"
export JAVA_OPTIONS="${JAVA_OPTIONS} -Delastic.apm.server_urls=http://localhost:8200"

Option 2: edit start.ini

start.ini. 

--exec
-javaagent:/path/to/elastic-apm-agent-<version>.jar
-Delastic.apm.service_name=my-cool-service
-Delastic.apm.application_packages=org.example,org.another.example
-Delastic.apm.server_urls=http://localhost:8200

Option 3: If you are using embedded Jetty, see Generic Setupedit.

WildFlyedit

Standalone Modeedit

Add the agent configuration at the bottom of the standalone.conf file:

Unixedit

bin/standalone.conf. 

export JAVA_OPTS="$JAVA_OPTS -javaagent:/path/to/elastic-apm-agent-<version>.jar"
export JAVA_OPTS="$JAVA_OPTS -Delastic.apm.service_name=my-cool-service"
export JAVA_OPTS="$JAVA_OPTS -Delastic.apm.application_packages=org.example,org.another.example"
export JAVA_OPTS="$JAVA_OPTS -Delastic.apm.server_urls=http://localhost:8200"

Windowsedit

bin/standalone.conf.bat. 

set JAVA_OPTS=%JAVA_OPTS% -javaagent:C:/path/to/elastic-apm-agent-<version>.jar
set JAVA_OPTS=%JAVA_OPTS% -Delastic.apm.service_name=my-cool-service
set JAVA_OPTS=%JAVA_OPTS% -Delastic.apm.application_packages=org.example,org.another.example
set JAVA_OPTS=%JAVA_OPTS% -Delastic.apm.server_urls=http://localhost:8200

Domain Modeedit

Edit the domain.xml file which is usually located under domain/configuration and add a JVM option for the -javaagent flag, as well as some system properties for the configuration.

domain/configuration/domain.xml. 

...
<server-group>
  <jvm>
     <jvm-options>
      ...
      <option value="-javaagent:/path/to/elastic-apm-agent-<version>.jar"/>
      ...
     </jvm-options>
  </jvm>
</server-group>
...
<system-properties>
  <property name="elastic.apm.service_name"         value="my-cool-service"/>
  <property name="elastic.apm.application_packages" value="org.example,org.another.example"/>
  <property name="elastic.apm.server_urls"          value="http://localhost:8200"/>
</system-properties>
...

WebSphere Libertyedit

Add the following lines to the jvm.options file.

jvm.options. 

-javaagent:/path/to/elastic-apm-agent-<version>.jar
-Delastic.apm.service_name=my-cool-service
-Delastic.apm.application_packages=org.example,org.another.example
-Delastic.apm.server_urls=http://localhost:8200

Payaraedit

Update the domain.xml file to add the -javaagent flag and system properties.

glassfish/domains/domain1/config/domain.xml. 

<java-config>
  ...
  <jvm-options>-javaagent:/path/to/elastic-apm-agent-<version>.jar</jvm-options>
  <jvm-options>-Delastic.apm.service_name=my-cool-service</jvm-options>
  <jvm-options>-Delastic.apm.application_packages=org.example,org.another.example</jvm-options>
  <jvm-options>-Delastic.apm.server_urls=http://localhost:8200</jvm-options>
</java-config>