[Java] Integrate APM in Dockerized Spring Boot Java application

Hello there,

We’ve properly digested the docs to integrate APM into a docker container to monitor a java application that runs inside that container. The java agent was properly configured in the Dockerfile.

We can build successfully the image and also run the container, but the java app is not sending data to new relic.

Even when New Relic Diagnostics is installed, and all the logs seems fine. It keeps invalidating our ingest license key.

This is my Dockerfile and screenshot of the nrdiag:

FROM maven:3.8.1-ibmjava-alpine as build
COPY pom.xml .
RUN mvn verify clean --fail-never --quiet
COPY . .
RUN mvn package -Dmaven.test.skip=true --quiet


FROM adoptopenjdk/openjdk11:alpine as deploy

RUN apk upgrade --update && \
    apk add --update tzdata && \
    apk add --update curl && \
    ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime && \
    rm -fr /tmp/* /var/cache/apk/*

# New Relic
VOLUME /tmp
RUN mkdir -p /var/log

#   Installing curl and zip
RUN apk --update --no-cache add unzip

#   Configure new relic logs
RUN mkdir -p /opt/newrelic/logs
RUN chmod 777 /opt/newrelic && chmod 777 /opt/newrelic/logs

#   Download and Install APM
RUN curl "http://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip" -o /tmp/newrelic.zip \
    && unzip /tmp/newrelic.zip -d /opt/ \
    && rm /tmp/newrelic.zip

RUN cat /opt/newrelic/newrelic.yml | sed -e "s/<%= license_key %>/$NRA_LICENSE_KEY/" \
    -e "s/app_name:.*/app_name: $NRA_APP_NAME/" > /opt/newrelic/newrelic.yml.new

# Overwrite the default newrelic.yml
RUN mv /opt/newrelic/newrelic.yml.new /opt/newrelic/newrelic.yml

RUN addgroup -S microservices && \
    adduser -S -D -h /app appuser microservices && \
    chown -R appuser:microservices /app
USER appuser

ARG DEPENDENCY=/target/dependency
COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF
COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app


ENV JAVA_TOOL_OPTIONS \
  -Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector \
  -Dlog4j2.formatMsgNoLookups=true \
  -Dspring.jpa.hibernate.ddl-auto=update \
  -Djava.net.debug=handshake \
  -XX:+UnlockExperimentalVMOptions \
  -XX:+UseG1GC \
  -XX:-UseCMSInitiatingOccupancyOnly \
  -XX:+UseStringDeduplication \
  -XX:MaxGCPauseMillis=120 \
  -XX:InitiatingHeapOccupancyPercent=60 \
  -XX:SurvivorRatio=2 \
  -XX:ParallelGCThreads=10 \
  -XX:ConcGCThreads=5

CMD java $JAVA_ADDITIONAL_OPTS --add-opens=java.base/java.net=ALL-UNNAMED -javaagent:/opt/newrelic/newrelic.jar -cp app:app/lib/* com.kinship.integration.petprofile.PetprofileServiceApplication

The license key and nr app name are been passed from an env_file


  • APM Agent Language = Java
  • APM Agent Version = Java Agent version 7.6.0
  • Operating System = Linux
  • Operating System Version
  • Frameworks your app is using = Springboot

I got corrected that my use of “invalidate” might have been wrong. As seen in the screenshot, what I meant was the nrdiag was failing to validate the ingest license key. I hope this clears things up? :smile:

Hi @Ayobami.Ayinde

Nice to see your first post in the community, you are very welcome to the Explorers Hub!

Thank you for confirming that the nrdiag was failing to validate the ingest license key, this was helpful to highlight.

I must confess this is out of my scope, so I will loop in a Java expert here to help support this issue, They will reach out via this post.

Should you have any new updates or questions we are here, please reach out! We got you covered!

1 Like

Hello @dcody any headway yet please?

Hi @Ayobami.Ayinde

I see this is still being worked out, however the engineer working on it is currently out of office due to timezone difference.

I will reach out to them, and ask them can they update you here on their findings so far.

Hey there @ ,

Thanks for reaching out to the New Relic Community! I think I might be able to shed some light on your situation. Can you confirm that you’re passing the ingest license key as shown below:

INGEST - LICENSE (original account license key)

You should be able to find this in your agent UI as shown in the screen shot below

The key you’d want to use in this case would be similar to the one shown in the green box

I hope this helps!

Cheers

Screen Shot 2022-04-28 at 9.55.21 PM

Yes. The license key being passed is the ingest license key. The second one in the screenshot I sent. Thanks

Hi @Ayobami.Ayinde,

Thank you for the feedback here.

Can you confirm that you are still facing the issue or was the update provided by @eschwall able to help resolve this issue.

Hello @dcody The update by @eschwall was just a question about our license key. It wasn’t a solution to the issue. But the issue has been solved on ur end now though. Thank you.

Hi @Ayobami.Ayinde

Thank you for coming back here and confirming that it was a followup question but that since the issue was solved.

Please do feel free to share any steps you took to help achieve this.

Wishing you a great day!

The issue was in our Dockerfile. We had to replace CMD with ENTRY in order for the spring boot java agent to be picked up.

@Ayobami.Ayinde

Thank you again for this, we really appreciate it.

To confirm you have worked around the issue?

Yes we have. And we’re fine now. Thank you.

Great, delight to hear.

Hope you have a great day!