Node.js

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 tracer can send custom metrics to the Datadog Agent in two ways: using an HTTP proxy (default) or using UDP (fallback).

By default, the tracer attempts to send metrics to an HTTP endpoint within the Datadog Agent. This is the preferred and most reliable method, as HTTP is a connection-oriented protocol that ensures delivery. If the Agent’s HTTP endpoint is unavailable, the tracer automatically falls back to sending metrics using UDP to the DogStatsD server on port 8125.

Note: You can’t force the tracer to use UDP if the HTTP endpoint is available.

For example, you can instrument your code to increment a counter for page views:

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

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

Agent configuration

You must ensure the Agent is configured to accept incoming metrics.

  • HTTP (Default): Metric submission over HTTP uses the same endpoint as trace collection. If you have already configured your application for tracing, no additional Agent configuration is needed. The Agent listens for HTTP traffic on port 8126 by default.

  • UDP (Fallback): For the UDP fallback to work, you must enable DogStatsD on the Agent. To allow metrics from containers or other hosts, set dogstatsd_non_local_traffic to true.

    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
    

Application configuration

By default, the tracer attempts to connect to the Agent at localhost. To specify a different agent host, use the DD_AGENT_HOST environment variable.

When DD_AGENT_HOST is set, the tracer automatically targets the correct ports for both HTTP and UDP.

# The tracer will attempt to send metrics to http://your-agent-host:8126
# If that fails, it will fall back to UDP on your-agent-host:8125
DD_AGENT_HOST=your-agent-host node app.js

For additional information about the Node.js integration, see the Metrics Submission page.

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.

Data Collected

Metrics

runtime.node.cpu.user
(gauge)
CPU usage in user code
Shown as percent
runtime.node.cpu.system
(gauge)
CPU usage in system code
Shown as percent
runtime.node.cpu.total
(gauge)
Total CPU usage
Shown as percent
runtime.node.mem.rss
(gauge)
Resident set size
Shown as byte
runtime.node.mem.heap_total
(gauge)
Total heap memory
Shown as byte
runtime.node.mem.heap_used
(gauge)
Heap memory usage
Shown as byte
runtime.node.mem.external
(gauge)
External memory
Shown as byte
runtime.node.heap.total_heap_size
(gauge)
Total heap size
Shown as byte
runtime.node.heap.total_heap_size_executable
(gauge)
Total executable heap size
Shown as byte
runtime.node.heap.total_physical_size
(gauge)
Total physical heap size
Shown as byte
runtime.node.heap.used_heap_size
(gauge)
Used heap size
Shown as byte
runtime.node.heap.heap_size_limit
(gauge)
Heap size limit
Shown as byte
runtime.node.heap.malloced_memory
(gauge)
Malloced memory
Shown as byte
runtime.node.heap.peak_malloced_memory
(gauge)
Peak allocated memory
Shown as byte
runtime.node.heap.size.by.space
(gauge)
Heap space size
Shown as byte
runtime.node.heap.used_size.by.space
(gauge)
Heap space used size
Shown as byte
runtime.node.heap.available_size.by.space
(gauge)
Heap space available size
Shown as byte
runtime.node.heap.physical_size.by.space
(gauge)
Heap space physical size
Shown as byte
runtime.node.process.uptime
(gauge)
Process uptime
Shown as second
runtime.node.event_loop.delay.max
(gauge)
Maximum event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.min
(gauge)
Minimum event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.avg
(gauge)
Average event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.sum
(rate)
Total event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.median
(gauge)
Median event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.95percentile
(gauge)
95th percentile event loop delay
Shown as nanosecond
runtime.node.event_loop.delay.count
(rate)
Event loop iteration count where a delay is detected
Shown as execution
runtime.node.gc.pause.max
(gauge)
Maximum garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.min
(gauge)
Minimum garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.avg
(gauge)
Average garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.sum
(rate)
Total garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.median
(gauge)
Median garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.95percentile
(gauge)
95th percentile garbage collection pause
Shown as nanosecond
runtime.node.gc.pause.count
(rate)
Number of garbage collections
Shown as garbage collection
runtime.node.gc.pause.by.type.max
(gauge)
Maximum garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.min
(gauge)
Minimum garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.avg
(gauge)
Average garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.sum
(rate)
Total garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.median
(gauge)
Median garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.95percentile
(gauge)
95th percentile garbage collection pause by type
Shown as nanosecond
runtime.node.gc.pause.by.type.count
(rate)
Number of garbage collections by type
Shown as garbage collection

Troubleshooting

Need help? Contact Datadog support.

Further Reading