k6/execution module provides detailed information about the current test’s execution state, including scenario metadata, VU information, and test control functions.
Overview
Use this module to:- Access scenario and test metadata
- Get unique identifiers for VUs and iterations
- Control test execution (abort, fail)
- Set custom tags and metadata on metrics
- Retrieve consolidated test options
Importing the Module
API Reference
Theexecution object provides four main property groups:
instance
Information about the current load generator instance (k6 process).number
Number of prematurely interrupted iterations in the current instance.
number
Number of completed iterations in the current instance.
number
Number of currently active VUs.
number
Number of currently initialized VUs.
number
Time elapsed since the start of the current test run (milliseconds).
scenario
Metadata and execution details about the current running scenario.string
The assigned name of the running scenario.
string
The name of the running executor type (e.g.,
"shared-iterations", "ramping-vus").number
Unix timestamp (milliseconds) when the scenario started.
number
Scenario progress as a float between 0 and 1.
number
Unique zero-based sequential number of the current iteration in the scenario, across the current instance.
number
Unique zero-based sequential number of the current iteration in the scenario, across all k6 instances (local, cloud, distributed).
test
Control functions and test-wide information.function
Aborts the test run with exit code
108. Optionally provide an error message.Parameters:string
Optional error message to log
Aborting does not prevent
teardown() from running.function
Marks the test run as failed with exit code
110. Does not interrupt test execution - all iterations finish normally.Parameters:string
Optional failure message to log
object
Returns an object with all consolidated test options following the order of precedence. Properties where no option is defined return
null.vu
Metadata and execution details about the current VU.number
Iteration identifier for this VU in the current instance. Only unique for this VU and instance.
number
Iteration identifier for this VU in the current scenario. Only unique for this VU and scenario.
number
VU identifier across the instance. Not unique across multiple instances.
number
Globally unique VU identifier across the entire test run.
object
Map for controlling VU-level tags. Tags are included in every metric emitted by this VU and maintained across iterations.
object
Map for controlling VU-level metadata. Metadata is included in every metric emitted by this VU and maintained across iterations.
Unique Identifiers: All unique identifiers are sequentially generated starting from zero (iterations) or one (VU IDs). In distributed/cloud tests, identifiers remain unique across instances, though gaps may exist due to different execution speeds.
Examples
Basic Scenario Information
Getting Unique Data
Use iteration identifiers for data parameterization:Timing Operations
Conditional Logic by Scenario
Test Abort
Test Fail
Getting Test Options
Custom Tags
Custom Metadata
Unique Data Distribution
Tag and Metadata Types
Supported Tag Types
k6 supports the following types as tag values:- Strings
- Numbers
- Booleans
Tags vs Metadata
Best Practices
Use iterationInTest for Unique Data
Use iterationInTest for Unique Data
Use
exec.scenario.iterationInTest or exec.vu.idInTest to distribute unique data across all VUs and instances:Use Metadata for High-Cardinality Data
Use Metadata for High-Cardinality Data
Use metadata instead of tags for high-cardinality data to avoid metric explosion:
Clean Up Resources on Abort
Clean Up Resources on Abort
Always use
teardown() for cleanup, as it runs even after test.abort():Related Resources
Init Context
Global variables and initialization
Scenarios
Configure test scenarios
Tags and Groups
Organize and filter metrics
Test Lifecycle
Understanding k6 execution phases