Question about Tags, http.post

Greetings!
For few weeks already I’m using k6 for our performance testing and it goes good, thanks in advance for this instrument.
Nevertheless, I would like to ask about “tags” and http.post.
According to documentation, http.post takes 3 arguments, which are url, body, params.
I do use all 3 of those in my requests, due to need in headers/tokens. And when I’m trying to apply tag, it just doesn’t work, Grafana recognizes only full URL as name (and that’s basically default name), resulting me seeing huge urls instead of my custom names.
However, with http.get tags work just fine.
Could you please give me an example of how do I apply tags to http post request, considering I’m using URL, body data and params already.

My code which doesn’t work:

 let res = http.post(`https://${__ENV.host}/v1/api/`, payload, params, 
 { tags: { name: 'Getting something from api' }})

Hi @Nesodus , Welcome to the forum!

The whole params is an object which can have any of the documented keys

So what you should’ve had is

var params = {
   header: {"Header1": "Header1Value", "Header2": "Header2Value"},
   tags: {name: "Getting something from api"},
/// any of the other onse
}
let res = http.post(`https://${__ENV.host}/v1/api/`, payload, params)

Hope this helps

Thank you!
I will try it out, but here’s another quick question: what if my headers in params are used in around 30 requests?
Currently I allocated params in init() context, so once per VU. But tags should be different for every request :frowning:
Thanks a lot in advance!
It’s mostly QoL thing to me.

You can either:

  1. have the headers as a separate object and do http.post(url, payload, {"headers": headers, tags: {name: "something"}}
  2. Change the params between invocations (which IMO will be problematic
  3. have different ones predefined for the different requests, I would expect that the headers will be slightly different as well :wink:
1 Like

Thank you, 1st one is exactly what I needed.
Cheers!