Module: NewRelic::Agent::StatsEngine::Transactions
- Included in:
- NewRelic::Agent::StatsEngine
- Defined in:
- lib/new_relic/agent/stats_engine/transactions.rb
Overview
Handles pushing and popping elements onto an internal stack that tracks where time should be allocated in Transaction Traces
Defined Under Namespace
Modules: Shim
Instance Method Summary collapse
-
#end_transaction ⇒ Object
Try to clean up gracefully, otherwise we leave things hanging around on thread locals.
-
#pop_scope(expected_scope, name, time = Time.now.to_f) ⇒ Object
Pops a scope off the transaction stack - this updates the transaction sampler that we’ve finished execution of a traced method
expected_scope
should be the ScopeStackElement that was returned by the corresponding push_scope call. -
#push_scope(tag, time = Time.now.to_f, deduct_call_time_from_parent = true) ⇒ Object
Pushes a scope onto the transaction stack - this generates a TransactionSample::Segment at the end of transaction execution The generated segment will not be named until the corresponding pop_scope call is made.
- #sampler_enabled? ⇒ Boolean
-
#scope_stack ⇒ Object
Returns the current scope stack, memoized to a thread local variable.
-
#start_transaction ⇒ Object
Start a new transaction, unless one is already in progress.
- #transaction_sampler ⇒ Object
-
#transaction_sampler=(sampler) ⇒ Object
deprecated–used to add transaction sampler, now we always look to the agent.
- #transaction_stats_hash ⇒ Object
Instance Method Details
#end_transaction ⇒ Object
Try to clean up gracefully, otherwise we leave things hanging around on thread locals. If it looks like a transaction is still in progress, then maybe this is an inner transaction and is ignored.
95 96 97 98 99 100 101 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 95 def end_transaction stack = scope_stack if stack && stack.empty? NewRelic::Agent::TransactionState.get.clear_stats_scope_stack end end |
#pop_scope(expected_scope, name, time = Time.now.to_f) ⇒ Object
Pops a scope off the transaction stack - this updates the transaction sampler that we’ve finished execution of a traced method expected_scope
should be the ScopeStackElement that was returned by the corresponding push_scope call. name
is the name that will be applied to the generated transaction trace segment.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 56 def pop_scope(expected_scope, name, time=Time.now.to_f) stack = scope_stack scope = stack.pop fail "unbalanced pop from blame stack, got #{scope ? scope.tag : 'nil'}, expected #{expected_scope ? expected_scope.tag : 'nil'}" if scope != expected_scope if !stack.empty? if scope.deduct_call_time_from_parent stack.last.children_time += (time - scope.start_time) else stack.last.children_time += scope.children_time end end transaction_sampler.notice_pop_scope(name, time) if sampler_enabled? scope.name = name scope end |
#push_scope(tag, time = Time.now.to_f, deduct_call_time_from_parent = true) ⇒ Object
Pushes a scope onto the transaction stack - this generates a TransactionSample::Segment at the end of transaction execution The generated segment will not be named until the corresponding pop_scope call is made. tag
should be a Symbol, and is only used for debugging purposes to identify this scope if the stack gets corrupted.
42 43 44 45 46 47 48 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 42 def push_scope(tag, time = Time.now.to_f, deduct_call_time_from_parent = true) stack = scope_stack transaction_sampler.notice_push_scope(time) if sampler_enabled? scope = ScopeStackElement.new(tag, time, deduct_call_time_from_parent) stack.push scope scope end |
#sampler_enabled? ⇒ Boolean
73 74 75 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 73 def sampler_enabled? Agent.config[:'transaction_tracer.enabled'] || Agent.config[:developer_mode] end |
#scope_stack ⇒ Object
Returns the current scope stack, memoized to a thread local variable
108 109 110 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 108 def scope_stack NewRelic::Agent::TransactionState.get.stats_scope_stack end |
#start_transaction ⇒ Object
Start a new transaction, unless one is already in progress
87 88 89 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 87 def start_transaction NewRelic::Agent.instance.events.notify(:start_transaction) end |
#transaction_sampler ⇒ Object
77 78 79 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 77 def transaction_sampler Agent.instance.transaction_sampler end |
#transaction_sampler=(sampler) ⇒ Object
deprecated–used to add transaction sampler, now we always look to the agent
82 83 84 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 82 def transaction_sampler= sampler NewRelic::Agent.logger.warn("NewRelic::Agent::StatsEngine#transaction_sampler is deprecated") end |
#transaction_stats_hash ⇒ Object
103 104 105 |
# File 'lib/new_relic/agent/stats_engine/transactions.rb', line 103 def transaction_stats_hash Transaction.current && Transaction.current.stats_hash end |