Hello, I was wondering if it is possible to call an xk6 extension function from the handleSummary function? From my testing so far, it seems like that is not the case since it seems like k6 doesn’t even acknowledge the call to my xk6 Go function.
What I am trying to do is convert the test summary to a structured format that we can store in our internal logging system. I have some code in my Go module to accomplish this, however, I need to be able to send the summary over from handleSummary to my Go code. Or are extensions only accessible within the default and tearDown functions? If so, are there any plans to allow functions like handleSummary to also use extensions?
For additional context, I have exposed my Go module to k6 using xk6 and have successfully called functions there from both the default function and the teardown function previously, so my question is specifically about handleSummary.
Hi @arosariofds!
Welcome to the forum!
I think you should use Output extension instead of javascript extension for this purpose. In an output exension you wil get all the metrics k6 produces, and you can do whatever you want with it.
Interesting, I hadn’t read up on those until now. I’m going to see if I can keep my current extension intact since it has some custom logic in there to make the db calls, but I will try and have a second Output extension to handle the metrics emitted by k6 and log them how/where I need them. I’m assuming I can use as many extensions as needed so I hope this will work. Thanks for the suggestion!
I am curious to know if k6 will ever support calling an extension from handleSummary either way, so I will definitely check back later as well.
@arosariofds
Yes. You can use as many extensions as you want.
So I’ve gotten the example Output Extensions code working from the k6 documentation but I am not seeing any clear way to access the test summary (the one that usually gets passed to handleSummary) in the extension. Or do I essentially have to build that summary myself, aggregating each sample’s metric value as it runs from the output extension? I was hoping to just be able to hook in to use the summary that k6 already creates so I can access the aggregated metrics from there.
Hey @arosariofds,
did you check the custom summary documentation? Take a look at this section for sending data to a remote service.
You can do the same creating a JavaScript extension and implementing the same function in Go, in case it is your preference for writing the code.
Let me know if it helps.
1 Like