Call Stacking

Debugging in Production with Ruby on Rails

Debugging a Ruby on Rails application in production can be challenging due to the complexity of the stack and the live environment. However, there are several strategies that can help you effectively debug your application and identify and fix issues.

  1. Remember for Ruby, classes are open. You can rewrite the implementation of a class method, to add additional logging. You can do this right from the console. And then rerun the offending method with the modified class to gain additional context.

    Go from this:
    class Greeting
      def self.hello(greeting)
        puts greeting
      end
    end

    To this:
    class Greeting
      def self.hello(greeting)
        Rails.logger.info("Greeting: #{greeting}")
        puts greeting
      end
    end
  2. Use Rails Logging: Rails provides detailed logging for all requests made to your application. This can be extremely useful for identifying issues, as it provides information on the request, response, and any errors that may have occurred.
  3. Use Third-Party Tools: There are several third-party tools that can be used to help debug Ruby on Rails applications in production. Some popular tools include New Relic, Airbrake, and Rollbar. These tools provide detailed error tracking and reporting, as well as performance monitoring and analysis.
  4. Monitor Performance: Performance issues can often be caused by slow database queries, memory leaks, or other performance bottlenecks. It's important to monitor the performance of your application, and to identify and fix any issues that may be causing performance problems.
  5. Use Staging and Test Environments: Having a staging and test environment can help you identify and fix issues before they occur in production. By testing your application in a controlled environment, you can identify and fix any issues that may arise in production.
Ruby on Rails, Debugging in Production Ruby on Rails, Existing Debugging Tools