Skip to main content
dd-trace automatically instruments HTTP server frameworks. Each incoming request produces a root span with HTTP method, URL, status code, and route information. Middleware functions each receive their own child span when middleware instrumentation is enabled.

Supported frameworks

Express

express

Fastify

fastify

Koa

koa

Hapi

@hapi/hapi

Next.js

next

Hono

hono

Restify

restify

Connect

connect

Moleculer

moleculer

Configuration

All web framework plugins extend the HttpServer interface and share these configuration options:
OptionTypeDefaultDescription
enabledbooleantrueEnable the plugin.
servicestringOverride the service name.
blockliststring | RegExp | Function | Array[]Paths that should not be instrumented.
allowliststring | RegExp | Function | Array/.*/Paths that should be instrumented.
headersstring[][]Request/response headers to capture as span tags.
validateStatus(code: number) => booleancode => code < 500Determines if a status code should be treated as an error.
middlewarebooleantrueCreate spans for individual middleware functions.
hooks.request(span, req, res) => voidHook called just before the request span finishes.
queryStringObfuscationboolean | string | RegExpObfuscate query string values in http.url.

Per-framework examples

const tracer = require('dd-trace').init()

tracer.use('express', {
  // Only instrument /api/* paths
  allowlist: /^\/api/,
  // Capture Authorization header
  headers: ['authorization'],
  hooks: {
    request: (span, req, res) => {
      span.setTag('customer.id', req.query.customerId)
    }
  }
})

const express = require('express')
const app = express()
app.get('/api/users', (req, res) => res.json([]))
app.listen(3000)

Span hooks

Span hooks let you add custom tags to spans created by the framework plugin without writing middleware. The hook runs just before the request span finishes, so all request and response information is available.
const tracer = require('dd-trace').init()

tracer.use('express', {
  hooks: {
    request: (span, req, res) => {
      span.setTag('customer.id', req.query.id)
      span.setTag('user.role', req.user?.role)
    }
  }
})

Blocking paths (AppSec)

Use blocklist to prevent instrumentation of health check or metrics endpoints. This reduces noise in your traces:
tracer.use('express', {
  blocklist: [
    '/healthcheck',
    '/readyz',
    /^\/metrics/
  ]
})
Note that blocklist and allowlist affect tracing only, not AppSec protection.

Moleculer

The moleculer plugin instruments both the Moleculer service bus client and server. Configure each side independently:
tracer.use('moleculer', {
  // Include context meta as tags on all spans
  meta: true,
  client: {
    service: 'moleculer-client'
  },
  server: {
    service: 'moleculer-server'
  }
})

Build docs developers (and LLMs) love