spring-bootdockerdevopsopen-telemetryzipkin

Paketo Buildpack for OpenTelemetry not working with maven spring boot 2.5.12 app


I'm trying to add OpenTelemetry automated instrumentation to our spring boot app but I can't get it working.

The app is deployed as a docker image and the image is created via the spring-boot-maven-plugin.

I'm following these instructions: https://github.com/paketo-buildpacks/opentelemetry

I've added an env section to the spring-boot-maven-plugin config in the pom.xml:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <image>
                    <name>appname</name>
                    <env>
                        <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
                    </env>
                </image>
            </configuration>
        </plugin>

I'm not sure this is the correct way to enable it but I'm having a hard time determining whether that step is working or not.

The docker image is created and run with:

    mvn clean spring-boot:build-image
    docker compose -f app.yml up

I've added environment variables to app.yml file (hostname replaced with XXXXXX):

    services:
      appname:
        image: appname:latest
        environment:
          - SPRING_PROFILES_ACTIVE=docker-local
          - BPE_OTEL_TRACES_EXPORTER=zipkin
          - BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://XXXXXX:9411/api/v2/spans
          - BPE_OTEL_SERVICE_NAME=appname
          - BPE_OTEL_JAVAAGENT_ENABLED=true

I don't think these environment variables are being set, however because I don't see them when I run:

docker run --entrypoint launcher -it appname:latest bash -c set

I don't see any traces going to zipkin and I don't see anything in the logs.

Without docker, I have everything working fine.

I tried to figure out if I just need to use a more recent version of spring boot but I couldn't find a way to determine that.

I couldn't find any examples of apps that have this working.

Edit to include working solution:

Martin Theiss's solution is correct. Here is the section of the pom.xml that does everything:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <image>
                    <name>appname</name>
                    <buildpacks>
                        <buildpack>paketo-buildpacks/java</buildpack>
                        <buildpack>gcr.io/paketo-buildpacks/opentelemetry</buildpack>
                    </buildpacks>
                    <env>
                        <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
                        <BPE_OTEL_JAVAAGENT_ENABLED>true</BPE_OTEL_JAVAAGENT_ENABLED>
                        <BPE_OTEL_TRACES_EXPORTER>zipkin</BPE_OTEL_TRACES_EXPORTER>
                        <BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT>http://zipkinhost:9411/api/v2/spans</BPE_OTEL_EXPORTER_ZIPKIN_ENDPOINT>
                        <BPE_OTEL_SERVICE_NAME>appname</BPE_OTEL_SERVICE_NAME>
                    </env>
                </image>
            </configuration>
        </plugin>

Note that this is sending traces directly to zipkin. Eventually I'll be sending traces to an opentelemetry collector.

Note also that I was wrong to try to put environment variables in the spring app.yml config file. These should be put in the pom.xml as per above.


Solution

  • OpenTelemetry buildpack is not contained in the buildpacks/java. You have to specify it additionally.

                        <image>
                            <buildpacks>
                                <buildpack>paketo-buildpacks/java</buildpack>
                                <buildpack>gcr.io/paketo-buildpacks/opentelemetry</buildpack>
                            </buildpacks>
                            <env>
                                <BP_OPENTELEMETRY_ENABLED>true</BP_OPENTELEMETRY_ENABLED>
                            </env>
                        </image>