Exceptions
Errors your app runs into, with stack traces and your source lines, grouped into issues and linked to the request they happened in.
PeekInside records the errors your app runs into, next to the requests. Each exception has its stack trace (with the source lines of your own code), its cause chain, the request it happened in and details of the process. Exceptions with the same type and the same top frames of your code are grouped into one issue, so a fix that moves a line doesn't split it.
What is recorded automatically#
| Where | Recorded | Handled? |
|---|---|---|
| Express 4 and 5 | Errors thrown by handlers, passed to next(err), or (Express 5) rejected by async handlers |
Yes when an error middleware (err, req, res, next) receives it; no when it reaches Express's default handler, which answers 500 |
| Koa | Errors thrown by middleware and routes | Yes when your own error-handling middleware answers it (registered before PeekInside, or reporting it with ctx.app.emit('error', err, ctx)); no when Koa's default handler answers 500 |
| Fastify | Errors from route handlers and hooks (onError) |
Yes when the app set its own error handler with setErrorHandler() |
| NestJS | Errors from controllers, guards, pipes, interceptors and middleware, on Express or Fastify | Yes when one of your exception filters catches it, unless the filter hands it on with super.catch(); no when Nest's own filter answers 500 |
| Hono | Errors thrown by handlers and middleware | Yes when your app.onError() handler (or a sub-app's) answers it, unless it throws it on; no when Hono's own handler answers 500 |
| Crashes | Uncaught exceptions and unhandled promise rejections | No |
Errors with a 4xx status, such as createError(404), Koa's ctx.throw(400), Nest's NotFoundException or Hono's HTTPException(401), are how apps answer bad requests, so they aren't recorded automatically. Nothing about how your app answers changes: same status codes, same bodies, same logging.
Crashes#
An uncaught exception or unhandled rejection still crashes your app exactly as before, with the same output and exit code: PeekInside only watches (with Node's uncaughtExceptionMonitor) and never handles them. It doesn't add an unhandledRejection listener either, since that alone would stop Node from crashing; when your app adds its own, PeekInside records the rejections your app now survives.
A crashing process can't wait for the next batch, so the crash, and the request it happened in, are saved before the process exits. With the local dashboard they are written to ~/.peekinside/spool, which the dashboard picks up within a second, or when it next starts. With PeekInside Cloud they are encrypted and sent right away (the process waits up to 3 seconds); if PeekInside Cloud can't be reached, the encrypted batch is saved and sent when the app starts again.
Reporting errors yourself#
try {
await chargeCard(order);
} catch (error) {
PeekInside.report(error, { tags: { provider: 'stripe' }, extra: { orderId: order.id } });
return res.status(502).json({ error: 'payment_failed' });
}
peekInside.report(error, options) records any error (or thrown value) and returns its id, or null when nothing was recorded. PeekInside.report() does the same with the instance that tracks the current request (or the most recently created one). Options:
| Option | Default | Description |
|---|---|---|
request |
the current request | The request the error relates to |
tags |
{} |
Up to 32 short labels, such as { provider: 'stripe' } |
extra |
none | Any JSON-safe data; past 16 KB only a preview is kept |
handled |
true |
Whether your app handled the error |
user |
the request's user | Who it happened to (see Users) |
Linked to requests#
During a request, PeekInside knows which request your code runs for, through timers, promises and callbacks (with AsyncLocalStorage). Every exception carries the id of its request and a snapshot of it (method, URL, headers, query, the first 8 KB of the body), and every request lists the exceptions that happened while it was handled. Exceptions thrown outside requests (at startup, in background jobs) are recorded without one.
Users#
Tell PeekInside who each request is for, and every request and exception carries the user:
app.use((req, res, next) => {
if (req.user) PeekInside.setUser({ id: req.user.id, email: req.user.email, name: req.user.name, phone: req.user.phone });
next();
});
The Exceptions page then counts the users each issue affects, and the filter user:ada (by id, email, name or phone number) shows one customer's issues; user: works on the Requests page too. From any request or exception, Their requests and Their errors list everything that user ran into, which is what a support ticket needs.
setUser() accepts { id, email, name, phone } (also _id, username, and phoneNumber, phone_number or mobile for the phone, as many user objects have them) or just an id, and returns false outside a request. Give at least one; the rest are optional. A phone number is kept as your app writes it (up to 32 characters), and user:98765 finds it by its digits. Other fields are ignored. With PeekInside Cloud, the user is encrypted with the request: we can't read it.
Source maps#
TypeScript and bundled apps run compiled code, so their stack traces point at lines of dist/*.js. PeekInside maps those frames back to the files you edit, with the source maps your build writes: it reads a map named by the file's sourceMappingURL comment (a .map file or an inline one), or a .js.map file next to it (webpack's hidden-source-map). Stack traces, source lines and grouping then use your .ts files, so a rebuild that moves compiled lines doesn't split an issue. Mapped frames are tagged mapped, with the compiled location they ran at.
Turn source maps on in your build, and deploy the .map files with the code:
| Build tool | Setting |
|---|---|
| tsc | "sourceMap": true (or "inlineSourceMap": true) in tsconfig.json |
| esbuild, tsup | sourcemap: true |
| webpack | devtool: 'source-map' (or 'hidden-source-map') |
| Vite (SSR), Rollup | build.sourcemap: true / output.sourcemap: true |
Maps that carry their sources (sourcesContent, the default of most tools) show your source lines even when the .ts files aren't deployed. Only maps of your own compiled files are read (inside the project folder, outside node_modules), up to 16 MB each, once per file. Apps run with --enable-source-maps, tsx or ts-node already have mapped stack traces; PeekInside leaves them as they are. Turn mapping off with sourceMaps: false.
Releases#
Every request and exception is tagged with the deploy it came from, so the Exceptions page can tell you which deploy broke something: issues show the release they first happened in, a New in a1b2c3d tag marks issues the latest deploy introduced, and the release filter narrows the list to one deploy. On the Requests page, release:a1b2c3d does the same.
PeekInside finds the release by itself, in this order:
- the
releaseoption, orPEEKINSIDE_RELEASE; - the commit your host deployed: Vercel, Netlify, Render, Railway, Heroku, Cloudflare Pages, Google Cloud Run, Fly.io, and CI variables such as
GITHUB_SHA; - the commit checked out in the project folder (read from
.git, without running git).
A release is a label of up to 64 characters (letters, digits and . _ : @ / + -), such as v2.4.0 or a commit hash; commits are shown by their first seven characters. Releases are stored readable, like the environment name, so they can be filtered.
Alerts#
With PeekInside Cloud, an error PeekInside hasn't seen before in a project's environment alerts the members who read exceptions: in the app on every plan, and with Pro and up by email and in the organization's Slack channel (connected under Settings → Slack with an incoming webhook). Each member chooses how new errors reach them in their notification settings.
- Errors from
developmentandtestenvironments never alert. - At most five new errors a project are alerted on in an hour; the rest wait on the Exceptions page.
- An error that hasn't happened for six months counts as new when it comes back.
- Alerts say where and when, and link to the error. They never say what it was: the error itself is encrypted on your server.
PeekInside tells a new error from a known one by its fingerprint, which the SDK sends next to the sealed exception (SDK 1.2.5 and later).
Source context and privacy#
For the top five frames of your own code (files in your project folder, outside node_modules), the line and the five lines on each side are read from disk and included. Turn this off with sourceContext: false; turn automatic recording off with captureExceptions: false (report() keeps working).
With PeekInside Cloud, exceptions are encrypted like requests: messages, stack traces, source lines, request snapshots, tags and extra are sealed with your project's public key, and PeekInside Cloud only sees when an exception happened, its environment and release, whether it was handled or fatal, the id of its request, and its fingerprint: a hash of the error's name and where in your code it was thrown. Cloud stores the fingerprint only keyed with a secret of its own, so a copy of the database can't be matched against guessed errors. Crashes saved to disk while PeekInside Cloud is unreachable are saved encrypted.
At most 50 exceptions a second are recorded (bursts of 100), so an app in trouble can't fill its memory with them; crashes are always recorded.