def statsd_count_success(method, name, *metric_options)
      add_to_method(method, name, :count_success) do
        define_method(method) do |*args, &block|
          begin
            truthiness = result = super(*args, &block)
          rescue
            truthiness = false
            raise
          else
            truthiness = (yield(result) rescue false) if block_given?
            result
          ensure
            suffix = truthiness == false ? 'failure' : 'success'
            StatsD.increment("#{StatsD::Instrument.generate_metric_name(name, self, *args)}.#{suffix}", 1, *metric_options)
          end
        end
      end
    end
def statsd_count_success(method, name, *metric_options)
      add_to_method(method, name, :count_success) do
        define_method(method) do |*args, &block|
          begin
            truthiness = result = super(*args, &block)
          rescue
            truthiness = false
            raise
          else
            truthiness = (yield(result) rescue false) if block_given?
            result
          ensure
            suffix = truthiness == false ? 'failure' : 'success'
            StatsD.increment("#{StatsD::Instrument.generate_metric_name(name, self, *args)}.#{suffix}", 1, *metric_options)
          end
        end
      end
    end
Adds success and failure counter instrumentation to a method.

 A method call will be considered successful if it does not raise an exception, and the result is true-y.
 For successful calls, the metric <tt>[name].success</tt> will be incremented; for failed calls, the metric
 name is <tt>[name].failure</tt>.

 @param method (see #statsd_measure)
 @param name (see #statsd_measure)
 @param metric_options (see #statsd_measure)
 @yield You can pass a block to this method if you want to define yourself what is a successful call
   based on the return value of the method.
 @yieldparam result The return value of the instrumented method.
 @yieldreturn [Boolean] Return true iff the return value is consisered a success, false otherwise.
 @return [void]
 @see #statsd_count_if