Sha256: 961cc3c8905344fdc17f033d01d3b2ea47a1f68dd4eadbcd6198f010d06b4b96
Contents?: true
Size: 1.64 KB
Versions: 4
Compression:
Stored size: 1.64 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) 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
4 entries across 4 versions & 1 rubygems