<commit_before>module Datadog::Notifications::Plugins
  class Grape < Base

    attr_reader :metric_name

    # Options:
    #
    # *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
    # *<tt>:tags</tt> - additional tags
    def initialize(opts = {})
      super
      @metric_name = opts[:metric_name] || "grape.request"

      Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
        record reporter, event
      end
    end

    private

    def record(reporter, event)
      payload  = event.payload
      endpoint = payload[:endpoint]
      route    = endpoint.route
      version  = route.route_version
      method   = route.route_method

      path = route.route_path.dup
      path.sub!(/\(\.\:format\)$/, '')
      path.sub!(":version/", "") if version
      path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
      path.gsub!(/[^\w\/\-]+/, '_')

      tags = self.tags + %W|method:#{method} path:#{path} status:#{endpoint.status}|
      tags.push "version:#{version}" if version

      reporter.batch do
        reporter.increment metric_name, tags: tags
        reporter.timing "#{metric_name}.time", event.duration, tags: tags
      end
    end

  end<commit_msg>Bump grape<commit_after>module Datadog::Notifications::Plugins
  class Grape < Base

    attr_reader :metric_name

    # Options:
    #
    # *<tt>:metric_name</tt> - the metric name, defaults to "grape.request"
    # *<tt>:tags</tt> - additional tags
    def initialize(opts = {})
      super
      @metric_name = opts[:metric_name] || "grape.request"

      Datadog::Notifications.subscribe 'endpoint_run.grape' do |reporter, event|
        record reporter, event
      end
    end

    private

    def record(reporter, event)
      payload  = event.payload
      endpoint = payload[:endpoint]
      route    = endpoint.route
      version  = route.version
      method   = route.request_method

      path = route.pattern.path.dup
      path.sub!(/\(\.\:format\)$/, '')
      path.sub!(":version/", "") if version
      path.gsub!(/:(\w+)/) {|m| m[1..-1].upcase }
      path.gsub!(/[^\w\/\-]+/, '_')

      tags = self.tags + %W|method:#{method} path:#{path} status:#{endpoint.status}|
      tags.push "version:#{version}" if version

      reporter.batch do
        reporter.increment metric_name, tags: tags
        reporter.timing "#{metric_name}.time", event.duration, tags: tags
      end
    end

  end
{'fraction_non_alphanumeric': 0.15356113627006998, 'fraction_numerical': 0.0016467682173734047, 'mean_word_length': 2.5268505079825836, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, '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': '5439495', 'n_tokens_mistral': 784, 'n_tokens_neox': 772, 'n_words': 162}