Locust: Support detailed logging for failed requests

Created on 15 Aug 2018  ยท  3Comments  ยท  Source: locustio/locust

Description of issue / feature request

Log all failed requests to a CSV or JSON file. Any time an HTTP request is marked as failure, log details of that request to a CSV file.

Currently we only have the capability to export summary information to a CSV file, but it is incredibly useful to correlate timestamps and details of requests to timestamps in service/application

Exporting request details is a critical part of analyzing the results of any performance test.

The expectation would also be that this functionality would work when running Locust headlessly.

Expected behavior

Desired fields would be, at the very least: request timestamp, request duration, response status code, response body, and perhaps some headers.

Actual behavior

Locust does not appear to have any useful support for this feature in its current state.

Some similar but not identical issues include: #675 #774

wontfix

Most helpful comment

A workaround for this could be something like:

from locust import events
def request_failure_handler(request_type, name, response_time, exception, **kwargs):
    # some logic
    pass
events.request_failure += request_failure_handler

To get the response body/headers/etc you can use the exception parameter which is a subclass of requests.exceptions.RequestException
http://docs.python-requests.org/en/master/_modules/requests/exceptions/

But it would be really useful to make this a command-line argument similar to how we export the distribution csv

All 3 comments

A workaround for this could be something like:

from locust import events
def request_failure_handler(request_type, name, response_time, exception, **kwargs):
    # some logic
    pass
events.request_failure += request_failure_handler

To get the response body/headers/etc you can use the exception parameter which is a subclass of requests.exceptions.RequestException
http://docs.python-requests.org/en/master/_modules/requests/exceptions/

But it would be really useful to make this a command-line argument similar to how we export the distribution csv

Is this solved by PR #999 ?

No solved by #999 I think, but I don't think the use-case for this is common enough for it to be included in Locust itself when you can easily achieve it yourself by using the request_failure event.

Was this page helpful?
0 / 5 - 0 ratings