Prompt
How do I set up crash reporting for a web app?
Latest observation
To set up crash reporting for a web app, you typically want to capture:
- JavaScript errors
- Unhandled promise rejections
- Network/API failures
- Performance/context data so you can reproduce issues
- Source maps for readable stack traces in production
1) Pick a crash/error reporting tool
Common options:
- Sentry — very popular, easy setup, strong JS support
- Datadog RUM
- Bugsnag
- Rollbar
- Firebase Crashlytics is more mobile-focused, not ideal for web
If you want the simplest path, Sentry is a good default.
2) Install the SDK
Example with Sentry:
npm install @sentry/browser
3) Initialize it early in your app
Put this near the top of your app startup code:
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
environment: process.env.NODE_ENV,
release: "my-app@1.0.0",
});
4) Capture errors automatically
Most SDKs will automatically capture:
- uncaught exceptions
- unhandled promise rejections
- some framework errors
You can also manually report errors:
try {
doSomething();
} catch (err) {
Sentry.captureException(err);
}
5) Add request/API error tracking
If your app uses fetch, you can wrap requests and report failed ones:
async function apiFetch(url, options) {
const res = await fetch(url, options);
if (!res.ok) {
Sentry.captureMessage(`API error: ${res.status} ${url}`, "error");
}
return res;
}
For better observability, include:
- URL
- status code
- request ID
- user/session context
6) Attach useful context
When a crash happens, you want to know who/what/where:
Sentry.setUser({ id: "123", email: "user@example.com" });
Sentry.setTag("feature", "checkout");
Sentry.setContext("cart", { items: 3, total: 49.99 });
7) Upload source maps
If you use a bundler like Vite, Webpack, or Next.js, enable source maps for production builds and upload them to your error tool. This converts minified stack traces into readable code locations.
Examples:
- Vite:
build.sourcemap = true - Webpack:
devtool: "source-map"
Then configure your error service to ingest those source maps during CI/CD.
8) Protect privacy
Be careful not to send:
- passwords
- tokens
- credit card data
- personal info in request payloads
Most tools let you scrub or filter sensitive fields before sending events.
9) Test it
Deliberately trigger a test error:
throw new Error("Test crash reporting");
Then confirm it appears in your dashboard with a readable stack trace.
10) Optional: add session replay and breadcrumbs
Helpful features:
- breadcrumbs: recent user actions before the crash
- session replay: video-like playback of what happened
- logs: correlate frontend errors with backend logs
If you want, I can give you a setup example for a specific framework like React, Next.js, Vue, or plain JavaScript.