rollbar-gem icon indicating copy to clipboard operation
rollbar-gem copied to clipboard

ActionCable errors are not reported

Open husam212 opened this issue 6 years ago • 6 comments

husam212 avatar Jul 23 '19 13:07 husam212

I've fixed it by monkey patching ActionCable in initializer.

module ActionCable
  module Channel

    class Base
      alias perform_action_without_rollbar perform_action

      def perform_action(*args, &block)
        perform_action_without_rollbar(*args, &block)
      rescue Exception => exception
        Rollbar.error(exception)
        raise exception
      end
    end

  end
end

EDIT: The above fix doesn't work for subscription errors, the following works better.

module ActionCable
  module Connection

    class Subscriptions
      alias execute_command_without_rollbar execute_command

      def execute_command(*args, &block)
        execute_command_without_rollbar(*args, &block)
      rescue Exception => exception
        Rollbar.error(exception)
        raise exception
      end
    end

  end
end

husam212 avatar Jul 23 '19 13:07 husam212

@husam212 Thank you for the report.

waltjones avatar Jul 23 '19 17:07 waltjones

to help anyone else, I was able to do this using the above monkey-patch as a guide but using prepend instead. I implemented both because I wasn't entirely sure if it was only needed in one place or not

module ActionCableRollbarSupport
  module Channel
    def perform_action(data)
      super
    rescue Exception => exception
      Rollbar.error(exception)
      raise exception
    end
  end

  module Connection
    def execute_command(data)
      super
    rescue Exception => exception
      Rollbar.error(exception)
      raise exception
    end
  end
end

ActionCable::Channel::Base.send(:prepend, ActionCableRollbarSupport::Channel)
ActionCable::Connection::Subscriptions.send(:prepend, ActionCableRollbarSupport::Connection)

ideasasylum avatar Nov 26 '19 11:11 ideasasylum

Code above is not working anymore. Rails ActionCable in master is allowing to use rescue_from gracefully. For 6.0.X < rails =< 6.1 I applied that patch:

# turn on reporting by rollbar errors on action cable server
# https://github.com/rollbar/rollbar-gem/issues/894
module ActionCableEnhancements
  module RollbarReport
    def add(data)
      super
    rescue Exception => e # rubocop:disable Lint/RescueException
      Rollbar.error(e)
      raise e
    end

    def perform_action(data)
      super
    rescue Exception => e # rubocop:disable Lint/RescueException
      Rollbar.error(e)
      raise e
    end

    def remove(data)
      super
    rescue Exception => e # rubocop:disable Lint/RescueException
      Rollbar.error(e)
      raise e
    end
  end
end

ActionCable::Connection::Subscriptions.prepend ActionCableEnhancements::RollbarReport

choosen avatar Aug 13 '20 12:08 choosen

Are there any plans to add support for Action Cable out of the box?

morgoth avatar Jun 02 '22 09:06 morgoth

FYI, Action Cable provides exception handling that can be used to forward errors to Rollbar:

# app/channels/application_cable/connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    rescue_from StandardError, with: :report_error

    private
      def report_error(e)
        Rollbar.error(e)
      end
  end
end

noahfpf avatar Jan 28 '24 15:01 noahfpf