Skip to content

Commit b4985d3

Browse files
Add base Metadata API documentation (#1207)
Co-authored-by: Oleg Bespalov <[email protected]>
1 parent 3b88f3d commit b4985d3

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

src/data/markdown/docs/02 javascript api/06 k6-execution.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,10 @@ Meta information and execution details about the current vu.
8484
| iterationInScenario | integer | The identifier of the iteration in the current scenario for this VU. This is only unique for current VU and scenario it is currently executing. |
8585
| idInInstance | integer | The identifier of the VU across the instance. Not unique across multiple instances. |
8686
| idInTest | integer | The globally unique (across the whole test run) identifier of the VU. |
87-
| tags | object | The map that gives control over [VU's Tags](/using-k6/tags-and-groups/#tags). The Tags will be included in every metric emitted by the VU and the Tags' state is maintained across different iterations of the same Scenario while the VU exists. Check how to use it in the [example](#tags) below. |
87+
| metrics.tags | object | The map that gives control over [VU's Tags](/using-k6/tags-and-groups/#tags). The Tags will be included in every metric emitted by the VU and the Tags' state is maintained across different iterations of the same Scenario while the VU exists. Check how to use it in the [example](#tags) below. |
88+
| metrics.metadata | object | The map that gives control over VU's Metadata. The Metadata will be included in every metric emitted by the VU and the Metadata's state is maintained across different iterations of the same Scenario while the VU exists. Check how to use it in the [example](#metadata) below. |
8889

89-
<Collapsible title="Setting vu.tags">
90+
<Collapsible title="Setting vu.metrics.tags">
9091

9192
Setting a Tag with the same key as a [system tag](/using-k6/k6-options/reference#system-tags) is allowed, but it requires attention to avoid unexpected results. Overwriting system tags will not throw an error, but in most cases will not actually change the value of the emitted metrics as expected. For example, trying to set the `url` tag value will not result in a changed tag value when `http.get()` is called, since the tag value is determined by the HTTP request itself. However, it will add the tag `url` to the metric samples emitted by a `check()` or `metric.add()`, which is probably not the desired behavior. On the other hand, setting the `name` tag will work as expected, since that was already supported for `http.*` methods, for the purposes of the [URL Grouping](/using-k6/http-requests/#url-grouping) feature.
9293

@@ -212,7 +213,7 @@ export default function () {
212213
</CodeGroup>
213214

214215
### Tags
215-
The `vu.tags` property can be used for getting or setting [VU's tags](/using-k6/tags-and-groups/#tags).
216+
The `vu.metrics.tags` property can be used for getting or setting [VU's tags](/using-k6/tags-and-groups/#tags).
216217

217218
<CodeGroup labels={["tags-control.js"]} lineNumbers={[true]}>
218219

@@ -221,12 +222,38 @@ import http from 'k6/http';
221222
import exec from 'k6/execution';
222223

223224
export default function () {
224-
exec.vu.tags['mytag'] = 'value1';
225-
exec.vu.tags['mytag2'] = 2;
225+
exec.vu.metrics.tags['mytag'] = 'value1';
226+
exec.vu.metrics.tags['mytag2'] = 2;
226227

227228
// the metrics these HTTP requests emit will get tagged with `mytag` and `mytag2`:
228229
http.batch(['https://test.k6.io', 'https://test-api.k6.io']);
229230
}
230231
```
231232

232233
</CodeGroup>
234+
235+
`vu.tags` (without `metrics`) can also be used, but is deprecated for the more context-specific variant.
236+
237+
238+
### Metadata
239+
The `vu.metrics.metadata` property can be used for getting or setting VU's metadata. It is similar to `tags`, but can be used for high cardinality data. It also can not be used in thresholds and will likely be handled differently by each output.
240+
241+
<CodeGroup labels={["metadata-control.js"]} lineNumbers={[true]}>
242+
243+
```javascript
244+
import http from 'k6/http';
245+
import exec from 'k6/execution';
246+
247+
export default function () {
248+
exec.vu.metrics.metadata['trace_id'] = 'somecoolide';
249+
250+
// the metrics these HTTP requests emit will get the metadata `trace_id`:
251+
http.batch(['https://test.k6.io', 'https://test-api.k6.io']);
252+
253+
delete exec.vu.metrics.metadata['trace_id'] // this will unset it
254+
// which will make the metrics these requests to not have the metadata `trace_id` set on them.
255+
http.batch(['https://test.k6.io', 'https://test-api.k6.io']);
256+
}
257+
```
258+
259+
</CodeGroup>

0 commit comments

Comments
 (0)