cause property or custom error linking keys.
Installation
This integration is enabled by default in all Sentry SDKs.How It Works
The integration captures linked errors in two ways:1. Error Cause Chain (ECMAScript 2022)
Automatic capture of errors linked via thecause property:
2. Aggregate Errors
Captures all errors fromAggregateError:
Configuration
Default Configuration
The integration uses these defaults:Custom Error Key
If your application uses a custom property for error chaining:Limit Linked Errors
Control the maximum depth of error chains:Configuration Options
string
default:"cause"
The property name to follow for linked errors
number
default:"5"
Maximum number of linked errors to capture
Practical Examples
Service Layer Error Chaining
Parallel Operations with AggregateError
API Integration Error Context
How Linked Errors Appear in Sentry
In the Sentry UI, linked errors appear as:- Main Exception: The top-level error you captured
- Chained Exceptions: Related errors shown below, marked as “caused by”
- Full Context: Each error includes its own stacktrace and metadata
Source Code
The Linked Errors integration is implemented in:packages/core/src/integrations/linkederrors.ts:16
Performance Considerations
- The integration limits error chains to prevent excessive data
- Each linked error includes its full stacktrace
- Consider the
limitoption for deeply nested error chains
Best Practices
-
Always preserve the original error:
-
Add context at each layer:
-
Use AggregateError for parallel operations:
Troubleshooting
Linked Errors Not Appearing
Ensure you’re using the correct property name:Too Many Linked Errors
Increase the limit if error chains are being truncated:Related
- Event Filters - Filter unwanted errors
- captureException - Manual error capture