Sha256: 4f5bb901105931ef6dc88469aaf08e7cb5b0b321c00d39c16f71873d51cda17c

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

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|
          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
        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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
site24x7_apminsight-1.5.3 lib/agent/server/instrument/rails.rb
site24x7_apminsight-1.5.2 lib/agent/server/instrument/rails.rb