<commit_before>require 'new_relic/agent/method_tracer'
require 'new_relic/agent/instrumentation/controller_instrumentation'

DependencyDetection.defer do
  @name = :carrierwave

  depends_on do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Instrumentation'
    defined?(::CarrierWave) &&
    !NewRelic::Control.instance['disable_carrierwave'] &&
    ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
  end

  executes do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Instrumentation'
  end

  executes do
    ::CarrierWave::Storage::Fog.class_eval do
      def call_store_with_newrelic_trace(file)

        metrics = ["External/CarrierWave/Fog"]

        if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
          total_metric = 'External/allWeb'
        else
          total_metric = 'External/allOther'
        end
        metrics << total_metric
        self.class.trace_execution_scoped(metrics) do
          call_storage_without_newrelic_trace(file)
        end
      end

      def call_retrieve_with_newrelic_trace(identifier)
        metrics = ["Custom/CarrierWave/Retrieve"]
        self.class.trace_execution_scoped(metrics) do
          call_retrieve_without_newrelic_trace(identifier)
        end
      end

      alias :call_store_without_newrelic_trace :store!
      alias :store! :call_store_with_newrelic_trace

      alias :call_retrieve_without_newrelic_trace :retrieve!
      alias :retrieve! :call_retrieve_with_newrelic_trace
    end

    ::CarrierWave::Uploader::Versions::ClassMethods.class_eval do

      def version_with_newrelic_trace(name, options = {}, &block)
        metrics = ["Custom/CarrierWave/Version/#{name}"]
        self.class.trace_execution_scoped(metrics) do
          version_without_newrelic_trace(name, options, &block)
        end
      end

      alias :version_without_newrelic_trace :version
      alias :version :version_with_newrelic_trace

    end
  end
end

DependencyDetection.defer do
  @name = :carrierwave_image_processing

  depends_on do
    defined?(::CarrierWave::Vips) &&
    !NewRelic::Control.instance['disable_carrierwave_image_processing'] &&
    ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
  end

  executes do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Image Processing Instrumentation'
  end

  executes do
    if defined?(::CarrierWave::Vips)
      ::CarrierWave::Vips.class_eval do
        include NewRelic::Agent::Instrumentation::ControllerInstrumentation

        def manipulate_with_newrelic
          metrics = ["Custom/CarrierWave/Manipulate"]
          self.class.trace_execution_scoped(metrics) do
            version_without_newrelic_trace(name, options, &block)
          end
        end

        alias :manipulate_without_newrelic :manipulate!
        alias :manipulate! :manipulate_with_newrelic

        add_method_tracer(:resize_image)
        add_method_tracer(:resize_to_limit)
        add_method_tracer(:resize_to_fill)
      end
    end
  end
end
<commit_msg>Fix for unused var round deuce<commit_after>require 'new_relic/agent/method_tracer'
require 'new_relic/agent/instrumentation/controller_instrumentation'

DependencyDetection.defer do
  @name = :carrierwave

  depends_on do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Instrumentation'
    defined?(::CarrierWave) &&
    !NewRelic::Control.instance['disable_carrierwave'] &&
    ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
  end

  executes do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Instrumentation'
  end

  executes do
    ::CarrierWave::Storage::Fog.class_eval do
      def call_store_with_newrelic_trace(file)

        metrics = ["External/CarrierWave/Fog"]

        if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
          total_metric = 'External/allWeb'
        else
          total_metric = 'External/allOther'
        end
        metrics << total_metric
        self.class.trace_execution_scoped(metrics) do
          call_storage_without_newrelic_trace(file)
        end
      end

      def call_retrieve_with_newrelic_trace(identifier)
        metrics = ["Custom/CarrierWave/Retrieve"]
        self.class.trace_execution_scoped(metrics) do
          call_retrieve_without_newrelic_trace(identifier)
        end
      end

      alias :call_store_without_newrelic_trace :store!
      alias :store! :call_store_with_newrelic_trace

      alias :call_retrieve_without_newrelic_trace :retrieve!
      alias :retrieve! :call_retrieve_with_newrelic_trace
    end

    ::CarrierWave::Uploader::Versions::ClassMethods.class_eval do

      def version_with_newrelic_trace(name, options = {}, &block)
        metrics = ["Custom/CarrierWave/Version/#{name}"]
        self.class.trace_execution_scoped(metrics) do
          version_without_newrelic_trace(name, options, &block)
        end
      end

      alias :version_without_newrelic_trace :version
      alias :version :version_with_newrelic_trace

    end
  end
end

DependencyDetection.defer do
  @name = :carrierwave_image_processing

  depends_on do
    defined?(::CarrierWave::Vips) &&
    !NewRelic::Control.instance['disable_carrierwave_image_processing'] &&
    ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
  end

  executes do
    NewRelic::Agent.logger.debug 'Installing CarrierWave Image Processing Instrumentation'
  end

  executes do
    if defined?(::CarrierWave::Vips)
      ::CarrierWave::Vips.class_eval do
        include NewRelic::Agent::Instrumentation::ControllerInstrumentation

        def manipulate_with_newrelic
          metrics = ["Custom/CarrierWave/Manipulate"]
          self.class.trace_execution_scoped(metrics) do
            manipulate_without_newrelic_trace
          end
        end

        alias :manipulate_without_newrelic :manipulate!
        alias :manipulate! :manipulate_with_newrelic

        add_method_tracer(:resize_image)
        add_method_tracer(:resize_to_limit)
        add_method_tracer(:resize_to_fill)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08326408509223866, 'fraction_numerical': 0.0, 'mean_word_length': 3.5453172205438066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '813884', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1858, 'n_words': 297}