Class: Radar::Matchers::BacktraceMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/radar/matchers/backtrace_matcher.rb

Overview

A matcher which matches exceptions which contain a certain file in their backtrace.

app.config.match :backtrace, "my_file"
app.config.match :backtrace, %r{lib/my_application}
app.config.match :backtrace, %r{lib/my_application}, :depth => 5

By default this will search the entire backtrace, unless a depth is specified.

Instance Method Summary collapse

Constructor Details

#initialize(file, opts = nil) ⇒ BacktraceMatcher

Returns a new instance of BacktraceMatcher.



13
14
15
16
# File 'lib/radar/matchers/backtrace_matcher.rb', line 13

def initialize(file, opts=nil)
  @file = file
  @opts = { :depth => nil }.merge(opts || {})
end

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/radar/matchers/backtrace_matcher.rb', line 18

def matches?(event)
  return false if !event.exception.backtrace

  event.exception.backtrace.each_with_index do |line, depth|
    return true if @file.is_a?(Regexp) && line =~ @file
    return true if @file.is_a?(String) && line.include?(@file)
    return false if @opts[:depth] && @opts[:depth].to_i <= (depth + 1)
  end

  false
end