Instruments enables out-of-the-box instrumentation on database & HTTP activities.
Provide an object that will take a hash as an argument.
Instruments.set_logger(Kernel, :puts)require "sinatra"
require "instruments"
instrument_routes
Instruments.set_logger(Kernel, :puts)
get "/hello/:name" do
  "hello #{params[:name]}"
endNow when you hit this endpoint, you will see the following in your log stream:
action="http-request" method="get" route="/hello/:name" status=200 elapsed=0.001
require "sequel"
require "instruments"
instrument_routes
Instruments.set_logger(Kernel, :puts)
DB.loggers << Logger.new($stdout) #sequel requires this :(
DB.class.send(:include, Sequel::Instrumentation)
DB[:events].countWill produce:
action=select elapsed_time=0.1 sql="select count(*) from events"
- rest-client
 - queue_classic
 - redis
 
- @konstantinhaase
 - @mmcgrana
 - @nzoschke
 - @jeremyevans
 
Neat!
A few comments:
select * from events where data->'password' = $1, so that queries are normalized and don't contain sensitive information?method=getin the Sinatra web logs?elapsed_timekey is pretty verbose - have you considered justelapsed?{:level => "debug", ..., which terminal logging clients can either chose to emit as data (level=debug), in a special cased way ([DEBUG] foo=bar), or not at all based on the level itself.release=v273 deploy=production. For this a single interface is most convenient:Insturments.logger = MyApp.method(:log). See here and here for an example of this inflation pattern.