module ManageEngine module Instrumentation class RailsFramework def present? defined?(::Rails) && defined?(::ActionController) end def version Rails::VERSION::STRING end def env if Rails::VERSION::MAJOR >= 3 ::Rails.env else RAILS_ENV.dup end end def name 'Rails' end def instrument @obj = ManageEngine::APMObjectHolder.instance @obj.log.info "Instrumenting ActionController.. Rails Version: #{version}" ActiveSupport::Notifications.subscribe('start_processing.action_controller') do |name, start, finish, id, payload| if @obj.config.agent_enabled && @obj.txn_util.listen?(payload[:path]) url = "#{payload[:path]} #{payload[:controller]}##{payload[:action]}" railsTracker = ManageEngine::Tracker::RootTracker.new(url, start.to_f * 1000) Thread.current[:apminsight] = railsTracker end end # subscribe ActiveSupport::Notifications.subscribe('process_action.action_controller') do |name, start, finish, id, payload| tracker = Thread.current[:apminsight] if tracker != nil tracker.finish(finish.to_f * 1000) exception = payload[:exception_object] if exception != nil tracker.setError(exception) tracker.setStatus(500) # By default, set 500 as status for error txns end ManageEngine::APMObjectHolder.instance.collector.updateTransaction(tracker.name, tracker) Thread.current[:apminsight] = nil # Removing threadlocal end end end # def instrument end end end