Class: Logatron::BacktraceCleaner
- Inherits:
-
Object
- Object
- Logatron::BacktraceCleaner
- Defined in:
- lib/logatron/backtrace_cleaner.rb
Instance Method Summary collapse
-
#clean(backtrace) ⇒ Object
Suppress irrelevant “external” frames.
Instance Method Details
#clean(backtrace) ⇒ Object
Suppress irrelevant “external” frames. In practice, these are often the frames leading up to the “entry point” we care about, whether that’s a rails controller or a rabbit_stew handler.
Algorithm: partition frames into contiguous external/internal chunks. Starting at the bottom, suppress chunks until we find the entry point chunk.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/logatron/backtrace_cleaner.rb', line 10 def clean(backtrace) all_chunks = backtrace.chunk { |x| external_frame?(x) }.to_a.reverse good_chunks = all_chunks.drop_while { |(is_ext, frames)| !entry_point_chunk?(is_ext, frames) } bad_chunks = all_chunks.take(all_chunks.size - good_chunks.size) good_bt = good_chunks.reverse.map(&:last).flatten bad_bt = bad_chunks.reverse.map(&:last).flatten good_bt + suppress(bad_bt) rescue # if something went wrong, give up on cleaning the backtrace backtrace end |