Observe your Spring Native Image application with OpenTelemetry
The OpenTelemetry Java agent is a convenient and well-established way to instrument Java applications. However, as of today it is not possible to use it with GraalVM Native Images.
To provide you with an easy and seamless way for Spring Boot Native Image application nevertheless, the OpenTelemetry Java contributors have improved the existing OpenTelemetry Spring Boot Starter to work well with Spring Boot Native Image applications. Read on to learn more!
A history of the last months
The OpenTelemetry Spring Boot Starter allows to add OpenTelemetry to your application without bytecode instrumentation. The OpenTelemetry Java contributors have used this to instrument Spring Boot Native Images. By adding the starter dependency to your project, you will benefit from an OTLP exports of logs (added the last months), spans and metrics, with an auto-instrumentation for Spring HTTP frameworks (updated the last months to make it work with Spring Boot 3) out of the box:
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-spring-boot-starter</artifactId>
<version>1.32.0-alpha</version>
</dependency>
</dependencies>
To get even more visibility, the Starter can be combined with instrumentation libraries. For this purpose, the OpenTelemetry Java contributors have improved the JDBC (database) libraries and logging instrumentation libraries. For example, for the Logback logging library, they have added GraalVM configuration to make the library work in native mode1.
Furthermore, they have worked to reduce the configuration to set up the logging
and database instrumentation with the Starter. For example, if your application
does not declare a DataSource bean, you can enable the database by simply adding
two properties in the application.properties
file:
spring.datasource.url=jdbc:otel:h2:mem:db
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver
To learn more, see Spring Boot Starter. You can use opentelemetry-java-examples/spring-native to run a Spring Boot Native Image application and look at the generated logs as well as HTTP and database telemetry data.
Finally, the OpenTelemetry Java contributors have added GraalVM Native automatic tests to the OpenTelemetry Java project to detect regressions related to the native mode execution.
What’s next?
The OpenTelemetry Java contributors expect to be able to enable automatic logging and database instrumentation configuration.
If you try out the OpenTelemetry Spring Boot Starter, share your thoughts and experiences via GitHub discussions or the #otel-java CNCF Slack channel.
Spring Boot Native Image applications do not support Log4j2 logging library. ↩︎