Class: Bugsnag::Stacktrace
- Inherits:
-
Object
- Object
- Bugsnag::Stacktrace
- Defined in:
- lib/bugsnag/stacktrace.rb
Constant Summary collapse
- BACKTRACE_LINE_REGEX =
e.g. “org/jruby/RubyKernel.java:1264:in ‘catch’”
/^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/
- JAVA_BACKTRACE_REGEX =
e.g. “org.jruby.Ruby.runScript(Ruby.java:807)”
/^(.*)\((.*)(?::([0-9]+))?\)$/
Instance Method Summary collapse
-
#initialize(backtrace, configuration) ⇒ Stacktrace
constructor
A new instance of Stacktrace.
- #to_a ⇒ Object
Constructor Details
#initialize(backtrace, configuration) ⇒ Stacktrace
Returns a new instance of Stacktrace.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 61 62 |
# File 'lib/bugsnag/stacktrace.rb', line 10 def initialize(backtrace, configuration) @configuration = configuration backtrace = caller if !backtrace || backtrace.empty? @processed_backtrace = backtrace.map do |trace| if trace.match(BACKTRACE_LINE_REGEX) file, line_str, method = [$1, $2, $3] elsif trace.match(JAVA_BACKTRACE_REGEX) method, file, line_str = [$1, $2, $3] end # Parse the stacktrace line # Skip stacktrace lines inside lib/bugsnag next(nil) if file.nil? || file =~ %r{lib/bugsnag(/|\.rb)} # Expand relative paths p = Pathname.new(file) if p.relative? file = p.realpath.to_s rescue file end # Generate the stacktrace line hash trace_hash = {} trace_hash[:inProject] = true if in_project?(file) trace_hash[:lineNumber] = line_str.to_i if configuration.send_code trace_hash[:code] = code(file, trace_hash[:lineNumber]) end # Clean up the file path in the stacktrace if defined?(@configuration.project_root) && @configuration.project_root.to_s != '' file.sub!(/#{@configuration.project_root}\//, "") end # Strip common gem path prefixes if defined?(Gem) file = Gem.path.inject(file) {|line, path| line.sub(/#{path}\//, "") } end trace_hash[:file] = file # Add a method if we have it trace_hash[:method] = method if method && (method =~ /^__bind/).nil? if trace_hash[:file] && !trace_hash[:file].empty? trace_hash else nil end end.compact end |
Instance Method Details
#to_a ⇒ Object
64 65 66 |
# File 'lib/bugsnag/stacktrace.rb', line 64 def to_a @processed_backtrace end |