Sha256: e3f802d03df367b28ed9b29e4b9611f9185e7817b9592530a0badbcd57f5cdef

Contents?: true

Size: 1.61 KB

Versions: 12

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true
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)
            metrics.timing("#{metric_name}.time.db", payload[:db_runtime].round(10), tags: tags) if payload[:db_runtime]



            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

12 entries across 12 versions & 1 rubygems

Version Path
sapience-3.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.15 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.14 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.13 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.12 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.11 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.10 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.9.1 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.8 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.7.0 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.6.1 lib/sapience/extensions/action_controller/notifications.rb
sapience-2.6.0 lib/sapience/extensions/action_controller/notifications.rb