Sha256: be704a5ac4c4b2d27145b6096fc3041489dec745de263c7be993e732da5368ce

Contents?: true

Size: 1.6 KB

Versions: 97

Compression:

Stored size: 1.6 KB

Contents

module ScoutApm
  module Remote
    class Recorder
      attr_reader :logger
      attr_reader :remote_agent_host
      attr_reader :remote_agent_port

      def initialize(remote_agent_host, remote_agent_port, logger)
        @remote_agent_host = remote_agent_host
        @remote_agent_port = remote_agent_port
        @logger = logger
      end

      def start
        # nothing to do
        self
      end

      def stop
        # nothing to do
      end

      def record!(request)
        begin
          t1 = Time.now
          # Mark this request as recorded, so the next lookup on this thread, it
          # can be recreated
          request.recorded!

          # Only send requests that we actually want. Incidental http &
          # background thread stuff can just be dropped
          unless request.job? || request.web?
            return
          end

          request.prepare_to_dump!
          message = ScoutApm::Remote::Message.new('record', 'record!', request)
          encoded = message.encode
          logger.debug "Remote Agent: Posting a message of length: #{encoded.length}"
          post(encoded)
          t2 = Time.now

          logger.debug("Remote Recording took: #{t2.to_f - t1.to_f} seconds")
        rescue => e
          logger.debug "Remote: Error while sending to collector: #{e.inspect}, #{e.backtrace.join("\n")}"
        end
      end

      def post(encoded_message)
        http = Net::HTTP.new(remote_agent_host, remote_agent_port)
        request = Net::HTTP::Post.new("/users")
        request.body = encoded_message
        response = http.request(request)
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
scout_apm-5.6.1 lib/scout_apm/remote/recorder.rb
scout_apm-5.6.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.5.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.4.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.8 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.7 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.5 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.3 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.2 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.1 lib/scout_apm/remote/recorder.rb
scout_apm-5.3.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.2.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.1.1 lib/scout_apm/remote/recorder.rb
scout_apm-5.1.0 lib/scout_apm/remote/recorder.rb
scout_apm-5.0.0 lib/scout_apm/remote/recorder.rb
scout_apm-4.1.2 lib/scout_apm/remote/recorder.rb
scout_apm-4.1.1 lib/scout_apm/remote/recorder.rb
scout_apm-4.1.0 lib/scout_apm/remote/recorder.rb
scout_apm-4.0.4 lib/scout_apm/remote/recorder.rb
scout_apm-4.0.3 lib/scout_apm/remote/recorder.rb