Rolf Nyffenegger
Rolf Nyffenegger

Reputation: 171

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:

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?

Upvotes: 9

Views: 2181

Answers (2)

jean_m
jean_m

Reputation: 99

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.

Upvotes: 1

Stephen C
Stephen C

Reputation: 719376

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.

Upvotes: 1

Related Questions