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, strip_backtrace_load_path: true) ⇒ StacktraceBuilder

Returns a new instance of StacktraceBuilder.

Parameters:

  • project_root (String)
  • app_dirs_pattern (Regexp, nil)
  • linecache (LineCache)
  • context_lines (Integer, nil)
  • backtrace_cleanup_callback (Proc, nil) (defaults to: nil)
  • strip_backtrace_load_path (Boolean) (defaults to: true)

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 40

def initialize(
  project_root:,
  app_dirs_pattern:,
  linecache:,
  context_lines:,
  backtrace_cleanup_callback: nil,
  strip_backtrace_load_path: true
)
  @project_root = project_root
  @app_dirs_pattern = app_dirs_pattern
  @linecache = linecache
  @context_lines = context_lines
  @backtrace_cleanup_callback = backtrace_cleanup_callback
  @strip_backtrace_load_path = strip_backtrace_load_path
  @in_app_pattern = Regexp.new("^(#{project_root}/)?#{app_dirs_pattern}") if app_dirs_pattern
  @filename_cache = FilenameCache.new(project_root)
end

Instance Attribute Details

#app_dirs_patternRegexp? (readonly)

Returns:

  • (Regexp, nil)


11
12
13
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 11

def app_dirs_pattern
  @app_dirs_pattern
end

#backtrace_cleanup_callbackProc? (readonly)

Returns:

  • (Proc, nil)


20
21
22
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 20

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#context_linesInteger? (readonly)

Returns:

  • (Integer, nil)


17
18
19
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 17

def context_lines
  @context_lines
end

#filename_cacheFilenameCache (readonly)

Returns:

  • (FilenameCache)


26
27
28
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 26

def filename_cache
  @filename_cache
end

#linecacheLineCache (readonly)

Returns:



14
15
16
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 14

def linecache
  @linecache
end

#project_rootString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 8

def project_root
  @project_root
end

#strip_backtrace_load_pathBoolean (readonly)

Returns:

  • (Boolean)


23
24
25
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 23

def strip_backtrace_load_path
  @strip_backtrace_load_path
end

Instance Method Details

#build(backtrace:, &frame_callback) {|frame| ... } ⇒ StacktraceInterface

Generates a StacktraceInterface with the given backtrace. You can pass a block to customize/exclude frames:

Examples:

builder.build(backtrace) do |frame|
  if frame.module.match?(/a_gem/)
    nil
  else
    frame
  end
end

Parameters:

  • backtrace (Array<String>)
  • frame_callback (Proc)

Yield Parameters:

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 73

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

  # Build frames in reverse order, skipping lines without files
  # Single pass instead of select + reverse + map + compact
  frames = []
  i = parsed_lines.size - 1
  while i >= 0
    line = parsed_lines[i]
    i -= 1
    next unless line.file

    frame = convert_parsed_line_into_frame(line)
    frame = frame_callback.call(frame) if frame_callback
    frames << frame if frame
  end

  StacktraceInterface.new(frames: frames)
end