Locust: See what request generated a failure

Created on 28 Oct 2013  路  13Comments  路  Source: locustio/locust

It would be very to nice to able to see what http request generated a failure. It also would be useful to include the payload that was sent with the request.

Most helpful comment

You can use Event hooks, like:

from locust.events import request_failure

def on_failure(request_type, name, response_time, exception, **kwargs):
    print exception.request.url
    print exception.response.status_code
    print exception.response.content

request_failure += on_failure

All 13 comments

Indeed, this has been on the todo list for a while. If time allows, I'll see if I can get this sorted once and for all.

I agree. We just have to make sure to use sampling of data, so that we don't end up using up all bandwidth when running Locust distributed with a lot of slaves.

About the number of samples, one of the issues that I have found is that the app I am load testing uses lot of unique urls, which makes the web interface heavy to load, or even impossible

You can name your requests using the name parameter to .get(), .post() etc.

l.get("/profile/%d" % user_id, name="/profile/[user-id]")

You can use Event hooks, like:

from locust.events import request_failure

def on_failure(request_type, name, response_time, exception, **kwargs):
    print exception.request.url
    print exception.response.status_code
    print exception.response.content

request_failure += on_failure

The above is an excellent debugging tip.

perhaps something like https://github.com/BenjamenMeyer/locust/tree/enhancement_track_responses would be good? It's more specific to an API that I'm developing, but it could probably be generalized by making the 'transaction-id' header field name a configuration variable.

If it isnt already in there, we should add @Alerion 鈥檚 suggestion to the documentation. Closing this.

Now in master it doesn't work, probably the API is changed and the API docs are not yet up-to-date. I get:

TypeError: unsupported operand type(s) for +=: 'EventHook' and 'function'

The docs are up to date here: https://docs.locust.io/en/latest/api.html#event-hooks
(you linked to the latest stable docs).

Ah, my bad, thank you!

Hi All

I got "TypeError: unsupported operand type(s) for +=: 'EventHook' and 'function'" I solved it by adding locust.events to requests.

Then now I am getting new error
Traceback (most recent call last):
File "C:UsersxxxxxxAppDataLocalProgramsPythonPython38Librunpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:UsersxxxxxxAppDataLocalProgramsPythonPython38Librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:UsersxxxxxxxxxxxvenvScriptslocust.exe__main__.py", line 7, in
File "c:usersxxxxxxxxxxxvenvlibsite-packageslocustmain.py",
line 133, in main
options = parse_options()
File "c:usersxxxxxxxxxvenvlibsite-packageslocustargument_parser.py", line 442, in parse_options
parser = get_parser()
File "c:usersxxxxxxxxxxxvenvlibsite-packageslocustargument_parser.py", line 437, in get_parser
locust.events.init_command_line_parser.fire(parser=parser)
AttributeError: module 'locust.events' has no attribute 'init_command_line_parser'

I am using all latest version python --3.8
PIP -20.0.2
Locust --1.2.3

Can you please help fix this error what eactly is reason for this error and what package needs to be updated.

I have the same error, how can I solve it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bretrouse picture bretrouse  路  4Comments

sanyco92 picture sanyco92  路  4Comments

meeech picture meeech  路  4Comments

ludo550 picture ludo550  路  3Comments

ghost picture ghost  路  3Comments