Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
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.
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();
});
}
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.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 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.
Experimental JavaScript Tracer!
This project is experimental and under active development. Use it at your own risk.
npm install --save dd-trace
Node >= 4 is required.
Simply require and initialize the tracer and all supported libraries will automatically be instrumented.
// The tracer must be initialized before other libraries
const tracer = require('dd-trace').init()
Options can be configured as a parameter to the init()
method
or as environment variables.
Config | Environment Variable | Default | Description |
---|---|---|---|
debug | DD_TRACE_DEBUG | false | Enable debug logging in the tracer. |
service | DD_SERVICE_NAME | The service name to be used for this program. | |
hostname | DD_TRACE_AGENT_HOSTNAME | localhost | The address of the trace agent that the tracer will submit to. |
port | DD_TRACE_AGENT_PORT | 8126 | The port of the trace agent that the tracer will submit to. |
flushInterval | 2000 | Interval in milliseconds at which the tracer will submit traces to the agent. | |
experimental | {} | Experimental features can be enabled all at once using boolean true or individually using key/value pairs. Available experimental features: asyncHooks . | |
plugins | true | Whether or not to enable automatic instrumentation of external libraries using the built-in plugins. |
The following libraries are instrumented automatically by default:
This library is OpenTracing compliant, so once the tracer is initialized it can be used as a global tracer.
const tracer = require('dd-trace').init()
const opentracing = require('opentracing')
opentracing.initGlobalTracer(tracer)
Then the tracer will be available with opentracing.globalTracer()
.
See the OpenTracing JavaScript documentation and API for more details.
NOTE: When using OpenTracing, context propagation is not handled automatically.
In some cases you may want to do manual instrumentation. For example if there is no built-in plugin covering a library you are using or if you want more control on how instrumentation is done.
const tracer = require('dd-trace').init()
const http = require('http')
const server = http.createServer((req, res) => {
const options = {
resource: '/hello/:name',
type: 'web',
tags: {
'span.kind': 'server',
'http.method': 'GET',
'http.url': req.url,
'http.status_code': '200'
}
}
tracer.trace('say_hello', options, span => {
res.write('Hello, World!')
span.finish()
})
res.end()
})
server.listen(8000)
Before contributing to this open source project, read our CONTRIBUTING.md.
Since this project supports multiple Node versions, using a version manager such as nvm is recommended.
To get started once you have a Node version installed, run:
$ npm install
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
To run the unit tests, use:
$ npm test
To run the unit tests continuously in watch mode while developing, use:
$ npm run tdd
We use ESLint to make sure that new code is conform to our coding standards.
To run the linter, use:
$ npm run lint
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 build-node-4
$ circleci build --job build-node-6
$ circleci build --job build-node-8
$ circleci build --job build-node-latest
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:
$ npm run bench
FAQs
Datadog APM tracing client for JavaScript
The npm package dd-trace receives a total of 2,701,885 weekly downloads. As such, dd-trace popularity was classified as popular.
We found that dd-trace demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.