Grafana k6 counter tags not being added (local run, CLI)

Hello,

I am creating a load test script with Grafana k6. This script will run on CLI. I am trying add tags to my custom counter, but the tags do not seem to be added to the counter.

Here is a minimal working example:

import http from 'k6/http';
import {Counter} from 'k6/metrics';

let myCounter = new Counter('custom_counter');

export default function () {
    let res = http.get('https://test.k6.io');
    myCounter.add(1, {tag1: 'value1'});
    myCounter.add(1, {tag1: 'value2'});
}

export function handleSummary(data) {
    console.log(JSON.stringify(data.metrics.custom_counter));
}

When running via:
k6 run --summary-trend-stats "min,avg,med,p(95),p(99),p(99.99),max" k6/mwe.js

I get this output (before the general summary):
INFO[0000] {"type":"counter","contains":"default","values":{"count":2,"rate":6.073655216814307}} source=console

What I would expect here is a something like a tags key with the value for each tag, or tag combination. How can I achieve this?

Thank you.

Hi @vicaba I don’t understand your question I will write what I understood. Counter is used to count how many iterations have in the execution in K6. Fot get metrics in K6 a each tag, you use Trend as in the example below

import http from 'k6/http';
import {Counter, Trend} from 'k6/metrics';

let myCounter = new Trend('custom_counter');
let myCounter1 = new Trend('custom_counter1');

export default function () {
    let res = http.get('https://test.k6.io');
    myCounter.add(1, {tag1: 'value1'});
    myCounter1.add(1, {tag1: 'value2'});
}

export function handleSummary(data) {
    console.log(JSON.stringify(data.metrics.custom_counter));
    console.log(JSON.stringify(data.metrics.custom_counter1));
}

Is that your question?
I’m here to help