Class: ScoutApm::Utils::BacktraceParser

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

Constant Summary collapse

APP_FRAMES =

will return this many backtrace frames from the app stack.

8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call_stack, root = ScoutApm::Agent.instance.context.environment.root) ⇒ BacktraceParser

call_stack - an Array of calls, typically generated via the caller method. Example single line: “/Users/dlite/.rvm/rubies/ruby-2.4.5/lib/ruby/2.4.0/irb/workspace.rb:87:in ‘eval’”



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

def initialize(call_stack, root=ScoutApm::Agent.instance.context.environment.root)
  @call_stack = call_stack
  # We can't use a constant as it'd be too early to fetch environment info
  #
  # This regex looks for files under the app root, inside lib/, app/, and
  # config/ dirs, and captures the path under root.
  @@app_dir_regex = %r[#{root}/((?:lib/|app/|config/).*)]
end

Instance Attribute Details

#call_stackObject (readonly)

Returns the value of attribute call_stack.



12
13
14
# File 'lib/scout_apm/utils/backtrace_parser.rb', line 12

def call_stack
  @call_stack
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/scout_apm/utils/backtrace_parser.rb', line 26

def call
  stack = []
  call_stack.each do |c|
    if m = c.match(@@app_dir_regex)
      stack << ScoutApm::Utils::Scm.relative_scm_path(m[1])
      break if stack.size == APP_FRAMES
    end
  end
  stack
end