lib/agent/server/instrument/rails.rb in site24x7_apminsight-1.9.2 vs lib/agent/server/instrument/rails.rb in site24x7_apminsight-1.9.3
- old
+ new
@@ -25,28 +25,37 @@
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]
- @railsTracker = ManageEngine::Tracker::RootTracker.new("#{payload[:controller]}.#{payload[:action]}", start.to_f * 1000)
- @railsTracker.url=(path)
- @railsTracker = ManageEngine::Agent::TrackerHandler.invokeTracker(@railsTracker)
+ result = payload[:path].partition("?")
+ railsTracker = ManageEngine::Tracker::RootTracker.new("#{payload[:controller]}.#{payload[:action]}", start.to_f * 1000)
+ railsTracker.url=(result[0])
+ railsTracker.queryString(result[2]) # even if value not available empty string will be returned
+ railsTracker.http_method(payload[:method])
+ railsTracker.http_params(payload[:params])
+
+ railsTracker = ManageEngine::Agent::TrackerHandler.invokeTracker(railsTracker)
+ Thread.current[:railsTracker] = railsTracker
end # subscribe
ActiveSupport::Notifications.subscribe('process_action.action_controller') do |name, start, finish, id, payload|
- if @railsTracker != nil
- @railsTracker.finish(finish.to_f * 1000)
- exception = payload[:exception_object]
- if exception != nil
- @railsTracker.setError(exception)
- @railsTracker.setStatus(500) # By default, set 500 as status for error txns
+ begin
+ railsTracker = Thread.current[:railsTracker]
+ if (railsTracker != nil)
+ railsTracker.finish(finish.to_f * 1000)
+ railsTracker.setStatus(payload[:status])
+ exception = payload[:exception_object]
+ if exception != nil
+ railsTracker.setError(exception)
+ end
+ ManageEngine::Agent::TrackerHandler.exitTracker(railsTracker)
end
- ManageEngine::Agent::TrackerHandler.exitTracker(@railsTracker)
+ rescue Exception=>e
+ @obj.log.logException("Unable to process controller event #{name}. Exception: " ,e)
end
end
end # def instrument
\ No newline at end of file