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:Strategy options
Generating faults
You have two main approaches to generating faults:Using FaultGenerator class
TheFaultGenerator 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.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