Closed
Description
Hello :)
While investigating a bug regarding very slow uploads, we discovered two things about the Starlette middleware.
- It does not honor the "capture_body" flag by consuming the stream regardless the flag is turned on or not. It replaces the original stream with a mocked one, making the Starlette request.stream() feature useless because the request is already entirely in memory (using a lot of memory in case of file uploads). I think the following piece of code could check the flag and behave differently.
apm-agent-python/elasticapm/contrib/starlette/__init__.py
Lines 151 to 163 in 69beac4
- The same block of code above uses byte concatenation instead of a byte array which is fine for very small buffers but prohibitively slow with anything bigger because of the quadratic behavior. Gigabyte-sized streams do not work at all.
I would happily send a pull request for that, but I would like some opinions first, especially after seeing this (#1528), which seems promising.
Anyway, Elastic APM is awesome. Thanks for the great work!