igr
igr

Reputation: 10624

Collect errors with Gatling?

In my long, but simple awesome Gatling simulation, I have few responses that ended with error 500. Is it possible to tell gatling to collect these error responses messages in a file during the simulation?

Upvotes: 6

Views: 1674

Answers (2)

llatinov
llatinov

Reputation: 104

It is possible to collect what ever you want and save it into simulation.log file. Use extraInfoExtractor method when you define protocol:

val httpProtocol = http
    .baseURL(url)
    .check(status.is(successStatus))
    .extraInfoExtractor { extraInfo => List(getExtraInfo(extraInfo)) }

Then define in your getExtraInfo(extraInfo: ExtraInfo) method whatever criteria you want. Example bellow outputs request and response in case of debug is enables via Java System Property OR response code is not 200 OR status of request is KO (it can be KO if you have setup some max time and this max time gets increased)

private val successStatus: Int = 200
private val isDebug = System.getProperty("debug").toBoolean   
private def getExtraInfo(extraInfo: ExtraInfo): String = {
    if (isDebug
        || extraInfo.response.statusCode.get != successStatus
        || extraInfo.status.eq(Status.valueOf("KO"))) {
        ",URL:" + extraInfo.request.getUrl +
            " Request: " + extraInfo.request.getStringData +
            " Response: " + extraInfo.response.body.string
    } else {
        ""
    }
}

Upvotes: 2

Stephane Landelle
Stephane Landelle

Reputation: 7038

No in production mode. You only have them when debug logging is enabled.

Upvotes: 2

Related Questions