Skip to content

Instantly share code, notes, and snippets.

@babney
Created May 27, 2015 20:50
Show Gist options
  • Save babney/f6a1fe75817bf746fb80 to your computer and use it in GitHub Desktop.
Save babney/f6a1fe75817bf746fb80 to your computer and use it in GitHub Desktop.
Log a stack trace for every transaction... action. Only for Mysql2adapter, could be fixed to work for others.
module TransactionScreamer
def begin_db_transaction
Rails.logger.debug "DB TRANSACTION STARTS"
Rails.logger.debug caller.join("\n")
super
end
def commit_db_transaction
Rails.logger.debug "DB TRANSACTION ENDS"
Rails.logger.debug caller.join("\n")
super
end
def rollback_db_transaction
Rails.logger.debug "DB TRANSACTION ROLLBACK"
Rails.logger.debug caller.join("\n")
super
end
end
# uncomment the following line to see stack traces every time a transaction
# starts, is committed, or rolls back
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :prepend, TransactionScreamer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment