This project demonstrates the agent support ability of GraalVM native image enforced by the agent support PR.
The base project is the Spring native demo project.
When gets started, it responds "Hello World!" to a request to localhost:2327. This project starts along with OpenTelemetry java agent instrumentation as described here: https://opentelemetry.io/docs/instrumentation/java/getting-started/#instrumentation. The monitoring data can be collected by log or other supported means.
To support agent instrumentation in native image, actions should be taken from two sides:
- GraalVM side: must support compiling the instrumented code into the native image. It is supported by the agent support PR.
- Agent side: agent developer must define agent's behaviors in native image. Such as the
premain
behaviors and JDK class transformations. Opentelemetry-agent-native project gives an example of how such adaption is done for OpenTelemetry agent.
- Build the
agent support PR
to get the GraalVM JDK. - Or download the [dev version binary for the experiment only.
- Make sure your
GRAALVM_HOME
system variable refers to one of the above GraalVM releases.
- cd to the root of this project
mvn package
: Build the jar package of this project./run.sh --jvm --collect --log
: Execute the project in JVM mode, enabling OpenTelemetry agent to log monitoring data. Meanwhile, native-image-agent is enabled to collect transformation classes and other dynamic data. When this step ends, data is dumped tonative-configs
directory../build.sh
: Build the native image../run.sh --svm --log
: Run the native image application.curl localhost:2327
: Send a request to the application.
In the above steps, the OT agent prints monitoring data in the console. In the more practical scenarios, the data is collected and sent to the monitoring platform such as ARMS (Application Real-Time Monitoring Service) from Alibaba Cloud.
This demo project supports such a scenario as well:
- Set your system variables
ARMS_AUTH
andARMS_ENDPOINT
.ARMS_AUTH
is your token, it looks likeb590lhguqs@3a7*********9b_b590lhguqs@53d*****8301
.ARMS_ENDPOINT
is your connection endpoint, it looks likehttp://tracing-analysis-dc-bj.aliyuncs.com:8090
. These two values can be obtained from your control panel if you're already a customer of ARMS. The service name by default is "native-agent-demo". It can be modified by editing therun.sh
script. - For the above step 3 and 5, replace
--log
with--arms
.
The following diagram illustrates the result shown in the ARMS platform.