Class: ScoutApm::Utils::BacktraceParser

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/utils/backtrace_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(call_stack) ⇒ BacktraceParser

Returns a new instance of BacktraceParser.



9
10
11
12
13
# File 'lib/scout_apm/utils/backtrace_parser.rb', line 9

def initialize(call_stack)
  @call_stack = call_stack
  # We can't use a constant as it'd be too early to fetch environment info
  @@app_dir_regex ||= /\A(#{ScoutApm::Environment.instance.root.to_s.gsub('/','\/')}\/)(app\/(.+))/.freeze
end

Instance Method Details

#callObject

Given a call stack Array, grabs the first call within the application root directory.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scout_apm/utils/backtrace_parser.rb', line 16

def call
  # We used to return an array of up to 5 elements...this will return a single element-array for backwards compatibility.
  # Only the first element is used in Github code display.
  stack = []
  @call_stack.each_with_index do |c,i|
    if m = c.match(@@app_dir_regex)
      stack << m[2]
      break
    end
  end
  stack
end