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.
Create a k6 extension
If you find a gap in your testing process that no k6 extension can fix, consider building your own extension.
These tutorials show you how to create custom JavaScript and output extensions.
- Create a JavaScript extension to extend the JavaScript functionality of your script or add support for a new network protocol to test.
- Create an Output extension to process the metrics emitted by k6 or publish them to unsupported backend stores.
Necessary knowledge
Anyone who can use the command line to edit files and install software should be able to follow along. But, if you want to create an extension for more than the purposes of demonstration, there’s some background knowledge you should have:
- You should be familiar with both Go(lang), JavaScript, and their tooling
- You should understand how the Go-to-JavaScript bridge works within k6
Note
If you maintain a public xk6 repository and wish to have your extension listed in our registry, be sure to review the requirements.
Avoid unneeded work
These actions may save you the trouble of building a whole new extension when its not needed.
- Confirm that a similar extension doesn’t already exist for your use case. Take a look at
the Extensions listing and the
xk6
topic on GitHub. - Prefer generic solutions. For example, if you can test a system with a generic protocol like MQTT, prefer xk6-mqtt over a new extension for some custom protocol.
- Lean toward writing pure JavaScript libraries over building an extension in Go. A JavaScript library will be better supported, more straightforward, and reusable than an extension.