JVM SDK
This page dives into the nitty-gritty details on installing Rookout under various configurations. If you encounter difficulties with deploying Rookout, this is the place to look.
JVM
The JVM SDK provides the ability to fetch debug data from a running application in real time. It can be download directly to the target system by running the following command:
curl -L "https://get.rookout.com/rook.jar" -o rook.jar
Supported Languages
The following languages are currently supported by the JVM SDK: Java, Scala, Kotlin, Groovy, ColdFusion, and Clojure.
If you use a language that is not mentioned above, please let us know at support@rookout.com
Setup
Java Agent
Simply add the Rookout SDK as a Java Agent to your environment:
- Environment Variable
- Command Line
# Add the Rookout Java Agent to your application using an environment variable
export JAVA_TOOL_OPTIONS="-javaagent:$(pwd)/rook.jar -DROOKOUT_TOKEN=[Your Rookout Token]"
# Optional, see Labels section below Projects
export ROOKOUT_LABELS=env:dev
java -javaagent:$(pwd)/rook.jar MyClass -DROOKOUT_TOKEN=[Your Rookout Token] -DROOKOUT_LABELS=env:dev
Debugging OSGi apps
To use Rookout in an OSGi application such as JBoss or Wildfly, delegate the Rookout package in the OSGi configuration:
- Environment Variable
- Command Line
export JAVA_TOOL_OPTIONS="-Dorg.osgi.framework.bootdelegation=com.rookout.* -javaagent:$(pwd)/rook.jar -DROOKOUT_TOKEN=[Your Rookout Token]"
java -Dorg.osgi.framework.bootdelegation=com.rookout.* -javaagent:$(pwd)/rook.jar MyClass -DROOKOUT_TOKEN=[Your Rookout Token] -DROOKOUT_LABELS=env:dev
This is done where all other JVM options are set (via -D flags, JVM_OPTS, etc.).
SDK Configuration
Configuration is performed using OS Environment Variables or Java System Properties.
Environment Variable | Default Value | Description |
---|---|---|
ROOKOUT_TOKEN | None | The Rookout token for your organization. |
ROOKOUT_LABELS | A dictionary of key:value labels for your application instances. Use k:v,k:v format for environment variables | |
ROOKOUT_COMMIT | None | String that indicates your git commit |
ROOKOUT_REMOTE_ORIGIN | None | String that indicates your git remote origin |
ROOKOUT_CONTROLLER_HOST | None | If you are using a Rookout ETL Controller, this is the hostname for it |
ROOKOUT_CONTROLLER_PORT | None | If you are using a Rookout ETL Controller, this is the port for it |
ROOKOUT_PROXY | None | URL to proxy server |
ROOKOUT_DEBUG | False | Set to True to increase log level to debug |
ROOKOUT_SOURCES | None | Source information (see below) |
ROOKOUT_LIVE_LOGGER | False | Set to True to enable Rookout Live Logger |
ROOKOUT_QUIET | False | Set to True to stop informative log messages from being written to the standard output and error |
Test connectivity
To make sure the SDK was properly installed and test your configuration (environment variables only), run the following command:
java -jar rook.jar
Debug Information
Rookout requires your application to be built with debug information. While most modern Java build tools such as Gradle
and Maven
do so by default, some such as Ant
and javac
do not.
Here a few examples on how to configure them:
- ANT
- javac
<javac srcdir="${source-directory}"
destdir="${classes-directory}"
classpath="${lib-directory}"
debug="true"
/>
javac -g MyClass.java
Packaging Sources
To make sure you are collecting data from the source line where you have set the breakpoint, include your source files within your JAR/WAR/EAR library.
- Gradle
- Maven
- Ant
jar {
from sourceSets.main.allSource
}
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
</resource>
</resources>
<jar destfile="${target.dir}/my-app.jar">
<fileset dir="${target.dir}/classes" />
<fileset dir="${source-directory}" includes="**/*.java"/>
</jar>
Source information
To enable automatic source fetching, information about the source control must be specified.
Environment Variables or Start Parameters
Use the environment variables or start parameters as described above in the API section.
Git Folder
Rookout gets the source information from the .git folder if both of the following apply:
- The .git folder is present at any of the parent directories of where the application is running (searching up the tree).
- No environment variables or start parameters are set for source information.
Multiple Sources
Use the environment variable ROOKOUT_SOURCES
to initialize the SDK with information about the sources used in your application.
ROOKOUT_SOURCES is a semicolon-separated list with either a source control repository and revision information, or a path on the local filesystem to a JAR file.
Example
ROOKOUT_SOURCES=https://github.com/Rookout/Rookout#afe123;/path/to/lib.jar
Jar File
To load source information from a jar file, you need to add the following attributes to the JAR manifest:
Rookout-Repository
: Repository URL
Rookout-Revision
: Revision identifier
Application Detection
Rookout uses the semi-documented sun.java.command
system property to identify your application and display it for within the Web Application.
Some Java based runtimes such as Jsvc don't set it as expected. If missing, you may set it manually:
jsvc -Dsun.java.command=my.main.class
Dynamic loading to a running JVM process
The Rookout SDK can be also loaded to an already running JVM process.
To do so, run the SDK jar using java [additional parameters] -jar rook.jar
, configure it using the following steps:
- Set SDK configuration parameters either as environment variables, or as
-D
parameters to the java command in[additional parameters]
(e.g.,-DROOKOUT_TOKEN=12345678
). - Add another parameter:
ROOKOUT_TARGET_PID
, and set its value to the PID of the running process.
Supported Versions
The following Java versions are supported: 7 (7u111+), 8 (8u74+), 11 (11u4+), 13, 17, 19, and 21.
If your version is not mentioned above, please let us know at support@rookout.com.
Serverless and PaaS deployments
Integrating with Serverless
To integrate Rookout to a serverless application, it is required to add Rookout as a dependency instead of using it as a Java agent. It is also required to flush the collected information explicitly.
Follow these steps to add Rookout to your serverless application:
First, add Rookout as a dependency:
- Gradle
- Maven
dependencies {
implementation 'com.rookout:rook:latest.release'
}
<dependencies>
<dependency>
<groupId>com.rookout</groupId>
<artifactId>rook</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
Some serverless environments may be missing the "tools" dependency, you can add it from the Nuiton repository:
- Gradle
- Maven
repositories {
mavenCentral()
maven {
url https: '//nexus.nuiton.org/nexus/service/local/repositories/thirdparty/content/'
}
}
dependencies {
implementation 'com.sun:tools:1.7.0.13'
}
<repositories>
<repository>
<id>nuiton</id>
<name>nuiton</name>
<url>https://nexus.nuiton.org/nexus/service/local/repositories/thirdparty/content/</url>
</repository>
</repositories>
<!--...
dependencies
com.sun
tools
1.7.0.13
-->
Now, add Rookout to your code, start is using API.start
and flush using API.flush
:
import com.rookout.rook.API;
import com.rookout.rook.RookOptions;
// ...
public String handleRequest(Map<String,String> event, Context context) { // AWS Lambda example
RookOptions opts = new RookOptions();
HashMap<String, String> labels = new HashMap<String, String>();
labels.put("env", "dev");
opts.labels = labels;
API.start(opts);
// ...
API.flush();
return response;
}
Optionally, you can add the function's name as a label. To do so, use the context provided by your cloud vendor. For example, in AWS Lambda:
labels.put("func_name", context.getFunctionName());
Next, add your Rookout token as an environment variable:
ROOKOUT_TOKEN=[Your Rookout Token]
For Java 11, also add the following option as an environment variable:
JAVA_TOOL_OPTIONS=-Djdk.attach.allowAttachSelf=true
Note: Adding the Rookout SDK may slow down your Serverless cold-start times. We recommend a timeout of 10 seconds or more.