Context: I'm trying to use opentelemetry-javaagent in my spring project.
If I get the file using curl in my Dockerfile:
RUN curl https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.30.0/opentelemetry-javaagent.jar -o /tmp/opentelemetry-javaagent.jar && \
chmod 540 /tmp/opentelemetry-javaagent.jar
When I run the docker image I get the following error:
Error opening zip file or JAR manifest missing : /tmp/opentelemetry-javaagent.jar
Error occurred during initialization of VM
agent library failed to init: instrument
However, if I manually download that exact file and add it:
ADD opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar
RUN chmod 540 /tmp/opentelemetry-javaagent.jar
It works fine. I'm probably missing something obvious but can't put my finger on it. Does anyone know what I'm missing? Thanks in advance.
Here is the full Dockerfile:
FROM eclipse-temurin:17-jre
ARG RUN_JAVA_VERSION=1.3.8
ENV APP my-project
ENV JAVA_OPTIONS="-XshowSettings:vm"
ENV SPRING_PROFILES_ACTIVE=docker
ENV JAVA_TOOL_OPTIONS -agentlib:jdwp=transport=dt_socket,address=10200,server=y,suspend=n -javaagent:/tmp/opentelemetry-javaagent.jar -Dotel.service.name=format-adapter -Dotel.traces.exporter=zipkin
WORKDIR /app
RUN apt-get update -q \
&& apt-get install -y --no-install-recommends wget curl \
&& rm -Rf /var/lib/apt /var/cache/apt
RUN curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /app/run-java.sh && \
chmod 540 /app/run-java.sh
#THIS DOESN'T WORK
RUN curl https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.30.0/opentelemetry-javaagent.jar -o /tmp/opentelemetry-javaagent.jar && \
chmod 540 /tmp/opentelemetry-javaagent.jar
##THIS WORKS
#ADD opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar
#RUN chmod 540 /tmp/opentelemetry-javaagent.jar
ADD build/libs/${APP}-*.jar /app/${APP}.jar
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost:${SERVER_PORT}/actuator/health || exit 1
ENTRYPOINT ["/app/run-java.sh"]
The given URL generates a redirect that curl
does not follow unless you add the -L
switch, so the curl
command in your Dockerfile
does not download anything.
As an alternative, wget
follows redirects by default (I see that you install both curl
and wget
but the base image already contains both); however a better, Dockerfile
-specific, alternative is the ADD
command:
ADD --chmod=540 https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.30.0/opentelemetry-javaagent.jar /tmp/opentelemetry-javaagent.jar
In any case you can remove the RUN apt-get
block to get a smaller image.