Error Context and Breadcrumbs
You'll learn how to enrich error reports with user actions, network requests, and state changes to understand what led to an error.
The Challenge of Isolated Errors
When an error report arrives showing "Cannot read property 'data' of undefined," you know what broke — but not why. Without context, you're solving a mystery with no clues. Did the user click five buttons rapidly? Did a network request fail first? What was the application state?
What Are Breadcrumbs?
Breadcrumbs are a chronological trail of events leading up to an error — like a flight recorder's black box. They capture user interactions, API calls, console logs, navigation, and state mutations, then attach them to error reports automatically.
Analogy: Imagine debugging a car accident. A photo of the crashed car (the error) is useful, but dashcam footage showing the 30 seconds before impact (breadcrumbs) reveals the cause.
Implementing Breadcrumbs
Most error tracking tools like Sentry automatically capture common breadcrumbs:
// Sentry automatically records these as breadcrumbs:
// - Navigation events
// - Console logs
// - Network requests (XHR/fetch)
// - User clicks
// You can also add custom breadcrumbs manually:
Sentry.addBreadcrumb({
category: 'cart',
message: 'User added item to cart',
level: 'info',
data: { itemId: '12345', quantity: 2 }
});
When an error occurs, your report includes the last 50-100 breadcrumbs, showing the user's journey:
- User navigated to
/checkout - Fetched cart data (200 OK)
- Clicked "Apply Coupon"
- API request to
/api/coupons(500 Error) - ERROR: Cannot read property 'data' of undefined
Now you know the API failure caused the undefined data.
Key Takeaway: Breadcrumbs transform cryptic error reports into actionable debugging stories by preserving the sequence of events that led to failure.