class Sentry::Rails::ActionCableExtensions::ErrorHandler
def capture(connection, transaction_name:, extra_context: nil, &block)
def capture(connection, transaction_name:, extra_context: nil, &block) return block.call unless Sentry.initialized? # 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) scope.set_span(transaction) if transaction begin block.call finish_transaction(transaction, 200) rescue Exception => e # rubocop:disable Lint/RescueException Sentry::Rails.capture_exception(e) finish_transaction(transaction, 500) raise end end end
def finish_transaction(transaction, status_code)
def finish_transaction(transaction, status_code) return unless transaction transaction.set_http_status(status_code) transaction.finish end
def start_transaction(env, transaction_name)
def start_transaction(env, transaction_name) sentry_trace = env["HTTP_SENTRY_TRACE"] options = { name: transaction_name, op: "rails.action_cable".freeze } transaction = Sentry::Transaction.from_sentry_trace(sentry_trace, **options) if sentry_trace Sentry.start_transaction(transaction: transaction, **options) end