What are tags?
Tags are key-value pairs attached to metrics, checks, and requests. They enable you to:- Filter metrics by request type, endpoint, or custom criteria
- Set thresholds for specific tagged metrics
- Analyze results by different dimensions
- Compare performance across different parts of your test
System tags
Automatically added by k6Examples:
status, method, urlUser-defined tags
Custom tags you add to your testExamples:
endpoint, type, prioritySystem tags
k6 automatically tags metrics with system-defined metadata:Optional system tags
These tags are disabled by default but can be enabled:
Enable them using the
systemTags option:
User-defined tags
Add custom tags to requests, checks, and metrics:Tag HTTP requests
Tag checks
Tag custom metrics
Test-wide tags
Set tags that apply to all metrics in your test:- In script
- CLI flags
- Comparing results across test runs
- Filtering results in monitoring systems
- Organizing tests by environment or team
Thresholds on tagged metrics
Set different thresholds for different tagged requests:Groups
Groups organize test code into logical sections and automatically tag all operations within them.Basic groups
group tag.
Nested groups
Groups can be nested for hierarchical organization:group tag shows the full path: ::user workflow::login
Group duration metric
k6 automatically creates agroup_duration metric for each group:
Dynamic tags from code
Set tags dynamically during test execution:Tagging stages
Use helper functions to tag operations by their test stage:Complete example
Here’s a comprehensive example using tags and groups:Best practices
Use descriptive tag names
Make tag names clear and consistent across your tests.
Tag by request type
Separate API, static content, and other request types with tags.
Group logical workflows
Use groups to organize user journeys and workflows.
Set thresholds per tag
Define different performance requirements for different request types.