Skip to main content
The Linked Errors integration automatically captures error cause chains and aggregate errors, following the error’s 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 the cause property:

2. Aggregate Errors

Captures all errors from AggregateError:

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:
  1. Main Exception: The top-level error you captured
  2. Chained Exceptions: Related errors shown below, marked as “caused by”
  3. 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 limit option for deeply nested error chains

Best Practices

Use error causes to preserve context when re-throwing errors
  1. Always preserve the original error:
  2. Add context at each layer:
  3. 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: