rollbar-gem
rollbar-gem copied to clipboard
ActionCable errors are not reported
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 Thank you for the report.
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)
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
Are there any plans to add support for Action Cable out of the box?
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