Custom metric data not same as builtin

The builtin metrics, such as “http_req_duration” (which is a threshold) have result data list this: metric_name timestamp metric_value check error error_code expected_response group method name proto scenario service status subproto tls_version url

A created custom metric only produces this data :
timestamp, metric_value, scenario

How do I produce the other values?

Hi @embenson864,

I am bit confused by your description of http_req_duration, can you explain in more details why you are describing it as being a threshold and “result data list” is not really a term I am familiar with.

I expect that and timetatmps and metric_value come from some output you are using?

To give some explanation http_req_duraiton is a metric that is emitted by a built-in module which means that it is kind of “reserved” but doesn’t really have anything else special about it.

It has tags (sometimes called labels in other systems) and the list you provided seems to be the list of tags that get added to http_req_duration by the k6/http module when emitted.

The API for custom metrics (for example Gauge has the add method as the way to emit a metric sample. And that method does take a map/object of tag key-value pairs as the second argument.

import { Gauge } from 'k6/metrics';

const myGauge = new Gauge('my_gauge');

export default function () {
  myGauge.add(1); // doesn't add additional tags
  myGauge.add(2, { tag1: 'value', tag2: 'value2' }); // adds additiona tags
}

scenario and group are usually added by default as they just get propagated when calling anything.

Hope this helps you!