-
-
Save thisismydesign/3cb3f48a7cd67f26d17b35f1420b4517 to your computer and use it in GitHub Desktop.
Rails: slow query logging instrumentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, start, finish, _id, payload| | |
duration = finish.to_f - start.to_f | |
if duration >= 1.0 # Feel free to change | |
Rails.logger.warn "slow query detected: #{payload[:sql]}, duration: #{duration}" | |
caller.each do |line| | |
next unless line.include? Dir.pwd | |
Rails.logger.warn line | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment