Class: Bulldogger::FrameSource

Inherits:
Object
  • Object
show all
Defined in:
lib/bulldogger/frame_source.rb

Overview

Turns a :raise TracePoint event into a bounded array of frame descriptions. Prefers DEBUGGER__.capture_frames, which yields every frame's Binding; falls back to TracePoint#binding (raising frame only) plus the exception's backtrace locations (position only, no locals) when debug/frame_info cannot be loaded. That fallback is not a rare edge case: debug is a bundled gem, not a default gem, so under Bundler it is only present when the app's own Gemfile asks for it.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, formatter:, redactor:, skip_path_prefix: self.class.default_skip_path_prefix) ⇒ FrameSource

Returns a new instance of FrameSource.



13
14
15
16
17
18
19
# File 'lib/bulldogger/frame_source.rb', line 13

def initialize(config:, formatter:, redactor:, skip_path_prefix: self.class.default_skip_path_prefix)
  @config = config
  @formatter = formatter
  @redactor = redactor
  @skip_path_prefix = skip_path_prefix
  @mode = nil
end

Class Method Details

.default_skip_path_prefixObject

skip_path_prefix must be this library's lib directory, not the app's. capture_frames drops every frame whose path starts with the given prefix; pointing it at the app's own lib directory was measured to make the app's frames disappear instead of ours, leaving a snapshot with zero useful frames.



26
27
28
# File 'lib/bulldogger/frame_source.rb', line 26

def self.default_skip_path_prefix
  File.expand_path("..", __dir__)
end

Instance Method Details

#capture(tp) ⇒ Object



42
43
44
# File 'lib/bulldogger/frame_source.rb', line 42

def capture(tp)
  mode == :capture_frames ? capture_via_debugger(tp) : capture_degraded(tp)
end

#modeObject



38
39
40
# File 'lib/bulldogger/frame_source.rb', line 38

def mode
  @mode ||= resolve_mode
end

#resolve!Object

:auto resolves once, here, and is cached for the life of this object -- not re-checked on every raise, which would repeat a require check thousands of times in a large suite.



33
34
35
36
# File 'lib/bulldogger/frame_source.rb', line 33

def resolve!
  @mode ||= resolve_mode
  self
end