Class: ScoutApm::Remote::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/remote/recorder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_agent_host, remote_agent_port, logger) ⇒ Recorder

Returns a new instance of Recorder.



8
9
10
11
12
# File 'lib/scout_apm/remote/recorder.rb', line 8

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

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



4
5
6
# File 'lib/scout_apm/remote/recorder.rb', line 4

def logger
  @logger
end

#remote_agent_hostObject (readonly)

Returns the value of attribute remote_agent_host.



5
6
7
# File 'lib/scout_apm/remote/recorder.rb', line 5

def remote_agent_host
  @remote_agent_host
end

#remote_agent_portObject (readonly)

Returns the value of attribute remote_agent_port.



6
7
8
# File 'lib/scout_apm/remote/recorder.rb', line 6

def remote_agent_port
  @remote_agent_port
end

Instance Method Details

#post(encoded_message) ⇒ Object



49
50
51
52
53
54
# File 'lib/scout_apm/remote/recorder.rb', line 49

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

#record!(request) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scout_apm/remote/recorder.rb', line 23

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

#startObject



14
15
16
17
# File 'lib/scout_apm/remote/recorder.rb', line 14

def start
  # nothing to do
  self
end

#stopObject



19
20
21
# File 'lib/scout_apm/remote/recorder.rb', line 19

def stop
  # nothing to do
end