Sentry Breadcrumbs: The Trail Before an Error
Breadcrumbs in Sentry are small records of what happened just before an error: clicks, network requests, console messages and page changes. The SDK collects many of them automatically, you add your own with Sentry.addBreadcrumb(), and they are attached to the next error event. By default the JavaScript SDK keeps the latest 100.
| Setting or call | What it does | Default |
|---|---|---|
| maxBreadcrumbs | How many breadcrumbs are kept | 100 |
| beforeBreadcrumb | Edit or drop each breadcrumb before it is stored | Not set |
| Sentry.addBreadcrumb() | Record your own breadcrumb | Not applicable |
| level | fatal, error, warning, log, info or debug | Not set |
Updated
When a customer hits an error on your site, the stack trace says where the code broke but not what they did first. Breadcrumbs fill that gap. This guide covers the browser JavaScript SDK; other Sentry SDKs follow the same idea with their own defaults.
Breadcrumb trail simulator
Record a few events, set the options, then trigger an error to see which breadcrumbs would travel with it. This is a simulation in your browser; nothing is sent to Sentry.
Record an event: Click Add to cart, Cart request finished, console.log call, Go to checkout, Customer signed in
maxBreadcrumbs
Drop console breadcrumbs in beforeBreadcrumb
Replace email addresses in messages
Throw an error
No breadcrumbs yet. Record an event above.
Clear trail
Sentry.init options for these settings
Code examples
Add a manual breadcrumb
Record a business step with a category, a short message, a level and extra fields under data.
import * as Sentry from "@sentry/browser";
function applyCoupon(code, cartTotal) {
Sentry.addBreadcrumb({
category: "cart",
message: "Coupon applied",
level: "info",
data: { code, cartTotal },
});
// ...apply the discount
}Filter and clean breadcrumbs
Drop console noise, mask email addresses, and keep the default limit written out so it is easy to change.
Sentry.init({
dsn: "https://[email protected]/0",
maxBreadcrumbs: 100,
beforeBreadcrumb(breadcrumb, hint) {
if (breadcrumb.category === "console") return null;
if (breadcrumb.message) {
breadcrumb.message = breadcrumb.message.replace(
/[\w.+-]+@[\w-]+\.[\w.-]+/g,
"[email]"
);
}
return breadcrumb;
},
});
Manual breadcrumbs worth adding
Automatic breadcrumbs tell you what the browser did. Manual ones tell you what the business flow did: a customer chose express shipping, a discount code was applied, a booking date was picked.
These are the moments a support person asks about first, so recording them saves a round of questions.
Keeping personal data out
Breadcrumbs often pick up text you did not mean to keep: an email in a console line, a search query in a URL. Clean them in beforeBreadcrumb before they are stored, and use beforeSend for the rest of the event.
Sentry also offers server-side data scrubbing configured in its UI, which acts as a second net.
How it works
- The SDK listens for clicks and key presses, fetch and XHR requests, console calls and location changes, and turns each into a breadcrumb.
- Your own code can add more with Sentry.addBreadcrumb(), for example after a sign-in or a coupon is applied.
- Each new breadcrumb first passes through beforeBreadcrumb if you set it. Returning null drops it.
- The kept trail is capped at maxBreadcrumbs; the SDK slices off the oldest ones when the list grows past the cap.
- When an error is captured, the current trail is attached to that event and shown on the issue page.
Tips
- Use a short, stable category such as auth, cart or payment so you can filter the trail on the issue page.
- Put details in data, not in the message, so they show as fields.
- Never put passwords, card numbers or full addresses in a breadcrumb. Sentry's own guidance says do not log PII when console logs become breadcrumbs.
- If the console is noisy, drop console breadcrumbs in beforeBreadcrumb rather than lowering maxBreadcrumbs for everything.
- Setting maxBreadcrumbs to 0 turns breadcrumbs off; the SDK returns early for values of 0 or less.
Frequently asked questions
What is the default maxBreadcrumbs?
100. The Sentry docs list a default of 100 for the JavaScript SDK, and the SDK source uses the same number when the option is not set.
Which breadcrumbs are recorded automatically?
In the browser SDK: clicks and key presses on DOM elements, XHR and fetch requests, console API calls and all location changes.
What keys can a breadcrumb have?
type, category, message, level, timestamp and data. The docs say other keys are dropped during processing.
How do I stop a breadcrumb from being recorded?
Set beforeBreadcrumb in Sentry.init. It receives each breadcrumb and an optional hint, and can return a changed breadcrumb or null to discard it.
Are breadcrumbs sent on their own?
No. They are kept in memory and attached to the next event the SDK sends, such as an error.
Related: Breadcrumb navigation on websites, Next.js environment variables, Web push notifications, What is an API key.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- SEO for Contractors: A Local SEO Checklist for Builders and Remodelers | How-to Guide
- SEO for Dentists: A Practical Local SEO Checklist (2026) | How-to Guide
- SEO for Lawyers: Local SEO Checklist for Law Firms
- SEO for Restaurants: A Practical Local SEO Checklist (2026) | How-to Guide
- SEO for Service-Area Businesses | How-to Guide
- SEO-Friendly Website Design: A Practical Small-Business Guide | How-to Guide
- Website Design for Services: Annotated Service Business Examples | How-to Guide
- shadcn Form and Data Table, Wired Together
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App