SDK Reference
HTTP Middleware
Auto-trace every request in Hono and Express with one line.
The @deeptracer/node package includes middleware for Hono and Express that automatically creates a span for every incoming HTTP request.
Hono
import { Hono } from "hono"
import { createLogger, honoMiddleware } from "@deeptracer/node"
const logger = createLogger({
apiKey: process.env.DEEPTRACER_KEY,
endpoint: process.env.DEEPTRACER_ENDPOINT,
service: "api",
})
const app = new Hono()
app.use(honoMiddleware(logger))
app.get("/users", (c) => {
return c.json({ users: [] })
})
// → creates a span: "GET /users"Express
import express from "express"
import { createLogger, expressMiddleware } from "@deeptracer/node"
const logger = createLogger({
apiKey: process.env.DEEPTRACER_KEY,
endpoint: process.env.DEEPTRACER_ENDPOINT,
service: "api",
})
const app = express()
app.use(expressMiddleware(logger))
app.get("/users", (req, res) => {
res.json({ users: [] })
})
// → creates a span: "GET /users"What the middleware does
For each incoming request, the middleware:
- Creates a request-scoped logger with
forRequest(request)to extract incoming trace context from headers - Starts a span named
"{METHOD} {path}"(e.g.,"GET /users") - Sets
x-trace-idandx-span-idresponse headers so the caller can correlate - Ends the span when the response finishes, marking it
"ok"or"error"based on status code
Options
Both honoMiddleware() and expressMiddleware() accept an optional second argument:
app.use(honoMiddleware(logger, {
operationName: (method, path) => `${method} ${path}`,
ignorePaths: ["/health", "/ready", "/.well-known"],
}))| Option | Type | Default | Description |
|---|---|---|---|
operationName | (method, path) => string | "{METHOD} {path}" | Custom span name for each request. |
ignorePaths | string[] | [] | Paths to skip tracing entirely. Matched with startsWith. |
Ignoring health checks
Health check endpoints can generate a lot of noise. Exclude them:
app.use(expressMiddleware(logger, {
ignorePaths: ["/health", "/ready", "/ping"],
}))Custom operation names
Group dynamic routes into a single operation:
app.use(honoMiddleware(logger, {
operationName: (method, path) => {
// /users/123 → "GET /users/:id"
const normalized = path.replace(/\/[a-f0-9-]{20,}/g, "/:id")
return `${method} ${normalized}`
},
}))Next.js
You don't need middleware for Next.js. The @deeptracer/nextjs package handles request tracing automatically via its OpenTelemetry integration. See Distributed Tracing for details.