opentelemetry-javaagent.jar issue with spring boot application

1k Views Asked by At

In my spring boot application using Jaeger UI to track the logs.We are using 'bootbuildimage' plugin to build and push the image. due to this not using 'Docker' file and only using 'docker-compose.yml' only. due to this the following details given in docker file is not executing. ADD https://github.com/open-telemetry/opentelemetry-java- instrumentation/releases/latest/download/opentelemetry-javaagent.jar . ENV JAVA_TOOL_OPTIONS "-javaagent:./opentelemetry-javaagent.jar"

How to configure opentelemetry-javaagent.jar without using Docker file to trace the logs in Jaeger UI?

docker-compose.yml is given below

services:
  app:
    build: 
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:8080"
    image :  demo-management
    container_name: demo-management-service
    environment :
      - OTEL_SERVICE_NAME=demo-management
      - OTEL_TRACES_EXPORTER=jaeger
      - OTEL_EXPORTER_JAEGER_ENDPOINT=http://jaeger:14250
      - OTEL_METRICS_EXPORTER=none
      - OTEL_EXPORTER_JAEGER_TIMEOUT=40000
  jaeger:
    container_name: jaeger
    image: jaegertracing/all-in-one:latest
    ports:
      - "16686:16686"
      - "14250:14250"
networks:
  demo-management-network: {}

Docker file is given below. This is not going to use so need to configure last two lines in another method.

FROM openjdk:17
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar .
ENV JAVA_TOOL_OPTIONS "-javaagent:./opentelemetry-javaagent.jar"

Configure following two lines other than Docker file

ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar .
ENV JAVA_TOOL_OPTIONS "-javaagent:./opentelemetry-javaagent.jar
1

There are 1 best solutions below

0
kjrun316 On

Update: I was able to export traces by adding an entrypoint to the docker compose which overrides the image entrypoint. The docker compose first downloads the agent jar and then runs the app jar.

version: "3"

services:
  app:
    build: 
      context: .
      dockerfile: Dockerfile
    container_name: demo-management-service
    entrypoint:
      - /bin/bash
      - -c
      - |
        curl -L -H 'Accept:application/zip' https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar -o otel-javaagent.jar
        java -javaagent:otel-javaagent.jar -jar app.jar
    environment :
      - OTEL_SERVICE_NAME=demo-management
      - OTEL_TRACES_EXPORTER=jaeger
      - OTEL_EXPORTER_JAEGER_ENDPOINT=http://jaeger:14250
      - OTEL_METRICS_EXPORTER=none
      - OTEL_EXPORTER_JAEGER_TIMEOUT=40000
    ports:
      - "8080:8080"
  jaeger:
    container_name: jaeger
    image: jaegertracing/all-in-one:latest
    ports:
      - "16686:16686"
      - "14250:14250"

networks:
  demo-management-network: {}

Below is the Dockerfile.

FROM openjdk:17
ARG JAR_FILE=build/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Hope this helps you.