module Sentry

def exception_locals_tp

@!visibility private
def exception_locals_tp
  @exception_locals_tp ||= TracePoint.new(:raise) do |tp|
    exception = tp.raised_exception
    # don't collect locals again if the exception is re-raised
    next if exception.instance_variable_get(:@sentry_locals)
    next unless tp.binding
    locals = tp.binding.local_variables.each_with_object({}) do |local, result|
      result[local] = tp.binding.local_variable_get(local)
    end
    exception.instance_variable_set(:@sentry_locals, locals)
  end
end