Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Error handler
When encountering errors from the backend, it’s often necessary to gather additional error information, such as error messages, tracing data, or request and response bodies. Our first suggestion is to leverage your observability solution to find these errors. However, capturing error details directly in k6 can also be useful for troubleshooting.
In k6, there are two common approaches to store additional error information:
- Console logs and output k6 logs to Loki, a file, or use Grafana Cloud k6.
- Using Tags in a custom counter metric to track error data.
When deciding what error data to store, consider whether it is an general or specific error, and be aware that high-load tests may generate a substantial volume of error data.
Below is an example using an ErrorHandler to log error information. It accepts a callback that instructs how to log errors. The example provides instructions for both previously mentioned options: console logs and custom metrics.