Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Java agent with native compiled spring boot application

Together with our SpringBoot (3.0.3) application we are using Application Insights (Azure) for monitoring.

Currently we are trying to compile the application natively with the GraalVM. That works quite well and gives us a lot of benefits (startup time and memory consumption). The only thing that does not yet work is Application Insights which is started as a Java agent. I found almost no useful information about the whole topic and asked myself if we are trying to do something that is currently not supported at all.

Here's what we've tried so far:

  • Use parameters of the nativeCompile Gradle task to specify an additional jvmArgs (as mentioned here: https://github.com/oracle/graal/issues/1065). Although the build works fine, it just don't includes (or starts?) the agent with application startup. gradle task configuration
  • Start the Application Insights agent from within the code as described here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/java-spring-boot#enabling-programmatically Unfortunately that did not work either, because it tries to load a JAR file during startup, which is (I think) not possible for a native compiled application (no JVM).
  • Use OpenTelemetry library as described here: https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable?tabs=java For me it still seems to use a kind of a javaagent jar to work properly.

Is there a solution to add javaagents also in native compiled builds, or are there any alternatives to send monitoring data from a SpringBoot application to ApplicationInsights?

like image 817
Rolf Nyffenegger Avatar asked May 31 '26 10:05

Rolf Nyffenegger


2 Answers

I couldn't find anything in the GraalVM documentation for native images that talks about attaching runtime agents to native apps. This suggests that it is not supported.

I then searched for "application insights graalvm native image" and found this on the Application Insights issue tracker:

https://github.com/microsoft/ApplicationInsights-Java/issues/1266

We are currently using a custom implementation of the OpenTracing SPI to send our tracing data to Application Insights (the implementation is based on the Application Insights SDK 2.6.1) from a Quarkus application. Our plan is to move to OpenTelemetry as soon as it is supported by Quarkus.

Since Quarkus also supports native image generation (using GraalVM) auto-instrumentation using a Java agent won't be possible and a "deep integration" with Quarkus will be required. I would like to know if use cases like this one are on the radar and if builds (i.e. Maven artifacts) will be provided, which cater for this use case. I imagine there would be a build which provides an exporter only.

The highlighted phrase aligns with what I deduced from the (lack of) documentation. And it is further confirmed by the response to this GraalVM issue: https://github.com/oracle/graal/issues/5912

You said:

Use the OpenTelemetry library [...]. For me it still seems to use a kind of a javaagent jar to work properly.

The alternative would be to include the OpenTelemetry JAR in your SpringBoot application and enable it programatically rather than via a javaagent. It would be converted to native code by the GraalVM native image builder.

like image 107
Stephen C Avatar answered Jun 01 '26 22:06

Stephen C


As specified on this Microsoft documentation page, the alternative is to use the Azure distribution of the OpenTelemetry Spring Boot starter to monitor Spring Boot native image applications on Azure.

like image 42
jean_m Avatar answered Jun 01 '26 22:06

jean_m



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!