lib/appsignal/transaction.rb in appsignal-0.11.13.beta.2 vs lib/appsignal/transaction.rb in appsignal-0.11.13.beta.3

- old
+ new

@@ -9,14 +9,14 @@ 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 HTTP_X_FORWARDED_FOR HTTP_CLIENT_IP).freeze - def self.create(request_id, env) + def self.create(request_id, env, defaults={}) Appsignal.logger.debug("Creating transaction: #{request_id}") Thread.current[:appsignal_transaction_id] = request_id - Appsignal::Transaction.new(request_id, env) + Appsignal::Transaction.new(request_id, env, defaults) end def self.current Appsignal.transactions[Thread.current[:appsignal_transaction_id]] end @@ -29,31 +29,38 @@ Appsignal.logger.error('Trying to complete current, but no transaction present') end end attr_reader :request_id, :events, :process_action_event, :action, :exception, - :env, :fullpath, :time, :tags, :kind, :queue_start, :paused + :env, :fullpath, :time, :tags, :kind, :queue_start, :paused, :params - def initialize(request_id, env) + def initialize(request_id, env, defaults={}) Appsignal.transactions[request_id] = self - @request_id = request_id - @events = [] + @request_id = request_id + @events = [] @process_action_event = nil - @exception = {} - @env = env - @tags = {} - @paused = false + @exception = {} + @env = env + @params = defaults[:params] || {} + @tags = defaults[:tags] || {} + @kind = defaults[:kind] || 'web' + @action = defaults[:action] + @paused = false end def sanitized_environment @sanitized_environment ||= {} end def sanitized_session_data @sanitized_session_data ||= {} end + def sanitized_params + @sanitized_params ||= {} + end + def request ::Rack::Request.new(@env) end def set_tags(given_tags={}) @@ -66,18 +73,10 @@ def resume! @paused = false end - def set_kind(kind) - @kind = kind - end - - def set_action(action) - @action = action - end - def set_process_action_event(event) return unless event && event.payload @process_action_event = event.dup if @process_action_event.payload[:controller] @action = "#{@process_action_event.payload[:controller]}##{@process_action_event.payload[:action]}" @@ -142,10 +141,11 @@ process_action_event.truncate! events.clear tags.clear sanitized_environment.clear sanitized_session_data.clear + sanitized_params.clear @env = nil @truncated = true end def truncated? @@ -219,10 +219,11 @@ def add_sanitized_context! sanitize_environment! sanitize_session_data! if kind == 'http_request' sanitize_tags! + sanitize_params! @env = nil end # Only keep tags if they meet the following criteria: # * Key is a symbol or string with less then 100 chars @@ -234,19 +235,24 @@ (((v.is_a?(Symbol) || v.is_a?(String)) && v.length <= 100) || (v.is_a?(Integer))) end end def sanitize_environment! - return unless env + return unless env && env.keys.any? ENV_METHODS.each do |key| sanitized_environment[key] = env[key] end end def sanitize_session_data! @sanitized_session_data = Appsignal::ParamsSanitizer.sanitize( request.session.to_hash ) if Appsignal.config[:skip_session_data] == false @fullpath = request.fullpath + end + + def sanitize_params! + return unless Appsignal.config[:send_params] + @sanitized_params = Appsignal::ParamsSanitizer.sanitize(@params) end end end