Sha256: 69663418a7017c9935bf5fefe589f365f3fe99e455ccee44ba5df6be0ac8bae4

Contents?: true

Size: 1.61 KB

Versions: 46

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Appsignal
  module Integrations
    # @api private
    module RakeIntegration
      def execute(*args)
        transaction =
          if Appsignal.config[:enable_rake_performance_instrumentation]
            Appsignal::Integrations::RakeIntegrationHelper.register_at_exit_hook
            _appsignal_create_transaction
          end

        Appsignal.instrument "task.rake" do
          super
        end
      rescue Exception => error # rubocop:disable Lint/RescueException
        Appsignal::Integrations::RakeIntegrationHelper.register_at_exit_hook
        transaction ||= _appsignal_create_transaction
        transaction.set_error(error)
        raise error
      ensure
        if transaction
          # Format given arguments and cast to hash if possible
          params, _ = args
          params = params.to_hash if params.respond_to?(:to_hash)
          transaction.set_action(name)
          transaction.add_params_if_nil(params)
          transaction.complete
        end
      end

      private

      def _appsignal_create_transaction
        Appsignal::Transaction.create("rake")
      end
    end

    # @api private
    module RakeIntegrationHelper
      # Register an `at_exit` hook when a task is executed. This will stop
      # AppSignal when _all_ tasks are executed and Rake exits.
      def self.register_at_exit_hook
        return if @register_at_exit_hook

        Kernel.at_exit(&method(:at_exit_hook))

        @register_at_exit_hook = true
      end

      # The at_exit hook itself
      def self.at_exit_hook
        Appsignal.stop("rake")
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
appsignal-4.3.2-java lib/appsignal/integrations/rake.rb
appsignal-4.3.2 lib/appsignal/integrations/rake.rb
appsignal-4.3.1-java lib/appsignal/integrations/rake.rb
appsignal-4.3.1 lib/appsignal/integrations/rake.rb
appsignal-4.3.0-java lib/appsignal/integrations/rake.rb
appsignal-4.3.0 lib/appsignal/integrations/rake.rb
appsignal-4.2.3-java lib/appsignal/integrations/rake.rb
appsignal-4.2.3 lib/appsignal/integrations/rake.rb
appsignal-4.2.2-java lib/appsignal/integrations/rake.rb
appsignal-4.2.2 lib/appsignal/integrations/rake.rb
appsignal-4.2.1-java lib/appsignal/integrations/rake.rb
appsignal-4.2.1 lib/appsignal/integrations/rake.rb
appsignal-4.2.0-java lib/appsignal/integrations/rake.rb
appsignal-4.2.0 lib/appsignal/integrations/rake.rb
appsignal-4.1.3-java lib/appsignal/integrations/rake.rb
appsignal-4.1.3 lib/appsignal/integrations/rake.rb
appsignal-4.1.2-java lib/appsignal/integrations/rake.rb
appsignal-4.1.2 lib/appsignal/integrations/rake.rb
appsignal-4.1.1-java lib/appsignal/integrations/rake.rb
appsignal-4.1.1 lib/appsignal/integrations/rake.rb