module Erorr class Notification def initialize(exception, params = {}) @exception = exception @params = params end def to_params { class: @exception.class.name, message: @exception.message, location: location, backtrace: backtrace.join("\n"), environment: Erorr.config.env, timestamp: Time.current, fingerprint: fingerprint, host: Socket.gethostname, pid: Process.pid, request_params: @params.dig(:request, :params), request_remote_ip: @params.dig(:request, :remote_ip), request_headers: @params.dig(:request, :headers), } end private def location @params[:location] || $PROGRAM_NAME end def backtrace @_backtrace ||= begin cleaner = ActiveSupport::BacktraceCleaner.new gem_paths.each { |gem_path| cleaner.add_filter { |line| line.sub(gem_path, '') } } cleaner.add_filter { |line| line.sub(Erorr.config.root.to_s, '') } cleaner.add_filter { |line| line.sub('/', '') } cleaner.clean(@exception.backtrace) end end def fingerprint first_backtrace_line = backtrace.find { |trace| trace !~ /pry|irb/ } checksum = [first_backtrace_line, @exception.class].join('|') Digest::SHA1.hexdigest checksum end def gem_paths @gem_paths ||= Gem.path | [Gem.default_dir] end end end