If you want to create the metric from the k6/metrics
and pass it to your extension as in:
import { Counter } from "k6/metrics";
import { customFunc } from "k6/x/myExtension";
var c = new Counter ("coolCounter");
export default function(){
customFunc(c); // this to then be able to call `c.Add`
}
In this case, you are hitting an issue with k6 use of common.Bind
which I try to explain here. So you can’t … easily.
I haven’t tried it but what you will get instead of the original object will be a map[string]interface{}
where the keys should be add
and the value func(call goja.FunctionCall) goja.Value
(for this particular case) so you technically should be able to call that … just with some more hoops to jump through.
Hopefully, we will drop the whole common.Bind
thing at some point (unfortunately breaking your code ;() and have it be way easier … but no ETAs, sorry.