Skip to main content

Java

Installation

  1. Download the Elastic APM Java agent jar.

    https://www.elastic.co/docs/reference/apm/agents/java/setup-javaagent#setup-javaagent-get-agent

  2. Configure the agent:

    JAVA_TOOL_OPTIONS=-javaagent:</path/elastic-apm-agent.jar>

    ELASTIC_APM_SERVICE_NAME=<app_name>
    # send traces to CubeAPM
    ELASTIC_APM_SERVER_URL=http://<ip_address_of_cubeapm_server>:3130

    # capture jvm non-heap buffer pool metrics (optional but recommended)
    ELASTIC_APM_CAPTURE_JMX_METRICS=object_name[java.nio:type=BufferPool,name=*] attribute[*]

    # optional settings
    ELASTIC_APM_ENVIRONMENT=UNSET
    ELASTIC_APM_SERVICE_VERSION=1.2.3
    ELASTIC_APM_GLOBAL_LABELS=mykey1=myvalue1,mykey2=myvalue2
    info

    Elastic APM Java agent also supports ELASTIC_APM_SERVER_URLS environment variable, which can be used to specify multiple urls. CubeAPM does not support it, so it should not be used with CubeAPM. In fact, Elastic APM's own documentation recommends against using it.

Sample App

A working example is available at https://github.com/cubeapm/sample_app_java_spring/tree/elastic

Troubleshooting

The following can be used for troubleshooting:

# Print Elastic agent logs on screen
ELASTIC_APM_LOG_FILE=stdout
# Set Elastic agent log level to debug if needed to see detailed logs
ELASTIC_APM_LOG_LEVEL=debug