Sha256: 0b39f1c74ed6991463806ad387948ff81f190e1c39fb1b036c464d4357775d62

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 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
              # may be possible to optimize better than #dup
              @exception_frames = @frames.dup
              @exception_signature = exception_signature(tp)
            end
          end
        end
      end

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

      def binding(trace)
        trace.binding
      rescue StandardError
        # Ruby internals will raise if we're on a Fiber,
        # since bindings aren't valid on Fibers.
        nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rollbar-3.6.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.5.2 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.5.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.5.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.4.2 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.4.1 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.4.0 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.3.3 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.3.2 lib/rollbar/notifier/trace_with_bindings.rb
rollbar-3.3.1 lib/rollbar/notifier/trace_with_bindings.rb