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:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 35

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
end

Instance Attribute Details

#app_dirs_patternRegexp? (readonly)

Returns:

  • (Regexp, nil)


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

def app_dirs_pattern
  @app_dirs_pattern
end

#backtrace_cleanup_callbackProc? (readonly)

Returns:

  • (Proc, nil)


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

def backtrace_cleanup_callback
  @backtrace_cleanup_callback
end

#context_linesInteger? (readonly)

Returns:

  • (Integer, nil)


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

def context_lines
  @context_lines
end

#linecacheLineCache (readonly)

Returns:



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

def linecache
  @linecache
end

#project_rootString (readonly)

Returns:

  • (String)


6
7
8
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 6

def project_root
  @project_root
end

#strip_backtrace_load_pathBoolean (readonly)

Returns:

  • (Boolean)


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

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:



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

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

#metrics_code_location(unparsed_line) ⇒ Hash

Get the code location hash for a single line for where metrics where added.

Returns:

  • (Hash)


80
81
82
83
84
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 80

def metrics_code_location(unparsed_line)
  parsed_line = Backtrace::Line.parse(unparsed_line)
  frame = convert_parsed_line_into_frame(parsed_line)
  frame.to_hash.reject { |k, _| %i[project_root in_app].include?(k) }
end