Class: Appsignal::Transaction
- Inherits:
-
Object
- Object
- Appsignal::Transaction
- Defined in:
- lib/appsignal/transaction.rb
Constant Summary collapse
- ENV_METHODS =
Based on what Rails uses + some variables we’d like to show
%w(CONTENT_LENGTH AUTH_TYPE GATEWAY_INTERFACE PATH_TRANSLATED REMOTE_HOST REMOTE_IDENT REMOTE_USER REMOTE_ADDR REQUEST_METHOD SERVER_NAME SERVER_PORT SERVER_PROTOCOL HTTP_X_REQUEST_START HTTP_X_MIDDLEWARE_START HTTP_X_QUEUE_START HTTP_X_QUEUE_TIME HTTP_X_HEROKU_QUEUE_WAIT_TIME HTTP_X_APPLICATION_START HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_CONNECTION HTTP_USER_AGENT HTTP_FROM HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER).freeze
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.
-
#fullpath ⇒ Object
readonly
Returns the value of attribute fullpath.
-
#process_action_event ⇒ Object
readonly
Returns the value of attribute process_action_event.
-
#request_id ⇒ Object
readonly
Returns the value of attribute request_id.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Class Method Summary collapse
Instance Method Summary collapse
- #add_event(event) ⇒ Object
- #add_exception(ex) ⇒ Object
- #complete! ⇒ Object
- #convert_values_to_primitives! ⇒ Object
- #exception? ⇒ Boolean
-
#initialize(request_id, env) ⇒ Transaction
constructor
A new instance of Transaction.
- #request ⇒ Object
- #sanitized_environment ⇒ Object
- #sanitized_session_data ⇒ Object
- #set_process_action_event(event) ⇒ Object
- #set_tags(given_tags = {}) ⇒ Object
- #slow_request? ⇒ Boolean
- #slower?(transaction) ⇒ Boolean
- #to_hash ⇒ Object
- #truncate! ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(request_id, env) ⇒ Transaction
Returns a new instance of Transaction.
31 32 33 34 35 36 37 38 |
# File 'lib/appsignal/transaction.rb', line 31 def initialize(request_id, env) @request_id = request_id @events = [] @process_action_event = nil @exception = nil @env = env = {} end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def action @action end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def env @env end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def events @events end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def exception @exception end |
#fullpath ⇒ Object (readonly)
Returns the value of attribute fullpath.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def fullpath @fullpath end |
#process_action_event ⇒ Object (readonly)
Returns the value of attribute process_action_event.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def process_action_event @process_action_event end |
#request_id ⇒ Object (readonly)
Returns the value of attribute request_id.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def request_id @request_id end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
28 29 30 |
# File 'lib/appsignal/transaction.rb', line 28 def time @time end |
Class Method Details
.create(key, env) ⇒ Object
18 19 20 21 22 |
# File 'lib/appsignal/transaction.rb', line 18 def self.create(key, env) Appsignal.logger.debug("Creating transaction: #{key}") Thread.current[:appsignal_transaction_id] = key Appsignal.transactions[key] = Appsignal::Transaction.new(key, env) end |
.current ⇒ Object
24 25 26 |
# File 'lib/appsignal/transaction.rb', line 24 def self.current Appsignal.transactions[Thread.current[:appsignal_transaction_id]] end |
Instance Method Details
#add_event(event) ⇒ Object
63 64 65 |
# File 'lib/appsignal/transaction.rb', line 63 def add_event(event) @events << event end |
#add_exception(ex) ⇒ Object
67 68 69 70 |
# File 'lib/appsignal/transaction.rb', line 67 def add_exception(ex) @time = Time.now.utc.to_f @exception = ex end |
#complete! ⇒ Object
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/appsignal/transaction.rb', line 111 def complete! Appsignal.logger.debug("Completing transaction: #{@request_id}") Thread.current[:appsignal_transaction_id] = nil current_transaction = Appsignal.transactions.delete(@request_id) if process_action_event || exception? Appsignal.enqueue(current_transaction) else Appsignal.logger.debug("No process_action_event or exception: #{@request_id}") end end |
#convert_values_to_primitives! ⇒ Object
95 96 97 98 99 |
# File 'lib/appsignal/transaction.rb', line 95 def convert_values_to_primitives! Appsignal::ParamsSanitizer.sanitize!(@process_action_event.payload) if @process_action_event @events.each { |o| Appsignal::ParamsSanitizer.sanitize!(o.payload) } add_sanitized_context! end |
#exception? ⇒ Boolean
72 73 74 |
# File 'lib/appsignal/transaction.rb', line 72 def exception? !!exception end |
#request ⇒ Object
48 49 50 |
# File 'lib/appsignal/transaction.rb', line 48 def request ActionDispatch::Request.new(@env) end |
#sanitized_environment ⇒ Object
40 41 42 |
# File 'lib/appsignal/transaction.rb', line 40 def sanitized_environment @sanitized_environment ||= {} end |
#sanitized_session_data ⇒ Object
44 45 46 |
# File 'lib/appsignal/transaction.rb', line 44 def sanitized_session_data @sanitized_session_data ||= {} end |
#set_process_action_event(event) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/appsignal/transaction.rb', line 56 def set_process_action_event(event) @process_action_event = event if event && event.payload @action = "#{event.payload[:controller]}##{event.payload[:action]}" end end |
#set_tags(given_tags = {}) ⇒ Object
52 53 54 |
# File 'lib/appsignal/transaction.rb', line 52 def (={}) .merge!() end |
#slow_request? ⇒ Boolean
76 77 78 79 80 |
# File 'lib/appsignal/transaction.rb', line 76 def slow_request? return false unless process_action_event && process_action_event.payload Appsignal.config[:slow_request_threshold] <= process_action_event.duration end |
#slower?(transaction) ⇒ Boolean
82 83 84 |
# File 'lib/appsignal/transaction.rb', line 82 def slower?(transaction) process_action_event.duration > transaction.process_action_event.duration end |
#to_hash ⇒ Object
107 108 109 |
# File 'lib/appsignal/transaction.rb', line 107 def to_hash TransactionFormatter.new(self).to_hash end |
#truncate! ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/appsignal/transaction.rb', line 86 def truncate! process_action_event.payload.clear events.clear .clear sanitized_environment.clear sanitized_session_data.clear @env = nil end |
#type ⇒ Object
101 102 103 104 105 |
# File 'lib/appsignal/transaction.rb', line 101 def type return :exception if exception? return :slow_request if slow_request? :regular_request end |