Class: Appsignal::Transaction
- Inherits:
-
Object
- Object
- Appsignal::Transaction
- Defined in:
- lib/appsignal/transaction.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#process_action_event ⇒ Object
readonly
Returns the value of attribute process_action_event.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #add_exception(ex) ⇒ Object
- #clear_payload_and_events! ⇒ Object
- #complete! ⇒ Object
- #exception? ⇒ Boolean
-
#initialize(id, env) ⇒ Transaction
constructor
A new instance of Transaction.
- #request ⇒ Object
- #set_process_action_event(event) ⇒ Object
- #slow_request? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(id, env) ⇒ Transaction
Returns a new instance of Transaction.
17 18 19 20 21 22 23 |
# File 'lib/appsignal/transaction.rb', line 17 def initialize(id, env) @id = id @events = [] @process_action_event = nil @exception = nil @env = env end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def action @action end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def env @env end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def events @events end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def exception @exception end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def id @id end |
#process_action_event ⇒ Object (readonly)
Returns the value of attribute process_action_event.
15 16 17 |
# File 'lib/appsignal/transaction.rb', line 15 def process_action_event @process_action_event end |
Class Method Details
.create(key, env) ⇒ Object
6 7 8 9 |
# File 'lib/appsignal/transaction.rb', line 6 def self.create(key, env) Thread.current[:appsignal_transaction_id] = key Appsignal.transactions[key] = Appsignal::Transaction.new(key, env) end |
.current ⇒ Object
11 12 13 |
# File 'lib/appsignal/transaction.rb', line 11 def self.current Appsignal.transactions[Thread.current[:appsignal_transaction_id]] end |
Instance Method Details
#add_event(event) ⇒ Object
37 38 39 |
# File 'lib/appsignal/transaction.rb', line 37 def add_event(event) @events << event end |
#add_exception(ex) ⇒ Object
41 42 43 |
# File 'lib/appsignal/transaction.rb', line 41 def add_exception(ex) @exception = ex end |
#clear_payload_and_events! ⇒ Object
54 55 56 57 |
# File 'lib/appsignal/transaction.rb', line 54 def clear_payload_and_events! @process_action_event.payload.clear @events.clear end |
#complete! ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/appsignal/transaction.rb', line 69 def complete! Thread.current[:appsignal_transaction_id] = nil current_transaction = Appsignal.transactions.delete(@id) if process_action_event || exception? Appsignal.agent.add_to_queue(current_transaction) end end |
#exception? ⇒ Boolean
45 46 47 |
# File 'lib/appsignal/transaction.rb', line 45 def exception? !!exception end |
#request ⇒ Object
25 26 27 |
# File 'lib/appsignal/transaction.rb', line 25 def request ActionDispatch::Request.new(@env) end |
#set_process_action_event(event) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/appsignal/transaction.rb', line 29 def set_process_action_event(event) @process_action_event = event if @process_action_event && @process_action_event.payload @action = "#{process_action_event.payload[:controller]}#"\ "#{process_action_event.payload[:action]}" end end |
#slow_request? ⇒ Boolean
49 50 51 52 |
# File 'lib/appsignal/transaction.rb', line 49 def slow_request? return false unless process_action_event && process_action_event.payload Appsignal.config[:slow_request_threshold] <= process_action_event.duration end |
#to_hash ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/appsignal/transaction.rb', line 59 def to_hash if exception? TransactionFormatter.faulty(self) elsif slow_request? TransactionFormatter.slow(self) else TransactionFormatter.regular(self) end.to_hash end |