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.



5
6
7
8
9
# File 'lib/new_relic/agent/thread.rb', line 5

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



11
12
13
14
15
16
17
18
19
# File 'lib/new_relic/agent/thread.rb', line 11

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

.scrub_backtrace(thread, profile_agent_code) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/new_relic/agent/thread.rb', line 21

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