Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error opening zip file or JAR manifest missing : /app/opentelemetry-javaagent.jar #13127

Closed
kramchas opened this issue Jan 30, 2025 · 5 comments
Labels
bug Something isn't working needs author feedback Waiting for additional feedback from the author

Comments

@kramchas
Copy link

Describe the bug

Help!!!
My dockerfile

Stage 1: Dependency identification (18-alpine)

FROM amazoncorretto:18-alpine as deps

Identify dependencies

COPY ./app/build/libs/app--SNAPSHOT.jar /app/app.jar
RUN mkdir /app/unpacked &&
cd /app/unpacked &&
unzip ../app.jar &&
cd .. &&
$JAVA_HOME/bin/jdeps
--ignore-missing-deps
--print-module-deps
-q
--recursive
--multi-release 17
--class-path="./unpacked/BOOT-INF/lib/
"
--module-path="./unpacked/BOOT-INF/lib/*"
./app.jar > /deps.info

Stage 2: Build JRE (17-alpine)

FROM amazoncorretto:17-alpine as openjdk

Required for strip-debug to work

RUN apk add --no-cache binutils

Copy module dependencies info

COPY --from=deps /deps.info /deps.info

RUN echo "cat deps.info,jdk.crypto.ec,jdk.zipfs" > /deps.info

Build small JRE image

RUN $JAVA_HOME/bin/jlink
--verbose
--add-modules $(cat deps.info)
--strip-debug
--no-man-pages
--no-header-files
--compress=2
--output /customjre

Stage 3: Main application image (alpine)

FROM alpine:latest

Set Java Home and PATH

ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"

Copy JRE from the previous image

COPY --from=openjdk /customjre $JAVA_HOME

Add application user

ARG APPLICATION_USER=flc
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER

Prepare app directory

RUN mkdir /app &&
chown -R $APPLICATION_USER /app

USER 1000

Copy the application JAR

COPY --chown=1000:1000 ./app/build/libs/app-*-SNAPSHOT.jar /app/app.jar

Copy the Elastic APM agent and OpenTelemetry Java agent

COPY --chown=1000:1000 ./elastic-apm-agent-1.35.0.jar /app/elastic-apm-agent-1.35.0.jar

Add OpenTelemetry Java Agent

ENV OTEL_AGENT_VERSION=1.28.0
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${OTEL_AGENT_VERSION}/opentelemetry-javaagent.jar /app/opentelemetry-javaagent.jar

USER root
RUN chmod 777 /app/opentelemetry-javaagent.jar

Verify if the OpenTelemetry Java agent is successfully added

RUN ls -lh /app/opentelemetry-javaagent.jar

USER 1000

WORKDIR /app

Expose application port

EXPOSE 8081

Define entrypoint with OpenTelemetry agent and Elastic APM agent

CMD /jre/bin/java $JAVA_MEMORY_OPTS $GC_OPTS $JAVA_OPTS
-javaagent:/app/opentelemetry-javaagent.jar
-Djava.security.egd=file:/dev/./urandom
-jar app.jar

LOGS:
Error opening zip file or JAR manifest missing : /app/opentelemetry-javaagent.jar
Error occurred during initialization of VM
agent library failed to init: instrument

Steps to reproduce

?

Expected behavior

?

Actual behavior

?

Javaagent or library instrumentation version

1.28, 1.27

Environment

JDK:
OS:

Additional context

No response

@kramchas kramchas added bug Something isn't working needs triage New issue that requires triage labels Jan 30, 2025
@jaydeluca
Copy link
Member

Do you have some requirement to run such an old version of the agent (1.28.0), when the latest is 2.12? Also, why are you including the elastic apm agent in your container?

I copied the code you used to embed the javaagent into an image and I am not able to reproduce your issue, everything works fine as far as I can tell. Can you run your container, exec into it, and look to make sure the OTel javaagent file is where you expect it to be?

@laurit
Copy link
Contributor

laurit commented Jan 30, 2025

Verify that /app/opentelemetry-javaagent.jar exists and actually contains the agent.

@kramchas
Copy link
Author

@jaydeluca @laurit HEY
/app/opentelemetry-javaagent.jar exists, after upgrade my dockerfile like this

Stage 1: Dependency identification (18-alpine)

FROM amazoncorretto:18-alpine as deps

Identify dependencies

COPY ./app/build/libs/app--SNAPSHOT.jar /app/app.jar
RUN mkdir /app/unpacked &&
cd /app/unpacked &&
unzip ../app.jar &&
cd .. &&
$JAVA_HOME/bin/jdeps
--ignore-missing-deps
--print-module-deps
-q
--recursive
--multi-release 17
--class-path="./unpacked/BOOT-INF/lib/
"
--module-path="./unpacked/BOOT-INF/lib/*"
./app.jar > /deps.info

Stage 2: Build JRE (17-alpine)

FROM amazoncorretto:17-alpine as openjdk

Required for strip-debug to work

RUN apk add --no-cache binutils

Copy module dependencies info

COPY --from=deps /deps.info /deps.info

RUN echo "cat deps.info,jdk.crypto.ec,jdk.zipfs" > /deps.info

Build small JRE image

RUN $JAVA_HOME/bin/jlink
--verbose
--add-modules $(cat deps.info)
--strip-debug
--no-man-pages
--no-header-files
--compress=2
--output /customjre

Stage 3: Main application image (alpine)

FROM alpine:latest

Set Java Home and PATH

ENV JAVA_HOME=/jre
ENV PATH="${JAVA_HOME}/bin:${PATH}"

Copy JRE from the previous image

COPY --from=openjdk /customjre $JAVA_HOME

Add application user

ARG APPLICATION_USER=flc
RUN adduser --no-create-home -u 1000 -D $APPLICATION_USER

Prepare app directory

RUN mkdir /app &&
chown -R $APPLICATION_USER /app

USER $APPLICATION_USER # Use application user

Copy the application JAR

COPY --chown=1000:1000 ./app/build/libs/app-*-SNAPSHOT.jar /app/app.jar

Add OpenTelemetry Java Agent (use version 2.12.0 as per recommendation)

ENV OTEL_AGENT_VERSION=2.12.0
ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${OTEL_AGENT_VERSION}/opentelemetry-javaagent.jar /app/opentelemetry-javaagent.jar

WORKDIR /app

Expose application port

EXPOSE 8081

Define entrypoint with OpenTelemetry agent

CMD /jre/bin/java $JAVA_MEMORY_OPTS $GC_OPTS $JAVA_OPTS
-javaagent:/app/opentelemetry-javaagent.jar
-Djava.security.egd=file:/dev/./urandom
-jar app.jar

still getting the error
Error opening zip file or JAR manifest missing : /app/opentelemetry-javaagent.jar
Error occurred during initialization of VM
agent library failed to init: instrument

@laurit
Copy link
Contributor

laurit commented Jan 30, 2025

@kramchas could you provide a sample project that reproduces this issue

@breedx-splk breedx-splk removed the needs triage New issue that requires triage label Jan 30, 2025
@breedx-splk
Copy link
Contributor

I wonder if the problem is that the github url to fetch the agent goes through a redirect: https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v${OTEL_AGENT_VERSION}/opentelemetry-javaagent.jar

I'm not sure if the docker ADD will do the right thing in terms of following redirects. You might try manually downloading and using ADD with a local file, or doing a curl or wget from within the container as a build step instead.

@breedx-splk breedx-splk added the needs author feedback Waiting for additional feedback from the author label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs author feedback Waiting for additional feedback from the author
Projects
None yet
Development

No branches or pull requests

4 participants