Class: OneApm::TransactionState
- Inherits:
-
Object
- Object
- OneApm::TransactionState
- Defined in:
- lib/one_apm/transaction/transaction_state.rb
Overview
This is THE location to store thread local information during a transaction Need a new piece of data? Add a method here, NOT a new thread local variable.
Instance Attribute Summary collapse
-
#busy_entries ⇒ Object
Busy calculator.
-
#client_cross_app_id ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts.
-
#current_transaction ⇒ Object
readonly
Current transaction stack and sample building.
-
#is_cross_app_caller ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts.
-
#record_sql ⇒ Object
TT’s and SQL.
-
#record_tt ⇒ Object
TT’s and SQL.
-
#referring_transaction_info ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts.
-
#request ⇒ Object
Request data.
-
#sql_sampler_transaction_data ⇒ Object
Sql Sampler Transaction Data.
-
#traced_method_stack ⇒ Object
readonly
Scope stack tracking from OneApm::StatsEngine::Transactions Should not be nil–this class manages its initialization and resetting.
-
#transaction_sample_builder ⇒ Object
Returns the value of attribute transaction_sample_builder.
-
#untraced ⇒ Object
Execution tracing on current thread.
Class Method Summary collapse
- .tl_clear_for_testing ⇒ Object
- .tl_get ⇒ Object
-
.tl_state_for(thread) ⇒ Object
This method should only be used by TransactionState for access to the current thread’s state or to provide read-only accessors for other threads.
Instance Method Summary collapse
- #in_background_transaction? ⇒ Boolean
- #in_web_transaction? ⇒ Boolean
-
#initialize ⇒ TransactionState
constructor
A new instance of TransactionState.
- #is_cross_app? ⇒ Boolean
- #is_cross_app_callee? ⇒ Boolean
- #is_cross_app_caller? ⇒ Boolean
- #is_execution_traced? ⇒ Boolean
- #is_sql_recorded? ⇒ Boolean
- #is_transaction_traced? ⇒ Boolean
- #pop_traced ⇒ Object
- #push_traced(should_trace) ⇒ Object
- #request_guid ⇒ Object
-
#reset(transaction = nil) ⇒ Object
This starts the timer for the transaction.
- #timings ⇒ Object
- #transaction_name ⇒ Object
- #transaction_queue_time ⇒ Object
- #transaction_start_time ⇒ Object
Constructor Details
#initialize ⇒ TransactionState
Returns a new instance of TransactionState.
33 34 35 36 37 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 33 def initialize @untraced = [] @traced_method_stack =OneApm::Support::TracedMethodStack.new @current_transaction = nil end |
Instance Attribute Details
#busy_entries ⇒ Object
Busy calculator
140 141 142 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 140 def busy_entries @busy_entries end |
#client_cross_app_id ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts
67 68 69 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 67 def client_cross_app_id @client_cross_app_id end |
#current_transaction ⇒ Object (readonly)
Current transaction stack and sample building
90 91 92 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 90 def current_transaction @current_transaction end |
#is_cross_app_caller ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts
67 68 69 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 67 def is_cross_app_caller @is_cross_app_caller end |
#record_sql ⇒ Object
TT’s and SQL
129 130 131 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 129 def record_sql @record_sql end |
#record_tt ⇒ Object
TT’s and SQL
129 130 131 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 129 def record_tt @record_tt end |
#referring_transaction_info ⇒ Object
Cross app tracing Because we need values from headers before the transaction actually starts
67 68 69 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 67 def referring_transaction_info @referring_transaction_info end |
#request ⇒ Object
Request data
82 83 84 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 82 def request @request end |
#sql_sampler_transaction_data ⇒ Object
Sql Sampler Transaction Data
143 144 145 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 143 def sql_sampler_transaction_data @sql_sampler_transaction_data end |
#traced_method_stack ⇒ Object (readonly)
Scope stack tracking from OneApm::StatsEngine::Transactions Should not be nil–this class manages its initialization and resetting
147 148 149 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 147 def traced_method_stack @traced_method_stack end |
#transaction_sample_builder ⇒ Object
Returns the value of attribute transaction_sample_builder.
91 92 93 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 91 def transaction_sample_builder @transaction_sample_builder end |
#untraced ⇒ Object
Execution tracing on current thread
114 115 116 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 114 def untraced @untraced end |
Class Method Details
.tl_clear_for_testing ⇒ Object
29 30 31 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 29 def self.tl_clear_for_testing Thread.current[:oneapm_transaction_state] = nil end |
.tl_get ⇒ Object
10 11 12 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 10 def self.tl_get tl_state_for(Thread.current) end |
.tl_state_for(thread) ⇒ Object
This method should only be used by TransactionState for access to the current thread’s state or to provide read-only accessors for other threads
If ever exposed, this requires additional synchronization
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 18 def self.tl_state_for(thread) state = thread[:oneapm_transaction_state] if state.nil? state = TransactionState.new thread[:oneapm_transaction_state] = state end state end |
Instance Method Details
#in_background_transaction? ⇒ Boolean
105 106 107 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 105 def in_background_transaction? !current_transaction.nil? && !current_transaction.recording_web_transaction? end |
#in_web_transaction? ⇒ Boolean
109 110 111 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 109 def in_web_transaction? !current_transaction.nil? && current_transaction.recording_web_transaction? end |
#is_cross_app? ⇒ Boolean
77 78 79 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 77 def is_cross_app? is_cross_app_caller? || is_cross_app_callee? end |
#is_cross_app_callee? ⇒ Boolean
73 74 75 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 73 def is_cross_app_callee? referring_transaction_info != nil end |
#is_cross_app_caller? ⇒ Boolean
69 70 71 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 69 def is_cross_app_caller? @is_cross_app_caller end |
#is_execution_traced? ⇒ Boolean
124 125 126 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 124 def is_execution_traced? @untraced.nil? || @untraced.last != false end |
#is_sql_recorded? ⇒ Boolean
135 136 137 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 135 def is_sql_recorded? @record_sql != false end |
#is_transaction_traced? ⇒ Boolean
131 132 133 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 131 def is_transaction_traced? @record_tt != false end |
#pop_traced ⇒ Object
120 121 122 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 120 def pop_traced @untraced.pop if @untraced end |
#push_traced(should_trace) ⇒ Object
116 117 118 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 116 def push_traced(should_trace) @untraced << should_trace end |
#request_guid ⇒ Object
84 85 86 87 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 84 def request_guid return nil unless current_transaction current_transaction.guid end |
#reset(transaction = nil) ⇒ Object
This starts the timer for the transaction.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 40 def reset(transaction=nil) # We purposefully don't reset @untraced, @record_tt and @record_sql # since those are managed by OneApm::Manager.disable_* calls explicitly # and (more importantly) outside the scope of a transaction @timings = nil @request = nil @current_transaction = transaction @traced_method_stack.clear @is_cross_app_caller = false @client_cross_app_id = nil @referring_transaction_info = nil @transaction_sample_builder = nil @sql_sampler_transaction_data = nil @busy_entries = 0 end |
#timings ⇒ Object
61 62 63 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 61 def timings @timings ||= TransactionTimings.new(transaction_queue_time, transaction_start_time, transaction_name) end |
#transaction_name ⇒ Object
101 102 103 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 101 def transaction_name current_transaction.nil? ? nil : current_transaction.best_name end |
#transaction_queue_time ⇒ Object
97 98 99 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 97 def transaction_queue_time current_transaction.nil? ? 0.0 : current_transaction.queue_time end |
#transaction_start_time ⇒ Object
93 94 95 |
# File 'lib/one_apm/transaction/transaction_state.rb', line 93 def transaction_start_time current_transaction.start_time if current_transaction end |