5 minute read At Shopify we frequently need to debug production Rails problems. Adding extra debugging code takes time to write and deploy, so we’ve learned how to use tools like gdb and rbtrace to quickly track down these issues. In this post, we’ll explain how to use gdb to retrieve a Ruby call stack, inspect environment variables, and debug a really odd warning message in production. We recently ran into an issue where we were seeing a large number of similar warning messages spamming our log files: /artifacts/ruby/2.1.0/gems/rack-1.6.4/lib/rack/utils.rb:92: warning: regexp match /.../n against to UTF-8 string This means we are trying to match an ASCII regular expression on a UTF-8 source string.
Overview
The article discusses effective strategies for debugging production issues in Rails applications at Shopify, focusing on the use of tools like gdb and rbtrace. It highlights a specific case of handling UTF-8 warnings generated by the Rack library and the steps taken to resolve the issue without impacting production traffic.
What You'll Learn
How to use gdb to retrieve a Ruby call stack in production
Why using breakpoints in gdb can help debug Ruby applications effectively
How to suppress Ruby warnings in production without modifying the application code
Prerequisites & Requirements
- Understanding of Ruby and Rails debugging techniques
- Familiarity with gdb and rbtrace(optional)
Key Questions Answered
How can gdb be used to debug Ruby applications in production?
What causes UTF-8 warnings in Ruby applications?
What steps can be taken to suppress Ruby warnings in production?
Key Statistics & Figures
Technologies & Tools
Key Actionable Insights
1Utilize gdb for debugging production issues without deploying new code.By attaching gdb to an idle Unicorn worker, you can analyze the application state in real-time, which minimizes the risk of impacting user requests.
2Implement breakpoints strategically to capture relevant stack traces.Setting breakpoints at critical points in the code allows for detailed inspection of the call stack, helping to identify the source of issues effectively.
3Consider monkey patching as a temporary solution for suppressing warnings.While not a permanent fix, monkey patching can reduce log noise and allow developers to focus on critical issues without distraction.