Node.js
Capture exceptions from Node servers with @sentry/node pointed at Epure.
Use official @sentry/node 7.120.0 (fixture-proven parse + captured envelope). Point dsn at your Epure host. No @epure/* package.
Use this guide when the code runs in a Node process: Express, Fastify, NestJS, Koa, Hono, workers, CLIs. Do not use this for browser SPAs (→ Browser) or Next.js (→ Next.js). Full map: Pick your SDK.
Capture exceptions in Node.js
Load @sentry/node 7.120.0 before the rest of the app, set dsn, and flush with Sentry.close before exit.
Shared DSN, environment, and release options: JavaScript / TypeScript.
How do I install @sentry/node?
npm install @sentry/node@7.120.0Pin 7.120.0 for the documented line. Newer majors may work; confirm an exception appears in Issues.
Init the Node SDK
Load instrumentation before the rest of the app, or at the top of the entry file.
import * as Sentry from "@sentry/node";
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: "production",
release: "my-api@1.0.0",
tracesSampleRate: 0,
profilesSampleRate: 0,
});| Option | Value |
|---|---|
dsn | Required: public key + Epure host + project UUID |
environment | Tag for the dashboard filter strip |
release | Same string as sourcemap uploads (if you demangle Node bundles) |
tracesSampleRate | 0; transactions discarded |
profilesSampleRate | 0; profiles discarded |
Replay sample rates do not apply on Node. No session replay product.
For Sentry JS v8+, also set enableTracing: false when the option exists.
How do uncaught handlers work?
After init, @sentry/node registers process-level handlers for uncaught exceptions and unhandled rejections (SDK defaults). Prefer catching at the framework boundary and calling captureException when you still want the event.
process.on("unhandledRejection", (reason) => {
Sentry.captureException(reason);
});How do I wire Express?
Request context first, then your routes, then the error handler after them.
import * as Sentry from "@sentry/node";
import express from "express";
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: "production",
release: "my-api@1.0.0",
tracesSampleRate: 0,
profilesSampleRate: 0,
});
const app = express();
app.use(Sentry.Handlers.requestHandler());
app.get("/debug-sentry", (_req, _res, next) => {
next(new Error("Epure node test"));
});
// … routes …
app.use(Sentry.Handlers.errorHandler());
app.listen(3000);Handlers.requestHandler attaches request data used as breadcrumbs/context. Handlers.errorHandler captures errors passed to Express next(err).
Manual capture inside a route:
app.post("/checkout", async (req, res) => {
try {
await charge(req.body);
res.sendStatus(204);
} catch (error) {
Sentry.captureException(error);
res.status(500).json({ error: "checkout_failed" });
}
});Generic HTTP and workers
No framework middleware required. Capture where you handle failures.
import http from "node:http";
import * as Sentry from "@sentry/node";
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0,
profilesSampleRate: 0,
});
const server = http.createServer(async (req, res) => {
try {
// …
res.writeHead(200);
res.end("ok");
} catch (error) {
Sentry.captureException(error);
res.writeHead(500);
res.end("error");
}
});
server.listen(3000);CLIs and queue workers: captureException in the catch path; call Sentry.close before exit (below).
How do I flush on shutdown?
Buffered events can be lost if the process exits immediately. Flush before exit.
async function shutdown(signal: string) {
console.log(signal);
await Sentry.close(2000);
process.exit(0);
}
process.on("SIGTERM", () => void shutdown("SIGTERM"));
process.on("SIGINT", () => void shutdown("SIGINT"));Sentry.close(timeoutMs) drains the transport (or times out). Use it in workers after the last job and in short-lived scripts after the final captureException.
How do Node source maps work?
If you ship minified Node bundles, upload maps with the same release string: Source maps.
Why does Node never send?
| What you see | What to do |
|---|---|
| Process exits with no issue | await Sentry.close(2000) before exit |
| 401 / 403 | Server DSN must include the secret if you used the full URL |
Handled catch with no event | Call captureException; Express errorHandler only sees next(err) |
Next
Are traces stored from Node?
No. Set tracesSampleRate and profilesSampleRate to 0, since transaction and profile items are discarded on ingest. Replay sample rates do not apply on Node. Exception events plus breadcrumbs stay: JavaScript overview.
Why did a short-lived process send nothing?
Buffered events can be lost if the process exits immediately, so call await Sentry.close(2000) before exit. Express errorHandler only sees next(err); a handled catch needs captureException. Confirm ingest 202, then Verify.