What is dd-trace?
The dd-trace npm package is a Node.js APM (Application Performance Monitoring) client for Datadog. It allows you to monitor the performance of your Node.js applications, providing insights into the runtime and helping you to diagnose and optimize your code.
What are dd-trace's main functionalities?
Tracing
This feature allows you to trace the execution of your application, marking and timing various operations within your code. You can tag spans with metadata and monitor the performance of individual requests or tasks.
const tracer = require('dd-trace').init();
// Instrument a function
tracer.trace('web.request', (span) => {
// Do some work
span.setTag('http.status_code', 200);
});
Automatic Instrumentation
dd-trace can automatically instrument popular libraries and frameworks such as Express, Koa, GraphQL, and many others. This means that you can get insights into how these libraries are performing without having to manually instrument code.
const tracer = require('dd-trace').init();
// Automatically instruments supported libraries
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World!'));
app.listen(3000);
Custom Tags and Metrics
You can add custom tags and metrics to your traces to provide additional context and granularity. This can be useful for filtering and searching through your traces in the Datadog APM interface.
const tracer = require('dd-trace').init();
// Add custom tags to a span
tracer.trace('web.request', (span) => {
span.setTag('my_tag', 'my_value');
span.setMetric('my_metric', 100);
});
Distributed Tracing
Distributed tracing allows you to trace requests as they move across different services and components in your system. This is essential for understanding the performance of microservices architectures.
const tracer = require('dd-trace').init();
// Continue a trace across asynchronous boundaries
async function part1() {
return tracer.trace('part1', async () => {
// Do something
});
}
async function part2() {
return tracer.trace('part2', async (span) => {
// Do something else
span.context().toTraceId();
});
}
Other packages similar to dd-trace
newrelic
New Relic's APM tool is similar to dd-trace in that it provides performance monitoring and tracing for Node.js applications. It offers a wide range of features for monitoring application health and is known for its user-friendly interface. However, it is a different product with its own set of integrations and pricing model.
elastic-apm-node
Elastic APM Node.js Agent is part of the Elastic APM suite, which integrates with the Elastic Stack (Elasticsearch, Kibana, etc.). It provides similar functionalities for monitoring Node.js applications, including distributed tracing and performance metrics. It is more focused on integration with the Elastic ecosystem.
zipkin
Zipkin is an open-source distributed tracing system. It provides features to gather timing data needed to troubleshoot latency problems in service architectures. While it supports various programming languages, it requires more manual setup and configuration compared to dd-trace.
dd-trace-js
JavaScript APM Tracer
Datadog APM tracing client for JavaScript.
Getting Started
For a basic product overview, check out our setup documentation.
For installation, configuration, and details about using the API, check out our API documentation.
For descriptions of terminology used in APM, take a look at the official documentation.
Development
Before contributing to this open source project, read our CONTRIBUTING.md.
Requirements
Since this project supports multiple Node versions, using a version
manager such as nvm is recommended.
We use yarn for its workspace functionality, so make sure to install that as well.
To get started once you have Node and yarn installed, run:
$ yarn
Testing
Before running the tests, the data stores need to be running.
The easiest way to start all of them is to use the provided
docker-compose configuration:
$ docker-compose up -d -V --remove-orphans --force-recreate
Unit Tests
To run the unit tests, use:
$ yarn test
To run the unit tests continuously in watch mode while developing, use:
$ yarn tdd
Memory Leaks
To run the memory leak tests, use:
$ yarn leak
Please note that memory leak tests only run on Node >=8
.
Linting
We use ESLint to make sure that new code is
conform to our coding standards.
To run the linter, use:
$ yarn lint
Continuous Integration
We rely on CircleCI 2.0 for our tests. If you want to test how the CI behaves
locally, you can use the CircleCI Command Line Interface as described here:
https://circleci.com/docs/2.0/local-jobs/
After installing the circleci
CLI, simply run one of the following:
$ circleci build --job lint
$ circleci build --job node-leaks
$ circleci build --job node-core-4
$ circleci build --job node-core-6
$ circleci build --job node-core-8
$ circleci build --job node-core-10
$ circleci build --job node-core-latest
Benchmarks
When two or more approaches must be compared, please write a benchmark
in the benchmark/index.js
module so that we can keep track of the
most efficient algorithm. To run your benchmark, just:
$ yarn bench