class Rollbar::Item::Backtrace
Attributes
configuration[R]
exception[R]
extra[R]
files[R]
message[R]
Public Class Methods
new(exception, options = {})
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 10 def initialize(exception, options = {}) @exception = exception @message = options[:message] @extra = options[:extra] @configuration = options[:configuration] @files = {} end
Public Instance Methods
get_file_lines(filename)
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 33 def get_file_lines(filename) files[filename] ||= read_file(filename) end
to_h()
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 18 def to_h traces = trace_chain traces[0][:exception][:description] = message if message traces[0][:extra] = extra if extra if traces.size > 1 { :trace_chain => traces } elsif traces.size == 1 { :trace => traces[0] } end end
Also aliased as: build
Private Instance Methods
cleaned_backtrace(current_exception)
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 83 def cleaned_backtrace(current_exception) normalized_backtrace = exception_backtrace(current_exception) if configuration.backtrace_cleaner configuration.backtrace_cleaner.clean(normalized_backtrace) else normalized_backtrace end end
exception_backtrace(current_exception)
click to toggle source
Returns the backtrace to be sent to our API. There are 3 options:
-
The exception received has a backtrace, then that backtrace is returned.
-
configuration.populate_empty_backtraces is disabled, we return [] here
-
The user has configuration.populate_empty_backtraces is enabled, then:
We want to send the caller as backtrace, but the first lines of that array are those from the user's Rollbar.error line until this method. We want to remove those lines.
# File lib/rollbar/item/backtrace.rb, line 101 def exception_backtrace(current_exception) if current_exception.backtrace.respond_to?(:map) return current_exception.backtrace end return [] unless configuration.populate_empty_backtraces caller_backtrace = caller caller_backtrace.shift while caller_backtrace[0].include?(rollbar_lib_gem_dir) caller_backtrace end
map_frames(current_exception)
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 75 def map_frames(current_exception) frames = cleaned_backtrace(current_exception).map do |frame| Rollbar::Item::Frame.new(self, frame, :configuration => configuration).to_h end frames.reverse! end
read_file(filename)
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 39 def read_file(filename) return unless File.exist?(filename) File.read(filename).split("\n") rescue StandardError nil end
rollbar_lib_gem_dir()
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 112 def rollbar_lib_gem_dir gem_dir = Gem::Specification.find_by_name('rollbar').gem_dir "#{gem_dir}/lib" end
trace_chain()
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 47 def trace_chain traces = [trace_data(exception)] visited = [exception] current_exception = exception while current_exception.respond_to?(:cause) && (cause = current_exception.cause) && cause.is_a?(Exception) && !visited.include?(cause) traces << trace_data(cause) visited << cause current_exception = cause end traces end
trace_data(current_exception)
click to toggle source
# File lib/rollbar/item/backtrace.rb, line 65 def trace_data(current_exception) { :frames => map_frames(current_exception), :exception => { :class => current_exception.class.name, :message => current_exception.message } } end