Sha256: 3465e9b792a74c8f1aeeb9a4b500f27916bf2f98a42162336c3445e0005417f0

Contents?: true

Size: 1.74 KB

Versions: 28

Compression:

Stored size: 1.74 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require 'new_relic/agent/instrumentation/notifications_subscriber'

module NewRelic
  module Agent
    module Instrumentation
      class ActionDispatchSubscriber < NotificationsSubscriber
        def start(name, id, payload)
          return unless state.is_execution_traced?

          start_segment(name, id, payload)
        rescue => e
          log_notification_error(e, name, 'start')
        end

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

          finish_segment(id, payload)
        rescue => e
          log_notification_error(e, name, 'finish')
        end

        def start_segment(name, id, payload)
          segment = Tracer.start_segment(name: metric_name(name, payload))
          push_segment(id, segment)
        end

        def finish_segment(id, payload)
          if segment = pop_segment(id)
            if exception = exception_object(payload)
              segment.notice_error(exception)
            end
            segment.finish
          end
        end

        def metric_name(name, payload)
          middleware = payload[:middleware]
          method = method_from_name(name)
          "Ruby/ActionDispatch/#{middleware}/#{method}"
        end

        PATTERN = /\A([^\.]+)\.action_dispatch\z/
        UNKNOWN = 'unknown'.freeze

        METHOD_NAME_MAPPING = Hash.new do |h, k|
          if PATTERN =~ k
            h[k] = $1
          else
            h[k] = UNKNOWN
          end
        end

        def method_from_name(name)
          METHOD_NAME_MAPPING[name]
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.5.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.4.2 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/instrumentation/action_dispatch_subscriber.rb