Custom benchmarking - problems monkey patching perform_actio

I would like to override
ActionController::Benchmarking.perform_action_with_benchmark method so
that custom application-layer information is logged alongside render
and DB times in the production.log. I’ve tried monkey-patching, but
for some reason, it doesn’t seem to work. I can define new methods in
the ActionController::Benchmarking, but if I override
perform_action_with_benchmark my changes are ignored.

Here’s what I’ve got in
vendor/plugins/benchmark_enhancements/lib/benchmark_enhancements.rb:

module ActionController #:nodoc:
module Benchmarking #:nodoc:
def perform_action_with_benchmark
unless logger
perform_action_without_benchmark
else
runtime = [Benchmark::measure{ perform_action_without_benchmark
}.real, 0.0001].max
log_message = “Completed in #{sprintf(”%.5f", runtime)} (#{(1
/ runtime).floor} reqs/sec)"
log_message << rendering_runtime(runtime) if @rendering_runtime
log_message << active_record_runtime(runtime) if
Object.const_defined?(“ActiveRecord”) && ActiveRecord::Base.connected?
log_message << custom_runtime(runtime)
log_message << " | #{headers[“Status”]}"
log_message << " [#{complete_request_uri rescue “unknown”}]"
logger.info(log_message)
end
end

def custom_runtime(runtime)
  " | Custom: #{sprintf("%.5f", rand)}"
end

end
end

I can verify that custom_runtime exists, so the file is being read, but
it never gets invoked. It works if I edit the gem version of
benchmark.rb, but it doesn’t work if I monkey patch under
vendor/plugins.

Any ideas?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs