NodeJS

Overview

The Node.js integration allows you to collect and monitor your Node.js application logs, traces, and custom metrics.

Setup

Metric collection

The Node.js integration enables you to monitor a custom metric by instrumenting a few lines of code. For instance, you can have a metric that returns the number of page views or the time of any function call.

For additional information about the Node.js integration, see the guide on submitting metrics.

// Require dd-trace
const tracer = require('dd-trace').init();

// Increment a counter
tracer.dogstatsd.increment('page.views');

Note that for custom metrics to work you need to enable DogStatsD on the Agent. Collection is enabled by default, but the Agent only listens for metrics from localhost. To allow external metrics, you need to either set an environment variable or update the config file:

DD_USE_DOGSTATSD=true # default
DD_DOGSTATSD_PORT=8125 # default
DD_DOGSTATSD_NON_LOCAL_TRAFFIC=true # if expecting external metrics
use_dogstatsd: true # default
dogstatsd_port: 8125 # default
dogstatsd_non_local_traffic: true # if expecting external metrics

You’ll also need to configure your application to use the agent’s DogStatsD collector:

DD_DOGSTATSD_HOSTNAME=localhost DD_DOGSTATSD_PORT=8125 node app.js

Trace collection

See the dedicated documentation for instrumenting your Node.js application for sending traces to Datadog.

Log collection

Available for Agent v6.0+

See the dedicated documentation to set up Node.js log collection for forwarding your logs to Datadog.

Profile collection

See the dedicated documentation for enabling the Node.js profiler.

Troubleshooting

Need help? Contact Datadog support.

Further Reading