# frozen_string_literal: true class WebLogger def self.log_exception(exception, expected: false, **params) if expected Rails.logger.info("#{exception.class}: #{exception.message}") else backtrace = Rails.backtrace_cleaner.clean(exception.backtrace).join("\n") Rails.logger.error("#{exception.class}: #{exception.message}\n#{backtrace}") ::NewRelic::Agent.notice_error(exception, expected: expected, custom_params: params) if defined?(::NewRelic) end end def self.initialize(request) add_attributes( "request.ip" => request.ip, "request.domain" => request.params[:domain], "request.path" => request.params[:path], ) end def self.add_attributes(**) return unless defined?(::NewRelic) ::NewRelic::Agent.add_custom_attributes(**) end end