Stop 19 · Monitoring & LoggingTopics · 7/9

Sentry for Error Tracking

Part of the Backend Developer Roadmap

In short

Most users never report bugs, they just leave. Sentry catches unhandled errors in production with the stack trace, request and release, and tells you before the reviews do.

A service that captures unhandled exceptions in production, with full stack traces and request context, so you find out about bugs from monitoring instead of user complaints.

The purple blob rushes with a small extinguisher towards a smoking pan as a ceiling alarm rings.

Think of it like this

A smoke alarm in every room

You don't wait to smell smoke from the bedroom. The kitchen alarm rings the moment the pan burns, and you know exactly which room. Sentry is a smoke alarm in your code: it rings on the first error and points to the exact line.

Watch it happen

From crash to alert

User
API
Sentry
You

POST /checkout

1/6A user checks out. Your code reads cart.items on a cart that's undefined.

The big ideas

What you need to know

Grouped issues

A thousand copies of one bug become one issue with a count, so you're not buried in duplicates.

Source maps

Upload source maps so stack traces point at your TypeScript lines, not compiled JavaScript.

Releases

Tag events with a release like the git SHA, and you'll see which deploy introduced a bug.

Scrub personal data

Control what gets sent. Strip passwords, tokens and card data before events leave your server.

See it in code

Walk through the code

ts
1// instrument.ts (import it first, before express)2import * as Sentry from "@sentry/node";3Sentry.init({4  dsn: process.env.SENTRY_DSN,5  environment: process.env.APP_ENV,6  release: process.env.GIT_SHA,7  tracesSampleRate: 0.1,8});9 10// server.ts11import "./instrument";12import * as Sentry from "@sentry/node";13import express from "express";14const app = express();15// ...your routes...16Sentry.setupExpressErrorHandler(app); // after all routes

1/4Connect to your Sentry project and tag every event with the environment and release.

If your app runs as native ES modules, load the file with node --import ./dist/instrument.js instead, so it runs before everything else.

Save yourself the pain

Common mistakes

Oops

Catching every error and only console.logging it.

Do this instead

Then Sentry never sees it. Re-throw, or call Sentry.captureException(err) for handled errors you still care about.

Oops

Sending performance traces for 100 percent of requests on a busy API.

Do this instead

Cost and overhead climb fast. Keep tracesSampleRate small; errors are captured regardless.

Your mission

Catch your first bug

~25 min

Quick check

Why set Sentry's release to the git commit SHA?

Go deeper

  1. 1Integrate Sentry into a Node.js project and trigger a test error.
  2. 2Add custom context (user ID, request data) to captured errors.
  3. 3Set up alerts so a spike in errors notifies you quickly.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge