I’m trying to use the trends for my tests and I’m unable to when the request name is dynamic. There are ~300 api calls and I don’t execute tests on all at all the time nor can I declare trends for 300 request names. I want to be able to run each request individually and I want to declare trend in the below fashion so that the requests names change and the trends for them are initiated in run time.
import { Trend } from 'k6/metrics';
let requestTrends = {};
export function requestTrend(stepName, response) {
if (!requestTrends[stepName]) {
requestTrends[stepName] = new Trend(stepName);
}
requestTrends[stepName].add(response.timings.duration);
}
When I import the function in other file and call it I get
GoError: metrics must be declared in the init context