class OneApm::Agent::Threading::AgentThread

Public Class Methods

backing_thread_class() click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 62
def backing_thread_class
  @backing_thread_class
end
backing_thread_class=(clazz) click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 66
def backing_thread_class=(clazz)
  @backing_thread_class = clazz
end
bucket_thread(thread, profile_agent_code) click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 36
def bucket_thread(thread, profile_agent_code)
  if thread.key?(:oneapm_label)
    profile_agent_code ? :agent : :ignore
  else
    state = TransactionState.tl_state_for(thread)
    if state.in_background_transaction?
      :background
    elsif state.in_web_transaction?
      :request
    else
      :other
    end
  end
end
create(label, &blk) click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 12
def create(label, &blk)
  OneApm::Manager.logger.debug("Creating OneApm thread: #{label}")
  wrapped_blk = Proc.new do
    begin
      blk.call
    rescue => e
      OneApm::Manager.logger.error("Thread #{label} exited with error", e)
    rescue Exception => e
      OneApm::Manager.logger.error("Thread #{label} exited with exception. Re-raising in case of interupt.", e)
      raise
    ensure
      OneApm::Manager.logger.debug("Exiting OneApm thread: #{label}")
    end
  end

  thread = backing_thread_class.new(&wrapped_blk)
  thread[:oneapm_label] = label
  thread
end
list() click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 32
def list
  backing_thread_class.list
end
scrub_backtrace(thread, profile_agent_code) click to toggle source
# File lib/one_apm/agent/threading/agent_thread.rb, line 51
def scrub_backtrace(thread, profile_agent_code)
  begin
    bt = thread.backtrace
  rescue Exception => e
    OneApm::Manager.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
  end
  return nil unless bt
  bt.reject! { |t| t.include?('one_apm') } unless profile_agent_code
  bt
end