Class: Sentry::Backtrace::Line Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/backtrace/line.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Handles backtrace parsing line by line

Constant Summary collapse

RB_EXTENSION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

".rb"
CLASS_EXTENSION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

".class"
RUBY_INPUT_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

regexp (optional leading X: on windows, or JRuby9000 class-prefix)

/
  ^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
  (\d+)
  (?: :in\s('|`)(?:([\w:]+)\#)?([^']+)')?$
/x
JAVA_INPUT_FORMAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)

/^([\w$.]+)\.([\w$]+)\(([\w$.]+):(\d+)\)$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, number, method, module_name, in_app_pattern) ⇒ Line

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Line.



77
78
79
80
81
82
83
# File 'lib/sentry/backtrace/line.rb', line 77

def initialize(file, number, method, module_name, in_app_pattern)
  @file = file
  @module_name = module_name
  @number = number.to_i
  @method = method
  @in_app_pattern = in_app_pattern
end

Instance Attribute Details

#fileObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file portion of the line (such as app/models/user.rb)



21
22
23
# File 'lib/sentry/backtrace/line.rb', line 21

def file
  @file
end

#in_app_patternObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/sentry/backtrace/line.rb', line 32

def in_app_pattern
  @in_app_pattern
end

#methodObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The method of the line (such as index)



27
28
29
# File 'lib/sentry/backtrace/line.rb', line 27

def method
  @method
end

#module_nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The module name (JRuby)



30
31
32
# File 'lib/sentry/backtrace/line.rb', line 30

def module_name
  @module_name
end

#numberObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The line number portion of the line



24
25
26
# File 'lib/sentry/backtrace/line.rb', line 24

def number
  @number
end

Class Method Details

.from_source_location(location, in_app_pattern = nil) ⇒ Line

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a Line from a Thread::Backtrace::Location object This is more efficient than converting to string and parsing with regex

Parameters:

  • location (Thread::Backtrace::Location)

    The location object

  • in_app_pattern (Regexp, nil) (defaults to: nil)

    Optional pattern to determine if the line is in-app

Returns:

  • (Line)

    The backtrace line



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sentry/backtrace/line.rb', line 65

def self.from_source_location(location, in_app_pattern = nil)
  file = location.absolute_path
  number = location.lineno
  method = location.base_label

  label = location.label
  index = label.index("#") || label.index(".")
  module_name = label[0, index] if index

  new(file, number, method, module_name, in_app_pattern)
end

.parse(unparsed_line, in_app_pattern = nil) ⇒ Line

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parses a single line of a given backtrace

Parameters:

  • unparsed_line (String)

    The raw line from caller or some backtrace

Returns:

  • (Line)

    The parsed backtrace line



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sentry/backtrace/line.rb', line 37

def self.parse(unparsed_line, in_app_pattern = nil)
  ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)

  if ruby_match
    file = ruby_match[1]
    number = ruby_match[2]
    module_name = ruby_match[4]
    method = ruby_match[5]
    if file.end_with?(CLASS_EXTENSION)
      file.sub!(/\.class$/, RB_EXTENSION)
    end
  else
    java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
    if java_match
      module_name = java_match[1]
      method = java_match[2]
      file = java_match[3]
      number = java_match[4]
    end
  end
  new(file, number, method, module_name, in_app_pattern)
end

Instance Method Details

#==(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
# File 'lib/sentry/backtrace/line.rb', line 97

def ==(other)
  to_s == other.to_s
end

#in_appObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



85
86
87
88
89
90
# File 'lib/sentry/backtrace/line.rb', line 85

def in_app
  return false unless in_app_pattern
  return false unless file

  file.match?(in_app_pattern)
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
# File 'lib/sentry/backtrace/line.rb', line 101

def inspect
  "<Line:#{self}>"
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reconstructs the line in a readable fashion



93
94
95
# File 'lib/sentry/backtrace/line.rb', line 93

def to_s
  "#{file}:#{number}:in `#{method}'"
end