timing-asgi icon indicating copy to clipboard operation
timing-asgi copied to clipboard

Metrics include time spent on background tasks in Starlette

Open eirikur-grid opened this issue 5 years ago • 3 comments

For some routes, we make use of the background tasks feature in Starlette. The timing metrics we have gathered indicate that time spent executing these background tasks is being included. While that's not necessarily bad, it would be preferable if we could have a measure of response time separate from overall time spent on a request.

eirikur-grid avatar Aug 28 '19 11:08 eirikur-grid

Agreed. The timing should be emitted after the response is sent to the client. It might be interesting to see the total time however, and subtracting the time-to-response from it, the time spent on background tasks could be derived.

steinnes avatar Aug 28 '19 17:08 steinnes

What's the status on this?

jeanlst avatar Jan 06 '22 20:01 jeanlst

I am not finding the time to work on it at the moment, but I did come up with a rough design for how I'd like to reengineer this middleware to emit metrics at 4 different points during the "request lifetime".

image

I have struggled to prioritise this, and should probably just roll a version of this middleware which wraps the response writing so we emit timing when writing response.

steinnes avatar Jul 13 '22 23:07 steinnes