Class: TingYun::Agent::TransactionState
- Inherits:
-
Object
- Object
- TingYun::Agent::TransactionState
- Defined in:
- lib/ting_yun/agent/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
-
#action_type ⇒ Object
Sql Sampler Transaction Data.
-
#call_list ⇒ Object
Sql Sampler Transaction Data.
-
#client_req_id ⇒ Object
Sql Sampler Transaction Data.
-
#client_tingyun_id_secret ⇒ Object
Sql Sampler Transaction Data.
-
#client_transaction_id ⇒ Object
Sql Sampler Transaction Data.
-
#current_transaction ⇒ Object
readonly
Returns the value of attribute current_transaction.
-
#extenel_req_id ⇒ Object
Sql Sampler Transaction Data.
-
#externel_time ⇒ Object
Sql Sampler Transaction Data.
-
#record_sql ⇒ Object
TT’s and SQL.
-
#record_tt ⇒ Object
TT’s and SQL.
-
#sql_sampler_transaction_data ⇒ Object
Sql Sampler Transaction Data.
-
#thrift_return_data ⇒ Object
Sql Sampler Transaction Data.
-
#timings ⇒ Object
readonly
Returns the value of attribute timings.
-
#traced_method_stack ⇒ Object
readonly
Returns the value of attribute traced_method_stack.
-
#transaction_name_md5 ⇒ Object
Sql Sampler Transaction Data.
-
#transaction_sample_builder ⇒ Object
Request data.
-
#untraced ⇒ Object
Returns the value of attribute untraced.
Class Method Summary collapse
- .process_thrift_data(data) ⇒ 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
- #add_current_node_params(hash) ⇒ Object
- #add_current_node_paramsV3(hash) ⇒ Object
-
#add_custom_params(key, value) ⇒ Object
if you wanna call the method, you must make sure current_transaction is not nil at first if current_transaction add_custom_params(:key1,:value1) add_custom_params(:key2,:value2) end public api.
- #execution_traced? ⇒ Boolean
- #init_sql_transaction(obj) ⇒ Object
-
#initialize ⇒ TransactionState
constructor
A new instance of TransactionState.
-
#merge_request_parameters(hash) ⇒ Object
same to add_custom_params.
- #pop_traced ⇒ Object
- #push_traced(should_trace) ⇒ Object
- #request_guid ⇒ Object
-
#reset(transaction = nil) ⇒ Object
This starts the timer for the transaction.
- #same_account? ⇒ Boolean
- #save_referring_transaction_info(data) ⇒ Object
- #sql_recorded? ⇒ Boolean
- #trace_id ⇒ Object
- #transaction_name ⇒ Object
- #transaction_queue_time ⇒ Object
- #transaction_start_time ⇒ Object
- #transaction_traced? ⇒ Boolean
Constructor Details
#initialize ⇒ TransactionState
Returns a new instance of TransactionState.
53 54 55 56 57 58 59 60 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 53 def initialize @untraced = [] @current_transaction = nil @traced_method_stack = TingYun::Agent::TracedMethodStack.new @record_tt = nil @action_type = "Transaction" #[WebAction, Transaction] @client_tingyun_id_secret = TingYun::Agent.config[:idSecret] end |
Instance Attribute Details
#action_type ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def action_type @action_type end |
#call_list ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def call_list @call_list end |
#client_req_id ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def client_req_id @client_req_id end |
#client_tingyun_id_secret ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def client_tingyun_id_secret @client_tingyun_id_secret end |
#client_transaction_id ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def client_transaction_id @client_transaction_id end |
#current_transaction ⇒ Object (readonly)
Returns the value of attribute current_transaction.
14 15 16 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 14 def current_transaction @current_transaction end |
#extenel_req_id ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def extenel_req_id @extenel_req_id end |
#externel_time ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def externel_time @externel_time end |
#record_sql ⇒ Object
TT’s and SQL
76 77 78 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 76 def record_sql @record_sql end |
#record_tt ⇒ Object
TT’s and SQL
76 77 78 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 76 def record_tt @record_tt end |
#sql_sampler_transaction_data ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def sql_sampler_transaction_data @sql_sampler_transaction_data end |
#thrift_return_data ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def thrift_return_data @thrift_return_data end |
#timings ⇒ Object (readonly)
Returns the value of attribute timings.
14 15 16 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 14 def timings @timings end |
#traced_method_stack ⇒ Object (readonly)
Returns the value of attribute traced_method_stack.
14 15 16 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 14 def traced_method_stack @traced_method_stack end |
#transaction_name_md5 ⇒ Object
Sql Sampler Transaction Data
16 17 18 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 16 def transaction_name_md5 @transaction_name_md5 end |
#transaction_sample_builder ⇒ Object
Request data
13 14 15 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 13 def transaction_sample_builder @transaction_sample_builder end |
#untraced ⇒ Object
Returns the value of attribute untraced.
77 78 79 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 77 def untraced @untraced end |
Class Method Details
.process_thrift_data(data) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 109 def self.process_thrift_data(data) state = tl_get state.thrift_return_data = data builder = state.transaction_sample_builder builder.set_txId_and_txData(state.request_guid, data) if builder end |
.tl_get ⇒ Object
34 35 36 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 34 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
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 42 def self.tl_state_for(thread) state = thread[:tingyun_transaction_state] if state.nil? state = TransactionState.new thread[:tingyun_transaction_state] = state end state end |
Instance Method Details
#add_current_node_params(hash) ⇒ Object
180 181 182 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 180 def add_current_node_params(hash) transaction_sample_builder.current_node.merge hash if transaction_sample_builder end |
#add_current_node_paramsV3(hash) ⇒ Object
183 184 185 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 183 def add_current_node_paramsV3(hash) transaction_sample_builder.current_node.params_data.merge! hash if transaction_sample_builder end |
#add_custom_params(key, value) ⇒ Object
if you wanna call the method, you must make sure current_transaction is not nil at first if current_transaction
add_custom_params(:key1,:value1)
add_custom_params(:key2,:value2)
end public api
171 172 173 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 171 def add_custom_params(key, value) current_transaction.attributes.add_custom_params(key, value) if current_transaction end |
#execution_traced? ⇒ Boolean
87 88 89 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 87 def execution_traced? @untraced.nil? || @untraced.last != false end |
#init_sql_transaction(obj) ⇒ Object
105 106 107 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 105 def init_sql_transaction(obj) @sql_sampler_transaction_data = obj end |
#merge_request_parameters(hash) ⇒ Object
same to add_custom_params
176 177 178 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 176 def merge_request_parameters(hash) current_transaction.attributes.merge_request_parameters(hash) if current_transaction end |
#pop_traced ⇒ Object
83 84 85 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 83 def pop_traced @untraced.pop if @untraced end |
#push_traced(should_trace) ⇒ Object
79 80 81 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 79 def push_traced(should_trace) @untraced << should_trace end |
#request_guid ⇒ Object
99 100 101 102 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 99 def request_guid return nil unless current_transaction current_transaction.guid end |
#reset(transaction = nil) ⇒ Object
This starts the timer for the transaction.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 63 def reset(transaction=nil) # We purposefully don't reset @untraced, @record_tt and @record_sql,@client_transaction_id,@client_tingyun_id_secret # since those are managed by TingYun::Agent.disable_* calls explicitly # and (more importantly) outside the scope of a transaction @current_transaction = transaction @traced_method_stack.clear @transaction_sample_builder = nil @sql_sampler_transaction_data = nil @thrift_return_data = nil @timings = nil end |
#same_account? ⇒ Boolean
155 156 157 158 159 160 161 162 163 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 155 def same_account? server_info = TingYun::Agent.config[:idSecret].split('|') client_info = (@client_tingyun_id_secret || '').split('|') if server_info[0] && !server_info[0].empty? && server_info[0] == client_info[0] return true else return false end end |
#save_referring_transaction_info(data) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 116 def save_referring_transaction_info(data) data = Array(data) data.each do |e| if m = e.match(/x=/) @client_transaction_id = m.post_match elsif m = e.match(/r=/) @client_req_id = m.post_match elsif m = e.match(/e=/) @extenel_req_id = m.post_match elsif m = e.match(/n=/) @transaction_name_md5 = m.post_match elsif m = e.match(/c=/) @call_list = m.post_match @action_type = "WebAction" if @call_list.start_with?("S|") @client_tingyun_id_secret = "#{TingYun::Agent.config[:idSecret]},#{call_list}" end end end |
#sql_recorded? ⇒ Boolean
91 92 93 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 91 def sql_recorded? @record_sql != false end |
#trace_id ⇒ Object
151 152 153 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 151 def trace_id transaction_sample_builder.nil? ? nil : transaction_sample_builder.trace.guid end |
#transaction_name ⇒ Object
147 148 149 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 147 def transaction_name current_transaction.nil? ? nil : current_transaction.best_name end |
#transaction_queue_time ⇒ Object
143 144 145 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 143 def transaction_queue_time current_transaction.nil? ? 0.0 : current_transaction.apdex.queue_time end |
#transaction_start_time ⇒ Object
139 140 141 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 139 def transaction_start_time current_transaction.nil? ? 0.0 : current_transaction.start_time end |
#transaction_traced? ⇒ Boolean
95 96 97 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 95 def transaction_traced? @record_tt != false end |