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
-
#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_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_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.
50 51 52 53 54 55 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 50 def initialize @untraced = [] @current_transaction = nil @traced_method_stack = TingYun::Agent::TracedMethodStack.new @record_tt = nil end |
Instance Attribute Details
#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
71 72 73 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 71 def record_sql @record_sql end |
#record_tt ⇒ Object
TT’s and SQL
71 72 73 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 71 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_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.
72 73 74 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 72 def untraced @untraced end |
Class Method Details
.process_thrift_data(data) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 104 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
31 32 33 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 31 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
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 39 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
172 173 174 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 172 def add_current_node_params(hash) transaction_sample_builder.current_node.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
163 164 165 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 163 def add_custom_params(key, value) current_transaction.attributes.add_custom_params(key, value) if current_transaction end |
#execution_traced? ⇒ Boolean
82 83 84 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 82 def execution_traced? @untraced.nil? || @untraced.last != false end |
#init_sql_transaction(obj) ⇒ Object
100 101 102 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 100 def init_sql_transaction(obj) @sql_sampler_transaction_data = obj end |
#merge_request_parameters(hash) ⇒ Object
same to add_custom_params
168 169 170 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 168 def merge_request_parameters(hash) current_transaction.attributes.merge_request_parameters(hash) if current_transaction end |
#pop_traced ⇒ Object
78 79 80 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 78 def pop_traced @untraced.pop if @untraced end |
#push_traced(should_trace) ⇒ Object
74 75 76 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 74 def push_traced(should_trace) @untraced << should_trace end |
#request_guid ⇒ Object
94 95 96 97 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 94 def request_guid return nil unless current_transaction current_transaction.guid end |
#reset(transaction = nil) ⇒ Object
This starts the timer for the transaction.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 58 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
147 148 149 150 151 152 153 154 155 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 147 def same_account? server_info = TingYun::Agent.config[:tingyunIdSecret].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
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 111 def save_referring_transaction_info(data) data = Array(data) @client_tingyun_id_secret = data.shift 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(/s=/) @externel_time = m.post_match end end end |
#sql_recorded? ⇒ Boolean
86 87 88 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 86 def sql_recorded? @record_sql != false end |
#trace_id ⇒ Object
143 144 145 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 143 def trace_id transaction_sample_builder.nil? ? nil : transaction_sample_builder.trace.guid end |
#transaction_name ⇒ Object
139 140 141 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 139 def transaction_name current_transaction.nil? ? nil : current_transaction.best_name end |
#transaction_queue_time ⇒ Object
135 136 137 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 135 def transaction_queue_time current_transaction.nil? ? 0.0 : current_transaction.apdex.queue_time end |
#transaction_start_time ⇒ Object
131 132 133 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 131 def transaction_start_time current_transaction.nil? ? 0.0 : current_transaction.start_time end |
#transaction_traced? ⇒ Boolean
90 91 92 |
# File 'lib/ting_yun/agent/transaction/transaction_state.rb', line 90 def transaction_traced? @record_tt != false end |