<commit_before>require 'statsd-instrument'

module CoAspects
  module Aspects
    # Increments a StatsD key after the method is executed.
    #
    # The key is automatically generated converting the modules, class name and
    # method name into underscores.
    #
    # The key can be overridden via the `as:` option and a dynamic part can be
    # added at the end using a block that receives the same arguments as the
    # method.
    #
    # Examples
    #
    #   module MyModule
    #     class MyClass
    #       aspects_annotations!
    #
    #       _stats_increment
    #       def task1
    #         ...
    #       end
    #
    #       _stats_increment(as: 'my_key') { |arg| arg }
    #       def task2(arg)
    #         ...
    #       end
    #     end
    #   end
    #
    #   MyClass.new.task1
    #   # => StatsD.increment('my_module.my_class.task1')
    #
    #   MyClass.new.task2('dynamic')
    #   # => StatsD.increment('my_key.dynamic')
    class StatsIncrementAspect < Aspector::Base
      around interception_arg: true, method_arg: true do |interception, method, proxy, *args, &block|
        result = proxy.call(*args, &block)

        key = StatsdHelper.key(self.class,
                               method,
                               args,
                               interception.options[:annotation][:as],
                               interception.options[:block])
        StatsD.increment(key)

        result
      end
    end
  end
end<commit_msg>More explicit order between proxy and statsd increment<commit_after>require 'statsd-instrument'

module CoAspects
  module Aspects
    # Increments a StatsD key after the method is executed.
    #
    # The key is automatically generated converting the modules, class name and
    # method name into underscores.
    #
    # The key can be overridden via the `as:` option and a dynamic part can be
    # added at the end using a block that receives the same arguments as the
    # method.
    #
    # Examples
    #
    #   module MyModule
    #     class MyClass
    #       aspects_annotations!
    #
    #       _stats_increment
    #       def task1
    #         ...
    #       end
    #
    #       _stats_increment(as: 'my_key') { |arg| arg }
    #       def task2(arg)
    #         ...
    #       end
    #     end
    #   end
    #
    #   MyClass.new.task1
    #   # => StatsD.increment('my_module.my_class.task1')
    #
    #   MyClass.new.task2('dynamic')
    #   # => StatsD.increment('my_key.dynamic')
    class StatsIncrementAspect < Aspector::Base
      around interception_arg: true, method_arg: true do |interception, method, proxy, *args, &block|
        key = StatsdHelper.key(self.class,
                               method,
                               args,
                               interception.options[:annotation][:as],
                               interception.options[:block])
        result = proxy.call(*args, &block)
        StatsD.increment(key)
        result
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0884196634774002, 'fraction_numerical': 0.003299241174529858, 'mean_word_length': 1.6549912434325744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '127667', 'n_tokens_mistral': 897, 'n_tokens_neox': 878, 'n_words': 230}