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.

Breadcrumb settings at a glance
Setting or callWhat it doesDefault
maxBreadcrumbsHow many breadcrumbs are kept100
beforeBreadcrumbEdit or drop each breadcrumb before it is storedNot set
Sentry.addBreadcrumb()Record your own breadcrumbNot applicable
levelfatal, error, warning, log, info or debugNot 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

  1. The SDK listens for clicks and key presses, fetch and XHR requests, console calls and location changes, and turns each into a breadcrumb.
  2. Your own code can add more with Sentry.addBreadcrumb(), for example after a sign-in or a coupon is applied.
  3. Each new breadcrumb first passes through beforeBreadcrumb if you set it. Returning null drops it.
  4. The kept trail is capped at maxBreadcrumbs; the SDK slices off the oldest ones when the list grows past the cap.
  5. When an error is captured, the current trail is attached to that event and shown on the issue page.

Tips

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.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap