Java

How to setup recording & monitoring for Java applications

Requirements

To setup RevDeBug you will need to:

Adding RevDeBug repository

Add the following lines to the super pom.xml / build.gradle file in the Java application main node:

Maven
Gradle
Maven
pom.xml
<project>
...
<repositories>
<repository>
<id>rdb-repo</id>
<name>RevDeBug Maven Repo</name>
<url>https://release.revdebug.com/repository/maven</url>
</repository>
</repositories>
...
</project>
Gradle
build.gradle
repositories {
maven {
url 'https://nexus.revdebug.com/repository/maven'
}
}

Adding RevDeBug dependency

Add the following lines to the super pom.xml / build.gradle file in the Java application main node:

Maven
Gradle
Maven
pom.xml
<project>
...
<dependencies>
<dependency>
<groupId>com.revdebug</groupId>
<artifactId>compiler</artifactId>
<version>6.0.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.revdebug</groupId>
<artifactId>RevDeBug</artifactId>
<version>6.0.9</version>
</dependency>
...
</project>
Gradle
build.gradle
dependencies {
compileOnly 'com.revdebug:compiler:6.0.0'
annotationProcessor 'com.revdebug:compiler:6.0.0' // Required after Gradle v4.10.2
implementation 'com.revdebug:RevDeBug:6.0.0'
}
//* Use compile keyword instead of implementation for Gradle version less than 3.0
//* Use compile keyword instead of compileOnly for Gradle version less than 2.12

For spring-boot projects additional exclusion in pom.xml is needed (without it build time dependencies will be packaged with application):

pom.xml
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>com.revdebug</groupId>
<artifactId>compiler</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>

Configure the connection to RevDeBug Server

RevDeBug can be easily added to all projects in the working directory. But if you want, you can add RevDeBug to the selected subset.

Maven - single project
Maven - many projects
Gradle
Maven - single project
pom.xml
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>-ArecordServerAddress=[SERVER_ADDRESS]</arg>
<arg>-ArecordServerPort=42734</arg>
<arg>-ArecordingMode=OnEvent</arg>
<arg>-AapplicationName=[APP_NAME]</arg>
<arg>-AsolutionName=[PROJECT_NAME]</arg>
<arg>-AreleaseId=${git.commit.id}</arg>
<arg>-AreleaseDisplayName=[DISPLAY_NAME]</arg>
<arg>-ArepositoryPath=[STORAGE_PATH]</arg>
<arg>-AuploadMetadata=true</arg>
<arg>-AforceTLS=false</arg>
</compilerArgs>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<project>
...
<repositories>
<repository>
<id>rdb-repo</id>
<name>RevDeBug Maven Repo</name>
<url>http://maven.revdebug.com</url>
</repository>
</repositories>
...
</project>
Maven - many projects
pom.xml
<project>
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<compilerArgs>
<arg>-ArecordServerAddress=[SERVER_ADDRESS]</arg>
<arg>-ArecordServerPort=42734</arg>
<arg>-ArecordingMode=OnEvent</arg>
<arg>-AapplicationName=[APP_NAME]</arg>
<arg>-AsolutionName=[PROJECT_NAME]</arg>
<arg>-AreleaseId=${git.commit.id}</arg>
<arg>-AreleaseDisplayName=[DISPLAY_NAME]</arg>
<arg>-ArepositoryPath=[STORAGE_PATH]</arg>
<arg>-AuploadMetadata=true</arg>
<arg>-AlogErrorClass=[LOG_CLASS]</arg>
<arg>-AlogErrorMethod=[LOG_METHOD]</arg>
<arg>-AREVDEBUG_TRACE_LOG_ERROR=true</arg>
<arg>-AforceTLS=false</arg>
</compilerArgs>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
</project>
Gradle
build.gradle
compileJava {
options.compilerArgs = [
"-ArecordServerAddress=[SERVER_ADDRESS]",
"-ArecordServerPort=42734",
"-ArecordingMode=OnEvent",
"-AapplicationName=[APP_NAME]",
"-AsolutionName=[PROJECT_NAME]",
"-AreleaseId=[HASH_COMMIT]",
"-AreleaseDisplayName=[DISPLAY_NAME]",
"-ArepositoryPath=[STORAGE_PATH]",
"-AuploadMetadata=true",
"-AlogErrorClass=[LOG_CLASS]",
"-AlogErrorMethod=[LOG_METHOD]",
"-AREVDEBUG_TRACE_LOG_ERROR=true",
"-AforceTLS=false"
]}

For maven builds to have ${git.commit.id}provided you need to add maven properties extension or use git commit info maven plugin in your project (we highly recommend maven properties extension as plugin lifecycle can break on more complex project structures).

Create .mvn/extensions.xml file in your project's root directory with the contents below:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
<extension>
<groupId>com.github.pascalgn</groupId>
<artifactId>properties-maven-extension</artifactId>
<version>0.4.0</version>
</extension>
</extensions>

Configuring fields

There are configurable fields in the connection section of RevDeBug DevOps Monitor:

ArecordServerAddress - IP address or hostname of the recording servers (if you are using Docker, use Ifconfig command to get an IP address)

ArecordServerPort - The default port to connect to RevDeBug DevOps Monitor is 42734.

ArecordingMode - RevDeBug offers ways to register applications:

  • OnEvent - registers only a specified number of steps back (default 1,000) and the error itself. This mode is very light and well suited for production use.

  • Continuous - records everything that occurred in the application, including every line of code executed, every variable value, every exception and performance data. It is recommended to use this mode only locally in a test environment.

  • MethodMetric - generates CSV files with information about each method occurring in the application and presents them broken down by package name, class name, method name with an initialization line. Additionally, it includes measurements such as the total number of calls, method run times (total time, minimum time and maximum time).

AapplicationName - Here you must enter the name of your application

AsolutionName - You must enter the name of your working java directory here.

AreleaseId - the configuration depends on the selected tool:

  • Maven - hash commit will be added automatically

  • Gradle - here you have to paste the hash commit manually

AreleaseDisplayName - This argument allows you to set the release name that will be displayed in the Releases panel within the application settings. If this argument is not set, the release name will be the same as the releaseId.

ArepositoryPath - Path to RevDeBug recording directory.

AuploadMetadata - This option enables displaying recordings in RevDeBug DevOps Monitor

AREVDEBUG_TRACE_LOG_ERROR - Enables treating log.error() calls as exceptions and recording them

AlogErrorClass - Define logger class to use for log.error() recording. Must be fully qualified name, such as ‘org.apache.log4j.Logger’

AlogErrorMethod - Define method part of log.error() call for logger class specified in AlogErrorClass. For example for log class ‘org.apache.log4j.Logger’ the log error method is ‘error’.

AforceTLS - set to true if your RevDeBug DevOps Monitor instance has been configured to work with a SSL certificate.

Add RevDeBug Java-agent

  • Download java-agent from nexus repo (link)

  • Unzip the archive and modify config/agent.config file

    • agent.service_name set to your app name

    • collector.backend_service set to point to your record server instance

    • agent.force_tls set to true if your RevDeBug DevOps Monitor instance has been configured to work with an SSL certificate.

  • Attach unzipped agent to your app with java argument: -javaagent:[Path-to-unzipped-agent]/agent/skywalking-agent.jar