Sha256: 40b80ba05410074b6186827a2016a05116dcdca98f9df42449945b8d1f916a87

Contents?: true

Size: 1.81 KB

Versions: 7

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
require 'new_relic/agent/instrumentation/notifications_subscriber'

module NewRelic
  module Agent
    module Instrumentation
      class ActionCableSubscriber < NotificationsSubscriber
        PERFORM_ACTION = 'perform_action.action_cable'.freeze

        def start(name, id, payload) # THREAD_LOCAL_ACCESS
          return unless state.is_execution_traced?

          finishable = if name == PERFORM_ACTION
            Tracer.start_transaction_or_segment(
              name: transaction_name_from_payload(payload),
              category: :action_cable
            )
          else
            Tracer.start_segment(name: metric_name_from_payload(name, payload))
          end
          push_segment(id, finishable)
        rescue => e
          log_notification_error e, name, 'start'
        end

        def finish(name, id, payload) # THREAD_LOCAL_ACCESS
          return unless state.is_execution_traced?

          if exception = exception_object(payload)
            NewRelic::Agent.notice_error exception
          end

          finishable = pop_segment(id)
          finishable.finish if finishable
        rescue => e
          log_notification_error e, name, 'finish'
        end

        private

        def transaction_name_from_payload(payload)
          "Controller/ActionCable/#{payload[:channel_class]}/#{payload[:action]}"
        end

        def metric_name_from_payload(name, payload)
          "Ruby/ActionCable/#{payload[:channel_class]}/#{action_name(name)}"
        end

        DOT_ACTION_CABLE = '.action_cable'.freeze

        def action_name(name)
          name.gsub DOT_ACTION_CABLE, NewRelic::EMPTY_STR
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
newrelic_rpm-8.9.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.8.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.7.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.6.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.5.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.4.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb
newrelic_rpm-8.3.0 lib/new_relic/agent/instrumentation/action_cable_subscriber.rb