Skip to main content
The fault proactive chaos strategy is designed to introduce faults (exceptions) into the system, simulating real-world scenarios where operations might fail unexpectedly. It is configurable to inject specific types of exceptions or use custom logic to generate faults dynamically.

Configuration

  • Options: ChaosFaultStrategyOptions
  • Extensions: AddChaosFault

Basic usage

Here are several ways to configure the fault chaos strategy:

Complete example

Here’s a complete example showing fault injection with retry:
Chaos strategies should be placed last in the resilience pipeline. This ensures that the fault is injected at the last minute, allowing your other resilience strategies (retry, circuit breaker, etc.) to handle the injected fault.

Strategy options

Generating faults

You have two main approaches to generating faults:

Using FaultGenerator class

The FaultGenerator is a convenience API that allows you to specify what faults (exceptions) are to be injected. Additionally, it also allows assigning weight to each registered fault.
When multiple exceptions are registered with different weights, exceptions with higher weights are more likely to be injected. For example, an exception with weight 50 will be injected half as often as one with weight 100.

Using delegates

Delegates give you the most flexibility at the expense of slightly more complicated syntax. Delegates also support asynchronous fault generation, if you ever need that possibility.
Returning null from the FaultGenerator delegate means no fault will be injected for that particular execution, and the user’s callback will be invoked normally.

Telemetry

The fault chaos strategy reports the following telemetry events: Here are some sample events:
The Chaos.OnFault telemetry event will be reported only if the fault chaos strategy injects an exception which is wrapped into a ValueTask. If the fault is either not injected or injected and throws an exception then there will be no telemetry emitted. Also, the Result will be always empty for the Chaos.OnFault telemetry event.

How it works

Normal execution (no chaos)

Chaos execution (fault injected)

Use cases

Fault injection is useful for:
  • Testing error handling: Verify that your retry, circuit breaker, and fallback strategies work correctly when exceptions occur
  • Simulating external service failures: Test how your application behaves when dependencies throw exceptions
  • Validating monitoring and alerting: Ensure your observability systems properly capture and report errors
  • Training operations teams: Help teams practice incident response procedures in a controlled environment
When using fault injection in production environments, always:
  • Start with a very low injection rate (e.g., 0.01 or 1%)
  • Target only specific test users or tenants
  • Monitor the impact closely
  • Have a quick way to disable chaos injection if needed