lib/sentry/rails/action_cable.rb in sentry-rails-4.9.0 vs lib/sentry/rails/action_cable.rb in sentry-rails-4.9.1

- old
+ new

@@ -1,11 +1,16 @@ module Sentry module Rails module ActionCableExtensions class ErrorHandler class << self - def capture(env, transaction_name:, extra_context: nil, &block) + def capture(connection, transaction_name:, extra_context: nil, &block) + # ActionCable's ConnectionStub (for testing) doesn't implement the exact same interfaces as Connection::Base. + # One thing that's missing is `env`. So calling `connection.env` direclty will fail in test environments when `stub_connection` is used. + # See https://github.com/getsentry/sentry-ruby/pull/1684 for more information. + env = connection.respond_to?(:env) ? connection.env : {} + Sentry.with_scope do |scope| scope.set_rack_env(env) scope.set_context("action_cable", extra_context) if extra_context scope.set_transaction_name(transaction_name) transaction = start_transaction(env, scope.transaction_name) @@ -41,17 +46,17 @@ module Connection private def handle_open - ErrorHandler.capture(env, transaction_name: "#{self.class.name}#connect") do + ErrorHandler.capture(self, transaction_name: "#{self.class.name}#connect") do super end end def handle_close - ErrorHandler.capture(env, transaction_name: "#{self.class.name}#disconnect") do + ErrorHandler.capture(self, transaction_name: "#{self.class.name}#disconnect") do super end end end @@ -67,20 +72,20 @@ private def sentry_capture(hook, &block) extra_context = { params: params } - ErrorHandler.capture(connection.env, transaction_name: "#{self.class.name}##{hook}", extra_context: extra_context, &block) + ErrorHandler.capture(connection, 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 } - ErrorHandler.capture(connection.env, transaction_name: "#{self.class.name}##{action}", extra_context: extra_context) do + ErrorHandler.capture(connection, transaction_name: "#{self.class.name}##{action}", extra_context: extra_context) do super end end end end