def statsd_count_if(method, name, *metric_options)
      add_to_method(method, name, :count_if) 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
            StatsD.increment(StatsD::Instrument.generate_metric_name(name, self, *args), *metric_options) if truthiness
          end
        end
      end
    end
def statsd_count_if(method, name, *metric_options)
      add_to_method(method, name, :count_if) 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
            StatsD.increment(StatsD::Instrument.generate_metric_name(name, self, *args), *metric_options) if truthiness
          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.
 Only for successful calls, the metric will be icnremented

 @param method (see #statsd_measure)
 @param name (see #statsd_measure)
 @param metric_options (see #statsd_measure)
 @yield (see #statsd_count_success)
 @yieldparam result (see #statsd_count_success)
 @yieldreturn (see #statsd_count_success)
 @return [void]
 @see #statsd_count_success