aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/action_cable/channel/base.rb
diff options
context:
space:
mode:
authorMatthew Wear <matthew.wear@gmail.com>2016-02-16 11:06:35 -0800
committerMatthew Wear <matthew.wear@gmail.com>2016-03-04 14:47:54 -0800
commit09a1321d5b57111edc273f68f428e4ee5471ed5c (patch)
tree306fcbd86405b85f36f02271c4d40ade1279f4de /actioncable/lib/action_cable/channel/base.rb
parent54286878c637e976223e06c4c78877d00112add1 (diff)
downloadrails-09a1321d5b57111edc273f68f428e4ee5471ed5c.tar.gz
rails-09a1321d5b57111edc273f68f428e4ee5471ed5c.tar.bz2
rails-09a1321d5b57111edc273f68f428e4ee5471ed5c.zip
Add AS::Notifications and LogSubscriber to ActionCable::Channel
This commit adds ActiveSupport::Notifications instrumentation hooks and a LogSuscriber to ActionCable::Channel::Base.
Diffstat (limited to 'actioncable/lib/action_cable/channel/base.rb')
-rw-r--r--actioncable/lib/action_cable/channel/base.rb24
1 files changed, 16 insertions, 8 deletions
diff --git a/actioncable/lib/action_cable/channel/base.rb b/actioncable/lib/action_cable/channel/base.rb
index 714d9887d4..a0319eb522 100644
--- a/actioncable/lib/action_cable/channel/base.rb
+++ b/actioncable/lib/action_cable/channel/base.rb
@@ -1,3 +1,4 @@
+require 'action_cable/channel/log_subscriber'
require 'set'
module ActionCable
@@ -160,7 +161,10 @@ module ActionCable
action = extract_action(data)
if processable_action?(action)
- dispatch_action(action, data)
+ payload = { channel_class: self.class.name, action: action, data: data }
+ ActiveSupport::Notifications.instrument("perform_action.action_cable", payload) do
+ dispatch_action(action, data)
+ end
else
logger.error "Unable to process #{action_signature(action, data)}"
end
@@ -191,8 +195,10 @@ module ActionCable
# Transmit a hash of data to the subscriber. The hash will automatically be wrapped in a JSON envelope with
# the proper channel identifier marked as the recipient.
def transmit(data, via: nil)
- logger.info "#{self.class.name} transmitting #{data.inspect.truncate(300)}".tap { |m| m << " (via #{via})" if via }
- connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, message: data)
+ payload = { channel_class: self.class.name, data: data, via: via }
+ ActiveSupport::Notifications.instrument("transmit.action_cable", payload) do
+ connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, message: data)
+ end
end
def defer_subscription_confirmation!
@@ -264,9 +270,10 @@ module ActionCable
def transmit_subscription_confirmation
unless subscription_confirmation_sent?
- logger.info "#{self.class.name} is transmitting the subscription confirmation"
- connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:confirmation])
- @subscription_confirmation_sent = true
+ ActiveSupport::Notifications.instrument("transmit_subscription_confirmation.action_cable", channel_class: self.class.name) do
+ connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:confirmation])
+ @subscription_confirmation_sent = true
+ end
end
end
@@ -276,8 +283,9 @@ module ActionCable
end
def transmit_subscription_rejection
- logger.info "#{self.class.name} is transmitting the subscription rejection"
- connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:rejection])
+ ActiveSupport::Notifications.instrument("transmit_subscription_rejection.action_cable", channel_class: self.class.name) do
+ connection.transmit ActiveSupport::JSON.encode(identifier: @identifier, type: ActionCable::INTERNAL[:message_types][:rejection])
+ end
end
end
end