Class: Errplane::ExceptionPresenter
- Inherits:
-
Object
- Object
- Errplane::ExceptionPresenter
- Defined in:
- lib/errplane/exception_presenter.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#custom_data ⇒ Object
readonly
Returns the value of attribute custom_data.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#request_url ⇒ Object
readonly
Returns the value of attribute request_url.
-
#session_data ⇒ Object
readonly
Returns the value of attribute session_data.
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #calculate_hash ⇒ Object
- #context ⇒ Object
-
#initialize(e, params = {}) ⇒ ExceptionPresenter
constructor
A new instance of ExceptionPresenter.
- #reporter ⇒ Object
- #request_data ⇒ Object
- #time_series_name ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(e, params = {}) ⇒ ExceptionPresenter
Returns a new instance of ExceptionPresenter.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/errplane/exception_presenter.rb', line 18 def initialize(e, params = {}) e = e.continued_exception if e.respond_to?(:continued_exception) e = e.original_exception if e.respond_to?(:original_exception) @exception = e.is_a?(String) ? Exception.new(e) : e @backtrace = Errplane::Backtrace.new(@exception.backtrace).to_a || [] @params = params[:params] @session_data = params[:session_data] @controller = params[:controller] @action = params[:action] @request_url = params[:request_url] @user_agent = params[:user_agent] @custom_data = params[:custom_data] || {} @environment_variables = ENV.to_hash || {} end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
13 14 15 |
# File 'lib/errplane/exception_presenter.rb', line 13 def action @action end |
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
9 10 11 |
# File 'lib/errplane/exception_presenter.rb', line 9 def backtrace @backtrace end |
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
12 13 14 |
# File 'lib/errplane/exception_presenter.rb', line 12 def controller @controller end |
#custom_data ⇒ Object (readonly)
Returns the value of attribute custom_data.
16 17 18 |
# File 'lib/errplane/exception_presenter.rb', line 16 def custom_data @custom_data end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
8 9 10 |
# File 'lib/errplane/exception_presenter.rb', line 8 def exception @exception end |
#hash ⇒ Object
Returns the value of attribute hash.
6 7 8 |
# File 'lib/errplane/exception_presenter.rb', line 6 def hash @hash end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/errplane/exception_presenter.rb', line 10 def params @params end |
#request_url ⇒ Object (readonly)
Returns the value of attribute request_url.
14 15 16 |
# File 'lib/errplane/exception_presenter.rb', line 14 def request_url @request_url end |
#session_data ⇒ Object (readonly)
Returns the value of attribute session_data.
11 12 13 |
# File 'lib/errplane/exception_presenter.rb', line 11 def session_data @session_data end |
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
15 16 17 |
# File 'lib/errplane/exception_presenter.rb', line 15 def user_agent @user_agent end |
Instance Method Details
#calculate_hash ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/errplane/exception_presenter.rb', line 62 def calculate_hash if hash hash elsif Errplane.configuration.aggregated_exception_classes.include?(@exception.class.to_s) Digest::SHA1.hexdigest(@exception.class.to_s) else Digest::SHA1.hexdigest(@exception.class.to_s + @backtrace.first.to_s) end end |
#context ⇒ Object
76 77 78 |
# File 'lib/errplane/exception_presenter.rb', line 76 def context Base64.strict_encode64(to_json) end |
#reporter ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/errplane/exception_presenter.rb', line 80 def reporter { :name => "Errplane", :version => Errplane::VERSION, :url => "https://github.com/errplane/errplane-ruby" } end |
#request_data ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/errplane/exception_presenter.rb', line 88 def request_data { :params => @params, :session_data => @session_data, :controller => @controller, :action => @action, :request_url => @request_url, :user_agent => @user_agent } end |
#time_series_name ⇒ Object
72 73 74 |
# File 'lib/errplane/exception_presenter.rb', line 72 def time_series_name "exceptions/" + calculate_hash end |
#to_json ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/errplane/exception_presenter.rb', line 34 def to_json payload = { :time => Time.now.utc.to_i, :application_name => Errplane.configuration.application_name, :application_root => Errplane.configuration.application_root, :framework => Errplane.configuration.framework, :framework_version => Errplane.configuration.framework_version, :message => @exception., :backtrace => @backtrace, :exception_class => @exception.class.to_s, :language => "Ruby", :language_version => "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}", :reporter => reporter, :hostname => Socket.gethostname, :custom_data => @custom_data } payload[:environment_variables] = @environment_variables.reject do |k,v| Errplane.configuration.environment_variable_filters.any? { |filter| k =~ filter } end Errplane.configuration.add_custom_exception_data(self) payload[:request_data] = request_data if @controller || @action || !@params.blank? payload[:hash] = calculate_hash payload.to_json end |