Skip to content

Java Agent Architecture

Jason Keller edited this page Dec 2, 2025 · 2 revisions

About

The Java Agent is responsible for instrumenting applications running on the Java Virtual Machine (JVM). The agent extracts performance and analytic information from the JVM and sends it to data services. While the overall architecture here is largely accurate there are some aspects that will drift out of sync over time.

image

Instrumentation

The Java agent adds instrumentation by intercepting classes as they are loading and modifying the actual bytes.

image

The Java agent uses the -javaagent flag to tell the JVM an agent is running. This causes the agent's premain method to run prior to the main application. In the premain, the Java agent reads its configuration file, sets up services, and registers ClassFileTransformers with the JVM. Each ClassFileTransformer receives the bytes of every class prior to the class being fully loaded into the JVM. This allows the Java agent to add instrumentation before and after every method of interest.

image

While the agent has many ClassFileTransformers, the main transformer is the InstrumentationContextManager. This transformer hooks up the weaver, the code responsible for adding the instrumentation to classes. For the other transformers, see the ClassTransformerService.

Clone this wiki locally