class DogStatsd::Instrumentation::Request::Subscriber
Public Class Methods
new(statsd)
click to toggle source
# File lib/dogstatsd/instrumentation/request.rb, line 28 def initialize(statsd) @statsd = statsd @subscriber = ActiveSupport::Notifications.subscribe /process_action.action_controller/ do |*args| event = ActiveSupport::Notifications::Event.new(*args) tags = { controller: event.payload[:controller], method: event.payload[:method], status: event.payload[:status], } tags[:action] = "#{tags[:controller]}##{event.payload[:action]}" if event.payload[:action] instrument stat: 'process_action.action_controller.duration', value: event.duration, tags: tags event.payload.select { |key, _| key.to_s.end_with? '_runtime' }.each do |name, duration| instrument stat: "process_action.action_controller.#{name}", value: duration, tags: tags end end end
tagify(hash)
click to toggle source
# File lib/dogstatsd/instrumentation/request.rb, line 53 def self.tagify(hash) hash.select { |_, value| value.present? }.map { |key, value| "#{key}:#{value}" } end
Public Instance Methods
instrument(stat:, value:, tags:)
click to toggle source
# File lib/dogstatsd/instrumentation/request.rb, line 49 def instrument(stat:, value:, tags:) @statsd.histogram stat, value, tags: Subscriber.tagify(tags) end
unsubscribe()
click to toggle source
# File lib/dogstatsd/instrumentation/request.rb, line 57 def unsubscribe ActiveSupport::Notifications.unsubscribe @subscriber nil end