Java agents cannot be used with GraalVM native applications. So how do we use OTEL instrumentation with a Spring native application?
This can be done by adding below POM dependencies:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>${opentelemetry-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-instrumentation-bom-alpha</artifactId>
<version>${opentelemetry-instrumentation-bom-alpha.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
</dependency>
The opentelemetry-spring-boot-starter
dependency enables auto instrumentation of Spring Web (RestTemplate), Web MVC (Controllers) and WebFlux (WebClient). Unlike the java agent, instrumentation of other libraries (like JDBC, Kafka etc) needs to be enabled explicitly.
Run below command to compile and build the docker images with Paketo buildpacks. Ensure you have GraalVM Java SDK deployed.
mvn spring-boot:build-image -Pnative
Run below command to start Jaeger and the HTTP services.
docker-compose up
curl http://localhost:8080
Open Jaeger at http://localhost:16686
and check the traces.