Application Agent
Drill4J Java Agent enables metrics collection for JVM-based applications.
General integration steps are:
Due to the diverse tools used in software development — such as CI/CD providers, deployment methods, testing stages — the exact process will depend on the environment.
#
How to download#
Download agent files manuallyThe most basic way to get agent files is to download release .zip manually.
Download release appropriate for your platform at
https://github.com/Drill4J/java-agent/releases/tag/v0.9.4mingwX64
is for Windows, Linux and Mac releases are called respectively.Unzip the file. Rename unzipped folder to
agent
.Inside you'll find the following files:
libdrill_agent.so
(on Windows -.dll
, on Mac -.dylib
)drill-runtime.jar
drill.properties
Refer to next section for further steps.
#
Use Docker image with a download scriptUse case: when you are already using Docker Compose to start your application.
We provide a small Docker image, that executes download script upon startup.
The way it works is:
- You add our container to your docker-compose.yml file, passing the desired version to
JAVA_AGENT
env variable. - On startup, the container launches the download script.
- Docker's healthcheck waits for it to complete.
- Downloaded agent files are placed in a shared volume.
- Shared volume is mounted to your application's container.
See the example docker-compose.yml file for details.
#
Use Drill4J CI/CD Integration Plugin for Maven and GradleUse cases: when application (or certain classes of application) is launched with Maven or Gradle. Thats most often the case with Unit tests.
Drill4J CI/CD Integration Plugin automatically downloads agent files and passes required parameters to Java.
Because of that, the next sections of this page are irrelevant in this scenario. Instead, please refer to CI/CD Integration Plugin page for more info.
#
How to set path to agentJava allows to load agents using special command line argument:
Where <path-to-agent>
must point to agent library file.
There are two way to set this command line argument.
-agentpath:
directly to Java process#
Pass Use case: when you have a direct access to Java's process launch arguments.
Considering your application is launched with:
Change it to:
-agentpath
to JAVA_TOOL_OPTIONS
env variable#
Set Use case: when you don't have direct access to the Java's process launch arguments. It's often the case when app is launched somewhere deep in scripts or inside Docker container.
Use JAVA_TOOL_OPTIONS
to instruct Java to use Drill4J Java Agent. Its a built-in env variable supported by any Java version.
#
TroubleshootingTo ensure you set agentpath correctly see how to confirm agent is loaded section below.
#
How to set agent parametersDrill4J agent supports 3 ways to set agent parameters
#
Set parameters using environment variablesThis is the recommended way to set agent parameters.
Env variables names are prefixed with DRILL_
with uppercase snake case. Examples:
- Given
packagePrefixes
parameter the env variable isDRILL_PACKAGE_PREFIXES
Precedence: parameter values set with env variables have the highest precedence and will override values set in -agentpath
string or drill.properties
file.
-agentpath
argument string#
Set parameters in Append parameters to the -agentpath
argument string. Add =<options>
after <path-to-agent>
:
Example:
Parameters are:
- passed after
<path-to-agent>
(/agent/libdrill_agent.so
above) - start of parameters string is indicated with
=
sign - parameters are
<key>=<value>
pairs - each pair is separated by comma.
Precedence: parameter values set with -agentpath
will override values set in drill.properties
drill.properties
file#
Set parameters in Alternatively, Drill4J agent checks for values in drill.properties
file. By default it is downloaded with agent files.
It adheres to the properties file syntax
Precedence: parameter values set in drill.properties
file have the lowest precedence and can be overriden by -agentpath
and env variables.
#
Agent parameters referenceParameter | Required | Example Value | Description |
---|---|---|---|
apiUrl | yes | http://localhost/api | URL to Drill4J Admin /api endpoint. |
apiKey | yes | 1_01cdf51ff20544ee... | Drill4J Backend API key. Generate it using Drill4J UI. Please make sure to read the apiKey security section |
groupId | yes | my-cool-app | Unique arbitrary string identifying your application group. |
appId | yes | api-service | Unique arbitrary string identifying your application. |
packagePrefixes | yes | my/org/somecoolapp | Specifies the packages for Drill4J to monitor. See syntax and examples below. |
buildVersion | recommended see more | v1.2.3 | Build version of your application. Typically set to version tag. |
commitSha | recommended see more | 8d87b0c2379a925... | Full SHA hash of commit from which your application .jar is built from. |
scanClassDelay | no | 5000 | Time in milliseconds to delay the class scanning procedure. If none is specified, the class scanning starts immediately upon JVM startup |
scanClassPath | no | Path(s) to application's .jar/.war/.ear files. If none are specified, the agent attempts to find application classes automatically. See syntax and examples below. |
#
Env variables namingEnvironment variables start with the prefix DRILL_
, followed by the parameter name in UPPERCASE_SNAKE_CASE
.
Example:
- For
apiUrl
, the env var isDRILL_API_URL
. - For
packagePrefixes
, the env var isDRILL_PACKAGE_PREFIXES
.
#
How to set package prefixespackagePrefixes is the filter that specifies which packages Drill4J should monitor. It is usually set to the topmost common package of your application.
Avoid setting it to something very broad (like com
or org
) - otherwise you will be scanning and collecting metrics for third-party dependencies.
#
Syntax- Parts of package names are separated with forward slashes
/
(and not dots.
) - Multiple packages can be specified using
;
delimiter - To exclude package use
!
prefix.
#
ExampleGiven you app packages are:
my.org.somecoolapp.user
my.org.somecoolapp.orders.repository
my.org.somecoolapp.db.models
packagePrefixes parameter should be set to my/org/somecoolapp
#
Adding extra packageAdd package name separated by ;
- my/org/somecoolapp;some/other/package
.
This adds both my/org/somecoolapp
and some.other.package
to scanned packages.
#
Excluding packageAdd package name prefixed with !
- my/org/somecoolapp;!my.org.somecoolapp.db.models
.
This adds my/org/somecoolapp
to scanned packages, but excludes my.org.somecoolapp.db.models
.
#
How to set scanClassPathSpecifies path(s) for the application agent to look for .jar, .war, or .ear files
Useful when the application agent is unable to locate these automatically (e.g. when running Wildfly or Tomcat)
#
API key security❗ Please avoid hardcoding apiKey and exposing it in plain text. Instead, use environment variables. ❗
Bad example:
Good example:
buildVersion
and commitSha
#
Considerations regarding Necessity: While
buildVersion
andcommitSha
are not strictly required, we recommend providing at least one (ideally both) for the following reasons:- It allows Drill4J to group metrics by version or commit.
- Without
buildVersion
andcommitSha
, Drill4J reports each application instance individually. Instances are identified with a random UUID.
Uniqueness: Both
buildVersion
andcommitSha
identify a unique application version, each associated with a specific set of classes and methods.To maintain the integrity of metrics, ensure that different application versions do not share the same
buildVersion
orcommitSha
values.Using identical values across different versions will lead to inaccurate metrics due to the mixing of unrelated data.
Semantics:
buildVersion
typically corresponds to the version tag of your application.Compliance with Semver is not required. Drill4J treats the build version as a unique string for grouping metrics, without any added semantics.
#
Troubleshooting#
How to confirm agent is loadedOnce loaded Drill4J agent prints the following ASCII logo:
It indicates that you have configured agent path correctly and Java picked up and loaded agent files.
#
Cannot load the agent because some agent parameters are set incorrectlyIf below Drill4J ASCII logo you see the following message:
It indicates that you are missing some required parameters. Refer to the agent parameters section.
#
Error "Could not create an Appender of type ..."The following error can be safely ignored as it doesn’t impact the functionality of the application or agent. It simply indicates that Logback is being used with a logback.xml file, which conflicts with the Drill4J logging configuration. However, logging will still function as expected.