Sha256: 28e0cbaf5895008a6e9b13b1a20ab58cec72f23de03f188019a8844fa68f52a1

Contents?: true

Size: 1.28 KB

Versions: 4

Compression:

Stored size: 1.28 KB

Contents

module Rails
  module Instrumentation
    module Patch
      def self.patch_process_action(klass: ::ActionController::Instrumentation)
        klass.class_eval do
          alias_method :process_action_original, :process_action

          def process_action(method_name, *args)
            # this naming scheme 'class.method' is how we ensure that the notification in the
            # subscriber is the same one
            name = "#{self.class.name}.#{method_name}"
            scope = ::Rails::Instrumentation.tracer.start_active_span(name)

            # skip adding tags here. Getting the complete set of information is
            # easiest in the notification

            process_action_original(method_name, *args)
          rescue Error => error
            if scope
              scope.span.set_tag('error', true)
              scope.span.log_kv(key: 'message', value: error.message)
            end

            raise
          ensure
            scope.close
          end
        end
      end

      def self.restore_process_action(klass: ::ActionController::Instrumentation)
        klass.class_eval do
          remove_method :process_action
          alias_method :process_action, :process_action_original
          remove_method :process_action_original
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails-instrumentation-0.1.5 lib/rails/instrumentation/patch.rb
rails-instrumentation-0.1.4 lib/rails/instrumentation/patch.rb
rails-instrumentation-0.1.3 lib/rails/instrumentation/patch.rb
rails-instrumentation-0.1.2 lib/rails/instrumentation/patch.rb