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.

Parameters:

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

See Also:



30
31
32
33
34
35
36
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 30

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_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

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:



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 53

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)


67
68
69
70
71
# File 'lib/sentry/interfaces/stacktrace_builder.rb', line 67

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