Class: Sentry::StacktraceBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/interfaces/stacktrace_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, app_dirs_pattern:, linecache:, context_lines:, backtrace_cleanup_callback: nil) ⇒ StacktraceBuilder

Returns a new instance of StacktraceBuilder.



5
6
7
8
9
10
11
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 5

def initialize(project_root:, app_dirs_pattern:, linecache:, context_lines:, backtrace_cleanup_callback: nil)
  @project_root = project_root
  @app_dirs_pattern = app_dirs_pattern
  @linecache = linecache
  @context_lines = context_lines
  @backtrace_cleanup_callback = backtrace_cleanup_callback
end

Instance Attribute Details

#app_dirs_patternObject (readonly)

Returns the value of attribute app_dirs_pattern.



3
4
5
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 3

def app_dirs_pattern
  @app_dirs_pattern
end

#backtrace_cleanup_callbackObject (readonly)

Returns the value of attribute backtrace_cleanup_callback.



3
4
5
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 3

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#context_linesObject (readonly)

Returns the value of attribute context_lines.



3
4
5
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 3

def context_lines
  @context_lines
end

#linecacheObject (readonly)

Returns the value of attribute linecache.



3
4
5
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 3

def linecache
  @linecache
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



3
4
5
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 3

def project_root
  @project_root
end

Instance Method Details

#build(backtrace:, &frame_callback) ⇒ Object

you can pass a block to customize/exclude frames:

“‘ruby builder.build(backtrace) do |frame|

if frame.module.match?(/a_gem/)
  nil
else
  frame
end

end “‘



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 24

def build(backtrace:, &frame_callback)
  parsed_lines = parse_backtrace_lines(backtrace).select(&:file)

  frames = parsed_lines.reverse.map do |line|
    frame = convert_parsed_line_into_frame(line)
    frame = frame_callback.call(frame) if frame_callback
    frame
  end.compact

  StacktraceInterface.new(frames: frames)
end