class TingYun::Agent::Collector::ErrorTraceArray

Public Class Methods

new(capacity) click to toggle source
# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 9
def initialize(capacity)
  @capacity = capacity
  @lock = Mutex.new
  @errors = []
end

Public Instance Methods

add_to_error_queue(noticed_error) click to toggle source

Synchronizes adding an error to the error queue, and checks if the error queue is too long - if so, we drop the error on the floor after logging a warning.

# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 48
def add_to_error_queue(noticed_error)
  return unless enabled?
  @lock.synchronize do
    if !over_queue_limit?(noticed_error.message) && !@errors.include?(noticed_error)
      @errors << noticed_error
    end
  end
end
enabled?() click to toggle source
# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 17
def enabled?
  ::TingYun::Agent.config[:'nbs.error_collector.enabled']
end
harvest!() click to toggle source

Get the errors currently queued up. Unsent errors are left over from a previous unsuccessful attempt to send them to the server.

# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 37
def harvest!
  @lock.synchronize do
    errors = @errors
    @errors = []
    errors
  end
end
merge!(errors) click to toggle source
# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 21
def merge!(errors)
  errors.each do |error|
    add_to_error_queue(error)
  end
end
notice_agent_error(exception) click to toggle source

see TingYun::Agent::Instance.error_collector.notice_agent_error

# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 69
def notice_agent_error(exception)
  return unless exception.class < TingYun::Support::Exception::InternalAgentError

  TingYun::Agent.logger.info(exception)

  @lock.synchronize do
    return if @errors.any? { |err| err.exception_class_name == exception.class.name }

    trace = exception.backtrace || caller.dup
    noticed_error = TingYun::Agent::Collector::NoticedError.new("TingYun/AgentError", exception)
    noticed_error.stack_trace = trace
    @errors << noticed_error
  end
rescue => e
  TingYun::Agent.logger.info("Unable to capture internal agent error due to an exception:", e)
end
over_queue_limit?(message) click to toggle source

checks the size of the error queue to make sure we are under the maximum limit, and logs a warning if we are over the limit.

# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 60
def over_queue_limit?(message)
  over_limit = (@errors.reject { |err| err.is_internal }.length >= @capacity)
  if over_limit
    ::TingYun::Agent.logger.warn("The error reporting queue has reached #{@capacity}. The error detail for this and subsequent errors will not be transmitted to TingYun  until the queued errors have been sent: #{message}")
  end
  over_limit
end
reset!() click to toggle source
# File lib/ting_yun/agent/collector/error_collector/error_trace_array.rb, line 28
def reset!
  @lock.synchronize do
    @errors = []
  end
end