lib/agent/server/instrument/rails.rb in site24x7_apminsight-1.5.3 vs lib/agent/server/instrument/rails.rb in site24x7_apminsight-1.6.0

- old
+ new

@@ -1,5 +1,7 @@ +require 'agent/handler/tracker_handler' + module ManageEngine module Instrumentation class RailsFramework def present? @@ -23,31 +25,28 @@ end def instrument @obj = ManageEngine::APMObjectHolder.instance @obj.log.info "Instrumenting ActionController.. Rails Version: #{version}" + @railsTracker = nil ActiveSupport::Notifications.subscribe('start_processing.action_controller') do |name, start, finish, id, payload| path = payload[:path].partition("?")[0] - if @obj.config.agent_enabled && @obj.txn_util.listen?(path) - url = "#{path} #{payload[:controller]}##{payload[:action]}" - railsTracker = ManageEngine::Tracker::RootTracker.new(url, start.to_f * 1000) - Thread.current[:apminsight] = railsTracker - end + @railsTracker = ManageEngine::Tracker::RootTracker.new("#{payload[:controller]}.#{payload[:action]}", start.to_f * 1000) + @railsTracker.url=(path) + @railsTracker = ManageEngine::Agent::TrackerHandler.invokeTracker(@railsTracker) 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) + if @railsTracker != nil + @railsTracker.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 + @railsTracker.setError(exception) + @railsTracker.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 + ManageEngine::Agent::TrackerHandler.exitTracker(@railsTracker) end end end # def instrument \ No newline at end of file