Easily record and emit Server-Timing headers in your Rack applications.
Add this line to your application's Gemfile:
gem "rack-server-timing"
And then execute:
$ bundle
Or install it yourself as:
$ gem install rack-server-timing
Simply require and add middleware:
# config.ru
require "rack-server-timing/middleware"
use RackServerTiming::Middleware
run ->(env) {
[200, {}, ["It Works!"]]
}
And then record your metrics:
env["rack.server_timing"].record("DB", 200)
Enable the plugin server_timing
after render
(if you wish to have the rendering profiled automatically).
class App < Roda
plugin :render # Optional
plugin :server_timing
end
A convenient server_timing
helper is available to quickly record
or benchmark
timing values.
Enable the server_timing
extension in your database instance. This extension will automatically create a
null logging instance if there is no logging configured so there may be a small performance hit.
DB = Sequel.connect
DB.extension :server_timing
Bug reports and pull requests are welcome on GitHub at https://github.com/adam12/rack-server-timing.
I love pull requests! If you fork this project and modify it, please ping me to see if your changes can be incorporated back into this project.
That said, if your feature idea is nontrivial, you should probably open an issue to discuss it before attempting a pull request.
The gem is available as open source under the terms of the MIT License.