Sha256: a0c05e56717c484abe83e4cc2d1a4b9f8aee5450df676ef50d70f04d034b20d6

Contents?: true

Size: 1.61 KB

Versions: 26

Compression:

Stored size: 1.61 KB

Contents

module Sapience
  module Extensions
    module ActionController
      class Notifications < ::Sapience::Extensions::Notifications
        # Options:
        #
        # *<tt>:metric_name</tt> - the metric name, defaults to "rails.request"
        # *<tt>:tags</tt> - additional tags
        def initialize(options = {})
          @metric_name = options[:metric_name] || "rails.request"
          super
          Sapience::Extensions::Notifications.subscribe("process_action.action_controller") do |event|
            record event
          end
        end

        private

        def record(event) # rubocop:disable AbcSize
          return unless record?

          payload = event.payload
          method  = payload[:method].downcase
          status  = payload[:status]
          action  = payload[:action]
          ctrl    = payload[:controller].sub(/Controller$/, "").underscore
          format  = payload[:format]

          tags    = self.tags + %W(
            method:#{method}
            status:#{status}
            action:#{action}
            controller:#{ctrl}
            format:#{format}
          )

          metrics.batch do
            metrics.increment metric_name, tags: tags
            metrics.timing("#{metric_name}.time", event.duration, tags: tags)
            if payload[:db_runtime]
              metrics.timing("#{metric_name}.time.db", payload[:db_runtime].round(10), tags: tags)
            end



            if payload[:view_runtime]
              metrics.timing("#{metric_name}.time.view", payload[:view_runtime].round(2), tags: tags)
            end
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
sapience-2.4.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.3.5 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.3.4 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.3.3 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.2.3 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.2.1 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.2.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.1.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.5 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.4 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.3 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.2 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.1 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.0.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.15 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.14 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.13 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.12 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.11 lib/sapience/extensions/action_controller/notifications.rb
sapience-1.0.10 lib/sapience/extensions/action_controller/notifications.rb