Class: Sentry::Backtrace Private

Inherits:
Object
  • Object
show all
Extended by:
CallbackHelper
Defined in:
lib/sentry/backtrace.rb,
lib/sentry/backtrace/line.rb

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.

Defined Under Namespace

Classes: Line

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ Backtrace

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 Backtrace.



82
83
84
# File 'lib/sentry/backtrace.rb', line 82

def initialize(lines)
  @lines = lines
end

Instance Attribute Details

#lines ⇒ Object (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.

holder for an Array of Backtrace::Line instances



13
14
15
# File 'lib/sentry/backtrace.rb', line 13

def lines
  @lines
end

Class Method Details

.line_cache ⇒ 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.



69
70
71
# File 'lib/sentry/backtrace.rb', line 69

def self.line_cache
  @line_cache ||= Concurrent::Map.new
end

.parse(backtrace, project_root, app_dirs_pattern, in_app_pattern: nil, &backtrace_cleanup_callback) ⇒ 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.

Deprecated.

project_root, in_app_pattern passed from outside



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sentry/backtrace.rb', line 17

def self.parse(backtrace, project_root, app_dirs_pattern, in_app_pattern: nil, &backtrace_cleanup_callback)
  ruby_lines = backtrace.is_a?(Array) ? backtrace : backtrace.split(/\n\s*/)

  if backtrace_cleanup_callback
    ruby_lines = safe_dispatch_callback(
      "backtrace_cleanup_callback",
      backtrace_cleanup_callback,
      [ruby_lines],
      fallback: ruby_lines
    )
  end

  # in_app_pattern is now passed in from StacktraceBuilder, so this regex won't be triggered
  # only here for backwards compat and will be deleted
  in_app_pattern ||= Regexp.new("^(#{project_root}/)?#{app_dirs_pattern}")

  lines = ruby_lines.to_a.map do |unparsed_line|
    Line.parse(unparsed_line, in_app_pattern)
  end

  new(lines)
end

.source_location ⇒ 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.

Since Sentry is mostly used in production, we don't want to fallback to the slower implementation and adds potentially big overhead to the application.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sentry/backtrace.rb', line 76

def self.source_location(&backtrace_cleaner)
  Thread.each_caller_location do |location|
    frame_key = [location.absolute_path, location.lineno]
    cached_value = line_cache[frame_key]

    next if cached_value == :skip

    if cached_value
      return cached_value
    else
      if cleaned_frame = backtrace_cleaner.(location)
        line = Line.from_source_location(location)
        line_cache[frame_key] = line

        return line
      else
        line_cache[frame_key] = :skip

        next
      end
    end
  end
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.



98
99
100
101
102
103
104
# File 'lib/sentry/backtrace.rb', line 98

def ==(other)
  if other.respond_to?(:lines)
    lines == other.lines
  else
    false
  end
end

#inspect ⇒ 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.



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

def inspect
  "<Backtrace: " + lines.map(&:inspect).join(", ") + ">"
end

#to_s ⇒ 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.



90
91
92
93
94
95
96
# File 'lib/sentry/backtrace.rb', line 90

def to_s
  content = []
  lines.each do |line|
    content << line
  end
  content.join("\n")
end