lib/appsignal/transaction.rb in appsignal-0.6.7 vs lib/appsignal/transaction.rb in appsignal-0.7.0.alpha.1

- old
+ new

@@ -1,9 +1,5 @@ -require 'socket' -require 'appsignal/transaction/transaction_formatter' -require 'appsignal/transaction/params_sanitizer' - module Appsignal class Transaction # Based on what Rails uses + some variables we'd like to show ENV_METHODS = %w(CONTENT_LENGTH AUTH_TYPE GATEWAY_INTERFACE PATH_TRANSLATED REMOTE_HOST REMOTE_IDENT REMOTE_USER REMOTE_ADDR @@ -24,11 +20,11 @@ def self.current Appsignal.transactions[Thread.current[:appsignal_transaction_id]] end attr_reader :request_id, :events, :process_action_event, :action, :exception, - :env, :fullpath, :time, :tags + :env, :fullpath, :time, :tags def initialize(request_id, env) @request_id = request_id @events = [] @process_action_event = nil @@ -44,11 +40,11 @@ def sanitized_session_data @sanitized_session_data ||= {} end def request - ActionDispatch::Request.new(@env) + ::Rack::Request.new(@env) end def set_tags(given_tags={}) @tags.merge!(given_tags) end @@ -73,12 +69,11 @@ !!exception end def slow_request? return false unless process_action_event && process_action_event.payload - Appsignal.config[:slow_request_threshold] <= - process_action_event.duration + Appsignal.config[:slow_request_threshold] <= process_action_event.duration end def slower?(transaction) process_action_event.duration > transaction.process_action_event.duration end @@ -91,23 +86,23 @@ sanitized_session_data.clear @env = nil end def convert_values_to_primitives! - Appsignal::ParamsSanitizer.sanitize!(@process_action_event.payload) if @process_action_event - @events.each { |o| Appsignal::ParamsSanitizer.sanitize!(o.payload) } + Appsignal::Transaction::ParamsSanitizer.sanitize!(@process_action_event.payload) if @process_action_event + @events.each { |o| Appsignal::Transaction::ParamsSanitizer.sanitize!(o.payload) } add_sanitized_context! end def type return :exception if exception? return :slow_request if slow_request? :regular_request end def to_hash - TransactionFormatter.new(self).to_hash + Formatter.new(self).to_hash end def complete! Appsignal.logger.debug("Completing transaction: #{@request_id}") Thread.current[:appsignal_transaction_id] = nil @@ -119,10 +114,21 @@ end end protected + def http_queue_start + return unless env + env_var = env['HTTP_X_QUEUE_START'] || env['HTTP_X_REQUEST_START'] + if env_var + value = env_var.tr('^0-9', '') + unless value.empty? + value.to_f / 1_000_000 + end + end + end + def add_sanitized_context! sanitize_environment! sanitize_session_data! sanitize_tags! @env = nil @@ -145,10 +151,10 @@ end end def sanitize_session_data! @sanitized_session_data = - Appsignal::ParamsSanitizer.sanitize(request.session.to_hash) + Appsignal::Transaction::ParamsSanitizer.sanitize(request.session.to_hash) @fullpath = request.fullpath end end end