You can use our Node.js agent to instrument Node.js applications deployed in Docker containers. This document explains how to build, configure, and deploy your Dockerized Node.js application that has been instrumented with New Relic.
With just a few additions your existing Dockerfile can be used with our Node.js agent. You'll configure the agent by running your new Docker image with environment variables set.
Depending on how your container is setup, you can edit the
newrelicmodule first with Node.js
--requireflag by running
node -r newrelic YOUR_PROGRAM.js. If you can't control how your program runs, you can load the
newrelicmodule before any other module in your program by adding
For Next.js use
TipIf you have an npm script to run your program such as
npm start, you can programmatically modify this script by running
npm pkg set scripts.start="node -r newrelic your-program.js".
Build your Docker image the way you normally do.
To run your Docker app with the agent enabled, add your and app name to your
docker runcommand as environment variables:bash$docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \>-e NEW_RELIC_APP_NAME="YOUR_APP_NAME" \>YOUR_IMAGE_NAME:latest
Did this doc help with your installation?
Don't include your license key in your Dockerfile or Docker image. For more information, see our documentation on license key security.
$docker run -e NEW_RELIC_LICENSE_KEY=YOUR_LICENSE_KEY \>-e NEW_RELIC_APP_NAME="YOUR_APP_NAME" \>-e NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true \>YOUR_IMAGE_NAME:latest
You can also set configuration options in your Dockerfile using
ENV NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true \NEW_RELIC_LOG=stdout# etc.