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]+))?\)$/
- VENDOR_PATH =
Path to vendored code. Used to mark file paths as out of project.
/^(vendor\/|\.bundle\/)/
Instance Method Summary collapse
-
#initialize(backtrace, configuration) ⇒ Stacktrace
constructor
Process a backtrace and the configuration into a parsed stacktrace.
-
#to_a ⇒ Object
Returns the processed backtrace.
Constructor Details
#initialize(backtrace, configuration) ⇒ Stacktrace
Process a backtrace and the configuration into a parsed stacktrace.
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 63 64 65 66 67 68 69 70 |
# File 'lib/bugsnag/stacktrace.rb', line 15 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[: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 != '' trace_hash[:inProject] = true if file.start_with?(@configuration.project_root.to_s) file.sub!(/#{@configuration.project_root}\//, "") trace_hash.delete(:inProject) if file.match(VENDOR_PATH) 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
Returns the processed backtrace
74 75 76 |
# File 'lib/bugsnag/stacktrace.rb', line 74 def to_a @processed_backtrace end |