Skip to content

Files

Latest commit

 

History

History

otel-http-opentelemetry-native

Observability of HTTP services with OpenTelemetry Instrumentation and Spring Boot Native GraalVM

image

Overview

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.

Building Application and Docker Images

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 Docker Compose setup

Run below command to start Jaeger and the HTTP services.

docker-compose up

Trigger a request to httpservice1.

curl http://localhost:8080

View Traces in Jaeger

Open Jaeger at http://localhost:16686 and check the traces.

image