Configuring the agentedit

There are three ways to configure the Node.js agent. In order of precedence (higher overwrites lower):

  1. APM Agent Configuration via Kibana. Enabled with centralConfig.
  2. Environment variables.
  3. If calling the apm.start() function, you can supply a configurations object as the first argument.
  4. Via the agent configuration file.

For information on the available configuration properties, and the expected names of environment variables, see the Configuration options documentation.

Agent configuration objectedit

To use the optional options argument, simply pass it into the apm.start() method:

var apm = require('elastic-apm-node').start({
  // add configuration options here

Here’s an example usage configuring the agent to only be active in production:

// Add this to the VERY top of the first file loaded in your app
  // Override service name from package.json
  // Allowed characters: a-z, A-Z, 0-9, -, _, and space
  serviceName: '',

  // Use if APM Server requires a token
  secretToken: '',

  // Set custom APM Server URL (default: http://localhost:8200)
  serverUrl: '',

  // Only activate the agent if it's running in production
  active: process.env.NODE_ENV === 'production'

Agent configuration fileedit

The Node.js agent will look for a file named elastic-apm-node.js in the current working directory. You can specify a custom path for this file using the configFile config option.