Git Product home page Git Product logo

production_rails's Introduction

Production Rails

Best practices for running Rails in production.

Disclaimer: ๐Ÿ’Ž indicates one of my gems

Security

Everyone writing code must be responsible for security. Best practices

Analytics

Use an analytics service like Google Analytics or Mixpanel.

And possibly an open source library like Ahoy. ๐Ÿ’Ž

Logging

Use Lograge.

gem 'lograge'

Add the following to config/environments/production.rb.

config.lograge.enabled = true
config.lograge.custom_options = lambda do |event|
  options = event.payload.slice(:request_id, :user_id, :visit_id)
  options[:params] = event.payload[:params].except("controller", "action")
  options
end

Add the following to app/controllers/application_controller.rb.

def append_info_to_payload(payload)
  super
  payload[:request_id] = request.uuid
  payload[:user_id] = current_user.id if current_user
  payload[:visit_id] = ahoy.visit_id # if you use Ahoy
end

Audits

Use an auditing library like Audited.

Errors

Use an error reporting service like Rollbar.

Monitoring

What to Monitor

Web Requests
  • requests by action - total time, count
  • queue time - X-Request-Start header
Background Jobs and Rake Tasks
  • jobs by type - total time, count
Data Stores - Database, Elasticsearch, Redis
  • requests by type - total time, count
  • CPU usage
  • space
External Services
  • requests by type - total time, count

Notable Events

Use Notable to track notable requests and background jobs. ๐Ÿ’Ž

  • errors
  • slow requests, jobs, and timeouts
  • 404s
  • validation failures
  • CSRF failures
  • unpermitted parameters
  • blocked and throttled requests

Timeouts

Add timeouts.

Add them to:

Performance

Development Bonus

If you experience double logging in the Rails console, create config/initializers/logger.rb with:

ActiveSupport::Logger.class_eval do
  def self.broadcast(logger)
    Module.new do
    end
  end
end

Lastly...

Have suggestions? Help make this guide better for everyone.

If you use Heroku, check out Rails on Heroku.

production_rails's People

Contributors

ankane avatar

Watchers

James Cloos avatar xiajian avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.