5

I have a Locust task that requires many HTTP requests. At the end of the task, I have conditions to check for success or failure. The statistics gathered are very informative in regards to the individual HTTP requests, but I would like to know more information about each invocation of the task itself. For example, how long it took to run the function, whether it completed successfully, etc.

I can't find a good way to do this. It seems like each HTTP request makes a log entry, but I don't know how to manually create one. Can anyone give me some guidance?

Sam Bobel
  • 1,784
  • 1
  • 15
  • 26

1 Answers1

6

You can create an entry manually by triggering the request_success event.

from locust import events
events.request_success.fire(
    request_type="task", 
    name="my_task", 
    response_time=1337, 
    response_length=0,
)

You could also create a decorator that automatically fires the above event and tracks the execution time for the tasks that it's applied to.

heyman
  • 4,845
  • 3
  • 26
  • 19