class PhusionPassenger::ActiveSupport3Extensions::AnalyticsLogging

Public Class Methods

install!(options, user_options) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 41
def self.install!(options, user_options)
        analytics_logger = options["analytics_logger"]
        app_group_name = options["app_group_name"]
        return false if !analytics_logger || !options["analytics"]
        
        # If the Ruby interpreter supports GC statistics then turn it on
        # so that the info can be logged.
        GC.enable_stats if GC.respond_to?(:enable_stats)
        
        subscriber = self.new(user_options)
        AnalyticsLogging.attach_to(:action_controller, subscriber)
        AnalyticsLogging.attach_to(:active_record, subscriber)
        if defined?(ActiveSupport::Cache::Store)
                ActiveSupport::Cache::Store.instrument = true
                AnalyticsLogging.attach_to(:active_support, subscriber)
        end
        PhusionPassenger.on_event(:starting_request_handler_thread) do
                if defined?(ActiveSupport::Cache::Store)
                        # This flag is thread-local.
                        ActiveSupport::Cache::Store.instrument = true
                end
        end
        
        if defined?(ActionDispatch::DebugExceptions)
                exceptions_middleware = ActionDispatch::DebugExceptions
        elsif defined?(ActionDispatch::ShowExceptions)
                exceptions_middleware = ActionDispatch::ShowExceptions
        end
        if exceptions_middleware
                if defined?(Rails)
                        Rails.application.middleware.insert_after(
                                exceptions_middleware,
                                ExceptionLogger, analytics_logger, app_group_name)
                end
        end
        
        if defined?(ActionController::Base)
                ActionController::Base.class_eval do
                        include ACExtension
                end
        end
        
        if defined?(ActiveSupport::Benchmarkable)
                ActiveSupport::Benchmarkable.class_eval do
                        include ASBenchmarkableExtension
                        alias_method_chain :benchmark, :passenger
                end
        end
        
        return true
end
new(options) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 93
def initialize(options)
        install_event_preprocessor(options[:event_preprocessor]) if options[:event_preprocessor]
end

Public Instance Methods

cache_fetch_hit(event) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 123
def cache_fetch_hit(event)
        PhusionPassenger.log_cache_hit(nil, event.payload[:key])
end
cache_generate(event) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 127
def cache_generate(event)
        PhusionPassenger.log_cache_miss(nil, event.payload[:key],
                event.duration * 1000)
end
cache_read(event) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 115
def cache_read(event)
        if event.payload[:hit]
                PhusionPassenger.log_cache_hit(nil, event.payload[:key])
        else
                PhusionPassenger.log_cache_miss(nil, event.payload[:key])
        end
end
process_action(event) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 97
def process_action(event)
        log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
        if log
                view_runtime = event.payload[:view_runtime]
                log.message("View rendering time: #{(view_runtime * 1000).to_i}") if view_runtime
        end
end
sql(event) click to toggle source
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 105
def sql(event)
        if log = Thread.current[PASSENGER_ANALYTICS_WEB_LOG]
                name = event.payload[:name] || "SQL"
                sql = event.payload[:sql]
                digest = Digest::MD5.hexdigest("#{name}\00##{sql}\00##{rand}")
                log.measured_time_points("DB BENCHMARK: #{digest}",
                        event.time, event.end, "#{name}\n#{sql}")
        end
end

Private Instance Methods

install_event_preprocessor(event_preprocessor) click to toggle source
Calls superclass method
# File lib/phusion_passenger/active_support3_extensions/init.rb, line 226
def install_event_preprocessor(event_preprocessor)
        public_methods(false).each do |name|
                singleton = class << self; self end
                singleton.send(:define_method, name, lambda do |event|
                        event_preprocessor.call(event)
                        super(event)
                end)
        end
end