Class: NewRelic::Agent::Threading::AgentThread
- Inherits:
-
Object
- Object
- NewRelic::Agent::Threading::AgentThread
- Defined in:
- lib/new_relic/agent/threading/agent_thread.rb
Class Method Summary collapse
- .backing_thread_class ⇒ Object
- .backing_thread_class=(clazz) ⇒ Object
-
.bucket_thread(thread, profile_agent_code) ⇒ Object
THREAD_LOCAL_ACCESS.
- .create(label, &blk) ⇒ Object
-
.list ⇒ Object
Simplifies testing if we don’t directly use ::Thread.list, so keep the accessor for it here on AgentThread to use and stub.
- .scrub_backtrace(thread, profile_agent_code) ⇒ Object
Class Method Details
.backing_thread_class ⇒ Object
72 73 74 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 72 def self.backing_thread_class @backing_thread_class end |
.backing_thread_class=(clazz) ⇒ Object
76 77 78 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 76 def self.backing_thread_class=(clazz) @backing_thread_class = clazz end |
.bucket_thread(thread, profile_agent_code) ⇒ Object
THREAD_LOCAL_ACCESS
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 39 def self.bucket_thread(thread, profile_agent_code) # THREAD_LOCAL_ACCESS if thread.key?(:newrelic_label) profile_agent_code ? :agent : :ignore else state = Tracer.state_for(thread) txn = state.current_transaction if txn && !txn.recording_web_transaction? :background elsif txn&.recording_web_transaction? :request else :other end end end |
.create(label, &blk) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 9 def self.create(label, &blk) ::NewRelic::Agent.logger.debug("Creating AgentThread: #{label}") wrapped_blk = proc do if ::Thread.current[:newrelic_tracer_state] && Thread.current[:newrelic_tracer_state].current_transaction txn = ::Thread.current[:newrelic_tracer_state].current_transaction ::NewRelic::Agent.logger.warn("AgentThread created with current transaction #{txn.best_name}") end begin yield rescue => e ::NewRelic::Agent.logger.error("AgentThread #{label} exited with error", e) rescue Exception => e ::NewRelic::Agent.logger.error("AgentThread #{label} exited with exception. Re-raising in case of interrupt.", e) raise ensure ::NewRelic::Agent.logger.debug("Exiting AgentThread: #{label}") end end thread = nil NewRelic::Agent.disable_all_tracing { thread = backing_thread_class.new(&wrapped_blk) } thread[:newrelic_label] = label thread end |
.list ⇒ Object
Simplifies testing if we don’t directly use ::Thread.list, so keep the accessor for it here on AgentThread to use and stub.
35 36 37 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 35 def self.list backing_thread_class.list end |
.scrub_backtrace(thread, profile_agent_code) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/new_relic/agent/threading/agent_thread.rb', line 56 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 bt.reject! { |t| t.include?('/newrelic_rpm-') } unless profile_agent_code bt end |