Rails: getting logic to run at end of request, regardless of filter chain aborts?

Posted by JSW on Stack Overflow See other posts from Stack Overflow or by JSW
Published on 2010-05-10T05:43:26Z Indexed on 2010/05/10 6:14 UTC
Read the original article Hit count: 231

Is there a reliable mechanism discussed in rails documentation for calling a function at the end of the request, regardless of filter chain aborts?

It's not after filters, because after filters don't get called if any prior filter redirected or rendered.

For context, I'm trying to put some structured profiling/reporting information into the app log at the end of every request. This information is collected throughought the request lifetime via instance variables wrapped in custom controller accessors, and dumped at the end in a JSON blob for use by a post-processing script.

My end goal is to generate reports about my application's logical query distribution (things that depend on controller logic, not just request URIs and parameters), performance profile (time spent in specific DB queries or blocked on webservices), failure rates (including invalid incoming requests that get rejected by before_filter validation rules), and a slew of other things that cannot really be parsed from the basic information in the application and apache logs.

At a higher level, is there a different "rails way" that solves my app profiling goal?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about logging