Skip to main content

NodeJS Fastify

Prerequisites

Node.js >=18

Installation

  1. Install dependencies:

    npm install dd-trace
  2. Initializes the Datadog tracer when your application starts:

    Add the following line at the top of your project's main file.

    const tracer = require('dd-trace').init();
  3. Configure the tracer.

     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"
    },
    });

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:

 const tracer = require('dd-trace').init({
startupLogs: true
debug: true,
});