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
Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast #24988
Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast #24988
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -1,2 +1,5 @@ | |||
* Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong CHANGELOG.md file 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😳
ef663d0
to
6986b54
Compare
@@ -20,7 +20,10 @@ module Server | |||
module Broadcasting | |||
# Broadcast a hash directly to a named <tt>broadcasting</tt>. This will later be JSON encoded. | |||
def broadcast(broadcasting, message, coder: ActiveSupport::JSON) | |||
broadcaster_for(broadcasting, coder: coder).broadcast(message) | |||
payload = { broadcasting: broadcasting, message: message, coder: coder } | |||
ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in Broadcaster#broadcast
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I put the notification code in the broadcast method on the Broadcasting module since that was the entry point for the public API. After your comment I noticed that broadcaster_for
is part of the public API and returns a Broadcaster instance. Putting the notification in Broadcaster#broadcast
is indeed the best place for the notification code. Thanks for pointing that out!
6986b54
to
35b6382
Compare
This addition of this notification hook will give users better visibility into the messages being sent over the PubSub adapter.
35b6382
to
f3ba0c1
Compare
Summary
ActionCable already has
ActiveSupport::Notifications
hooks around a number of operations inChannel::Base
. It would be nice to gain visibility into messages sent viaActionCable.server.broadcast
. This PR adds a notification hook to the broadcast method that will allow users to monitor and profile the performance messages being sent over the PubSub adapter.