Sha256: 558ab0f5fd9a96f788bd172854c01b6e607e06af7f555cdad56fc1b5d541ad64

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  # @api private
  module Spies
    # @api private
    class RakeSpy
      def install
        ::Rake::Task.class_eval do
          alias execute_without_apm execute

          def execute(*args)
            agent = ElasticAPM.start

            unless agent && agent.config.instrumented_rake_tasks.include?(name)
              return execute_without_apm(*args)
            end

            transaction =
              ElasticAPM.start_transaction("Rake::Task[#{name}]", 'Rake')

            begin
              result = execute_without_apm(*args)

              transaction.result = 'success' if transaction
            rescue StandardError => e
              transaction.result = 'error' if transaction
              ElasticAPM.report(e)

              raise
            ensure
              ElasticAPM.end_transaction
              ElasticAPM.stop
            end

            result
          end
        end
      end
    end
    register 'Rake::Task', 'rake', RakeSpy.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
elastic-apm-3.6.0 lib/elastic_apm/spies/rake.rb
elastic-apm-3.5.0 lib/elastic_apm/spies/rake.rb
elastic-apm-3.4.0 lib/elastic_apm/spies/rake.rb
elastic-apm-3.3.0 lib/elastic_apm/spies/rake.rb