0.15
No commit activity in last 3 years
No release in over 3 years
View server-side performance metrics in your browser.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0

Runtime

 Project Readme

Server Timing Response Headers for Rails

Bring Ruby on Rails server-side performance metrics 📈 to Chrome's Developer Tools (and other browsers that support the Server Timing API) via the server_timing gem. Production Safe™.

Metrics are collected from the scout_apm gem. A Scout account is not required.

server timing screenshot

Gem Installation

Add this line to your application's Gemfile:

gem 'server_timing'

And then execute:

$ bundle

Configuration

A minimal Scout config file is required. The server_timing gem reports metrics collected by the scout_apm gem (added as a dependency of server_timing).

If you don't have a Scout account, copy and paste the following minimal configuration into a RAILS_ROOT/config/scout_apm.yml file:

common: &defaults
  monitor: true

production:
  <<: *defaults

If you have a Scout account, no extra configuration is required. If you wish to see server timing metrics in development, ensure monitor: true is set for the development environment in the scout_apm.yml file.

See the scout_apm configuration reference for more information.

Browser Support

  • Chrome 65+ (Chrome 64 uses an old format of the server timing headers. This isn't supported by the gem).
  • Firefox 59+
  • Opera 52+

Instrumentation

Auto-Instrumentation

By default, the total time consumed by each of the libraries scout_apm instruments is reported. This includes ActiveRecord, HTTP, Redis, and more. View the full list of supported libraries.

Custom Instrumentation

Collect performance data on additional method calls by adding custom instrumentation via scout_apm. See the docs for instructions.

Security

  • Non-Production Environments (ex: development, staging) - Server timing response headers are sent by default.
  • Production - The headers must be enabled.

Response headers can be enabled in production by calling ServerTiming::Auth.ok!:

# app/controllers/application_controller.rb

before_action do
  if current_user && current_user.admin?
    ServerTiming::Auth.ok!
  end
end

To only enable response headers in development and for admins in production:

# app/controllers/application_controller.rb

before_action do
  if current_user && current_user.admin?
    ServerTiming::Auth.ok!
  elsif Rails.env.development?
    ServerTiming::Auth.ok!
  else
    ServerTiming::Auth.deny!
  end
end

Overhead

The scout_apm gem, a dependency of server_timing, applies low overhead instrumentation designed for production use.

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/scoutapp/ruby_server_timing.

License

The gem is available as open source under the terms of the MIT License.