Worker Logging, Bytes Sent
I am trying to troubleshoot a worker and need to know how many bytes was sent for each request, especially when the request is canceled by the client. I am trying to implement some debugging g logging in hono middleware, and cannot find a way to either get the info from Cloudflare, or make some sort of “proxy” stream to capture bytes read before client disconnects. I tried going with TransformStream as intermediary, but get “Body has already been used. It can only be used once. Use tee() first if you need to read it twice.” exception. Any advice how to know per request bytes sent in hono worker?
1 Reply
You should be able to find the number of bytes in the
content-length
header, and if compressed, the number of bytes transmitted in the transfer-length
header for the request. Although if you don't trust the values, for debugging, here's a script that should (I'm just writing it here on discord, so some minor issues might need to be fixed)
Ps. instead of tee()-ing, I cloned them, but it's basically the same, just with a less confusing syntax
Hope this helps!