Saturday, 31 August 2013

How to capture size of an API response in Rails?

How to capture size of an API response in Rails?

I want to capture the size of responses being made by the API of my Rails
3 app.
The idea is that if a client application requests a resource, the full
size of the JSON response (in KB/MB, after RABL renders it) can be
captured and stored, so that I can see how much data the client
application is using later. Because they are exceptionally large, some of
these API JSON responses are cached (locally for now, on Redis in the near
future), so the solution needs to be able to capture the size of cached
responses, not just rendered ones.
What is the best method and place for accomplishing this in Rails? On the
Rack level? In the controller (the controllers use
ActionController::Metal)? Obviously, the less overhead this puts on
response times, the better.

No comments:

Post a Comment