MetricMessage
A MetricMessage
object allows tagging of metrics that are measured and emitted for the page.
MetricMessage
objects are dispatched by the page when a handler is registered with page.on(‘metric’). For each metric that is measured and emitted for the page, the k6 browser module delivers a MetricMessage
object to the registered handlers, allowing them to pattern match and tag metrics.
tag
The tag
method matches the given matches
with the current metric’s url and name tags. When a match is found, it will use name
to replace the existing URL and name tag values.
Doing this helps group metrics with different URL and name tags that, in fact, reference the same resource, allowing for correlation over time and reducing the cardinality of the metrics.
Example Usage
// First we need to register a handler with `page.on('metric')`.
page.on('metric', (metric) => {
// It will find a match between the current metric url and name tags against
// the supplied regular expression in `url`.
metric.tag({
// This is the new name value that will replace the existing value in the
// url and name tags when a match is found.
name: 'test',
// You can provide multiple matches here.
matches: [
{
url: /^https:\/\/test\.k6\.io\/\?q=[0-9a-z]+$/,
// When a method is defined it will also need to match on that too. If a
// method is not provided it will match on all method types.
method: 'GET',
},
],
});
});