unique identifier in http headers for every Gatling request ???

I’m trying to add a unique transaction-id in the http headers to every request that Gatling executes in my scenario. The transaction-id is simply a unique identifier based on the combination of a common value and a unique value.

I can create a counter to append to the global value, but I can’t seem to inject that value into the http header for every request. Here’s what I have so far:

`
val counter = new java.util.concurrent.atomic.AtomicInteger(1)

def http_header() : Map[String, String] = {
var global_id = “gatling_request”
var unique_id = counter.getAndIncrement.toString
var transaction_id = global_id + unique_id ### unique transaction-id
var http_header = Map(
“Content-Type” → “application/json”,
“tid” → transaction_id )
return http_header
}

val show_list = group(“Get API”) {
exec(http(“List API”)
.get("/api/v1/list")
.check(status.is(200))
)
.exec { session =>
.headers(http_header()) ### transaction-id in http header
}
.pause(500 milliseconds)
}
`

The best I can do is to inject the same transaction-id for all of the requests in the scenario (‘gatling_request1’). But I’m having trouble injecting a unique id for every transaction. I’m sure there’s different ways to accomplish this, and I’m open to anyway that works. But basically, I’m just looking for a way to inject some sort of unique identifier into the http header for every single requests that Gatling executes.

THANK YOU!
Jim

Hi,

You got right that you have to compute your tid header value in a function, but you don’t do it right (or your sample is messed up because you didn’t paste it all).

http(“foo”).get(“url”).header(“tid”, session => generateTransactionId())

Cheers,