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.
-
#format ⇒ Object
Returns the value of attribute format.
-
#framework_finished_at ⇒ Object
Returns the value of attribute framework_finished_at.
-
#framework_started_at ⇒ Object
Returns the value of attribute framework_started_at.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #absolute_time(datetime) ⇒ Object
- #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 10 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 6 def initialize(env={}) self.middleware_started_at = absolute_time(DateTime.now) self.url = ["#{env['rack.url_scheme']}://", env['HTTP_HOST'], env['REQUEST_PATH']].compact.join self.method = env['REQUEST_METHOD'] 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 |
#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_finished_at ⇒ Object
Returns the value of attribute framework_finished_at.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def framework_finished_at @framework_finished_at end |
#framework_started_at ⇒ Object
Returns the value of attribute framework_started_at.
3 4 5 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 3 def framework_started_at @framework_started_at 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 |
Class Method Details
.endpoint ⇒ Object
49 50 51 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 49 def self.endpoint @endpoint ||= URI("#{AlacrityRails::Config.collector_host}/v1/web-transactions") end |
Instance Method Details
#absolute_time(datetime) ⇒ Object
57 58 59 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 57 def absolute_time(datetime) datetime.strftime('%Q').to_i end |
#as_json(*args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 30 def as_json(*args) middleware_finished_at = absolute_time(DateTime.now) { environment: AlacrityRails::ServerConfig.environment, url: url, controller: controller, action: action, middleware_elapsed: middleware_finished_at - middleware_started_at, middleware_started_at: middleware_started_at, middleware_finished_at: middleware_finished_at, framework_started_at: framework_started_at, framework_finished_at: framework_finished_at, format: format, method: method, status: status, sql_queries: sql_queries } end |
#sql_queries ⇒ Object
53 54 55 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 53 def sql_queries @sql_queries ||= [] end |
#store_database_metrics(started_at, finished_at, data) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 12 def store_database_metrics(started_at, finished_at, data) sql_queries << { started_at: absolute_time(started_at.to_datetime), finished_at: absolute_time(finished_at.to_datetime), name: data[:name], sql: data[:sql] } end |
#store_request_metrics(started_at, finished_at, data) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/alacrity-rails/transaction/web_transaction.rb', line 21 def store_request_metrics(started_at, finished_at, data) self.framework_started_at = absolute_time(started_at.to_datetime) self.framework_finished_at = absolute_time(finished_at.to_datetime) self.controller = data[:controller] self.action = data[:action] self.format = data[:format] self.status = data[:status] end |