Type to search.

Configuring the agent

Serverless Observability

Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

APM Agent Node.js

The Elastic APM Node.js agent enables you to trace the execution of operations in your Node.js applications, sending performance metrics and errors to the Elastic APM Server.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

There are multiple ways to configure the Node.js agent. In order of precedence:

  1. APM Agent Central Configuration via Kibana. (supported options are marked with dynamic config )
  2. Environment variables.
  3. If calling the apm.start() function, 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.

Configuration options marked with the dynamic config badge can be changed at runtime when set from a supported source.

The Node.js Agent supports Central configuration, which allows you to fine-tune certain configurations via the APM app in Kibana. This feature is enabled in the Agent by default, with centralConfig.

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

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

This example shows how to configure the agent to only be active in production:

JavaScript
// Add this to the VERY top of the first file loaded in your app
require('elastic-apm-node').start({
  // 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: '',

  // Use if APM Server uses API keys for authentication
  apiKey: '',

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

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

The Node.js agent looks for a file named elastic-apm-node.js in the current working directory. You can specify a custom path for this file with the configFile configuration option.