< Back to list

New Relic Java Agent

New Relic is an application performance monitoring (APM) and Software Analytics solution which provides services to monitor your applications, and all other components in your infrastructure. New Relic offers language agents for 6 most common languages (java, .NET, node.js, ruby, python, PHP).

This document provides information on how to use a base docker image with New Relic's java agent to bind it with your applications that are developed in java language. The process for the other 5 languages is very similar to java with some language-specific differences.

~~~
- Use registry-nrpartners.rhcloud.com/newrelic/rhel71:nr-java as the base docker image (which contains all dependencies + JRE 8 & New Relic Agent 3.17.0.
- Add all necessary Dockerfile instructions for your application
- Add the following 3 environment variables using Dockerfile's "ENV" directive. These environment variables are used to pass information to the container to be consumed by New Relic java agent:

  • ENV NEWRELIC_KEY REAL_NR_LICENSE_KEY : you need to have a valid New Relic account to obtain a license key

  • ENV NEWRELIC_APP_NAME NR_APPLICATION_NAME : this is the app name by which your application is identified in New Relic

  • ENV ADDITIONAL_VM_ARGS= : any additional New Relic configuration changes that you need to pass to the agent goes into this environment variable (i.e. "ENV ADDITIONAL_VM_ARGS -Dnewrelic.config.attributes.include=request.parameters.*"). If you don’t want to change any additional configuration just set to blank. By default its value is set to blank.

    • Make sure your application startup will include the following java VM arguments in its startup process and will assign the values from the environment variables to them:
      -javaagent:/opt/newrelic/newrelic.jar -Dnewrelic.config.license_key=${NEWRELIC_KEY} -Dnewrelic.config.app_name=${NEWRELIC_APP_NAME} ${ADDITIONAL_VM_ARGS}

Alternatively, instead of defining 3 ENV variables you can use one environment variable called "JAVA_OPTS" and assign "-javaagent" and all "-D" options to it.

docker build command for building the docker image using your application’s Dockerfile:

    docker build -t MY-CONTAINER  .

docker run command:

    docker run -e NEWRELIC_KEY=<NR_LICENSE_KEY> -e NEWRELIC_APP_NAME=my-docker-app -e ADDITIONAL_VM_ARGS="-Dnewrelic.config.attributes.include=request.parameters.*" MY-CONTAINER

Category

Developer tools

Red Hat Certifications

This product has been certified to run on the following Red Hat products and technologies: