Express error tracking
Express error tracking in one line
Add one error handler after your routes and every server error in your Express app is reported with the route, the request and the trace — while your own error handlers keep working.
Set up
npm install @errorlenshq/nodeimport * as ErrorLens from "@errorlenshq/node";
ErrorLens.init({ dsn: process.env.ERRORLENS_DSN, tracesSampleRate: 0.2 });
import express from "express";
const app = express();
app.get("/orders/:id", getOrder);
// after all routes, before your own error handlers
ErrorLens.setupExpressErrorHandler(app);
app.listen(3000);What you get
- Only server errors are reported — a 404 or validation error passed to
next(err)with a 4xx status is skipped - Transactions named after the full route, including routers:
GET /api/orders/:id - Request method, URL, headers and query string; cookies and bodies only with
sendDefaultPii - Each request isolated:
ErrorLens.setUser()in one request never shows up on another
Fastify, Koa and Hapi
ErrorLens.setupFastifyErrorHandler(fastify);
ErrorLens.setupKoaErrorHandler(app);
await ErrorLens.setupHapiErrorHandler(server);Frequently asked questions
Do I still need my own error middleware?
Keep it. The ErrorLens handler reports the error and passes it on with next(err), so your handler still decides the response.
Express 4 or 5?
Both are supported.
Keep reading
Node.js error tracking with per-request context
Track Node.js errors, unhandled rejections and slow requests with per-request context and distributed tracing. Zero-dependency SDK, ESM and CommonJS.
Open-source APM that links slow requests to their errors and logs
Open-source application performance monitoring: p50/p95 latency, throughput, failure rate and distributed traces linked to errors and logs. Self-host free.
An open-source backend for your OpenTelemetry traces and logs
An open-source OpenTelemetry backend: send traces and logs over OTLP/HTTP and get trace waterfalls, latency percentiles, log search and alerts. Self-host free.
Uptime monitoring next to the errors that explain the outage
Check your websites and APIs every 30 seconds to every hour and get alerted when they go down or come back. Open-source uptime monitoring, self-hostable.
Start tracking errors in minutes
Free hosted plan with 5,000 errors a month, or self-host with no limits. No credit card.