Last active
April 5, 2018 18:27
-
-
Save jnjcub/f52755b1bd68cbe47cad62913512d366 to your computer and use it in GitHub Desktop.
How to get Instrumentation logs locally using Activesupport Notifications
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
jjacob~/Code/netflix/orion_api/src $ cat config/initializers/my_per_logger.rb | |
class InstrumentationLogger | |
MAX_DURATION = 3.0 | |
def self.initialize! | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload| | |
duration =( (finish.to_f - start.to_f) * 1000).round(2) | |
Rails.logger.info("slow query detected: #{payload[:name]}, duration: #{duration}") | |
end | |
ActiveSupport::Notifications.subscribe('instantiation.active_record') do |name, start, finish, id, payload| | |
duration =( (finish.to_f - start.to_f) * 1000).round(2) | |
Rails.logger.info("Instantiation of : #{payload[:class_name]}, Record Count # #{payload[:record_count]} duration: #{duration} ms") | |
end | |
end | |
end | |
InstrumentationLogger.initialize! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment