Sha256: 065f4a6c8b068a96c3364239ebd110edc71cfdc59f08a20de772e8e84eb32d1b

Contents?: true

Size: 1.61 KB

Versions: 24

Compression:

Stored size: 1.61 KB

Contents

module Rollbar
  class Notifier
    class TraceWithBindings # :nodoc:
      attr_reader :frames, :exception_frames

      def initialize
        reset
      end

      def reset
        @frames = []
        @exception_frames = []
        @exception_signature = nil
      end

      def enable
        reset
        trace_point.enable if defined?(TracePoint)
      end

      def disable
        trace_point.disable if defined?(TracePoint)
      end

      private

      def exception_signature(trace)
        # use the exception backtrace to detect reraised exception.
        trace.raised_exception.backtrace.first
      end

      def detect_reraise(trace)
        @exception_signature == exception_signature(trace)
      end

      def trace_point
        return unless defined?(TracePoint)

        @trace_point ||= TracePoint.new(:call, :return, :b_call, :b_return, :c_call, :c_return, :raise) do |tp|
          case tp.event
          when :call, :b_call, :c_call, :class
            frames.push frame(tp)
          when :return, :b_return, :c_return, :end
            frames.pop
          when :raise
            unless detect_reraise(tp) # ignore reraised exceptions
              @exception_frames = @frames.dup # may be possible to optimize better than #dup
              @exception_signature = exception_signature(tp)
            end
          end
        end
      end

      def frame(trace)
        {
          :binding => trace.binding,
          :defined_class => trace.defined_class,
          :method_id => trace.method_id,
          :path => trace.path,
          :lineno => trace.lineno
        }
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
rollbar-3.2.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.1.2 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.1.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.1.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.0.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.0.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.27.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.27.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.26.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.26.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.25.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.25.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.24.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.23.2 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.23.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.23.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.22.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.22.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.21.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-2.20.2 lib/rollbar/notifier/trace_with_bindings.rb