Skip to main content
To use k6 extensions, you need to build a custom k6 binary that includes the extensions you want. This is done using xk6, the k6 extension builder.

Prerequisites

  • Go 1.22 or later
  • Git
  • Basic command-line knowledge
You don’t need to write Go code to use extensions, only to build k6 with them included.

Installing xk6

Install xk6 using Go:
Verify installation:

Building k6 with Extensions

Build k6 with one or more extensions:
This creates a k6 binary in the current directory with the Redis extension included.

Multiple Extensions

Include multiple extensions in a single build:
You can specify any number of extensions in a single build command.

Specific Versions

Pin extensions to specific versions for reproducibility:
Use Git references:

Local Development

Use local extension code during development:
This is useful when:
  • Developing extensions
  • Testing unreleased changes
  • Making local modifications

Output Location

By default, xk6 creates the binary in the current directory. Specify a different location:
You may need sudo to write to system directories like /usr/local/bin.

Using Extensions in Tests

Once you’ve built k6 with extensions, use them in your test scripts.

JavaScript Extensions

Import JavaScript extensions from the k6/x/ namespace:
The import name matches the extension’s registered name.

Output Extensions

Use output extensions with the --out flag:
Pass configuration:
Or via script options:

Subcommand Extensions

If an extension adds a subcommand, use it like any k6 command:

Verifying Extensions

Check which extensions are included in your build:
Output shows k6 version and all compiled extensions:
If an extension doesn’t appear, it wasn’t properly included during the build.

Common Extension Use Cases

Testing Databases

Testing Message Queues

Browser Testing

Custom Outputs

Environment-Specific Builds

Create different builds for different environments:

Development

Production

Automation

Build Script

Create a build script for consistent builds:
Make it executable and run:

Docker

Create a Dockerfile with extensions:
Build and use:
Using Docker ensures consistent builds across different environments and team members.

Troubleshooting

Build Failures

If the build fails:
  1. Check Go version: Ensure Go 1.22+
  2. Verify extension exists: Check the repository URL
  3. Check version compatibility: Some extensions require specific k6 versions
  4. Clear Go cache:

Import Errors

If JavaScript imports fail:
  1. Verify extension is included:
  2. Check import path: Must use k6/x/ namespace
  3. Rebuild: Ensure you’re using the custom binary

Extension Not Found

If an extension doesn’t appear:
  1. Check registration: Extension must call ext.Register() in init()
  2. Rebuild with verbose:
  3. Check extension documentation: Some extensions have special requirements

Finding Extensions

Discover extensions:
Not all extensions are officially supported by Grafana. Community extensions may have varying quality and maintenance levels.

Best Practices

Next Steps