class OneApm::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

busy_entries[RW]

Busy calculator

client_cross_app_id[RW]

Cross app tracing Because we need values from headers before the transaction actually starts

current_transaction[R]

Current transaction stack and sample building

is_cross_app_caller[RW]

Cross app tracing Because we need values from headers before the transaction actually starts

record_sql[RW]

TT's and SQL

record_tt[RW]

TT's and SQL

referring_transaction_info[RW]

Cross app tracing Because we need values from headers before the transaction actually starts

request[RW]

Request data

sql_sampler_transaction_data[RW]

Sql Sampler Transaction Data

traced_method_stack[R]

Scope stack tracking from OneApm::StatsEngine::Transactions Should not be nil–this class manages its initialization and resetting

transaction_sample_builder[RW]
untraced[RW]

Execution tracing on current thread

Public Class Methods

new() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 33
def initialize
  @untraced = []
  @traced_method_stack =OneApm::Support::TracedMethodStack.new
  @current_transaction = nil
end
tl_clear_for_testing() click to toggle source
# 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() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 10
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/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

Public Instance Methods

in_background_transaction?() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 73
def is_cross_app_callee?
  referring_transaction_info != nil
end
is_cross_app_caller?() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 69
def is_cross_app_caller?
  @is_cross_app_caller
end
is_execution_traced?() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 124
def is_execution_traced?
  @untraced.nil? || @untraced.last != false
end
is_sql_recorded?() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 135
def is_sql_recorded?
  @record_sql != false
end
is_transaction_traced?() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 131
def is_transaction_traced?
  @record_tt != false
end
pop_traced() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 120
def pop_traced
  @untraced.pop if @untraced
end
push_traced(should_trace) click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 116
def push_traced(should_trace)
  @untraced << should_trace
end
request_guid() click to toggle source
# 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) click to toggle source

This starts the timer for the transaction.

# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/one_apm/transaction/transaction_state.rb, line 93
def transaction_start_time
  current_transaction.start_time if current_transaction
end