module Tremolo::ExceptionTracking

Public Class Methods

included(controller) click to toggle source
# File lib/tremolo/exception_tracking.rb, line 4
def self.included(controller)
  controller.rescue_from ::Exception,
    with: :track_exception_with_tremolo_and_raise
end

Public Instance Methods

backtrace_location(exception) click to toggle source
# File lib/tremolo/exception_tracking.rb, line 19
def backtrace_location(exception)
  if exception.respond_to?(:backtrace_locations)
    if location = (exception.backtrace_locations || []).first

      {
        path: location.path,
        line: location.lineno
      }
    else
      {}
    end
  else
    {}
  end
end
backtrace_tags(exception) click to toggle source
# File lib/tremolo/exception_tracking.rb, line 13
def backtrace_tags(exception)
  {
    name: exception.class.name
  }.merge!(backtrace_location(exception))
end
track_exception_with_tremolo(exception) click to toggle source
# File lib/tremolo/exception_tracking.rb, line 9
def track_exception_with_tremolo(exception)
  tracker.increment('exception', backtrace_tags(exception))
end
track_exception_with_tremolo_and_raise(exception) click to toggle source
# File lib/tremolo/exception_tracking.rb, line 35
def track_exception_with_tremolo_and_raise(exception)
  track_exception_with_tremolo(exception)

  # re-raise the exception as normal
  raise exception
end