NodeJS Fastify
Prerequisites
Node.js >=18
Installation
-
Install dependencies:
npm install dd-trace -
Initializes the Datadog tracer when your application starts:
- Code
- Environment Variables
- Startup Command
Add the following line at the top of your project's main file.
const tracer = require('dd-trace').init();NODE_OPTIONS=--require dd-trace/initAdd
--require dd-trace/initto your application run command, e.g.,node --require dd-trace/init app.js -
Configure the tracer.
- Code
- Environment Variables
const tracer = require('dd-trace').init({
service: "<app_name>",
// send traces to CubeAPM
url: "http://<ip_address_of_cubeapm_server>:3130",
// optional settings
env: "myenv",
version: "1.2.3",
tags: {
mykey1: "myvalue1",
mykey2: "myvalue2"
},
});DD_SERVICE=<app_name>
# send traces to CubeAPM
DD_TRACE_AGENT_URL=http://<ip_address_of_cubeapm_server>:3130
# optional settings
DD_ENV=myenv
DD_VERSION=1.2.3
DD_TAGS=mykey1:myvalue1,mykey2:myvalue2
Sample Application
A working example is available at https://github.com/cubeapm/sample_app_nodejs_fastify/tree/datadog.
Troubleshooting
The following can be used for debugging:
- Code
- Environment Variables
const tracer = require('dd-trace').init({
startupLogs: true
debug: true,
});
# Print Datadog tracer startup logs on screen
DD_TRACE_STARTUP_LOGS=true
# Enable Datadog tracer debug logging if needed to see detailed logs
DD_TRACE_DEBUG=true