class Sqreen::RequestRecord

When a request is deeemed worthy of being sent to the backend

Attributes

redactor[R]

Public Class Methods

new(payload, redactor = nil) click to toggle source

@param [Hash] payload @param [Sqreen::SensitiveDataRedactor] redactor

Calls superclass method Sqreen::Event::new
# File lib/sqreen/events/request_record.rb, line 20
def initialize(payload, redactor = nil)
  @redactor = redactor
  super(payload)
end

Public Instance Methods

last_identify_args() click to toggle source
# File lib/sqreen/events/request_record.rb, line 29
def last_identify_args
  return nil unless observed[:sdk]

  observed[:sdk].reverse_each do |meth, _time, *args|
    next unless meth == :identify
    return args
  end
  nil
end
observed() click to toggle source
# File lib/sqreen/events/request_record.rb, line 25
def observed
  (payload && payload[:observed]) || {}
end
processed_sdk_calls() click to toggle source
# File lib/sqreen/events/request_record.rb, line 39
def processed_sdk_calls
  return [] unless observed[:sdk]
  auth_keys = last_identify_id

  observed[:sdk].map do |meth, time, *args|
    {
      :name => meth,
      :time => time,
      :args => inject_identifiers(args, meth, auth_keys),
    }
  end
end

Private Instance Methods

inject_identifiers(args, meth, auth_keys) click to toggle source
# File lib/sqreen/events/request_record.rb, line 54
def inject_identifiers(args, meth, auth_keys)
  return args unless meth == :track && auth_keys

  track_opts = args[1] || {}
  if track_opts[:user_identifiers].nil?
    args[1] = track_opts.dup
    args[1][:user_identifiers] = auth_keys
  elsif track_opts[:user_identifiers] != auth_keys
    Sqreen.log.warn 'Sqreen.identify and Sqreen.track have been called ' \
                      'with different user_identifiers values'
  end

  args
end
last_identify_id() click to toggle source
# File lib/sqreen/events/request_record.rb, line 69
def last_identify_id
  args = last_identify_args
  args.first if args.respond_to? :first
end