Class: Appsignal::Transaction
Constant Summary collapse
- HTTP_REQUEST =
"http_request"
- BACKGROUND_JOB =
"background_job"
Class Method Summary collapse
-
.complete_current! ⇒ void
Complete the currently active transaction and unset it as the active transaction.
-
.create(namespace) ⇒ Transaction
Create a new transaction and set it as the currently active transaction.
-
.current ⇒ Appsignal::Transaction, Appsignal::Transaction::NilTransaction
Returns currently active transaction or a NilTransaction if none is active.
-
.current? ⇒ Boolean
Returns if any transaction is currently active or not.
Instance Method Summary collapse
-
#add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc) ⇒ void
Add breadcrumbs to the transaction.
-
#add_custom_data(data) ⇒ void
(also: #set_custom_data)
Add custom data to the transaction.
-
#add_headers(given_headers = nil) { ... } ⇒ void
(also: #set_headers)
Add headers to the transaction.
-
#add_params(given_params = nil) { ... } ⇒ void
(also: #set_params)
Add parameters to the transaction.
-
#add_session_data(given_session_data = nil) { ... } ⇒ void
(also: #set_session_data)
Add session data to the transaction.
-
#add_tags(given_tags = {}) ⇒ void
(also: #set_tags)
Add tags to the transaction.
-
#set_action(action) ⇒ void
Set an action name for the transaction.
-
#set_namespace(namespace) ⇒ void
Set the namespace for this transaction.
-
#set_queue_start(start) ⇒ void
Set queue start time for transaction.
Class Method Details
.complete_current! ⇒ void
This method returns an undefined value.
Complete the currently active transaction and unset it as the active transaction.
130 131 132 133 134 135 136 137 138 |
# File 'lib/appsignal/transaction.rb', line 130 def complete_current! current.complete rescue => e Appsignal.internal_logger.error( "Failed to complete transaction ##{current.transaction_id}. #{e.}" ) ensure clear_current_transaction! end |
.create(namespace) ⇒ Transaction
Create a new transaction and set it as the currently active transaction.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/appsignal/transaction.rb', line 32 def create(namespace) # Reset the transaction if it was already completed but not cleared if Thread.current[:appsignal_transaction]&.completed? Thread.current[:appsignal_transaction] = nil end if Thread.current[:appsignal_transaction].nil? # If not, start a new transaction set_current_transaction(Appsignal::Transaction.new(namespace)) else transaction = current # Otherwise, log the issue about trying to start another transaction Appsignal.internal_logger.warn( "Trying to start new transaction, but a transaction " \ "with id '#{transaction.transaction_id}' is already running. " \ "Using transaction '#{transaction.transaction_id}'." ) # And return the current transaction instead transaction end end |
.current ⇒ Appsignal::Transaction, Appsignal::Transaction::NilTransaction
Returns currently active transaction or a NilTransaction if none is active.
113 114 115 |
# File 'lib/appsignal/transaction.rb', line 113 def current Thread.current[:appsignal_transaction] || NilTransaction.new end |
.current? ⇒ Boolean
Returns if any transaction is currently active or not. A NilTransaction is not considered an active transaction.
122 123 124 |
# File 'lib/appsignal/transaction.rb', line 122 def current? current && !current.nil_transaction? end |
Instance Method Details
#add_breadcrumb(category, action, message = "", metadata = {}, time = Time.now.utc) ⇒ void
This method returns an undefined value.
Add breadcrumbs to the transaction.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
# File 'lib/appsignal/transaction.rb', line 473 def (category, action, = "", = {}, time = Time.now.utc) unless .is_a? Hash Appsignal.internal_logger.error "add_breadcrumb: Cannot add breadcrumb. " \ "The given metadata argument is not a Hash." return end @breadcrumbs.push( :time => time.to_i, :category => category, :action => action, :message => , :metadata => ) @breadcrumbs = @breadcrumbs.last(BREADCRUMB_LIMIT) end |
#add_custom_data(data) ⇒ void Also known as: set_custom_data
This method returns an undefined value.
Add custom data to the transaction.
454 455 456 |
# File 'lib/appsignal/transaction.rb', line 454 def add_custom_data(data) @custom_data.add(data) end |
#add_headers(given_headers = nil) { ... } ⇒ void Also known as: set_headers
This method returns an undefined value.
Add headers to the transaction.
418 419 420 |
# File 'lib/appsignal/transaction.rb', line 418 def add_headers(given_headers = nil, &block) @headers.add(given_headers, &block) end |
#add_params(given_params = nil) { ... } ⇒ void Also known as: set_params
This method returns an undefined value.
Add parameters to the transaction.
When this method is called multiple times, it will merge the request parameters.
When both the ‘given_params` and a block is given to this method, the block is leading and the argument will not be used.
311 312 313 |
# File 'lib/appsignal/transaction.rb', line 311 def add_params(given_params = nil, &block) @params.add(given_params, &block) end |
#add_session_data(given_session_data = nil) { ... } ⇒ void Also known as: set_session_data
This method returns an undefined value.
Add session data to the transaction.
When this method is called multiple times, it will merge the session data.
When both the ‘given_session_data` and a block is given to this method, the block is leading and the argument will not be used.
379 380 381 |
# File 'lib/appsignal/transaction.rb', line 379 def add_session_data(given_session_data = nil, &block) @session_data.add(given_session_data, &block) end |
#add_tags(given_tags = {}) ⇒ void Also known as:
This method returns an undefined value.
Add tags to the transaction.
When this method is called multiple times, it will merge the tags.
357 358 359 |
# File 'lib/appsignal/transaction.rb', line 357 def ( = {}) @tags.merge!() end |
#set_action(action) ⇒ void
This method returns an undefined value.
Set an action name for the transaction.
An action name is used to identify the location of a certain sample; error and performance issues.
500 501 502 503 504 505 |
# File 'lib/appsignal/transaction.rb', line 500 def set_action(action) return unless action @action = action @ext.set_action(action) end |
#set_namespace(namespace) ⇒ void
This method returns an undefined value.
Set the namespace for this transaction.
Useful to split up parts of an application into certain namespaces. For example: http requests, background jobs and administration panel controllers.
Note: The “http_request” namespace gets transformed on AppSignal.com to “Web” and “background_job” gets transformed to “Background”.
548 549 550 551 552 553 |
# File 'lib/appsignal/transaction.rb', line 548 def set_namespace(namespace) return unless namespace @namespace = namespace @ext.set_namespace(namespace) end |
#set_queue_start(start) ⇒ void
This method returns an undefined value.
Set queue start time for transaction.
563 564 565 566 567 568 569 |
# File 'lib/appsignal/transaction.rb', line 563 def set_queue_start(start) return unless start @ext.set_queue_start(start) rescue RangeError Appsignal.internal_logger.warn("Queue start value #{start} is too big") end |