class TingYun::Agent::TransactionState

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.

Attributes

action_type[RW]

Sql Sampler Transaction Data

call_list[RW]

Sql Sampler Transaction Data

client_req_id[RW]

Sql Sampler Transaction Data

client_tingyun_id_secret[RW]

Sql Sampler Transaction Data

client_transaction_id[RW]

Sql Sampler Transaction Data

current_transaction[R]
extenel_req_id[RW]

Sql Sampler Transaction Data

externel_time[RW]

Sql Sampler Transaction Data

record_sql[RW]

TT's and SQL

record_tt[RW]

TT's and SQL

sql_sampler_transaction_data[RW]

Sql Sampler Transaction Data

thrift_return_data[RW]

Sql Sampler Transaction Data

timings[R]
traced_method_stack[R]
transaction_name_md5[RW]

Sql Sampler Transaction Data

transaction_sample_builder[RW]

Request data

untraced[RW]

Public Class Methods

new() click to toggle source
# 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
process_thrift_data(data) click to toggle source
# 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() click to toggle source
# 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) click to toggle source

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

# 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

Public Instance Methods

add_current_node_params(hash) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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

# 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?() click to toggle source
# File lib/ting_yun/agent/transaction/transaction_state.rb, line 87
def execution_traced?
  @untraced.nil? || @untraced.last != false
end
init_sql_transaction(obj) click to toggle source
# 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) click to toggle source

same to add_custom_params

# 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() click to toggle source
# File lib/ting_yun/agent/transaction/transaction_state.rb, line 83
def pop_traced
  @untraced.pop if @untraced
end
push_traced(should_trace) click to toggle source
# File lib/ting_yun/agent/transaction/transaction_state.rb, line 79
def push_traced(should_trace)
  @untraced << should_trace
end
request_guid() click to toggle source
# 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) click to toggle source

This starts the timer for the transaction.

# 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?() click to toggle source
# 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) click to toggle source
# 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?() click to toggle source
# File lib/ting_yun/agent/transaction/transaction_state.rb, line 91
def sql_recorded?
  @record_sql != false
end
trace_id() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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?() click to toggle source
# File lib/ting_yun/agent/transaction/transaction_state.rb, line 95
def transaction_traced?
  @record_tt != false
end