Prerequisites
- Node.js >= 18 (for dd-trace v5)
- A running Datadog Agent (or use agentless mode)
Setup
Initialize the tracer
Initialize dd-trace before importing any other modules. This is critical — the tracer must load first to instrument your libraries.
- CommonJS
- ESM
- Environment variable
Create a dedicated initialization file:Then require it as the very first line of your entry point:
tracer.js
server.js
Configure the Datadog Agent connection
By default, dd-trace connects to the Datadog Agent at Or pass them to
localhost:8126. Set these environment variables if your Agent runs elsewhere:init():What happens automatically
Once initialized, dd-trace automatically instruments your supported libraries with no additional code:- HTTP servers: Express, Fastify, Koa, Hapi, Restify, Next.js
- HTTP clients:
http,https,fetch,undici,axios - Databases: PostgreSQL, MySQL, MongoDB, Redis, Elasticsearch
- Message queues: Kafka, RabbitMQ, SQS, BullMQ
- And 100+ more — see the full plugin list
Next steps
Configuration Options
Customize service name, environment, sampling rates, and more.
Manual Instrumentation
Add custom spans to your business logic with tracer.trace().
All Integrations
Browse all 100+ supported libraries and frameworks.
Environment Variables
Full reference of all DD_* environment variables.
