Class: AlacrityRails::Transaction::WebTransaction
- Defined in:
- lib/alacrity-rails/transaction/web_transaction.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#db_runtime ⇒ Object
Returns the value of attribute db_runtime.
-
#format ⇒ Object
Returns the value of attribute format.
-
#framework_elapsed ⇒ Object
Returns the value of attribute framework_elapsed.
-
#method ⇒ Object
Returns the value of attribute method.
-
#middleware_started_at ⇒ Object
Returns the value of attribute middleware_started_at.
-
#status ⇒ Object
Returns the value of attribute status.
-
#url ⇒ Object
Returns the value of attribute url.
-
#view_runtime ⇒ Object
Returns the value of attribute view_runtime.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(*args) ⇒ Object
-
#initialize(env = {}) ⇒ WebTransaction
constructor
A new instance of WebTransaction.
- #sql_queries ⇒ Object
- #store_database_metrics(started_at, finished_at, data) ⇒ Object
- #store_request_metrics(started_at, finished_at, data) ⇒ Object
Methods inherited from Base
authorization_header_value, #authorization_header_value, #endpoint, net_http_start_arguments, #net_http_start_arguments, #post_request, #to_json
Constructor Details
#initialize(env = {}) ⇒ WebTransaction
Returns a new instance of WebTransaction.
6 7 8 9 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 6 def initialize(env={}) self.middleware_started_at = Time.now self.url = ["#{env['rack.url_scheme']}://", env['HTTP_HOST'], env['REQUEST_PATH']].compact.join end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def action @action end |
#controller ⇒ Object
Returns the value of attribute controller.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def controller @controller end |
#db_runtime ⇒ Object
Returns the value of attribute db_runtime.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def db_runtime @db_runtime end |
#format ⇒ Object
Returns the value of attribute format.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def format @format end |
#framework_elapsed ⇒ Object
Returns the value of attribute framework_elapsed.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def framework_elapsed @framework_elapsed end |
#method ⇒ Object
Returns the value of attribute method.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def method @method end |
#middleware_started_at ⇒ Object
Returns the value of attribute middleware_started_at.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def middleware_started_at @middleware_started_at end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def status @status end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def url @url end |
#view_runtime ⇒ Object
Returns the value of attribute view_runtime.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def view_runtime @view_runtime end |
Class Method Details
.endpoint ⇒ Object
47 48 49 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 47 def self.endpoint @endpoint ||= URI("#{AlacrityRails::Config.collector_host}/v1/web-transactions") end |
Instance Method Details
#as_json(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 30 def as_json(*args) { environment: AlacrityRails::ServerConfig.environment, url: url, controller: controller, action: action, middleware_elapsed: ((Time.now - middleware_started_at) * 1000).to_i, framework_elapsed: framework_elapsed, format: format, method: method, status: status, view_runtime: view_runtime, db_runtime: db_runtime, sql_queries: sql_queries } end |
#sql_queries ⇒ Object
51 52 53 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 51 def sql_queries @sql_queries ||= [] end |
#store_database_metrics(started_at, finished_at, data) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 11 def store_database_metrics(started_at, finished_at, data) sql_queries << { statement_elapsed: ((finished_at - started_at) * 1000).to_i, name: data[:name], sql: data[:sql] } end |
#store_request_metrics(started_at, finished_at, data) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 19 def store_request_metrics(started_at, finished_at, data) self.framework_elapsed = ((finished_at - started_at) * 1000).to_i self.controller = data[:controller] self.action = data[:action] self.format = data[:format] self.method = data[:method] self.status = data[:status] self.view_runtime = data[:view_runtime].try(:to_i) self.db_runtime = data[:db_runtime].try(:to_i) end |