Method: NewRelic::Agent::NewRelicService#session

Defined in:
lib/new_relic/agent/new_relic_service.rb

#session(&block) ⇒ Object

One session with the service’s endpoint. In this case the session represents 1 tcp connection which may transmit multiple HTTP requests via keep-alive.

Raises:

  • (ArgumentError)
[View source]

239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/new_relic/agent/new_relic_service.rb', line 239

def session(&block)
  raise ArgumentError, "#{self.class}#shared_connection must be passed a block" unless block

  begin
    t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    @in_session = true
    if NewRelic::Agent.config[:aggressive_keepalive]
      session_with_keepalive(&block)
    else
      session_without_keepalive(&block)
    end
  rescue *CONNECTION_ERRORS => e
    elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0
    raise NewRelic::Agent::ServerConnectionException, "Recoverable error connecting to #{@collector} after #{elapsed} seconds: #{e}"
  ensure
    @in_session = false
  end
end