Node.js
For a long-running Node server — Express, Fastify, NestJS, or plain Node — use the @heystack/otel/node entry. initHeystack bundles auto-instrumentations (HTTP and common libraries) and registers a graceful-shutdown flush.
Install
npm install "@heystack/otel@>=0.19.1"
Initialize as the very first import
initHeystack must run before your framework loads, so auto-instrumentation can patch modules. Make it the first import in your entry file:
import { initHeystack } from "@heystack/otel/node";
initHeystack({ apiKey: process.env.HEYSTACK_API_KEY, service: "my-app" });
// ...then the rest of your imports / app...
This enables auto-instrumentations so you get spans without manual wiring.
Entry-ordering tip: if your build can't guarantee this runs first, use
node --importwith a smallheystack.mjsthat callsinitHeystack, or your framework's instrumentation hook.
Set the key
# .env (loaded before initHeystack runs, and gitignored)
HEYSTACK_API_KEY=sk_live_…
Graceful shutdown
initHeystack registers SIGTERM/SIGINT handlers automatically, so the SDK flushes and shuts down before exit — you won't lose the last batch on short-lived processes.
Privacy
Recorded URLs have secrets removed (?token=, ?code=, ?apikey=, userinfo, …) and the end user's IP address is not recorded unless you pass captureClientIp: true. Add your own parameter names with redactQueryParams: ["invite"]. See Privacy.
Verify
Pass debug: true to print OTel export logs while you're checking the wiring:
initHeystack({ apiKey: process.env.HEYSTACK_API_KEY, service: "my-app", debug: true });
Then run your app and make a request — traces appear in the console, usually within a minute.