Class: NewRelic::Agent::AgentThread

Inherits:
Thread
  • Object
show all
Defined in:
lib/new_relic/agent/thread.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label) ⇒ AgentThread

Returns a new instance of AgentThread.



9
10
11
12
13
# File 'lib/new_relic/agent/thread.rb', line 9

def initialize(label)
  ::NewRelic::Agent.logger.debug("Creating New Relic thread: #{label}")
  self[:newrelic_label] = label
  super
end

Class Method Details

.bucket_thread(thread, profile_agent_code) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/new_relic/agent/thread.rb', line 15

def self.bucket_thread(thread, profile_agent_code)
  if thread.key?(:newrelic_label)
    return profile_agent_code ? :agent : :ignore
  elsif thread[:newrelic_transaction].respond_to?(:last) &&
      thread[:newrelic_transaction].last
    thread[:newrelic_transaction].last.request.nil? ? :background : :request
  else
    :other
  end
end

.scrub_backtrace(thread, profile_agent_code) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/new_relic/agent/thread.rb', line 26

def self.scrub_backtrace(thread, profile_agent_code)
  begin
    bt = thread.backtrace
  rescue Exception => e
    ::NewRelic::Agent.logger.debug("Failed to backtrace #{thread.inspect}: #{e.class.name}: #{e.to_s}")
  end
  return nil unless bt
  profile_agent_code ? bt : bt.select { |t| t !~ /\/newrelic_rpm-\d/ }
end