Class: NewRelic::Agent::TransactionState

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransactionState

Returns a new instance of TransactionState.



36
37
38
# File 'lib/new_relic/agent/transaction_state.rb', line 36

def initialize
  @stats_scope_stack = []
end

Instance Attribute Details

#busy_entriesObject

Busy calculator



151
152
153
# File 'lib/new_relic/agent/transaction_state.rb', line 151

def busy_entries
  @busy_entries
end

#client_cross_app_idObject

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



61
62
63
# File 'lib/new_relic/agent/transaction_state.rb', line 61

def client_cross_app_id
  @client_cross_app_id
end

#current_transaction_stackObject

Returns and initializes the transaction stack if necessary

We don’t default in the initializer so non-transaction threads retain a nil stack, and methods in this class use has_current_transction? instead of this accessor to see if we’re a transaction thread or not



75
76
77
# File 'lib/new_relic/agent/transaction_state.rb', line 75

def current_transaction_stack
  @current_transaction_stack ||= []
end

#record_sqlObject

TT’s and SQL



140
141
142
# File 'lib/new_relic/agent/transaction_state.rb', line 140

def record_sql
  @record_sql
end

#record_ttObject

TT’s and SQL



140
141
142
# File 'lib/new_relic/agent/transaction_state.rb', line 140

def record_tt
  @record_tt
end

#referring_transaction_infoObject

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



61
62
63
# File 'lib/new_relic/agent/transaction_state.rb', line 61

def referring_transaction_info
  @referring_transaction_info
end

#requestObject

Request data



64
65
66
# File 'lib/new_relic/agent/transaction_state.rb', line 64

def request
  @request
end

#request_guidObject

Request data



64
65
66
# File 'lib/new_relic/agent/transaction_state.rb', line 64

def request_guid
  @request_guid
end

#request_ignore_enduserObject

Request data



64
65
66
# File 'lib/new_relic/agent/transaction_state.rb', line 64

def request_ignore_enduser
  @request_ignore_enduser
end

#request_tokenObject

Request data



64
65
66
# File 'lib/new_relic/agent/transaction_state.rb', line 64

def request_token
  @request_token
end

#sql_sampler_transaction_dataObject

Sql Sampler Transaction Data



154
155
156
# File 'lib/new_relic/agent/transaction_state.rb', line 154

def sql_sampler_transaction_data
  @sql_sampler_transaction_data
end

#stats_scope_stackObject

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



158
159
160
# File 'lib/new_relic/agent/transaction_state.rb', line 158

def stats_scope_stack
  @stats_scope_stack
end

#transactionObject

Current transaction stack and sample building



67
68
69
# File 'lib/new_relic/agent/transaction_state.rb', line 67

def transaction
  @transaction
end

#transaction_sample_builderObject

Current transaction stack and sample building



67
68
69
# File 'lib/new_relic/agent/transaction_state.rb', line 67

def transaction_sample_builder
  @transaction_sample_builder
end

#untracedObject

Execution tracing on current thread



124
125
126
# File 'lib/new_relic/agent/transaction_state.rb', line 124

def untraced
  @untraced
end

Class Method Details

.clearObject



27
28
29
# File 'lib/new_relic/agent/transaction_state.rb', line 27

def self.clear
  Thread.current[:newrelic_transaction_state] = nil
end

.getObject



14
15
16
# File 'lib/new_relic/agent/transaction_state.rb', line 14

def self.get
  state_for(Thread.current)
end

.in_background_transaction?(thread) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/new_relic/agent/transaction_state.rb', line 99

def self.in_background_transaction?(thread)
  state_for(thread).in_background_transaction?
end

.in_request_transaction?(thread) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/new_relic/agent/transaction_state.rb', line 103

def self.in_request_transaction?(thread)
  state_for(thread).in_request_transaction?
end

.reset(request = nil) ⇒ Object

This starts the timer for the transaction.



32
33
34
# File 'lib/new_relic/agent/transaction_state.rb', line 32

def self.reset(request=nil)
  self.get.reset(request)
end

Instance Method Details

#clear_stats_scope_stackObject



160
161
162
# File 'lib/new_relic/agent/transaction_state.rb', line 160

def clear_stats_scope_stack
  @stats_scope_stack = []
end

#current_transactionObject



115
116
117
# File 'lib/new_relic/agent/transaction_state.rb', line 115

def current_transaction
  current_transaction_stack.last if has_current_transaction?
end

#has_current_transaction?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/new_relic/agent/transaction_state.rb', line 119

def has_current_transaction?
  !@current_transaction_stack.nil?
end

#in_background_transaction?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/new_relic/agent/transaction_state.rb', line 107

def in_background_transaction?
  !current_transaction.nil? && current_transaction.request.nil?
end

#in_request_transaction?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/new_relic/agent/transaction_state.rb', line 111

def in_request_transaction?
  !current_transaction.nil? && !current_transaction.request.nil?
end

#is_sql_recorded?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/new_relic/agent/transaction_state.rb', line 146

def is_sql_recorded?
  @record_sql != false
end

#is_traced?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/new_relic/agent/transaction_state.rb', line 135

def is_traced?
  @untraced.nil? || @untraced.last != false
end

#is_transaction_traced?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/new_relic/agent/transaction_state.rb', line 142

def is_transaction_traced?
  @record_tt != false
end

#pop_tracedObject



131
132
133
# File 'lib/new_relic/agent/transaction_state.rb', line 131

def pop_traced
  @untraced.pop if @untraced
end

#push_traced(should_trace) ⇒ Object



126
127
128
129
# File 'lib/new_relic/agent/transaction_state.rb', line 126

def push_traced(should_trace)
  @untraced ||= []
  @untraced << should_trace
end

#reset(request) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/new_relic/agent/transaction_state.rb', line 40

def reset(request)
  # We almost always want to use the transaction time, but in case it's
  # not available, we track the last reset. No accessor, as only the
  # TransactionState class should use it.
  @last_reset_time = Time.now

  @transaction = Transaction.current
  @timings = nil

  @request = request
  @request_token = BrowserToken.get_token(request)
  @request_guid = ""
  @request_ignore_enduser = false
end

#timingsObject



55
56
57
# File 'lib/new_relic/agent/transaction_state.rb', line 55

def timings
  @timings ||= TransactionTimings.new(transaction_queue_time, transaction_start_time, transaction_name)
end

#transaction_nameObject



91
92
93
# File 'lib/new_relic/agent/transaction_state.rb', line 91

def transaction_name
  transaction.nil? ? nil : transaction.name
end

#transaction_noticed_error_idsObject



95
96
97
# File 'lib/new_relic/agent/transaction_state.rb', line 95

def transaction_noticed_error_ids
  transaction.nil? ? [] : transaction.noticed_error_ids
end

#transaction_queue_timeObject



87
88
89
# File 'lib/new_relic/agent/transaction_state.rb', line 87

def transaction_queue_time
  transaction.nil? ? 0.0 : transaction.queue_time
end

#transaction_start_timeObject



79
80
81
82
83
84
85
# File 'lib/new_relic/agent/transaction_state.rb', line 79

def transaction_start_time
  if transaction.nil?
    @last_reset_time
  else
    transaction.start_time
  end
end