proxy-chain icon indicating copy to clipboard operation
proxy-chain copied to clipboard

Feature Request: Emit `requestFinished` Event for Per-Request Bandwidth Tracking

Open shresthaoshan opened this issue 7 months ago • 7 comments

Currently, the library emits a connectionClosed event, which is helpful for tracking the overall bandwidth usage of a socket connection. However, in many real-world scenarios involving persistent connections (e.g., HTTP keep-alive), it's valuable to monitor bandwidth usage on a per-request basis.

Feature Request

I’d like to propose adding support for a new event, requestFinished, which would be emitted at the end of each individual HTTP/HTTPS request-response cycle.

While precise per-request bandwidth usage may not be trivial to isolate due to socket reuse, this event would still provide:

  • A time-based approximation of bandwidth usage across requests.
  • Insight into request frequency, response size patterns, and endpoint behavior.
  • A hook for logging, monitoring, or quota management per request.

Why This Matters

Tracking only at the socket level can obscure usage spikes or performance anomalies associated with individual requests—especially under connection pooling or when clients reuse a single proxy connection.

shresthaoshan avatar Jul 20 '25 03:07 shresthaoshan

Thanks for the feature request! We're placing this into our backlog. We expect more capacity to be invested into proxy so there is a good chance we'll look into this soon.

tobice avatar Jul 30 '25 09:07 tobice

Ah, sorry, I can see you have already sent a PR. We'll take a look 👍

tobice avatar Jul 30 '25 09:07 tobice

The PR was closed because of no activity, should I look into it?

lewis-wow avatar Sep 18 '25 10:09 lewis-wow

I'd say go ahead. The no activity is probably on us 😄

tobice avatar Sep 18 '25 10:09 tobice

cc @bliuchak

jancurn avatar Sep 18 '25 10:09 jancurn

We're having some diffulties with running tests. We're gonna take a look at it.

bliuchak avatar Sep 25 '25 09:09 bliuchak

Since the tests weren't working locally, we've set up a Docker environment for them. I can now run the tests and review the changes.

lewis-wow avatar Oct 06 '25 12:10 lewis-wow