-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActionCable probably doesn't work #470
Comments
Yikes, looks like we haven't looked at ActiveJob in a while either. EDIT: Fixed this since I commented. |
@nateberkopec any ideas if this is being actively developed? I've wrapped most of my ActionCable channel methods, so Sentry is catching what it needs, but native support for this would be awesome. |
any updates? |
I confirm that actioncable exceptions are not being reported on Rails 5.1.2 and sentry-raven 2.5.3 |
Thanks for all the comments, folks. I'll work on this next. |
Thanks @nateberkopec , keep up the nice work on this and the techemporwer bench ;) |
@nateberkopec Anything I can do to help on this? |
@nateberkopec any news on this or a way I can help out? It seems like actioncable is rescuing from |
@nateberkopec Would love to help out with this, searching for a way to catch subscription errors for ActionCable |
👋 Hello all, I no longer maintain raven-ruby. However, what you're looking for is some kind of "middleware" concept for ActionCable. What you need is a way to wrap Sentry "around" an ActionCable response. I'm sure there's ways to do this, I just have no experience with it. After that, simply write up a PR + some tests. Shouldn't be too bad. |
I recently ran into this, wanting Sentry integration into Action Cable, and ended up implementing it like this: module Raven
module Integrations
module ActionCable
class ExceptionReporter
TRANSACTION_PREFIX = 'ActionCable'
def self.capture(env, transaction_name:, extra_context: nil, &block)
Raven.rack_context(env)
Raven.extra_context(action_cable: extra_context) if extra_context
Raven.context.transaction.push [TRANSACTION_PREFIX, transaction_name].join('/')
block.call
rescue Exception => e # rubocop:disable Lint/RescueException
Raven.capture_exception(e)
raise
ensure
Raven.context.transaction.pop
Raven::Context.clear!
end
end
module Channel
module Subscriptions
extend ActiveSupport::Concern
included do
set_callback :subscribe, :around, ->(_, block) { raven_capture(:subscribe, &block) }, prepend: true
set_callback :unsubscribe, :around, ->(_, block) { raven_capture(:unsubscribe, &block) }, prepend: true
end
private
def raven_capture(hook, &block)
extra_context = { params: params }
ExceptionReporter.capture(connection.env, transaction_name: "#{self.class.name}##{hook}", extra_context: extra_context, &block)
end
end
module Actions
private
def dispatch_action(action, data)
extra_context = { params: params, data: data }
ExceptionReporter.capture(connection.env, transaction_name: "#{self.class.name}##{action}", extra_context: extra_context) { super }
end
end
module Connection
private
def handle_open
ExceptionReporter.capture(env, transaction_name: self.class.name) { super }
end
end
end
end
end
ActiveSupport.on_load :action_cable_connection do
prepend Raven::Integrations::ActionCable::Connection
end
ActiveSupport.on_load :action_cable_channel do
include Raven::Integrations::ActionCable::Channel::Subscriptions
prepend Raven::Integrations::ActionCable::Channel::Actions
end
ActiveSupport.on_load :action_cable_channel_test_case do
class ::ActionCable::Channel::ConnectionStub # rubocop:disable Lint/ConstantDefinitionInBlock, Style/ClassAndModuleChildren
def env
@_env ||= ::ActionCable::Connection::TestRequest.create.env # rubocop:disable Rails/SaveBang
end
end
end |
@agrobbin wow this looks great! the 3.x version is now in maintenance mode so we probably won't add ActionCable support to it. but I will add it to the 4.x version's |
Great to hear that it will be added! I couldn't find time to add test coverage, but hopefully that isn't too hard to do with Action Cable's test helpers. There are 2 "gotchas" I should mention ... First off, using the original websocket Secondly, injecting module SentryUserContextActionSupport
private
def dispatch_action(*)
Raven.user_context(id: current_user.id, username: current_user.name, email: current_user.email)
super
end
end
module SentryUserContextSubscriptionSupport
extend ActiveSupport::Concern
included do
set_callback :subscribe, :before, :assign_raven_user_context
set_callback :unsubscribe, :before, :assign_raven_user_context
end
private
def assign_raven_user_context
Raven.user_context(id: current_user.id, username: current_user.name, email: current_user.email)
end
end
ActiveSupport.on_load :action_cable_channel do
# this has to be *before* Sentry's `dispatch_action` integration
prepend SentryUserContextActionSupport
require 'raven/integrations/action_cable/channel'
include Raven::Integrations::ActionCable::Channel::Subscriptions
prepend Raven::Integrations::ActionCable::Channel::Actions
include SentryUserContextSubscriptionSupport
end I didn't want to spend a ton of time right now figuring out a really nice pattern for setting |
Hey @st0012, we running into the same issue of Actioncable errors not ending up in Sentry and wondering whether to roll the implementation above or wait until sentry 4 drops. Do you have any finger-in-the-air estimate of when that might be? |
@thrgamon the new SDK may be ready for production by the end of the next month. but the current goal is to make the new SDK's features match the old one's while increasing the stability of it, this feature should need to wait longer than that. btw, I've implemented the |
Sure, thanks for the context @st0012! |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you label it "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Just realized we probably aren't catching ActionCable exceptions, need to confirm/fix
The text was updated successfully, but these errors were encountered: