npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lokalise/datadog-fastify-bootstrap

v1.0.0

Published

This package provides a pre-configured Datadog APM setup for Fastify applications using the native `dd-trace` library, with support for auto-instrumentation, runtime metrics, profiling, and log injection.

Readme

Datadog Fastify Bootstrap

This package provides a pre-configured Datadog APM setup for Fastify applications using the native dd-trace library, with support for auto-instrumentation, runtime metrics, profiling, and log injection.

Installation

npm install @lokalise/datadog-fastify-bootstrap dd-trace

ESM Loader Requirement

The dd-trace ESM loader hook must be registered at process start via the --import flag:

node --import dd-trace/initialize.mjs app.js

This flag registers the ESM loader hook and creates the tracer singleton before any application code runs. Without it, dd-trace cannot hook into ESM module loading and auto-instrumentation will not work.

Usage

Since --import dd-trace/initialize.mjs handles early initialization, you can use regular static imports — no dynamic await import() needed:

// index.ts (entry point)
import { initDatadog } from '@lokalise/datadog-fastify-bootstrap'

initDatadog({
  service: 'my-api',
  env: 'production',
  skippedPaths: ['/health', '/ready', '/live', '/metrics', '/'],
})

Using defaults

If you don't need custom configuration:

import { initDatadog } from '@lokalise/datadog-fastify-bootstrap'

initDatadog()

Configuration

Environment Variables

| Variable | Description | Default | |----------|-------------|---------| | NODE_ENV | When set to test, tracing is disabled | - | | DD_TRACE_ENABLED | Set to true to enable Datadog tracing | false | | OTEL_ENABLED | Fallback for DD_TRACE_ENABLED (for migration from OTEL package) | false | | DD_TRACE_AGENT_URL | Full URL of the Datadog Agent (e.g. http://dd-agent:8126) | - | | OTEL_EXPORTER_URL | Fallback for DD_TRACE_AGENT_URL (for migration from OTEL package) | - | | DD_TRACE_DEBUG | Enable verbose dd-trace internal logging (see Debugging in Docker) | false | | DD_SERVICE | Service name (can also be set via options) | inferred from package.json | | DD_ENV | Environment name (can also be set via options) | - | | DD_VERSION | Application version (can also be set via options) | inferred from package.json |

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | service | string | - | Service name reported to Datadog | | env | string | - | Environment name (e.g. prod, staging) | | version | string | - | Application version | | url | string | - | Full URL of the DD Agent. Takes priority over agentHost/agentPort | | agentHost | string | '127.0.0.1' | Datadog Agent hostname. Ignored when url is set | | agentPort | number | 8126 | Datadog Agent trace port. Ignored when url is set | | skippedPaths | string[] | ['/health', '/metrics', '/'] | Paths to exclude from tracing | | runtimeMetrics | boolean | false | Enable runtime metrics collection | | profiling | boolean | false | Enable continuous profiling | | logInjection | boolean | false | Inject trace IDs into log records | | sampleRate | number | - | Global trace sample rate (0 to 1) | | debug | boolean | false | Enable dd-trace debug logging | | startupLogs | boolean | true | Enable dd-trace startup logs | | tags | Record<string, string> | - | Additional tags for every span and metric |

Features

  • Automatic instrumentation for Node.js applications via dd-trace
  • Runtime metrics collection (event loop, GC, heap)
  • Continuous profiling (CPU and heap)
  • Trace ID injection into application logs
  • Configurable path filtering
  • Custom tags for spans and metrics
  • Graceful shutdown with trace flushing

Custom Spans

Use getTracer() to access the tracer instance for creating custom spans:

import { getTracer } from '@lokalise/datadog-fastify-bootstrap'

const tracer = getTracer()
const span = tracer?.startSpan('my.custom.operation')
try {
  // ... do work ...
} finally {
  span?.finish()
}

Graceful Shutdown

To properly flush pending traces when your application exits:

import { gracefulDatadogShutdown } from '@lokalise/datadog-fastify-bootstrap'

process.on('SIGTERM', async () => {
  await gracefulDatadogShutdown()
  process.exit(0)
})

Debugging in Docker

To troubleshoot tracing issues in a Docker environment, enable debug logging via the debug option or the DD_TRACE_DEBUG environment variable. This makes dd-trace emit verbose internal logs showing agent connectivity, span submission, and instrumentation status.

docker-compose example

services:
  app:
    build: .
    environment:
      DD_TRACE_ENABLED: 'true'
      DD_TRACE_AGENT_URL: 'http://datadog-agent:8126'
      DD_TRACE_DEBUG: 'true'   # verbose dd-trace logs
    command: ['node', '--import', 'dd-trace/initialize.mjs', 'dist/index.js']

  datadog-agent:
    image: datadog/agent:latest
    environment:
      DD_API_KEY: ${DD_API_KEY}
      DD_APM_ENABLED: 'true'

What to look for

  • Agent not reachable — the app cannot connect to the DD Agent. Verify DD_TRACE_AGENT_URL points to the correct host/port and that the agent container is running.
  • Encoding traces / Flushing traces — traces are being sent successfully.
  • Instrumentation applied — modules (http, fastify, etc.) were patched correctly.
  • No dd-trace logs at all — the --import dd-trace/initialize.mjs flag is missing from the node command.