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

1,608 views
Skip to first unread message

jimt1234

unread,
Feb 26, 2015, 2:06:20 PM2/26/15
to gat...@googlegroups.com
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

Stéphane LANDELLE

unread,
Mar 3, 2015, 5:09:50 AM3/3/15
to gat...@googlegroups.com
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,

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages