Java APM Setup
  • 13 Dec 2022
  • 1 Minute to read
  • Dark

Java APM Setup

  • Dark

Prequisites :

  • To monitor APM data on dashboard, Middleware Host agent needs to be installed.
  • You can refer this demo project to refer use cases of

Distributed Tracing

For recording the traces you will need to download JAR files given below.


And then run your project with command given below

java -javaagent:/PATH/TO/middleware-javaagent.jar \ \ \
    -jar <YOUR_APP>.jar

Add custom logs

Add this dependency in pom.xml


Then run ...

mvn install

Import logger package

import io.github.middlewarelabs.agentapmjava.Logger;

Use these functions for logging with different severity levels"info message");
Logger.debug("debug message");
Logger.warn("warn message");
Logger.error("error message");


If you are using APM in a Kubernetes cluster make sure to pass ENV variable:{FIRST-5-LETTERS-OF-API-KEY}.svc.cluster.local

Error Handling :

If you want to record exception in traces then you can use Logger.recordError(e) method.

import io.github.middlewarelabs.agentapmjava.Logger;
try {
       int[] myNumbers = {1, 2, 3};
     } catch (Throwable  e) {
       System.out.println("Something went wrong.");

What's Next